17 #define OSSL_IMPL_ARY2SK(name, type, expected_class, dup) \ 19 ossl_##name##_ary2sk0(VALUE ary) \ 26 Check_Type(ary, T_ARRAY); \ 27 sk = sk_##type##_new_null(); \ 28 if (!sk) ossl_raise(eOSSLError, NULL); \ 30 for (i = 0; i < RARRAY_LEN(ary); i++) { \ 31 val = rb_ary_entry(ary, i); \ 32 if (!rb_obj_is_kind_of(val, expected_class)) { \ 33 sk_##type##_pop_free(sk, type##_free); \ 34 ossl_raise(eOSSLError, "object in array not" \ 35 " of class ##type##"); \ 38 sk_##type##_push(sk, x); \ 44 ossl_protect_##name##_ary2sk(VALUE ary, int *status) \ 46 return (STACK_OF(type)*)rb_protect( \ 47 (VALUE (*)(VALUE))ossl_##name##_ary2sk0, \ 53 ossl_##name##_ary2sk(VALUE ary) \ 58 sk = ossl_protect_##name##_ary2sk(ary, &status); \ 59 if (status) rb_jump_tag(status); \ 65 #define OSSL_IMPL_SK2ARY(name, type) \ 67 ossl_##name##_sk2ary(const STACK_OF(type) *sk) \ 74 OSSL_Debug("empty sk!"); \ 77 num = sk_##type##_num(sk); \ 79 OSSL_Debug("items in sk < -1???"); \ 80 return rb_ary_new(); \ 82 ary = rb_ary_new2(num); \ 84 for (i=0; i<num; i++) { \ 85 t = sk_##type##_value(sk, i); \ 86 rb_ary_push(ary, ossl_##name##_new(t)); \ 106 str =
rb_protect(ossl_str_new_i, len, &state);
135 const char *hex =
"0123456789abcdef";
139 for (i = 0; i < inlen; i++) {
140 unsigned char p = in[i];
142 out[i * 2 + 0] = hex[p >> 4];
143 out[i * 2 + 1] = hex[p & 0x0f];
167 ossl_pem_passwd_cb0(
VALUE flag)
189 if (len <= max_len) {
194 OSSL_Debug(
"passed data is not valid String???");
199 return PEM_def_callback(buf, max_len, flag,
NULL);
209 pass =
rb_protect(ossl_pem_passwd_cb0, rflag, &status);
219 rb_warning(
"password must not be longer than %d bytes", max_len);
241 static ID ossl_s_to_der;
266 ossl_make_error(
VALUE exc,
const char *fmt, va_list args)
274 e = ERR_peek_last_error();
276 const char *msg = ERR_reason_error_string(e);
298 err = ossl_make_error(exc, fmt, args);
308 const char *file, *data, *errstr;
311 while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
312 errstr = ERR_error_string(e,
NULL);
316 if (flags & ERR_TXT_STRING) {
319 rb_warn(
"error on stack: %s (%s)", errstr, data);
322 rb_warn(
"error on stack: %s", errstr);
347 while ((e = ERR_get_error()) != 0){
359 #if !defined(HAVE_VA_ARGS_MACRO) 365 if (dOSSL ==
Qtrue) {
366 fprintf(stderr,
"OSSL_DEBUG: ");
368 vfprintf(stderr, fmt, args);
370 fprintf(stderr,
" [CONTEXT N/A]\n");
380 ossl_debug_get(
VALUE self)
405 ossl_fips_mode_get(
VALUE self)
434 if (
RTEST(enabled)) {
435 int mode = FIPS_mode();
436 if(!mode && !FIPS_mode_set(1))
437 ossl_raise(eOSSLError,
"Turning on FIPS mode failed");
439 if(!FIPS_mode_set(0))
440 ossl_raise(eOSSLError,
"Turning off FIPS mode failed");
445 ossl_raise(eOSSLError,
"This version of OpenSSL does not support FIPS mode");
450 #if defined(OSSL_DEBUG) 451 #if !defined(LIBRESSL_VERSION_NUMBER) && \ 452 (OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \ 453 defined(CRYPTO_malloc_debug_init)) 465 mem_check_start(
VALUE self)
467 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
494 print_mem_leaks(
VALUE self)
496 #if OPENSSL_VERSION_NUMBER >= 0x10100000 503 #if OPENSSL_VERSION_NUMBER >= 0x10100000 504 ret = CRYPTO_mem_leaks_fp(stderr);
506 ossl_raise(eOSSLError,
"CRYPTO_mem_leaks_fp");
509 CRYPTO_mem_leaks_fp(stderr);
516 #if !defined(HAVE_OPENSSL_110_THREADING_API) 536 if (mode & CRYPTO_LOCK) {
553 ossl_dyn_create_callback(
const char *file,
int line)
559 ossl_lock_init(dynlock);
566 ossl_lock_unlock(mode, l);
576 static void ossl_threadid_func(CRYPTO_THREADID *
id)
585 ossl_lock_callback(
int mode,
int type,
const char *file,
int line)
587 ossl_lock_unlock(mode, &ossl_locks[type]);
590 static void Init_ossl_locks(
void)
593 int num_locks = CRYPTO_num_locks();
596 for (i = 0; i < num_locks; i++)
597 ossl_lock_init(&ossl_locks[i]);
599 CRYPTO_THREADID_set_callback(ossl_threadid_func);
600 CRYPTO_set_locking_callback(ossl_lock_callback);
601 CRYPTO_set_dynlock_create_callback(ossl_dyn_create_callback);
602 CRYPTO_set_dynlock_lock_callback(ossl_dyn_lock_callback);
603 CRYPTO_set_dynlock_destroy_callback(ossl_dyn_destroy_callback);
1114 OpenSSL_add_ssl_algorithms();
1115 OpenSSL_add_all_algorithms();
1116 ERR_load_crypto_strings();
1117 SSL_load_error_strings();
1124 CONF_modules_unload(1);
1125 destroy_ui_method();
1128 CRYPTO_cleanup_all_ex_data();
1129 ERR_remove_state(0);
1196 #if !defined(HAVE_OPENSSL_110_THREADING_API) 1220 #if defined(OSSL_DEBUG) 1224 #if !defined(LIBRESSL_VERSION_NUMBER) && \ 1225 (OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \ 1226 defined(CRYPTO_malloc_debug_init)) 1230 #if defined(CRYPTO_malloc_debug_init) 1231 CRYPTO_malloc_debug_init();
1234 #if defined(V_CRYPTO_MDEBUG_ALL) 1235 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
1238 #if OPENSSL_VERSION_NUMBER < 0x10100000 1246 for (i = 0; i <= 15; i++) {
1247 if (CRYPTO_get_ex_new_index(i, 0, (
void *)
"ossl-mdebug-dummy", 0, 0, 0) < 0)
1249 "class index %d failed", i);
RUBY_SYMBOL_EXPORT_BEGIN rb_nativethread_id_t rb_nativethread_self()
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
void rb_warn(const char *fmt,...)
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_raise(VALUE exc, const char *fmt,...)
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
void Init_ossl_engine(void)
rb_nativethread_lock_t lock
void Init_ossl_config(void)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define OSSL_IMPL_SK2ARY(name, type)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void Init_ossl_asn1(void)
void Init_ossl_rand(void)
void Init_ossl_ocsp(void)
void ossl_debug(const char *fmt,...)
void rb_global_variable(VALUE *var)
#define RB_TYPE_P(obj, type)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_clear_error(void)
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock)
VALUE rb_str_cat2(VALUE, const char *)
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
void rb_define_const(VALUE, const char *, VALUE)
void Init_ossl_hmac(void)
void Init_ossl_digest(void)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
void Init_ossl_pkcs12(void)
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
unsigned char buf[MIME_BUF_SIZE]
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup)
VALUE ossl_pem_passwd_value(VALUE pass)
VALUE rb_str_new_cstr(const char *)
void ossl_bin2hex(unsigned char *in, char *out, size_t inlen)
int rb_respond_to(VALUE, ID)
register unsigned int len
void Init_ossl_ns_spki(void)
Stores locks needed for OpenSSL thread safety.
VALUE ossl_get_errors(void)
rb_nativethread_id_t owner
void Init_ossl_x509(void)
void rb_warning(const char *fmt,...)
VALUE ossl_buf2str(char *buf, int len)
void ossl_raise(VALUE exc, const char *fmt,...)
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
X509 * DupX509CertPtr(VALUE)
void Init_ossl_cipher(void)
void Init_ossl_pkcs7(void)
VALUE ossl_str_new(const char *ptr, long len, int *pstate)
void Init_ossl_pkey(void)
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
VALUE rb_define_module(const char *name)
VALUE rb_vsprintf(const char *, va_list)
VALUE ossl_to_der(VALUE obj)
VALUE rb_str_new(const char *, long)