8143377: Test PKCS8Test.java fails

Reviewed-by: weijun
This commit is contained in:
Amanda Jiang 2015-11-25 09:42:34 +08:00
parent da87510683
commit 32b34954c2
2 changed files with 15 additions and 25 deletions

View File

@ -217,9 +217,6 @@ java/rmi/activation/Activatable/extLoadedImpl/ext.sh generic-all
# jdk_security
# 8143377
sun/security/pkcs/pkcs8/PKCS8Test.java solaris-all
# 7157786
sun/security/pkcs11/ec/TestKeyFactory.java generic-all

View File

@ -25,6 +25,7 @@
* @test
* @bug 8048357
* @summary PKCS8 Standards Conformance Tests
* @requires (os.family != "solaris")
* @modules java.base/sun.security.pkcs
* java.base/sun.security.util
* java.base/sun.security.provider
@ -33,6 +34,11 @@
* @compile -XDignore.symbol.file PKCS8Test.java
* @run main PKCS8Test
*/
/*
* Skip Solaris since the DSAPrivateKeys returned by
* SunPKCS11 Provider are not subclasses of PKCS8Key
*/
import java.io.IOException;
import java.math.BigInteger;
import java.security.InvalidKeyException;
@ -43,7 +49,6 @@ import sun.security.provider.DSAPrivateKey;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
import sun.security.x509.AlgorithmId;
import static java.lang.System.out;
public class PKCS8Test {
@ -191,7 +196,14 @@ public class PKCS8Test {
public static void main(String[] args)
throws IOException, InvalidKeyException {
byte[] encodedKey = getEncodedKey();
BigInteger p = BigInteger.valueOf(1);
BigInteger q = BigInteger.valueOf(2);
BigInteger g = BigInteger.valueOf(3);
BigInteger x = BigInteger.valueOf(4);
DSAPrivateKey priv = new DSAPrivateKey(p, q, g, x);
byte[] encodedKey = priv.getEncoded();
byte[] expectedBytes = new byte[EXPECTED.length];
for (int i = 0; i < EXPECTED.length; i++) {
expectedBytes[i] = (byte) EXPECTED[i];
@ -203,6 +215,7 @@ public class PKCS8Test {
}
PKCS8Key decodedKey = PKCS8Key.parse(new DerValue(encodedKey));
String alg = decodedKey.getAlgorithm();
AlgorithmId algId = decodedKey.getAlgorithmId();
out.println("Algorithm :" + alg);
@ -265,30 +278,10 @@ public class PKCS8Test {
+ EXCEPTION_MESSAGE + " get: " + e.getMessage());
}
}
}
// get a byte array from somewhere
static byte[] getEncodedKey() throws InvalidKeyException {
BigInteger p = BigInteger.valueOf(1);
BigInteger q = BigInteger.valueOf(2);
BigInteger g = BigInteger.valueOf(3);
BigInteger x = BigInteger.valueOf(4);
DSAPrivateKey priv = new DSAPrivateKey(p, q, g, x);
return priv.getEncoded();
}
static void dumpByteArray(String nm, byte[] bytes) throws IOException {
out.println(nm + " length: " + bytes.length);
hexDump.encodeBuffer(bytes, out);
}
static String toString(PKCS8Key key) {
StringBuilder builder = new StringBuilder(key.getAlgorithm());
builder.append('\n').append("parameters:")
.append(key.getAlgorithmId().toString());
return builder.toString();
}
}