@Override public String call() throws Exception { KeyPair kp = SshKeyGen.generateKeyPair(); return SshKeyGen.toPEM(kp); } });
@Override public String call() throws Exception { X509Certificate cert = SshKeyGen.createRootCACert(kp); return SshKeyGen.toPEM(cert); } });
/** * Obtains the fingerprint of the certificate in the "ab:cd:ef:...:12" format. */ public static String getCertificateFingerprint(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); if (cert == null) { return null; } return digest(cert); }
public static String[] generateKeys() throws Exception { KeyPair pair = generateKeyPair(); String publicString = sshRsaTextFormat((RSAPublicKey) pair.getPublic()); return new String[] { publicString, toPEM(pair) }; }
public String getPrivateKey() { RSAPrivateKeyHolder keyHolder = keyProvider.getPrivateKey(); if(keyHolder == null) { return null; } try { return SshKeyGen.toPEM(keyProvider.getPrivateKey().getKey()); } catch (Exception e) { log.error("getPrivateKey: Failed to write PEM", e); return null; } }
public String getPublicKey() { for (Map.Entry<String, PublicKey> entry : keyProvider.getPublicKeys().entrySet()) { try { return SshKeyGen.writePublicKey(entry.getValue()); } catch (Exception e) { log.error("getPublicKey: Failed to write PEM", e); } } return null; }
public static String getSerialNumber(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getSerialNumber().toString(); }
protected String getOptions() { String cert = certDao.getPublicCA(); if (cert == null) { return ""; } try { String fingerprint = SslCertificateUtils.getCertificateFingerprint(cert); return "-e CA_FINGERPRINT=\"" + fingerprint.trim().toUpperCase() + "\" "; } catch (Exception e) { return ""; } }
@Override public CertSet generateCertificate(String subject, String... sans) throws Exception { KeyPair caKp = getKeyPair(); X509Certificate caCert = getCACertificate(); KeyPair clientKp = SshKeyGen.generateKeyPair(); X509Certificate clientCert = SshKeyGen.generateClientCert(subject, clientKp.getPublic(), caKp.getPrivate(), caCert, sans); CertSet result = new CertSet(caCert, clientCert, clientKp.getPrivate()); return result; }
public static KeyPair generateKeyPair() throws Exception { return generateKeyPair(2048); }
protected KeyPair getKeyPair() { String encoded = dataDao.getOrCreate(KEY, false, new Callable<String>() { @Override public String call() throws Exception { KeyPair kp = SshKeyGen.generateKeyPair(); return SshKeyGen.toPEM(kp); } }); try { return SshKeyGen.readKeyPair(encoded); } catch (Exception e) { ExceptionUtils.throwRuntime("Failed to read key pair from PEM", e); /* Won't hit next line */ return null; } }
@Override public X509Certificate getCACertificate() { final KeyPair kp = getKeyPair(); String encoded = dataDao.getOrCreate(CERT, false, new Callable<String>() { @Override public String call() throws Exception { X509Certificate cert = SshKeyGen.createRootCACert(kp); return SshKeyGen.toPEM(cert); } }); try { return SshKeyGen.readCACert(encoded); } catch (Exception e) { ExceptionUtils.throwRuntime("Failed to CA cert from PEM", e); /* Won't hit next line */ return null; } }
public String getPrivateKey() { RSAPrivateKeyHolder keyHolder = keyProvider.getPrivateKey(); if(keyHolder == null) { return null; } try { return SshKeyGen.toPEM(keyProvider.getPrivateKey().getKey()); } catch (Exception e) { log.error("getPrivateKey: Failed to write PEM", e); return null; } }
public String getPublicKey() { for (Map.Entry<String, PublicKey> entry : keyProvider.getPublicKeys().entrySet()) { try { return SshKeyGen.writePublicKey(entry.getValue()); } catch (Exception e) { log.error("getPublicKey: Failed to write PEM", e); } } return null; }
public static String getExpirationDate(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getNotAfter().toString(); }
public static String getIssuedDate(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getNotBefore().toString(); }
public static String getIssuer(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getIssuerX500Principal().getName(); }
public static String getAlgorithm(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getSigAlgName(); }
public static Integer getKeySize(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); PublicKey key = cert.getPublicKey(); if (key instanceof RSAPublicKey) { RSAPublicKey keySpec = (RSAPublicKey) key; return keySpec.getModulus().bitLength(); } return null; }
public static String getVersion(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return String.valueOf(cert.getVersion()); }