use of org.xdi.oxauth.model.crypto.Certificate in project oxAuth by GluuFederation.
the class KeyGenerator method generateU2fAttestationKeys.
public static void generateU2fAttestationKeys(Date startDate, Date expirationDate, String dnName) throws Exception {
ECDSAKeyFactory keyFactory = new ECDSAKeyFactory(SignatureAlgorithm.ES256, null);
Key<ECDSAPrivateKey, ECDSAPublicKey> key = keyFactory.getKey();
Certificate certificate = keyFactory.generateV3Certificate(startDate, expirationDate, dnName);
key.setCertificate(certificate);
key.setKeyType(SignatureAlgorithm.ES256.getFamily());
key.setUse(Use.SIGNATURE.toString());
key.setAlgorithm(SignatureAlgorithm.ES256.getName());
key.setKeyId(UUID.randomUUID().toString());
key.setExpirationTime(expirationDate.getTime());
key.setCurve(SignatureAlgorithm.ES256.getCurve());
JSONObject jsonKey = key.toJSONObject();
System.out.println(jsonKey);
System.out.println("CERTIFICATE:");
System.out.println(certificate);
}
use of org.xdi.oxauth.model.crypto.Certificate in project oxAuth by GluuFederation.
the class ECDSAKeyFactory method generateV3Certificate.
public Certificate generateV3Certificate(Date startDate, Date expirationDate, String dnName) throws CertificateEncodingException, InvalidKeyException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException {
// Create certificate
// serial number for certificate
BigInteger serialNumber = new BigInteger(1024, new Random());
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
X500Principal principal = new X500Principal(dnName);
certGen.setSerialNumber(serialNumber);
certGen.setIssuerDN(principal);
certGen.setNotBefore(startDate);
certGen.setNotAfter(expirationDate);
// note: same as issuer
certGen.setSubjectDN(principal);
certGen.setPublicKey(keyPair.getPublic());
certGen.setSignatureAlgorithm(signatureAlgorithm.getAlgorithm());
X509Certificate x509Certificate = certGen.generate(keyPair.getPrivate(), "BC");
return new Certificate(signatureAlgorithm, x509Certificate);
}
use of org.xdi.oxauth.model.crypto.Certificate in project oxAuth by GluuFederation.
the class SignatureTest method generateES384Keys.
@Test
public void generateES384Keys() throws Exception {
showTitle("TEST: generateES384Keys");
KeyFactory<ECDSAPrivateKey, ECDSAPublicKey> keyFactory = new ECDSAKeyFactory(SignatureAlgorithm.ES384, "CN=Test CA Certificate");
Key<ECDSAPrivateKey, ECDSAPublicKey> key = keyFactory.getKey();
ECDSAPrivateKey privateKey = key.getPrivateKey();
ECDSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
ECDSASigner ecdsaSigner1 = new ECDSASigner(SignatureAlgorithm.ES384, privateKey);
String signature = ecdsaSigner1.generateSignature(signingInput);
ECDSASigner ecdsaSigner2 = new ECDSASigner(SignatureAlgorithm.ES384, publicKey);
assertTrue(ecdsaSigner2.validateSignature(signingInput, signature));
ECDSASigner ecdsaSigner3 = new ECDSASigner(SignatureAlgorithm.ES384, certificate);
assertTrue(ecdsaSigner3.validateSignature(signingInput, signature));
}
use of org.xdi.oxauth.model.crypto.Certificate in project oxAuth by GluuFederation.
the class SignatureTest method generateES256Keys.
@Test
public void generateES256Keys() throws Exception {
showTitle("TEST: generateES256Keys");
KeyFactory<ECDSAPrivateKey, ECDSAPublicKey> keyFactory = new ECDSAKeyFactory(SignatureAlgorithm.ES256, "CN=Test CA Certificate");
Key<ECDSAPrivateKey, ECDSAPublicKey> key = keyFactory.getKey();
ECDSAPrivateKey privateKey = key.getPrivateKey();
ECDSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
ECDSASigner ecdsaSigner1 = new ECDSASigner(SignatureAlgorithm.ES256, privateKey);
String signature = ecdsaSigner1.generateSignature(signingInput);
ECDSASigner ecdsaSigner2 = new ECDSASigner(SignatureAlgorithm.ES256, publicKey);
assertTrue(ecdsaSigner2.validateSignature(signingInput, signature));
ECDSASigner ecdsaSigner3 = new ECDSASigner(SignatureAlgorithm.ES256, certificate);
assertTrue(ecdsaSigner3.validateSignature(signingInput, signature));
}
Aggregations