8 static VALUE eSSLSession;
11 ossl_ssl_session_free(
void *ptr)
13 SSL_SESSION_free(ptr);
17 "OpenSSL/SSL/Session",
19 0, ossl_ssl_session_free,
24 static VALUE ossl_ssl_session_alloc(
VALUE klass)
39 SSL_SESSION *ctx =
NULL;
41 if (
RDATA(
self)->data)
42 ossl_raise(eSSLSession,
"SSL Session already initialized");
49 if ((ctx = SSL_get1_session(ssl)) ==
NULL)
50 ossl_raise(eSSLSession,
"no session available");
58 ctx = d2i_SSL_SESSION_bio(in,
NULL);
69 ossl_raise(eSSLSession,
"ctx not set - internal error");
71 RDATA(
self)->data = ctx;
77 ossl_ssl_session_initialize_copy(
VALUE self,
VALUE other)
79 SSL_SESSION *sess, *sess_other, *sess_new;
85 sess_new = ASN1_dup((i2d_of_void *)i2d_SSL_SESSION, (d2i_of_void *)d2i_SSL_SESSION,
91 SSL_SESSION_free(sess);
97 ossl_SSL_SESSION_cmp(
const SSL_SESSION *a,
const SSL_SESSION *b)
100 const unsigned char *a_sid = SSL_SESSION_get_id(a, &a_len);
102 const unsigned char *b_sid = SSL_SESSION_get_id(b, &b_len);
109 return CRYPTO_memcmp(a_sid, b_sid, a_len);
120 SSL_SESSION *ctx1, *ctx2;
125 switch (ossl_SSL_SESSION_cmp(ctx1, ctx2)) {
126 case 0:
return Qtrue;
138 ossl_ssl_session_get_time(
VALUE self)
144 t = SSL_SESSION_get_time(ctx);
160 ossl_ssl_session_get_timeout(
VALUE self)
166 t = SSL_SESSION_get_timeout(ctx);
189 SSL_SESSION_set_time(ctx, t);
190 return ossl_ssl_session_get_time(
self);
206 SSL_SESSION_set_timeout(ctx, t);
207 return ossl_ssl_session_get_timeout(
self);
216 static VALUE ossl_ssl_session_get_id(
VALUE self)
219 const unsigned char *p =
NULL;
224 p = SSL_SESSION_get_id(ctx, &i);
235 static VALUE ossl_ssl_session_to_der(
VALUE self)
243 len = i2d_SSL_SESSION(ctx,
NULL);
250 i2d_SSL_SESSION(ctx, &p);
261 static VALUE ossl_ssl_session_to_pem(
VALUE self)
268 if (!(out = BIO_new(BIO_s_mem()))) {
272 if (!PEM_write_bio_SSL_SESSION(out, ctx)) {
274 ossl_raise(eSSLSession,
"SSL_SESSION_print()");
288 static VALUE ossl_ssl_session_to_text(
VALUE self)
295 if (!(out = BIO_new(BIO_s_mem()))) {
299 if (!SSL_SESSION_print(out, ctx)) {
301 ossl_raise(eSSLSession,
"SSL_SESSION_print()");
#define RUBY_TYPED_FREE_IMMEDIATELY
#define ossl_str_adjust(str, p)
#define TypedData_Wrap_Struct(klass, data_type, sval)
BIO * ossl_obj2bio(volatile VALUE *pobj)
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 rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE ossl_membio2str(BIO *bio)
#define SSL_SESSION_get_protocol_version(s)
void Init_ossl_ssl_session(void)
RUBY_EXTERN VALUE rb_cObject
#define OSSL_BIO_reset(bio)
VALUE rb_obj_is_instance_of(VALUE, VALUE)
call-seq: obj.instance_of?(class) -> true or false
#define GetSSLSession(obj, sess)
const rb_data_type_t ossl_ssl_session_type
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
void ossl_raise(VALUE exc, const char *fmt,...)
#define RTYPEDDATA_DATA(v)
#define rb_check_frozen(obj)
VALUE rb_define_module(const char *name)
RUBY_EXTERN VALUE rb_cTime
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)