diff --git a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java index 53f2cdff24a..9a8f8a437cc 100644 --- a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java +++ b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java @@ -407,6 +407,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi { byte[] keyBytes = in.getOctetString(); if (keyAlgo.equals(KnownOIDs.OIW_DES_CBC.stdName())) { keyAlgo = "DES"; + } else if (keyAlgo.equals(KnownOIDs.RC2$CBC$PKCS5Padding.stdName())) { + keyAlgo = "RC2"; } SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, keyAlgo); diff --git a/src/java.base/share/classes/sun/security/util/KnownOIDs.java b/src/java.base/share/classes/sun/security/util/KnownOIDs.java index e1f3aeed46d..fe0eccbfad4 100644 --- a/src/java.base/share/classes/sun/security/util/KnownOIDs.java +++ b/src/java.base/share/classes/sun/security/util/KnownOIDs.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -268,7 +268,7 @@ public enum KnownOIDs { HmacSHA512$256("1.2.840.113549.2.13", "HmacSHA512/256"), // encryptionAlgs 1.2.840.113549.3.* - RC2$CBC$PKCS5Padding("1.2.840.113549.3.2", "RC2/CBC/PKCS5Padding"), + RC2$CBC$PKCS5Padding("1.2.840.113549.3.2", "RC2/CBC/PKCS5Padding", "RC2"), ARCFOUR("1.2.840.113549.3.4", "ARCFOUR", "RC4"), DESede$CBC$NoPadding("1.2.840.113549.3.7", "DESede/CBC/NoPadding"), RC5$CBC$PKCS5Padding("1.2.840.113549.3.9", "RC5/CBC/PKCS5Padding"), @@ -427,7 +427,9 @@ public enum KnownOIDs { SkipIPAddress("1.3.6.1.4.1.42.2.11.2.1"), JAVASOFT_JDKKeyProtector("1.3.6.1.4.1.42.2.17.1.1"), JAVASOFT_JCEKeyProtector("1.3.6.1.4.1.42.2.19.1"), - MICROSOFT_ExportApproved("1.3.6.1.4.1.311.10.3.3"); + MICROSOFT_ExportApproved("1.3.6.1.4.1.311.10.3.3"), + + Blowfish("1.3.6.1.4.1.3029.1.1.2"); private String stdName; private String oid; diff --git a/test/jdk/sun/security/pkcs12/DESName.java b/test/jdk/sun/security/pkcs12/SecretKeyAlgorithms.java similarity index 61% rename from test/jdk/sun/security/pkcs12/DESName.java rename to test/jdk/sun/security/pkcs12/SecretKeyAlgorithms.java index 8f21c4a80e5..c32a1957b2f 100644 --- a/test/jdk/sun/security/pkcs12/DESName.java +++ b/test/jdk/sun/security/pkcs12/SecretKeyAlgorithms.java @@ -23,9 +23,9 @@ /* * @test - * @bug 8286024 + * @bug 8286024 8286422 * @library /test/lib - * @summary PKCS12 keystore shows "DES/CBC" as the algorithm of a DES SecretKeyEntry + * @summary PKCS12 keystore should show correct SecretKey algorithm names */ import jdk.test.lib.Asserts; @@ -33,17 +33,30 @@ import jdk.test.lib.Asserts; import javax.crypto.KeyGenerator; import java.security.Key; import java.security.KeyStore; +import java.util.Collections; +import java.util.Map; -public class DESName { +public class SecretKeyAlgorithms { public static void main(String[] args) throws Exception { char[] pass = "changeit".toCharArray(); KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(null, null); - KeyGenerator g = KeyGenerator.getInstance("DES"); - Key k = g.generateKey(); - Asserts.assertEQ(k.getAlgorithm(), "DES"); - ks.setKeyEntry("d", k, pass, null); - k = ks.getKey("d", pass); - Asserts.assertEQ(k.getAlgorithm(), "DES"); + var names = Map.of( + "des", "DES", + "desede", "DESede", + "aes", "AES", + "blowfish", "Blowfish", + "rc2", "RC2", + "arcfour", "ARCFOUR"); + for (var alg : names.entrySet()) { + KeyGenerator g = KeyGenerator.getInstance(alg.getKey()); + Key k = g.generateKey(); + Asserts.assertEQ(k.getAlgorithm(), alg.getValue()); + ks.setKeyEntry(alg.getKey(), k, pass, null); + } + for (var alias : Collections.list(ks.aliases())) { + var k = ks.getKey(alias, pass); + Asserts.assertEQ(k.getAlgorithm(), names.get(alias)); + } } }