mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_ssl.c (ossl_start_ssl): new function to wrap
SSL_connect and SSL_accept; if SSL_connect (or SSL_accept) returned but not finished the handshake process, we should retry it. * ext/openssl/ossl_ssl.c (ossl_ssl_connect): call ossl_start_ssl. * ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto. * ext/openssl/ossl_ssl.c (ossl_ssl_read): allow signal traps. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a971d184ce
commit
70daacc533
2 changed files with 37 additions and 6 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Sat Dec 6 22:58:03 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||
|
||||
* ext/openssl/ossl_ssl.c (ossl_start_ssl): new function to wrap
|
||||
SSL_connect and SSL_accept; if SSL_connect (or SSL_accept) returned
|
||||
but not finished the handshake process, we should retry it.
|
||||
|
||||
* ext/openssl/ossl_ssl.c (ossl_ssl_connect): call ossl_start_ssl.
|
||||
|
||||
* ext/openssl/ossl_ssl.c (ossl_ssl_accept): ditto.
|
||||
|
||||
* ext/openssl/ossl_ssl.c (ossl_ssl_read): allow signal traps.
|
||||
|
||||
Sat Dec 6 21:45:10 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* io.c (flush_before_seek): flush before seek on any platform.
|
||||
|
|
|
@ -435,6 +435,27 @@ ossl_ssl_setup(VALUE self)
|
|||
return Qtrue;
|
||||
}
|
||||
|
||||
static void
|
||||
ossl_start_ssl(SSL *ssl, int (*func)())
|
||||
{
|
||||
int ret;
|
||||
|
||||
for(;;){
|
||||
if((ret = func(ssl)) > 0) break;
|
||||
switch(SSL_get_error(ssl, ret)){
|
||||
case SSL_ERROR_NONE:
|
||||
break;
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
rb_thread_schedule();
|
||||
continue;
|
||||
default:
|
||||
ossl_raise(eSSLError, "SSL_accept:");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_ssl_connect(VALUE self)
|
||||
{
|
||||
|
@ -445,9 +466,7 @@ ossl_ssl_connect(VALUE self)
|
|||
Data_Get_Struct(self, SSL, ssl);
|
||||
cb = ossl_sslctx_get_verify_cb(ossl_ssl_get_ctx(self));
|
||||
SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)cb);
|
||||
if (SSL_connect(ssl) <= 0) {
|
||||
ossl_raise(eSSLError, "SSL_connect:");
|
||||
}
|
||||
ossl_start_ssl(ssl, SSL_connect);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -462,9 +481,7 @@ ossl_ssl_accept(VALUE self)
|
|||
Data_Get_Struct(self, SSL, ssl);
|
||||
cb = ossl_sslctx_get_verify_cb(ossl_ssl_get_ctx(self));
|
||||
SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)cb);
|
||||
if (SSL_accept(ssl) <= 0) {
|
||||
ossl_raise(eSSLError, "SSL_accept:");
|
||||
}
|
||||
ossl_start_ssl(ssl, SSL_accept);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -482,7 +499,9 @@ ossl_ssl_read(VALUE self, VALUE len)
|
|||
str = rb_str_new(0, ilen);
|
||||
|
||||
if (ssl) {
|
||||
TRAP_BEG;
|
||||
nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
|
||||
TRAP_END;
|
||||
if (nread < 0) {
|
||||
ossl_raise(eSSLError, "SSL_read:");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue