Skip to content

Commit 877f0e9

Browse files
committed
Follow-on to PR #1109. Further minor fixes for Digest auth
Add a change log entry Update RFC references Correct digest parameter from "digest-uri" to "uri"
1 parent 4d7506f commit 877f0e9

13 files changed

Lines changed: 44 additions & 32 deletions

File tree

‎java/org/apache/catalina/authenticator/DigestAuthenticator.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void setOpaque(String opaque) {
245245
}
246246

247247
/**
248-
* Get whether the URI should be validated as required by RFC2617.
248+
* Get whether the URI should be validated as required by RFC 7616.
249249
*
250250
* @return {@code true} if URI validation is enabled
251251
*/
@@ -254,7 +254,7 @@ public boolean isValidateUri() {
254254
}
255255

256256
/**
257-
* Set whether the URI should be validated as required by RFC2617.
257+
* Set whether the URI should be validated as required by RFC 7616.
258258
*
259259
* @param validateUri {@code true} to enable URI validation
260260
*/
@@ -756,7 +756,7 @@ public boolean validate(Request request, List<AuthDigest> algorithms) {
756756
if (cnonce == null || nc == null) {
757757
return false;
758758
}
759-
// RFC 2617 says nc must be 8 digits long. Older Android clients
759+
// RFC 7616 says nc must be 8 digits long. Older Android clients
760760
// use 6. 2.3.5 < fixed Android version <= 4.0.3
761761
if (nc.length() < 6 || nc.length() > 8) {
762762
return false;

‎java/org/apache/catalina/authenticator/mbeans-descriptors.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
writeable="false"/>
140140

141141
<attribute name="validateUri"
142-
description="Should the uri be validated as required by RFC2617?"
142+
description="Should the uri be validated as required by RFC 7616?"
143143
type="boolean"/>
144144
</mbean>
145145

‎java/org/apache/catalina/authenticator/package.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
<p>The standard authentication methods that are currently provided include:</p>
4545
<ul>
4646
<li><b>BasicAuthenticator</b> - Implements HTTP BASIC authentication, as
47-
described in RFC 2617.</li>
47+
described in RFC 7617.</li>
4848
<li><b>DigestAuthenticator</b> - Implements HTTP DIGEST authentication, as
49-
described in RFC 2617.</li>
49+
described in RFC 7616.</li>
5050
<li><b>FormAuthenticator</b> - Implements FORM-BASED authentication, as
5151
described in the Servlet API Specification.</li>
5252
</ul>

‎java/org/apache/tomcat/util/http/parser/Authorization.java‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ public class Authorization {
3131

3232
static {
3333
// Digest field types.
34-
// Note: These are more relaxed than RFC2617. This adheres to the
35-
// recommendation of RFC2616 that servers are tolerant of buggy
36-
// clients when they can be so without ambiguity.
34+
// Note: These are more relaxed than RFC 7616 without introducing ambiguities
3735
fieldTypes.put("username", FieldType.QUOTED_STRING);
3836
fieldTypes.put("realm", FieldType.QUOTED_STRING);
3937
fieldTypes.put("nonce", FieldType.QUOTED_STRING);
40-
fieldTypes.put("digest-uri", FieldType.QUOTED_STRING);
41-
// RFC2617 says response is <">32LHEX<">. 32LHEX will also be accepted
38+
fieldTypes.put("uri", FieldType.QUOTED_STRING);
39+
// RFC 7616 says response is quoted lower case hex. unquoted will also be accepted
4240
fieldTypes.put("response", FieldType.LHEX);
43-
// RFC2617 says algorithm is token. <">token<"> will also be accepted
41+
// RFC 7616 says algorithm is token. <">token<"> will also be accepted
4442
fieldTypes.put("algorithm", FieldType.QUOTED_TOKEN);
4543
fieldTypes.put("cnonce", FieldType.QUOTED_STRING);
4644
fieldTypes.put("opaque", FieldType.QUOTED_STRING);
47-
// RFC2617 says qop is token. <">token<"> will also be accepted
45+
// RFC 7616 says qop is token. <">token<"> will also be accepted
4846
fieldTypes.put("qop", FieldType.QUOTED_TOKEN);
49-
// RFC2617 says nc is 8LHEX. <">8LHEX<"> will also be accepted
47+
// RFC 7616 says nc is 8LHEX. <">8LHEX<"> will also be accepted
5048
fieldTypes.put("nc", FieldType.LHEX);
5149

5250
}
@@ -58,15 +56,15 @@ private Authorization() {
5856

5957

6058
/**
61-
* Parses an HTTP Authorization header for DIGEST authentication as per RFC 2617 section 3.2.2.
59+
* Parses an HTTP Authorization header for DIGEST authentication as per RFC 7616 section 3.4.
6260
*
6361
* @param input The header value to parse
6462
*
6563
* @return A map of directives and values as {@link String}s or <code>null</code> if a parsing error occurs.
6664
* Although the values returned are {@link String}s they will have been validated to ensure that they
67-
* conform to RFC 2617.
65+
* conform to RFC 7616.
6866
*
69-
* @throws IllegalArgumentException If the header does not conform to RFC 2617
67+
* @throws IllegalArgumentException If the header does not conform to RFC 7616
7068
* @throws IOException If an error occurs while reading the input
7169
*/
7270
public static Map<String,String> parseAuthorizationDigest(StringReader input)

‎java/org/apache/tomcat/websocket/DigestAuthenticator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private String calculateRequestDigest(String method, String requestUri, String u
158158

159159
/*
160160
* If the "qop" value is "auth-int", then A2 is:
161-
* A2 = Method ":" digest-uri-value ":" H(entity-body)
161+
* A2 = Method ":" request-uri ":" H(entity-body)
162162
* There is no entity-body for a WebSocket handshake but the hash of
163163
* the empty body still has to be included.
164164
*/

‎test/org/apache/catalina/authenticator/TestBasicAuthParser.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public void testLineWrap() throws Exception {
100100
}
101101

102102
/*
103-
* RFC 2045 says the Base64 encoded string should be represented as lines of no more than 76 characters. However,
104-
* RFC 2617 says a base64-user-pass token is not limited to 76 char/line.
103+
* RFC 7617 uses token68 which in this case holds base 64 without whitespace so there is no 76 character per line
104+
* limit.
105105
*/
106106
@Test
107107
public void testGoodCribBase64Big() throws Exception {
@@ -119,7 +119,7 @@ public void testGoodCribBase64Big() throws Exception {
119119

120120

121121
/*
122-
* verify the parser follows RFC2617 by treating the auth-scheme token as case-insensitive.
122+
* Verify the parser follows RFC 9110 by treating the auth-scheme token as case-insensitive.
123123
*/
124124
@Test
125125
public void testAuthMethodCaseBasic() throws Exception {

‎test/org/apache/catalina/authenticator/TestDigestAuthenticator.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ protected static String getOpaque(Map<String,List<String>> respHeaders) {
293293
/*
294294
* @formatter:off
295295
*
296-
* Notes from RFC2617
297-
* H(data) = MD5(data)
296+
* Notes from RFC 7616
297+
* H(data) = hash-algorithm(data)
298298
* KD(secret, data) = H(concat(secret, ":", data))
299299
* A1 = unq(username-value) ":" unq(realm-value) ":" passwd
300-
* A2 = Method ":" digest-uri-value
300+
* A2 = Method ":" request-uri
301301
* request-digest = <"> < KD ( H(A1), unq(nonce-value)
302302
* ":" nc-value
303303
* ":" unq(cnonce-value)

‎test/org/apache/catalina/authenticator/TestNonLoginAndBasicAuthenticator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void testAuthMethodBadCredentials() throws Exception {
138138
}
139139

140140
/*
141-
* This is the same as testAcceptProtectedBasic (above), except to verify the server follows RFC2617 by treating the
141+
* This is the same as testAcceptProtectedBasic (above), except to verify the server follows RFC 9110 by treating the
142142
* auth-scheme token as case-insensitive.
143143
*/
144144
@Test

‎test/org/apache/catalina/authenticator/TestSSOnonLoginAndDigestAuthenticator.java‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,20 @@ protected static String getAuthToken(Map<String,List<String>> respHeaders, Strin
339339
}
340340

341341
/*
342-
* Notes from RFC2617 H(data) = MD5(data) KD(secret, data) = H(concat(secret, ":", data)) A1 = unq(username-value)
343-
* ":" unq(realm-value) ":" passwd A2 = Method ":" digest-uri-value request-digest = <"> < KD ( H(A1),
344-
* unq(nonce-value) ":" nc-value ":" unq(cnonce-value) ":" unq(qop-value) ":" H(A2) ) <">
342+
* @formatter:off
343+
*
344+
* Notes from RFC 7616
345+
* H(data) = hash-algorithm(data)
346+
* KD(secret, data) = H(concat(secret, ":", data))
347+
* A1 = unq(username-value) ":" unq(realm-value) ":" passwd
348+
* A2 = Method ":" request-uri
349+
* request-digest = <"> < KD ( H(A1), unq(nonce-value)
350+
* ":" nc-value
351+
* ":" unq(cnonce-value)
352+
* ":" unq(qop-value)
353+
* ":" H(A2)
354+
* ) <">
355+
* @formatter:on
345356
*/
346357
private static String buildDigestResponse(String user, String pwd, String uri, String realm, String nonce,
347358
String opaque, String nc, String cnonce, String qop) {

‎test/org/apache/tomcat/websocket/TestDigestAuthenticator.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ private void doTestAuthorization(String qop) throws Exception {
7373
Assert.assertEquals("00000001", nc);
7474

7575
// Calculate the expected response independently of the code under
76-
// test, in the same way as a server would, per RFC 2617 section
77-
// 3.2.2.1 and RFC 7616 section 3.4.2.
76+
// test, in the same way as a server would, per RFC 7616 section 3.4.2.
7877
String a1 = userName + ":" + realm + ":" + password;
7978
String a2 = method + ":" + requestUri;
8079
if ("auth-int".equals(qop)) {

0 commit comments

Comments
 (0)