Search in sources :

Example 1 with RevokedInfo

use of org.bouncycastle.asn1.ocsp.RevokedInfo in project jruby-openssl by jruby.

the class OCSPBasicResponse method add_status.

@JRubyMethod(name = "add_status", rest = true)
public OCSPBasicResponse add_status(final ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    Arity.checkArgumentCount(runtime, args, 7, 7);
    IRubyObject certificateId = args[0];
    IRubyObject status = args[1];
    IRubyObject reason = args[2];
    IRubyObject revocation_time = args[3];
    IRubyObject this_update = args[4];
    IRubyObject next_update = args[5];
    IRubyObject extensions = args[6];
    CertStatus certStatus = null;
    switch(RubyFixnum.fix2int((RubyFixnum) status)) {
        case 0:
            certStatus = new CertStatus();
            break;
        case 1:
            ASN1GeneralizedTime revTime = rubyIntOrTimeToGenTime(revocation_time);
            RevokedInfo revokedInfo = new RevokedInfo(revTime, CRLReason.lookup(RubyFixnum.fix2int((RubyFixnum) reason)));
            certStatus = new CertStatus(revokedInfo);
            break;
        case 2:
            certStatus = new CertStatus(2, DERNull.INSTANCE);
            break;
        default:
            break;
    }
    ASN1GeneralizedTime thisUpdate = rubyIntOrTimeToGenTime(this_update);
    ASN1GeneralizedTime nextUpdate = rubyIntOrTimeToGenTime(next_update);
    Extensions singleExtensions = convertRubyExtensions(extensions);
    CertID certID = ((OCSPCertificateId) certificateId).getCertID();
    SingleResponse ocspSingleResp = new SingleResponse(certID, certStatus, thisUpdate, nextUpdate, singleExtensions);
    OCSPSingleResponse rubySingleResp = new OCSPSingleResponse(runtime);
    try {
        rubySingleResp.initialize(context, RubyString.newString(runtime, ocspSingleResp.getEncoded()));
        singleResponses.add(rubySingleResp);
    } catch (IOException e) {
        throw newOCSPError(runtime, e);
    }
    return this;
}
Also used : CertStatus(org.bouncycastle.asn1.ocsp.CertStatus) SingleResponse(org.bouncycastle.asn1.ocsp.SingleResponse) CertID(org.bouncycastle.asn1.ocsp.CertID) ASN1GeneralizedTime(org.bouncycastle.asn1.ASN1GeneralizedTime) IOException(java.io.IOException) IRubyObject(org.jruby.runtime.builtin.IRubyObject) RevokedInfo(org.bouncycastle.asn1.ocsp.RevokedInfo) Extensions(org.bouncycastle.asn1.x509.Extensions) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 2 with RevokedInfo

use of org.bouncycastle.asn1.ocsp.RevokedInfo in project jruby-openssl by jruby.

the class OCSPSingleResponse method revocation_reason.

@JRubyMethod(name = "revocation_reason")
public IRubyObject revocation_reason() {
    Ruby runtime = getRuntime();
    RubyFixnum revoked = (RubyFixnum) _OCSP(runtime).getConstant("V_CERTSTATUS_REVOKED");
    if (bcSingleResponse.getCertStatus().getTagNo() == (int) revoked.getLongValue()) {
        try {
            RevokedInfo revokedInfo = RevokedInfo.getInstance(DERTaggedObject.fromByteArray(bcSingleResponse.getCertStatus().getStatus().toASN1Primitive().getEncoded()));
            return RubyFixnum.newFixnum(runtime, revokedInfo.getRevocationReason().getValue().intValue());
        } catch (IOException e) {
            throw newOCSPError(runtime, e);
        }
    }
    return runtime.getNil();
}
Also used : IOException(java.io.IOException) RevokedInfo(org.bouncycastle.asn1.ocsp.RevokedInfo) Ruby(org.jruby.Ruby) RubyFixnum(org.jruby.RubyFixnum) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 3 with RevokedInfo

use of org.bouncycastle.asn1.ocsp.RevokedInfo in project jruby-openssl by jruby.

the class OCSPSingleResponse method revocation_time.

@JRubyMethod(name = "revocation_time")
public IRubyObject revocation_time() {
    Ruby runtime = getRuntime();
    RubyFixnum revoked = (RubyFixnum) _OCSP(runtime).getConstant("V_CERTSTATUS_REVOKED");
    if (bcSingleResponse.getCertStatus().getTagNo() == (int) revoked.getLongValue()) {
        try {
            RevokedInfo revokedInfo = RevokedInfo.getInstance(DERTaggedObject.fromByteArray(bcSingleResponse.getCertStatus().getStatus().toASN1Primitive().getEncoded()));
            return RubyTime.newTime(runtime, revokedInfo.getRevocationTime().getDate().getTime());
        } catch (Exception e) {
            throw newOCSPError(runtime, e);
        }
    }
    return runtime.getNil();
}
Also used : RevokedInfo(org.bouncycastle.asn1.ocsp.RevokedInfo) Ruby(org.jruby.Ruby) RubyFixnum(org.jruby.RubyFixnum) RaiseException(org.jruby.exceptions.RaiseException) ParseException(java.text.ParseException) IOException(java.io.IOException) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

IOException (java.io.IOException)3 RevokedInfo (org.bouncycastle.asn1.ocsp.RevokedInfo)3 Ruby (org.jruby.Ruby)3 JRubyMethod (org.jruby.anno.JRubyMethod)3 RubyFixnum (org.jruby.RubyFixnum)2 ParseException (java.text.ParseException)1 ASN1GeneralizedTime (org.bouncycastle.asn1.ASN1GeneralizedTime)1 CertID (org.bouncycastle.asn1.ocsp.CertID)1 CertStatus (org.bouncycastle.asn1.ocsp.CertStatus)1 SingleResponse (org.bouncycastle.asn1.ocsp.SingleResponse)1 Extensions (org.bouncycastle.asn1.x509.Extensions)1 RaiseException (org.jruby.exceptions.RaiseException)1 IRubyObject (org.jruby.runtime.builtin.IRubyObject)1