Skip to content

Commit

Permalink
8007632: DES/3DES keys support in PKCS12 keystore
Browse files Browse the repository at this point in the history
Reviewed-by: weijun
  • Loading branch information
Alexey Bakhtin authored and wangweij committed Oct 27, 2020
1 parent a023b93 commit 7a7ce02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/java.base/share/classes/sun/security/util/KnownOIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public enum KnownOIDs {
ECDH("1.3.132.1.12"),

// OIW secsig 1.3.14.3.*
OIW_DES_CBC("1.3.14.3.2.7", "DES/CBC"),
OIW_DES_CBC("1.3.14.3.2.7", "DES/CBC", "DES"),

OIW_DSA("1.3.14.3.2.12", "DSA") {
@Override
Expand All @@ -371,6 +371,8 @@ public enum KnownOIDs {
boolean registerNames() { return false; }
},

DESede("1.3.14.3.2.17", "DESede"),

SHA_1("1.3.14.3.2.26", "SHA-1", "SHA", "SHA1"),

OIW_SHA1withDSA("1.3.14.3.2.27", "SHA1withDSA") {
Expand Down
22 changes: 12 additions & 10 deletions test/jdk/sun/security/pkcs12/P12SecretKey.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
Expand All @@ -23,8 +23,11 @@

/*
* @test
* @bug 8149411
* @bug 8149411 8007632
* @summary Get AES key from keystore (uses SecretKeySpec not SecretKeyFactory)
* @run main P12SecretKey pkcs12 AES 128
* @run main P12SecretKey pkcs12 DES 56
* @run main P12SecretKey pkcs12 DESede 168
*/

import java.io.File;
Expand All @@ -43,20 +46,19 @@ public class P12SecretKey {

public static void main(String[] args) throws Exception {
P12SecretKey testp12 = new P12SecretKey();
String keystoreType = "pkcs12";
if (args != null && args.length > 0) {
keystoreType = args[0];
}
testp12.run(keystoreType);
String keystoreType = args[0];
String algName = args[1];
int keySize = Integer.parseInt(args[2]);
testp12.run(keystoreType, algName, keySize);
}

private void run(String keystoreType) throws Exception {
private void run(String keystoreType, String algName, int keySize) throws Exception {
char[] pw = "password".toCharArray();
KeyStore ks = KeyStore.getInstance(keystoreType);
ks.load(null, pw);

KeyGenerator kg = KeyGenerator.getInstance("AES");
kg.init(128);
KeyGenerator kg = KeyGenerator.getInstance(algName);
kg.init(keySize);
SecretKey key = kg.generateKey();

KeyStore.SecretKeyEntry ske = new KeyStore.SecretKeyEntry(key);
Expand Down

1 comment on commit 7a7ce02

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 7a7ce02 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.