2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
2015-04-19 23:55:09 -04:00
|
|
|
* This program is licensed under the same licence as Ruby.
|
2003-07-23 12:12:24 -04:00
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#if !defined(_OSSL_SSL_H_)
|
|
|
|
#define _OSSL_SSL_H_
|
|
|
|
|
2014-12-12 16:57:33 -05:00
|
|
|
#define GetSSL(obj, ssl) do { \
|
2014-12-12 16:58:34 -05:00
|
|
|
TypedData_Get_Struct((obj), SSL, &ossl_ssl_type, (ssl)); \
|
openssl: move SSLSocket#initialize to C extension
* ext/openssl/lib/openssl/ssl.rb (SSLSocket): Move the implementation of
SSLSocket#initialize to C. Initialize the SSL (OpenSSL object) in it.
Currently this is delayed until ossl_ssl_setup(), which is called from
SSLSocket#accept or #connect. Say we call SSLSocket#hostname= with an
illegal value. We expect an exception to be raised in #hostname= but
actually we get it in the later SSLSocket#connect. Because the SSL is
not ready at #hostname=, the actual call of SSL_set_tlsext_host_name()
is also delayed.
This also fixes: [ruby-dev:49376] [Bug #11724]
* ext/openssl/ossl_ssl.c (ossl_ssl_initialize): Added. Almost the same
as the Ruby version but this instantiate the SSL object at the same
time.
(ossl_ssl_setup): Adjust to the changes. Just set the underlying IO to
the SSL.
(ssl_started): Added. Make use of SSL_get_fd(). This returns -1 if not
yet set by SSL_set_fd().
(ossl_ssl_data_get_struct): Removed. Now GetSSL() checks that the SSL
exists.
(ossl_ssl_set_session): Don't call ossl_ssl_setup() here as now the
SSL is already instantiated in #initialize.
(ossl_ssl_shutdown, ossl_start_ssl, ossl_ssl_read_internal,
ossl_ssl_write_internal, ossl_ssl_stop, ossl_ssl_get_cert,
ossl_ssl_get_peer_cert, ossl_ssl_get_peer_cert_chain,
ossl_ssl_get_version, ossl_ssl_get_cipher, ossl_ssl_get_state,
ossl_ssl_pending, ossl_ssl_session_reused,
ossl_ssl_get_verify_result, ossl_ssl_get_client_ca_list,
ossl_ssl_npn_protocol, ossl_ssl_alpn_protocol, ossl_ssl_tmp_key): Use
GetSSL() instead of ossl_ssl_data_get_struct(). Use ssl_started().
(Init_ossl_ssl): Add method declarations of SSLSocket#{initialize,
hostname=}.
* ext/openssl/ossl_ssl.h (GetSSL): Check that the SSL is not NULL. It
should not be NULL because we now set it in #initialize.
* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_initialize): No need
to check if the SSL is NULL.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-28 01:00:36 -04:00
|
|
|
if (!(ssl)) { \
|
|
|
|
ossl_raise(rb_eRuntimeError, "SSL is not initialized"); \
|
|
|
|
} \
|
2014-12-12 16:57:33 -05:00
|
|
|
} while (0)
|
|
|
|
|
2007-04-02 18:10:12 -04:00
|
|
|
#define GetSSLSession(obj, sess) do { \
|
2014-12-12 16:58:25 -05:00
|
|
|
TypedData_Get_Struct((obj), SSL_SESSION, &ossl_ssl_session_type, (sess)); \
|
2011-03-10 08:28:58 -05:00
|
|
|
if (!(sess)) { \
|
2007-04-02 18:10:12 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-12-12 16:58:34 -05:00
|
|
|
extern const rb_data_type_t ossl_ssl_type;
|
2014-12-12 16:58:25 -05:00
|
|
|
extern const rb_data_type_t ossl_ssl_session_type;
|
2003-07-23 12:12:24 -04:00
|
|
|
extern VALUE mSSL;
|
|
|
|
extern VALUE cSSLSocket;
|
2007-04-02 18:10:12 -04:00
|
|
|
extern VALUE cSSLSession;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
void Init_ossl_ssl(void);
|
2007-04-02 18:10:12 -04:00
|
|
|
void Init_ossl_ssl_session(void);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
#endif /* _OSSL_SSL_H_ */
|