Blame SOURCES/pr3393-rh1273760.patch

404409
diff --git a/src/share/classes/sun/security/pkcs11/P11Signature.java b/src/share/classes/sun/security/pkcs11/P11Signature.java
404409
--- openjdk/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java
404409
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java
404409
@@ -87,8 +87,8 @@
404409
     // name of the key algorithm, currently either RSA or DSA
404409
     private final String keyAlgorithm;
404409
 
404409
-    // mechanism id
404409
-    private final long mechanism;
404409
+    // mechanism
404409
+    private final CK_MECHANISM mechanism;
404409
 
404409
     // digest algorithm OID, if we encode RSA signature ourselves
404409
     private final ObjectIdentifier digestOID;
404409
@@ -138,11 +138,62 @@
404409
         super();
404409
         this.token = token;
404409
         this.algorithm = algorithm;
404409
-        this.mechanism = mechanism;
404409
+        CK_MECHANISM ckMechanism = new CK_MECHANISM(mechanism);
404409
+        final CK_RSA_PKCS_PSS_PARAMS mechParams;
404409
         byte[] buffer = null;
404409
         ObjectIdentifier digestOID = null;
404409
         MessageDigest md = null;
404409
         switch ((int)mechanism) {
404409
+        case (int)CKM_SHA1_RSA_PKCS_PSS:
404409
+            mechParams = new CK_RSA_PKCS_PSS_PARAMS();
404409
+            mechParams.hashAlg = CKM_SHA_1;
404409
+            mechParams.mgf = CKG_MGF1_SHA1;
404409
+            mechParams.sLen = 20;
404409
+            ckMechanism = new CK_MECHANISM(mechanism, mechParams);
404409
+            this.keyAlgorithm = "RSA";
404409
+            this.type = T_UPDATE;
404409
+            buffer = new byte[1];
404409
+            break;
404409
+        case (int)CKM_SHA224_RSA_PKCS_PSS:
404409
+            mechParams = new CK_RSA_PKCS_PSS_PARAMS();
404409
+            mechParams.hashAlg = CKM_SHA224;
404409
+            mechParams.mgf = CKG_MGF1_SHA224;
404409
+            mechParams.sLen = 28;
404409
+            ckMechanism = new CK_MECHANISM(mechanism, mechParams);
404409
+            this.keyAlgorithm = "RSA";
404409
+            this.type = T_UPDATE;
404409
+            buffer = new byte[1];
404409
+            break;
404409
+        case (int)CKM_SHA256_RSA_PKCS_PSS:
404409
+            mechParams = new CK_RSA_PKCS_PSS_PARAMS();
404409
+            mechParams.hashAlg = CKM_SHA256;
404409
+            mechParams.mgf = CKG_MGF1_SHA256;
404409
+            mechParams.sLen = 32;
404409
+            ckMechanism = new CK_MECHANISM(mechanism, mechParams);
404409
+            this.keyAlgorithm = "RSA";
404409
+            this.type = T_UPDATE;
404409
+            buffer = new byte[1];
404409
+            break;
404409
+        case (int)CKM_SHA384_RSA_PKCS_PSS:
404409
+            mechParams = new CK_RSA_PKCS_PSS_PARAMS();
404409
+            mechParams.hashAlg = CKM_SHA384;
404409
+            mechParams.mgf = CKG_MGF1_SHA384;
404409
+            mechParams.sLen = 48;
404409
+            ckMechanism = new CK_MECHANISM(mechanism, mechParams);
404409
+            this.keyAlgorithm = "RSA";
404409
+            this.type = T_UPDATE;
404409
+            buffer = new byte[1];
404409
+            break;
404409
+        case (int)CKM_SHA512_RSA_PKCS_PSS:
404409
+            mechParams = new CK_RSA_PKCS_PSS_PARAMS();
404409
+            mechParams.hashAlg = CKM_SHA512;
404409
+            mechParams.mgf = CKG_MGF1_SHA512;
404409
+            mechParams.sLen = 64;
404409
+            ckMechanism = new CK_MECHANISM(mechanism, mechParams);
404409
+            this.keyAlgorithm = "RSA";
404409
+            this.type = T_UPDATE;
404409
+            buffer = new byte[1];
404409
+            break;
404409
         case (int)CKM_MD2_RSA_PKCS:
404409
         case (int)CKM_MD5_RSA_PKCS:
404409
         case (int)CKM_SHA1_RSA_PKCS:
404409
@@ -232,6 +283,7 @@
404409
         default:
404409
             throw new ProviderException("Unknown mechanism: " + mechanism);
404409
         }
404409
+        this.mechanism = ckMechanism;
404409
         this.buffer = buffer;
404409
         this.digestOID = digestOID;
404409
         this.md = md;
404409
@@ -309,10 +361,10 @@
404409
             }
404409
             if (mode == M_SIGN) {
404409
                 token.p11.C_SignInit(session.id(),
404409
-                        new CK_MECHANISM(mechanism), p11Key.keyID);
404409
+                        mechanism, p11Key.keyID);
404409
             } else {
404409
                 token.p11.C_VerifyInit(session.id(),
404409
-                        new CK_MECHANISM(mechanism), p11Key.keyID);
404409
+                        mechanism, p11Key.keyID);
404409
             }
404409
             initialized = true;
404409
         } catch (PKCS11Exception e) {
404409
@@ -350,7 +402,8 @@
404409
         } else if (algorithm.equals("SHA512withRSA")) {
404409
             encodedLength = 83;
404409
         } else {
404409
-            throw new ProviderException("Unknown signature algo: " + algorithm);
404409
+            encodedLength = 0;
404409
+            //throw new ProviderException("Unknown signature algo: " + algorithm);
404409
         }
404409
         if (encodedLength > maxDataSize) {
404409
             throw new InvalidKeyException
404409
@@ -523,7 +576,7 @@
404409
                 if (type == T_DIGEST) {
404409
                     digest = md.digest();
404409
                 } else { // T_RAW
404409
-                    if (mechanism == CKM_DSA) {
404409
+                    if (mechanism.mechanism == CKM_DSA) {
404409
                         if (bytesProcessed != buffer.length) {
404409
                             throw new SignatureException
404409
                             ("Data for RawDSA must be exactly 20 bytes long");
404409
@@ -543,7 +596,7 @@
404409
                     signature = token.p11.C_Sign(session.id(), digest);
404409
                 } else { // RSA
404409
                     byte[] data = encodeSignature(digest);
404409
-                    if (mechanism == CKM_RSA_X_509) {
404409
+                    if (mechanism.mechanism == CKM_RSA_X_509) {
404409
                         data = pkcs1Pad(data);
404409
                     }
404409
                     signature = token.p11.C_Sign(session.id(), data);
404409
@@ -578,7 +631,7 @@
404409
                 if (type == T_DIGEST) {
404409
                     digest = md.digest();
404409
                 } else { // T_RAW
404409
-                    if (mechanism == CKM_DSA) {
404409
+                    if (mechanism.mechanism == CKM_DSA) {
404409
                         if (bytesProcessed != buffer.length) {
404409
                             throw new SignatureException
404409
                             ("Data for RawDSA must be exactly 20 bytes long");
404409
@@ -598,7 +651,7 @@
404409
                     token.p11.C_Verify(session.id(), digest, signature);
404409
                 } else { // RSA
404409
                     byte[] data = encodeSignature(digest);
404409
-                    if (mechanism == CKM_RSA_X_509) {
404409
+                    if (mechanism.mechanism == CKM_RSA_X_509) {
404409
                         data = pkcs1Pad(data);
404409
                     }
404409
                     token.p11.C_Verify(session.id(), data, signature);
404409
diff --git a/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/src/share/classes/sun/security/pkcs11/SunPKCS11.java
404409
--- openjdk/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
404409
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
404409
@@ -729,6 +729,16 @@
404409
         d(SIG, "SHA512withRSA", P11Signature,
404409
                 s("1.2.840.113549.1.1.13", "OID.1.2.840.113549.1.1.13"),
404409
                 m(CKM_SHA512_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509));
404409
+        d(SIG, "SHA1withRSAandMGF1", P11Signature,
404409
+                m(CKM_SHA1_RSA_PKCS_PSS));
404409
+        d(SIG, "SHA224withRSAandMGF1", P11Signature,
404409
+                m(CKM_SHA224_RSA_PKCS_PSS));
404409
+        d(SIG, "SHA256withRSAandMGF1", P11Signature,
404409
+                m(CKM_SHA256_RSA_PKCS_PSS));
404409
+        d(SIG, "SHA384withRSAandMGF1", P11Signature,
404409
+                m(CKM_SHA384_RSA_PKCS_PSS));
404409
+        d(SIG, "SHA512withRSAandMGF1", P11Signature,
404409
+                m(CKM_SHA512_RSA_PKCS_PSS));
404409
 
404409
         /*
404409
          * TLS 1.2 uses a different hash algorithm than 1.0/1.1 for the
404409
diff --git a/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java b/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
404409
--- openjdk/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
404409
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
404409
@@ -112,6 +112,10 @@
404409
         init(mechanism, params);
404409
     }
404409
 
404409
+    public CK_MECHANISM(long mechanism, CK_RSA_PKCS_PSS_PARAMS params) {
404409
+        init(mechanism, params);
404409
+    }
404409
+
404409
     public CK_MECHANISM(long mechanism, CK_SSL3_KEY_MAT_PARAMS params) {
404409
         init(mechanism, params);
404409
     }
404409
diff --git a/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java b/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
404409
--- openjdk/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
404409
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
404409
@@ -458,6 +458,12 @@
404409
     public static final long  CKM_SHA384_RSA_PKCS            = 0x00000041L;
404409
     public static final long  CKM_SHA512_RSA_PKCS            = 0x00000042L;
404409
 
404409
+    // v2.30
404409
+    public static final long  CKM_SHA256_RSA_PKCS_PSS        = 0x00000043L;
404409
+    public static final long  CKM_SHA384_RSA_PKCS_PSS        = 0x00000044L;
404409
+    public static final long  CKM_SHA512_RSA_PKCS_PSS        = 0x00000045L;
404409
+
404409
+
404409
     public static final long  CKM_RC2_KEY_GEN                = 0x00000100L;
404409
     public static final long  CKM_RC2_ECB                    = 0x00000101L;
404409
     public static final long  CKM_RC2_CBC                    = 0x00000102L;
404409
@@ -911,6 +917,10 @@
404409
 
404409
     /* The following MGFs are defined */
404409
     public static final long  CKG_MGF1_SHA1       =  0x00000001L;
404409
+    public static final long  CKG_MGF1_SHA256     =  0x00000002L;
404409
+    public static final long  CKG_MGF1_SHA384     =  0x00000003L;
404409
+    public static final long  CKG_MGF1_SHA512     =  0x00000004L;
404409
+
404409
     // new for v2.20 amendment 3
404409
     public static final long  CKG_MGF1_SHA224     = 0x00000005L;
404409
 
ac5d43
diff --git a/src/share/classes/sun/security/pkcs11/Token.java b/src/share/classes/sun/security/pkcs11/Token.java
ac5d43
--- openjdk/jdk/src/share/classes/sun/security/pkcs11/Token.java
ac5d43
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/Token.java
ac5d43
@@ -377,6 +377,10 @@
ac5d43
         return keyStore;
ac5d43
     }
ac5d43
 
ac5d43
+    CK_MECHANISM_INFO getMechanismInfo(CK_MECHANISM mechanism) throws PKCS11Exception {
ac5d43
+        return getMechanismInfo(mechanism.mechanism);
ac5d43
+    }
ac5d43
+
ac5d43
     CK_MECHANISM_INFO getMechanismInfo(long mechanism) throws PKCS11Exception {
ac5d43
         CK_MECHANISM_INFO result = mechInfoMap.get(mechanism);
ac5d43
         if (result == null) {