1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.org.conscrypt; 19 20 import java.security.Provider; 21 22 /** 23 * Provider that uses BoringSSL to perform the actual cryptographic operations. 24 * <p> 25 * Every algorithm should have its IANA assigned OID as an alias. See the following URLs for each 26 * type: <ul> <li><a 27 * href="http://www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xml">Hash 28 * functions</a></li> <li><a href="http://www.iana.org/assignments/dssc/dssc.xml">Signature 29 * algorithms</a></li> <li><a 30 * href="http://csrc.nist.gov/groups/ST/crypto_apps_infra/csor/algorithms.html">NIST cryptographic 31 * algorithms</a></li> 32 * </ul> 33 * @hide This class is not part of the Android public SDK API 34 */ 35 @libcore.api.CorePlatformApi 36 @Internal 37 public final class OpenSSLProvider extends Provider { 38 private static final long serialVersionUID = 2996752495318905136L; 39 40 private static final String PREFIX = OpenSSLProvider.class.getPackage().getName() + "."; 41 42 private static final String STANDARD_EC_PRIVATE_KEY_INTERFACE_CLASS_NAME = 43 "java.security.interfaces.ECPrivateKey"; 44 private static final String STANDARD_RSA_PRIVATE_KEY_INTERFACE_CLASS_NAME = 45 "java.security.interfaces.RSAPrivateKey"; 46 private static final String STANDARD_RSA_PUBLIC_KEY_INTERFACE_CLASS_NAME = 47 "java.security.interfaces.RSAPublicKey"; 48 49 @dalvik.annotation.compat.UnsupportedAppUsage 50 @libcore.api.CorePlatformApi OpenSSLProvider()51 public OpenSSLProvider() { 52 this(Platform.getDefaultProviderName()); 53 } 54 OpenSSLProvider(String providerName)55 public OpenSSLProvider(String providerName) { 56 this(providerName, Platform.provideTrustManagerByDefault()); 57 } 58 OpenSSLProvider(String providerName, boolean includeTrustManager)59 OpenSSLProvider(String providerName, boolean includeTrustManager) { 60 super(providerName, 1.0, "Android's OpenSSL-backed security provider"); 61 62 // Ensure that the native library has been loaded. 63 NativeCrypto.checkAvailability(); 64 65 // Make sure the platform is initialized. 66 Platform.setup(); 67 68 /* === SSL Contexts === */ 69 final String classOpenSSLContextImpl = PREFIX + "OpenSSLContextImpl"; 70 final String tls13SSLContext = classOpenSSLContextImpl + "$TLSv13"; 71 // Keep SSL as an alias to TLS 72 put("SSLContext.SSL", tls13SSLContext); 73 put("SSLContext.TLS", tls13SSLContext); 74 put("SSLContext.TLSv1", classOpenSSLContextImpl + "$TLSv1"); 75 put("SSLContext.TLSv1.1", classOpenSSLContextImpl + "$TLSv11"); 76 put("SSLContext.TLSv1.2", classOpenSSLContextImpl + "$TLSv12"); 77 put("SSLContext.TLSv1.3", tls13SSLContext); 78 put("SSLContext.Default", PREFIX + "DefaultSSLContextImpl"); 79 80 if (includeTrustManager) { 81 put("TrustManagerFactory.PKIX", TrustManagerFactoryImpl.class.getName()); 82 put("Alg.Alias.TrustManagerFactory.X509", "PKIX"); 83 } 84 85 /* === AlgorithmParameters === */ 86 put("AlgorithmParameters.AES", PREFIX + "IvParameters$AES"); 87 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.2", "AES"); 88 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.22", "AES"); 89 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.42", "AES"); 90 91 put("AlgorithmParameters.ChaCha20", PREFIX + "IvParameters$ChaCha20"); 92 93 put("AlgorithmParameters.DESEDE", PREFIX + "IvParameters$DESEDE"); 94 put("Alg.Alias.AlgorithmParameters.TDEA", "DESEDE"); 95 put("Alg.Alias.AlgorithmParameters.1.2.840.113549.3.7", "DESEDE"); 96 97 put("AlgorithmParameters.GCM", PREFIX + "GCMParameters"); 98 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.6", "GCM"); 99 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.26", "GCM"); 100 put("Alg.Alias.AlgorithmParameters.2.16.840.1.101.3.4.1.46", "GCM"); 101 put("AlgorithmParameters.OAEP", PREFIX + "OAEPParameters"); 102 put("AlgorithmParameters.PSS", PREFIX + "PSSParameters"); 103 put("AlgorithmParameters.EC", PREFIX + "ECParameters"); 104 105 /* === Message Digests === */ 106 put("MessageDigest.SHA-1", PREFIX + "OpenSSLMessageDigestJDK$SHA1"); 107 put("Alg.Alias.MessageDigest.SHA1", "SHA-1"); 108 put("Alg.Alias.MessageDigest.SHA", "SHA-1"); 109 put("Alg.Alias.MessageDigest.1.3.14.3.2.26", "SHA-1"); 110 111 put("MessageDigest.SHA-224", PREFIX + "OpenSSLMessageDigestJDK$SHA224"); 112 put("Alg.Alias.MessageDigest.SHA224", "SHA-224"); 113 put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.4", "SHA-224"); 114 115 put("MessageDigest.SHA-256", PREFIX + "OpenSSLMessageDigestJDK$SHA256"); 116 put("Alg.Alias.MessageDigest.SHA256", "SHA-256"); 117 put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.1", "SHA-256"); 118 119 put("MessageDigest.SHA-384", PREFIX + "OpenSSLMessageDigestJDK$SHA384"); 120 put("Alg.Alias.MessageDigest.SHA384", "SHA-384"); 121 put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.2", "SHA-384"); 122 123 put("MessageDigest.SHA-512", PREFIX + "OpenSSLMessageDigestJDK$SHA512"); 124 put("Alg.Alias.MessageDigest.SHA512", "SHA-512"); 125 put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.3", "SHA-512"); 126 127 // iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) md5(5) 128 put("MessageDigest.MD5", PREFIX + "OpenSSLMessageDigestJDK$MD5"); 129 put("Alg.Alias.MessageDigest.1.2.840.113549.2.5", "MD5"); 130 131 /* == KeyGenerators == */ 132 put("KeyGenerator.ARC4", PREFIX + "KeyGeneratorImpl$ARC4"); 133 put("Alg.Alias.KeyGenerator.RC4", "ARC4"); 134 put("Alg.Alias.KeyGenerator.1.2.840.113549.3.4", "ARC4"); 135 136 put("KeyGenerator.AES", PREFIX + "KeyGeneratorImpl$AES"); 137 138 put("KeyGenerator.ChaCha20", PREFIX + "KeyGeneratorImpl$ChaCha20"); 139 140 put("KeyGenerator.DESEDE", PREFIX + "KeyGeneratorImpl$DESEDE"); 141 put("Alg.Alias.KeyGenerator.TDEA", "DESEDE"); 142 143 put("KeyGenerator.HmacMD5", PREFIX + "KeyGeneratorImpl$HmacMD5"); 144 put("Alg.Alias.KeyGenerator.1.3.6.1.5.5.8.1.1", "HmacMD5"); 145 put("Alg.Alias.KeyGenerator.HMAC-MD5", "HmacMD5"); 146 put("Alg.Alias.KeyGenerator.HMAC/MD5", "HmacMD5"); 147 148 put("KeyGenerator.HmacSHA1", PREFIX + "KeyGeneratorImpl$HmacSHA1"); 149 put("Alg.Alias.KeyGenerator.1.2.840.113549.2.7", "HmacSHA1"); 150 put("Alg.Alias.KeyGenerator.1.3.6.1.5.5.8.1.2", "HmacSHA1"); 151 put("Alg.Alias.KeyGenerator.HMAC-SHA1", "HmacSHA1"); 152 put("Alg.Alias.KeyGenerator.HMAC/SHA1", "HmacSHA1"); 153 154 put("KeyGenerator.HmacSHA224", PREFIX + "KeyGeneratorImpl$HmacSHA224"); 155 put("Alg.Alias.KeyGenerator.1.2.840.113549.2.8", "HmacSHA224"); 156 put("Alg.Alias.KeyGenerator.HMAC-SHA224", "HmacSHA224"); 157 put("Alg.Alias.KeyGenerator.HMAC/SHA224", "HmacSHA224"); 158 159 put("KeyGenerator.HmacSHA256", PREFIX + "KeyGeneratorImpl$HmacSHA256"); 160 put("Alg.Alias.KeyGenerator.1.2.840.113549.2.9", "HmacSHA256"); 161 put("Alg.Alias.KeyGenerator.2.16.840.1.101.3.4.2.1", "HmacSHA256"); 162 put("Alg.Alias.KeyGenerator.HMAC-SHA256", "HmacSHA256"); 163 put("Alg.Alias.KeyGenerator.HMAC/SHA256", "HmacSHA256"); 164 165 put("KeyGenerator.HmacSHA384", PREFIX + "KeyGeneratorImpl$HmacSHA384"); 166 put("Alg.Alias.KeyGenerator.1.2.840.113549.2.10", "HmacSHA384"); 167 put("Alg.Alias.KeyGenerator.HMAC-SHA384", "HmacSHA384"); 168 put("Alg.Alias.KeyGenerator.HMAC/SHA384", "HmacSHA384"); 169 170 put("KeyGenerator.HmacSHA512", PREFIX + "KeyGeneratorImpl$HmacSHA512"); 171 put("Alg.Alias.KeyGenerator.1.2.840.113549.2.11", "HmacSHA512"); 172 put("Alg.Alias.KeyGenerator.HMAC-SHA512", "HmacSHA512"); 173 put("Alg.Alias.KeyGenerator.HMAC/SHA512", "HmacSHA512"); 174 175 /* == KeyPairGenerators == */ 176 put("KeyPairGenerator.RSA", PREFIX + "OpenSSLRSAKeyPairGenerator"); 177 put("Alg.Alias.KeyPairGenerator.1.2.840.113549.1.1.1", "RSA"); 178 put("Alg.Alias.KeyPairGenerator.1.2.840.113549.1.1.7", "RSA"); 179 put("Alg.Alias.KeyPairGenerator.2.5.8.1.1", "RSA"); 180 181 put("KeyPairGenerator.EC", PREFIX + "OpenSSLECKeyPairGenerator"); 182 put("Alg.Alias.KeyPairGenerator.1.2.840.10045.2.1", "EC"); 183 put("Alg.Alias.KeyPairGenerator.1.3.133.16.840.63.0.2", "EC"); 184 185 /* == KeyFactory == */ 186 put("KeyFactory.RSA", PREFIX + "OpenSSLRSAKeyFactory"); 187 put("Alg.Alias.KeyFactory.1.2.840.113549.1.1.1", "RSA"); 188 put("Alg.Alias.KeyFactory.1.2.840.113549.1.1.7", "RSA"); 189 put("Alg.Alias.KeyFactory.2.5.8.1.1", "RSA"); 190 191 put("KeyFactory.EC", PREFIX + "OpenSSLECKeyFactory"); 192 put("Alg.Alias.KeyFactory.1.2.840.10045.2.1", "EC"); 193 put("Alg.Alias.KeyFactory.1.3.133.16.840.63.0.2", "EC"); 194 195 /* == SecretKeyFactory == */ 196 put("SecretKeyFactory.DESEDE", PREFIX + "DESEDESecretKeyFactory"); 197 put("Alg.Alias.SecretKeyFactory.TDEA", "DESEDE"); 198 199 /* == KeyAgreement == */ 200 putECDHKeyAgreementImplClass("OpenSSLECDHKeyAgreement"); 201 202 /* == Signatures == */ 203 putSignatureImplClass("MD5withRSA", "OpenSSLSignature$MD5RSA"); 204 put("Alg.Alias.Signature.MD5withRSAEncryption", "MD5withRSA"); 205 put("Alg.Alias.Signature.MD5/RSA", "MD5withRSA"); 206 put("Alg.Alias.Signature.1.2.840.113549.1.1.4", "MD5withRSA"); 207 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.4", "MD5withRSA"); 208 put("Alg.Alias.Signature.1.2.840.113549.2.5with1.2.840.113549.1.1.1", "MD5withRSA"); 209 210 putSignatureImplClass("SHA1withRSA", "OpenSSLSignature$SHA1RSA"); 211 put("Alg.Alias.Signature.SHA1withRSAEncryption", "SHA1withRSA"); 212 put("Alg.Alias.Signature.SHA1/RSA", "SHA1withRSA"); 213 put("Alg.Alias.Signature.SHA-1/RSA", "SHA1withRSA"); 214 put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA"); 215 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA"); 216 put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.1", "SHA1withRSA"); 217 put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.5", "SHA1withRSA"); 218 put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1withRSA"); 219 put("Alg.Alias.Signature.OID.1.3.14.3.2.29", "SHA1withRSA"); 220 221 putSignatureImplClass("SHA224withRSA", "OpenSSLSignature$SHA224RSA"); 222 put("Alg.Alias.Signature.SHA224withRSAEncryption", "SHA224withRSA"); 223 put("Alg.Alias.Signature.SHA224/RSA", "SHA224withRSA"); 224 put("Alg.Alias.Signature.1.2.840.113549.1.1.14", "SHA224withRSA"); 225 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.14", "SHA224withRSA"); 226 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.4with1.2.840.113549.1.1.1", 227 "SHA224withRSA"); 228 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.4with1.2.840.113549.1.1.14", 229 "SHA224withRSA"); 230 231 putSignatureImplClass("SHA256withRSA", "OpenSSLSignature$SHA256RSA"); 232 put("Alg.Alias.Signature.SHA256withRSAEncryption", "SHA256withRSA"); 233 put("Alg.Alias.Signature.SHA256/RSA", "SHA256withRSA"); 234 put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA"); 235 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA"); 236 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.1with1.2.840.113549.1.1.1", 237 "SHA256withRSA"); 238 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.1with1.2.840.113549.1.1.11", 239 "SHA256withRSA"); 240 241 putSignatureImplClass("SHA384withRSA", "OpenSSLSignature$SHA384RSA"); 242 put("Alg.Alias.Signature.SHA384withRSAEncryption", "SHA384withRSA"); 243 put("Alg.Alias.Signature.SHA384/RSA", "SHA384withRSA"); 244 put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA"); 245 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.12", "SHA384withRSA"); 246 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.2with1.2.840.113549.1.1.1", 247 "SHA384withRSA"); 248 249 putSignatureImplClass("SHA512withRSA", "OpenSSLSignature$SHA512RSA"); 250 put("Alg.Alias.Signature.SHA512withRSAEncryption", "SHA512withRSA"); 251 put("Alg.Alias.Signature.SHA512/RSA", "SHA512withRSA"); 252 put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA"); 253 put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.13", "SHA512withRSA"); 254 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.3with1.2.840.113549.1.1.1", 255 "SHA512withRSA"); 256 257 putRAWRSASignatureImplClass("OpenSSLSignatureRawRSA"); 258 259 putSignatureImplClass("NONEwithECDSA", "OpenSSLSignatureRawECDSA"); 260 261 putSignatureImplClass("SHA1withECDSA", "OpenSSLSignature$SHA1ECDSA"); 262 put("Alg.Alias.Signature.ECDSA", "SHA1withECDSA"); 263 put("Alg.Alias.Signature.ECDSAwithSHA1", "SHA1withECDSA"); 264 // iso(1) member-body(2) us(840) ansi-x962(10045) signatures(4) ecdsa-with-SHA1(1) 265 put("Alg.Alias.Signature.1.2.840.10045.4.1", "SHA1withECDSA"); 266 put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.10045.2.1", "SHA1withECDSA"); 267 268 // iso(1) member-body(2) us(840) ansi-x962(10045) signatures(4) ecdsa-with-SHA2(3) 269 putSignatureImplClass("SHA224withECDSA", "OpenSSLSignature$SHA224ECDSA"); 270 put("Alg.Alias.Signature.SHA224/ECDSA", "SHA224withECDSA"); 271 // ecdsa-with-SHA224(1) 272 put("Alg.Alias.Signature.1.2.840.10045.4.3.1", "SHA224withECDSA"); 273 put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.1", "SHA224withECDSA"); 274 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.4with1.2.840.10045.2.1", "SHA224withECDSA"); 275 276 // iso(1) member-body(2) us(840) ansi-x962(10045) signatures(4) ecdsa-with-SHA2(3) 277 putSignatureImplClass("SHA256withECDSA", "OpenSSLSignature$SHA256ECDSA"); 278 put("Alg.Alias.Signature.SHA256/ECDSA", "SHA256withECDSA"); 279 // ecdsa-with-SHA256(2) 280 put("Alg.Alias.Signature.1.2.840.10045.4.3.2", "SHA256withECDSA"); 281 put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.2", "SHA256withECDSA"); 282 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.1with1.2.840.10045.2.1", "SHA256withECDSA"); 283 284 putSignatureImplClass("SHA384withECDSA", "OpenSSLSignature$SHA384ECDSA"); 285 put("Alg.Alias.Signature.SHA384/ECDSA", "SHA384withECDSA"); 286 // ecdsa-with-SHA384(3) 287 put("Alg.Alias.Signature.1.2.840.10045.4.3.3", "SHA384withECDSA"); 288 put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.3", "SHA384withECDSA"); 289 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.2with1.2.840.10045.2.1", "SHA384withECDSA"); 290 291 putSignatureImplClass("SHA512withECDSA", "OpenSSLSignature$SHA512ECDSA"); 292 put("Alg.Alias.Signature.SHA512/ECDSA", "SHA512withECDSA"); 293 // ecdsa-with-SHA512(4) 294 put("Alg.Alias.Signature.1.2.840.10045.4.3.4", "SHA512withECDSA"); 295 put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.4", "SHA512withECDSA"); 296 put("Alg.Alias.Signature.2.16.840.1.101.3.4.2.3with1.2.840.10045.2.1", "SHA512withECDSA"); 297 298 putSignatureImplClass("SHA1withRSA/PSS", "OpenSSLSignature$SHA1RSAPSS"); 299 put("Alg.Alias.Signature.SHA1withRSAandMGF1", "SHA1withRSA/PSS"); 300 301 putSignatureImplClass("SHA224withRSA/PSS", "OpenSSLSignature$SHA224RSAPSS"); 302 put("Alg.Alias.Signature.SHA224withRSAandMGF1", "SHA224withRSA/PSS"); 303 304 putSignatureImplClass("SHA256withRSA/PSS", "OpenSSLSignature$SHA256RSAPSS"); 305 put("Alg.Alias.Signature.SHA256withRSAandMGF1", "SHA256withRSA/PSS"); 306 307 putSignatureImplClass("SHA384withRSA/PSS", "OpenSSLSignature$SHA384RSAPSS"); 308 put("Alg.Alias.Signature.SHA384withRSAandMGF1", "SHA384withRSA/PSS"); 309 310 putSignatureImplClass("SHA512withRSA/PSS", "OpenSSLSignature$SHA512RSAPSS"); 311 put("Alg.Alias.Signature.SHA512withRSAandMGF1", "SHA512withRSA/PSS"); 312 313 /* === SecureRandom === */ 314 /* 315 * We have to specify SHA1PRNG because various documentation mentions 316 * that algorithm by name instead of just recommending calling 317 * "new SecureRandom()" 318 */ 319 put("SecureRandom.SHA1PRNG", PREFIX + "OpenSSLRandom"); 320 put("SecureRandom.SHA1PRNG ImplementedIn", "Software"); 321 322 /* === Cipher === */ 323 putRSACipherImplClass("RSA/ECB/NoPadding", "OpenSSLCipherRSA$Raw"); 324 put("Alg.Alias.Cipher.RSA/None/NoPadding", "RSA/ECB/NoPadding"); 325 putRSACipherImplClass("RSA/ECB/PKCS1Padding", "OpenSSLCipherRSA$PKCS1"); 326 put("Alg.Alias.Cipher.RSA/None/PKCS1Padding", "RSA/ECB/PKCS1Padding"); 327 328 putRSACipherImplClass("RSA/ECB/OAEPPadding", "OpenSSLCipherRSA$OAEP$SHA1"); 329 put("Alg.Alias.Cipher.RSA/None/OAEPPadding", "RSA/ECB/OAEPPadding"); 330 putRSACipherImplClass("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", "OpenSSLCipherRSA$OAEP$SHA1"); 331 put("Alg.Alias.Cipher.RSA/None/OAEPWithSHA-1AndMGF1Padding", 332 "RSA/ECB/OAEPWithSHA-1AndMGF1Padding"); 333 putRSACipherImplClass( 334 "RSA/ECB/OAEPWithSHA-224AndMGF1Padding", "OpenSSLCipherRSA$OAEP$SHA224"); 335 put("Alg.Alias.Cipher.RSA/None/OAEPWithSHA-224AndMGF1Padding", 336 "RSA/ECB/OAEPWithSHA-224AndMGF1Padding"); 337 putRSACipherImplClass( 338 "RSA/ECB/OAEPWithSHA-256AndMGF1Padding", "OpenSSLCipherRSA$OAEP$SHA256"); 339 put("Alg.Alias.Cipher.RSA/None/OAEPWithSHA-256AndMGF1Padding", 340 "RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); 341 putRSACipherImplClass( 342 "RSA/ECB/OAEPWithSHA-384AndMGF1Padding", "OpenSSLCipherRSA$OAEP$SHA384"); 343 put("Alg.Alias.Cipher.RSA/None/OAEPWithSHA-384AndMGF1Padding", 344 "RSA/ECB/OAEPWithSHA-384AndMGF1Padding"); 345 putRSACipherImplClass( 346 "RSA/ECB/OAEPWithSHA-512AndMGF1Padding", "OpenSSLCipherRSA$OAEP$SHA512"); 347 put("Alg.Alias.Cipher.RSA/None/OAEPWithSHA-512AndMGF1Padding", 348 "RSA/ECB/OAEPWithSHA-512AndMGF1Padding"); 349 350 /* 351 * OpenSSL only supports a subset of modes, so we'll name them 352 * explicitly here. 353 * 354 * Moreover, OpenSSL only supports PKCS#7 padding. PKCS#5 padding 355 * is also supported because it's a special case of PKCS#7 for 64-bit 356 * blocks. PKCS#5 technically supports only 64-bit blocks and won't 357 * produce the same result as PKCS#7 for blocks that are not 64 bits 358 * long. However, everybody assumes PKCS#7 when they say PKCS#5. For 359 * example, lots of code uses PKCS#5 with AES whose blocks are longer 360 * than 64 bits. We solve this confusion by making PKCS7Padding an 361 * alias for PKCS5Padding. 362 */ 363 putSymmetricCipherImplClass("AES/ECB/NoPadding", 364 "OpenSSLCipher$EVP_CIPHER$AES$ECB$NoPadding"); 365 putSymmetricCipherImplClass("AES/ECB/PKCS5Padding", 366 "OpenSSLCipher$EVP_CIPHER$AES$ECB$PKCS5Padding"); 367 put("Alg.Alias.Cipher.AES/ECB/PKCS7Padding", "AES/ECB/PKCS5Padding"); 368 putSymmetricCipherImplClass("AES/CBC/NoPadding", 369 "OpenSSLCipher$EVP_CIPHER$AES$CBC$NoPadding"); 370 putSymmetricCipherImplClass("AES/CBC/PKCS5Padding", 371 "OpenSSLCipher$EVP_CIPHER$AES$CBC$PKCS5Padding"); 372 put("Alg.Alias.Cipher.AES/CBC/PKCS7Padding", "AES/CBC/PKCS5Padding"); 373 putSymmetricCipherImplClass("AES/CTR/NoPadding", "OpenSSLCipher$EVP_CIPHER$AES$CTR"); 374 375 putSymmetricCipherImplClass( 376 "AES_128/ECB/NoPadding", "OpenSSLCipher$EVP_CIPHER$AES_128$ECB$NoPadding"); 377 putSymmetricCipherImplClass( 378 "AES_128/ECB/PKCS5Padding", "OpenSSLCipher$EVP_CIPHER$AES_128$ECB$PKCS5Padding"); 379 put("Alg.Alias.Cipher.AES_128/ECB/PKCS7Padding", "AES_128/ECB/PKCS5Padding"); 380 putSymmetricCipherImplClass( 381 "AES_128/CBC/NoPadding", "OpenSSLCipher$EVP_CIPHER$AES_128$CBC$NoPadding"); 382 putSymmetricCipherImplClass( 383 "AES_128/CBC/PKCS5Padding", "OpenSSLCipher$EVP_CIPHER$AES_128$CBC$PKCS5Padding"); 384 put("Alg.Alias.Cipher.AES_128/CBC/PKCS7Padding", "AES_128/CBC/PKCS5Padding"); 385 386 put("Alg.Alias.Cipher.PBEWithHmacSHA1AndAES_128", "AES_128/CBC/PKCS5PADDING"); 387 put("Alg.Alias.Cipher.PBEWithHmacSHA224AndAES_128", "AES_128/CBC/PKCS5PADDING"); 388 put("Alg.Alias.Cipher.PBEWithHmacSHA256AndAES_128", "AES_128/CBC/PKCS5PADDING"); 389 put("Alg.Alias.Cipher.PBEWithHmacSHA384AndAES_128", "AES_128/CBC/PKCS5PADDING"); 390 put("Alg.Alias.Cipher.PBEWithHmacSHA512AndAES_128", "AES_128/CBC/PKCS5PADDING"); 391 392 putSymmetricCipherImplClass( 393 "AES_256/ECB/NoPadding", "OpenSSLCipher$EVP_CIPHER$AES_256$ECB$NoPadding"); 394 putSymmetricCipherImplClass( 395 "AES_256/ECB/PKCS5Padding", "OpenSSLCipher$EVP_CIPHER$AES_256$ECB$PKCS5Padding"); 396 put("Alg.Alias.Cipher.AES_256/ECB/PKCS7Padding", "AES_256/ECB/PKCS5Padding"); 397 putSymmetricCipherImplClass( 398 "AES_256/CBC/NoPadding", "OpenSSLCipher$EVP_CIPHER$AES_256$CBC$NoPadding"); 399 putSymmetricCipherImplClass( 400 "AES_256/CBC/PKCS5Padding", "OpenSSLCipher$EVP_CIPHER$AES_256$CBC$PKCS5Padding"); 401 put("Alg.Alias.Cipher.AES_256/CBC/PKCS7Padding", "AES_256/CBC/PKCS5Padding"); 402 403 put("Alg.Alias.Cipher.PBEWithHmacSHA1AndAES_256", "AES_256/CBC/PKCS5PADDING"); 404 put("Alg.Alias.Cipher.PBEWithHmacSHA224AndAES_256", "AES_256/CBC/PKCS5PADDING"); 405 put("Alg.Alias.Cipher.PBEWithHmacSHA256AndAES_256", "AES_256/CBC/PKCS5PADDING"); 406 put("Alg.Alias.Cipher.PBEWithHmacSHA384AndAES_256", "AES_256/CBC/PKCS5PADDING"); 407 put("Alg.Alias.Cipher.PBEWithHmacSHA512AndAES_256", "AES_256/CBC/PKCS5PADDING"); 408 409 putSymmetricCipherImplClass("DESEDE/CBC/NoPadding", 410 "OpenSSLCipher$EVP_CIPHER$DESEDE$CBC$NoPadding"); 411 putSymmetricCipherImplClass("DESEDE/CBC/PKCS5Padding", 412 "OpenSSLCipher$EVP_CIPHER$DESEDE$CBC$PKCS5Padding"); 413 put("Alg.Alias.Cipher.DESEDE/CBC/PKCS7Padding", "DESEDE/CBC/PKCS5Padding"); 414 415 putSymmetricCipherImplClass("ARC4", "OpenSSLCipher$EVP_CIPHER$ARC4"); 416 put("Alg.Alias.Cipher.ARCFOUR", "ARC4"); 417 put("Alg.Alias.Cipher.RC4", "ARC4"); 418 put("Alg.Alias.Cipher.1.2.840.113549.3.4", "ARC4"); 419 put("Alg.Alias.Cipher.OID.1.2.840.113549.3.4", "ARC4"); 420 421 putSymmetricCipherImplClass("AES/GCM/NoPadding", "OpenSSLCipher$EVP_AEAD$AES$GCM"); 422 put("Alg.Alias.Cipher.GCM", "AES/GCM/NoPadding"); 423 put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.6", "AES/GCM/NoPadding"); 424 put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.26", "AES/GCM/NoPadding"); 425 put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.46", "AES/GCM/NoPadding"); 426 putSymmetricCipherImplClass( 427 "AES_128/GCM/NoPadding", "OpenSSLCipher$EVP_AEAD$AES$GCM$AES_128"); 428 putSymmetricCipherImplClass( 429 "AES_256/GCM/NoPadding", "OpenSSLCipher$EVP_AEAD$AES$GCM$AES_256"); 430 431 putSymmetricCipherImplClass("ChaCha20", 432 "OpenSSLCipherChaCha20"); 433 putSymmetricCipherImplClass("ChaCha20/Poly1305/NoPadding", 434 "OpenSSLCipher$EVP_AEAD$ChaCha20"); 435 put("Alg.Alias.Cipher.ChaCha20-Poly1305", "ChaCha20/Poly1305/NoPadding"); 436 437 /* === Mac === */ 438 439 putMacImplClass("HmacMD5", "OpenSSLMac$HmacMD5"); 440 put("Alg.Alias.Mac.1.3.6.1.5.5.8.1.1", "HmacMD5"); 441 put("Alg.Alias.Mac.HMAC-MD5", "HmacMD5"); 442 put("Alg.Alias.Mac.HMAC/MD5", "HmacMD5"); 443 444 // PKCS#2 - iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 445 // http://www.oid-info.com/get/1.2.840.113549.2 446 447 // HMAC-SHA-1 PRF (7) 448 putMacImplClass("HmacSHA1", "OpenSSLMac$HmacSHA1"); 449 put("Alg.Alias.Mac.1.2.840.113549.2.7", "HmacSHA1"); 450 put("Alg.Alias.Mac.1.3.6.1.5.5.8.1.2", "HmacSHA1"); 451 put("Alg.Alias.Mac.HMAC-SHA1", "HmacSHA1"); 452 put("Alg.Alias.Mac.HMAC/SHA1", "HmacSHA1"); 453 454 // id-hmacWithSHA224 (8) 455 putMacImplClass("HmacSHA224", "OpenSSLMac$HmacSHA224"); 456 put("Alg.Alias.Mac.1.2.840.113549.2.8", "HmacSHA224"); 457 put("Alg.Alias.Mac.HMAC-SHA224", "HmacSHA224"); 458 put("Alg.Alias.Mac.HMAC/SHA224", "HmacSHA224"); 459 put("Alg.Alias.Mac.PBEWITHHMACSHA224", "HmacSHA224"); 460 461 // id-hmacWithSHA256 (9) 462 putMacImplClass("HmacSHA256", "OpenSSLMac$HmacSHA256"); 463 put("Alg.Alias.Mac.1.2.840.113549.2.9", "HmacSHA256"); 464 put("Alg.Alias.Mac.2.16.840.1.101.3.4.2.1", "HmacSHA256"); 465 put("Alg.Alias.Mac.HMAC-SHA256", "HmacSHA256"); 466 put("Alg.Alias.Mac.HMAC/SHA256", "HmacSHA256"); 467 put("Alg.Alias.Mac.PBEWITHHMACSHA256", "HmacSHA256"); 468 469 // id-hmacWithSHA384 (10) 470 putMacImplClass("HmacSHA384", "OpenSSLMac$HmacSHA384"); 471 put("Alg.Alias.Mac.1.2.840.113549.2.10", "HmacSHA384"); 472 put("Alg.Alias.Mac.HMAC-SHA384", "HmacSHA384"); 473 put("Alg.Alias.Mac.HMAC/SHA384", "HmacSHA384"); 474 put("Alg.Alias.Mac.PBEWITHHMACSHA384", "HmacSHA384"); 475 476 // id-hmacWithSHA384 (11) 477 putMacImplClass("HmacSHA512", "OpenSSLMac$HmacSHA512"); 478 put("Alg.Alias.Mac.1.2.840.113549.2.11", "HmacSHA512"); 479 put("Alg.Alias.Mac.HMAC-SHA512", "HmacSHA512"); 480 put("Alg.Alias.Mac.HMAC/SHA512", "HmacSHA512"); 481 put("Alg.Alias.Mac.PBEWITHHMACSHA512", "HmacSHA512"); 482 483 /* === Certificate === */ 484 485 put("CertificateFactory.X509", PREFIX + "OpenSSLX509CertificateFactory"); 486 put("Alg.Alias.CertificateFactory.X.509", "X509"); 487 } 488 putMacImplClass(String algorithm, String className)489 private void putMacImplClass(String algorithm, String className) { 490 // Accept only keys for which any of the following is true: 491 // * the key is from this provider (subclass of OpenSSLKeyHolder), 492 // * the key provides its key material in "RAW" encoding via Key.getEncoded. 493 String supportedKeyClasses = PREFIX + "OpenSSLKeyHolder"; 494 String supportedKeyFormats = "RAW"; 495 putImplClassWithKeyConstraints( 496 "Mac." + algorithm, 497 PREFIX + className, 498 supportedKeyClasses, 499 supportedKeyFormats); 500 } 501 putSymmetricCipherImplClass(String transformation, String className)502 private void putSymmetricCipherImplClass(String transformation, String className) { 503 // Accept only keys for which any of the following is true: 504 // * the key provides its key material in "RAW" encoding via Key.getEncoded. 505 String supportedKeyClasses = null; // ignored -- filtered based on encoding format only 506 String supportedKeyFormats = "RAW"; 507 putImplClassWithKeyConstraints( 508 "Cipher." + transformation, 509 PREFIX + className, 510 supportedKeyClasses, 511 supportedKeyFormats); 512 } 513 putRSACipherImplClass(String transformation, String className)514 private void putRSACipherImplClass(String transformation, String className) { 515 // Accept only keys for which any of the following is true: 516 // * the key is instance of OpenSSLRSAPrivateKey, RSAPrivateKey, OpenSSLRSAPublicKey, or 517 // RSAPublicKey. 518 String supportedKeyClasses = PREFIX + "OpenSSLRSAPrivateKey" 519 + "|" + STANDARD_RSA_PRIVATE_KEY_INTERFACE_CLASS_NAME 520 + "|" + PREFIX + "OpenSSLRSAPublicKey" 521 + "|" + STANDARD_RSA_PUBLIC_KEY_INTERFACE_CLASS_NAME; 522 String supportedKeyFormats = null; // ignored -- filtered based on class only 523 putImplClassWithKeyConstraints( 524 "Cipher." + transformation, 525 PREFIX + className, 526 supportedKeyClasses, 527 supportedKeyFormats); 528 } 529 putSignatureImplClass(String algorithm, String className)530 private void putSignatureImplClass(String algorithm, String className) { 531 // Accept only keys for which any of the following is true: 532 // * the key is from this provider (subclass of OpenSSLKeyHolder), 533 // * the key provides its key material in "PKCS#8" or "X.509" encodings via Key.getEncoded. 534 // * the key is a transparent private key (subclass of RSAPrivateKey or ECPrivateKey). For 535 // some reason this provider's Signature implementation does not unconditionally accept 536 // transparent public keys -- it only accepts them if they provide their key material in 537 // encoded form (see above). 538 String supportedKeyClasses = PREFIX + "OpenSSLKeyHolder" 539 + "|" + STANDARD_RSA_PRIVATE_KEY_INTERFACE_CLASS_NAME 540 + "|" + STANDARD_EC_PRIVATE_KEY_INTERFACE_CLASS_NAME 541 + "|" + STANDARD_RSA_PUBLIC_KEY_INTERFACE_CLASS_NAME; 542 String supportedKeyFormats = "PKCS#8|X.509"; 543 putImplClassWithKeyConstraints( 544 "Signature." + algorithm, 545 PREFIX + className, 546 supportedKeyClasses, 547 supportedKeyFormats); 548 } 549 putRAWRSASignatureImplClass(String className)550 private void putRAWRSASignatureImplClass(String className) { 551 // Accept only keys for which any of the following is true: 552 // * the key is instance of OpenSSLRSAPrivateKey, RSAPrivateKey, OpenSSLRSAPublicKey, or 553 // RSAPublicKey. 554 String supportedKeyClasses = PREFIX + "OpenSSLRSAPrivateKey" 555 + "|" + STANDARD_RSA_PRIVATE_KEY_INTERFACE_CLASS_NAME 556 + "|" + PREFIX + "OpenSSLRSAPublicKey" 557 + "|" + STANDARD_RSA_PUBLIC_KEY_INTERFACE_CLASS_NAME; 558 String supportedKeyFormats = null; // ignored -- filtered based on class only 559 putImplClassWithKeyConstraints( 560 "Signature.NONEwithRSA", 561 PREFIX + className, 562 supportedKeyClasses, 563 supportedKeyFormats); 564 } 565 putECDHKeyAgreementImplClass(String className)566 private void putECDHKeyAgreementImplClass(String className) { 567 // Accept only keys for which any of the following is true: 568 // * the key is from this provider (subclass of OpenSSLKeyHolder), 569 // * the key provides its key material in "PKCS#8" encoding via Key.getEncoded. 570 // * the key is a transparent EC private key (subclass of ECPrivateKey). 571 String supportedKeyClasses = PREFIX + "OpenSSLKeyHolder" 572 + "|" + STANDARD_EC_PRIVATE_KEY_INTERFACE_CLASS_NAME; 573 String supportedKeyFormats = "PKCS#8"; 574 putImplClassWithKeyConstraints( 575 "KeyAgreement.ECDH", 576 PREFIX + className, 577 supportedKeyClasses, 578 supportedKeyFormats); 579 } 580 putImplClassWithKeyConstraints(String typeAndAlgName, String fullyQualifiedClassName, String supportedKeyClasses, String supportedKeyFormats)581 private void putImplClassWithKeyConstraints(String typeAndAlgName, 582 String fullyQualifiedClassName, 583 String supportedKeyClasses, 584 String supportedKeyFormats) { 585 put(typeAndAlgName, fullyQualifiedClassName); 586 if (supportedKeyClasses != null) { 587 put(typeAndAlgName + " SupportedKeyClasses", supportedKeyClasses); 588 } 589 if (supportedKeyFormats != null) { 590 put(typeAndAlgName + " SupportedKeyFormats", supportedKeyFormats); 591 } 592 } 593 } 594