use of com.github.zhenwei.core.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DDistributionPointsChooser method okPressed.
private void okPressed() {
DistributionPointName distributionPointName;
ReasonFlags reasonFlags = null;
int reasons = 0;
if (jcbKeyCompromise.isSelected()) {
reasons = reasons | ReasonFlags.keyCompromise;
}
if (jcbCACompromise.isSelected()) {
reasons = reasons | ReasonFlags.cACompromise;
}
if (jcbAffiliationChanged.isSelected()) {
reasons = reasons | ReasonFlags.affiliationChanged;
}
if (jcbSuperseded.isSelected()) {
reasons = reasons | ReasonFlags.superseded;
}
if (jcbCessationOfOperation.isSelected()) {
reasons = reasons | ReasonFlags.cessationOfOperation;
}
if (jcbCertificateHold.isSelected()) {
reasons = reasons | ReasonFlags.certificateHold;
}
if (jcbPrivilegeWithdrawn.isSelected()) {
reasons = reasons | ReasonFlags.privilegeWithdrawn;
}
if (jcbAACompromise.isSelected()) {
reasons = reasons | ReasonFlags.aACompromise;
}
if (reasons > 0) {
reasonFlags = new ReasonFlags(reasons);
}
if (jgnDistributionPointFullName.getGeneralNames().getNames().length == 0) {
JOptionPane.showMessageDialog(this, res.getString("DDistributionPointsChooser.DistributionPointFullNameNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
} else {
distributionPointName = new DistributionPointName(jgnDistributionPointFullName.getGeneralNames());
}
GeneralNames cRLIssuer = null;
if (jgnDistributionPointCrlIssuer.getGeneralNames().getNames().length > 0) {
cRLIssuer = jgnDistributionPointCrlIssuer.getGeneralNames();
}
distributionPoint = new DistributionPoint(distributionPointName, reasonFlags, cRLIssuer);
closeDialog();
}
use of com.github.zhenwei.core.asn1.x509.GeneralNames in project zookeeper by apache.
the class QuorumSSLTest method buildEndEntityCert.
public X509Certificate buildEndEntityCert(KeyPair keyPair, X509Certificate caCert, PrivateKey caPrivateKey, String hostname, String ipAddress, String crlPath, Integer ocspPort) throws Exception {
X509CertificateHolder holder = new JcaX509CertificateHolder(caCert);
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(caPrivateKey);
List<GeneralName> generalNames = new ArrayList<>();
if (hostname != null) {
generalNames.add(new GeneralName(GeneralName.dNSName, hostname));
}
if (ipAddress != null) {
generalNames.add(new GeneralName(GeneralName.iPAddress, ipAddress));
}
SubjectPublicKeyInfo entityKeyInfo = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(PublicKeyFactory.createKey(keyPair.getPublic().getEncoded()));
X509ExtensionUtils extensionUtils = new BcX509ExtensionUtils();
JcaX509v3CertificateBuilder jcaX509v3CertificateBuilder = new JcaX509v3CertificateBuilder(holder.getSubject(), new BigInteger(128, new Random()), certStartTime, certEndTime, new X500Name("CN=Test End Entity Certificate"), keyPair.getPublic());
X509v3CertificateBuilder certificateBuilder = jcaX509v3CertificateBuilder.addExtension(Extension.authorityKeyIdentifier, false, extensionUtils.createAuthorityKeyIdentifier(holder)).addExtension(Extension.subjectKeyIdentifier, false, extensionUtils.createSubjectKeyIdentifier(entityKeyInfo)).addExtension(Extension.basicConstraints, true, new BasicConstraints(false)).addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
if (!generalNames.isEmpty()) {
certificateBuilder.addExtension(Extension.subjectAlternativeName, true, new GeneralNames(generalNames.toArray(new GeneralName[] {})));
}
if (crlPath != null) {
DistributionPointName distPointOne = new DistributionPointName(new GeneralNames(new GeneralName(GeneralName.uniformResourceIdentifier, "file://" + crlPath)));
certificateBuilder.addExtension(Extension.cRLDistributionPoints, false, new CRLDistPoint(new DistributionPoint[] { new DistributionPoint(distPointOne, null, null) }));
}
if (ocspPort != null) {
certificateBuilder.addExtension(Extension.authorityInfoAccess, false, new AuthorityInformationAccess(X509ObjectIdentifiers.ocspAccessMethod, new GeneralName(GeneralName.uniformResourceIdentifier, "http://" + hostname + ":" + ocspPort)));
}
return new JcaX509CertificateConverter().getCertificate(certificateBuilder.build(signer));
}
use of com.github.zhenwei.core.asn1.x509.GeneralNames in project jmulticard by ctt-gob-es.
the class X509CRLHolder method init.
private void init(CertificateList x509CRL) {
this.x509CRL = x509CRL;
this.extensions = x509CRL.getTBSCertList().getExtensions();
this.isIndirect = isIndirectCRL(extensions);
this.issuerName = new GeneralNames(new GeneralName(x509CRL.getIssuer()));
}
use of com.github.zhenwei.core.asn1.x509.GeneralNames in project signer by demoiselle.
the class SigningCertificate method getValue.
@Override
public Attribute getValue() {
try {
X509Certificate cert = (X509Certificate) certificates[0];
Digest digest = DigestFactory.getInstance().factoryDefault();
digest.setAlgorithm(DigestAlgorithmEnum.SHA_1);
byte[] hash = digest.digest(cert.getEncoded());
X500Name dirName = new X500Name(cert.getSubjectDN().getName());
GeneralName name = new GeneralName(dirName);
GeneralNames issuer = new GeneralNames(name);
ASN1Integer serial = new ASN1Integer(cert.getSerialNumber());
IssuerSerial issuerSerial = new IssuerSerial(issuer, serial);
ESSCertID essCertId = new ESSCertID(hash, issuerSerial);
return new Attribute(identifier, new DERSet(new DERSequence(new ASN1Encodable[] { new DERSequence(essCertId), new DERSequence(DERNull.INSTANCE) })));
} catch (CertificateEncodingException ex) {
throw new SignerException(ex.getMessage());
}
}
use of com.github.zhenwei.core.asn1.x509.GeneralNames in project signer by demoiselle.
the class CertificateRefs method getValue.
@Override
public Attribute getValue() throws SignerException {
try {
int chainSize = certificates.length - 1;
OtherCertID[] arrayOtherCertID = new OtherCertID[chainSize];
for (int i = 1; i <= chainSize; i++) {
X509Certificate issuerCert = null;
X509Certificate cert = (X509Certificate) certificates[i];
if (i < chainSize) {
issuerCert = (X509Certificate) certificates[i + 1];
} else {
// raiz
issuerCert = (X509Certificate) certificates[i];
}
Digest digest = DigestFactory.getInstance().factoryDefault();
digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
byte[] certHash = digest.digest(cert.getEncoded());
// X500Name dirName = new X500Name(issuerCert.getSubjectX500Principal().getName());
X500Name dirName = new JcaX509CertificateHolder(issuerCert).getSubject();
GeneralName name = new GeneralName(dirName);
GeneralNames issuer = new GeneralNames(name);
ASN1Integer serialNumber = new ASN1Integer(cert.getSerialNumber());
IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber);
AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);
OtherCertID otherCertID = new OtherCertID(algId, certHash, issuerSerial);
arrayOtherCertID[i - 1] = otherCertID;
}
return new Attribute(identifier, new DERSet(new ASN1Encodable[] { new DERSequence(arrayOtherCertID) }));
} catch (CertificateEncodingException e) {
throw new SignerException(e.getMessage());
}
}
Aggregations