32 #ifndef _QORE_SSLSOCKETHELPER_H
34 #define _QORE_SSLSOCKETHELPER_H
36 #include <openssl/ssl.h>
38 #ifdef NEED_SSL_CTX_NEW_CONST
39 #define SSL_METHOD_CONST const
41 #define SSL_METHOD_CONST
44 hashdecl qore_socket_private;
52 static inline const char* get_action_method(SslAction action) {
54 case READ:
return "SSL_read";
55 case WRITE:
return "SSL_write";
56 case PEEK:
return "SSL_peek";
62 class SSLSocketHelper {
64 DLLLOCAL SSLSocketHelper(qore_socket_private& qs) : qs(qs) {
68 DLLLOCAL
bool deref() {
82 DLLLOCAL
int doSSLRW(
ExceptionSink* xsink,
const char* mname,
void* buf,
int num,
int timeout_ms,
83 SslAction action,
bool do_timeout =
true);
92 DLLLOCAL
int doNonBlockingIo(
ExceptionSink* xsink,
const char* mname,
void* buf,
size_t size, SslAction action,
95 DLLLOCAL
int setClient(
const char* mname,
const char* sni_target_host,
int sd, X509* cert, EVP_PKEY* pk,
97 DLLLOCAL
int setServer(
const char* mname,
int sd, X509* cert, EVP_PKEY* pk,
ExceptionSink* xsink);
99 DLLLOCAL
int connect(
const char* mname,
int timeout_ms,
ExceptionSink* xsink);
101 DLLLOCAL
int accept(
const char* mname,
int timeout_ms,
ExceptionSink* xsink);
103 DLLLOCAL
int shutdown();
107 DLLLOCAL
int read(
const char* mname,
char* buf,
int size,
int timeout_ms,
ExceptionSink* xsink);
109 DLLLOCAL
int write(
const char* mname,
const void* buf,
int size,
int timeout_ms,
ExceptionSink* xsink);
117 DLLLOCAL
const char* getCipherName()
const;
118 DLLLOCAL
const char* getCipherVersion()
const;
119 DLLLOCAL X509* getPeerCertificate()
const;
120 DLLLOCAL
long verifyPeerCertificate()
const;
122 DLLLOCAL
void setVerifyMode(
int mode,
bool accept_all_certs,
const std::string& target);
124 DLLLOCAL
bool captureRemoteCert()
const;
125 DLLLOCAL
void clearRemoteCertContext()
const;
128 qore_socket_private& qs;
129 SSL_METHOD_CONST SSL_METHOD* meth =
nullptr;
130 SSL_CTX* ctx =
nullptr;
134 DLLLOCAL
int setIntern(
const char* meth,
int sd, X509* cert, EVP_PKEY* pk,
ExceptionSink* xsink);
137 DLLLOCAL
int doSSLUpgradeNonBlockingIO(
int rc,
const char* mname,
int timeout_ms,
const char* ssl_func,
140 DLLLOCAL ~SSLSocketHelper();
143 DLLLOCAL
bool sslError(
ExceptionSink* xsink,
const char* meth,
const char* msg,
bool always_error =
true);
146 DLLLOCAL
int sysCallError(
ExceptionSink* xsink,
int rc,
const char* mname,
const char* ssl_func);
148 DLLLOCAL
void handleErrorIntern(
ExceptionSink* xsink,
int e,
const char* mname,
const char* func,
152 class SSLSocketReferenceHelper {
154 DLLLOCAL SSLSocketReferenceHelper(SSLSocketHelper* s,
bool set_thread_context =
false);
156 DLLLOCAL ~SSLSocketReferenceHelper();
160 bool context_saved =
false;
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48