554
555 // See if any of the installed providers supply a mapping from
556 // the given algorithm name to an OID string
557 String oidString;
558 if (!initOidTable) {
559 Provider[] provs = Security.getProviders();
560 for (int i=0; i<provs.length; i++) {
561 for (Enumeration<Object> enum_ = provs[i].keys();
562 enum_.hasMoreElements(); ) {
563 String alias = (String)enum_.nextElement();
564 String upperCaseAlias = alias.toUpperCase(Locale.ENGLISH);
565 int index;
566 if (upperCaseAlias.startsWith("ALG.ALIAS") &&
567 (index=upperCaseAlias.indexOf("OID.", 0)) != -1) {
568 index += "OID.".length();
569 if (index == alias.length()) {
570 // invalid alias entry
571 break;
572 }
573 if (oidTable == null) {
574 oidTable = new HashMap<String,ObjectIdentifier>();
575 }
576 oidString = alias.substring(index);
577 String stdAlgName = provs[i].getProperty(alias);
578 if (stdAlgName != null) {
579 stdAlgName = stdAlgName.toUpperCase(Locale.ENGLISH);
580 }
581 if (stdAlgName != null &&
582 oidTable.get(stdAlgName) == null) {
583 oidTable.put(stdAlgName,
584 new ObjectIdentifier(oidString));
585 }
586 }
587 }
588 }
589
590 if (oidTable == null) {
591 oidTable = new HashMap<String,ObjectIdentifier>(1);
592 }
593 initOidTable = true;
594 }
595
596 return oidTable.get(name.toUpperCase(Locale.ENGLISH));
597 }
598
599 private static ObjectIdentifier oid(int ... values) {
600 return ObjectIdentifier.newInternal(values);
601 }
602
603 private static boolean initOidTable = false;
604 private static Map<String,ObjectIdentifier> oidTable;
605 private static final Map<ObjectIdentifier,String> nameTable;
606
607 /*****************************************************************/
608
609 /*
610 * HASHING ALGORITHMS
611 */
870 * SHA digest is signed using the Digital Signing Algorithm (DSA).
871 * This should not be used.
872 * OID = 1.3.14.3.2.13
873 */
874 shaWithDSA_OIW_oid = ObjectIdentifier.newInternal(shaWithDSA_OIW_data);
875
876 /**
877 * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
878 * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
879 * OID = 1.3.14.3.2.27
880 */
881 sha1WithDSA_OIW_oid = ObjectIdentifier.newInternal(sha1WithDSA_OIW_data);
882
883 /**
884 * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
885 * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
886 * OID = 1.2.840.10040.4.3
887 */
888 sha1WithDSA_oid = ObjectIdentifier.newInternal(dsaWithSHA1_PKIX_data);
889
890 nameTable = new HashMap<ObjectIdentifier,String>();
891 nameTable.put(MD5_oid, "MD5");
892 nameTable.put(MD2_oid, "MD2");
893 nameTable.put(SHA_oid, "SHA-1");
894 nameTable.put(SHA224_oid, "SHA-224");
895 nameTable.put(SHA256_oid, "SHA-256");
896 nameTable.put(SHA384_oid, "SHA-384");
897 nameTable.put(SHA512_oid, "SHA-512");
898 nameTable.put(RSAEncryption_oid, "RSA");
899 nameTable.put(RSA_oid, "RSA");
900 nameTable.put(DH_oid, "Diffie-Hellman");
901 nameTable.put(DH_PKIX_oid, "Diffie-Hellman");
902 nameTable.put(DSA_oid, "DSA");
903 nameTable.put(DSA_OIW_oid, "DSA");
904 nameTable.put(EC_oid, "EC");
905 nameTable.put(ECDH_oid, "ECDH");
906
907 nameTable.put(AES_oid, "AES");
908
909 nameTable.put(sha1WithECDSA_oid, "SHA1withECDSA");
910 nameTable.put(sha224WithECDSA_oid, "SHA224withECDSA");
|
554
555 // See if any of the installed providers supply a mapping from
556 // the given algorithm name to an OID string
557 String oidString;
558 if (!initOidTable) {
559 Provider[] provs = Security.getProviders();
560 for (int i=0; i<provs.length; i++) {
561 for (Enumeration<Object> enum_ = provs[i].keys();
562 enum_.hasMoreElements(); ) {
563 String alias = (String)enum_.nextElement();
564 String upperCaseAlias = alias.toUpperCase(Locale.ENGLISH);
565 int index;
566 if (upperCaseAlias.startsWith("ALG.ALIAS") &&
567 (index=upperCaseAlias.indexOf("OID.", 0)) != -1) {
568 index += "OID.".length();
569 if (index == alias.length()) {
570 // invalid alias entry
571 break;
572 }
573 if (oidTable == null) {
574 oidTable = new HashMap<>();
575 }
576 oidString = alias.substring(index);
577 String stdAlgName = provs[i].getProperty(alias);
578 if (stdAlgName != null) {
579 stdAlgName = stdAlgName.toUpperCase(Locale.ENGLISH);
580 }
581 if (stdAlgName != null &&
582 oidTable.get(stdAlgName) == null) {
583 oidTable.put(stdAlgName,
584 new ObjectIdentifier(oidString));
585 }
586 }
587 }
588 }
589
590 if (oidTable == null) {
591 oidTable = new HashMap<>(1);
592 }
593 initOidTable = true;
594 }
595
596 return oidTable.get(name.toUpperCase(Locale.ENGLISH));
597 }
598
599 private static ObjectIdentifier oid(int ... values) {
600 return ObjectIdentifier.newInternal(values);
601 }
602
603 private static boolean initOidTable = false;
604 private static Map<String,ObjectIdentifier> oidTable;
605 private static final Map<ObjectIdentifier,String> nameTable;
606
607 /*****************************************************************/
608
609 /*
610 * HASHING ALGORITHMS
611 */
870 * SHA digest is signed using the Digital Signing Algorithm (DSA).
871 * This should not be used.
872 * OID = 1.3.14.3.2.13
873 */
874 shaWithDSA_OIW_oid = ObjectIdentifier.newInternal(shaWithDSA_OIW_data);
875
876 /**
877 * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
878 * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
879 * OID = 1.3.14.3.2.27
880 */
881 sha1WithDSA_OIW_oid = ObjectIdentifier.newInternal(sha1WithDSA_OIW_data);
882
883 /**
884 * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
885 * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
886 * OID = 1.2.840.10040.4.3
887 */
888 sha1WithDSA_oid = ObjectIdentifier.newInternal(dsaWithSHA1_PKIX_data);
889
890 nameTable = new HashMap<>();
891 nameTable.put(MD5_oid, "MD5");
892 nameTable.put(MD2_oid, "MD2");
893 nameTable.put(SHA_oid, "SHA-1");
894 nameTable.put(SHA224_oid, "SHA-224");
895 nameTable.put(SHA256_oid, "SHA-256");
896 nameTable.put(SHA384_oid, "SHA-384");
897 nameTable.put(SHA512_oid, "SHA-512");
898 nameTable.put(RSAEncryption_oid, "RSA");
899 nameTable.put(RSA_oid, "RSA");
900 nameTable.put(DH_oid, "Diffie-Hellman");
901 nameTable.put(DH_PKIX_oid, "Diffie-Hellman");
902 nameTable.put(DSA_oid, "DSA");
903 nameTable.put(DSA_OIW_oid, "DSA");
904 nameTable.put(EC_oid, "EC");
905 nameTable.put(ECDH_oid, "ECDH");
906
907 nameTable.put(AES_oid, "AES");
908
909 nameTable.put(sha1WithECDSA_oid, "SHA1withECDSA");
910 nameTable.put(sha224WithECDSA_oid, "SHA224withECDSA");
|