Blame SOURCES/pr2815.patch

045ef6
# HG changeset patch
045ef6
# User andrew
045ef6
# Date 1453867347 0
045ef6
#      Wed Jan 27 04:02:27 2016 +0000
045ef6
# Node ID 26e2e029ee256e9815fdc324831a03d8582255e1
045ef6
# Parent  0ff7720931e8dbf7de25720bdc93b18527ab89e8
045ef6
PR2815: Race condition in SunEC provider with system NSS
045ef6
Summary: Perform initialisation and shutdown only when library is loaded or SunEC is finalized respectively
045ef6
045ef6
diff -r 0ff7720931e8 -r 26e2e029ee25 make/mapfiles/libsunec/mapfile-vers
045ef6
--- openjdk/jdk/make/mapfiles/libsunec/mapfile-vers	Wed Jan 27 03:45:06 2016 +0000
045ef6
+++ openjdk/jdk/make/mapfiles/libsunec/mapfile-vers	Wed Jan 27 04:02:27 2016 +0000
045ef6
@@ -31,6 +31,8 @@
045ef6
                 Java_sun_security_ec_ECDSASignature_signDigest;
045ef6
                 Java_sun_security_ec_ECDSASignature_verifySignedDigest;
045ef6
                 Java_sun_security_ec_ECDHKeyAgreement_deriveKey;
045ef6
+		Java_sun_security_ec_SunEC_initialize;
045ef6
+		Java_sun_security_ec_SunEC_cleanup;
045ef6
         local:
045ef6
                 *;
045ef6
 };
045ef6
diff -r 0ff7720931e8 -r 26e2e029ee25 src/share/classes/sun/security/ec/SunEC.java
045ef6
--- openjdk/jdk/src/share/classes/sun/security/ec/SunEC.java	Wed Jan 27 03:45:06 2016 +0000
045ef6
+++ openjdk/jdk/src/share/classes/sun/security/ec/SunEC.java	Wed Jan 27 04:02:27 2016 +0000
045ef6
@@ -58,6 +58,7 @@
045ef6
             AccessController.doPrivileged(new PrivilegedAction<Void>() {
045ef6
                 public Void run() {
045ef6
                     System.loadLibrary("sunec"); // check for native library
045ef6
+                    initialize();
045ef6
                     return null;
045ef6
                 }
045ef6
             });
045ef6
@@ -81,4 +82,22 @@
045ef6
         }
045ef6
     }
045ef6
 
045ef6
+    /**
045ef6
+     * Cleanup native resources during finalisation.
045ef6
+     */
045ef6
+    @Override
045ef6
+    protected void finalize() {
045ef6
+        cleanup();
045ef6
+    }
045ef6
+
045ef6
+    /**
045ef6
+     * Initialize the native code.
045ef6
+     */
045ef6
+    private static native void initialize();
045ef6
+
045ef6
+    /**
045ef6
+     * Cleanup in the native layer.
045ef6
+     */
045ef6
+    private static native void cleanup();
045ef6
+
045ef6
 }
045ef6
diff -r 0ff7720931e8 -r 26e2e029ee25 src/share/native/sun/security/ec/ECC_JNI.cpp
045ef6
--- openjdk/jdk/src/share/native/sun/security/ec/ECC_JNI.cpp	Wed Jan 27 03:45:06 2016 +0000
045ef6
+++ openjdk/jdk/src/share/native/sun/security/ec/ECC_JNI.cpp	Wed Jan 27 04:02:27 2016 +0000
045ef6
@@ -121,13 +121,6 @@
045ef6
         goto cleanup;
045ef6
     }
045ef6
 
045ef6
-#ifdef SYSTEM_NSS
045ef6
-    if (SECOID_Init() != SECSuccess) {
045ef6
-	ThrowException(env, INTERNAL_ERROR);
045ef6
-	goto cleanup;
045ef6
-    }
045ef6
-#endif
045ef6
-
045ef6
     // Fill a new ECParams using the supplied OID
045ef6
     if (EC_DecodeParams(&params_item, &ecparams, 0) != SECSuccess) {
045ef6
         /* bad curve OID */
045ef6
@@ -183,11 +176,6 @@
045ef6
         if (params_item.data) {
045ef6
             env->ReleaseByteArrayElements(encodedParams,
045ef6
                 (jbyte *) params_item.data, JNI_ABORT);
045ef6
-#ifdef SYSTEM_NSS
045ef6
-	    if (SECOID_Shutdown() != SECSuccess) {
045ef6
-		ThrowException(env, INTERNAL_ERROR);
045ef6
-	    }
045ef6
-#endif
045ef6
         }
045ef6
         if (ecparams) {
045ef6
             FreeECParams(ecparams, true);
045ef6
@@ -253,13 +241,6 @@
045ef6
         goto cleanup;
045ef6
     }
045ef6
 
045ef6
-#ifdef SYSTEM_NSS
045ef6
-    if (SECOID_Init() != SECSuccess) {
045ef6
-	ThrowException(env, INTERNAL_ERROR);
045ef6
-	goto cleanup;
045ef6
-    }
045ef6
-#endif
045ef6
-
045ef6
     // Fill a new ECParams using the supplied OID
045ef6
     if (EC_DecodeParams(&params_item, &ecparams, 0) != SECSuccess) {
045ef6
         /* bad curve OID */
045ef6
@@ -307,11 +288,6 @@
045ef6
         if (params_item.data) {
045ef6
             env->ReleaseByteArrayElements(encodedParams,
045ef6
                 (jbyte *) params_item.data, JNI_ABORT);
045ef6
-#ifdef SYSTEM_NSS
045ef6
-	    if (SECOID_Shutdown() != SECSuccess) {
045ef6
-		ThrowException(env, INTERNAL_ERROR);
045ef6
-	    }
045ef6
-#endif
045ef6
         }
045ef6
         if (privKey.privateValue.data) {
045ef6
             env->ReleaseByteArrayElements(privateKey,
045ef6
@@ -378,13 +354,6 @@
045ef6
         goto cleanup;
045ef6
     }
045ef6
 
045ef6
-#ifdef SYSTEM_NSS
045ef6
-    if (SECOID_Init() != SECSuccess) {
045ef6
-	ThrowException(env, INTERNAL_ERROR);
045ef6
-	goto cleanup;
045ef6
-    }
045ef6
-#endif
045ef6
-
045ef6
     // Fill a new ECParams using the supplied OID
045ef6
     if (EC_DecodeParams(&params_item, &ecparams, 0) != SECSuccess) {
045ef6
         /* bad curve OID */
045ef6
@@ -408,11 +377,6 @@
045ef6
         if (params_item.data) {
045ef6
             env->ReleaseByteArrayElements(encodedParams,
045ef6
                 (jbyte *) params_item.data, JNI_ABORT);
045ef6
-#ifdef SYSTEM_NSS
045ef6
-	    if (SECOID_Shutdown() != SECSuccess) {
045ef6
-		ThrowException(env, INTERNAL_ERROR);
045ef6
-	    }
045ef6
-#endif
045ef6
 	}
045ef6
 
045ef6
         if (pubKey.publicValue.data)
045ef6
@@ -474,13 +438,6 @@
045ef6
         goto cleanup;
045ef6
     }
045ef6
 
045ef6
-#ifdef SYSTEM_NSS
045ef6
-    if (SECOID_Init() != SECSuccess) {
045ef6
-	ThrowException(env, INTERNAL_ERROR);
045ef6
-	goto cleanup;
045ef6
-    }
045ef6
-#endif
045ef6
-
045ef6
     // Fill a new ECParams using the supplied OID
045ef6
     if (EC_DecodeParams(&params_item, &ecparams, 0) != SECSuccess) {
045ef6
         /* bad curve OID */
045ef6
@@ -525,11 +482,6 @@
045ef6
         if (params_item.data) {
045ef6
             env->ReleaseByteArrayElements(encodedParams,
045ef6
                 (jbyte *) params_item.data, JNI_ABORT);
045ef6
-#ifdef SYSTEM_NSS
045ef6
-	    if (SECOID_Shutdown() != SECSuccess) {
045ef6
-		ThrowException(env, INTERNAL_ERROR);
045ef6
-	    }
045ef6
-#endif
045ef6
 	}
045ef6
 
045ef6
         if (ecparams)
045ef6
@@ -539,4 +491,26 @@
045ef6
     return jSecret;
045ef6
 }
045ef6
 
045ef6
+JNIEXPORT void
045ef6
+JNICALL Java_sun_security_ec_SunEC_initialize
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz))
045ef6
+{
045ef6
+#ifdef SYSTEM_NSS
045ef6
+    if (SECOID_Init() != SECSuccess) {
045ef6
+	ThrowException(env, INTERNAL_ERROR);
045ef6
+    }
045ef6
+#endif
045ef6
+}
045ef6
+
045ef6
+JNIEXPORT void
045ef6
+JNICALL Java_sun_security_ec_SunEC_cleanup
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz))
045ef6
+{
045ef6
+#ifdef SYSTEM_NSS
045ef6
+    if (SECOID_Shutdown() != SECSuccess) {
045ef6
+	ThrowException(env, INTERNAL_ERROR);
045ef6
+    }
045ef6
+#endif
045ef6
+}
045ef6
+
045ef6
 } /* extern "C" */