Search in sources :

Example 66 with DERSequence

use of org.openecard.bouncycastle.asn1.DERSequence in project pac4j by pac4j.

the class SAML2ClientConfiguration method createSelfSignedCert.

/**
 * Generate a self-signed certificate for dn using the provided signature algorithm and key pair.
 *
 * @param dn X.500 name to associate with certificate issuer/subject.
 * @param sigName name of the signature algorithm to use.
 * @param sigAlgID algorithm ID associated with the signature algorithm name.
 * @param keyPair the key pair to associate with the certificate.
 * @return an X509Certificate containing the public key in keyPair.
 * @throws Exception
 */
private X509Certificate createSelfSignedCert(X500Name dn, String sigName, AlgorithmIdentifier sigAlgID, KeyPair keyPair) throws Exception {
    V3TBSCertificateGenerator certGen = new V3TBSCertificateGenerator();
    certGen.setSerialNumber(new ASN1Integer(BigInteger.valueOf(1)));
    certGen.setIssuer(dn);
    certGen.setSubject(dn);
    certGen.setStartDate(new Time(new Date(System.currentTimeMillis() - 1000L)));
    final Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.add(Calendar.YEAR, 1);
    certGen.setEndDate(new Time(c.getTime()));
    certGen.setSignature(sigAlgID);
    certGen.setSubjectPublicKeyInfo(SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
    Signature sig = Signature.getInstance(sigName);
    sig.initSign(keyPair.getPrivate());
    sig.update(certGen.generateTBSCertificate().getEncoded(ASN1Encoding.DER));
    TBSCertificate tbsCert = certGen.generateTBSCertificate();
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbsCert);
    v.add(sigAlgID);
    v.add(new DERBitString(sig.sign()));
    X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(new DERSequence(v).getEncoded(ASN1Encoding.DER)));
    // check the certificate - this will confirm the encoded sig algorithm ID is correct.
    cert.verify(keyPair.getPublic());
    return cert;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ByteArrayInputStream(java.io.ByteArrayInputStream) Calendar(java.util.Calendar) Signature(java.security.Signature) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) V3TBSCertificateGenerator(org.bouncycastle.asn1.x509.V3TBSCertificateGenerator) Time(org.bouncycastle.asn1.x509.Time) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) TBSCertificate(org.bouncycastle.asn1.x509.TBSCertificate) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate)

Example 67 with DERSequence

use of org.openecard.bouncycastle.asn1.DERSequence in project BiglyBT by BiglySoftware.

the class EncryptionScheme method getDERObject.

@Override
public DERObject getDERObject() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(objectId);
    v.add(obj);
    return new DERSequence(v);
}
Also used : DERSequence(org.gudy.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.gudy.bouncycastle.asn1.ASN1EncodableVector)

Example 68 with DERSequence

use of org.openecard.bouncycastle.asn1.DERSequence in project keystore-explorer by kaikramer.

the class PolicyMapping method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector dv = new ASN1EncodableVector();
    dv.add(issuerDomainPolicy);
    dv.add(subjectDomainPolicy);
    return new DERSequence(dv);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 69 with DERSequence

use of org.openecard.bouncycastle.asn1.DERSequence in project keystore-explorer by kaikramer.

the class SubjectInfoAccess method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vec = new ASN1EncodableVector();
    Iterator<AccessDescription> it = accessDescriptions.iterator();
    while (it.hasNext()) {
        vec.add(it.next().toASN1Primitive());
    }
    return new DERSequence(vec);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) AccessDescription(org.bouncycastle.asn1.x509.AccessDescription) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 70 with DERSequence

use of org.openecard.bouncycastle.asn1.DERSequence in project keystore-explorer by kaikramer.

the class DPolicyInformationChooser method okPressed.

private void okPressed() {
    ASN1ObjectIdentifier policyIdentifer = joiPolicyIdentifier.getObjectId();
    if (policyIdentifer == null) {
        JOptionPane.showMessageDialog(this, res.getString("DPolicyInformationChooser.PolicyIdentifierValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    List<PolicyQualifierInfo> policyQualifierInfo = jpqPolicyQualifiers.getPolicyQualifierInfo();
    if (policyQualifierInfo.size() > 0) {
        ASN1EncodableVector policyQualifiersVec = new ASN1EncodableVector();
        for (PolicyQualifierInfo policyQualInfo : policyQualifierInfo) {
            try {
                policyQualifiersVec.add(policyQualInfo);
            } catch (Exception ex) {
                DError dError = new DError(this, ex);
                dError.setLocationRelativeTo(this);
                dError.setVisible(true);
                return;
            }
        }
        DERSequence policyQualifiersSeq = new DERSequence(policyQualifiersVec);
        policyInformation = new PolicyInformation(policyIdentifer, policyQualifiersSeq);
    } else {
        policyInformation = new PolicyInformation(policyIdentifer);
    }
    closeDialog();
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) PolicyQualifierInfo(org.bouncycastle.asn1.x509.PolicyQualifierInfo) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Aggregations

DERSequence (org.bouncycastle.asn1.DERSequence)225 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)196 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)48 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)41 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)41 DEROctetString (org.bouncycastle.asn1.DEROctetString)36 IOException (java.io.IOException)34 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)30 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)27 BigInteger (java.math.BigInteger)23 X509Certificate (java.security.cert.X509Certificate)23 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)22 DERBitString (org.bouncycastle.asn1.DERBitString)19 DERIA5String (org.bouncycastle.asn1.DERIA5String)19 DERSet (org.bouncycastle.asn1.DERSet)19 GeneralName (org.bouncycastle.asn1.x509.GeneralName)17 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)16 X500Name (org.bouncycastle.asn1.x500.X500Name)16 DERInteger (org.bouncycastle.asn1.DERInteger)14 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)14