]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/transport.h
ba8e3973be88048cc95fd376e0b37539a7c4b943
[user/henk/code/inspircd.git] / src / modules / transport.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __TRANSPORT_H__
15 #define __TRANSPORT_H__
16
17 #include <map>
18 #include <string>
19
20 /** A generic container for certificate data
21  */
22 typedef std::map<std::string,std::string> ssl_data;
23
24 /** A shorthand way of representing an iterator into ssl_data
25  */
26 typedef ssl_data::iterator ssl_data_iter;
27
28 /** ssl_cert is a class which abstracts SSL certificate
29  * and key information.
30  *
31  * Because gnutls and openssl represent key information in
32  * wildly different ways, this class allows it to be accessed
33  * in a unified manner. These classes are attached to ssl-
34  * connected local users using Extensible::Extend() and the
35  * key 'ssl_cert'.
36  */
37 class ssl_cert
38 {
39         /** Always contains an empty string
40          */
41         const std::string empty;
42
43  public:
44         /** The data for this certificate
45          */
46         ssl_data data;
47
48         /** Default constructor, initializes 'empty'
49          */
50         ssl_cert() : empty("")
51         {
52         }
53         
54         /** Get certificate distinguished name
55          * @return Certificate DN
56          */
57         const std::string& GetDN()
58         {
59                 ssl_data_iter ssldi = data.find("dn");
60
61                 if (ssldi != data.end())
62                         return ssldi->second;
63                 else
64                         return empty;
65         }
66
67         /** Get Certificate issuer
68          * @return Certificate issuer
69          */
70         const std::string& GetIssuer()
71         {
72                 ssl_data_iter ssldi = data.find("issuer");
73
74                 if (ssldi != data.end())
75                         return ssldi->second;
76                 else
77                         return empty;
78         }
79
80         /** Get error string if an error has occured
81          * @return The error associated with this users certificate,
82          * or an empty string if there is no error.
83          */
84         const std::string& GetError()
85         {
86                 ssl_data_iter ssldi = data.find("error");
87
88                 if (ssldi != data.end())
89                         return ssldi->second;
90                 else
91                         return empty;
92         }
93
94         /** Get key fingerprint.
95          * @return The key fingerprint as a hex string.
96          */
97         const std::string& GetFingerprint()
98         {
99                 ssl_data_iter ssldi = data.find("fingerprint");
100
101                 if (ssldi != data.end())
102                         return ssldi->second;
103                 else
104                         return empty;
105         }
106
107         /** Get trust status
108          * @return True if this is a trusted certificate
109          * (the certificate chain validates)
110          */
111         bool IsTrusted()
112         {
113                 ssl_data_iter ssldi = data.find("trusted");
114
115                 if (ssldi != data.end())
116                         return (ssldi->second == "1");
117                 else
118                         return false;
119         }
120
121         /** Get validity status
122          * @return True if the certificate itself is
123          * correctly formed.
124          */
125         bool IsInvalid()
126         {
127                 ssl_data_iter ssldi = data.find("invalid");
128
129                 if (ssldi != data.end())
130                         return (ssldi->second == "1");
131                 else
132                         return false;
133         }
134
135         /** Get signer status
136          * @return True if the certificate appears to be
137          * self-signed.
138          */
139         bool IsUnknownSigner()
140         {
141                 ssl_data_iter ssldi = data.find("unknownsigner");
142
143                 if (ssldi != data.end())
144                         return (ssldi->second == "1");
145                 else
146                         return false;
147         }
148
149         /** Get revokation status.
150          * @return True if the certificate is revoked.
151          * Note that this only works properly for GnuTLS
152          * right now.
153          */
154         bool IsRevoked()
155         {
156                 ssl_data_iter ssldi = data.find("revoked");
157
158                 if (ssldi != data.end())
159                         return (ssldi->second == "1");
160                 else
161                         return false;
162         }
163 };
164
165 /** Used to represent a request to a transport provider module
166  */
167 class ISHRequest : public Request
168 {
169  public:
170         InspSocket* Sock;
171
172         ISHRequest(Module* Me, Module* Target, const char* rtype, InspSocket* sock) : Request(Me, Target, rtype), Sock(sock)
173         {
174         }
175 };
176
177 /** Used to represent a request to attach a cert to an InspSocket
178  */
179 class InspSocketAttachCertRequest : public ISHRequest
180 {
181  public:
182         /** Initialize the request as an attach cert message */
183         InspSocketAttachCertRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_ATTACH", is)
184         {
185         }
186 };
187
188 /** Used to check if a handshake is complete on an InspSocket yet
189  */
190 class InspSocketHSCompleteRequest : public ISHRequest
191 {
192  public:
193         /** Initialize the request as a 'handshake complete?' message */
194         InspSocketHSCompleteRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HSDONE", is)
195         {
196         }
197 };
198
199 /** Used to hook a transport provider to an InspSocket
200  */
201 class InspSocketHookRequest : public ISHRequest
202 {
203  public:
204         /** Initialize request as a hook message */
205         InspSocketHookRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HOOK", is)
206         {
207         }
208 };
209
210 /** Used to unhook a transport provider from an InspSocket
211  */
212 class InspSocketUnhookRequest : public ISHRequest
213 {
214  public:
215         /** Initialize request as an unhook message */
216         InspSocketUnhookRequest(InspSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_UNHOOK", is)
217         {
218         }
219 };
220
221 class InspSocketNameRequest : public ISHRequest
222 {
223  public:
224         /** Initialize request as a get name message */
225         InspSocketNameRequest(Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_NAME", NULL)
226         {
227         }
228 };
229
230 #endif
231