Remove unused JNI objects (#50224)
authorElinor Fung <elfung@microsoft.com>
Thu, 25 Mar 2021 22:43:44 +0000 (15:43 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Mar 2021 22:43:44 +0000 (23:43 +0100)
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_eckey.c
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_jni.c
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_jni.h

index e3e6542..73fb254 100644 (file)
@@ -137,6 +137,7 @@ EC_KEY* AndroidCryptoNative_EcKeyCreateByOid(const char* oid)
     }
 
     jobject curveParameters = (*env)->CallObjectMethod(env, keySpec, g_ECPublicKeySpecGetParams);
+    ReleaseLRef(env, keySpec);
     return AndroidCryptoNative_NewEcKey(ToGRef(env, curveParameters), ToGRef(env, keyPair));
 }
 
index c2fa8e2..f5f6819 100644 (file)
@@ -19,11 +19,6 @@ jclass    g_ThrowableClass;
 jmethodID g_ThrowableGetCause;
 jmethodID g_ThrowableGetMessage;
 
-// java/security/Key
-jclass    g_KeyClass;
-jmethodID g_KeyGetAlgorithm;
-jmethodID g_KeyGetEncoded;
-
 // java/security/SecureRandom
 jclass    g_randClass;
 jmethodID g_randCtor;
@@ -154,7 +149,6 @@ jmethodID g_CertFactoryGenerateCertificate;
 jmethodID g_CertFactoryGenerateCertificates;
 jmethodID g_CertFactoryGenerateCertPathFromList;
 jmethodID g_CertFactoryGenerateCertPathFromStream;
-jmethodID g_CertFactoryGenerateCRL;
 
 // java/security/cert/CertPath
 jclass    g_CertPathClass;
@@ -193,7 +187,6 @@ jclass    g_PKIXBuilderParametersClass;
 jmethodID g_PKIXBuilderParametersCtor;
 jmethodID g_PKIXBuilderParametersAddCertStore;
 jmethodID g_PKIXBuilderParametersAddCertPathChecker;
-jmethodID g_PKIXBuilderParametersSetCertPathCheckers;
 jmethodID g_PKIXBuilderParametersSetDate;
 jmethodID g_PKIXBuilderParametersSetRevocationEnabled;
 jmethodID g_PKIXBuilderParametersSetTrustAnchors;
@@ -212,10 +205,7 @@ jmethodID g_PKIXRevocationCheckerSetOptions;
 
 // java/security/cert/PKIXRevocationChecker$Option - only in API level 24+
 jclass    g_PKIXRevocationCheckerOptionClass;
-jfieldID  g_PKIXRevocationCheckerOptionNoFallback;
 jfieldID  g_PKIXRevocationCheckerOptionOnlyEndEntity;
-jfieldID  g_PKIXRevocationCheckerOptionPreferCrls;
-jfieldID  g_PKIXRevocationCheckerOptionSoftFail;
 
 // java/security/cert/TrustAnchor
 jclass    g_TrustAnchorClass;
@@ -355,7 +345,6 @@ jmethodID g_CollectionSize;
 // java/util/Date
 jclass    g_DateClass;
 jmethodID g_DateCtor;
-jmethodID g_DateGetTime;
 
 // java/util/Enumeration
 jclass    g_Enumeration;
@@ -376,10 +365,6 @@ jmethodID g_IteratorNext;
 jclass    g_ListClass;
 jmethodID g_ListGet;
 
-// java/util/Set
-jclass    g_SetClass;
-jmethodID g_SetIterator;
-
 // javax/net/ssl/SSLEngine
 jclass    g_SSLEngine;
 jmethodID g_SSLEngineSetUseClientModeMethod;
@@ -424,11 +409,6 @@ jmethodID g_SSLEngineResultGetHandshakeStatusMethod;
 // javax/net/ssl/TrustManager
 jclass    g_TrustManager;
 
-// javax/security/auth/x500/X500Principal
-jclass    g_X500PrincipalClass;
-jmethodID g_X500PrincipalGetEncoded;
-jmethodID g_X500PrincipalHashCode;
-
 // javax/crypto/KeyAgreement
 jclass    g_KeyAgreementClass;
 jmethodID g_KeyAgreementGetInstance;
@@ -626,10 +606,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
     g_ThrowableGetCause =   GetMethod(env, false, g_ThrowableClass, "getCause", "()Ljava/lang/Throwable;");
     g_ThrowableGetMessage = GetMethod(env, false, g_ThrowableClass, "getMessage", "()Ljava/lang/String;");
 
-    g_KeyClass =        GetClassGRef(env, "java/security/Key");
-    g_KeyGetAlgorithm = GetMethod(env, false, g_KeyClass, "getAlgorithm", "()Ljava/lang/String;");
-    g_KeyGetEncoded =   GetMethod(env, false, g_KeyClass, "getEncoded", "()[B");
-
     g_randClass =               GetClassGRef(env, "java/security/SecureRandom");
     g_randCtor =                GetMethod(env, false, g_randClass, "<init>", "()V");
     g_randNextBytesMethod =     GetMethod(env, false, g_randClass, "nextBytes", "([B)V");
@@ -692,7 +668,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
     g_CertFactoryGenerateCertificates =         GetMethod(env, false, g_CertFactoryClass, "generateCertificates", "(Ljava/io/InputStream;)Ljava/util/Collection;");
     g_CertFactoryGenerateCertPathFromList =     GetMethod(env, false, g_CertFactoryClass, "generateCertPath", "(Ljava/util/List;)Ljava/security/cert/CertPath;");
     g_CertFactoryGenerateCertPathFromStream =   GetMethod(env, false, g_CertFactoryClass, "generateCertPath", "(Ljava/io/InputStream;Ljava/lang/String;)Ljava/security/cert/CertPath;");
-    g_CertFactoryGenerateCRL =                  GetMethod(env, false, g_CertFactoryClass, "generateCRL", "(Ljava/io/InputStream;)Ljava/security/cert/CRL;");
 
     g_CertPathClass =           GetClassGRef(env, "java/security/cert/CertPath");
     g_CertPathGetEncoded =      GetMethod(env, false, g_CertPathClass, "getEncoded", "(Ljava/lang/String;)[B");
@@ -723,7 +698,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
     g_PKIXBuilderParametersCtor =                   GetMethod(env, false, g_PKIXBuilderParametersClass, "<init>", "(Ljava/security/KeyStore;Ljava/security/cert/CertSelector;)V");
     g_PKIXBuilderParametersAddCertStore =           GetMethod(env, false, g_PKIXBuilderParametersClass, "addCertStore", "(Ljava/security/cert/CertStore;)V");
     g_PKIXBuilderParametersAddCertPathChecker =     GetMethod(env, false, g_PKIXBuilderParametersClass, "addCertPathChecker", "(Ljava/security/cert/PKIXCertPathChecker;)V");
-    g_PKIXBuilderParametersSetCertPathCheckers =    GetMethod(env, false, g_PKIXBuilderParametersClass, "setCertPathCheckers", "(Ljava/util/List;)V");
     g_PKIXBuilderParametersSetDate =                GetMethod(env, false, g_PKIXBuilderParametersClass, "setDate", "(Ljava/util/Date;)V");
     g_PKIXBuilderParametersSetRevocationEnabled =   GetMethod(env, false, g_PKIXBuilderParametersClass, "setRevocationEnabled", "(Z)V");
     g_PKIXBuilderParametersSetTrustAnchors =        GetMethod(env, false, g_PKIXBuilderParametersClass, "setTrustAnchors", "(Ljava/util/Set;)V");
@@ -740,10 +714,7 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
         g_PKIXRevocationCheckerSetOptions =             GetMethod(env, false, g_PKIXRevocationCheckerClass, "setOptions", "(Ljava/util/Set;)V");
 
         g_PKIXRevocationCheckerOptionClass =            GetClassGRef(env, "java/security/cert/PKIXRevocationChecker$Option");
-        g_PKIXRevocationCheckerOptionNoFallback =       GetField(env, true, g_PKIXRevocationCheckerOptionClass, "NO_FALLBACK", "Ljava/security/cert/PKIXRevocationChecker$Option;");
         g_PKIXRevocationCheckerOptionOnlyEndEntity =    GetField(env, true, g_PKIXRevocationCheckerOptionClass, "ONLY_END_ENTITY", "Ljava/security/cert/PKIXRevocationChecker$Option;");
-        g_PKIXRevocationCheckerOptionPreferCrls =       GetField(env, true, g_PKIXRevocationCheckerOptionClass, "PREFER_CRLS", "Ljava/security/cert/PKIXRevocationChecker$Option;");
-        g_PKIXRevocationCheckerOptionSoftFail =         GetField(env, true, g_PKIXRevocationCheckerOptionClass, "SOFT_FAIL", "Ljava/security/cert/PKIXRevocationChecker$Option;");
     }
 
     g_TrustAnchorClass =            GetClassGRef(env, "java/security/cert/TrustAnchor");
@@ -906,7 +877,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
 
     g_DateClass =   GetClassGRef(env, "java/util/Date");
     g_DateCtor =    GetMethod(env, false, g_DateClass, "<init>", "(J)V");
-    g_DateGetTime = GetMethod(env, false, g_DateClass, "getTime", "()J");
 
     g_Enumeration =                 GetClassGRef(env, "java/util/Enumeration");
     g_EnumerationHasMoreElements =  GetMethod(env, false, g_Enumeration, "hasMoreElements", "()Z");
@@ -923,9 +893,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
     g_ListClass =   GetClassGRef(env, "java/util/List");
     g_ListGet =     GetMethod(env, false, g_ListClass, "get", "(I)Ljava/lang/Object;");
 
-    g_SetClass =    GetClassGRef(env, "java/util/Set");
-    g_SetIterator = GetMethod(env, false, g_SetClass, "iterator", "()Ljava/util/Iterator;");
-
     g_SSLEngine =                         GetClassGRef(env, "javax/net/ssl/SSLEngine");
     g_SSLEngineSetUseClientModeMethod =   GetMethod(env, false, g_SSLEngine, "setUseClientMode", "(Z)V");
     g_SSLEngineGetSessionMethod =         GetMethod(env, false, g_SSLEngine, "getSession", "()Ljavax/net/ssl/SSLSession;");
@@ -964,10 +931,6 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
 
     g_TrustManager =                             GetClassGRef(env, "javax/net/ssl/TrustManager");
 
-    g_X500PrincipalClass =      GetClassGRef(env, "javax/security/auth/x500/X500Principal");
-    g_X500PrincipalGetEncoded = GetMethod(env, false, g_X500PrincipalClass, "getEncoded", "()[B");
-    g_X500PrincipalHashCode =   GetMethod(env, false, g_X500PrincipalClass, "hashCode", "()I");
-
     g_KeyAgreementClass          = GetClassGRef(env, "javax/crypto/KeyAgreement");
     g_KeyAgreementGetInstance    = GetMethod(env, true, g_KeyAgreementClass, "getInstance", "(Ljava/lang/String;)Ljavax/crypto/KeyAgreement;");
     g_KeyAgreementInit           = GetMethod(env, false, g_KeyAgreementClass, "init", "(Ljava/security/Key;)V");
index c8135f6..1414e74 100644 (file)
@@ -28,11 +28,6 @@ extern jclass    g_ThrowableClass;
 extern jmethodID g_ThrowableGetCause;
 extern jmethodID g_ThrowableGetMessage;
 
-// java/security/Key
-extern jclass    g_KeyClass;
-extern jmethodID g_KeyGetAlgorithm;
-extern jmethodID g_KeyGetEncoded;
-
 // java/security/SecureRandom
 extern jclass    g_randClass;
 extern jmethodID g_randCtor;
@@ -106,7 +101,6 @@ extern jmethodID g_CertFactoryGenerateCertificate;
 extern jmethodID g_CertFactoryGenerateCertificates;
 extern jmethodID g_CertFactoryGenerateCertPathFromList;
 extern jmethodID g_CertFactoryGenerateCertPathFromStream;
-extern jmethodID g_CertFactoryGenerateCRL;
 
 // java/security/cert/CertPath
 extern jclass    g_CertPathClass;
@@ -145,7 +139,6 @@ extern jclass    g_PKIXBuilderParametersClass;
 extern jmethodID g_PKIXBuilderParametersCtor;
 extern jmethodID g_PKIXBuilderParametersAddCertStore;
 extern jmethodID g_PKIXBuilderParametersAddCertPathChecker;
-extern jmethodID g_PKIXBuilderParametersSetCertPathCheckers;
 extern jmethodID g_PKIXBuilderParametersSetDate;
 extern jmethodID g_PKIXBuilderParametersSetRevocationEnabled;
 extern jmethodID g_PKIXBuilderParametersSetTrustAnchors;
@@ -164,10 +157,7 @@ extern jmethodID g_PKIXRevocationCheckerSetOptions;
 
 // java/security/cert/PKIXRevocationChecker$Option - only in API level 24+
 extern jclass    g_PKIXRevocationCheckerOptionClass;
-extern jfieldID  g_PKIXRevocationCheckerOptionNoFallback;
 extern jfieldID  g_PKIXRevocationCheckerOptionOnlyEndEntity;
-extern jfieldID  g_PKIXRevocationCheckerOptionPreferCrls;
-extern jfieldID  g_PKIXRevocationCheckerOptionSoftFail;
 
 // java/security/cert/TrustAnchor
 extern jclass    g_TrustAnchorClass;
@@ -364,7 +354,6 @@ extern jmethodID g_CollectionSize;
 // java/util/Date
 extern jclass    g_DateClass;
 extern jmethodID g_DateCtor;
-extern jmethodID g_DateGetTime;
 
 // java/util/Enumeration
 extern jclass    g_Enumeration;
@@ -385,10 +374,6 @@ extern jmethodID g_IteratorNext;
 extern jclass    g_ListClass;
 extern jmethodID g_ListGet;
 
-// java/util/Set
-extern jclass    g_SetClass;
-extern jmethodID g_SetIterator;
-
 // javax/net/ssl/SSLEngine
 extern jclass    g_SSLEngine;
 extern jmethodID g_SSLEngineSetUseClientModeMethod;
@@ -433,11 +418,6 @@ extern jmethodID g_SSLEngineResultGetHandshakeStatusMethod;
 // javax/net/ssl/TrustManager
 extern jclass    g_TrustManager;
 
-// javax/security/auth/x500/X500Principal
-extern jclass    g_X500PrincipalClass;
-extern jmethodID g_X500PrincipalGetEncoded;
-extern jmethodID g_X500PrincipalHashCode;
-
 // javax/crypto/KeyAgreement
 extern jclass    g_KeyAgreementClass;
 extern jmethodID g_KeyAgreementGetInstance;