17#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup) \
19ossl_##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); \
44ossl_protect_##name##_ary2sk(VALUE ary, int *status) \
46 return (STACK_OF(type)*)rb_protect( \
47 (VALUE (*)(VALUE))ossl_##name##_ary2sk0, \
53ossl_##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) \
67ossl_##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)); \
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];
167ossl_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);
241static ID ossl_s_to_der;
274 e = ERR_peek_last_error();
276 const char *msg = ERR_reason_error_string(e);
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)
380ossl_debug_get(
VALUE self)
405ossl_fips_mode_get(
VALUE self)
434 if (
RTEST(enabled)) {
435 int mode = FIPS_mode();
436 if(!mode && !FIPS_mode_set(1))
439 if(!FIPS_mode_set(0))
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))
465mem_check_start(
VALUE self)
467 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
494print_mem_leaks(
VALUE self)
496#if OPENSSL_VERSION_NUMBER >= 0x10100000
503#if OPENSSL_VERSION_NUMBER >= 0x10100000
504 ret = CRYPTO_mem_leaks_fp(
stderr);
509 CRYPTO_mem_leaks_fp(
stderr);
516#if !defined(HAVE_OPENSSL_110_THREADING_API)
536 if (mode & CRYPTO_LOCK) {
553ossl_dyn_create_callback(
const char *file,
int line)
559 ossl_lock_init(dynlock);
566 ossl_lock_unlock(mode, l);
576static void ossl_threadid_func(CRYPTO_THREADID *
id)
585ossl_lock_callback(
int mode,
int type,
const char *file,
int line)
587 ossl_lock_unlock(mode, &ossl_locks[
type]);
590static 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);
1113#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000
1114 if (!OPENSSL_init_ssl(0,
NULL))
1117 OpenSSL_add_ssl_algorithms();
1118 OpenSSL_add_all_algorithms();
1119 ERR_load_crypto_strings();
1120 SSL_load_error_strings();
1142#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000
1190#if !defined(HAVE_OPENSSL_110_THREADING_API)
1214#if defined(OSSL_DEBUG)
1218#if !defined(LIBRESSL_VERSION_NUMBER) && \
1219 (OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \
1220 defined(CRYPTO_malloc_debug_init))
1224#if defined(CRYPTO_malloc_debug_init)
1225 CRYPTO_malloc_debug_init();
1228#if defined(V_CRYPTO_MDEBUG_ALL)
1229 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
1232#if OPENSSL_VERSION_NUMBER < 0x10100000
1240 for (
i = 0;
i <= 15;
i++) {
1241 if (CRYPTO_get_ex_new_index(
i, 0, (
void *)
"ossl-mdebug-dummy", 0, 0, 0) < 0)
1243 "class index %d failed",
i);
char str[HTML_ESCAPE_MAX_LEN+1]
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *)
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_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_protect(VALUE(*)(VALUE), VALUE, int *)
Protects a function call from potential global escapes from the function.
void rb_warn(const char *fmt,...)
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
VALUE type(ANYARGS)
ANYARGS-ed function type.
unsigned char buf[MIME_BUF_SIZE]
void ossl_bin2hex(unsigned char *in, char *out, size_t inlen)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
VALUE ossl_get_errors(VALUE _)
#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup)
VALUE ossl_buf2str(char *buf, int len)
VALUE ossl_str_new(const char *ptr, long len, int *pstate)
#define OSSL_IMPL_SK2ARY(name, type)
void ossl_debug(const char *fmt,...)
VALUE ossl_pem_passwd_value(VALUE pass)
VALUE ossl_to_der(VALUE obj)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_raise(VALUE exc, const char *fmt,...)
void ossl_clear_error(void)
void Init_ossl_asn1(void)
void Init_ossl_cipher(void)
void Init_ossl_config(void)
void Init_ossl_digest(void)
void Init_ossl_engine(void)
void Init_ossl_hmac(void)
void Init_ossl_ns_spki(void)
void Init_ossl_ocsp(void)
void Init_ossl_pkcs12(void)
void Init_ossl_pkcs7(void)
void Init_ossl_pkey(void)
void Init_ossl_rand(void)
void Init_ossl_x509(void)
X509 * DupX509CertPtr(VALUE)
Stores locks needed for OpenSSL thread safety.
rb_nativethread_lock_t lock
rb_nativethread_id_t owner