18 string2hex(
const unsigned char *
buf,
int buf_len,
char **hexbuf,
int *hexbuf_len)
20 static const char hex[]=
"0123456789abcdef";
21 int i,
len = 2 * buf_len;
23 if (buf_len < 0 || len < buf_len) {
32 if (!(*hexbuf = OPENSSL_malloc(len + 1))) {
35 for (i = 0; i < buf_len; i++) {
36 (*hexbuf)[2 *
i] = hex[((
unsigned char)buf[i]) >> 4];
37 (*hexbuf)[2 * i + 1] = hex[buf[
i] & 0x0f];
39 (*hexbuf)[2 *
i] =
'\0';
50 #define OSSL_IMPL_ARY2SK(name, type, expected_class, dup) \
52 ossl_##name##_ary2sk0(VALUE ary) \
59 Check_Type(ary, T_ARRAY); \
60 sk = sk_##type##_new_null(); \
61 if (!sk) ossl_raise(eOSSLError, NULL); \
63 for (i = 0; i < RARRAY_LEN(ary); i++) { \
64 val = rb_ary_entry(ary, i); \
65 if (!rb_obj_is_kind_of(val, expected_class)) { \
66 sk_##type##_pop_free(sk, type##_free); \
67 ossl_raise(eOSSLError, "object in array not" \
68 " of class ##type##"); \
71 sk_##type##_push(sk, x); \
77 ossl_protect_##name##_ary2sk(VALUE ary, int *status) \
79 return (STACK_OF(type)*)rb_protect( \
80 (VALUE(*)_((VALUE)))ossl_##name##_ary2sk0, \
86 ossl_##name##_ary2sk(VALUE ary) \
91 sk = ossl_protect_##name##_ary2sk(ary, &status); \
92 if (status) rb_jump_tag(status); \
98 #define OSSL_IMPL_SK2ARY(name, type) \
100 ossl_##name##_sk2ary(STACK_OF(type) *sk) \
107 OSSL_Debug("empty sk!"); \
110 num = sk_##type##_num(sk); \
112 OSSL_Debug("items in sk < -1???"); \
113 return rb_ary_new(); \
115 ary = rb_ary_new2(num); \
117 for (i=0; i<num; i++) { \
118 t = sk_##type##_value(sk, i); \
119 rb_ary_push(ary, ossl_##name##_new(t)); \
178 if (status)
return -1;
181 rb_warning(
"password must be longer than 4 bytes");
185 rb_warning(
"password must be shorter then %d bytes", max_len-1);
209 VALUE proc, rctx, ret;
213 proc = (
VALUE)X509_STORE_CTX_get_ex_data(ctx, ossl_verify_cb_idx);
214 if ((
void*)proc == 0)
216 if ((
void*)proc == 0)
229 rb_warn(
"exception in verify_callback is ignored");
233 X509_STORE_CTX_set_error(ctx, X509_V_OK);
237 if (X509_STORE_CTX_get_error(ctx) == X509_V_OK) {
238 X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
292 #ifdef HAVE_ERR_PEEK_LAST_ERROR
293 e = ERR_peek_last_error();
295 e = ERR_peek_error();
300 if (len < BUFSIZ && e) {
302 msg = ERR_error_string(e,
NULL);
304 msg = ERR_reason_error_string(e);
305 len +=
snprintf(buf+len, BUFSIZ-len,
"%s%s", (len ?
": " :
""), msg);
308 while ((e = ERR_get_error()) != 0){
309 rb_warn(
"error on stack: %s", ERR_error_string(e,
NULL));
355 while ((e = ERR_get_error()) != 0){
367 #if !defined(HAVE_VA_ARGS_MACRO)
373 if (dOSSL ==
Qtrue) {
374 fprintf(stderr,
"OSSL_DEBUG: ");
376 vfprintf(stderr, fmt, args);
378 fprintf(stderr,
" [CONTEXT N/A]\n");
407 if (dOSSL ==
Qtrue) {
408 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
409 fprintf(stderr,
"OSSL_DEBUG: IS NOW ON!\n");
410 }
else if (old ==
Qtrue) {
411 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);
412 fprintf(stderr,
"OSSL_DEBUG: IS NOW OFF!\n");
806 OpenSSL_add_ssl_algorithms();
807 OpenSSL_add_all_algorithms();
808 ERR_load_crypto_strings();
809 SSL_load_error_strings();
816 CONF_modules_unload(1);
820 CRYPTO_cleanup_all_ex_data();
854 if ((ossl_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (
void *)
"ossl_verify_cb_idx", 0, 0, 0)) < 0)
855 ossl_raise(eOSSLError,
"X509_STORE_CTX_get_ex_new_index");
891 #if defined(OSSL_DEBUG)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
static VALUE ossl_str_new(int size)
size_t strlen(const char *)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE INT2NUM(int v)
#define OSSL_IMPL_SK2ARY(name, type)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RSTRING_PTR(string)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void * X509_STORE_get_ex_data(X509_STORE *str, int idx)
static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args)
void ossl_debug(const char *fmt,...)
VALUE ossl_exc_new(VALUE exc, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
static VALUE ossl_pem_passwd_cb0(VALUE flag)
VALUE ossl_x509stctx_clear_ptr(VALUE)
VALUE ossl_to_der_if_possible(VALUE obj)
int rb_block_given_p(void)
VALUE ossl_x509stctx_new(X509_STORE_CTX *)
void rb_define_const(VALUE, const char *, VALUE)
int PEM_def_callback(char *buf, int num, int w, void *key)
static VALUE ossl_debug_get(VALUE self)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
unsigned char buf[MIME_BUF_SIZE]
#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup)
register unsigned int len
void rb_jump_tag(int tag)
static VALUE ossl_debug_set(VALUE self, VALUE val)
int rb_respond_to(VALUE, ID)
VALUE ossl_buf2str(char *buf, int len)
void ossl_raise(VALUE exc, const char *fmt,...)
#define SafeStringValue(v)
X509 * DupX509CertPtr(VALUE)
int main(int argc, char **argv)
void Init_ossl_cipher(void)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
void rb_warning(const char *fmt,...)
#define RSTRING_LENINT(str)
VALUE ossl_call_verify_cb_proc(struct ossl_verify_cb_args *args)
VALUE rb_define_module(const char *name)
VALUE rb_str_new2(const char *)
void rb_warn(const char *fmt,...)
int string2hex(const unsigned char *buf, int buf_len, char **hexbuf, int *hexbuf_len)
int ossl_verify_cb(int ok, X509_STORE_CTX *ctx)
VALUE ossl_to_der(VALUE obj)
VALUE rb_str_new(const char *, long)