提交 d4150ac6 编写于 作者: V vinnie

8036612: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/mscapi/security.cpp

Reviewed-by: valeriep
上级 02615e3f
/* /*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -74,7 +74,10 @@ ALG_ID MapHashAlgorithm(JNIEnv *env, jstring jHashAlgorithm) { ...@@ -74,7 +74,10 @@ ALG_ID MapHashAlgorithm(JNIEnv *env, jstring jHashAlgorithm) {
const char* pszHashAlgorithm = NULL; const char* pszHashAlgorithm = NULL;
ALG_ID algId = 0; ALG_ID algId = 0;
pszHashAlgorithm = env->GetStringUTFChars(jHashAlgorithm, NULL); if ((pszHashAlgorithm = env->GetStringUTFChars(jHashAlgorithm, NULL))
== NULL) {
return algId;
}
if ((strcmp("SHA", pszHashAlgorithm) == 0) || if ((strcmp("SHA", pszHashAlgorithm) == 0) ||
(strcmp("SHA1", pszHashAlgorithm) == 0) || (strcmp("SHA1", pszHashAlgorithm) == 0) ||
...@@ -179,7 +182,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_PRNG_generateSeed ...@@ -179,7 +182,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_PRNG_generateSeed
*/ */
if (length < 0) { if (length < 0) {
length = env->GetArrayLength(seed); length = env->GetArrayLength(seed);
reseedBytes = env->GetByteArrayElements(seed, 0); if ((reseedBytes = env->GetByteArrayElements(seed, 0)) == NULL) {
__leave;
}
if (::CryptGenRandom( if (::CryptGenRandom(
hCryptProv, hCryptProv,
...@@ -211,7 +216,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_PRNG_generateSeed ...@@ -211,7 +216,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_PRNG_generateSeed
} else { // length == 0 } else { // length == 0
length = env->GetArrayLength(seed); length = env->GetArrayLength(seed);
seedBytes = env->GetByteArrayElements(seed, 0); if ((seedBytes = env->GetByteArrayElements(seed, 0)) == NULL) {
__leave;
}
if (::CryptGenRandom( if (::CryptGenRandom(
hCryptProv, hCryptProv,
...@@ -275,7 +282,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh ...@@ -275,7 +282,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh
__try __try
{ {
// Open a system certificate store. // Open a system certificate store.
pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL); if ((pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL))
== NULL) {
__leave;
}
if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName))
== NULL) { == NULL) {
...@@ -710,7 +720,10 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_RSAKeyPairGenerator_generateR ...@@ -710,7 +720,10 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_RSAKeyPairGenerator_generateR
__try __try
{ {
pszKeyContainerName = env->GetStringUTFChars(keyContainerName, NULL); if ((pszKeyContainerName =
env->GetStringUTFChars(keyContainerName, NULL)) == NULL) {
__leave;
}
// Acquire a CSP context (create a new key container). // Acquire a CSP context (create a new key container).
// Prefer a PROV_RSA_AES CSP, when available, due to its support // Prefer a PROV_RSA_AES CSP, when available, due to its support
...@@ -847,7 +860,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate ...@@ -847,7 +860,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
__try __try
{ {
// Open a system certificate store. // Open a system certificate store.
pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL); if ((pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL))
== NULL) {
__leave;
}
if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) { if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) {
ThrowException(env, KEYSTORE_EXCEPTION, GetLastError()); ThrowException(env, KEYSTORE_EXCEPTION, GetLastError());
__leave; __leave;
...@@ -1086,7 +1102,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate ...@@ -1086,7 +1102,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate
__try __try
{ {
// Open a system certificate store. // Open a system certificate store.
pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL); if ((pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL))
== NULL) {
__leave;
}
if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) { if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) {
ThrowException(env, KEYSTORE_EXCEPTION, GetLastError()); ThrowException(env, KEYSTORE_EXCEPTION, GetLastError());
__leave; __leave;
...@@ -1123,7 +1142,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate ...@@ -1123,7 +1142,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_removeCertificate
cchNameString); cchNameString);
// Compare the certificate's friendly name with supplied alias name // Compare the certificate's friendly name with supplied alias name
pszCertAliasName = env->GetStringUTFChars(jCertAliasName, NULL); if ((pszCertAliasName = env->GetStringUTFChars(jCertAliasName, NULL))
== NULL) {
__leave;
}
if (strcmp(pszCertAliasName, pszNameString) == 0) { if (strcmp(pszCertAliasName, pszNameString) == 0) {
// Only delete the certificate if the alias names matches // Only delete the certificate if the alias names matches
...@@ -1181,7 +1203,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_destroyKeyContainer ...@@ -1181,7 +1203,10 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_destroyKeyContainer
__try __try
{ {
pszKeyContainerName = env->GetStringUTFChars(keyContainerName, NULL); if ((pszKeyContainerName =
env->GetStringUTFChars(keyContainerName, NULL)) == NULL) {
__leave;
}
// Destroying the default key container is not permitted // Destroying the default key container is not permitted
// (because it may contain more one keypair). // (because it may contain more one keypair).
...@@ -1234,8 +1259,14 @@ JNIEXPORT jlong JNICALL Java_sun_security_mscapi_RSACipher_findCertificateUsingA ...@@ -1234,8 +1259,14 @@ JNIEXPORT jlong JNICALL Java_sun_security_mscapi_RSACipher_findCertificateUsingA
__try __try
{ {
pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL); if ((pszCertStoreName = env->GetStringUTFChars(jCertStoreName, NULL))
pszCertAliasName = env->GetStringUTFChars(jCertAliasName, NULL); == NULL) {
__leave;
}
if ((pszCertAliasName = env->GetStringUTFChars(jCertAliasName, NULL))
== NULL) {
__leave;
}
// Open a system certificate store. // Open a system certificate store.
if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) { if ((hCertStore = ::CertOpenSystemStore(NULL, pszCertStoreName)) == NULL) {
...@@ -1530,7 +1561,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getExponent ...@@ -1530,7 +1561,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getExponent
__try { __try {
jsize length = env->GetArrayLength(jKeyBlob); jsize length = env->GetArrayLength(jKeyBlob);
keyBlob = env->GetByteArrayElements(jKeyBlob, 0); if ((keyBlob = env->GetByteArrayElements(jKeyBlob, 0)) == NULL) {
__leave;
}
PUBLICKEYSTRUC* pPublicKeyStruc = (PUBLICKEYSTRUC *) keyBlob; PUBLICKEYSTRUC* pPublicKeyStruc = (PUBLICKEYSTRUC *) keyBlob;
...@@ -1580,7 +1613,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getModulus ...@@ -1580,7 +1613,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getModulus
__try { __try {
jsize length = env->GetArrayLength(jKeyBlob); jsize length = env->GetArrayLength(jKeyBlob);
keyBlob = env->GetByteArrayElements(jKeyBlob, 0); if ((keyBlob = env->GetByteArrayElements(jKeyBlob, 0)) == NULL) {
__leave;
}
PUBLICKEYSTRUC* pPublicKeyStruc = (PUBLICKEYSTRUC *) keyBlob; PUBLICKEYSTRUC* pPublicKeyStruc = (PUBLICKEYSTRUC *) keyBlob;
...@@ -1632,6 +1667,9 @@ int convertToLittleEndian(JNIEnv *env, jbyteArray source, jbyte* destination, ...@@ -1632,6 +1667,9 @@ int convertToLittleEndian(JNIEnv *env, jbyteArray source, jbyte* destination,
} }
jbyte* sourceBytes = env->GetByteArrayElements(source, 0); jbyte* sourceBytes = env->GetByteArrayElements(source, 0);
if (sourceBytes == NULL) {
return -1;
}
// Copy bytes from the end of the source array to the beginning of the // Copy bytes from the end of the source array to the beginning of the
// destination array (until the destination array is full). // destination array (until the destination array is full).
...@@ -1740,45 +1778,61 @@ jbyteArray generateKeyBlob( ...@@ -1740,45 +1778,61 @@ jbyteArray generateKeyBlob(
} }
// The length argument must be the smaller of jPublicExponentLength // The length argument must be the smaller of jPublicExponentLength
// and sizeof(pRsaPubKey->pubkey) // and sizeof(pRsaPubKey->pubkey)
convertToLittleEndian(env, jPublicExponent, if ((jElementLength = convertToLittleEndian(env, jPublicExponent,
(jbyte *) &(pRsaPubKey->pubexp), jPublicExponentLength); (jbyte *) &(pRsaPubKey->pubexp), jPublicExponentLength)) < 0) {
__leave;
}
// Modulus n // Modulus n
jBlobElement = jBlobElement =
(jbyte *) (jBlobBytes + sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY)); (jbyte *) (jBlobBytes + sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY));
jElementLength = convertToLittleEndian(env, jModulus, jBlobElement, if ((jElementLength = convertToLittleEndian(env, jModulus, jBlobElement,
jKeyByteLength); jKeyByteLength)) < 0) {
__leave;
}
if (bGeneratePrivateKeyBlob) { if (bGeneratePrivateKeyBlob) {
// Prime p // Prime p
jBlobElement += jElementLength; jBlobElement += jElementLength;
jElementLength = convertToLittleEndian(env, jPrimeP, jBlobElement, if ((jElementLength = convertToLittleEndian(env, jPrimeP,
jKeyByteLength / 2); jBlobElement, jKeyByteLength / 2)) < 0) {
__leave;
}
// Prime q // Prime q
jBlobElement += jElementLength; jBlobElement += jElementLength;
jElementLength = convertToLittleEndian(env, jPrimeQ, jBlobElement, if ((jElementLength = convertToLittleEndian(env, jPrimeQ,
jKeyByteLength / 2); jBlobElement, jKeyByteLength / 2)) < 0) {
__leave;
}
// Prime exponent p // Prime exponent p
jBlobElement += jElementLength; jBlobElement += jElementLength;
jElementLength = convertToLittleEndian(env, jExponentP, if ((jElementLength = convertToLittleEndian(env, jExponentP,
jBlobElement, jKeyByteLength / 2); jBlobElement, jKeyByteLength / 2)) < 0) {
__leave;
}
// Prime exponent q // Prime exponent q
jBlobElement += jElementLength; jBlobElement += jElementLength;
jElementLength = convertToLittleEndian(env, jExponentQ, if ((jElementLength = convertToLittleEndian(env, jExponentQ,
jBlobElement, jKeyByteLength / 2); jBlobElement, jKeyByteLength / 2)) < 0) {
__leave;
}
// CRT coefficient // CRT coefficient
jBlobElement += jElementLength; jBlobElement += jElementLength;
jElementLength = convertToLittleEndian(env, jCrtCoefficient, if ((jElementLength = convertToLittleEndian(env, jCrtCoefficient,
jBlobElement, jKeyByteLength / 2); jBlobElement, jKeyByteLength / 2)) < 0) {
__leave;
}
// Private exponent // Private exponent
jBlobElement += jElementLength; jBlobElement += jElementLength;
convertToLittleEndian(env, jPrivateExponent, jBlobElement, if ((jElementLength = convertToLittleEndian(env, jPrivateExponent,
jKeyByteLength); jBlobElement, jKeyByteLength)) < 0) {
__leave;
}
} }
jBlob = env->NewByteArray(jBlobLength); jBlob = env->NewByteArray(jBlobLength);
...@@ -1849,9 +1903,15 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_KeyStore_storePrivateKey ...@@ -1849,9 +1903,15 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_KeyStore_storePrivateKey
__try __try
{ {
pszKeyContainerName = env->GetStringUTFChars(keyContainerName, NULL); if ((pszKeyContainerName =
env->GetStringUTFChars(keyContainerName, NULL)) == NULL) {
__leave;
}
dwBlobLen = env->GetArrayLength(keyBlob); dwBlobLen = env->GetArrayLength(keyBlob);
pbKeyBlob = (BYTE *) env->GetByteArrayElements(keyBlob, 0); if ((pbKeyBlob = (BYTE *) env->GetByteArrayElements(keyBlob, 0))
== NULL) {
__leave;
}
// Acquire a CSP context (create a new key container). // Acquire a CSP context (create a new key container).
if (::CryptAcquireContext( if (::CryptAcquireContext(
...@@ -1923,7 +1983,10 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_RSASignature_importPublicKey ...@@ -1923,7 +1983,10 @@ JNIEXPORT jobject JNICALL Java_sun_security_mscapi_RSASignature_importPublicKey
__try __try
{ {
dwBlobLen = env->GetArrayLength(keyBlob); dwBlobLen = env->GetArrayLength(keyBlob);
pbKeyBlob = (BYTE *) env->GetByteArrayElements(keyBlob, 0); if ((pbKeyBlob = (BYTE *) env->GetByteArrayElements(keyBlob, 0))
== NULL) {
__leave;
}
// Acquire a CSP context (create a new key container). // Acquire a CSP context (create a new key container).
// Prefer a PROV_RSA_AES CSP, when available, due to its support // Prefer a PROV_RSA_AES CSP, when available, due to its support
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册