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;
}
}
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);
}
}
Aggregations