jdk/src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
changeset 24372 2ff88b15e82e
parent 23010 6dadb192ad81
child 24969 afa6934dd8e8
--- a/jdk/src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java	Tue May 13 11:03:25 2014 +0100
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java	Wed May 14 11:16:41 2014 +0100
@@ -34,8 +34,11 @@
 import java.util.Random;
 
 import sun.net.www.HeaderParser;
+import sun.net.NetProperties;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
 import static sun.net.www.protocol.http.HttpURLConnection.HTTP_CONNECT;
 
 /**
@@ -51,6 +54,23 @@
 
     private String authMethod;
 
+    private final static String compatPropName = "http.auth.digest." +
+        "quoteParameters";
+
+    // true if http.auth.digest.quoteParameters Net property is true
+    private static final boolean delimCompatFlag;
+
+    static {
+        Boolean b = AccessController.doPrivileged(
+            new PrivilegedAction<Boolean>() {
+                public Boolean run() {
+                    return NetProperties.getBoolean(compatPropName);
+                }
+            }
+        );
+        delimCompatFlag = (b == null) ? false : b.booleanValue();
+    }
+
     // Authentication parameters defined in RFC2617.
     // One instance of these may be shared among several DigestAuthentication
     // instances as a result of a single authorization (for multiple domains)
@@ -206,7 +226,7 @@
     }
 
     /**
-     * Reclaculates the request-digest and returns it.
+     * Recalculates the request-digest and returns it.
      *
      * <P> Used in the common case where the requestURI is simply the
      * abs_path.
@@ -225,7 +245,7 @@
     }
 
     /**
-     * Reclaculates the request-digest and returns it.
+     * Recalculates the request-digest and returns it.
      *
      * <P> Used when the requestURI is not the abs_path. The exact
      * requestURI can be passed as a String.
@@ -357,24 +377,34 @@
             ncfield = "\", nc=" + ncstring;
         }
 
+        String algoS, qopS;
+
+        if (delimCompatFlag) {
+            // Put quotes around these String value parameters
+            algoS = ", algorithm=\"" + algorithm + "\"";
+            qopS = ", qop=\"auth\"";
+        } else {
+            // Don't put quotes around them, per the RFC
+            algoS = ", algorithm=" + algorithm;
+            qopS = ", qop=auth";
+        }
+
         String value = authMethod
                         + " username=\"" + pw.getUserName()
                         + "\", realm=\"" + realm
                         + "\", nonce=\"" + nonce
                         + ncfield
                         + ", uri=\"" + uri
-                        + "\", response=\"" + response
-                        + "\", algorithm=" + algorithm;
+                        + "\", response=\"" + response + "\""
+                        + algoS;
         if (opaque != null) {
-            value = value + ", opaque=\"" + opaque;
-            value = value + "\"";
+            value += ", opaque=\"" + opaque + "\"";
         }
         if (cnonce != null) {
-            value = value + ", cnonce=\"" + cnonce;
-            value = value + "\"";
+            value += ", cnonce=\"" + cnonce + "\"";
         }
         if (qop) {
-            value = value + ", qop=auth";
+            value += qopS;
         }
         return value;
     }