]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/ssl.h
Clarify handshake failure messages
[user/henk/code/inspircd.git] / src / modules / ssl.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __SSL_H__
15 #define __SSL_H__
16
17 #include <map>
18 #include <string>
19
20 /** ssl_cert is a class which abstracts SSL certificate
21  * and key information.
22  *
23  * Because gnutls and openssl represent key information in
24  * wildly different ways, this class allows it to be accessed
25  * in a unified manner. These classes are attached to ssl-
26  * connected local users using SSLCertExt
27  */
28 class ssl_cert
29 {
30  public:
31         std::string dn;
32         std::string issuer;
33         std::string error;
34         std::string fingerprint;
35         bool trusted, invalid, unknownsigner, revoked;
36
37         /** Get certificate distinguished name
38          * @return Certificate DN
39          */
40         const std::string& GetDN()
41         {
42                 return dn;
43         }
44
45         /** Get Certificate issuer
46          * @return Certificate issuer
47          */
48         const std::string& GetIssuer()
49         {
50                 return issuer;
51         }
52
53         /** Get error string if an error has occured
54          * @return The error associated with this users certificate,
55          * or an empty string if there is no error.
56          */
57         const std::string& GetError()
58         {
59                 return error;
60         }
61
62         /** Get key fingerprint.
63          * @return The key fingerprint as a hex string.
64          */
65         const std::string& GetFingerprint()
66         {
67                 return fingerprint;
68         }
69
70         /** Get trust status
71          * @return True if this is a trusted certificate
72          * (the certificate chain validates)
73          */
74         bool IsTrusted()
75         {
76                 return trusted;
77         }
78
79         /** Get validity status
80          * @return True if the certificate itself is
81          * correctly formed.
82          */
83         bool IsInvalid()
84         {
85                 return invalid;
86         }
87
88         /** Get signer status
89          * @return True if the certificate appears to be
90          * self-signed.
91          */
92         bool IsUnknownSigner()
93         {
94                 return unknownsigner;
95         }
96
97         /** Get revokation status.
98          * @return True if the certificate is revoked.
99          * Note that this only works properly for GnuTLS
100          * right now.
101          */
102         bool IsRevoked()
103         {
104                 return revoked;
105         }
106
107         std::string GetMetaLine()
108         {
109                 std::stringstream value;
110                 bool hasError = error.length();
111                 value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
112                         << (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
113                 if (hasError)
114                         value << GetError();
115                 else
116                         value << GetFingerprint() << " " << GetDN() << " " << GetIssuer();
117                 return value.str();
118         }
119 };
120
121 struct SSLCertificateRequest : public Request
122 {
123         Extensible* const item;
124         ssl_cert* cert;
125
126         SSLCertificateRequest(Extensible* e, Module* Me, Module* info = ServerInstance->Modules->Find("m_sslinfo.so"))
127                 : Request(Me, info, "GET_CERT"), item(e), cert(NULL)
128         {
129                 Send();
130         }
131
132         std::string GetFingerprint()
133         {
134                 if (cert)
135                         return cert->GetFingerprint();
136                 return "";
137         }
138 };
139
140 struct SSLCertSubmission : public Request
141 {
142         Extensible* const item;
143         ssl_cert* const cert;
144         SSLCertSubmission(Extensible* is, Module* Me, Module* Target, ssl_cert* Cert)
145                 : Request(Me, Target, "SET_CERT"), item(is), cert(Cert)
146         {
147                 Send();
148         }
149 };
150
151 #endif