Class: OpenSSL::X509::StoreContext (Ruby 2.7.2)
Description: Class : OpenSSL::X509::StoreContext - Ruby 2.7.2

### Home Classes Methods

### In Files

- openssl/lib/openssl/x509.rb
- openssl/ossl_x509attr.c

### Parent

Object

### Methods

- ::new
- #chain
- #cleanup
- #current_cert
- #current_crl
- #error
- #error=
- #error_depth
- #error_string
- #flags=
- #purpose=
- #time=
- #trust=
- #verify

### Class/Module Index

Quicksearch

- IO
- IO::WaitReadable
- IO::WaitWritable
- Integer
- OpenSSL
- OpenSSL::ASN1
- OpenSSL::ASN1::ASN1Data
- OpenSSL::ASN1::ASN1Error
- OpenSSL::ASN1::Constructive
- OpenSSL::ASN1::ObjectId
- OpenSSL::ASN1::Primitive
- OpenSSL::BN
- OpenSSL::BNError
- OpenSSL::Buffering
- OpenSSL::Cipher
- OpenSSL::Cipher::Cipher
- OpenSSL::Cipher::CipherError
- OpenSSL::Config
- OpenSSL::ConfigError
- OpenSSL::Digest
- OpenSSL::Digest::DigestError
- OpenSSL::Engine
- OpenSSL::Engine::EngineError
- OpenSSL::ExtConfig
- OpenSSL::HMAC
- OpenSSL::HMACError
- OpenSSL::KDF
- OpenSSL::KDF::KDFError
- OpenSSL::Netscape
- OpenSSL::Netscape::SPKI
- OpenSSL::Netscape::SPKIError
- OpenSSL::OCSP
- OpenSSL::OCSP::BasicResponse
- OpenSSL::OCSP::CertificateId
- OpenSSL::OCSP::OCSPError
- OpenSSL::OCSP::Request
- OpenSSL::OCSP::Response
- OpenSSL::OCSP::SingleResponse
- OpenSSL::OpenSSLError
- OpenSSL::PKCS12
- OpenSSL::PKCS12::PKCS12Error
- OpenSSL::PKCS5
- OpenSSL::PKCS7
- OpenSSL::PKCS7::PKCS7Error
- OpenSSL::PKCS7::RecipientInfo
- OpenSSL::PKCS7::SignerInfo
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DHError
- OpenSSL::PKey::DSA
- OpenSSL::PKey::DSAError
- OpenSSL::PKey::EC
- OpenSSL::PKey::EC::Group
- OpenSSL::PKey::EC::Group::Error
- OpenSSL::PKey::EC::Point
- OpenSSL::PKey::EC::Point::Error
- OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::PKeyError
- OpenSSL::PKey::RSA
- OpenSSL::PKey::RSAError
- OpenSSL::Random
- OpenSSL::Random::RandomError
- OpenSSL::SSL
- OpenSSL::SSL::SSLContext
- OpenSSL::SSL::SSLError
- OpenSSL::SSL::SSLErrorWaitReadable
- OpenSSL::SSL::SSLErrorWaitWritable
- OpenSSL::SSL::SSLServer
- OpenSSL::SSL::SSLSocket
- OpenSSL::SSL::Session
- OpenSSL::SSL::Session::SessionError
- OpenSSL::SSL::SocketForwarder
- OpenSSL::X509
- OpenSSL::X509::Attribute
- OpenSSL::X509::AttributeError
- OpenSSL::X509::CRL
- OpenSSL::X509::CRLError
- OpenSSL::X509::Certificate
- OpenSSL::X509::CertificateError
- OpenSSL::X509::Extension
- OpenSSL::X509::ExtensionError
- OpenSSL::X509::ExtensionFactory
- OpenSSL::X509::Name
- OpenSSL::X509::Name::RFC2253DN
- OpenSSL::X509::NameError
- OpenSSL::X509::Request
- OpenSSL::X509::RequestError
- OpenSSL::X509::Revoked
- OpenSSL::X509::RevokedError
- OpenSSL::X509::Store
- OpenSSL::X509::StoreContext
- OpenSSL::X509::StoreError
- unknown

No matching classes.

# OpenSSL::X509::StoreContext

A StoreContext is used while validating a single certificate and holds the status involved.

### Public Class Methods

new(store, cert = nil, chain = nil) click to toggle source

                   static VALUE
    ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
    {
        VALUE store, cert, chain, t;
        X509_STORE_CTX *ctx;
        X509_STORE *x509st;
        X509 *x509 = NULL;
        STACK_OF(X509) *x509s = NULL;

        rb_scan_args(argc, argv, "12", &store, &cert, &chain);
        GetX509StCtx(self, ctx);
        GetX509Store(store, x509st);
        if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */
        if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
        if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
            sk_X509_pop_free(x509s, X509_free);
            ossl_raise(eX509StoreError, NULL);
        }
        if (!NIL_P(t = rb_iv_get(store, "@time")))
            ossl_x509stctx_set_time(self, t);
        rb_iv_set(self, "@verify_callback", rb_iv_get(store, "@verify_callback"));
        rb_iv_set(self, "@cert", cert);

        return self;
    }

### Public Instance Methods

chain → Array of X509::Certificate click to toggle source

                   static VALUE
    ossl_x509stctx_get_chain(VALUE self)
    {
        X509_STORE_CTX *ctx;
        STACK_OF(X509) *chain;
        X509 *x509;
        int i, num;
        VALUE ary;

        GetX509StCtx(self, ctx);
        if((chain = X509_STORE_CTX_get0_chain(ctx)) == NULL){
            return Qnil;
        }
        if((num = sk_X509_num(chain)) < 0){
            OSSL_Debug("certs in chain < 0???");
            return rb_ary_new();
        }
        ary = rb_ary_new2(num);
        for(i = 0; i < num; i++) {
            x509 = sk_X509_value(chain, i);
            rb_ary_push(ary, ossl_x509_new(x509));
        }

        return ary;
    }

cleanup() click to toggle source

                   # File openssl/lib/openssl/x509.rb, line 176
    def cleanup
      warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE
    end

current_cert → X509::Certificate click to toggle source

                   static VALUE
    ossl_x509stctx_get_curr_cert(VALUE self)
    {
        X509_STORE_CTX *ctx;

        GetX509StCtx(self, ctx);

        return ossl_x509_new(X509_STORE_CTX_get_current_cert(ctx));
    }

current_crl → X509::CRL click to toggle source

                   static VALUE
    ossl_x509stctx_get_curr_crl(VALUE self)
    {
        X509_STORE_CTX *ctx;
        X509_CRL *crl;

        GetX509StCtx(self, ctx);
        crl = X509_STORE_CTX_get0_current_crl(ctx);
        if (!crl)
            return Qnil;

        return ossl_x509crl_new(crl);
    }

error → Integer click to toggle source

                   static VALUE
    ossl_x509stctx_get_err(VALUE self)
    {
        X509_STORE_CTX *ctx;

        GetX509StCtx(self, ctx);

        return INT2NUM(X509_STORE_CTX_get_error(ctx));
    }

error = error_code click to toggle source

                   static VALUE
    ossl_x509stctx_set_error(VALUE self, VALUE err)
    {
        X509_STORE_CTX *ctx;

        GetX509StCtx(self, ctx);
        X509_STORE_CTX_set_error(ctx, NUM2INT(err));

        return err;
    }

error_depth → Integer click to toggle source

                   static VALUE
    ossl_x509stctx_get_err_depth(VALUE self)
    {
        X509_STORE_CTX *ctx;

        GetX509StCtx(self, ctx);

        return INT2NUM(X509_STORE_CTX_get_error_depth(ctx));
    }

error_string → String click to toggle source

Returns the error string corresponding to the error code retrieved by error.

                   static VALUE
    ossl_x509stctx_get_err_string(VALUE self)
    {
        X509_STORE_CTX *ctx;
        long err;

        GetX509StCtx(self, ctx);
        err = X509_STORE_CTX_get_error(ctx);

        return rb_str_new2(X509_verify_cert_error_string(err));
    }

flags = flags click to toggle source

Sets the verification flags to the context. See OpenSSL::X509::Store#flags=.

                   static VALUE
    ossl_x509stctx_set_flags(VALUE self, VALUE flags)
    {
        X509_STORE_CTX *store;
        long f = NUM2LONG(flags);

        GetX509StCtx(self, store);
        X509_STORE_CTX_set_flags(store, f);

        return flags;
    }

purpose = purpose click to toggle source

Sets the purpose of the context. See OpenSSL::X509::Store#purpose=.

                   static VALUE
    ossl_x509stctx_set_purpose(VALUE self, VALUE purpose)
    {
        X509_STORE_CTX *store;
        int p = NUM2INT(purpose);

        GetX509StCtx(self, store);
        X509_STORE_CTX_set_purpose(store, p);

        return purpose;
    }

time = time click to toggle source

Sets the time used in the verification. If not set, the current time is used.

                   static VALUE
    ossl_x509stctx_set_time(VALUE self, VALUE time)
    {
        X509_STORE_CTX *store;
        long t;

        t = NUM2LONG(rb_Integer(time));
        GetX509StCtx(self, store);
        X509_STORE_CTX_set_time(store, 0, t);

        return time;
    }

trust = trust click to toggle source

                   static VALUE
    ossl_x509stctx_set_trust(VALUE self, VALUE trust)
    {
        X509_STORE_CTX *store;
        int t = NUM2INT(trust);

        GetX509StCtx(self, store);
        X509_STORE_CTX_set_trust(store, t);

        return trust;
    }

verify → true | false click to toggle source

                   static VALUE
    ossl_x509stctx_verify(VALUE self)
    {
        X509_STORE_CTX *ctx;

        GetX509StCtx(self, ctx);
        X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx,
                                   (void *)rb_iv_get(self, "@verify_callback"));

        switch (X509_verify_cert(ctx)) {
          case 1:
            return Qtrue;
          case 0:
            ossl_clear_error();
            return Qfalse;
          default:
            ossl_raise(eX509CertError, NULL);
        }
    }