Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions test/jdk/sun/security/rsa/TestCACerts.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, 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 @@ -21,20 +21,27 @@
* questions.
*/

/**
/*
* @test
* @bug 4853305
* @summary Test the new RSA provider can verify all the RSA certs in the cacerts file
* @author Andreas Sterbenz
* @library /test/lib/
*/

// this test serves as our known answer test

import java.io.*;
import java.util.*;
import jtreg.SkippedException;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.PublicKey;
import java.security.KeyStore;
import java.security.cert.X509Certificate;

import java.security.*;
import java.security.cert.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class TestCACerts {

Expand All @@ -51,6 +58,9 @@ public static void main(String[] args) throws Exception {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(in, null);
in.close();

final List<String> skippedCases = new ArrayList<>();

for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
String alias = (String)e.nextElement();
if (ks.isCertificateEntry(alias)) {
Expand All @@ -65,10 +75,17 @@ public static void main(String[] args) throws Exception {
System.out.println("Skipping cert with key: " + alg);
}
} else {
skippedCases.add(String.format("[alias: %s]",
alias));
System.out.println("Skipping alias " + alias);
}
}
long stop = System.currentTimeMillis();

if (!skippedCases.isEmpty()) {
throw new SkippedException("Some tests were skipped " +
skippedCases);
}
System.out.println("All tests passed (" + (stop - start) + " ms).");
}

Expand Down
29 changes: 21 additions & 8 deletions test/jdk/sun/security/rsa/TestSigGen15.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, 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 @@ -21,14 +21,17 @@
* questions.
*/

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import jtreg.SkippedException;

import java.io.IOException;
import java.io.InputStreamReader;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.util.ArrayList;
import java.util.HexFormat;
import java.util.List;
Expand All @@ -37,15 +40,19 @@
* @test
* @bug 8146293
* @summary Known Answer Tests based on NIST 186-3 at:
* @library /test/lib/
* @compile SigRecord.java
* @run main/othervm TestSigGen15
*/

public class TestSigGen15 {

private static final String[] testFiles = {
"SigGen15_186-3.txt", "SigGen15_186-3_TruncatedSHAs.txt"
};

private static final List<String> skippedAlgs = new ArrayList<>();

public static void main(String[] args) throws Exception {
boolean success = true;
for (String f : testFiles) {
Expand All @@ -62,6 +69,11 @@ public static void main(String[] args) throws Exception {
if (!success) {
throw new RuntimeException("One or more test failed");
}

if (!skippedAlgs.isEmpty()) {
throw new SkippedException("Some algorithms were skipped " +
skippedAlgs);
}
System.out.println("Test passed");
}

Expand Down Expand Up @@ -100,6 +112,7 @@ static boolean check(PrivateKey privKey, PublicKey pubKey,
} catch (NoSuchAlgorithmException e) {
System.out.println("\tSkip " + sigAlgo +
" due to no support");
skippedAlgs.add(sigAlgo);
continue;
}
byte[] msgBytes = HexFormat.of().parseHex(v.msg);
Expand Down
43 changes: 39 additions & 4 deletions test/jdk/sun/security/rsa/pss/SignatureTest2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, 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 @@ -20,11 +20,33 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.security.*;
import jtreg.SkippedException;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.PSSParameterSpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import static javax.crypto.Cipher.PRIVATE_KEY;
import static javax.crypto.Cipher.PUBLIC_KEY;
Expand All @@ -35,6 +57,7 @@
* @summary Create a signature for RSASSA-PSS and get its signed data.
* re-initiate the signature with the public key. The signature
* can be verified by acquired signed data.
* @library /test/lib/
* @run main SignatureTest2 768
* @run main SignatureTest2 1024
* @run main SignatureTest2 1025
Expand Down Expand Up @@ -75,8 +98,10 @@ public class SignatureTest2 {

private static final String SIG_ALG = "RSASSA-PSS";

private static final List<String> skippedAlgs = new ArrayList<>();

private static PSSParameterSpec genPSSParameter(String digestAlgo,
int digestLen, int keySize) {
int digestLen, int keySize) {
// pick a salt length based on the key length and digestAlgo
int saltLength = keySize/8 - digestLen - 2;
if (saltLength < 0) {
Expand Down Expand Up @@ -109,6 +134,10 @@ public static void main(String[] args) throws Exception {
}
)));

if (!skippedAlgs.isEmpty()) {
throw new SkippedException("Some algorithms were skipped " +
skippedAlgs);
}
}

private static KeyPair generateKeys(String keyalg, int size)
Expand Down Expand Up @@ -151,6 +180,12 @@ private static void checkSignature(byte[] data, PublicKey pub,
int digestLen = MessageDigest.getInstance(digestAlg).getDigestLength();
PSSParameterSpec params = genPSSParameter(digestAlg, digestLen, keySize);
if (params == null) {
skippedAlgs.add(
String.format("[digestAlg: %s, digestLen: %d, " +
"keysize: %d]",
digestAlg,
digestLen,
keySize));
System.out.println("Skip test due to short key size");
return;
}
Expand Down
24 changes: 17 additions & 7 deletions test/jdk/sun/security/rsa/pss/TestSigGenPSS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, 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 @@ -21,16 +21,28 @@
* questions.
*/

import jtreg.SkippedException;

import java.io.IOException;
import java.security.*;
import java.security.spec.*;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.SecureRandom;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PSSParameterSpec;
import java.util.HexFormat;
import java.util.List;

/*
* @test
* @bug 8146293
* @summary Known Answer Tests based on NIST 186-3 at:
* @library /test/lib/
* @compile SigRecord.java
* @run main/othervm TestSigGenPSS
*/
Expand Down Expand Up @@ -61,16 +73,14 @@ public void nextBytes(byte[] bytes) {
}

public static void main(String[] args) throws Exception {
//for (Provider provider : Security.getProviders()) {
Provider p = Security.getProvider(
System.getProperty("test.provider.name", "SunRsaSign"));
Signature sig;
try {
sig = Signature.getInstance("RSASSA-PSS", p);
} catch (NoSuchAlgorithmException e) {
System.out.println("Skip testing RSASSA-PSS" +
" due to no support");
return;
throw new SkippedException("Skip testing RSASSA-PSS" +
" due to no support");
}

boolean success = true;
Expand Down