Search in sources :

Example 11 with IssuerAndSerialNumber

use of org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber in project jruby-openssl by jruby.

the class SignerInfoWithPkey method set.

/* c: PKCS7_SIGNER_INFO_set
     *
     */
public void set(X509AuxCertificate x509, PrivateKey pkey, MessageDigest dgst) throws PKCS7Exception {
    boolean dsa = (pkey instanceof DSAPrivateKey) || (pkey instanceof ECPrivateKey);
    version = new ASN1Integer(BigInteger.ONE);
    X500Name issuer = X500Name.getInstance(x509.getIssuerX500Principal().getEncoded());
    BigInteger serial = x509.getSerialNumber();
    issuerAndSerialNumber = new IssuerAndSerialNumber(issuer, serial);
    this.pkey = pkey;
    if (dsa) {
        digAlgorithm = new AlgorithmIdentifier(OID_sha1);
    } else {
        digAlgorithm = new AlgorithmIdentifier(ASN1Registry.nid2obj(EVP.type(dgst)));
    }
    if (pkey instanceof RSAPrivateKey) {
        digEncryptionAlgorithm = new AlgorithmIdentifier(OID_rsaEncryption);
    } else if (pkey instanceof DSAPrivateKey) {
        digEncryptionAlgorithm = new AlgorithmIdentifier(OID_dsa);
    } else if (pkey instanceof ECPrivateKey) {
        digEncryptionAlgorithm = new AlgorithmIdentifier(OID_ecdsa_with_SHA1);
    }
}
Also used : IssuerAndSerialNumber(org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber) ECPrivateKey(java.security.interfaces.ECPrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) BigInteger(java.math.BigInteger) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) X500Name(org.bouncycastle.asn1.x500.X500Name) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 12 with IssuerAndSerialNumber

use of org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber in project jruby-openssl by jruby.

the class SignerInfoWithPkey method toASN1Object.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 *  SignerInfo ::= SEQUENCE {
 *      version Version,
 *      issuerAndSerialNumber IssuerAndSerialNumber,
 *      digestAlgorithm DigestAlgorithmIdentifier,
 *      authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
 *      digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
 *      encryptedDigest EncryptedDigest,
 *      unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
 *  }
 *
 *  EncryptedDigest ::= OCTET STRING
 *
 *  DigestAlgorithmIdentifier ::= AlgorithmIdentifier
 *
 *  DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
 * </pre>
 */
public ASN1Encodable toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(version);
    v.add(issuerAndSerialNumber);
    v.add(digAlgorithm);
    if (authenticatedAttributes != null) {
        v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
    }
    v.add(digEncryptionAlgorithm);
    v.add(encryptedDigest);
    if (unauthenticatedAttributes != null) {
        v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
    }
    return new DLSequence(v);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Aggregations

IssuerAndSerialNumber (org.bouncycastle.asn1.cms.IssuerAndSerialNumber)7 ContentInfo (org.bouncycastle.asn1.cms.ContentInfo)5 X500Name (org.bouncycastle.asn1.x500.X500Name)4 DecodedPkiMessage (org.xipki.scep.message.DecodedPkiMessage)4 PkiMessage (org.xipki.scep.message.PkiMessage)4 BigInteger (java.math.BigInteger)3 CertificateException (java.security.cert.CertificateException)3 X509Certificate (java.security.cert.X509Certificate)3 Date (java.util.Date)3 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)3 CertificationRequest (org.bouncycastle.asn1.pkcs.CertificationRequest)3 IssuerAndSerialNumber (org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber)3 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)3 CMSSignedData (org.bouncycastle.cms.CMSSignedData)3 MessageType (org.xipki.scep.transaction.MessageType)3 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CRLException (java.security.cert.CRLException)1 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)1