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