8183348: Better cleanup for jdk/test/sun/security/pkcs12/P12SecretKey.java
Reviewed-by: rhalade, weijun
This commit is contained in:
parent
4d2d12987f
commit
03f0ec4a35
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2025, 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
|
||||||
@ -25,6 +25,7 @@
|
|||||||
* @test
|
* @test
|
||||||
* @bug 8149411 8007632
|
* @bug 8149411 8007632
|
||||||
* @summary Get AES key from keystore (uses SecretKeySpec not SecretKeyFactory)
|
* @summary Get AES key from keystore (uses SecretKeySpec not SecretKeyFactory)
|
||||||
|
* @library /test/lib
|
||||||
* @run main P12SecretKey pkcs12 AES 128
|
* @run main P12SecretKey pkcs12 AES 128
|
||||||
* @run main P12SecretKey pkcs12 DES 56
|
* @run main P12SecretKey pkcs12 DES 56
|
||||||
* @run main P12SecretKey pkcs12 DESede 168
|
* @run main P12SecretKey pkcs12 DESede 168
|
||||||
@ -33,14 +34,14 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.crypto.KeyGenerator;
|
import javax.crypto.KeyGenerator;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
|
import static jdk.test.lib.Utils.createTempFile;
|
||||||
|
|
||||||
public class P12SecretKey {
|
public class P12SecretKey {
|
||||||
|
|
||||||
private static final String ALIAS = "alias";
|
private static final String ALIAS = "alias";
|
||||||
@ -66,9 +67,14 @@ public class P12SecretKey {
|
|||||||
KeyStore.ProtectionParameter kspp = new KeyStore.PasswordProtection(pw);
|
KeyStore.ProtectionParameter kspp = new KeyStore.PasswordProtection(pw);
|
||||||
ks.setEntry(ALIAS, ske, kspp);
|
ks.setEntry(ALIAS, ske, kspp);
|
||||||
|
|
||||||
File ksFile = File.createTempFile("test", ".test");
|
// temporary files are created in scratch directory
|
||||||
|
final File ksFile = createTempFile(
|
||||||
|
String.format("%s-%s-%d-",
|
||||||
|
keystoreType,
|
||||||
|
algName,
|
||||||
|
keySize),
|
||||||
|
".ks").toFile();
|
||||||
|
|
||||||
try {
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(ksFile)) {
|
try (FileOutputStream fos = new FileOutputStream(ksFile)) {
|
||||||
ks.store(fos, pw);
|
ks.store(fos, pw);
|
||||||
fos.flush();
|
fos.flush();
|
||||||
@ -84,12 +90,9 @@ public class P12SecretKey {
|
|||||||
System.err.println("OK: worked just fine with " + keystoreType +
|
System.err.println("OK: worked just fine with " + keystoreType +
|
||||||
" keystore");
|
" keystore");
|
||||||
} else {
|
} else {
|
||||||
System.err.println("ERROR: keys are NOT equal after storing in "
|
throw new RuntimeException("ERROR: keys are NOT equal after storing in "
|
||||||
+ keystoreType + " keystore");
|
+ keystoreType + " keystore");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
Files.deleteIfExists(ksFile.toPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user