Search in sources :

Example 1 with NotVerifiedPKCS7Exception

use of org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception in project jruby-openssl by jruby.

the class PKCS7 method verify.

@JRubyMethod(rest = true)
public IRubyObject verify(IRubyObject[] args) {
    final Ruby runtime = getRuntime();
    IRubyObject certs;
    X509Store store;
    IRubyObject indata = runtime.getNil();
    IRubyObject vflags = runtime.getNil();
    switch(Arity.checkArgumentCount(runtime, args, 2, 4)) {
        case 4:
            vflags = args[3];
        case 3:
            indata = args[2];
        default:
            store = (X509Store) args[1];
            certs = args[0];
    }
    final int flg = vflags.isNil() ? 0 : RubyNumeric.fix2int(vflags);
    if (indata.isNil())
        indata = getData();
    final BIO in = indata.isNil() ? null : obj2bio(indata);
    List<X509AuxCertificate> x509s = certs.isNil() ? null : getAuxCerts(certs);
    final Store storeStr = store.getStore();
    final BIO out = BIO.mem();
    boolean result = false;
    try {
        p7.verify(x509s, storeStr, in, out, flg);
        result = true;
    } catch (NotVerifiedPKCS7Exception e) {
    // result = false;
    } catch (PKCS7Exception pkcs7e) {
        if (isDebug(runtime)) {
            // runtime.getOut().println(pkcs7e);
            pkcs7e.printStackTrace(runtime.getOut());
        }
    // result = false;
    }
    IRubyObject data = membio2str(getRuntime(), out);
    setData(data);
    return result ? runtime.getTrue() : runtime.getFalse();
}
Also used : MemBIO(org.jruby.ext.openssl.impl.MemBIO) BIO(org.jruby.ext.openssl.impl.BIO) Store(org.jruby.ext.openssl.x509store.Store) NotVerifiedPKCS7Exception(org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception) IRubyObject(org.jruby.runtime.builtin.IRubyObject) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate) PKCS7Exception(org.jruby.ext.openssl.impl.PKCS7Exception) NotVerifiedPKCS7Exception(org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

Ruby (org.jruby.Ruby)1 JRubyMethod (org.jruby.anno.JRubyMethod)1 BIO (org.jruby.ext.openssl.impl.BIO)1 MemBIO (org.jruby.ext.openssl.impl.MemBIO)1 NotVerifiedPKCS7Exception (org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception)1 PKCS7Exception (org.jruby.ext.openssl.impl.PKCS7Exception)1 Store (org.jruby.ext.openssl.x509store.Store)1 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)1 IRubyObject (org.jruby.runtime.builtin.IRubyObject)1