You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Steve Caum <st...@caumfamily.com> on 2003/03/13 18:43:15 UTC

James Passwords for Tomcat4 Authentication

I am trying to make Tomcat 4.1 use JDBCRealm to authenticate users to the 'protected' apps.  I am hoping to ultimately be able to put a web-based email link to James (using IMP) on the protected page and avoid making the users log in multiple times.

I've hit a little problem.  James is storing the user information to the database (mysql) using the 'SHA' encryption algorithm and BASE-64.  It is apparently doing something to concatenate the final encrypted password to 20 bytes.  When I ask Tomcat (server.xml) to use this database table for authentication, the passwords are not matching.  If I change to clear text passwords (and put a dummy entry in the mysql table with a clear text password), then it works.  I am using auth-method=BASIC, so Tomcat is throwing up a password box.

Apparently, the problem is due to Tomcat and Apache deriving a different encrypted password string from the same clear text password.  Google searches have found a few discussions from over a year ago on this subject, but no ultimate resolution.  Has anyone successfully gotten this to work?  Is there a better way I should approach it?

Thanks.

Steve

RE: James Passwords for Tomcat4 Authentication

Posted by "Noel J. Bergman" <no...@devtech.com>.
Steve,

James' logic is encapsulated in three methods.  Two of them are:

   DefaultUser.verifyPassword(String);
   DefaultUser.setPassword(String newPass);

both of which are pretty trivial.  The real method is:

   DigestUtil.digestString(String, String);

See:
http://cvs.apache.org/viewcvs/jakarta-james/src/java/org/apache/james/securi
ty/DigestUtil.java

There is a test driver built-in to allow standalone testing, which should
make things easier for you.

Basically, James computes a digest for the password, and base64 encodes it.
Both of those operations are performed using standard packages,
java.security.MessageDigest and javax.mail.internet.MimeUtility,
respectively.

HTTP Authentication works differently, as you can see by reading the RFCs or
this easy to understand article:
http://frontier.userland.com/stories/storyReader$2159

With basic authentication, the HTTP password is base64 encoded, shipped, and
decoded.  Then you can treat it as you wish.  The drawback is that it is
shipped in plain text, although TLS can address that issue.

At the moment, James does not support APOP.  If/when it did, user
authentication would have to change.  Amongst other things, the user
password would have to be stored in a reversible format (or plain-text) to
allow the digest to be computed locally.

	--- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-user-help@jakarta.apache.org


RE: James Passwords for Tomcat4 Authentication

Posted by Vincenzo Gianferrari Pini <vi...@praxis.it>.
Steve,

here I'll describe what I have up an running.

Notice though that I have everything set to use MD5, so I'm not sure that it
would fully apply to SHA.

The system we have is composed of a custom made web application based on
Oracle PL/SQL, of a Tomcat 4.0 web container we use for our intranet and
extranet sites, and James.

First of all, we had already an existing application handling employee
information (including its creation/update/deletion), and among other things
there is a functionality allowing each employee to set/change his own
password to access such system.
The password is "digested" (hashed) using an MD5 algorithm we had already
written in 'C' and such digest (in hex = base-16) is stored in an Oracle
table. Signons to the application are done checking against it.

The said application is running on a Linux server located in location A.

In location B there is a Win2K server running a Tomcat 4.0 server managing
our company web site and our signon protected (using standard Tomcat
passwords) company intranet site, and a James 2.1.2a2 server which is our
mail server.

We want to have passwords shared by the three systems, with a single user
add/modify/delete and password set/change function (not a single signon
though).

So we have set up the following:

1) Both James and Tomcat share the same table (the "users" table created by
James augmented by some fields) in a MS SQL Server 2000 database in location
B. In particular there is a "pwdHashHex" that contains the base-16 MD5
digest to be used by Tomcat, while "pwdHash" is in base-64 to be used by
Tomcat. There are also other tables, a "user_roles" used by Tomcat and a
"lists" created and used by James.

2) There is a Win2K java service that, each 10 minutes, accesses the Oracle
database in location A and, based on that, updates by difference all tables
in location B, creating new users, deleting others, inserting/removing them
in special branch-office related mailing lists, inserting/removing in
special security roles based on other employee data, generating contact
lists (Address Books) to be imported in Outlook or Outlook Express etc.
Among all this, it updates the MD5 password digests when finds them changed
in the Oracle database in location A.

Regarding the passwords, we decided to not change anything in James or
Tomcat, but just to import directly the base-16 MD5 digest from the Oracle
table to the "pwdHashHex" field used by Tomcat (the values are consistent)
and transform it into base-64 and store it in the "pwdHash" field used by
James. Remember that the Win2K java service had no way to "see" the password
in plain text.

To transform the MD5 digest from base-16 to base-64 we use the code attached
to the
http://www.mail-archive.com/james-user@jakarta.apache.org/msg04612.html
message in this list. The code uses a base-64 conversion java routine
("Base64.encodeBytes") that we found somewhere in the net, while James (see
the link shown by Noel in another message of this thread) uses
"MimeUtility.encode".

There was a problem: for certain passwords, the result of our algorithm was
a base-64 string longer than 20 characters, while the James algorithm gives
20 characters. I *don't know* if it's a bug in "Base64.encodeBytes" or if
"MimeUtility.encode" truncates to 20 characters (I may check in the future):
we just truncate our result to 20 and everything is fine. If the problem is
in "MimeUtility.encode", it would mean that it exists a loss of information,
and it would be impossible in general to convert from a James MD5 digest to
a Tomcat MD5 digest, while the reverse is always possible as is our case.

To summarize in your case:

1) If you directly control with a code of yours the update of a password,
you can simply just build the two MD5 (or SHA or a mix) digests and store
them in the two different table fields;

2) if you have to build from the Tomcat MD5 base-16 digest a James base-64
MD5 digest you can do as we did, perhaps using "MimeUtility.encode" instead
of the less known "Base64.encodeBytes" (MD5 to MD5 is ok, SHA to SHA I don't
know, MD5 to SHA and viceversa is impossible by definition);

3) if you have to build from the James MD5 base-64 digest a Tomcat base-16
MD5 digest it may be possible or not depending on the said "20 characters
truncation issue".

4) I would avoid "as the pest" modifying either James or Tomcat.

It's been a long message, but I hope it helps you.

Bye,

Vincenzo

> -----Original Message-----
> From: Steve Caum [mailto:steve@caumfamily.com]
> Sent: venerdì 14 marzo 2003 0.37
> To: James Users List
> Subject: Re: James Passwords for Tomcat4 Authentication
>
>
> Vincenzo,
>
> Thanks for your timely response.  I had actually found your
> previous thread
> through a google search.  I didn't think it applied to what I need.  Maybe
> I'm wrong.  Let me describe what I think is going on.
>
> Tomcat can authenticate users through an existing database.  You
> define the
> url to the database and the column names in the 'server.xml' config file.
> Here is the relevant item I have set up.
>      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
>              driverName="org.gjt.mm.mysql.Driver"
>           connectionURL="jdbc:mysql://localhost/test"
>          connectionName="dbuser" connectionPassword="dbpasswd"
>               userTable="users" userNameCol="username"
> userCredCol="pwdhash"
>           userRoleTable="users" roleNameCol="pwdAlgorithm"/>
>           digest="SHA" />
> Note that since the 'pwdAlgorithm' column contains the same data for every
> user, I made that the role name, rather than creating an additional ROLE
> table.  The secure page (web.xml) is defined to use role="SHA".
>
> James uses its own database schema, and creates it automatically the first
> time it is started up.  Here is the relevant config information I have set
> up in James.
>          <data-source name="maildb"
>             class="org.apache.james.util.mordred.JdbcDataSource">
>             <driver>org.gjt.mm.mysql.Driver</driver>
>             <dburl>jdbc:mysql://localhost/test?autoReconnect=true</dburl>
>             <user>dbuser</user>
>             <password>dbpasswd</password>
>             <max>20</max>
>          </data-source>
>
> The problem I think I'm having is that James and Tomcat are generating
> different encrypted password strings for the same password, which is
> resulting in a failure of authentication.  Following is James'
> and Tomcat's
> interpretation of the same password.
>
> password:  george
> James:  n9jeX8KnwsDUabL/8a/eTl3v
> Tomcat: 9fd8de5fc2a7c2c0d469b2fff1afde4e5def37ba
>
> I obtained the James password from the database.  The Tomcat password was
> generated using RealmBase.  It looks to me like James might be
> using base-64
> and Tomcat base-16.  It is obvious to me that I have to change
> either James
> or Tomcat to fix this.  Problem is, I am not sure which should be modified
> or how.
>
> Any help?
>
> Steve
>
> ----- Original Message -----
> From: "Vincenzo Gianferrari Pini" <vi...@praxis.it>
> To: "James Users List" <ja...@jakarta.apache.org>
> Sent: Thursday, March 13, 2003 1:25 PM
> Subject: RE: James Passwords for Tomcat4 Authentication
>
>
> > Hello Steve,
> >
> > I have something quite similar working.
> >
> > There has already been a discussion in this list some time ago:
> > http://www.mail-archive.com/james-user@jakarta.apache.org/msg04612.html
> >
> > Unfortunately I have to leave right now, so I don't have time to explain
> the
> > things in detail, but if you need more explanation than what is in the
> link,
> > let me know and tomorrow I will answer you.
> >
> > Bye,
> >
> > Vincenzo
> >
> > > -----Original Message-----
> > > From: Steve Caum [mailto:steve@caumfamily.com]
> > > Sent: giovedì 13 marzo 2003 18.43
> > > To: james-user@jakarta.apache.org
> > > Subject: James Passwords for Tomcat4 Authentication
> > >
> > >
> > > I am trying to make Tomcat 4.1 use JDBCRealm to authenticate
> > > users to the 'protected' apps.  I am hoping to ultimately be able
> > > to put a web-based email link to James (using IMP) on the
> > > protected page and avoid making the users log in multiple times.
> > >
> > > I've hit a little problem.  James is storing the user information
> > > to the database (mysql) using the 'SHA' encryption algorithm and
> > > BASE-64.  It is apparently doing something to concatenate the
> > > final encrypted password to 20 bytes.  When I ask Tomcat
> > > (server.xml) to use this database table for authentication, the
> > > passwords are not matching.  If I change to clear text passwords
> > > (and put a dummy entry in the mysql table with a clear text
> > > password), then it works.  I am using auth-method=BASIC, so
> > > Tomcat is throwing up a password box.
> > >
> > > Apparently, the problem is due to Tomcat and Apache deriving a
> > > different encrypted password string from the same clear text
> > > password.  Google searches have found a few discussions from over
> > > a year ago on this subject, but no ultimate resolution.  Has
> > > anyone successfully gotten this to work?  Is there a better way I
> > > should approach it?
> > >
> > > Thanks.
> > >
> > > Steve
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: james-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: james-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-user-help@jakarta.apache.org


RE: James Passwords for Tomcat4 Authentication

Posted by "Noel J. Bergman" <no...@devtech.com>.
> password:  george
> James:  n9jeX8KnwsDUabL/8a/eTl3v
> Tomcat: 9fd8de5fc2a7c2c0d469b2fff1afde4e5def37ba

> It looks to me like James might be using base-64
> and Tomcat base-16.

As I said earlier, see:
http://cvs.apache.org/viewcvs/jakarta-james/src/java/org/apache/james/securi
ty/DigestUtil.java

	--- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-user-help@jakarta.apache.org


Re: James Passwords for Tomcat4 Authentication

Posted by Steve Caum <st...@caumfamily.com>.
Vincenzo,

Thanks for your timely response.  I had actually found your previous thread
through a google search.  I didn't think it applied to what I need.  Maybe
I'm wrong.  Let me describe what I think is going on.

Tomcat can authenticate users through an existing database.  You define the
url to the database and the column names in the 'server.xml' config file.
Here is the relevant item I have set up.
     <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
             driverName="org.gjt.mm.mysql.Driver"
          connectionURL="jdbc:mysql://localhost/test"
         connectionName="dbuser" connectionPassword="dbpasswd"
              userTable="users" userNameCol="username" userCredCol="pwdhash"
          userRoleTable="users" roleNameCol="pwdAlgorithm"/>
          digest="SHA" />
Note that since the 'pwdAlgorithm' column contains the same data for every
user, I made that the role name, rather than creating an additional ROLE
table.  The secure page (web.xml) is defined to use role="SHA".

James uses its own database schema, and creates it automatically the first
time it is started up.  Here is the relevant config information I have set
up in James.
         <data-source name="maildb"
            class="org.apache.james.util.mordred.JdbcDataSource">
            <driver>org.gjt.mm.mysql.Driver</driver>
            <dburl>jdbc:mysql://localhost/test?autoReconnect=true</dburl>
            <user>dbuser</user>
            <password>dbpasswd</password>
            <max>20</max>
         </data-source>

The problem I think I'm having is that James and Tomcat are generating
different encrypted password strings for the same password, which is
resulting in a failure of authentication.  Following is James' and Tomcat's
interpretation of the same password.

password:  george
James:  n9jeX8KnwsDUabL/8a/eTl3v
Tomcat: 9fd8de5fc2a7c2c0d469b2fff1afde4e5def37ba

I obtained the James password from the database.  The Tomcat password was
generated using RealmBase.  It looks to me like James might be using base-64
and Tomcat base-16.  It is obvious to me that I have to change either James
or Tomcat to fix this.  Problem is, I am not sure which should be modified
or how.

Any help?

Steve

----- Original Message -----
From: "Vincenzo Gianferrari Pini" <vi...@praxis.it>
To: "James Users List" <ja...@jakarta.apache.org>
Sent: Thursday, March 13, 2003 1:25 PM
Subject: RE: James Passwords for Tomcat4 Authentication


> Hello Steve,
>
> I have something quite similar working.
>
> There has already been a discussion in this list some time ago:
> http://www.mail-archive.com/james-user@jakarta.apache.org/msg04612.html
>
> Unfortunately I have to leave right now, so I don't have time to explain
the
> things in detail, but if you need more explanation than what is in the
link,
> let me know and tomorrow I will answer you.
>
> Bye,
>
> Vincenzo
>
> > -----Original Message-----
> > From: Steve Caum [mailto:steve@caumfamily.com]
> > Sent: giovedì 13 marzo 2003 18.43
> > To: james-user@jakarta.apache.org
> > Subject: James Passwords for Tomcat4 Authentication
> >
> >
> > I am trying to make Tomcat 4.1 use JDBCRealm to authenticate
> > users to the 'protected' apps.  I am hoping to ultimately be able
> > to put a web-based email link to James (using IMP) on the
> > protected page and avoid making the users log in multiple times.
> >
> > I've hit a little problem.  James is storing the user information
> > to the database (mysql) using the 'SHA' encryption algorithm and
> > BASE-64.  It is apparently doing something to concatenate the
> > final encrypted password to 20 bytes.  When I ask Tomcat
> > (server.xml) to use this database table for authentication, the
> > passwords are not matching.  If I change to clear text passwords
> > (and put a dummy entry in the mysql table with a clear text
> > password), then it works.  I am using auth-method=BASIC, so
> > Tomcat is throwing up a password box.
> >
> > Apparently, the problem is due to Tomcat and Apache deriving a
> > different encrypted password string from the same clear text
> > password.  Google searches have found a few discussions from over
> > a year ago on this subject, but no ultimate resolution.  Has
> > anyone successfully gotten this to work?  Is there a better way I
> > should approach it?
> >
> > Thanks.
> >
> > Steve
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: james-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-user-help@jakarta.apache.org


RE: James Passwords for Tomcat4 Authentication

Posted by Vincenzo Gianferrari Pini <vi...@praxis.it>.
Hello Steve,

I have something quite similar working.

There has already been a discussion in this list some time ago:
http://www.mail-archive.com/james-user@jakarta.apache.org/msg04612.html

Unfortunately I have to leave right now, so I don't have time to explain the
things in detail, but if you need more explanation than what is in the link,
let me know and tomorrow I will answer you.

Bye,

Vincenzo

> -----Original Message-----
> From: Steve Caum [mailto:steve@caumfamily.com]
> Sent: giovedì 13 marzo 2003 18.43
> To: james-user@jakarta.apache.org
> Subject: James Passwords for Tomcat4 Authentication
>
>
> I am trying to make Tomcat 4.1 use JDBCRealm to authenticate
> users to the 'protected' apps.  I am hoping to ultimately be able
> to put a web-based email link to James (using IMP) on the
> protected page and avoid making the users log in multiple times.
>
> I've hit a little problem.  James is storing the user information
> to the database (mysql) using the 'SHA' encryption algorithm and
> BASE-64.  It is apparently doing something to concatenate the
> final encrypted password to 20 bytes.  When I ask Tomcat
> (server.xml) to use this database table for authentication, the
> passwords are not matching.  If I change to clear text passwords
> (and put a dummy entry in the mysql table with a clear text
> password), then it works.  I am using auth-method=BASIC, so
> Tomcat is throwing up a password box.
>
> Apparently, the problem is due to Tomcat and Apache deriving a
> different encrypted password string from the same clear text
> password.  Google searches have found a few discussions from over
> a year ago on this subject, but no ultimate resolution.  Has
> anyone successfully gotten this to work?  Is there a better way I
> should approach it?
>
> Thanks.
>
> Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: james-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-user-help@jakarta.apache.org