use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project sshj by hierynomus.
the class ECDSAPrivateKeyInfoKeyPairConverter method getKeyPair.
/**
* Get PEM Key Pair calculating ECDSA Public Key from ECDSA Private Key Information
*
* @param privateKeyInfo ECDSA Private Key Information
* @return PEM Key Pair
* @throws IOException Thrown on Public Key parsing failures
*/
@Override
public PEMKeyPair getKeyPair(final PrivateKeyInfo privateKeyInfo) throws IOException {
Objects.requireNonNull(privateKeyInfo, "Private Key Info required");
final AlgorithmIdentifier algorithmIdentifier = privateKeyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
if (X9ObjectIdentifiers.id_ecPublicKey.equals(algorithm)) {
logger.debug("ECDSA Algorithm Found [{}]", algorithm);
} else {
throw new IllegalArgumentException(String.format("ECDSA Algorithm OID required [%s]", algorithm));
}
final byte[] encodedPublicKey = getEncodedPublicKey(privateKeyInfo);
final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, encodedPublicKey);
return new PEMKeyPair(subjectPublicKeyInfo, privateKeyInfo);
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project sshj by hierynomus.
the class RSAPrivateKeyInfoKeyPairConverter method getKeyPair.
/**
* Get PEM Key Pair parsing RSA Public Key attributes from RSA Private Key Information
*
* @param privateKeyInfo RSA Private Key Information
* @return PEM Key Pair
* @throws IOException Thrown on Public Key parsing failures
*/
@Override
public PEMKeyPair getKeyPair(final PrivateKeyInfo privateKeyInfo) throws IOException {
Objects.requireNonNull(privateKeyInfo, "Private Key Info required");
final AlgorithmIdentifier algorithmIdentifier = privateKeyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
if (PKCSObjectIdentifiers.rsaEncryption.equals(algorithm)) {
logger.debug("RSA Algorithm Found [{}]", algorithm);
} else {
throw new IllegalArgumentException(String.format("RSA Algorithm OID required [%s]", algorithm));
}
final RSAPublicKey rsaPublicKey = getRsaPublicKey(privateKeyInfo);
final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, rsaPublicKey);
return new PEMKeyPair(subjectPublicKeyInfo, privateKeyInfo);
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project interlok by adaptris.
the class X509Builder method build.
private X509Certificate build() throws NoSuchAlgorithmException, CertificateException, OperatorCreationException {
X509Certificate result = null;
if (privateKey == null) {
createKeyPair();
}
// The certificate is self-signed, so use the current
// subject as the issuer
X500Name name = certificateParm.getSubjectInfo();
// The certificate is self-signed, do we exactly care what
// the serial number that uniquely identifies is
BigInteger serial = BigInteger.valueOf(Integer.valueOf(SecurityUtil.getSecureRandom().nextInt(10000)).longValue());
GregorianCalendar valid = new GregorianCalendar();
Date notBefore = valid.getTime();
valid.add(Calendar.MONTH, 12);
Date notAfter = valid.getTime();
SubjectPublicKeyInfo pubKeyInfo = SubjectPublicKeyInfo.getInstance(ASN1Sequence.getInstance(publicKey.getEncoded()));
X509v3CertificateBuilder certGen = new X509v3CertificateBuilder(name, serial, notBefore, notAfter, name, pubKeyInfo);
String alg = certificateParm.getSignatureAlgorithm();
JcaContentSignerBuilder builder = new JcaContentSignerBuilder(alg);
// build and sign the certificate
X509CertificateHolder certHolder = certGen.build(builder.build(privateKey));
result = new JcaX509CertificateConverter().getCertificate(certHolder);
return result;
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project remoting by jenkinsci.
the class X509CertificateRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
Skip skip = description.getAnnotation(Skip.class);
if (skip != null && (skip.value().length == 0 || Arrays.asList(skip.value()).contains(id))) {
return base;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
Date now = new Date();
Date firstDate = new Date(now.getTime() + startDateOffsetMillis);
Date lastDate = new Date(now.getTime() + endDateOffsetMillis);
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(subjectKey.getPublic().getEncoded());
X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
if (id != null) {
nameBuilder.addRDN(BCStyle.CN, id);
}
X500Name subject = nameBuilder.addRDN(BCStyle.CN, description.getDisplayName()).addRDN(BCStyle.C, "US").build();
X509v3CertificateBuilder certGen = new X509v3CertificateBuilder(subject, BigInteger.ONE, firstDate, lastDate, subject, subjectPublicKeyInfo);
JcaX509ExtensionUtils instance = new JcaX509ExtensionUtils();
certGen.addExtension(Extension.subjectKeyIdentifier, false, instance.createSubjectKeyIdentifier(subjectPublicKeyInfo));
ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider(BOUNCY_CASTLE_PROVIDER).build(X509CertificateRule.this.signerKey.getPrivate());
certificate = new JcaX509CertificateConverter().setProvider(BOUNCY_CASTLE_PROVIDER).getCertificate(certGen.build(signer));
try {
base.evaluate();
} finally {
certificate = null;
}
}
};
}
use of com.android.apksig.internal.x509.SubjectPublicKeyInfo in project hotmoka by Hotmoka.
the class QTESLA3 method verify.
@Override
public boolean verify(T what, PublicKey publicKey, byte[] signature) throws SignatureException {
byte[] bytes;
try {
bytes = supplier.get(what);
} catch (Exception e) {
throw new SignatureException("cannot transform value into bytes before verifying the signature", e);
}
synchronized (signer) {
try {
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(new X509EncodedKeySpec(encodingOf(publicKey)).getEncoded());
signer.init(false, PublicKeyFactory.createKey(subjectPublicKeyInfo));
return signer.verifySignature(bytes, signature);
} catch (Exception e) {
throw new SignatureException("cannot verify signature", e);
}
}
}
Aggregations