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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
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.createKeystore;
import static com.yahoo.security.TestUtils.createKeystoreFile;
/**
* @author bjorncs
*/
public class SslContextBuilderTest {
private static final char[] PASSWORD = new char[0];
@Rule
public TemporaryFolder tempDirectory = new TemporaryFolder();
@Test
public void can_build_sslcontext_with_truststore_only() throws Exception {
new SslContextBuilder()
.withTrustStore(createKeystore(KeyStoreType.JKS, PASSWORD))
.build();
}
@Test
public void can_build_sslcontext_with_keystore_only() throws Exception {
new SslContextBuilder()
.withKeyStore(createKeystore(KeyStoreType.JKS, PASSWORD), PASSWORD)
.build();
}
@Test
public void can_build_sslcontext_with_truststore_and_keystore() throws Exception {
new SslContextBuilder()
.withKeyStore(createKeystore(KeyStoreType.JKS, PASSWORD), PASSWORD)
.withTrustStore(createKeystore(KeyStoreType.JKS, PASSWORD))
.build();
}
@Test
public void can_build_sslcontext_with_keystore_from_private_key_and_certificate() throws Exception {
KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
X509Certificate certificate = createCertificate(keyPair);
new SslContextBuilder()
.withKeyStore(keyPair.getPrivate(), certificate)
.build();
}
@Test
public void can_build_sslcontext_with_jks_keystore_from_file() throws Exception {
Path keystoreFile = tempDirectory.newFile().toPath();
createKeystoreFile(keystoreFile, KeyStoreType.JKS, PASSWORD);
new SslContextBuilder()
.withKeyStore(keystoreFile, PASSWORD, KeyStoreType.JKS)
.build();
}
@Test
public void can_build_sslcontext_with_pcks12_keystore_from_file() throws Exception {
Path keystoreFile = tempDirectory.newFile().toPath();
createKeystoreFile(keystoreFile, KeyStoreType.PKCS12, PASSWORD);
new SslContextBuilder()
.withKeyStore(keystoreFile, PASSWORD, KeyStoreType.PKCS12)
.build();
}
}
|