10

I am trying to use the manager application that comes with Tomcat 8.5. However, every time that I try to log on with the password of "test" for the user "admin", it does not work. If I plug in the exact MD5 hash that I obtained from digest.bat, I am able to log in.

Has anyone managed to get this working appropriately?

server.xml

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase" digest="md5" />
              <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="MD5" />
        </Realm>

tomcat-users.xml

<?xml version='1.0' encoding='cp1252'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">

<user username="admin" password="41858d1250c84a1bfb882bcb02b85ba8" roles="admin-gui,manager-gui" />
<user username="test" password="test" roles="manager-gui,admin-gui" />
</tomcat-users>

tomcat webapp manager web.xml excerpt

  <!-- Define the Login Configuration for this Application -->
  <login-config>
    <auth-method>DIGEST</auth-method>
    <realm-name>TEST</realm-name>
    <!--<realm-name>Tomcat Manager Application</realm-name>-->
  </login-config>

digest.bat output

.\digest.bat -a MD5 -s 0 admin:TEST:test
admin:TEST:test:41858d1250c84a1bfb882bcb02b85ba8
appsecguy
  • 1,019
  • 3
  • 19
  • 36

4 Answers4

14

**** Password digest process has been change to tomcat 8.5 version; it has been modified then how it was in tomcat earlier versions

Here is the tomcat password digest process for Tomcat 8.5.x ( we are using algorithm SHA-256 and SHA-512)

1. Change in $CATALINA_BASE/conf/server.xml file:
    a. From 
         <Realm className="org.apache.catalina.realm.LockOutRealm">
                <!-- This Realm uses the UserDatabase configured in the global JNDI
                     resources under the key "UserDatabase".  Any edits
                     that are performed against this UserDatabase are immediately
                     available for use by the Realm.  -->
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                        resourceName="UserDatabase"/>
             </Realm>
    b. To
         <Realm className="org.apache.catalina.realm.LockOutRealm">
                <!-- This Realm uses the UserDatabase configured in the global JNDI
                     resources under the key "UserDatabase".  Any edits
                     that are performed against this UserDatabase are immediately
                     available for use by the Realm.  -->
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                        resourceName="UserDatabase">
                                <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="sha-512" />
                </Realm>
             </Realm>
2. Create digest password:
    a. Go to location $CATALINA_BASE/bin/ and run digest.sh
        i. For sha-256: 
        [root@aa22 bin]# ./digest.sh -a sha-256 -h org.apache.catalina.realm.MessageDigestCredentialHandler xxxxxxxx
        xxxxxxxx:5327b745a19144e34ca40128219ab660b09ff9cf866222c1850a5e7a716db669$1$b4b734709246d25373a730cad709151db47920f79e1a1d65f6772d1307216f1b

        ii. For sha-512:
        [root@aa12 bin]# ./digest.sh -a sha-512 -h org.apache.catalina.realm.MessageDigestCredentialHandler xxxxxxxx
        xxxxxxxx:d92d95ae2fab83ca1eafae3b900ae9ab2115eac644935fb35a5973c3032dbcc7$1$c1f8e55b0beb771198ab46a69e1559ae145f172226d6f11ee91d67fde361717ca7498f48e486e4267e810b64e0a9096b16311ddc85b746c0019088462975bc9f

3. Now copy digested password to $CATALINA_BASE/conf/tomcat-users.xml
    a. Replace the plain text password with this digested password and restart tomcat. Make sure; you are using same algo name in server.xml; by which you digested the plain test password.
4. End
Tushar De
  • 399
  • 1
  • 5
  • 14
  • This did it for me! Any idea why digest.sh sha-512 gives different output from 'echo -n myPassword | sha512sum' ? – Nikolai May 02 '17 at 09:34
  • This answer is not correct, and there appears to be confusion about the question. *This* answer answers the question "how do I correctly digest my passwords for use with Tomcat authentication" but says nothing about the use of `HTTP DIGEST` authentication, which is a very special beast specifically mentioned by the author of the question. The `HTTP DIGEST` spec demands the use of MD5 and SHA-256 simply will not work. – Christopher Schultz Nov 06 '17 at 05:36
3

Mine worked by following your steps except by placing the CredentialHandler inside the Realm:

<Realm className="org.apache.catalina.realm.LockOutRealm">
   <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase">
      <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="MD5" />
   </Realm>
</Realm>
MasterWill
  • 31
  • 6
  • I'd really rather use SHA which can be done in Tomcat 7, but apparently you're limited to MD5 in Tomcat 8.5. In addition, using this method at least, a user can be responsible for only one app since it needs to be specified while creating the digest :/ – MasterWill Oct 26 '16 at 08:17
  • Tomcat 8.5 is not limited to MD5. You can use any algorithm supported by [java MessageDigest](https://docs.oracle.com/javase/8/docs/api/java/security/MessageDigest.html) – Ben Arena Apr 13 '17 at 00:38
  • I can confirm this. I got Tomcat 8.5 to work with SHA-256. When properly configured, it will work. See here for an example: http://www.techpaste.com/2013/05/enable-password-encryption-policy-tomcat-7/ – atom88 Jun 15 '17 at 16:00
  • see also: https://stackoverflow.com/questions/2978884/tomcat-digest-with-manager-webapp – atom88 Jun 15 '17 at 16:06
3

Here's how you do it in 4 simple steps. Some of the above advice was missing some of the steps (like Step # 4). Also, -s 0 (salt 0) when generating the hash will work also.

1) Generate password: /bin>digest.bat -s 0 -a sha-256

Example: /bin>digest.bat -s 0 -a sha-256 admin

Password to use is: 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918

*Important note: You must use “-s 0 “(salt 0) or it won’t work.

2) paste password above into your tomcat-users.xml file.

Example:

<!-- for password “admin” -->
<user username="tomcat" password="8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918" roles="manager-gui,manager,admin"></user>

3) configure server.xml to use SHA-256 digest hashed based passwords:

<Realm className="org.apache.catalina.realm.LockOutRealm">
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase">
        <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="SHA-256" /> 
    </Realm>
</Realm>

4) configure your web.xml to use “DIGEST” passwords and update RealmName to match above (in the HTMLManager section)

 <catalina_home>/webapps/manager\WEB-INF\web.xml

    <login-config>
        <auth-method>DIGEST</auth-method>
        <realm-name>UserDatabase</realm-name> 
    </login-config>

Full context:
  <servlet>
    <servlet-name>HTMLManager</servlet-name>
    <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>

… SNIPPED_FOR_BREVITY ...   

    <login-config>
    <auth-method>DIGEST</auth-method>
    <realm-name>UserDatabase</realm-name>
  </login-config>

    <multipart-config>
      <!-- 50MB max -->
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>
  </servlet>
atom88
  • 1,449
  • 3
  • 22
  • 32
  • Most complete answer – Benrobot Jan 17 '18 at 02:37
  • This answer doesn't work, `LockoutRealm` doesn't support `CredentialHandlers`. https://stackoverflow.com/questions/64733766/how-to-get-tomcat-credentialhandler-inside-java-when-nested-in-lockoutrealm `Nov 14, 2022 9:03:48 PM org.apache.catalina.realm.CombinedRealm setCredentialHandler WARNUNG: A CredentialHandler was set on an instance of the CombinedRealm (or a sub-class of CombinedRealm). CombinedRealm doesn't use a configured CredentialHandler. Is this a configuration error?` – Thorsten Schöning Nov 14 '22 at 20:33
  • I'm checking the default `web.xml` that came with `tomcat-9.0.78` version and I don't see anything matching with what you have mentioned in your Step #4. Has anything updated for this version? – Tan Aug 16 '23 at 18:29
0

I don't think that it is not easy to choose the algorithm if using DIGEST. (At least I failed...) According the docs https://tomcat.apache.org/tomcat-8.5-doc/realm-howto.html#Digested_Passwords -- "If using digested passwords with DIGEST authentication, the cleartext used to generate the digest is different and the digest must use one iteration of the MD5 algorithm with no salt." Sounds for me that you have to use md5 at least once. It would be much easier to get rid of md5 with form based auth etc.

M van Gock
  • 11
  • 1
  • I can confirm that SHA-256 will work, MD5 is not a requirement. I got Tomcat 8.5 to work with SHA-256. When properly configured, it will work. See here for an example: http://www.techpaste.com/2013/05/enable-password-encryption-policy-tomcat-7/ – atom88 Jun 15 '17 at 16:01
  • see also: https://stackoverflow.com/questions/2978884/tomcat-digest-with-manager-webapp – atom88 Jun 15 '17 at 16:06
  • 1
    This multiply-downvoted answer is actually *the correct one*. – Christopher Schultz Nov 13 '17 at 18:38