4 static int p5_ssl_ex_ssl_ptr=0;
5 static int p5_ssl_ex_ssl_info_callback=0;
6 static int p5_ssl_ex_ssl_ctx_ptr=0;
7 static int p5_ssl_ctx_ex_ssl_info_callback=0;
9 typedef struct ssl_ic_args_st {
14 static void p5_ssl_info_callback(ssl,mode,ret)
22 me=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_ptr);
23 cb=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_info_callback);
25 cb=(SV *)SSL_CTX_get_ex_data(
26 SSL_get_SSL_CTX(ssl),p5_ssl_ctx_ex_ssl_info_callback);
33 XPUSHs(sv_2mortal(newSViv(mode)));
34 XPUSHs(sv_2mortal(newSViv(ret)));
37 i=perl_call_sv(cb,G_DISCARD);
41 croak("Internal error in SSL p5_ssl_info_callback");
48 SSL_get_ex_new_index(0,"OpenSSL::SSL",ex_new,NULL,ex_cleanup);
49 p5_ssl_ex_ssl_info_callback=
50 SSL_get_ex_new_index(0,"ssl_info_callback",NULL,NULL,
52 p5_ssl_ex_ssl_ctx_ptr=
53 SSL_get_ex_new_index(0,"ssl_ctx_ptr",NULL,NULL,
55 p5_ssl_ctx_ex_ssl_info_callback=
56 SSL_CTX_get_ex_new_index(0,"ssl_ctx_info_callback",NULL,NULL,
61 MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL::CTX PREFIX = p5_SSL_CTX_
73 pr_name("p5_SSL_CTX_new");
74 if ((items == 1) && SvPOK(ST(0)))
75 method=SvPV(ST(0),na);
76 else if ((items == 2) && SvPOK(ST(1)))
77 method=SvPV(ST(1),na);
79 croak("Usage: OpenSSL::SSL::CTX::new(type)");
81 if (strcmp(method,"SSLv3") == 0)
83 else if (strcmp(method,"SSLv3_client") == 0)
84 meth=SSLv3_client_method();
85 else if (strcmp(method,"SSLv3_server") == 0)
86 meth=SSLv3_server_method();
87 else if (strcmp(method,"SSLv23") == 0)
89 else if (strcmp(method,"SSLv23_client") == 0)
90 meth=SSLv23_client_method();
91 else if (strcmp(method,"SSLv23_server") == 0)
92 meth=SSLv23_server_method();
93 else if (strcmp(method,"SSLv2") == 0)
95 else if (strcmp(method,"SSLv2_client") == 0)
96 meth=SSLv2_client_method();
97 else if (strcmp(method,"SSLv2_server") == 0)
98 meth=SSLv2_server_method();
99 else if (strcmp(method,"TLSv1") == 0)
101 else if (strcmp(method,"TLSv1_client") == 0)
102 meth=TLSv1_client_method();
103 else if (strcmp(method,"TLSv1_server") == 0)
104 meth=TLSv1_server_method();
107 croak("Not a valid SSL method name, should be 'SSLv[23] [client|server]'");
110 PUSHs(sv_newmortal());
111 ctx=SSL_CTX_new(meth);
112 sv_setref_pv(ST(0), "OpenSSL::SSL::CTX", (void*)ctx);
115 p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
119 int i=SSL_FILETYPE_PEM;
122 pr_name("p5_SSL_CTX_use_PrivateKey_file");
124 croak("OpenSSL::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
128 if (strcmp(ptr,"der") == 0)
133 RETVAL=SSL_CTX_use_RSAPrivateKey_file(ctx,file,i);
138 p5_SSL_CTX_set_options(ctx,...)
145 pr_name("p5_SSL_CTX_set_options");
147 for (i=1; i<items; i++)
150 croak("Usage: OpenSSL::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
152 if (strcmp(ptr,"-info_callback") == 0)
154 SSL_CTX_set_info_callback(ctx,
155 p5_ssl_info_callback);
156 sv=sv_mortalcopy(ST(i+1));
158 SSL_CTX_set_ex_data(ctx,
159 p5_ssl_ctx_ex_ssl_info_callback,
165 croak("OpenSSL::SSL_CTX::set_options(): unknown option");
170 p5_SSL_CTX_DESTROY(ctx)
175 pr_name_d("p5_SSL_CTX_DESTROY",ctx->references);
178 MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL PREFIX = p5_SSL_
188 pr_name("p5_SSL_new");
189 if ((items != 1) && (items != 2))
190 croak("Usage: OpenSSL::SSL::new(ssl_ctx)");
191 if (sv_derived_from(ST(items-1),"OpenSSL::SSL::CTX"))
193 IV tmp = SvIV((SV*)SvRV(ST(items-1)));
198 croak("ssl_ctx is not of type OpenSSL::SSL::CTX");
201 PUSHs(sv_newmortal());
203 sv_setref_pv(ST(0), "OpenSSL::SSL", (void*)ssl);
205 /* Now this is being a little hairy, we keep a pointer to
206 * our perl reference. We need to do a different one
207 * to the one we return because it will have its reference
208 * count dropped to 0 upon return and if we up its reference
209 * count, it will never be DESTROYED */
211 SSL_set_ex_data(ssl,p5_ssl_ex_ssl_ptr,(char *)arg);
212 SvREFCNT_inc(sv_ctx);
213 SSL_set_ex_data(ssl,p5_ssl_ex_ssl_ctx_ptr,(char *)sv_ctx);
219 RETVAL=SSL_connect(ssl);
227 RETVAL=SSL_connect(ssl);
232 p5_SSL_sysread(ssl,in,num, ...)
251 croak("Offset outside string");
255 if ((num+offset) > olen)
257 SvGROW(in,num+offset+1);
259 memset(&(p[olen]),0,(num+offset)-olen+1);
263 i=SSL_read(ssl,p+offset,num);
266 SvCUR_set(in,offset+i);
271 p5_SSL_syswrite(ssl,in, ...)
283 len=SvOK(ST(2))?SvIV(ST(2)):in_len;
289 if (-offset > in_len)
290 croak("Offset outside string");
293 else if ((offset >= in_len) && (in_len > 0))
294 croak("Offset outside string");
296 if (len >= (in_len-offset))
302 RETVAL=SSL_write(ssl,ptr+offset,len);
307 p5_SSL_set_bio(ssl,bio)
312 SSL_set_bio(ssl,bio,bio);
315 p5_SSL_set_options(ssl,...)
322 pr_name("p5_SSL_set_options");
324 for (i=1; i<items; i++)
327 croak("Usage: OpenSSL::SSL::set_options(ssl[,option,value]+)");
329 if (strcmp(ptr,"-info_callback") == 0)
331 SSL_set_info_callback(ssl,
332 p5_ssl_info_callback);
333 sv=sv_mortalcopy(ST(i+1));
336 p5_ssl_ex_ssl_info_callback,(char *)sv);
339 else if (strcmp(ptr,"-connect_state") == 0)
341 SSL_set_connect_state(ssl);
343 else if (strcmp(ptr,"-accept_state") == 0)
345 SSL_set_accept_state(ssl);
349 croak("OpenSSL::SSL::set_options(): unknown option");
359 pr_name("p5_SSL_state");
361 PUSHs(sv_newmortal());
362 state=SSL_state(ssl);
363 sv_setpv(ST(0),SSL_state_string_long(ssl));
364 sv_setiv(ST(0),state);
371 pr_name_dd("p5_SSL_DESTROY",ssl->references,ssl->ctx->references);
373 fprintf(stderr,"SSL_DESTROY %d\n",ssl->references);
378 p5_SSL_references(ssl)
381 RETVAL=ssl->references;
386 p5_SSL_do_handshake(ssl)
389 RETVAL=SSL_do_handshake(ssl);
394 p5_SSL_renegotiate(ssl)
397 RETVAL=SSL_renegotiate(ssl);
405 RETVAL=SSL_shutdown(ssl);
410 p5_SSL_get_version(ssl)
413 RETVAL=SSL_get_version(ssl);
418 p5_SSL_get_current_cipher(ssl)
421 RETVAL=SSL_get_current_cipher(ssl);
426 p5_SSL_get_peer_certificate(ssl)
429 RETVAL=SSL_get_peer_certificate(ssl);
433 MODULE = OpenSSL::SSL PACKAGE = OpenSSL::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
436 p5_SSL_CIPHER_get_bits(sc)
442 PUSHs(sv_newmortal());
443 PUSHs(sv_newmortal());
444 ret=SSL_CIPHER_get_bits(sc,&i);
445 sv_setiv(ST(0),(IV)ret);
446 sv_setiv(ST(1),(IV)i);
449 p5_SSL_CIPHER_get_version(sc)
452 RETVAL=SSL_CIPHER_get_version(sc);
457 p5_SSL_CIPHER_get_name(sc)
460 RETVAL=SSL_CIPHER_get_name(sc);
464 MODULE = OpenSSL::SSL PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
474 if ((i=BIO_get_ssl(bio,&ssl)) > 0)
476 ret=(SV *)SSL_get_ex_data(ssl,p5_ssl_ex_ssl_ptr);
477 ret=sv_mortalcopy(ret);