2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
2015-04-19 23:55:09 -04:00
|
|
|
* This program is licensed under the same licence as Ruby.
|
2003-07-23 12:12:24 -04:00
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
#define NewX509CRL(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_x509crl_type, 0)
|
|
|
|
#define SetX509CRL(obj, crl) do { \
|
2011-03-15 05:34:51 -04:00
|
|
|
if (!(crl)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (crl); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetX509CRL(obj, crl) do { \
|
2014-12-12 18:39:04 -05:00
|
|
|
TypedData_Get_Struct((obj), X509_CRL, &ossl_x509crl_type, (crl)); \
|
2011-03-15 05:34:51 -04:00
|
|
|
if (!(crl)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cX509CRL;
|
|
|
|
VALUE eX509CRLError;
|
|
|
|
|
2014-12-12 18:39:04 -05:00
|
|
|
static void
|
|
|
|
ossl_x509crl_free(void *ptr)
|
|
|
|
{
|
|
|
|
X509_CRL_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_x509crl_type = {
|
|
|
|
"OpenSSL/X509/CRL",
|
|
|
|
{
|
|
|
|
0, ossl_x509crl_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* PUBLIC
|
|
|
|
*/
|
|
|
|
X509_CRL *
|
|
|
|
GetX509CRLPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
GetX509CRL(obj, crl);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return crl;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
ossl_x509crl_new(X509_CRL *crl)
|
|
|
|
{
|
|
|
|
X509_CRL *tmp;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewX509CRL(cX509CRL);
|
2003-07-23 12:12:24 -04:00
|
|
|
tmp = crl ? X509_CRL_dup(crl) : X509_CRL_new();
|
|
|
|
if(!tmp) ossl_raise(eX509CRLError, NULL);
|
2015-05-29 01:55:02 -04:00
|
|
|
SetX509CRL(obj, tmp);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PRIVATE
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewX509CRL(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(crl = X509_CRL_new())) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetX509CRL(obj, crl);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
BIO *in;
|
2021-05-19 04:58:18 -04:00
|
|
|
X509_CRL *crl, *crl_orig = RTYPEDDATA_DATA(self);
|
2003-09-17 05:05:02 -04:00
|
|
|
VALUE arg;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2021-05-19 04:58:18 -04:00
|
|
|
rb_check_frozen(self);
|
2003-09-17 05:05:02 -04:00
|
|
|
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
2003-07-23 12:12:24 -04:00
|
|
|
return self;
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
arg = ossl_to_der_if_possible(arg);
|
2017-08-10 05:23:45 -04:00
|
|
|
in = ossl_obj2bio(&arg);
|
2021-05-19 04:58:18 -04:00
|
|
|
crl = d2i_X509_CRL_bio(in, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!crl) {
|
2021-05-19 04:58:18 -04:00
|
|
|
OSSL_BIO_reset(in);
|
|
|
|
crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
BIO_free(in);
|
2021-05-19 04:58:18 -04:00
|
|
|
if (!crl)
|
|
|
|
ossl_raise(eX509CRLError, "PEM_read_bio_X509_CRL");
|
|
|
|
|
|
|
|
RTYPEDDATA_DATA(self) = crl;
|
|
|
|
X509_CRL_free(crl_orig);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_x509crl_copy(VALUE self, VALUE other)
|
|
|
|
{
|
|
|
|
X509_CRL *a, *b, *crl;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_check_frozen(self);
|
|
|
|
if (self == other) return self;
|
|
|
|
GetX509CRL(self, a);
|
2017-09-03 08:35:27 -04:00
|
|
|
GetX509CRL(other, b);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(crl = X509_CRL_dup(b))) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
X509_CRL_free(a);
|
|
|
|
DATA_PTR(self) = crl;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_version(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
long ver;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
ver = X509_CRL_get_version(crl);
|
|
|
|
|
|
|
|
return LONG2NUM(ver);
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_version(VALUE self, VALUE version)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
long ver;
|
|
|
|
|
|
|
|
if ((ver = NUM2LONG(version)) < 0) {
|
|
|
|
ossl_raise(eX509CRLError, "version must be >= 0!");
|
|
|
|
}
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509CRL(self, crl);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!X509_CRL_set_version(crl, ver)) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_signature_algorithm(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2016-08-29 01:47:09 -04:00
|
|
|
const X509_ALGOR *alg;
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO *out;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
2016-08-29 01:47:09 -04:00
|
|
|
X509_CRL_get0_signature(crl, NULL, &alg);
|
2016-06-05 11:35:12 -04:00
|
|
|
if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
2016-11-30 09:41:46 -05:00
|
|
|
|
|
|
|
return ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_issuer(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
|
|
|
|
return ossl_x509name_new(X509_CRL_get_issuer(crl)); /* NO DUP - don't free */
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
|
|
|
|
if (!X509_CRL_set_issuer_name(crl, GetX509NamePtr(issuer))) { /* DUPs name */
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
return issuer;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_last_update(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2017-09-03 08:35:27 -04:00
|
|
|
const ASN1_TIME *time;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
2017-09-03 08:35:27 -04:00
|
|
|
time = X509_CRL_get0_lastUpdate(crl);
|
|
|
|
if (!time)
|
|
|
|
return Qnil;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
return asn1time_to_time(time);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_last_update(VALUE self, VALUE time)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2016-08-29 01:47:09 -04:00
|
|
|
ASN1_TIME *asn1time;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509CRL(self, crl);
|
2016-08-29 01:47:09 -04:00
|
|
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
2017-11-25 09:12:08 -05:00
|
|
|
if (!X509_CRL_set1_lastUpdate(crl, asn1time)) {
|
2016-08-29 01:47:09 -04:00
|
|
|
ASN1_TIME_free(asn1time);
|
|
|
|
ossl_raise(eX509CRLError, "X509_CRL_set_lastUpdate");
|
|
|
|
}
|
|
|
|
ASN1_TIME_free(asn1time);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_next_update(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2017-09-03 08:35:27 -04:00
|
|
|
const ASN1_TIME *time;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
2017-09-03 08:35:27 -04:00
|
|
|
time = X509_CRL_get0_nextUpdate(crl);
|
|
|
|
if (!time)
|
|
|
|
return Qnil;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
return asn1time_to_time(time);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_next_update(VALUE self, VALUE time)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2016-08-29 01:47:09 -04:00
|
|
|
ASN1_TIME *asn1time;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509CRL(self, crl);
|
2016-08-29 01:47:09 -04:00
|
|
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
2017-11-25 09:12:08 -05:00
|
|
|
if (!X509_CRL_set1_nextUpdate(crl, asn1time)) {
|
2016-08-29 01:47:09 -04:00
|
|
|
ASN1_TIME_free(asn1time);
|
|
|
|
ossl_raise(eX509CRLError, "X509_CRL_set_nextUpdate");
|
2016-06-05 11:35:12 -04:00
|
|
|
}
|
2016-08-29 01:47:09 -04:00
|
|
|
ASN1_TIME_free(asn1time);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_x509crl_get_revoked(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
int i, num;
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
VALUE ary, revoked;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
2010-02-27 21:56:26 -05:00
|
|
|
num = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
|
2003-07-23 12:12:24 -04:00
|
|
|
if (num < 0) {
|
|
|
|
OSSL_Debug("num < 0???");
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(num);
|
|
|
|
for(i=0; i<num; i++) {
|
|
|
|
/* NO DUP - don't free! */
|
2010-02-27 21:56:26 -05:00
|
|
|
rev = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
|
2003-07-23 12:12:24 -04:00
|
|
|
revoked = ossl_x509revoked_new(rev);
|
|
|
|
rb_ary_push(ary, revoked);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_revoked(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
X509_REVOKED *rev;
|
2016-08-29 01:47:09 -04:00
|
|
|
STACK_OF(X509_REVOKED) *sk;
|
2015-11-04 02:18:01 -05:00
|
|
|
long i;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
Check_Type(ary, T_ARRAY);
|
|
|
|
/* All ary members should be X509 Revoked */
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
2015-11-04 20:09:17 -05:00
|
|
|
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Rev);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509CRL(self, crl);
|
2016-08-29 01:47:09 -04:00
|
|
|
if ((sk = X509_CRL_get_REVOKED(crl))) {
|
|
|
|
while ((rev = sk_X509_REVOKED_pop(sk)))
|
|
|
|
X509_REVOKED_free(rev);
|
|
|
|
}
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
2015-11-04 20:09:17 -05:00
|
|
|
rev = DupX509RevokedPtr(RARRAY_AREF(ary, i));
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
2016-08-29 01:47:09 -04:00
|
|
|
X509_REVOKED_free(rev);
|
|
|
|
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
X509_CRL_sort(crl);
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
rev = DupX509RevokedPtr(revoked);
|
|
|
|
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
2016-08-29 01:47:09 -04:00
|
|
|
X509_REVOKED_free(rev);
|
|
|
|
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
X509_CRL_sort(crl);
|
|
|
|
|
|
|
|
return revoked;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
const EVP_MD *md;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
2017-09-03 08:35:27 -04:00
|
|
|
md = ossl_evp_get_digestbyname(digest);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!X509_CRL_sign(crl, pkey, md)) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_verify(VALUE self, VALUE key)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
2017-11-25 09:12:08 -05:00
|
|
|
EVP_PKEY *pkey;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
2017-11-25 09:12:08 -05:00
|
|
|
pkey = GetPKeyPtr(key);
|
|
|
|
ossl_pkey_check_public_key(pkey);
|
|
|
|
switch (X509_CRL_verify(crl, pkey)) {
|
2016-05-18 00:07:47 -04:00
|
|
|
case 1:
|
2003-07-23 12:12:24 -04:00
|
|
|
return Qtrue;
|
2016-05-18 00:07:47 -04:00
|
|
|
case 0:
|
|
|
|
ossl_clear_error();
|
|
|
|
return Qfalse;
|
|
|
|
default:
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_to_der(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
BIO *out;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
if (!i2d_X509_CRL_bio(out, crl)) {
|
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
return ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_to_pem(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
BIO *out;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
if (!PEM_write_bio_X509_CRL(out, crl)) {
|
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
return ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_to_text(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
BIO *out;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
if (!X509_CRL_print(out, crl)) {
|
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
return ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets X509v3 extensions as array of X509Ext objects
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_get_extensions(VALUE self)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
int count, i;
|
|
|
|
X509_EXTENSION *ext;
|
|
|
|
VALUE ary;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
|
|
|
count = X509_CRL_get_ext_count(crl);
|
|
|
|
if (count < 0) {
|
|
|
|
OSSL_Debug("count < 0???");
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(count);
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
|
|
|
|
rb_ary_push(ary, ossl_x509ext_new(ext));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets X509_EXTENSIONs
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_set_extensions(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
X509_EXTENSION *ext;
|
2015-11-04 02:18:01 -05:00
|
|
|
long i;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
Check_Type(ary, T_ARRAY);
|
|
|
|
/* All ary members should be X509 Extensions */
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
2015-11-04 20:09:17 -05:00
|
|
|
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509CRL(self, crl);
|
2016-06-05 11:35:12 -04:00
|
|
|
while ((ext = X509_CRL_delete_ext(crl, 0)))
|
|
|
|
X509_EXTENSION_free(ext);
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
2016-08-29 01:47:09 -04:00
|
|
|
ext = GetX509ExtPtr(RARRAY_AREF(ary, i)); /* NO NEED TO DUP */
|
|
|
|
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509crl_add_extension(VALUE self, VALUE extension)
|
|
|
|
{
|
|
|
|
X509_CRL *crl;
|
|
|
|
X509_EXTENSION *ext;
|
|
|
|
|
|
|
|
GetX509CRL(self, crl);
|
2016-08-29 01:47:09 -04:00
|
|
|
ext = GetX509ExtPtr(extension);
|
|
|
|
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(eX509CRLError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
void
|
2014-09-30 01:25:32 -04:00
|
|
|
Init_ossl_x509crl(void)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2016-08-29 01:47:09 -04:00
|
|
|
#if 0
|
|
|
|
mOSSL = rb_define_module("OpenSSL");
|
|
|
|
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
|
|
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
|
|
#endif
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError);
|
|
|
|
|
|
|
|
cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_alloc_func(cX509CRL, ossl_x509crl_alloc);
|
|
|
|
rb_define_method(cX509CRL, "initialize", ossl_x509crl_initialize, -1);
|
2017-09-03 08:35:27 -04:00
|
|
|
rb_define_method(cX509CRL, "initialize_copy", ossl_x509crl_copy, 1);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cX509CRL, "version", ossl_x509crl_get_version, 0);
|
|
|
|
rb_define_method(cX509CRL, "version=", ossl_x509crl_set_version, 1);
|
|
|
|
rb_define_method(cX509CRL, "signature_algorithm", ossl_x509crl_get_signature_algorithm, 0);
|
|
|
|
rb_define_method(cX509CRL, "issuer", ossl_x509crl_get_issuer, 0);
|
|
|
|
rb_define_method(cX509CRL, "issuer=", ossl_x509crl_set_issuer, 1);
|
|
|
|
rb_define_method(cX509CRL, "last_update", ossl_x509crl_get_last_update, 0);
|
|
|
|
rb_define_method(cX509CRL, "last_update=", ossl_x509crl_set_last_update, 1);
|
|
|
|
rb_define_method(cX509CRL, "next_update", ossl_x509crl_get_next_update, 0);
|
|
|
|
rb_define_method(cX509CRL, "next_update=", ossl_x509crl_set_next_update, 1);
|
|
|
|
rb_define_method(cX509CRL, "revoked", ossl_x509crl_get_revoked, 0);
|
|
|
|
rb_define_method(cX509CRL, "revoked=", ossl_x509crl_set_revoked, 1);
|
|
|
|
rb_define_method(cX509CRL, "add_revoked", ossl_x509crl_add_revoked, 1);
|
|
|
|
rb_define_method(cX509CRL, "sign", ossl_x509crl_sign, 2);
|
|
|
|
rb_define_method(cX509CRL, "verify", ossl_x509crl_verify, 1);
|
|
|
|
rb_define_method(cX509CRL, "to_der", ossl_x509crl_to_der, 0);
|
|
|
|
rb_define_method(cX509CRL, "to_pem", ossl_x509crl_to_pem, 0);
|
|
|
|
rb_define_alias(cX509CRL, "to_s", "to_pem");
|
|
|
|
rb_define_method(cX509CRL, "to_text", ossl_x509crl_to_text, 0);
|
|
|
|
rb_define_method(cX509CRL, "extensions", ossl_x509crl_get_extensions, 0);
|
|
|
|
rb_define_method(cX509CRL, "extensions=", ossl_x509crl_set_extensions, 1);
|
|
|
|
rb_define_method(cX509CRL, "add_extension", ossl_x509crl_add_extension, 1);
|
|
|
|
}
|