src/java.base/share/classes/sun/security/x509/AlgorithmId.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 51216 e429a304c97d
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   180                 algid.equals((Object)SHA_oid) ||
   180                 algid.equals((Object)SHA_oid) ||
   181                 algid.equals((Object)SHA224_oid) ||
   181                 algid.equals((Object)SHA224_oid) ||
   182                 algid.equals((Object)SHA256_oid) ||
   182                 algid.equals((Object)SHA256_oid) ||
   183                 algid.equals((Object)SHA384_oid) ||
   183                 algid.equals((Object)SHA384_oid) ||
   184                 algid.equals((Object)SHA512_oid) ||
   184                 algid.equals((Object)SHA512_oid) ||
       
   185                 algid.equals((Object)SHA512_224_oid) ||
       
   186                 algid.equals((Object)SHA512_256_oid) ||
   185                 algid.equals((Object)DSA_oid) ||
   187                 algid.equals((Object)DSA_oid) ||
   186                 algid.equals((Object)sha1WithDSA_oid)) {
   188                 algid.equals((Object)sha1WithDSA_oid)) {
   187                 ; // no parameter part encoded
   189                 ; // no parameter part encoded
   188             } else {
   190             } else {
   189                 bytes.putNull();
   191                 bytes.putNull();
   481         }
   483         }
   482         if (name.equalsIgnoreCase("SHA-224") ||
   484         if (name.equalsIgnoreCase("SHA-224") ||
   483             name.equalsIgnoreCase("SHA224")) {
   485             name.equalsIgnoreCase("SHA224")) {
   484             return AlgorithmId.SHA224_oid;
   486             return AlgorithmId.SHA224_oid;
   485         }
   487         }
   486 
   488         if (name.equalsIgnoreCase("SHA-512/224") ||
       
   489             name.equalsIgnoreCase("SHA512/224")) {
       
   490             return AlgorithmId.SHA512_224_oid;
       
   491         }
       
   492         if (name.equalsIgnoreCase("SHA-512/256") ||
       
   493             name.equalsIgnoreCase("SHA512/256")) {
       
   494             return AlgorithmId.SHA512_256_oid;
       
   495         }
   487         // Various public key algorithms
   496         // Various public key algorithms
   488         if (name.equalsIgnoreCase("RSA")) {
   497         if (name.equalsIgnoreCase("RSA")) {
   489             return AlgorithmId.RSAEncryption_oid;
   498             return AlgorithmId.RSAEncryption_oid;
       
   499         }
       
   500         if (name.equalsIgnoreCase("RSASSA-PSS")) {
       
   501             return AlgorithmId.RSASSA_PSS_oid;
       
   502         }
       
   503         if (name.equalsIgnoreCase("RSAES-OAEP")) {
       
   504             return AlgorithmId.RSAES_OAEP_oid;
   490         }
   505         }
   491         if (name.equalsIgnoreCase("Diffie-Hellman")
   506         if (name.equalsIgnoreCase("Diffie-Hellman")
   492             || name.equalsIgnoreCase("DH")) {
   507             || name.equalsIgnoreCase("DH")) {
   493             return AlgorithmId.DH_oid;
   508             return AlgorithmId.DH_oid;
   494         }
   509         }
   646     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2});
   661     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2});
   647 
   662 
   648     public static final ObjectIdentifier SHA512_oid =
   663     public static final ObjectIdentifier SHA512_oid =
   649     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 3});
   664     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 3});
   650 
   665 
       
   666     public static final ObjectIdentifier SHA512_224_oid =
       
   667     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 5});
       
   668 
       
   669     public static final ObjectIdentifier SHA512_256_oid =
       
   670     ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 6});
       
   671 
   651     /*
   672     /*
   652      * COMMON PUBLIC KEY TYPES
   673      * COMMON PUBLIC KEY TYPES
   653      */
   674      */
   654     private static final int[] DH_data = { 1, 2, 840, 113549, 1, 3, 1 };
   675     private static final int[] DH_data = { 1, 2, 840, 113549, 1, 3, 1 };
   655     private static final int[] DH_PKIX_data = { 1, 2, 840, 10046, 2, 1 };
   676     private static final int[] DH_PKIX_data = { 1, 2, 840, 10046, 2, 1 };
   656     private static final int[] DSA_OIW_data = { 1, 3, 14, 3, 2, 12 };
   677     private static final int[] DSA_OIW_data = { 1, 3, 14, 3, 2, 12 };
   657     private static final int[] DSA_PKIX_data = { 1, 2, 840, 10040, 4, 1 };
   678     private static final int[] DSA_PKIX_data = { 1, 2, 840, 10040, 4, 1 };
   658     private static final int[] RSA_data = { 2, 5, 8, 1, 1 };
   679     private static final int[] RSA_data = { 2, 5, 8, 1, 1 };
   659     private static final int[] RSAEncryption_data =
       
   660                                  { 1, 2, 840, 113549, 1, 1, 1 };
       
   661 
   680 
   662     public static final ObjectIdentifier DH_oid;
   681     public static final ObjectIdentifier DH_oid;
   663     public static final ObjectIdentifier DH_PKIX_oid;
   682     public static final ObjectIdentifier DH_PKIX_oid;
   664     public static final ObjectIdentifier DSA_oid;
   683     public static final ObjectIdentifier DSA_oid;
   665     public static final ObjectIdentifier DSA_OIW_oid;
   684     public static final ObjectIdentifier DSA_OIW_oid;
   666     public static final ObjectIdentifier EC_oid = oid(1, 2, 840, 10045, 2, 1);
   685     public static final ObjectIdentifier EC_oid = oid(1, 2, 840, 10045, 2, 1);
   667     public static final ObjectIdentifier ECDH_oid = oid(1, 3, 132, 1, 12);
   686     public static final ObjectIdentifier ECDH_oid = oid(1, 3, 132, 1, 12);
   668     public static final ObjectIdentifier RSA_oid;
   687     public static final ObjectIdentifier RSA_oid;
   669     public static final ObjectIdentifier RSAEncryption_oid;
   688     public static final ObjectIdentifier RSAEncryption_oid =
       
   689                                             oid(1, 2, 840, 113549, 1, 1, 1);
       
   690     public static final ObjectIdentifier RSAES_OAEP_oid =
       
   691                                             oid(1, 2, 840, 113549, 1, 1, 7);
       
   692     public static final ObjectIdentifier RSASSA_PSS_oid =
       
   693                                             oid(1, 2, 840, 113549, 1, 1, 10);
   670 
   694 
   671     /*
   695     /*
   672      * COMMON SECRET KEY TYPES
   696      * COMMON SECRET KEY TYPES
   673      */
   697      */
   674     public static final ObjectIdentifier AES_oid =
   698     public static final ObjectIdentifier AES_oid =
   691                                        { 1, 2, 840, 113549, 1, 1, 11 };
   715                                        { 1, 2, 840, 113549, 1, 1, 11 };
   692     private static final int[] sha384WithRSAEncryption_data =
   716     private static final int[] sha384WithRSAEncryption_data =
   693                                        { 1, 2, 840, 113549, 1, 1, 12 };
   717                                        { 1, 2, 840, 113549, 1, 1, 12 };
   694     private static final int[] sha512WithRSAEncryption_data =
   718     private static final int[] sha512WithRSAEncryption_data =
   695                                        { 1, 2, 840, 113549, 1, 1, 13 };
   719                                        { 1, 2, 840, 113549, 1, 1, 13 };
       
   720 
   696     private static final int[] shaWithDSA_OIW_data =
   721     private static final int[] shaWithDSA_OIW_data =
   697                                        { 1, 3, 14, 3, 2, 13 };
   722                                        { 1, 3, 14, 3, 2, 13 };
   698     private static final int[] sha1WithDSA_OIW_data =
   723     private static final int[] sha1WithDSA_OIW_data =
   699                                        { 1, 3, 14, 3, 2, 27 };
   724                                        { 1, 3, 14, 3, 2, 27 };
   700     private static final int[] dsaWithSHA1_PKIX_data =
   725     private static final int[] dsaWithSHA1_PKIX_data =
   706     public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid;
   731     public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid;
   707     public static final ObjectIdentifier sha224WithRSAEncryption_oid;
   732     public static final ObjectIdentifier sha224WithRSAEncryption_oid;
   708     public static final ObjectIdentifier sha256WithRSAEncryption_oid;
   733     public static final ObjectIdentifier sha256WithRSAEncryption_oid;
   709     public static final ObjectIdentifier sha384WithRSAEncryption_oid;
   734     public static final ObjectIdentifier sha384WithRSAEncryption_oid;
   710     public static final ObjectIdentifier sha512WithRSAEncryption_oid;
   735     public static final ObjectIdentifier sha512WithRSAEncryption_oid;
       
   736     public static final ObjectIdentifier sha512_224WithRSAEncryption_oid =
       
   737                                             oid(1, 2, 840, 113549, 1, 1, 15);
       
   738     public static final ObjectIdentifier sha512_256WithRSAEncryption_oid =
       
   739                                             oid(1, 2, 840, 113549, 1, 1, 16);;
       
   740 
   711     public static final ObjectIdentifier shaWithDSA_OIW_oid;
   741     public static final ObjectIdentifier shaWithDSA_OIW_oid;
   712     public static final ObjectIdentifier sha1WithDSA_OIW_oid;
   742     public static final ObjectIdentifier sha1WithDSA_OIW_oid;
   713     public static final ObjectIdentifier sha1WithDSA_oid;
   743     public static final ObjectIdentifier sha1WithDSA_oid;
   714     public static final ObjectIdentifier sha224WithDSA_oid =
   744     public static final ObjectIdentifier sha224WithDSA_oid =
   715                                             oid(2, 16, 840, 1, 101, 3, 4, 3, 1);
   745                                             oid(2, 16, 840, 1, 101, 3, 4, 3, 1);
   795      * OID = 2.5.8.1.1
   825      * OID = 2.5.8.1.1
   796      */
   826      */
   797         RSA_oid = ObjectIdentifier.newInternal(RSA_data);
   827         RSA_oid = ObjectIdentifier.newInternal(RSA_data);
   798 
   828 
   799     /**
   829     /**
   800      * Algorithm ID for RSA keys used with RSA encryption, as defined
       
   801      * in PKCS #1.  There are no parameters associated with this algorithm.
       
   802      * OID = 1.2.840.113549.1.1.1
       
   803      */
       
   804         RSAEncryption_oid = ObjectIdentifier.newInternal(RSAEncryption_data);
       
   805 
       
   806     /**
       
   807      * Identifies a signing algorithm where an MD2 digest is encrypted
   830      * Identifies a signing algorithm where an MD2 digest is encrypted
   808      * using an RSA private key; defined in PKCS #1.  Use of this
   831      * using an RSA private key; defined in PKCS #1.  Use of this
   809      * signing algorithm is discouraged due to MD2 vulnerabilities.
   832      * signing algorithm is discouraged due to MD2 vulnerabilities.
   810      * OID = 1.2.840.113549.1.1.2
   833      * OID = 1.2.840.113549.1.1.2
   811      */
   834      */
   896         nameTable.put(SHA_oid, "SHA-1");
   919         nameTable.put(SHA_oid, "SHA-1");
   897         nameTable.put(SHA224_oid, "SHA-224");
   920         nameTable.put(SHA224_oid, "SHA-224");
   898         nameTable.put(SHA256_oid, "SHA-256");
   921         nameTable.put(SHA256_oid, "SHA-256");
   899         nameTable.put(SHA384_oid, "SHA-384");
   922         nameTable.put(SHA384_oid, "SHA-384");
   900         nameTable.put(SHA512_oid, "SHA-512");
   923         nameTable.put(SHA512_oid, "SHA-512");
       
   924         nameTable.put(SHA512_224_oid, "SHA-512/224");
       
   925         nameTable.put(SHA512_256_oid, "SHA-512/256");
   901         nameTable.put(RSAEncryption_oid, "RSA");
   926         nameTable.put(RSAEncryption_oid, "RSA");
   902         nameTable.put(RSA_oid, "RSA");
   927         nameTable.put(RSA_oid, "RSA");
   903         nameTable.put(DH_oid, "Diffie-Hellman");
   928         nameTable.put(DH_oid, "Diffie-Hellman");
   904         nameTable.put(DH_PKIX_oid, "Diffie-Hellman");
   929         nameTable.put(DH_PKIX_oid, "Diffie-Hellman");
   905         nameTable.put(DSA_oid, "DSA");
   930         nameTable.put(DSA_oid, "DSA");
   925         nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA");
   950         nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA");
   926         nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA");
   951         nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA");
   927         nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA");
   952         nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA");
   928         nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA");
   953         nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA");
   929         nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA");
   954         nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA");
       
   955         nameTable.put(sha512_224WithRSAEncryption_oid, "SHA512/224withRSA");
       
   956         nameTable.put(sha512_256WithRSAEncryption_oid, "SHA512/256withRSA");
       
   957         nameTable.put(RSASSA_PSS_oid, "RSASSA-PSS");
       
   958         nameTable.put(RSAES_OAEP_oid, "RSAES-OAEP");
       
   959 
   930         nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES");
   960         nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES");
   931         nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2");
   961         nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2");
   932         nameTable.put(pbeWithSHA1AndDES_oid, "PBEWithSHA1AndDES");
   962         nameTable.put(pbeWithSHA1AndDES_oid, "PBEWithSHA1AndDES");
   933         nameTable.put(pbeWithSHA1AndRC2_oid, "PBEWithSHA1AndRC2");
   963         nameTable.put(pbeWithSHA1AndRC2_oid, "PBEWithSHA1AndRC2");
   934         nameTable.put(pbeWithSHA1AndDESede_oid, "PBEWithSHA1AndDESede");
   964         nameTable.put(pbeWithSHA1AndDESede_oid, "PBEWithSHA1AndDESede");