use of com.yahoo.athenz.zts.ZTSClientException in project athenz by yahoo.
the class ZTSAWSCredsClient method retrieveAWSTempCreds.
private static boolean retrieveAWSTempCreds(AWSCredentialsProvider awsCredProvider) {
try {
for (int i = 0; i < 120; i++) {
AWSCredentials awsCreds = awsCredProvider.getCredentials();
if (awsCreds == null) {
System.out.println("Error: AWS Credentials are not available");
return false;
}
System.out.println("AWS Temporary Credentials:\n");
System.out.println("\tAccess Key Id : " + awsCreds.getAWSAccessKeyId());
System.out.println("\tSecret Key : " + awsCreds.getAWSSecretKey());
try {
Thread.sleep(60000);
} catch (InterruptedException ex) {
}
}
} catch (ZTSClientException ex) {
System.out.println("Unable to retrieve AWS credentials: " + ex.getMessage());
return false;
}
return true;
}
use of com.yahoo.athenz.zts.ZTSClientException in project athenz by yahoo.
the class InstanceClientRegister method main.
public static void main(String[] args) throws MalformedURLException, IOException {
// parse our command line to retrieve required input
CommandLine cmd = parseCommandLine(args);
String domainName = cmd.getOptionValue("domain").toLowerCase();
String serviceName = cmd.getOptionValue("service").toLowerCase();
String provider = cmd.getOptionValue("provider").toLowerCase();
String instance = cmd.getOptionValue("instance");
String dnsSuffix = cmd.getOptionValue("dnssuffix");
String providerKeyPath = cmd.getOptionValue("providerkey");
String providerKeyId = cmd.getOptionValue("providerkeyid");
String instanceKeyPath = cmd.getOptionValue("instancekey");
String ztsUrl = cmd.getOptionValue("ztsurl");
// get our configured private key
PrivateKey providerKey = Crypto.loadPrivateKey(new File(providerKeyPath));
// first we are going to generate our attestation data
// which we are going to use jwt. ZTS Server will send
// this object to the specified provider for validation
String compactJws = Jwts.builder().setSubject(domainName + "." + serviceName).setIssuer(provider).setAudience("zts").setId(instance).setExpiration(new Date(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES))).setHeaderParam("keyId", providerKeyId).signWith(SignatureAlgorithm.RS256, providerKey).compact();
System.out.println("JWS: \n" + compactJws + "\n");
// now we need to generate our CSR so we can get
// a TLS certificate for our instance
PrivateKey instanceKey = Crypto.loadPrivateKey(new File(instanceKeyPath));
String csr = generateCSR(domainName, serviceName, instance, dnsSuffix, instanceKey);
if (csr == null) {
System.err.println("Unable to generate CSR for instance");
System.exit(1);
}
System.out.println("CSR: \n" + csr + "\n");
// now let's generate our instance register object that will be sent
// to the ZTS Server
InstanceRegisterInformation info = new InstanceRegisterInformation().setAttestationData(compactJws).setDomain(domainName).setService(serviceName).setProvider(provider).setToken(true).setCsr(csr);
// now contact zts server to request identity for instance
InstanceIdentity identity = null;
Map<String, List<String>> responseHeaders = new HashMap<>();
try (ZTSClient ztsClient = new ZTSClient(ztsUrl)) {
identity = ztsClient.postInstanceRegisterInformation(info, responseHeaders);
} catch (ZTSClientException ex) {
System.out.println("Unable to register instance: " + ex.getMessage());
System.exit(2);
}
System.out.println("Identity TLS Certificate: \n" + identity.getX509Certificate());
Map<String, String> attrs = identity.getAttributes();
if (attrs != null) {
System.out.println("Provider Attributes:");
for (String key : attrs.keySet()) {
System.out.println("\t" + key + ": " + attrs.get(key));
}
}
}
use of com.yahoo.athenz.zts.ZTSClientException 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.ZTSClientException 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);
}
}
use of com.yahoo.athenz.zts.ZTSClientException in project athenz by yahoo.
the class InstanceClientRefresh method main.
public static void main(String[] args) throws MalformedURLException, IOException {
// parse our command line to retrieve required input
CommandLine cmd = parseCommandLine(args);
String domainName = cmd.getOptionValue("domain").toLowerCase();
String serviceName = cmd.getOptionValue("service").toLowerCase();
String provider = cmd.getOptionValue("provider").toLowerCase();
String instance = cmd.getOptionValue("instance");
String dnsSuffix = cmd.getOptionValue("dnssuffix");
String instanceKeyPath = cmd.getOptionValue("instancekey");
String ztsUrl = cmd.getOptionValue("ztsurl");
// now we need to generate our CSR so we can get
// a TLS certificate for our instance
PrivateKey instanceKey = Crypto.loadPrivateKey(new File(instanceKeyPath));
String csr = generateCSR(domainName, serviceName, instance, dnsSuffix, instanceKey);
if (csr == null) {
System.err.println("Unable to generate CSR for instance");
System.exit(1);
}
System.out.println("CSR: \n" + csr + "\n");
// now let's generate our instance refresh object that will be sent
// to the ZTS Server
InstanceRefreshInformation info = new InstanceRefreshInformation().setToken(true).setCsr(csr);
// now contact zts server to request identity for instance
InstanceIdentity identity = null;
try (ZTSClient ztsClient = new ZTSClient(ztsUrl)) {
identity = ztsClient.postInstanceRefreshInformation(provider, domainName, serviceName, instance, info);
} catch (ZTSClientException ex) {
System.out.println("Unable to register instance: " + ex.getMessage());
System.exit(2);
}
System.out.println("Identity TLS Certificate: \n" + identity.getX509Certificate());
}
Aggregations