Class: OpenSSL::X509::Request (Ruby 2.5.7)
Description: Class : OpenSSL::X509::Request - Ruby 2.5.7

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::new
- #==
- #add_attribute
- #attributes
- #attributes=
- #initialize_copy
- #public_key
- #public_key=
- #sign
- #signature_algorithm
- #subject
- #subject=
- #to_der
- #to_pem
- #to_s
- #to_text
- #verify
- #version
- #version=

### 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

No matching classes.

# OpenSSL::X509::Request

### Public Class Methods

new(p1 = v1) click to toggle source

                   static VALUE
    ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
    {
        BIO *in;
        X509_REQ *req, *x = DATA_PTR(self);
        VALUE arg;

        if (rb_scan_args(argc, argv, "01", &arg) == 0) {
            return self;
        }
        arg = ossl_to_der_if_possible(arg);
        in = ossl_obj2bio(&arg);
        req = PEM_read_bio_X509_REQ(in, &x, NULL, NULL);
        DATA_PTR(self) = x;
        if (!req) {
            OSSL_BIO_reset(in);
            req = d2i_X509_REQ_bio(in, &x);
            DATA_PTR(self) = x;
        }
        BIO_free(in);
        if (!req) ossl_raise(eX509ReqError, NULL);

        return self;
    }

### Public Instance Methods

==(other) click to toggle source

                   # File openssl/lib/openssl/x509.rb, line 209
    def ==(other)
      return false unless Request === other
      to_der == other.to_der
    end

add_attribute(p1) click to toggle source

                   static VALUE
    ossl_x509req_add_attribute(VALUE self, VALUE attr)
    {
        X509_REQ *req;

        GetX509Req(self, req);
        if (!X509_REQ_add1_attr(req, GetX509AttrPtr(attr))) {
            ossl_raise(eX509ReqError, NULL);
        }

        return attr;
    }

attributes() click to toggle source

                   static VALUE
    ossl_x509req_get_attributes(VALUE self)
    {
        X509_REQ *req;
        int count, i;
        X509_ATTRIBUTE *attr;
        VALUE ary;

        GetX509Req(self, req);

        count = X509_REQ_get_attr_count(req);
        if (count < 0) {
            OSSL_Debug("count < 0???");
            return rb_ary_new();
        }
        ary = rb_ary_new2(count);
        for (i=0; i<count; i++) {
            attr = X509_REQ_get_attr(req, i);
            rb_ary_push(ary, ossl_x509attr_new(attr));
        }

        return ary;
    }

attributes=(p1) click to toggle source

                   static VALUE
    ossl_x509req_set_attributes(VALUE self, VALUE ary)
    {
        X509_REQ *req;
        X509_ATTRIBUTE *attr;
        long i;
        VALUE item;

        Check_Type(ary, T_ARRAY);
        for (i=0;i<RARRAY_LEN(ary); i++) {
            OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Attr);
        }
        GetX509Req(self, req);
        while ((attr = X509_REQ_delete_attr(req, 0)))
            X509_ATTRIBUTE_free(attr);
        for (i=0;i<RARRAY_LEN(ary); i++) {
            item = RARRAY_AREF(ary, i);
            attr = GetX509AttrPtr(item);
            if (!X509_REQ_add1_attr(req, attr)) {
                ossl_raise(eX509ReqError, NULL);
            }
        }
        return ary;
    }

initialize_copy(p1) click to toggle source

                   static VALUE
    ossl_x509req_copy(VALUE self, VALUE other)
    {
        X509_REQ *a, *b, *req;

        rb_check_frozen(self);
        if (self == other) return self;
        GetX509Req(self, a);
        GetX509Req(other, b);
        if (!(req = X509_REQ_dup(b))) {
            ossl_raise(eX509ReqError, NULL);
        }
        X509_REQ_free(a);
        DATA_PTR(self) = req;

        return self;
    }

public_key() click to toggle source

                   static VALUE
    ossl_x509req_get_public_key(VALUE self)
    {
        X509_REQ *req;
        EVP_PKEY *pkey;

        GetX509Req(self, req);
        if (!(pkey = X509_REQ_get_pubkey(req))) { /* adds reference */
            ossl_raise(eX509ReqError, NULL);
        }

        return ossl_pkey_new(pkey); /* NO DUP - OK */
    }

public_key=(p1) click to toggle source

                   static VALUE
    ossl_x509req_set_public_key(VALUE self, VALUE key)
    {
        X509_REQ *req;
        EVP_PKEY *pkey;

        GetX509Req(self, req);
        pkey = GetPKeyPtr(key);
        ossl_pkey_check_public_key(pkey);
        if (!X509_REQ_set_pubkey(req, pkey))
            ossl_raise(eX509ReqError, "X509_REQ_set_pubkey");
        return key;
    }

sign(p1, p2) click to toggle source

                   static VALUE
    ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
    {
        X509_REQ *req;
        EVP_PKEY *pkey;
        const EVP_MD *md;

        GetX509Req(self, req);
        pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
        md = ossl_evp_get_digestbyname(digest);
        if (!X509_REQ_sign(req, pkey, md)) {
            ossl_raise(eX509ReqError, NULL);
        }

        return self;
    }

signature_algorithm() click to toggle source

                   static VALUE
    ossl_x509req_get_signature_algorithm(VALUE self)
    {
        X509_REQ *req;
        const X509_ALGOR *alg;
        BIO *out;

        GetX509Req(self, req);

        if (!(out = BIO_new(BIO_s_mem()))) {
            ossl_raise(eX509ReqError, NULL);
        }
        X509_REQ_get0_signature(req, NULL, &alg);
        if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
            BIO_free(out);
            ossl_raise(eX509ReqError, NULL);
        }

        return ossl_membio2str(out);
    }

subject() click to toggle source

                   static VALUE
    ossl_x509req_get_subject(VALUE self)
    {
        X509_REQ *req;
        X509_NAME *name;

        GetX509Req(self, req);
        if (!(name = X509_REQ_get_subject_name(req))) { /* NO DUP - don't free */
            ossl_raise(eX509ReqError, NULL);
        }

        return ossl_x509name_new(name);
    }

subject=(p1) click to toggle source

                   static VALUE
    ossl_x509req_set_subject(VALUE self, VALUE subject)
    {
        X509_REQ *req;

        GetX509Req(self, req);
        /* DUPs name */
        if (!X509_REQ_set_subject_name(req, GetX509NamePtr(subject))) {
            ossl_raise(eX509ReqError, NULL);
        }

        return subject;
    }

to_der() click to toggle source

                   static VALUE
    ossl_x509req_to_der(VALUE self)
    {
        X509_REQ *req;
        VALUE str;
        long len;
        unsigned char *p;

        GetX509Req(self, req);
        if ((len = i2d_X509_REQ(req, NULL)) <= 0)
            ossl_raise(eX509ReqError, NULL);
        str = rb_str_new(0, len);
        p = (unsigned char *)RSTRING_PTR(str);
        if (i2d_X509_REQ(req, &p) <= 0)
            ossl_raise(eX509ReqError, NULL);
        ossl_str_adjust(str, p);

        return str;
    }

to_pem() click to toggle source

                   static VALUE
    ossl_x509req_to_pem(VALUE self)
    {
        X509_REQ *req;
        BIO *out;

        GetX509Req(self, req);
        if (!(out = BIO_new(BIO_s_mem()))) {
            ossl_raise(eX509ReqError, NULL);
        }
        if (!PEM_write_bio_X509_REQ(out, req)) {
            BIO_free(out);
            ossl_raise(eX509ReqError, NULL);
        }

        return ossl_membio2str(out);
    }

Also aliased as: to_s
to_s() click to toggle source
Alias for: to_pem
to_text() click to toggle source

                   static VALUE
    ossl_x509req_to_text(VALUE self)
    {
        X509_REQ *req;
        BIO *out;

        GetX509Req(self, req);
        if (!(out = BIO_new(BIO_s_mem()))) {
            ossl_raise(eX509ReqError, NULL);
        }
        if (!X509_REQ_print(out, req)) {
            BIO_free(out);
            ossl_raise(eX509ReqError, NULL);
        }

        return ossl_membio2str(out);
    }

verify(p1) click to toggle source

Checks that cert signature is made with PRIVversion of this PUBLIC 'key'

                   static VALUE
    ossl_x509req_verify(VALUE self, VALUE key)
    {
        X509_REQ *req;
        EVP_PKEY *pkey;

        GetX509Req(self, req);
        pkey = GetPKeyPtr(key);
        ossl_pkey_check_public_key(pkey);
        switch (X509_REQ_verify(req, pkey)) {
          case 1:
            return Qtrue;
          case 0:
            ossl_clear_error();
            return Qfalse;
          default:
            ossl_raise(eX509ReqError, NULL);
        }
    }

version() click to toggle source

                   static VALUE
    ossl_x509req_get_version(VALUE self)
    {
        X509_REQ *req;
        long version;

        GetX509Req(self, req);
        version = X509_REQ_get_version(req);

        return LONG2NUM(version);
    }

version=(p1) click to toggle source

                   static VALUE
    ossl_x509req_set_version(VALUE self, VALUE version)
    {
        X509_REQ *req;
        long ver;

        if ((ver = NUM2LONG(version)) < 0) {
            ossl_raise(eX509ReqError, "version must be >= 0!");
        }
        GetX509Req(self, req);
        if (!X509_REQ_set_version(req, ver)) {
            ossl_raise(eX509ReqError, "X509_REQ_set_version");
        }

        return version;
    }