0N/A/*
3002N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.crypto.provider;
0N/A
0N/Aimport java.security.AccessController;
0N/Aimport java.security.Provider;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport java.security.cert.*;
0N/Aimport java.net.URL;
0N/Aimport java.io.ByteArrayInputStream;
0N/Aimport java.security.CodeSource;
0N/Aimport java.security.SecureRandom;
0N/A
0N/A
0N/A/**
0N/A * The "SunJCE" Cryptographic Service Provider.
0N/A *
0N/A * @author Jan Luehe
0N/A * @author Sharon Liu
0N/A */
0N/A
0N/A/**
0N/A * Defines the "SunJCE" provider.
0N/A *
0N/A * Supported algorithms and their names:
0N/A *
0N/A * - RSA encryption (PKCS#1 v1.5 and raw)
0N/A *
0N/A * - DES
0N/A *
0N/A * - DES-EDE
0N/A *
0N/A * - AES
0N/A *
0N/A * - Blowfish
0N/A *
0N/A * - RC2
0N/A *
0N/A * - ARCFOUR (RC4 compatible)
0N/A *
0N/A * - Cipher modes ECB, CBC, CFB, OFB, PCBC, CTR, and CTS for all block ciphers
0N/A *
0N/A * - Cipher padding ISO10126Padding for non-PKCS#5 block ciphers and
0N/A * NoPadding and PKCS5Padding for all block ciphers
0N/A *
0N/A * - Password-based Encryption (PBE)
0N/A *
0N/A * - Diffie-Hellman Key Agreement
0N/A *
0N/A * - HMAC-MD5, HMAC-SHA1, HMAC-SHA-256, HMAC-SHA-384, HMAC-SHA-512
0N/A *
0N/A */
0N/A
0N/Apublic final class SunJCE extends Provider {
0N/A
0N/A private static final long serialVersionUID = 6812507587804302833L;
0N/A
0N/A private static final String info = "SunJCE Provider " +
0N/A "(implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, "
0N/A + "Diffie-Hellman, HMAC)";
0N/A
0N/A private static final String OID_PKCS12_RC2_40 = "1.2.840.113549.1.12.1.6";
0N/A private static final String OID_PKCS12_DESede = "1.2.840.113549.1.12.1.3";
0N/A private static final String OID_PKCS5_MD5_DES = "1.2.840.113549.1.5.3";
0N/A private static final String OID_PKCS5_PBKDF2 = "1.2.840.113549.1.5.12";
0N/A private static final String OID_PKCS3 = "1.2.840.113549.1.3.1";
0N/A
0N/A /* Are we debugging? -- for developers */
0N/A static final boolean debug = false;
0N/A
0N/A static final SecureRandom RANDOM = new SecureRandom();
0N/A
0N/A public SunJCE() {
0N/A /* We are the "SunJCE" provider */
0N/A super("SunJCE", 1.7d, info);
0N/A
0N/A final String BLOCK_MODES = "ECB|CBC|PCBC|CTR|CTS|CFB|OFB" +
0N/A "|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64" +
0N/A "|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64";
0N/A final String BLOCK_MODES128 = BLOCK_MODES +
0N/A "|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128" +
0N/A "|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128";
0N/A final String BLOCK_PADS = "NOPADDING|PKCS5PADDING|ISO10126PADDING";
0N/A
0N/A AccessController.doPrivileged(new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A
0N/A /*
0N/A * Cipher engines
0N/A */
0N/A put("Cipher.RSA", "com.sun.crypto.provider.RSACipher");
0N/A put("Cipher.RSA SupportedModes", "ECB");
0N/A put("Cipher.RSA SupportedPaddings",
0N/A "NOPADDING|PKCS1PADDING|OAEPWITHMD5ANDMGF1PADDING"
0N/A + "|OAEPWITHSHA1ANDMGF1PADDING"
0N/A + "|OAEPWITHSHA-1ANDMGF1PADDING"
0N/A + "|OAEPWITHSHA-256ANDMGF1PADDING"
0N/A + "|OAEPWITHSHA-384ANDMGF1PADDING"
0N/A + "|OAEPWITHSHA-512ANDMGF1PADDING");
0N/A put("Cipher.RSA SupportedKeyClasses",
0N/A "java.security.interfaces.RSAPublicKey" +
0N/A "|java.security.interfaces.RSAPrivateKey");
0N/A
0N/A put("Cipher.DES", "com.sun.crypto.provider.DESCipher");
0N/A put("Cipher.DES SupportedModes", BLOCK_MODES);
0N/A put("Cipher.DES SupportedPaddings", BLOCK_PADS);
0N/A put("Cipher.DES SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.DESede", "com.sun.crypto.provider.DESedeCipher");
0N/A put("Alg.Alias.Cipher.TripleDES", "DESede");
0N/A put("Cipher.DESede SupportedModes", BLOCK_MODES);
0N/A put("Cipher.DESede SupportedPaddings", BLOCK_PADS);
0N/A put("Cipher.DESede SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.DESedeWrap",
0N/A "com.sun.crypto.provider.DESedeWrapCipher");
0N/A put("Cipher.DESedeWrap SupportedModes", "CBC");
0N/A put("Cipher.DESedeWrap SupportedPaddings", "NOPADDING");
0N/A put("Cipher.DESedeWrap SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.PBEWithMD5AndDES",
0N/A "com.sun.crypto.provider.PBEWithMD5AndDESCipher");
0N/A put("Alg.Alias.Cipher.OID."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A put("Alg.Alias.Cipher."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A put("Cipher.PBEWithMD5AndTripleDES",
0N/A "com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher");
0N/A put("Cipher.PBEWithSHA1AndRC2_40",
0N/A "com.sun.crypto.provider.PKCS12PBECipherCore$" +
0N/A "PBEWithSHA1AndRC2_40");
0N/A put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A put("Alg.Alias.Cipher." + OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A put("Cipher.PBEWithSHA1AndDESede",
0N/A "com.sun.crypto.provider.PKCS12PBECipherCore$" +
0N/A "PBEWithSHA1AndDESede");
0N/A put("Alg.Alias.Cipher.OID." + OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A put("Alg.Alias.Cipher." + OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A
0N/A put("Cipher.Blowfish",
0N/A "com.sun.crypto.provider.BlowfishCipher");
0N/A put("Cipher.Blowfish SupportedModes", BLOCK_MODES);
0N/A put("Cipher.Blowfish SupportedPaddings", BLOCK_PADS);
0N/A put("Cipher.Blowfish SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.AES", "com.sun.crypto.provider.AESCipher");
0N/A put("Alg.Alias.Cipher.Rijndael", "AES");
0N/A put("Cipher.AES SupportedModes", BLOCK_MODES128);
0N/A put("Cipher.AES SupportedPaddings", BLOCK_PADS);
0N/A put("Cipher.AES SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.AESWrap", "com.sun.crypto.provider.AESWrapCipher");
0N/A put("Cipher.AESWrap SupportedModes", "ECB");
0N/A put("Cipher.AESWrap SupportedPaddings", "NOPADDING");
0N/A put("Cipher.AESWrap SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.RC2",
0N/A "com.sun.crypto.provider.RC2Cipher");
0N/A put("Cipher.RC2 SupportedModes", BLOCK_MODES);
0N/A put("Cipher.RC2 SupportedPaddings", BLOCK_PADS);
0N/A put("Cipher.RC2 SupportedKeyFormats", "RAW");
0N/A
0N/A put("Cipher.ARCFOUR",
0N/A "com.sun.crypto.provider.ARCFOURCipher");
0N/A put("Alg.Alias.Cipher.RC4", "ARCFOUR");
0N/A put("Cipher.ARCFOUR SupportedModes", "ECB");
0N/A put("Cipher.ARCFOUR SupportedPaddings", "NOPADDING");
0N/A put("Cipher.ARCFOUR SupportedKeyFormats", "RAW");
0N/A
0N/A /*
0N/A * Key(pair) Generator engines
0N/A */
0N/A put("KeyGenerator.DES",
0N/A "com.sun.crypto.provider.DESKeyGenerator");
0N/A
0N/A put("KeyGenerator.DESede",
0N/A "com.sun.crypto.provider.DESedeKeyGenerator");
0N/A put("Alg.Alias.KeyGenerator.TripleDES", "DESede");
0N/A
0N/A put("KeyGenerator.Blowfish",
0N/A "com.sun.crypto.provider.BlowfishKeyGenerator");
0N/A
0N/A put("KeyGenerator.AES",
0N/A "com.sun.crypto.provider.AESKeyGenerator");
0N/A put("Alg.Alias.KeyGenerator.Rijndael", "AES");
0N/A
0N/A put("KeyGenerator.RC2",
0N/A "com.sun.crypto.provider.KeyGeneratorCore$" +
0N/A "RC2KeyGenerator");
0N/A put("KeyGenerator.ARCFOUR",
0N/A "com.sun.crypto.provider.KeyGeneratorCore$" +
0N/A "ARCFOURKeyGenerator");
0N/A put("Alg.Alias.KeyGenerator.RC4", "ARCFOUR");
0N/A
0N/A put("KeyGenerator.HmacMD5",
0N/A "com.sun.crypto.provider.HmacMD5KeyGenerator");
0N/A
0N/A put("KeyGenerator.HmacSHA1",
0N/A "com.sun.crypto.provider.HmacSHA1KeyGenerator");
0N/A
0N/A put("KeyGenerator.HmacSHA256",
0N/A "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA256KG");
0N/A put("KeyGenerator.HmacSHA384",
0N/A "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA384KG");
0N/A put("KeyGenerator.HmacSHA512",
0N/A "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA512KG");
0N/A
0N/A put("KeyPairGenerator.DiffieHellman",
0N/A "com.sun.crypto.provider.DHKeyPairGenerator");
0N/A put("Alg.Alias.KeyPairGenerator.DH", "DiffieHellman");
0N/A put("Alg.Alias.KeyPairGenerator.OID."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A put("Alg.Alias.KeyPairGenerator."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A /*
0N/A * Algorithm parameter generation engines
0N/A */
0N/A put("AlgorithmParameterGenerator.DiffieHellman",
0N/A "com.sun.crypto.provider.DHParameterGenerator");
0N/A put("Alg.Alias.AlgorithmParameterGenerator.DH",
0N/A "DiffieHellman");
0N/A put("Alg.Alias.AlgorithmParameterGenerator.OID."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A put("Alg.Alias.AlgorithmParameterGenerator."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A
0N/A /*
0N/A * Key Agreement engines
0N/A */
0N/A put("KeyAgreement.DiffieHellman",
0N/A "com.sun.crypto.provider.DHKeyAgreement");
0N/A put("Alg.Alias.KeyAgreement.DH", "DiffieHellman");
0N/A put("Alg.Alias.KeyAgreement.OID."+OID_PKCS3, "DiffieHellman");
0N/A put("Alg.Alias.KeyAgreement."+OID_PKCS3, "DiffieHellman");
0N/A
0N/A put("KeyAgreement.DiffieHellman SupportedKeyClasses",
0N/A "javax.crypto.interfaces.DHPublicKey" +
0N/A "|javax.crypto.interfaces.DHPrivateKey");
0N/A
0N/A /*
0N/A * Algorithm Parameter engines
0N/A */
0N/A put("AlgorithmParameters.DiffieHellman",
0N/A "com.sun.crypto.provider.DHParameters");
0N/A put("Alg.Alias.AlgorithmParameters.DH", "DiffieHellman");
0N/A put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A put("Alg.Alias.AlgorithmParameters."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A
0N/A put("AlgorithmParameters.DES",
0N/A "com.sun.crypto.provider.DESParameters");
0N/A
0N/A put("AlgorithmParameters.DESede",
0N/A "com.sun.crypto.provider.DESedeParameters");
0N/A put("Alg.Alias.AlgorithmParameters.TripleDES", "DESede");
0N/A
0N/A put("AlgorithmParameters.PBE",
0N/A "com.sun.crypto.provider.PBEParameters");
0N/A
0N/A put("AlgorithmParameters.PBEWithMD5AndDES",
0N/A "com.sun.crypto.provider.PBEParameters");
0N/A put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A put("Alg.Alias.AlgorithmParameters."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A
0N/A put("AlgorithmParameters.PBEWithMD5AndTripleDES",
0N/A "com.sun.crypto.provider.PBEParameters");
0N/A
0N/A put("AlgorithmParameters.PBEWithSHA1AndDESede",
0N/A "com.sun.crypto.provider.PBEParameters");
0N/A put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A put("Alg.Alias.AlgorithmParameters."+OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A
0N/A put("AlgorithmParameters.PBEWithSHA1AndRC2_40",
0N/A "com.sun.crypto.provider.PBEParameters");
0N/A put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A
0N/A put("AlgorithmParameters.Blowfish",
0N/A "com.sun.crypto.provider.BlowfishParameters");
0N/A
0N/A put("AlgorithmParameters.AES",
0N/A "com.sun.crypto.provider.AESParameters");
0N/A put("Alg.Alias.AlgorithmParameters.Rijndael", "AES");
0N/A
0N/A
0N/A put("AlgorithmParameters.RC2",
0N/A "com.sun.crypto.provider.RC2Parameters");
0N/A
0N/A put("AlgorithmParameters.OAEP",
0N/A "com.sun.crypto.provider.OAEPParameters");
0N/A
0N/A
0N/A /*
0N/A * Key factories
0N/A */
0N/A put("KeyFactory.DiffieHellman",
0N/A "com.sun.crypto.provider.DHKeyFactory");
0N/A put("Alg.Alias.KeyFactory.DH", "DiffieHellman");
0N/A put("Alg.Alias.KeyFactory.OID."+OID_PKCS3,
0N/A "DiffieHellman");
0N/A put("Alg.Alias.KeyFactory."+OID_PKCS3, "DiffieHellman");
0N/A /*
0N/A * Secret-key factories
0N/A */
0N/A put("SecretKeyFactory.DES",
0N/A "com.sun.crypto.provider.DESKeyFactory");
0N/A
0N/A put("SecretKeyFactory.DESede",
0N/A "com.sun.crypto.provider.DESedeKeyFactory");
0N/A put("Alg.Alias.SecretKeyFactory.TripleDES", "DESede");
0N/A
0N/A put("SecretKeyFactory.PBEWithMD5AndDES",
0N/A "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES"
0N/A );
0N/A put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A put("Alg.Alias.SecretKeyFactory."+OID_PKCS5_MD5_DES,
0N/A "PBEWithMD5AndDES");
0N/A
0N/A put("Alg.Alias.SecretKeyFactory.PBE",
0N/A "PBEWithMD5AndDES");
0N/A
0N/A /*
0N/A * Internal in-house crypto algorithm used for
0N/A * the JCEKS keystore type. Since this was developed
0N/A * internally, there isn't an OID corresponding to this
0N/A * algorithm.
0N/A */
0N/A put("SecretKeyFactory.PBEWithMD5AndTripleDES",
0N/A "com.sun.crypto.provider.PBEKeyFactory$" +
0N/A "PBEWithMD5AndTripleDES"
0N/A );
0N/A
0N/A put("SecretKeyFactory.PBEWithSHA1AndDESede",
0N/A "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede"
0N/A );
0N/A put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_DESede,
0N/A "PBEWithSHA1AndDESede");
0N/A
0N/A put("SecretKeyFactory.PBEWithSHA1AndRC2_40",
0N/A "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40"
0N/A );
0N/A put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC2_40,
0N/A "PBEWithSHA1AndRC2_40");
0N/A
0N/A put("SecretKeyFactory.PBKDF2WithHmacSHA1",
0N/A "com.sun.crypto.provider.PBKDF2HmacSHA1Factory");
0N/A put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS5_PBKDF2,
0N/A "PBKDF2WithHmacSHA1");
0N/A put("Alg.Alias.SecretKeyFactory." + OID_PKCS5_PBKDF2,
0N/A "PBKDF2WithHmacSHA1");
0N/A
0N/A /*
0N/A * MAC
0N/A */
0N/A put("Mac.HmacMD5", "com.sun.crypto.provider.HmacMD5");
0N/A put("Mac.HmacSHA1", "com.sun.crypto.provider.HmacSHA1");
0N/A put("Mac.HmacSHA256",
0N/A "com.sun.crypto.provider.HmacCore$HmacSHA256");
0N/A put("Mac.HmacSHA384",
0N/A "com.sun.crypto.provider.HmacCore$HmacSHA384");
0N/A put("Mac.HmacSHA512",
0N/A "com.sun.crypto.provider.HmacCore$HmacSHA512");
0N/A put("Mac.HmacPBESHA1",
0N/A "com.sun.crypto.provider.HmacPKCS12PBESHA1");
0N/A
0N/A put("Mac.SslMacMD5",
0N/A "com.sun.crypto.provider.SslMacCore$SslMacMD5");
0N/A put("Mac.SslMacSHA1",
0N/A "com.sun.crypto.provider.SslMacCore$SslMacSHA1");
0N/A
0N/A put("Mac.HmacMD5 SupportedKeyFormats", "RAW");
0N/A put("Mac.HmacSHA1 SupportedKeyFormats", "RAW");
0N/A put("Mac.HmacSHA256 SupportedKeyFormats", "RAW");
0N/A put("Mac.HmacSHA384 SupportedKeyFormats", "RAW");
0N/A put("Mac.HmacSHA512 SupportedKeyFormats", "RAW");
0N/A put("Mac.HmacPBESHA1 SupportedKeyFormats", "RAW");
0N/A put("Mac.SslMacMD5 SupportedKeyFormats", "RAW");
0N/A put("Mac.SslMacSHA1 SupportedKeyFormats", "RAW");
0N/A
0N/A /*
0N/A * KeyStore
0N/A */
0N/A put("KeyStore.JCEKS", "com.sun.crypto.provider.JceKeyStore");
0N/A
0N/A /*
0N/A * SSL/TLS mechanisms
3002N/A *
3002N/A * These are strictly internal implementations and may
3002N/A * be changed at any time. These names were chosen
3002N/A * because PKCS11/SunPKCS11 does not yet have TLS1.2
3002N/A * mechanisms, and it will cause calls to come here.
0N/A */
0N/A put("KeyGenerator.SunTlsPrf",
3002N/A "com.sun.crypto.provider.TlsPrfGenerator$V10");
3002N/A put("KeyGenerator.SunTls12Prf",
3002N/A "com.sun.crypto.provider.TlsPrfGenerator$V12");
3002N/A
0N/A put("KeyGenerator.SunTlsMasterSecret",
3002N/A "com.sun.crypto.provider.TlsMasterSecretGenerator");
3002N/A put("Alg.Alias.KeyGenerator.SunTls12MasterSecret",
3002N/A "SunTlsMasterSecret");
3002N/A
0N/A put("KeyGenerator.SunTlsKeyMaterial",
3002N/A "com.sun.crypto.provider.TlsKeyMaterialGenerator");
3002N/A put("Alg.Alias.KeyGenerator.SunTls12KeyMaterial",
3002N/A "SunTlsKeyMaterial");
3002N/A
3002N/A put("KeyGenerator.SunTlsRsaPremasterSecret",
3002N/A "com.sun.crypto.provider.TlsRsaPremasterSecretGenerator");
3002N/A put("Alg.Alias.KeyGenerator.SunTls12RsaPremasterSecret",
3002N/A "SunTlsRsaPremasterSecret");
0N/A
0N/A return null;
0N/A }
0N/A });
0N/A }
0N/A}