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,
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()");