8237804: sun/security/mscapi tests fail with "Key pair not generated, alias <nnnnnn> already exists"

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2020-02-05 11:09:02 +08:00
parent 029f547700
commit 06579fcefa
2 changed files with 24 additions and 6 deletions

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 8213009 * @bug 8213009 8237804
* @summary Make sure SunMSCAPI keys have correct algorithm names * @summary Make sure SunMSCAPI keys have correct algorithm names
* @requires os.family == "windows" * @requires os.family == "windows"
* @library /test/lib * @library /test/lib
@ -42,6 +42,7 @@ public class KeyAlgorithms {
public static void main(String[] arg) throws Exception { public static void main(String[] arg) throws Exception {
cleanup();
SecurityTools.keytool("-genkeypair", SecurityTools.keytool("-genkeypair",
"-storetype", "Windows-My", "-storetype", "Windows-My",
"-keyalg", ALG, "-keyalg", ALG,
@ -52,13 +53,21 @@ public class KeyAlgorithms {
try { try {
test(loadKeysFromKeyStore()); test(loadKeysFromKeyStore());
} finally { } finally {
cleanup();
}
test(generateKeys());
}
private static void cleanup() {
try {
KeyStore ks = KeyStore.getInstance("Windows-MY"); KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null); ks.load(null, null);
ks.deleteEntry(ALIAS); ks.deleteEntry(ALIAS);
ks.store(null, null); ks.store(null, null);
} catch (Exception e) {
System.out.println("No such entry.");
} }
test(generateKeys());
} }
static KeyPair loadKeysFromKeyStore() throws Exception { static KeyPair loadKeysFromKeyStore() throws Exception {

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 6888925 8180570 * @bug 6888925 8180570 8237804
* @summary SunMSCAPI's Cipher can't use RSA public keys obtained from other sources. * @summary SunMSCAPI's Cipher can't use RSA public keys obtained from other sources.
* @requires os.family == "windows" * @requires os.family == "windows"
* @library /test/lib * @library /test/lib
@ -45,6 +45,7 @@ public class PublicKeyInterop {
public static void main(String[] arg) throws Exception { public static void main(String[] arg) throws Exception {
cleanup();
SecurityTools.keytool("-genkeypair", SecurityTools.keytool("-genkeypair",
"-storetype", "Windows-My", "-storetype", "Windows-My",
"-keyalg", "RSA", "-keyalg", "RSA",
@ -55,10 +56,18 @@ public class PublicKeyInterop {
try { try {
run(); run();
} finally { } finally {
cleanup();
}
}
private static void cleanup() {
try {
KeyStore ks = KeyStore.getInstance("Windows-MY"); KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null); ks.load(null, null);
ks.deleteEntry("6888925"); ks.deleteEntry("6888925");
ks.store(null, null); ks.store(null, null);
} catch (Exception e) {
System.out.println("No such entry.");
} }
} }