Skip to content

Commit

Permalink
8237804: sun/security/mscapi tests fail with "Key pair not generated,…
Browse files Browse the repository at this point in the history
… alias <nnnnnn> already exists"

Reviewed-by: mullan
  • Loading branch information
wangweij committed Feb 5, 2020
1 parent 029f547 commit 06579fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
17 changes: 13 additions & 4 deletions test/jdk/sun/security/mscapi/KeyAlgorithms.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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,7 +23,7 @@

/**
* @test
* @bug 8213009
* @bug 8213009 8237804
* @summary Make sure SunMSCAPI keys have correct algorithm names
* @requires os.family == "windows"
* @library /test/lib
Expand All @@ -42,6 +42,7 @@ public class KeyAlgorithms {

public static void main(String[] arg) throws Exception {

cleanup();
SecurityTools.keytool("-genkeypair",
"-storetype", "Windows-My",
"-keyalg", ALG,
Expand All @@ -52,13 +53,21 @@ public static void main(String[] arg) throws Exception {
try {
test(loadKeysFromKeyStore());
} finally {
cleanup();
}

test(generateKeys());
}

private static void cleanup() {
try {
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
ks.deleteEntry(ALIAS);
ks.store(null, null);
} catch (Exception e) {
System.out.println("No such entry.");
}

test(generateKeys());
}

static KeyPair loadKeysFromKeyStore() throws Exception {
Expand Down
13 changes: 11 additions & 2 deletions test/jdk/sun/security/mscapi/PublicKeyInterop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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,7 +23,7 @@

/**
* @test
* @bug 6888925 8180570
* @bug 6888925 8180570 8237804
* @summary SunMSCAPI's Cipher can't use RSA public keys obtained from other sources.
* @requires os.family == "windows"
* @library /test/lib
Expand All @@ -45,6 +45,7 @@ public class PublicKeyInterop {

public static void main(String[] arg) throws Exception {

cleanup();
SecurityTools.keytool("-genkeypair",
"-storetype", "Windows-My",
"-keyalg", "RSA",
Expand All @@ -55,10 +56,18 @@ public static void main(String[] arg) throws Exception {
try {
run();
} finally {
cleanup();
}
}

private static void cleanup() {
try {
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
ks.deleteEntry("6888925");
ks.store(null, null);
} catch (Exception e) {
System.out.println("No such entry.");
}
}

Expand Down

0 comments on commit 06579fc

Please sign in to comment.