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)); \ 117 const char *hex =
"0123456789abcdef";
121 for (i = 0; i < inlen; i++) {
122 unsigned char p = in[i];
124 out[i * 2 + 0] = hex[p >> 4];
125 out[i * 2 + 1] = hex[p & 0x0f];
171 if (len <= max_len) {
176 OSSL_Debug(
"passed data is not valid String???");
181 return PEM_def_callback(buf, max_len, flag,
NULL);
201 rb_warning(
"password must not be longer than %d bytes", max_len);
254 e = ERR_peek_last_error();
260 msg = ERR_error_string(e,
NULL);
262 msg = ERR_reason_error_string(e);
293 const char *file, *data, *errstr;
296 while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
297 errstr = ERR_error_string(e,
NULL);
301 if (flags & ERR_TXT_STRING) {
304 rb_warn(
"error on stack: %s (%s)", errstr, data);
307 rb_warn(
"error on stack: %s", errstr);
331 while ((e = ERR_get_error()) != 0){
343 #if !defined(HAVE_VA_ARGS_MACRO) 349 if (dOSSL ==
Qtrue) {
350 fprintf(stderr,
"OSSL_DEBUG: ");
352 vfprintf(stderr, fmt, args);
354 fprintf(stderr,
" [CONTEXT N/A]\n");
401 if (
RTEST(enabled)) {
402 int mode = FIPS_mode();
403 if(!mode && !FIPS_mode_set(1))
404 ossl_raise(eOSSLError,
"Turning on FIPS mode failed");
406 if(!FIPS_mode_set(0))
407 ossl_raise(eOSSLError,
"Turning off FIPS mode failed");
412 ossl_raise(eOSSLError,
"This version of OpenSSL does not support FIPS mode");
417 #if !defined(HAVE_OPENSSL_110_THREADING_API) 426 if (mode & CRYPTO_LOCK) {
464 #ifdef HAVE_CRYPTO_THREADID_PTR 465 static void ossl_threadid_func(CRYPTO_THREADID *
id)
481 int num_locks = CRYPTO_num_locks();
483 if ((
unsigned)num_locks >= INT_MAX / (
int)
sizeof(
VALUE)) {
486 ossl_locks = (rb_nativethread_lock_t *) OPENSSL_malloc(num_locks * (
int)
sizeof(rb_nativethread_lock_t));
490 for (i = 0; i < num_locks; i++) {
494 #ifdef HAVE_CRYPTO_THREADID_PTR 495 CRYPTO_THREADID_set_callback(ossl_threadid_func);
1013 OpenSSL_add_ssl_algorithms();
1014 OpenSSL_add_all_algorithms();
1015 ERR_load_crypto_strings();
1016 SSL_load_error_strings();
1023 CONF_modules_unload(1);
1024 destroy_ui_method();
1027 CRYPTO_cleanup_all_ex_data();
1028 ERR_remove_state(0);
1094 #if !defined(HAVE_OPENSSL_110_THREADING_API) 1119 #if defined(OSSL_DEBUG)
RUBY_SYMBOL_EXPORT_BEGIN rb_nativethread_id_t rb_nativethread_self()
static VALUE ossl_str_new(int size)
static void ossl_lock_callback(int mode, int type, const char *file, int line)
static void ossl_lock_unlock(int mode, rb_nativethread_lock_t *lock)
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_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static void Init_ossl_locks(void)
static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args)
void Init_ossl_asn1(void)
void Init_ossl_rand(void)
static rb_nativethread_lock_t * ossl_locks
Stores locks needed for OpenSSL thread safety.
void Init_ossl_ocsp(void)
void ossl_debug(const char *fmt,...)
void rb_global_variable(VALUE *var)
void rb_exc_raise(VALUE mesg)
static VALUE ossl_pem_passwd_cb0(VALUE flag)
#define RB_TYPE_P(obj, type)
static VALUE ossl_fips_mode_set(VALUE self, VALUE enabled)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_clear_error(void)
int rb_block_given_p(void)
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock)
static void ossl_dyn_destroy_callback(struct CRYPTO_dynlock_value *l, const char *file, int line)
VALUE rb_str_cat2(VALUE, const char *)
void rb_define_const(VALUE, const char *, VALUE)
void Init_ossl_hmac(void)
static struct CRYPTO_dynlock_value * ossl_dyn_create_callback(const char *file, int line)
void Init_ossl_digest(void)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
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.
void Init_ossl_pkcs12(void)
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
static void ossl_dyn_lock_callback(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)
unsigned char buf[MIME_BUF_SIZE]
#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup)
VALUE ossl_pem_passwd_value(VALUE pass)
VALUE rb_str_new_cstr(const char *)
void rb_jump_tag(int tag)
static VALUE ossl_debug_set(VALUE self, VALUE val)
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)
VALUE ossl_get_errors(void)
void Init_ossl_x509(void)
static unsigned long ossl_thread_id(void)
void rb_set_errinfo(VALUE err)
void Init_ossl_pkcs5(void)
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)
void rb_warning(const char *fmt,...)
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)
void rb_warn(const char *fmt,...)
VALUE ossl_to_der(VALUE obj)
VALUE rb_str_new(const char *, long)