8206258: [Test Error] sun/security/pkcs11 tests fail if NSS libs not found

Improve the logics on skipping test

Reviewed-by: valeriep
This commit is contained in:
John Jiang 2018-07-26 08:46:27 +08:00
parent d2b2780859
commit 126394f271
9 changed files with 98 additions and 54 deletions

View File

@ -154,7 +154,15 @@ public abstract class PKCS11Test {
public abstract void main(Provider p) throws Exception; public abstract void main(Provider p) throws Exception;
protected boolean skipTest(Provider p) {
return false;
}
private void premain(Provider p) throws Exception { private void premain(Provider p) throws Exception {
if (skipTest(p)) {
return;
}
// set a security manager and policy before a test case runs, // set a security manager and policy before a test case runs,
// and disable them after the test case finished // and disable them after the test case finished
try { try {
@ -327,9 +335,10 @@ public abstract class PKCS11Test {
} }
static boolean isBadNSSVersion(Provider p) { static boolean isBadNSSVersion(Provider p) {
if (isNSS(p) && badNSSVersion) { double nssVersion = getNSSVersion();
if (isNSS(p) && nssVersion >= 3.11 && nssVersion < 3.12) {
System.out.println("NSS 3.11 has a DER issue that recent " + System.out.println("NSS 3.11 has a DER issue that recent " +
"version do not."); "version do not, skipping");
return true; return true;
} }
return false; return false;
@ -667,9 +676,6 @@ public abstract class PKCS11Test {
private final static char[] hexDigits = "0123456789abcdef".toCharArray(); private final static char[] hexDigits = "0123456789abcdef".toCharArray();
static final boolean badNSSVersion =
getNSSVersion() >= 3.11 && getNSSVersion() < 3.12;
private static final String distro = distro(); private static final String distro = distro();
static final boolean badSolarisSparc = static final boolean badSolarisSparc =

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. * Copyright (c) 2017, 2018, Red Hat, Inc. and/or its affiliates.
* *
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
@ -66,7 +66,9 @@ public final class TestNssDbSqlite extends SecmodTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
initialize(); if (!initialize()) {
return;
}
if (enableDebug) { if (enableDebug) {
System.out.println("SunPKCS11 provider: " + System.out.println("SunPKCS11 provider: " +
@ -108,14 +110,15 @@ public final class TestNssDbSqlite extends SecmodTest {
} }
} }
private static void initialize() throws Exception { private static boolean initialize() throws Exception {
initializeProvider(); return initializeProvider();
} }
private static void initializeProvider () throws Exception { private static boolean initializeProvider() throws Exception {
useSqlite(true); useSqlite(true);
if (!initSecmod()) { if (!initSecmod()) {
return; System.out.println("Cannot init security module database, skipping");
return false;
} }
sunPKCS11NSSProvider = getSunPKCS11(BASE + SEP + "nss-sqlite.cfg"); sunPKCS11NSSProvider = getSunPKCS11(BASE + SEP + "nss-sqlite.cfg");
@ -132,5 +135,7 @@ public final class TestNssDbSqlite extends SecmodTest {
gen.generate(2048); gen.generate(2048);
privateKey = gen.getPrivateKey(); privateKey = gen.getPrivateKey();
certificate = gen.getSelfCertificate(new X500Name("CN=Me"), 365); certificate = gen.getSelfCertificate(new X500Name("CN=Me"), 365);
return true;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2018, 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
@ -47,12 +47,17 @@ public class TestDSAKeyLength extends PKCS11Test {
} }
@Override @Override
public void main(Provider provider) throws Exception { protected boolean skipTest(Provider provider) {
if (isNSS(provider) && getNSSVersion() >= 3.14) { if (isNSS(provider) && getNSSVersion() >= 3.14) {
System.out.println("Skip testing NSS " + getNSSVersion()); System.out.println("Skip testing NSS " + getNSSVersion());
return; return true;
} }
return false;
}
@Override
public void main(Provider provider) throws Exception {
/* /*
* Use Solaris SPARC 11.2 or later to avoid an intermittent failure * Use Solaris SPARC 11.2 or later to avoid an intermittent failure
* when running SunPKCS11-Solaris (8044554) * when running SunPKCS11-Solaris (8044554)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2018, 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
@ -51,20 +51,21 @@ public class TestCurves extends PKCS11Test {
} }
@Override @Override
public void main(Provider p) throws Exception { protected boolean skipTest(Provider p) {
if (p.getService("KeyAgreement", "ECDH") == null) { if (p.getService("KeyAgreement", "ECDH") == null) {
System.out.println("Not supported by provider, skipping"); System.out.println("Not supported by provider, skipping");
return; return true;
} }
if (isBadNSSVersion(p)) { if (isBadNSSVersion(p) || isBadSolarisSparc(p)) {
return; return true;
} }
if (isBadSolarisSparc(p)) { return false;
return; }
}
@Override
public void main(Provider p) throws Exception {
// Check if this is sparc for later failure avoidance. // Check if this is sparc for later failure avoidance.
boolean sparc = false; boolean sparc = false;
if (props.getProperty("os.arch").equals("sparcv9")) { if (props.getProperty("os.arch").equals("sparcv9")) {

View File

@ -91,17 +91,22 @@ public class TestECDH extends PKCS11Test {
private final static String privBrainpoolP512r1b = "3062020100301406072a8648ce3d020106092b240303020801010d044730450201010440230e18e1bcc88a362fa54e4ea3902009292f7f8033624fd471b5d8ace49d12cfabbc19963dab8e2f1eba00bffb29e4d72d13f2224562f405cb80503666b25429"; private final static String privBrainpoolP512r1b = "3062020100301406072a8648ce3d020106092b240303020801010d044730450201010440230e18e1bcc88a362fa54e4ea3902009292f7f8033624fd471b5d8ace49d12cfabbc19963dab8e2f1eba00bffb29e4d72d13f2224562f405cb80503666b25429";
private final static String secretBrainpoolP512r1 = "a7927098655f1f9976fa50a9d566865dc530331846381c87256baf3226244b76d36403c024d7bbf0aa0803eaff405d3d24f11a9b5c0bef679fe1454b21c4cd1f"; private final static String secretBrainpoolP512r1 = "a7927098655f1f9976fa50a9d566865dc530331846381c87256baf3226244b76d36403c024d7bbf0aa0803eaff405d3d24f11a9b5c0bef679fe1454b21c4cd1f";
@Override public void main(Provider p) throws Exception { @Override
protected boolean skipTest(Provider p) {
if (p.getService("KeyAgreement", "ECDH") == null) { if (p.getService("KeyAgreement", "ECDH") == null) {
System.out.println("Provider does not support ECDH, skipping"); System.out.println("Provider does not support ECDH, skipping");
return; return true;
} }
if (isNSS(p) && getNSSECC() == ECCState.Basic) { if (isNSS(p) && getNSSECC() == ECCState.Basic) {
System.out.println("NSS only supports Basic ECC. Skipping.."); System.out.println("NSS only supports Basic ECC, skipping");
return; return true;
} }
return false;
}
@Override public void main(Provider p) throws Exception {
/* /*
* PKCS11Test.main will remove this provider if needed * PKCS11Test.main will remove this provider if needed
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2018, 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
@ -111,16 +111,21 @@ public class TestECDH2 extends PKCS11Test {
} }
@Override @Override
public void main(Provider provider) throws Exception { protected boolean skipTest(Provider provider) {
if (provider.getService("KeyAgreement", "ECDH") == null) { if (provider.getService("KeyAgreement", "ECDH") == null) {
System.out.println("ECDH not supported, skipping"); System.out.println("ECDH not supported, skipping");
return; return true;
} }
if (isBadNSSVersion(provider)) { if (isBadNSSVersion(provider)) {
return; return true;
} }
return false;
}
@Override
public void main(Provider provider) throws Exception {
kf = KeyFactory.getInstance("EC", provider); kf = KeyFactory.getInstance("EC", provider);
kpg = KeyPairGenerator.getInstance("EC", provider); kpg = KeyPairGenerator.getInstance("EC", provider);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2018, 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
@ -120,21 +120,22 @@ public class TestECDSA extends PKCS11Test {
} }
@Override @Override
public void main(Provider provider) throws Exception { protected boolean skipTest(Provider provider) {
long start = System.currentTimeMillis();
if (provider.getService("Signature", "SHA1withECDSA") == null) { if (provider.getService("Signature", "SHA1withECDSA") == null) {
System.out.println("ECDSA not supported, skipping"); System.out.println("ECDSA not supported, skipping");
return; return true;
} }
if (isBadNSSVersion(provider)) { if (isBadNSSVersion(provider) || isBadSolarisSparc(provider)) {
return; return true;
} }
if (isBadSolarisSparc(provider)) { return false;
return; }
}
@Override
public void main(Provider provider) throws Exception {
long start = System.currentTimeMillis();
/* /*
* PKCS11Test.main will remove this provider if needed * PKCS11Test.main will remove this provider if needed

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2018, 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
@ -101,6 +101,26 @@ public class TestECDSA2 extends PKCS11Test {
main(new TestECDSA2(), args); main(new TestECDSA2(), args);
} }
@Override
protected boolean skipTest(Provider provider) {
boolean testP256 =
provider.getService("Signature", "SHA256withECDSA") != null;
boolean testP384 =
provider.getService("Signature", "SHA384withECDSA") != null;
if (!testP256 && !testP384) {
System.out.println("ECDSA not supported, skipping");
return true;
}
if (isBadNSSVersion(provider)) {
return true;
}
return false;
}
@Override @Override
public void main(Provider provider) throws Exception { public void main(Provider provider) throws Exception {
boolean testP256 = boolean testP256 =
@ -109,15 +129,6 @@ public class TestECDSA2 extends PKCS11Test {
boolean testP384 = boolean testP384 =
(provider.getService("Signature", "SHA384withECDSA") != null); (provider.getService("Signature", "SHA384withECDSA") != null);
if (!testP256 && !testP384) {
System.out.println("ECDSA not supported, skipping");
return;
}
if (isBadNSSVersion(provider)) {
return;
}
kf = KeyFactory.getInstance("EC", provider); kf = KeyFactory.getInstance("EC", provider);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2018, 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
@ -47,16 +47,21 @@ public class TestECGenSpec extends PKCS11Test {
} }
@Override @Override
public void main(Provider p) throws Exception { protected boolean skipTest(Provider p) {
if (p.getService("Signature", "SHA1withECDSA") == null) { if (p.getService("Signature", "SHA1withECDSA") == null) {
System.out.println("Provider does not support ECDSA, skipping..."); System.out.println("Provider does not support ECDSA, skipping...");
return; return true;
} }
if (isBadNSSVersion(p)) { if (isBadNSSVersion(p)) {
return; return true;
} }
return false;
}
@Override
public void main(Provider p) throws Exception {
String[] names = { "secp256r1", "NIST P-192", "sect163k1", "1.3.132.0.26", String[] names = { "secp256r1", "NIST P-192", "sect163k1", "1.3.132.0.26",
"X9.62 c2tnb239v1"}; "X9.62 c2tnb239v1"};
int curves = 1; int curves = 1;