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 NewPKCS7(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
|
|
|
|
#define SetPKCS7(obj, pkcs7) do { \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(pkcs7)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (pkcs7); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetPKCS7(obj, pkcs7) do { \
|
2014-12-12 17:37:55 -05:00
|
|
|
TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(pkcs7)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
#define NewPKCS7si(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
|
|
|
|
#define SetPKCS7si(obj, p7si) do { \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(p7si)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (p7si); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetPKCS7si(obj, p7si) do { \
|
2014-12-12 17:37:58 -05:00
|
|
|
TypedData_Get_Struct((obj), PKCS7_SIGNER_INFO, &ossl_pkcs7_signer_info_type, (p7si)); \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(p7si)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
#define NewPKCS7ri(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_pkcs7_recip_info_type, 0)
|
|
|
|
#define SetPKCS7ri(obj, p7ri) do { \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(p7ri)) { \
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (p7ri); \
|
2005-09-07 03:40:55 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetPKCS7ri(obj, p7ri) do { \
|
2014-12-12 17:38:01 -05:00
|
|
|
TypedData_Get_Struct((obj), PKCS7_RECIP_INFO, &ossl_pkcs7_recip_info_type, (p7ri)); \
|
2011-03-07 03:44:45 -05:00
|
|
|
if (!(p7ri)) { \
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
#define ossl_pkcs7_set_data(o,v) rb_iv_set((o), "@data", (v))
|
|
|
|
#define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data")
|
|
|
|
#define ossl_pkcs7_set_err_string(o,v) rb_iv_set((o), "@error_string", (v))
|
|
|
|
#define ossl_pkcs7_get_err_string(o) rb_iv_get((o), "@error_string")
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
/*
|
2003-07-23 12:12:24 -04:00
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cPKCS7;
|
|
|
|
VALUE cPKCS7Signer;
|
2005-09-07 03:40:55 -04:00
|
|
|
VALUE cPKCS7Recipient;
|
2003-07-23 12:12:24 -04:00
|
|
|
VALUE ePKCS7Error;
|
|
|
|
|
2014-12-12 17:37:55 -05:00
|
|
|
static void
|
|
|
|
ossl_pkcs7_free(void *ptr)
|
|
|
|
{
|
|
|
|
PKCS7_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_pkcs7_type = {
|
|
|
|
"OpenSSL/PKCS7",
|
|
|
|
{
|
|
|
|
0, ossl_pkcs7_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2014-12-12 17:37:58 -05:00
|
|
|
static void
|
|
|
|
ossl_pkcs7_signer_info_free(void *ptr)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_pkcs7_signer_info_type = {
|
|
|
|
"OpenSSL/PKCS7/SIGNER_INFO",
|
|
|
|
{
|
|
|
|
0, ossl_pkcs7_signer_info_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2014-12-12 17:38:01 -05:00
|
|
|
static void
|
|
|
|
ossl_pkcs7_recip_info_free(void *ptr)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_pkcs7_recip_info_type = {
|
|
|
|
"OpenSSL/PKCS7/RECIP_INFO",
|
|
|
|
{
|
|
|
|
0, ossl_pkcs7_recip_info_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Public
|
|
|
|
* (MADE PRIVATE UNTIL SOMEBODY WILL NEED THEM)
|
|
|
|
*/
|
2016-05-25 04:50:03 -04:00
|
|
|
static PKCS7_SIGNER_INFO *
|
|
|
|
ossl_PKCS7_SIGNER_INFO_dup(const PKCS7_SIGNER_INFO *si)
|
|
|
|
{
|
|
|
|
return (PKCS7_SIGNER_INFO *)ASN1_dup((i2d_of_void *)i2d_PKCS7_SIGNER_INFO,
|
|
|
|
(d2i_of_void *)d2i_PKCS7_SIGNER_INFO,
|
|
|
|
(char *)si);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PKCS7_RECIP_INFO *
|
|
|
|
ossl_PKCS7_RECIP_INFO_dup(const PKCS7_RECIP_INFO *si)
|
|
|
|
{
|
|
|
|
return (PKCS7_RECIP_INFO *)ASN1_dup((i2d_of_void *)i2d_PKCS7_RECIP_INFO,
|
|
|
|
(d2i_of_void *)d2i_PKCS7_RECIP_INFO,
|
|
|
|
(char *)si);
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7si_new(PKCS7_SIGNER_INFO *p7si)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *pkcs7;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKCS7si(cPKCS7Signer);
|
2016-05-25 04:50:03 -04:00
|
|
|
pkcs7 = p7si ? ossl_PKCS7_SIGNER_INFO_dup(p7si) : PKCS7_SIGNER_INFO_new();
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7si(obj, pkcs7);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PKCS7_SIGNER_INFO *
|
|
|
|
DupPKCS7SignerPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si, *pkcs7;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
GetPKCS7si(obj, p7si);
|
2016-05-25 04:50:03 -04:00
|
|
|
if (!(pkcs7 = ossl_PKCS7_SIGNER_INFO_dup(p7si))) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkcs7;
|
|
|
|
}
|
|
|
|
|
2005-09-07 03:40:55 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_new(PKCS7_RECIP_INFO *p7ri)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *pkcs7;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKCS7ri(cPKCS7Recipient);
|
2016-05-25 04:50:03 -04:00
|
|
|
pkcs7 = p7ri ? ossl_PKCS7_RECIP_INFO_dup(p7ri) : PKCS7_RECIP_INFO_new();
|
2005-09-07 03:40:55 -04:00
|
|
|
if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7ri(obj, pkcs7);
|
2005-09-07 03:40:55 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PKCS7_RECIP_INFO *
|
|
|
|
DupPKCS7RecipientPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri, *pkcs7;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
GetPKCS7ri(obj, p7ri);
|
2016-05-25 04:50:03 -04:00
|
|
|
if (!(pkcs7 = ossl_PKCS7_RECIP_INFO_dup(p7ri))) {
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkcs7;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
2007-04-05 01:59:22 -04:00
|
|
|
* call-seq:
|
|
|
|
* PKCS7.read_smime(string) => pkcs7
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
|
|
|
|
{
|
|
|
|
BIO *in, *out;
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
VALUE ret, data;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
ret = NewPKCS7(cPKCS7);
|
2017-08-10 05:23:45 -04:00
|
|
|
in = ossl_obj2bio(&arg);
|
2003-07-23 12:12:24 -04:00
|
|
|
out = NULL;
|
2003-09-17 05:05:02 -04:00
|
|
|
pkcs7 = SMIME_read_PKCS7(in, &out);
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(in);
|
2003-09-17 05:05:02 -04:00
|
|
|
if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
|
|
|
data = out ? ossl_membio2str(out) : Qnil;
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7(ret, pkcs7);
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_pkcs7_set_data(ret, data);
|
|
|
|
ossl_pkcs7_set_err_string(ret, Qnil);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* PKCS7.write_smime(pkcs7 [, data [, flags]]) => string
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE pkcs7, data, flags;
|
2003-09-17 05:05:02 -04:00
|
|
|
BIO *out, *in;
|
2003-07-23 12:12:24 -04:00
|
|
|
PKCS7 *p7;
|
|
|
|
VALUE str;
|
2003-09-17 05:05:02 -04:00
|
|
|
int flg;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", &pkcs7, &data, &flags);
|
|
|
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
|
|
|
if(NIL_P(data)) data = ossl_pkcs7_get_data(pkcs7);
|
2017-09-03 08:35:27 -04:00
|
|
|
GetPKCS7(pkcs7, p7);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!NIL_P(data) && PKCS7_is_detached(p7))
|
|
|
|
flg |= PKCS7_DETACHED;
|
2017-08-10 05:23:45 -04:00
|
|
|
in = NIL_P(data) ? NULL : ossl_obj2bio(&data);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!(out = BIO_new(BIO_s_mem()))){
|
|
|
|
BIO_free(in);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
if(!SMIME_write_PKCS7(out, p7, in, flg)){
|
|
|
|
BIO_free(out);
|
|
|
|
BIO_free(in);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
BIO_free(in);
|
2003-09-17 05:05:02 -04:00
|
|
|
str = ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* PKCS7.sign(cert, key, data, [, certs [, flags]]) => pkcs7
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE cert, key, data, certs, flags;
|
|
|
|
X509 *x509;
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
BIO *in;
|
|
|
|
STACK_OF(X509) *x509s;
|
|
|
|
int flg, status = 0;
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
VALUE ret;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "32", &cert, &key, &data, &certs, &flags);
|
|
|
|
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
|
|
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
|
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
2015-05-29 01:55:02 -04:00
|
|
|
ret = NewPKCS7(cPKCS7);
|
2017-08-10 05:23:45 -04:00
|
|
|
in = ossl_obj2bio(&data);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(NIL_P(certs)) x509s = NULL;
|
|
|
|
else{
|
|
|
|
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
|
|
|
if(status){
|
|
|
|
BIO_free(in);
|
|
|
|
rb_jump_tag(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!(pkcs7 = PKCS7_sign(x509, pkey, x509s, in, flg))){
|
|
|
|
BIO_free(in);
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7(ret, pkcs7);
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_pkcs7_set_data(ret, data);
|
|
|
|
ossl_pkcs7_set_err_string(ret, Qnil);
|
|
|
|
BIO_free(in);
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* PKCS7.encrypt(certs, data, [, cipher [, flags]]) => pkcs7
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE certs, data, cipher, flags;
|
|
|
|
STACK_OF(X509) *x509s;
|
|
|
|
BIO *in;
|
|
|
|
const EVP_CIPHER *ciph;
|
|
|
|
int flg, status = 0;
|
|
|
|
VALUE ret;
|
|
|
|
PKCS7 *p7;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "22", &certs, &data, &cipher, &flags);
|
|
|
|
if(NIL_P(cipher)){
|
|
|
|
#if !defined(OPENSSL_NO_RC2)
|
|
|
|
ciph = EVP_rc2_40_cbc();
|
|
|
|
#elif !defined(OPENSSL_NO_DES)
|
|
|
|
ciph = EVP_des_ede3_cbc();
|
|
|
|
#elif !defined(OPENSSL_NO_RC2)
|
|
|
|
ciph = EVP_rc2_40_cbc();
|
|
|
|
#elif !defined(OPENSSL_NO_AES)
|
|
|
|
ciph = EVP_EVP_aes_128_cbc();
|
|
|
|
#else
|
|
|
|
ossl_raise(ePKCS7Error, "Must specify cipher");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2017-09-03 08:35:27 -04:00
|
|
|
else ciph = ossl_evp_get_cipherbyname(cipher);
|
2003-07-23 12:12:24 -04:00
|
|
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
2015-05-29 01:55:02 -04:00
|
|
|
ret = NewPKCS7(cPKCS7);
|
2017-08-10 05:23:45 -04:00
|
|
|
in = ossl_obj2bio(&data);
|
2003-07-23 12:12:24 -04:00
|
|
|
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
|
|
|
if(status){
|
|
|
|
BIO_free(in);
|
|
|
|
rb_jump_tag(status);
|
|
|
|
}
|
2003-07-25 02:50:55 -04:00
|
|
|
if(!(p7 = PKCS7_encrypt(x509s, in, (EVP_CIPHER*)ciph, flg))){
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(in);
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
BIO_free(in);
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7(ret, p7);
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_pkcs7_set_data(ret, data);
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKCS7(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(pkcs7 = PKCS7_new())) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7(obj, pkcs7);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* PKCS7.new => pkcs7
|
|
|
|
* PKCS7.new(string) => pkcs7
|
|
|
|
*
|
|
|
|
* Many methods in this class aren't documented.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
2008-07-22 11:34:23 -04:00
|
|
|
PKCS7 *p7, *pkcs = DATA_PTR(self);
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO *in;
|
2003-09-17 05:05:02 -04:00
|
|
|
VALUE arg;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
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);
|
2008-07-22 11:34:23 -04:00
|
|
|
p7 = PEM_read_bio_PKCS7(in, &pkcs, NULL, NULL);
|
2003-09-17 05:05:02 -04:00
|
|
|
if (!p7) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2008-07-22 11:34:23 -04:00
|
|
|
p7 = d2i_PKCS7_bio(in, &pkcs);
|
2012-03-28 21:27:17 -04:00
|
|
|
if (!p7) {
|
|
|
|
BIO_free(in);
|
|
|
|
PKCS7_free(pkcs);
|
|
|
|
DATA_PTR(self) = NULL;
|
2011-06-22 04:41:08 -04:00
|
|
|
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
|
2012-03-28 21:27:17 -04:00
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2012-03-28 21:27:17 -04:00
|
|
|
DATA_PTR(self) = pkcs;
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(in);
|
|
|
|
ossl_pkcs7_set_data(self, Qnil);
|
|
|
|
ossl_pkcs7_set_err_string(self, Qnil);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_copy(VALUE self, VALUE other)
|
|
|
|
{
|
|
|
|
PKCS7 *a, *b, *pkcs7;
|
|
|
|
|
|
|
|
rb_check_frozen(self);
|
|
|
|
if (self == other) return self;
|
|
|
|
|
|
|
|
GetPKCS7(self, a);
|
2017-09-03 08:35:27 -04:00
|
|
|
GetPKCS7(other, b);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
pkcs7 = PKCS7_dup(b);
|
|
|
|
if (!pkcs7) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
DATA_PTR(self) = pkcs7;
|
|
|
|
PKCS7_free(a);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ossl_pkcs7_sym2typeid(VALUE sym)
|
|
|
|
{
|
|
|
|
int i, ret = Qnil;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const char *s;
|
2014-08-03 11:19:16 -04:00
|
|
|
size_t l;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2014-08-03 11:19:20 -04:00
|
|
|
static const struct {
|
|
|
|
char name[20];
|
2003-07-23 12:12:24 -04:00
|
|
|
int nid;
|
|
|
|
} p7_type_tab[] = {
|
|
|
|
{ "signed", NID_pkcs7_signed },
|
|
|
|
{ "data", NID_pkcs7_data },
|
|
|
|
{ "signedAndEnveloped", NID_pkcs7_signedAndEnveloped },
|
|
|
|
{ "enveloped", NID_pkcs7_enveloped },
|
|
|
|
{ "encrypted", NID_pkcs7_encrypted },
|
|
|
|
{ "digest", NID_pkcs7_digest },
|
|
|
|
};
|
|
|
|
|
2016-05-23 07:40:07 -04:00
|
|
|
if (SYMBOL_P(sym)) sym = rb_sym2str(sym);
|
2014-08-03 11:19:16 -04:00
|
|
|
else StringValue(sym);
|
|
|
|
RSTRING_GETMEM(sym, s, l);
|
2016-05-23 07:40:07 -04:00
|
|
|
|
2014-08-03 11:19:20 -04:00
|
|
|
for(i = 0; ; i++){
|
|
|
|
if(i == numberof(p7_type_tab))
|
2016-05-23 07:40:07 -04:00
|
|
|
ossl_raise(ePKCS7Error, "unknown type \"%"PRIsVALUE"\"", sym);
|
2014-08-03 11:19:16 -04:00
|
|
|
if(strlen(p7_type_tab[i].name) != l) continue;
|
2003-07-23 12:12:24 -04:00
|
|
|
if(strcmp(p7_type_tab[i].name, s) == 0){
|
|
|
|
ret = p7_type_tab[i].nid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* pkcs7.type = type => type
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_set_type(VALUE self, VALUE type)
|
|
|
|
{
|
|
|
|
PKCS7 *p7;
|
|
|
|
|
|
|
|
GetPKCS7(self, p7);
|
|
|
|
if(!PKCS7_set_type(p7, ossl_pkcs7_sym2typeid(type)))
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* pkcs7.type => string or nil
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_type(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *p7;
|
|
|
|
|
|
|
|
GetPKCS7(self, p7);
|
|
|
|
if(PKCS7_type_is_signed(p7))
|
|
|
|
return ID2SYM(rb_intern("signed"));
|
|
|
|
if(PKCS7_type_is_encrypted(p7))
|
|
|
|
return ID2SYM(rb_intern("encrypted"));
|
|
|
|
if(PKCS7_type_is_enveloped(p7))
|
|
|
|
return ID2SYM(rb_intern("enveloped"));
|
|
|
|
if(PKCS7_type_is_signedAndEnveloped(p7))
|
|
|
|
return ID2SYM(rb_intern("signedAndEnveloped"));
|
|
|
|
if(PKCS7_type_is_data(p7))
|
|
|
|
return ID2SYM(rb_intern("data"));
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_set_detached(VALUE self, VALUE flag)
|
|
|
|
{
|
|
|
|
PKCS7 *p7;
|
|
|
|
|
|
|
|
GetPKCS7(self, p7);
|
|
|
|
if(flag != Qtrue && flag != Qfalse)
|
2004-03-29 02:54:38 -05:00
|
|
|
ossl_raise(ePKCS7Error, "must specify a boolean");
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!PKCS7_set_detached(p7, flag == Qtrue ? 1 : 0))
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_detached(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *p7;
|
|
|
|
GetPKCS7(self, p7);
|
|
|
|
return PKCS7_get_detached(p7) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_detached_p(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *p7;
|
|
|
|
GetPKCS7(self, p7);
|
|
|
|
return PKCS7_is_detached(p7) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_set_cipher(VALUE self, VALUE cipher)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
2017-09-03 08:35:27 -04:00
|
|
|
if (!PKCS7_set_cipher(pkcs7, ossl_evp_get_cipherbyname(cipher))) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cipher;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_add_signer(VALUE self, VALUE signer)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
|
|
|
|
p7si = DupPKCS7SignerPtr(signer); /* NEED TO DUP */
|
2004-12-15 01:35:55 -05:00
|
|
|
GetPKCS7(self, pkcs7);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!PKCS7_add_signer(pkcs7, p7si)) {
|
|
|
|
PKCS7_SIGNER_INFO_free(p7si);
|
|
|
|
ossl_raise(ePKCS7Error, "Could not add signer.");
|
|
|
|
}
|
|
|
|
if (PKCS7_type_is_signed(pkcs7)){
|
|
|
|
PKCS7_add_signed_attribute(p7si, NID_pkcs9_contentType,
|
|
|
|
V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_signer(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
STACK_OF(PKCS7_SIGNER_INFO) *sk;
|
|
|
|
PKCS7_SIGNER_INFO *si;
|
|
|
|
int num, i;
|
|
|
|
VALUE ary;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
if (!(sk = PKCS7_get_signer_info(pkcs7))) {
|
|
|
|
OSSL_Debug("OpenSSL::PKCS7#get_signer_info == NULL!");
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
if ((num = sk_PKCS7_SIGNER_INFO_num(sk)) < 0) {
|
|
|
|
ossl_raise(ePKCS7Error, "Negative number of signers!");
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(num);
|
|
|
|
for (i=0; i<num; i++) {
|
|
|
|
si = sk_PKCS7_SIGNER_INFO_value(sk, i);
|
|
|
|
rb_ary_push(ary, ossl_pkcs7si_new(si));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_pkcs7_add_recipient(VALUE self, VALUE recip)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
PKCS7_RECIP_INFO *ri;
|
2005-09-07 03:40:55 -04:00
|
|
|
|
|
|
|
ri = DupPKCS7RecipientPtr(recip); /* NEED TO DUP */
|
2004-12-15 01:35:55 -05:00
|
|
|
GetPKCS7(self, pkcs7);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!PKCS7_add_recipient_info(pkcs7, ri)) {
|
|
|
|
PKCS7_RECIP_INFO_free(ri);
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_raise(ePKCS7Error, "Could not add recipient.");
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2005-09-07 03:40:55 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_recipient(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
STACK_OF(PKCS7_RECIP_INFO) *sk;
|
|
|
|
PKCS7_RECIP_INFO *si;
|
|
|
|
int num, i;
|
|
|
|
VALUE ary;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2005-09-07 03:40:55 -04:00
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
if (PKCS7_type_is_enveloped(pkcs7))
|
|
|
|
sk = pkcs7->d.enveloped->recipientinfo;
|
|
|
|
else if (PKCS7_type_is_signedAndEnveloped(pkcs7))
|
|
|
|
sk = pkcs7->d.signed_and_enveloped->recipientinfo;
|
|
|
|
else sk = NULL;
|
|
|
|
if (!sk) return rb_ary_new();
|
|
|
|
if ((num = sk_PKCS7_RECIP_INFO_num(sk)) < 0) {
|
|
|
|
ossl_raise(ePKCS7Error, "Negative number of recipient!");
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(num);
|
|
|
|
for (i=0; i<num; i++) {
|
|
|
|
si = sk_PKCS7_RECIP_INFO_value(sk, i);
|
|
|
|
rb_ary_push(ary, ossl_pkcs7ri_new(si));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_add_certificate(VALUE self, VALUE cert)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
X509 *x509;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
|
|
|
if (!PKCS7_add_certificate(pkcs7, x509)){
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-02-27 21:56:26 -05:00
|
|
|
static STACK_OF(X509) *
|
|
|
|
pkcs7_get_certs(VALUE self)
|
2003-11-11 16:20:20 -05:00
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
STACK_OF(X509) *certs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
i = OBJ_obj2nid(pkcs7->type);
|
|
|
|
switch(i){
|
|
|
|
case NID_pkcs7_signed:
|
|
|
|
certs = pkcs7->d.sign->cert;
|
|
|
|
break;
|
|
|
|
case NID_pkcs7_signedAndEnveloped:
|
|
|
|
certs = pkcs7->d.signed_and_enveloped->cert;
|
2010-02-27 21:56:26 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
certs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return certs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static STACK_OF(X509_CRL) *
|
|
|
|
pkcs7_get_crls(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
STACK_OF(X509_CRL) *crls;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
i = OBJ_obj2nid(pkcs7->type);
|
|
|
|
switch(i){
|
|
|
|
case NID_pkcs7_signed:
|
|
|
|
crls = pkcs7->d.sign->crl;
|
|
|
|
break;
|
|
|
|
case NID_pkcs7_signedAndEnveloped:
|
2003-11-11 16:20:20 -05:00
|
|
|
crls = pkcs7->d.signed_and_enveloped->crl;
|
|
|
|
break;
|
|
|
|
default:
|
2010-02-27 21:56:26 -05:00
|
|
|
crls = NULL;
|
2003-11-11 16:20:20 -05:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:56:26 -05:00
|
|
|
return crls;
|
2003-11-11 16:20:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-11-29 02:59:14 -05:00
|
|
|
ossl_pkcs7_set_certs_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
|
2003-11-11 16:20:20 -05:00
|
|
|
{
|
|
|
|
return ossl_pkcs7_add_certificate(arg, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
STACK_OF(X509) *certs;
|
|
|
|
X509 *cert;
|
|
|
|
|
2010-02-27 21:56:26 -05:00
|
|
|
certs = pkcs7_get_certs(self);
|
2003-11-11 16:20:20 -05:00
|
|
|
while((cert = sk_X509_pop(certs))) X509_free(cert);
|
2006-02-03 04:15:42 -05:00
|
|
|
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
|
2003-11-11 16:20:20 -05:00
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_certificates(VALUE self)
|
|
|
|
{
|
2010-02-27 21:56:26 -05:00
|
|
|
return ossl_x509_sk2ary(pkcs7_get_certs(self));
|
2003-11-11 16:20:20 -05:00
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_add_crl(VALUE self, VALUE crl)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
X509_CRL *x509crl;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7); /* NO DUP needed! */
|
|
|
|
x509crl = GetX509CRLPtr(crl);
|
|
|
|
if (!PKCS7_add_crl(pkcs7, x509crl)) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-11-11 16:20:20 -05:00
|
|
|
static VALUE
|
2013-11-29 02:59:14 -05:00
|
|
|
ossl_pkcs7_set_crls_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
|
2003-11-11 16:20:20 -05:00
|
|
|
{
|
|
|
|
return ossl_pkcs7_add_crl(arg, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_set_crls(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
STACK_OF(X509_CRL) *crls;
|
|
|
|
X509_CRL *crl;
|
|
|
|
|
2010-02-27 21:56:26 -05:00
|
|
|
crls = pkcs7_get_crls(self);
|
2003-11-11 16:20:20 -05:00
|
|
|
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
|
2006-02-03 04:15:42 -05:00
|
|
|
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
|
2003-11-11 16:20:20 -05:00
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_get_crls(VALUE self)
|
|
|
|
{
|
2010-02-27 21:56:26 -05:00
|
|
|
return ossl_x509crl_sk2ary(pkcs7_get_crls(self));
|
2003-11-11 16:20:20 -05:00
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE certs, store, indata, flags;
|
|
|
|
STACK_OF(X509) *x509s;
|
|
|
|
X509_STORE *x509st;
|
|
|
|
int flg, ok, status = 0;
|
|
|
|
BIO *in, *out;
|
|
|
|
PKCS7 *p7;
|
|
|
|
VALUE data;
|
|
|
|
const char *msg;
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
GetPKCS7(self, p7);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_scan_args(argc, argv, "22", &certs, &store, &indata, &flags);
|
2016-08-29 01:47:09 -04:00
|
|
|
x509st = GetX509StorePtr(store);
|
2003-07-23 12:12:24 -04:00
|
|
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
|
|
|
if(NIL_P(indata)) indata = ossl_pkcs7_get_data(self);
|
2017-08-10 05:23:45 -04:00
|
|
|
in = NIL_P(indata) ? NULL : ossl_obj2bio(&indata);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(NIL_P(certs)) x509s = NULL;
|
|
|
|
else{
|
|
|
|
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
|
|
|
if(status){
|
|
|
|
BIO_free(in);
|
|
|
|
rb_jump_tag(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!(out = BIO_new(BIO_s_mem()))){
|
|
|
|
BIO_free(in);
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
ok = PKCS7_verify(p7, x509s, x509st, in, out, flg);
|
2003-09-17 05:05:02 -04:00
|
|
|
BIO_free(in);
|
2016-08-29 01:47:09 -04:00
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
if (ok < 0) ossl_raise(ePKCS7Error, "PKCS7_verify");
|
2016-11-30 09:41:46 -05:00
|
|
|
msg = ERR_reason_error_string(ERR_peek_error());
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_pkcs7_set_err_string(self, msg ? rb_str_new2(msg) : Qnil);
|
2016-05-18 00:07:45 -04:00
|
|
|
ossl_clear_error();
|
2003-09-17 05:05:02 -04:00
|
|
|
data = ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_pkcs7_set_data(self, data);
|
|
|
|
|
|
|
|
return (ok == 1) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE pkey, cert, flags;
|
|
|
|
EVP_PKEY *key;
|
|
|
|
X509 *x509;
|
|
|
|
int flg;
|
|
|
|
PKCS7 *p7;
|
|
|
|
BIO *out;
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "21", &pkey, &cert, &flags);
|
|
|
|
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
|
|
|
|
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
|
|
|
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetPKCS7(self, p7);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!(out = BIO_new(BIO_s_mem())))
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
if(!PKCS7_decrypt(p7, key, x509, out, flg)){
|
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
str = ossl_membio2str(out); /* out will be free */
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_add_data(VALUE self, VALUE data)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
BIO *out, *in;
|
|
|
|
char buf[4096];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
if(PKCS7_type_is_signed(pkcs7)){
|
|
|
|
if(!PKCS7_content_new(pkcs7, NID_pkcs7_data))
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2017-08-10 05:23:45 -04:00
|
|
|
in = ossl_obj2bio(&data);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!(out = PKCS7_dataInit(pkcs7, NULL))) goto err;
|
|
|
|
for(;;){
|
|
|
|
if((len = BIO_read(in, buf, sizeof(buf))) <= 0)
|
|
|
|
break;
|
|
|
|
if(BIO_write(out, buf, len) != len)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if(!PKCS7_dataFinal(pkcs7, out)) goto err;
|
|
|
|
ossl_pkcs7_set_data(self, Qnil);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
err:
|
2016-08-29 01:47:09 -04:00
|
|
|
BIO_free_all(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(in);
|
|
|
|
if(ERR_peek_error()){
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2003-09-17 05:05:02 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_to_der(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
VALUE str;
|
|
|
|
long len;
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
if((len = i2d_PKCS7(pkcs7, NULL)) <= 0)
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
str = rb_str_new(0, len);
|
2008-07-22 11:34:23 -04:00
|
|
|
p = (unsigned char *)RSTRING_PTR(str);
|
2003-09-17 05:05:02 -04:00
|
|
|
if(i2d_PKCS7(pkcs7, &p) <= 0)
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
ossl_str_adjust(str, p);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7_to_pem(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7 *pkcs7;
|
|
|
|
BIO *out;
|
|
|
|
VALUE str;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetPKCS7(self, pkcs7);
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
if (!PEM_write_bio_PKCS7(out, pkcs7)) {
|
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
str = ossl_membio2str(out);
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SIGNER INFO
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7si_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKCS7si(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(p7si = PKCS7_SIGNER_INFO_new())) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7si(obj, p7si);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7si_initialize(VALUE self, VALUE cert, VALUE key, VALUE digest)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
X509 *x509;
|
|
|
|
const EVP_MD *md;
|
|
|
|
|
|
|
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
|
|
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
2017-09-03 08:35:27 -04:00
|
|
|
md = ossl_evp_get_digestbyname(digest);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetPKCS7si(self, p7si);
|
2003-07-25 02:50:55 -04:00
|
|
|
if (!(PKCS7_SIGNER_INFO_set(p7si, x509, pkey, (EVP_MD*)md))) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2005-09-07 03:40:55 -04:00
|
|
|
ossl_pkcs7si_get_issuer(VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
|
|
|
|
GetPKCS7si(self, p7si);
|
|
|
|
|
|
|
|
return ossl_x509name_new(p7si->issuer_and_serial->issuer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7si_get_serial(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
|
|
|
|
GetPKCS7si(self, p7si);
|
|
|
|
|
|
|
|
return asn1integer_to_num(p7si->issuer_and_serial->serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7si_get_signed_time(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7_SIGNER_INFO *p7si;
|
|
|
|
ASN1_TYPE *asn1obj;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetPKCS7si(self, p7si);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(asn1obj = PKCS7_get_signed_attribute(p7si, NID_pkcs9_signingTime))) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
if (asn1obj->type == V_ASN1_UTCTIME) {
|
|
|
|
return asn1time_to_time(asn1obj->value.utctime);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* OR
|
|
|
|
* ossl_raise(ePKCS7Error, "...");
|
|
|
|
* ?
|
|
|
|
*/
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2005-09-07 03:40:55 -04:00
|
|
|
/*
|
|
|
|
* RECIPIENT INFO
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKCS7ri(klass);
|
2005-09-07 03:40:55 -04:00
|
|
|
if (!(p7ri = PKCS7_RECIP_INFO_new())) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKCS7ri(obj, p7ri);
|
2005-09-07 03:40:55 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_initialize(VALUE self, VALUE cert)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri;
|
|
|
|
X509 *x509;
|
|
|
|
|
|
|
|
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
|
|
|
GetPKCS7ri(self, p7ri);
|
|
|
|
if (!PKCS7_RECIP_INFO_set(p7ri, x509)) {
|
|
|
|
ossl_raise(ePKCS7Error, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_get_issuer(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri;
|
|
|
|
|
|
|
|
GetPKCS7ri(self, p7ri);
|
|
|
|
|
|
|
|
return ossl_x509name_new(p7ri->issuer_and_serial->issuer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_get_serial(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri;
|
|
|
|
|
|
|
|
GetPKCS7ri(self, p7ri);
|
|
|
|
|
|
|
|
return asn1integer_to_num(p7ri->issuer_and_serial->serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_pkcs7ri_get_enc_key(VALUE self)
|
|
|
|
{
|
|
|
|
PKCS7_RECIP_INFO *p7ri;
|
|
|
|
|
|
|
|
GetPKCS7ri(self, p7ri);
|
|
|
|
|
|
|
|
return asn1str_to_str(p7ri->enc_key);
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
|
|
|
void
|
2014-09-30 01:25:32 -04:00
|
|
|
Init_ossl_pkcs7(void)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2018-02-16 03:39:48 -05:00
|
|
|
#undef rb_intern
|
2016-08-29 01:47:09 -04:00
|
|
|
#if 0
|
|
|
|
mOSSL = rb_define_module("OpenSSL");
|
|
|
|
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
|
|
#endif
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
cPKCS7 = rb_define_class_under(mOSSL, "PKCS7", rb_cObject);
|
|
|
|
ePKCS7Error = rb_define_class_under(cPKCS7, "PKCS7Error", eOSSLError);
|
|
|
|
rb_define_singleton_method(cPKCS7, "read_smime", ossl_pkcs7_s_read_smime, 1);
|
|
|
|
rb_define_singleton_method(cPKCS7, "write_smime", ossl_pkcs7_s_write_smime, -1);
|
|
|
|
rb_define_singleton_method(cPKCS7, "sign", ossl_pkcs7_s_sign, -1);
|
|
|
|
rb_define_singleton_method(cPKCS7, "encrypt", ossl_pkcs7_s_encrypt, -1);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_attr(cPKCS7, rb_intern("data"), 1, 0, Qfalse);
|
|
|
|
rb_attr(cPKCS7, rb_intern("error_string"), 1, 1, Qfalse);
|
|
|
|
rb_define_alloc_func(cPKCS7, ossl_pkcs7_alloc);
|
2017-09-03 08:35:27 -04:00
|
|
|
rb_define_method(cPKCS7, "initialize_copy", ossl_pkcs7_copy, 1);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cPKCS7, "initialize", ossl_pkcs7_initialize, -1);
|
|
|
|
rb_define_method(cPKCS7, "type=", ossl_pkcs7_set_type, 1);
|
|
|
|
rb_define_method(cPKCS7, "type", ossl_pkcs7_get_type, 0);
|
|
|
|
rb_define_method(cPKCS7, "detached=", ossl_pkcs7_set_detached, 1);
|
|
|
|
rb_define_method(cPKCS7, "detached", ossl_pkcs7_get_detached, 0);
|
|
|
|
rb_define_method(cPKCS7, "detached?", ossl_pkcs7_detached_p, 0);
|
|
|
|
rb_define_method(cPKCS7, "cipher=", ossl_pkcs7_set_cipher, 1);
|
|
|
|
rb_define_method(cPKCS7, "add_signer", ossl_pkcs7_add_signer, 1);
|
|
|
|
rb_define_method(cPKCS7, "signers", ossl_pkcs7_get_signer, 0);
|
|
|
|
rb_define_method(cPKCS7, "add_recipient", ossl_pkcs7_add_recipient, 1);
|
2005-09-07 03:40:55 -04:00
|
|
|
rb_define_method(cPKCS7, "recipients", ossl_pkcs7_get_recipient, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cPKCS7, "add_certificate", ossl_pkcs7_add_certificate, 1);
|
2003-11-11 16:20:20 -05:00
|
|
|
rb_define_method(cPKCS7, "certificates=", ossl_pkcs7_set_certificates, 1);
|
|
|
|
rb_define_method(cPKCS7, "certificates", ossl_pkcs7_get_certificates, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cPKCS7, "add_crl", ossl_pkcs7_add_crl, 1);
|
2003-11-11 16:20:20 -05:00
|
|
|
rb_define_method(cPKCS7, "crls=", ossl_pkcs7_set_crls, 1);
|
|
|
|
rb_define_method(cPKCS7, "crls", ossl_pkcs7_get_crls, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cPKCS7, "add_data", ossl_pkcs7_add_data, 1);
|
|
|
|
rb_define_alias(cPKCS7, "data=", "add_data");
|
|
|
|
rb_define_method(cPKCS7, "verify", ossl_pkcs7_verify, -1);
|
|
|
|
rb_define_method(cPKCS7, "decrypt", ossl_pkcs7_decrypt, -1);
|
|
|
|
rb_define_method(cPKCS7, "to_pem", ossl_pkcs7_to_pem, 0);
|
|
|
|
rb_define_alias(cPKCS7, "to_s", "to_pem");
|
2003-09-17 05:05:02 -04:00
|
|
|
rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject);
|
|
|
|
rb_define_const(cPKCS7, "Signer", cPKCS7Signer);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
|
|
|
|
rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
|
2005-09-07 03:40:55 -04:00
|
|
|
rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
|
|
|
|
rb_define_alias(cPKCS7Signer, "name", "issuer");
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
|
2005-09-07 03:40:55 -04:00
|
|
|
rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);
|
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
cPKCS7Recipient = rb_define_class_under(cPKCS7,"RecipientInfo",rb_cObject);
|
2005-09-07 03:40:55 -04:00
|
|
|
rb_define_alloc_func(cPKCS7Recipient, ossl_pkcs7ri_alloc);
|
2010-04-22 04:04:13 -04:00
|
|
|
rb_define_method(cPKCS7Recipient, "initialize", ossl_pkcs7ri_initialize,1);
|
2005-09-07 03:40:55 -04:00
|
|
|
rb_define_method(cPKCS7Recipient, "issuer", ossl_pkcs7ri_get_issuer,0);
|
|
|
|
rb_define_method(cPKCS7Recipient, "serial", ossl_pkcs7ri_get_serial,0);
|
2010-04-22 04:04:13 -04:00
|
|
|
rb_define_method(cPKCS7Recipient, "enc_key", ossl_pkcs7ri_get_enc_key,0);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2007-04-05 01:59:22 -04:00
|
|
|
#define DefPKCS7Const(x) rb_define_const(cPKCS7, #x, INT2NUM(PKCS7_##x))
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
DefPKCS7Const(TEXT);
|
|
|
|
DefPKCS7Const(NOCERTS);
|
|
|
|
DefPKCS7Const(NOSIGS);
|
|
|
|
DefPKCS7Const(NOCHAIN);
|
|
|
|
DefPKCS7Const(NOINTERN);
|
|
|
|
DefPKCS7Const(NOVERIFY);
|
|
|
|
DefPKCS7Const(DETACHED);
|
|
|
|
DefPKCS7Const(BINARY);
|
|
|
|
DefPKCS7Const(NOATTR);
|
|
|
|
DefPKCS7Const(NOSMIMECAP);
|
|
|
|
}
|