summaryrefslogtreecommitdiff
path: root/include/modules/ssl.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/modules/ssl.h')
-rw-r--r--include/modules/ssl.h63
1 files changed, 55 insertions, 8 deletions
diff --git a/include/modules/ssl.h b/include/modules/ssl.h
index a45121537..9830b1ca6 100644
--- a/include/modules/ssl.h
+++ b/include/modules/ssl.h
@@ -132,20 +132,67 @@ class ssl_cert : public refcountbase
}
};
-/** Get certificate from a socket (only useful with an SSL module) */
-struct SocketCertificateRequest : public Request
+class SSLIOHook : public IOHook
{
- StreamSocket* const sock;
- ssl_cert* cert;
+ public:
+ SSLIOHook(Module* mod, const std::string& Name)
+ : IOHook(mod, Name, IOHook::IOH_SSL)
+ {
+ }
+
+ /**
+ * Get the client certificate from a socket
+ * @param sock The socket to get the certificate from, must be using this IOHook
+ * @return The SSL client certificate information
+ */
+ virtual ssl_cert* GetCertificate(StreamSocket* sock) = 0;
- SocketCertificateRequest(StreamSocket* ss, Module* Me)
- : Request(Me, (ss->GetIOHook() ? (Module*)ss->GetIOHook()->creator : NULL), "GET_SSL_CERT"), sock(ss), cert(NULL)
+ /**
+ * Get the fingerprint of a client certificate from a socket
+ * @param sock The socket to get the certificate fingerprint from, must be using this IOHook
+ * @return The fingerprint of the SSL client certificate sent by the peer,
+ * empty if no cert was sent
+ */
+ std::string GetFingerprint(StreamSocket* sock)
{
- Send();
+ ssl_cert* cert = GetCertificate(sock);
+ if (cert)
+ return cert->GetFingerprint();
+ return "";
}
+};
- std::string GetFingerprint()
+/** Helper functions for obtaining SSL client certificates and key fingerprints
+ * from StreamSockets
+ */
+class SSLClientCert
+{
+ public:
+ /**
+ * Get the client certificate from a socket
+ * @param sock The socket to get the certificate from, the socket does not have to use SSL
+ * @return The SSL client certificate information, NULL if the peer is not using SSL
+ */
+ static ssl_cert* GetCertificate(StreamSocket* sock)
+ {
+ IOHook* iohook = sock->GetIOHook();
+ if ((!iohook) || (iohook->type != IOHook::IOH_SSL))
+ return NULL;
+
+ SSLIOHook* ssliohook = static_cast<SSLIOHook*>(iohook);
+ return ssliohook->GetCertificate(sock);
+ }
+
+ /**
+ * Get the fingerprint of a client certificate from a socket
+ * @param sock The socket to get the certificate fingerprint from, the
+ * socket does not have to use SSL
+ * @return The key fingerprint from the SSL certificate sent by the peer,
+ * empty if no cert was sent or the peer is not using SSL
+ */
+ static std::string GetFingerprint(StreamSocket* sock)
{
+ ssl_cert* cert = SSLClientCert::GetCertificate(sock);
if (cert)
return cert->GetFingerprint();
return "";