2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This program is licenced under the same licence as Ruby.
|
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
|
|
|
#define WrapX509Rev(klass, obj, rev) do { \
|
2011-03-18 23:30:59 -04:00
|
|
|
if (!(rev)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
|
|
|
|
} \
|
2011-03-18 23:30:59 -04:00
|
|
|
(obj) = Data_Wrap_Struct((klass), 0, X509_REVOKED_free, (rev)); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetX509Rev(obj, rev) do { \
|
2011-03-18 23:30:59 -04:00
|
|
|
Data_Get_Struct((obj), X509_REVOKED, (rev)); \
|
|
|
|
if (!(rev)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define SafeGetX509Rev(obj, rev) do { \
|
2011-03-18 23:30:59 -04:00
|
|
|
OSSL_Check_Kind((obj), cX509Rev); \
|
|
|
|
GetX509Rev((obj), (rev)); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cX509Rev;
|
|
|
|
VALUE eX509RevError;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PUBLIC
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_new(X509_REVOKED *rev)
|
|
|
|
{
|
|
|
|
X509_REVOKED *new;
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
if (!rev) {
|
|
|
|
new = X509_REVOKED_new();
|
|
|
|
} else {
|
|
|
|
new = X509_REVOKED_dup(rev);
|
|
|
|
}
|
|
|
|
if (!new) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
WrapX509Rev(cX509Rev, obj, new);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
X509_REVOKED *
|
|
|
|
DupX509RevokedPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev, *new;
|
|
|
|
|
|
|
|
SafeGetX509Rev(obj, rev);
|
|
|
|
if (!(new = X509_REVOKED_dup(rev))) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PRIVATE
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
if (!(rev = X509_REVOKED_new())) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
WrapX509Rev(klass, obj, rev);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
/* EMPTY */
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_get_serial(VALUE self)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
|
|
|
|
GetX509Rev(self, rev);
|
|
|
|
|
|
|
|
return asn1integer_to_num(rev->serialNumber);
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_set_serial(VALUE self, VALUE num)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
|
|
|
|
GetX509Rev(self, rev);
|
|
|
|
rev->serialNumber = num_to_asn1integer(num, rev->serialNumber);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_get_time(VALUE self)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetX509Rev(self, rev);
|
|
|
|
|
|
|
|
return asn1time_to_time(rev->revocationDate);
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509revoked_set_time(VALUE self, VALUE time)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
time_t sec;
|
|
|
|
|
|
|
|
sec = time_to_time_t(time);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509Rev(self, rev);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!X509_time_adj(rev->revocationDate, 0, &sec)) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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_x509revoked_get_extensions(VALUE self)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
int count, i;
|
|
|
|
X509_EXTENSION *ext;
|
|
|
|
VALUE ary;
|
|
|
|
|
|
|
|
GetX509Rev(self, rev);
|
|
|
|
count = X509_REVOKED_get_ext_count(rev);
|
|
|
|
if (count < 0) {
|
|
|
|
OSSL_Debug("count < 0???");
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(count);
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
ext = X509_REVOKED_get_ext(rev, i);
|
|
|
|
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_x509revoked_set_extensions(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
|
|
|
X509_EXTENSION *ext;
|
|
|
|
int i;
|
|
|
|
VALUE item;
|
|
|
|
|
|
|
|
Check_Type(ary, T_ARRAY);
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
|
|
OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509Rev(self, rev);
|
2003-07-23 12:12:24 -04:00
|
|
|
sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
|
|
|
|
rev->extensions = NULL;
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
|
|
item = RARRAY_PTR(ary)[i];
|
2003-07-23 12:12:24 -04:00
|
|
|
ext = DupX509ExtPtr(item);
|
|
|
|
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_x509revoked_add_extension(VALUE self, VALUE ext)
|
|
|
|
{
|
|
|
|
X509_REVOKED *rev;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetX509Rev(self, rev);
|
|
|
|
if(!X509_REVOKED_add_ext(rev, DupX509ExtPtr(ext), -1)) {
|
|
|
|
ossl_raise(eX509RevError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Init_ossl_x509revoked()
|
|
|
|
{
|
|
|
|
eX509RevError = rb_define_class_under(mX509, "RevokedError", eOSSLError);
|
|
|
|
|
|
|
|
cX509Rev = rb_define_class_under(mX509, "Revoked", rb_cObject);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_alloc_func(cX509Rev, ossl_x509revoked_alloc);
|
|
|
|
rb_define_method(cX509Rev, "initialize", ossl_x509revoked_initialize, -1);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cX509Rev, "serial", ossl_x509revoked_get_serial, 0);
|
|
|
|
rb_define_method(cX509Rev, "serial=", ossl_x509revoked_set_serial, 1);
|
|
|
|
rb_define_method(cX509Rev, "time", ossl_x509revoked_get_time, 0);
|
|
|
|
rb_define_method(cX509Rev, "time=", ossl_x509revoked_set_time, 1);
|
|
|
|
rb_define_method(cX509Rev, "extensions", ossl_x509revoked_get_extensions, 0);
|
|
|
|
rb_define_method(cX509Rev, "extensions=", ossl_x509revoked_set_extensions, 1);
|
|
|
|
rb_define_method(cX509Rev, "add_extension", ossl_x509revoked_add_extension, 1);
|
|
|
|
}
|
|
|
|
|