Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8349533: Refactor validator tests shell files to java #23727

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
myankelev committed Feb 24, 2025
commit aef7091ba2c7a4842bce40e9ef453e830f42aa8d
34 changes: 16 additions & 18 deletions test/jdk/sun/security/validator/CertReplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @library /test/lib
* @modules java.base/sun.security.validator
*
* @run main/othervm CertReplace certreplace.jks certreplace.certs
* @run main CertReplace certreplace.jks certreplace.certs
*/

/*
Expand Down Expand Up @@ -102,20 +102,17 @@ private static void certReplace() throws Exception {
"-outfile int.cert");

//putting the certificate in the keystore
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");

final FileInputStream certInputStream = new FileInputStream("int.cert");
final Certificate[] certs = new Certificate[]{
CertUtils.getCertFromStream(
certInputStream
)
};
certInputStream.close();

final PrivateKey privateKey = (PrivateKey) keyStore.getKey("int", PASSWORD_CHAR_ARR);
keyStore.setKeyEntry("int", privateKey, PASSWORD_CHAR_ARR, certs);
keyStore.store(new FileOutputStream(CERTREPLACE_JKS), PASSWORD_CHAR_ARR);

try (final FileInputStream certInputStream = new FileInputStream("int.cert")) {
final Certificate[] certs = new Certificate[]{
CertUtils.getCertFromStream(
certInputStream
)
};

final PrivateKey privateKey = (PrivateKey) keyStore.getKey("int", PASSWORD_CHAR_ARR);
keyStore.setKeyEntry("int", privateKey, PASSWORD_CHAR_ARR, certs);
keyStore.store(new FileOutputStream(CERTREPLACE_JKS), PASSWORD_CHAR_ARR);
}

SecurityTools.keytool(ktBaseParameters +
"-certreq -alias user -file user.req");
Expand Down Expand Up @@ -168,8 +165,6 @@ private static void sameDn() throws Exception {
SecurityTools.keytool(ktBaseParameters +
"-genkeypair -alias user -dname CN=User -keyalg rsa");

final KeyStore keyStore = KeyStoreUtils.loadKeyStore(SAMEDN_JKS, PASSWORD);

// 2. Signing: ca -> user. The startdate is set to 1 minute in the past to ensure the certificate
// is valid at the time of validation and to prevent any issues with timing discrepancies
// Automatically saves the certs to the certs files
Expand All @@ -184,6 +179,7 @@ private static void sameDn() throws Exception {
"-startdate -1M -infile user.req -outfile samedn2.certs");

// 3. Remove user for cacerts
final KeyStore keyStore = KeyStoreUtils.loadKeyStore(SAMEDN_JKS, PASSWORD);
keyStore.deleteEntry("user");
keyStore.store(new FileOutputStream(CERTREPLACE_JKS), PASSWORD_CHAR_ARR);
}
Expand All @@ -202,7 +198,9 @@ public static void main(String[] args) throws Exception {
}

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(args[0]), "changeit".toCharArray());
try (final FileInputStream certInputStream = new FileInputStream(args[0])) {
ks.load(certInputStream, PASSWORD_CHAR_ARR);
}
Validator v = Validator.getInstance
(Validator.TYPE_PKIX, Validator.VAR_GENERIC, ks);
X509Certificate[] chain = createPath(args[1]);
Expand Down