32 #ifndef _QORE_SSLSOCKETHELPER_H
34 #define _QORE_SSLSOCKETHELPER_H
36 #ifdef NEED_SSL_CTX_NEW_CONST
37 #define SSL_METHOD_CONST const
39 #define SSL_METHOD_CONST
42 hashdecl qore_socket_private;
50 static inline const char* get_action_method(SslAction action) {
52 case READ:
return "SSL_read";
53 case WRITE:
return "SSL_write";
54 case PEEK:
return "SSL_peek";
60 class SSLSocketHelper {
62 DLLLOCAL SSLSocketHelper(qore_socket_private& qs) : qs(qs) {
66 DLLLOCAL
bool deref() {
80 DLLLOCAL
int doSSLRW(
ExceptionSink* xsink,
const char* mname,
void* buf,
int num,
int timeout_ms,
81 SslAction action,
bool do_timeout =
true);
83 DLLLOCAL
int setClient(
const char* mname,
const char* sni_target_host,
int sd, X509* cert, EVP_PKEY* pk,
85 DLLLOCAL
int setServer(
const char* mname,
int sd, X509* cert, EVP_PKEY* pk,
ExceptionSink* xsink);
87 DLLLOCAL
int connect(
const char* mname,
int timeout_ms,
ExceptionSink* xsink);
89 DLLLOCAL
int accept(
const char* mname,
int timeout_ms,
ExceptionSink* xsink);
91 DLLLOCAL
int shutdown();
95 DLLLOCAL
int read(
const char* mname,
char* buf,
int size,
int timeout_ms,
ExceptionSink* xsink);
97 DLLLOCAL
int write(
const char* mname,
const void* buf,
int size,
int timeout_ms,
ExceptionSink* xsink);
98 DLLLOCAL
const char* getCipherName()
const;
99 DLLLOCAL
const char* getCipherVersion()
const;
100 DLLLOCAL X509* getPeerCertificate()
const;
101 DLLLOCAL
long verifyPeerCertificate()
const;
103 DLLLOCAL
void setVerifyMode(
int mode,
bool accept_all_certs,
const std::string& target);
105 DLLLOCAL
bool captureRemoteCert()
const;
106 DLLLOCAL
void clearRemoteCertContext()
const;
109 qore_socket_private& qs;
110 SSL_METHOD_CONST SSL_METHOD* meth =
nullptr;
111 SSL_CTX* ctx =
nullptr;
115 DLLLOCAL
int setIntern(
const char* meth,
int sd, X509* cert, EVP_PKEY* pk,
ExceptionSink* xsink);
118 DLLLOCAL
int doSSLUpgradeNonBlockingIO(
int rc,
const char* mname,
int timeout_ms,
const char* ssl_func,
121 DLLLOCAL ~SSLSocketHelper();
124 DLLLOCAL
bool sslError(
ExceptionSink* xsink,
const char* meth,
const char* msg,
bool always_error =
true);
126 DLLLOCAL
void handleErrorIntern(
ExceptionSink* xsink,
int e,
const char* mname,
const char* func,
130 class SSLSocketReferenceHelper {
132 DLLLOCAL SSLSocketReferenceHelper(SSLSocketHelper* s,
bool set_thread_context =
false);
134 DLLLOCAL ~SSLSocketReferenceHelper();
138 bool context_saved =
false;