aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/KeyStoreOptions.java
blob: fbcaf701c6ff24a25971cd669aa2213a3a31e48e (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
package com.yahoo.vespa.hosted.node.admin.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

class KeyStoreOptions {
    public final Path path;
    public final char[] password;
    public final String type;

    public KeyStoreOptions(Path path, char[] password, String type) {
        this.path = path;
        this.password = password;
        this.type = type;
    }

    public KeyStore getKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
        try (FileInputStream fis = new FileInputStream(path.toFile())) {
            KeyStore keyStore = KeyStore.getInstance(type);
            keyStore.load(fis, password);

            return keyStore;
        }
    }
}