blob: ed17511e77c5d1d549687d422dddb117fa5e3276 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.nio.file.Path;
import java.security.KeyPair;
import java.security.cert.X509Certificate;
import static com.yahoo.security.TestUtils.createCertificate;
import static com.yahoo.security.TestUtils.createKeystoreFile;
/**
* @author bjorncs
*/
public class KeyStoreBuilderTest {
private static final char[] PASSWORD = new char[0];
@TempDir
public File tempDirectory;
@Test
void can_create_jks_keystore_from_privatekey_and_certificate() throws Exception {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X509Certificate certificate = createCertificate(keyPair);
KeyStoreBuilder.withType(KeyStoreType.JKS)
.withKeyEntry("key", keyPair.getPrivate(), certificate)
.build();
}
@Test
void can_build_jks_keystore_from_file() throws Exception {
Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.JKS, PASSWORD);
KeyStoreBuilder.withType(KeyStoreType.JKS)
.fromFile(keystoreFile, PASSWORD)
.build();
}
@Test
void can_build_pcks12_keystore_from_file() throws Exception {
Path keystoreFile = File.createTempFile("junit", null, tempDirectory).toPath();
createKeystoreFile(keystoreFile, KeyStoreType.PKCS12, PASSWORD);
KeyStoreBuilder.withType(KeyStoreType.PKCS12)
.fromFile(keystoreFile, PASSWORD)
.build();
}
}
|