Search in sources :

Example 1 with PublicKeyEntry

use of com.yahoo.athenz.zts.PublicKeyEntry in project athenz by yahoo.

the class ZTSMock method getPublicKeyEntry.

@Override
public PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId) {
    PublicKeyEntry keyEntry = null;
    if ("2".equals(keyId)) {
        keyEntry = new PublicKeyEntry();
        Path path = Paths.get("./src/test/resources/zts_public_k1.pem");
        keyEntry.setId(keyId);
        try {
            keyEntry.setKey(Crypto.ybase64(Files.readAllBytes(path)));
        } catch (IOException e) {
        }
    }
    if (keyEntry == null) {
        throw new ZTSClientException(404, "Unknown ZTS Public Key");
    } else {
        return keyEntry;
    }
}
Also used : PublicKeyEntry(com.yahoo.athenz.zts.PublicKeyEntry) Path(java.nio.file.Path) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) IOException(java.io.IOException)

Example 2 with PublicKeyEntry

use of com.yahoo.athenz.zts.PublicKeyEntry in project athenz by yahoo.

the class ZTSTLSClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String domainName = cmd.getOptionValue("domain").toLowerCase();
    final String serviceName = cmd.getOptionValue("service").toLowerCase();
    final String keyId = cmd.getOptionValue("keyid").toLowerCase();
    final String ztsUrl = cmd.getOptionValue("ztsurl");
    final String keyPath = cmd.getOptionValue("key");
    final String certPath = cmd.getOptionValue("cert");
    final String trustStorePath = cmd.getOptionValue("trustStorePath");
    final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
    final String proxyUrl = cmd.getOptionValue("proxy");
    try {
        KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
        SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
        try (ZTSClient ztsClient = new ZTSClient(ztsUrl, proxyUrl, sslContext)) {
            try {
                PublicKeyEntry publicKey = ztsClient.getPublicKeyEntry(domainName, serviceName, keyId);
                System.out.println("PublicKey: " + publicKey.getKey());
            } catch (ZTSClientException ex) {
                System.out.println("Unable to retrieve public key: " + ex.getMessage());
                System.exit(2);
            }
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : PublicKeyEntry(com.yahoo.athenz.zts.PublicKeyEntry) CommandLine(org.apache.commons.cli.CommandLine) ZTSClient(com.yahoo.athenz.zts.ZTSClient) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) SSLContext(javax.net.ssl.SSLContext) KeyRefresher(com.oath.auth.KeyRefresher) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

PublicKeyEntry (com.yahoo.athenz.zts.PublicKeyEntry)2 ZTSClientException (com.yahoo.athenz.zts.ZTSClientException)2 KeyRefresher (com.oath.auth.KeyRefresher)1 ZTSClient (com.yahoo.athenz.zts.ZTSClient)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 SSLContext (javax.net.ssl.SSLContext)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1