X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=include%2Fmodules%2Fssl.h;h=9830b1ca6b24a8b289d03218616470be6feed47f;hb=3d6d9cda32d72ff25cf6e624bb271b629898e018;hp=a4512153761af0f11f8cb0010a39db0cc0466a5b;hpb=79db1cf848c64ba50bebadef4c683ae4237080b7;p=user%2Fhenk%2Fcode%2Finspircd.git 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(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 "";