use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class PKCS7 method decrypt.
@JRubyMethod(rest = true)
public IRubyObject decrypt(IRubyObject[] args) {
IRubyObject dflags;
if (Arity.checkArgumentCount(getRuntime(), args, 2, 3) == 3) {
dflags = args[2];
} else {
dflags = getRuntime().getNil();
}
PKey pkey = (PKey) args[0];
X509Cert cert = (X509Cert) args[1];
final PrivateKey privKey = pkey.getPrivateKey();
final X509AuxCertificate auxCert = cert.getAuxCert();
final int flg = dflags.isNil() ? 0 : RubyNumeric.fix2int(dflags);
final BIO out = BIO.mem();
try {
p7.decrypt(privKey, auxCert, out, flg);
} catch (PKCS7Exception pkcs7e) {
throw newPKCS7Error(getRuntime(), pkcs7e);
}
return membio2str(getRuntime(), out);
}
use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class PKCS7 method getAuxCerts.
private static List<X509AuxCertificate> getAuxCerts(final IRubyObject arg) {
final RubyArray arr = (RubyArray) arg;
List<X509AuxCertificate> certs = new ArrayList<X509AuxCertificate>(arr.size());
for (int i = 0; i < arr.size(); i++) {
certs.add(((X509Cert) arr.eltInternal(i)).getAuxCert());
}
return certs;
}
use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class PKCS7 method getSigners.
/* c: PKCS7_get0_signers
*
*/
public List<X509AuxCertificate> getSigners(Collection<X509AuxCertificate> certs, Collection<SignerInfoWithPkey> infos, int flags) throws PKCS7Exception {
if (!isSigned()) {
throw new PKCS7Exception(F_PKCS7_GET0_SIGNERS, R_WRONG_CONTENT_TYPE);
}
if (infos == null || infos.size() == 0) {
throw new PKCS7Exception(F_PKCS7_GET0_SIGNERS, R_NO_SIGNERS);
}
final ArrayList<X509AuxCertificate> signers = new ArrayList<X509AuxCertificate>(infos.size());
for (final SignerInfoWithPkey info : infos) {
final IssuerAndSerialNumber ias = info.getIssuerAndSerialNumber();
X509AuxCertificate signer = null;
// System.err.println(" in: " + getSign().getCert());
if (certs != null) {
signer = findByIssuerAndSerial(certs, ias.getName(), ias.getCertificateSerialNumber().getValue());
}
if (signer == null && (flags & NOINTERN) == 0 && getSign().getCert() != null) {
signer = findByIssuerAndSerial(getSign().getCert(), ias.getName(), ias.getCertificateSerialNumber().getValue());
}
if (signer == null) {
throw new PKCS7Exception(F_PKCS7_GET0_SIGNERS, R_SIGNER_CERTIFICATE_NOT_FOUND);
}
signers.add(signer);
}
return signers;
}
use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class PKCS7 method sign.
/* c: PKCS7_sign
*
*/
public static PKCS7 sign(X509AuxCertificate signcert, PrivateKey pkey, Collection<X509AuxCertificate> certs, BIO data, int flags) throws PKCS7Exception {
PKCS7 p7 = new PKCS7();
p7.setType(ASN1Registry.NID_pkcs7_signed);
p7.contentNew(ASN1Registry.NID_pkcs7_data);
SignerInfoWithPkey si = p7.addSignature(signcert, pkey, EVP.sha1());
if ((flags & NOCERTS) == 0) {
p7.addCertificate(signcert);
if (certs != null) {
for (X509AuxCertificate c : certs) {
p7.addCertificate(c);
}
}
}
if ((flags & NOATTR) == 0) {
si.addSignedAttribute(ASN1Registry.NID_pkcs9_contentType, OID_pkcs7_data);
if ((flags & NOSMIMECAP) == 0) {
ASN1EncodableVector smcap = new ASN1EncodableVector();
smcap.add(new AlgorithmIdentifier(OID_des_ede3_cbc));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_128)));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_64)));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_40)));
smcap.add(new AlgorithmIdentifier(OID_des_cbc));
si.addSignedAttribute(ASN1Registry.NID_SMIMECapabilities, new DLSequence(smcap));
}
}
if ((flags & STREAM) != 0) {
return p7;
}
BIO p7bio = p7.dataInit(null);
try {
data.crlfCopy(p7bio, flags);
} catch (IOException e) {
throw new PKCS7Exception(F_PKCS7_SIGN, R_PKCS7_DATAFINAL_ERROR, e);
}
if ((flags & DETACHED) != 0) {
p7.setDetached(1);
}
p7.dataFinal(p7bio);
return p7;
}
use of org.jruby.ext.openssl.x509store.X509AuxCertificate in project jruby-openssl by jruby.
the class Signed method certificatesFromASN1Set.
private static Collection<X509AuxCertificate> certificatesFromASN1Set(ASN1Encodable content) throws PKCS7Exception {
Collection<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>();
if (content instanceof ASN1Sequence) {
try {
for (Enumeration<?> enm = ((ASN1Sequence) content).getObjects(); enm.hasMoreElements(); ) {
ASN1Encodable current = (ASN1Encodable) enm.nextElement();
result.add(certificateFromASN1(current));
}
} catch (IllegalArgumentException iae) {
result.add(certificateFromASN1(content));
}
} else if (content instanceof ASN1Set) {
// EXPLICIT Set shouldn't apper here but keep this for backward compatibility.
for (Enumeration<?> enm = ((ASN1Set) content).getObjects(); enm.hasMoreElements(); ) {
ASN1Encodable current = (ASN1Encodable) enm.nextElement();
result.add(certificateFromASN1(current));
}
} else {
throw new PKCS7Exception(PKCS7.F_B64_READ_PKCS7, PKCS7.R_CERTIFICATE_VERIFY_ERROR, "unknown certificates format");
}
return result;
}
Aggregations