Save This Page
Home » openjdk-7 » com.sun.crypto » provider » [javadoc | source]
    1   /*
    2    * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   
   26   package com.sun.crypto.provider;
   27   
   28   import java.security.AccessController;
   29   import java.security.Provider;
   30   import java.security.PrivilegedAction;
   31   import java.security.cert;
   32   import java.net.URL;
   33   import java.io.ByteArrayInputStream;
   34   import java.security.CodeSource;
   35   import java.security.SecureRandom;
   36   
   37   
   38   /**
   39    * The "SunJCE" Cryptographic Service Provider.
   40    *
   41    * @author Jan Luehe
   42    * @author Sharon Liu
   43    */
   44   
   45   /**
   46    * Defines the "SunJCE" provider.
   47    *
   48    * Supported algorithms and their names:
   49    *
   50    * - RSA encryption (PKCS#1 v1.5 and raw)
   51    *
   52    * - DES
   53    *
   54    * - DES-EDE
   55    *
   56    * - AES
   57    *
   58    * - Blowfish
   59    *
   60    * - RC2
   61    *
   62    * - ARCFOUR (RC4 compatible)
   63    *
   64    * - Cipher modes ECB, CBC, CFB, OFB, PCBC, CTR, and CTS for all block ciphers
   65    *
   66    * - Cipher padding ISO10126Padding for non-PKCS#5 block ciphers and
   67    *   NoPadding and PKCS5Padding for all block ciphers
   68    *
   69    * - Password-based Encryption (PBE)
   70    *
   71    * - Diffie-Hellman Key Agreement
   72    *
   73    * - HMAC-MD5, HMAC-SHA1, HMAC-SHA-256, HMAC-SHA-384, HMAC-SHA-512
   74    *
   75    */
   76   
   77   public final class SunJCE extends Provider {
   78   
   79       private static final long serialVersionUID = 6812507587804302833L;
   80   
   81       private static final String info = "SunJCE Provider " +
   82       "(implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, "
   83       + "Diffie-Hellman, HMAC)";
   84   
   85       private static final String OID_PKCS12_RC2_40 = "1.2.840.113549.1.12.1.6";
   86       private static final String OID_PKCS12_DESede = "1.2.840.113549.1.12.1.3";
   87       private static final String OID_PKCS5_MD5_DES = "1.2.840.113549.1.5.3";
   88       private static final String OID_PKCS5_PBKDF2 = "1.2.840.113549.1.5.12";
   89       private static final String OID_PKCS3 = "1.2.840.113549.1.3.1";
   90   
   91       /* Are we debugging? -- for developers */
   92       static final boolean debug = false;
   93   
   94       static final SecureRandom RANDOM = new SecureRandom();
   95   
   96       public SunJCE() {
   97           /* We are the "SunJCE" provider */
   98           super("SunJCE", 1.7d, info);
   99   
  100           final String BLOCK_MODES = "ECB|CBC|PCBC|CTR|CTS|CFB|OFB" +
  101               "|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64" +
  102               "|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64";
  103           final String BLOCK_MODES128 = BLOCK_MODES +
  104               "|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128" +
  105               "|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128";
  106           final String BLOCK_PADS = "NOPADDING|PKCS5PADDING|ISO10126PADDING";
  107   
  108           AccessController.doPrivileged(new java.security.PrivilegedAction() {
  109                   public Object run() {
  110   
  111                   /*
  112                    * Cipher engines
  113                    */
  114                   put("Cipher.RSA", "com.sun.crypto.provider.RSACipher");
  115                   put("Cipher.RSA SupportedModes", "ECB");
  116                   put("Cipher.RSA SupportedPaddings",
  117                           "NOPADDING|PKCS1PADDING|OAEPWITHMD5ANDMGF1PADDING"
  118                           + "|OAEPWITHSHA1ANDMGF1PADDING"
  119                           + "|OAEPWITHSHA-1ANDMGF1PADDING"
  120                           + "|OAEPWITHSHA-256ANDMGF1PADDING"
  121                           + "|OAEPWITHSHA-384ANDMGF1PADDING"
  122                           + "|OAEPWITHSHA-512ANDMGF1PADDING");
  123                   put("Cipher.RSA SupportedKeyClasses",
  124                           "java.security.interfaces.RSAPublicKey" +
  125                           "|java.security.interfaces.RSAPrivateKey");
  126   
  127                   put("Cipher.DES", "com.sun.crypto.provider.DESCipher");
  128                   put("Cipher.DES SupportedModes", BLOCK_MODES);
  129                   put("Cipher.DES SupportedPaddings", BLOCK_PADS);
  130                   put("Cipher.DES SupportedKeyFormats", "RAW");
  131   
  132                   put("Cipher.DESede", "com.sun.crypto.provider.DESedeCipher");
  133                   put("Alg.Alias.Cipher.TripleDES", "DESede");
  134                   put("Cipher.DESede SupportedModes", BLOCK_MODES);
  135                   put("Cipher.DESede SupportedPaddings", BLOCK_PADS);
  136                   put("Cipher.DESede SupportedKeyFormats", "RAW");
  137   
  138                   put("Cipher.DESedeWrap",
  139                       "com.sun.crypto.provider.DESedeWrapCipher");
  140                   put("Cipher.DESedeWrap SupportedModes", "CBC");
  141                   put("Cipher.DESedeWrap SupportedPaddings", "NOPADDING");
  142                   put("Cipher.DESedeWrap SupportedKeyFormats", "RAW");
  143   
  144                   put("Cipher.PBEWithMD5AndDES",
  145                       "com.sun.crypto.provider.PBEWithMD5AndDESCipher");
  146                   put("Alg.Alias.Cipher.OID."+OID_PKCS5_MD5_DES,
  147                       "PBEWithMD5AndDES");
  148                   put("Alg.Alias.Cipher."+OID_PKCS5_MD5_DES,
  149                       "PBEWithMD5AndDES");
  150                   put("Cipher.PBEWithMD5AndTripleDES",
  151                       "com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher");
  152                   put("Cipher.PBEWithSHA1AndRC2_40",
  153                       "com.sun.crypto.provider.PKCS12PBECipherCore$" +
  154                       "PBEWithSHA1AndRC2_40");
  155                   put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC2_40,
  156                       "PBEWithSHA1AndRC2_40");
  157                   put("Alg.Alias.Cipher." + OID_PKCS12_RC2_40,
  158                       "PBEWithSHA1AndRC2_40");
  159                   put("Cipher.PBEWithSHA1AndDESede",
  160                       "com.sun.crypto.provider.PKCS12PBECipherCore$" +
  161                       "PBEWithSHA1AndDESede");
  162                   put("Alg.Alias.Cipher.OID." + OID_PKCS12_DESede,
  163                       "PBEWithSHA1AndDESede");
  164                   put("Alg.Alias.Cipher." + OID_PKCS12_DESede,
  165                       "PBEWithSHA1AndDESede");
  166   
  167                   put("Cipher.Blowfish",
  168                       "com.sun.crypto.provider.BlowfishCipher");
  169                   put("Cipher.Blowfish SupportedModes", BLOCK_MODES);
  170                   put("Cipher.Blowfish SupportedPaddings", BLOCK_PADS);
  171                   put("Cipher.Blowfish SupportedKeyFormats", "RAW");
  172   
  173                   put("Cipher.AES", "com.sun.crypto.provider.AESCipher");
  174                   put("Alg.Alias.Cipher.Rijndael", "AES");
  175                   put("Cipher.AES SupportedModes", BLOCK_MODES128);
  176                   put("Cipher.AES SupportedPaddings", BLOCK_PADS);
  177                   put("Cipher.AES SupportedKeyFormats", "RAW");
  178   
  179                   put("Cipher.AESWrap", "com.sun.crypto.provider.AESWrapCipher");
  180                   put("Cipher.AESWrap SupportedModes", "ECB");
  181                   put("Cipher.AESWrap SupportedPaddings", "NOPADDING");
  182                   put("Cipher.AESWrap SupportedKeyFormats", "RAW");
  183   
  184                   put("Cipher.RC2",
  185                       "com.sun.crypto.provider.RC2Cipher");
  186                   put("Cipher.RC2 SupportedModes", BLOCK_MODES);
  187                   put("Cipher.RC2 SupportedPaddings", BLOCK_PADS);
  188                   put("Cipher.RC2 SupportedKeyFormats", "RAW");
  189   
  190                   put("Cipher.ARCFOUR",
  191                       "com.sun.crypto.provider.ARCFOURCipher");
  192                   put("Alg.Alias.Cipher.RC4", "ARCFOUR");
  193                   put("Cipher.ARCFOUR SupportedModes", "ECB");
  194                   put("Cipher.ARCFOUR SupportedPaddings", "NOPADDING");
  195                   put("Cipher.ARCFOUR SupportedKeyFormats", "RAW");
  196   
  197                   /*
  198                    *  Key(pair) Generator engines
  199                    */
  200                   put("KeyGenerator.DES",
  201                       "com.sun.crypto.provider.DESKeyGenerator");
  202   
  203                   put("KeyGenerator.DESede",
  204                       "com.sun.crypto.provider.DESedeKeyGenerator");
  205                   put("Alg.Alias.KeyGenerator.TripleDES", "DESede");
  206   
  207                   put("KeyGenerator.Blowfish",
  208                       "com.sun.crypto.provider.BlowfishKeyGenerator");
  209   
  210                   put("KeyGenerator.AES",
  211                       "com.sun.crypto.provider.AESKeyGenerator");
  212                   put("Alg.Alias.KeyGenerator.Rijndael", "AES");
  213   
  214                   put("KeyGenerator.RC2",
  215                       "com.sun.crypto.provider.KeyGeneratorCore$" +
  216                       "RC2KeyGenerator");
  217                   put("KeyGenerator.ARCFOUR",
  218                       "com.sun.crypto.provider.KeyGeneratorCore$" +
  219                       "ARCFOURKeyGenerator");
  220                   put("Alg.Alias.KeyGenerator.RC4", "ARCFOUR");
  221   
  222                   put("KeyGenerator.HmacMD5",
  223                       "com.sun.crypto.provider.HmacMD5KeyGenerator");
  224   
  225                   put("KeyGenerator.HmacSHA1",
  226                       "com.sun.crypto.provider.HmacSHA1KeyGenerator");
  227   
  228                   put("KeyGenerator.HmacSHA256",
  229                       "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA256KG");
  230                   put("KeyGenerator.HmacSHA384",
  231                       "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA384KG");
  232                   put("KeyGenerator.HmacSHA512",
  233                       "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA512KG");
  234   
  235                   put("KeyPairGenerator.DiffieHellman",
  236                       "com.sun.crypto.provider.DHKeyPairGenerator");
  237                   put("Alg.Alias.KeyPairGenerator.DH", "DiffieHellman");
  238                   put("Alg.Alias.KeyPairGenerator.OID."+OID_PKCS3,
  239                       "DiffieHellman");
  240                   put("Alg.Alias.KeyPairGenerator."+OID_PKCS3,
  241                       "DiffieHellman");
  242                   /*
  243                    * Algorithm parameter generation engines
  244                    */
  245                   put("AlgorithmParameterGenerator.DiffieHellman",
  246                       "com.sun.crypto.provider.DHParameterGenerator");
  247                   put("Alg.Alias.AlgorithmParameterGenerator.DH",
  248                       "DiffieHellman");
  249                   put("Alg.Alias.AlgorithmParameterGenerator.OID."+OID_PKCS3,
  250                       "DiffieHellman");
  251                   put("Alg.Alias.AlgorithmParameterGenerator."+OID_PKCS3,
  252                       "DiffieHellman");
  253   
  254                   /*
  255                    * Key Agreement engines
  256                    */
  257                   put("KeyAgreement.DiffieHellman",
  258                       "com.sun.crypto.provider.DHKeyAgreement");
  259                   put("Alg.Alias.KeyAgreement.DH", "DiffieHellman");
  260                   put("Alg.Alias.KeyAgreement.OID."+OID_PKCS3, "DiffieHellman");
  261                   put("Alg.Alias.KeyAgreement."+OID_PKCS3, "DiffieHellman");
  262   
  263                   put("KeyAgreement.DiffieHellman SupportedKeyClasses",
  264                       "javax.crypto.interfaces.DHPublicKey" +
  265                       "|javax.crypto.interfaces.DHPrivateKey");
  266   
  267                   /*
  268                    * Algorithm Parameter engines
  269                    */
  270                   put("AlgorithmParameters.DiffieHellman",
  271                       "com.sun.crypto.provider.DHParameters");
  272                   put("Alg.Alias.AlgorithmParameters.DH", "DiffieHellman");
  273                   put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS3,
  274                       "DiffieHellman");
  275                   put("Alg.Alias.AlgorithmParameters."+OID_PKCS3,
  276                       "DiffieHellman");
  277   
  278                   put("AlgorithmParameters.DES",
  279                       "com.sun.crypto.provider.DESParameters");
  280   
  281                   put("AlgorithmParameters.DESede",
  282                       "com.sun.crypto.provider.DESedeParameters");
  283                   put("Alg.Alias.AlgorithmParameters.TripleDES", "DESede");
  284   
  285                   put("AlgorithmParameters.PBE",
  286                       "com.sun.crypto.provider.PBEParameters");
  287   
  288                   put("AlgorithmParameters.PBEWithMD5AndDES",
  289                       "com.sun.crypto.provider.PBEParameters");
  290                   put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS5_MD5_DES,
  291                       "PBEWithMD5AndDES");
  292                   put("Alg.Alias.AlgorithmParameters."+OID_PKCS5_MD5_DES,
  293                       "PBEWithMD5AndDES");
  294   
  295                   put("AlgorithmParameters.PBEWithMD5AndTripleDES",
  296                       "com.sun.crypto.provider.PBEParameters");
  297   
  298                   put("AlgorithmParameters.PBEWithSHA1AndDESede",
  299                       "com.sun.crypto.provider.PBEParameters");
  300                   put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_DESede,
  301                       "PBEWithSHA1AndDESede");
  302                   put("Alg.Alias.AlgorithmParameters."+OID_PKCS12_DESede,
  303                       "PBEWithSHA1AndDESede");
  304   
  305                   put("AlgorithmParameters.PBEWithSHA1AndRC2_40",
  306                       "com.sun.crypto.provider.PBEParameters");
  307                   put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC2_40,
  308                       "PBEWithSHA1AndRC2_40");
  309                   put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC2_40,
  310                       "PBEWithSHA1AndRC2_40");
  311   
  312                   put("AlgorithmParameters.Blowfish",
  313                       "com.sun.crypto.provider.BlowfishParameters");
  314   
  315                   put("AlgorithmParameters.AES",
  316                       "com.sun.crypto.provider.AESParameters");
  317                   put("Alg.Alias.AlgorithmParameters.Rijndael", "AES");
  318   
  319   
  320                   put("AlgorithmParameters.RC2",
  321                       "com.sun.crypto.provider.RC2Parameters");
  322   
  323                   put("AlgorithmParameters.OAEP",
  324                       "com.sun.crypto.provider.OAEPParameters");
  325   
  326   
  327                   /*
  328                    * Key factories
  329                    */
  330                   put("KeyFactory.DiffieHellman",
  331                       "com.sun.crypto.provider.DHKeyFactory");
  332                   put("Alg.Alias.KeyFactory.DH", "DiffieHellman");
  333                   put("Alg.Alias.KeyFactory.OID."+OID_PKCS3,
  334                       "DiffieHellman");
  335                   put("Alg.Alias.KeyFactory."+OID_PKCS3, "DiffieHellman");
  336                   /*
  337                    * Secret-key factories
  338                    */
  339                   put("SecretKeyFactory.DES",
  340                       "com.sun.crypto.provider.DESKeyFactory");
  341   
  342                   put("SecretKeyFactory.DESede",
  343                       "com.sun.crypto.provider.DESedeKeyFactory");
  344                   put("Alg.Alias.SecretKeyFactory.TripleDES", "DESede");
  345   
  346                   put("SecretKeyFactory.PBEWithMD5AndDES",
  347                       "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES"
  348                       );
  349                   put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS5_MD5_DES,
  350                       "PBEWithMD5AndDES");
  351                   put("Alg.Alias.SecretKeyFactory."+OID_PKCS5_MD5_DES,
  352                       "PBEWithMD5AndDES");
  353   
  354                   put("Alg.Alias.SecretKeyFactory.PBE",
  355                       "PBEWithMD5AndDES");
  356   
  357                   /*
  358                    * Internal in-house crypto algorithm used for
  359                    * the JCEKS keystore type.  Since this was developed
  360                    * internally, there isn't an OID corresponding to this
  361                    * algorithm.
  362                    */
  363                   put("SecretKeyFactory.PBEWithMD5AndTripleDES",
  364                       "com.sun.crypto.provider.PBEKeyFactory$" +
  365                       "PBEWithMD5AndTripleDES"
  366                       );
  367   
  368                   put("SecretKeyFactory.PBEWithSHA1AndDESede",
  369                       "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede"
  370                       );
  371                   put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS12_DESede,
  372                       "PBEWithSHA1AndDESede");
  373                   put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_DESede,
  374                       "PBEWithSHA1AndDESede");
  375   
  376                   put("SecretKeyFactory.PBEWithSHA1AndRC2_40",
  377                       "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40"
  378                       );
  379                   put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC2_40,
  380                       "PBEWithSHA1AndRC2_40");
  381                   put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC2_40,
  382                       "PBEWithSHA1AndRC2_40");
  383   
  384                   put("SecretKeyFactory.PBKDF2WithHmacSHA1",
  385                       "com.sun.crypto.provider.PBKDF2HmacSHA1Factory");
  386                   put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS5_PBKDF2,
  387                       "PBKDF2WithHmacSHA1");
  388                   put("Alg.Alias.SecretKeyFactory." + OID_PKCS5_PBKDF2,
  389                       "PBKDF2WithHmacSHA1");
  390   
  391                   /*
  392                    * MAC
  393                    */
  394                   put("Mac.HmacMD5", "com.sun.crypto.provider.HmacMD5");
  395                   put("Mac.HmacSHA1", "com.sun.crypto.provider.HmacSHA1");
  396                   put("Mac.HmacSHA256",
  397                       "com.sun.crypto.provider.HmacCore$HmacSHA256");
  398                   put("Mac.HmacSHA384",
  399                       "com.sun.crypto.provider.HmacCore$HmacSHA384");
  400                   put("Mac.HmacSHA512",
  401                       "com.sun.crypto.provider.HmacCore$HmacSHA512");
  402                   put("Mac.HmacPBESHA1",
  403                       "com.sun.crypto.provider.HmacPKCS12PBESHA1");
  404   
  405                   put("Mac.SslMacMD5",
  406                       "com.sun.crypto.provider.SslMacCore$SslMacMD5");
  407                   put("Mac.SslMacSHA1",
  408                       "com.sun.crypto.provider.SslMacCore$SslMacSHA1");
  409   
  410                   put("Mac.HmacMD5 SupportedKeyFormats", "RAW");
  411                   put("Mac.HmacSHA1 SupportedKeyFormats", "RAW");
  412                   put("Mac.HmacSHA256 SupportedKeyFormats", "RAW");
  413                   put("Mac.HmacSHA384 SupportedKeyFormats", "RAW");
  414                   put("Mac.HmacSHA512 SupportedKeyFormats", "RAW");
  415                   put("Mac.HmacPBESHA1 SupportedKeyFormats", "RAW");
  416                   put("Mac.SslMacMD5 SupportedKeyFormats", "RAW");
  417                   put("Mac.SslMacSHA1 SupportedKeyFormats", "RAW");
  418   
  419                   /*
  420                    * KeyStore
  421                    */
  422                   put("KeyStore.JCEKS", "com.sun.crypto.provider.JceKeyStore");
  423   
  424                   /*
  425                    * SSL/TLS mechanisms
  426                    *
  427                    * These are strictly internal implementations and may
  428                    * be changed at any time.  These names were chosen
  429                    * because PKCS11/SunPKCS11 does not yet have TLS1.2
  430                    * mechanisms, and it will cause calls to come here.
  431                    */
  432                   put("KeyGenerator.SunTlsPrf",
  433                           "com.sun.crypto.provider.TlsPrfGenerator$V10");
  434                   put("KeyGenerator.SunTls12Prf",
  435                           "com.sun.crypto.provider.TlsPrfGenerator$V12");
  436   
  437                   put("KeyGenerator.SunTlsMasterSecret",
  438                       "com.sun.crypto.provider.TlsMasterSecretGenerator");
  439                   put("Alg.Alias.KeyGenerator.SunTls12MasterSecret",
  440                       "SunTlsMasterSecret");
  441   
  442                   put("KeyGenerator.SunTlsKeyMaterial",
  443                       "com.sun.crypto.provider.TlsKeyMaterialGenerator");
  444                   put("Alg.Alias.KeyGenerator.SunTls12KeyMaterial",
  445                       "SunTlsKeyMaterial");
  446   
  447                   put("KeyGenerator.SunTlsRsaPremasterSecret",
  448                       "com.sun.crypto.provider.TlsRsaPremasterSecretGenerator");
  449                   put("Alg.Alias.KeyGenerator.SunTls12RsaPremasterSecret",
  450                       "SunTlsRsaPremasterSecret");
  451   
  452                   return null;
  453               }
  454           });
  455       }
  456   }

Save This Page
Home » openjdk-7 » com.sun.crypto » provider » [javadoc | source]