Class: OpenSSL::X509::Request
- Inherits:
-
Object
- Object
- OpenSSL::X509::Request
- Includes:
- Marshal
- Defined in:
- lib/openssl/x509.rb,
ext/openssl/ossl_x509req.c
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_attribute(attr) ⇒ Object
- #attributes ⇒ Object
- #attributes=(ary) ⇒ Object
- #initialize(*args) ⇒ Object constructor
-
#initialize_copy(other) ⇒ Object
:nodoc:.
- #public_key ⇒ Object
- #public_key=(key) ⇒ Object
- #sign(key, digest) ⇒ Object
-
#signature_algorithm ⇒ String
Returns the signature algorithm used to sign this request.
- #subject ⇒ Object
- #subject=(subject) ⇒ Object
- #to_der ⇒ Object
- #to_pem ⇒ Object (also: #to_s)
- #to_text ⇒ Object
-
#verify(key) ⇒ Object
Checks that cert signature is made with PRIVversion of this PUBLIC ‘key’.
- #version ⇒ Object
- #version=(version) ⇒ Object
Methods included from Marshal
Constructor Details
#initialize(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'ext/openssl/ossl_x509req.c', line 78
static VALUE
ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
{
BIO *in;
X509_REQ *req, *req_orig = RTYPEDDATA_DATA(self);
VALUE arg;
rb_check_frozen(self);
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
return self;
}
arg = ossl_to_der_if_possible(arg);
in = ossl_obj2bio(&arg);
req = d2i_X509_REQ_bio(in, NULL);
if (!req) {
OSSL_BIO_reset(in);
req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);
}
BIO_free(in);
if (!req)
ossl_raise(eX509ReqError, "PEM_read_bio_X509_REQ");
RTYPEDDATA_DATA(self) = req;
X509_REQ_free(req_orig);
return self;
}
|
Instance Method Details
#==(other) ⇒ Object
394 395 396 397 |
# File 'lib/openssl/x509.rb', line 394 def ==(other) return false unless Request === other to_der == other.to_der end |
#add_attribute(attr) ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'ext/openssl/ossl_x509req.c', line 398
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 ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'ext/openssl/ossl_x509req.c', line 349
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=(ary) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'ext/openssl/ossl_x509req.c', line 373
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);
for (i = X509_REQ_get_attr_count(req); i > 0; i--)
X509_ATTRIBUTE_free(X509_REQ_delete_attr(req, 0));
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, "X509_REQ_add1_attr");
}
}
return ary;
}
|
#initialize_copy(other) ⇒ Object
:nodoc:
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'ext/openssl/ossl_x509req.c', line 107
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 ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'ext/openssl/ossl_x509req.c', line 280
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_wrap(pkey);
}
|
#public_key=(key) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'ext/openssl/ossl_x509req.c', line 294
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(key, digest) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'ext/openssl/ossl_x509req.c', line 308
static VALUE
ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
{
X509_REQ *req;
EVP_PKEY *pkey;
const EVP_MD *md;
VALUE md_holder;
GetX509Req(self, req);
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
/* NULL needed for some key types, e.g. Ed25519 */
md = NIL_P(digest) ? NULL : ossl_evp_md_fetch(digest, &md_holder);
if (!X509_REQ_sign(req, pkey, md))
ossl_raise(eX509ReqError, "X509_REQ_sign");
return self;
}
|
#signature_algorithm ⇒ String
Returns the signature algorithm used to sign this request.
Returns the long name of the signature algorithm, or the dotted decimal notation if OpenSSL does not define a long name for it.
267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'ext/openssl/ossl_x509req.c', line 267
static VALUE
ossl_x509req_get_signature_algorithm(VALUE self)
{
X509_REQ *req;
const X509_ALGOR *alg;
const ASN1_OBJECT *obj;
GetX509Req(self, req);
X509_REQ_get0_signature(req, NULL, &alg);
X509_ALGOR_get0(&obj, NULL, NULL, alg);
return ossl_asn1obj_to_string_long_name(obj);
}
|
#subject ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'ext/openssl/ossl_x509req.c', line 230
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=(subject) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'ext/openssl/ossl_x509req.c', line 244
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 ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'ext/openssl/ossl_x509req.c', line 143
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 ⇒ Object Also known as: to_s
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/openssl/ossl_x509req.c', line 125
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);
}
|
#to_text ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'ext/openssl/ossl_x509req.c', line 163
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(key) ⇒ Object
Checks that cert signature is made with PRIVversion of this PUBLIC ‘key’
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'ext/openssl/ossl_x509req.c', line 329
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 ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'ext/openssl/ossl_x509req.c', line 201
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=(version) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'ext/openssl/ossl_x509req.c', line 213
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;
}
|