]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/transport.h
Introduce "X" snomask for remote *:line messages [patch by jackmcbarn]
[user/henk/code/inspircd.git] / src / modules / transport.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 __TRANSPORT_H__
15 #define __TRANSPORT_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 /** Used to represent a request to a transport provider module
122  */
123 class ISHRequest : public Request
124 {
125  public:
126         BufferedSocket* Sock;
127
128         ISHRequest(Module* Me, Module* Target, const char* rtype, BufferedSocket* sock) : Request(Me, Target, rtype), Sock(sock)
129         {
130         }
131 };
132
133 /** Used to represent a request to attach a cert to an BufferedSocket
134  */
135 class BufferedSocketAttachCertRequest : public ISHRequest
136 {
137  public:
138         /** Initialize the request as an attach cert message */
139         BufferedSocketAttachCertRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_ATTACH", is)
140         {
141         }
142 };
143
144 /** Used to check if a handshake is complete on an BufferedSocket yet
145  */
146 class BufferedSocketHSCompleteRequest : public ISHRequest
147 {
148  public:
149         /** Initialize the request as a 'handshake complete?' message */
150         BufferedSocketHSCompleteRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HSDONE", is)
151         {
152         }
153 };
154
155 /** Used to hook a transport provider to an BufferedSocket
156  */
157 class BufferedSocketHookRequest : public ISHRequest
158 {
159  public:
160         /** Initialize request as a hook message */
161         BufferedSocketHookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HOOK", is)
162         {
163         }
164 };
165
166 /** Used to unhook a transport provider from an BufferedSocket
167  */
168 class BufferedSocketUnhookRequest : public ISHRequest
169 {
170  public:
171         /** Initialize request as an unhook message */
172         BufferedSocketUnhookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_UNHOOK", is)
173         {
174         }
175 };
176
177 class BufferedSocketNameRequest : public ISHRequest
178 {
179  public:
180         /** Initialize request as a get name message */
181         BufferedSocketNameRequest(Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_NAME", NULL)
182         {
183         }
184 };
185
186 struct BufferedSocketCertificateRequest : public Request
187 {
188         Extensible* const item;
189         ssl_cert* cert;
190         BufferedSocketCertificateRequest(Extensible* is, Module* Me, Module* Target)
191                 : Request(Me, Target, "GET_CERT"), item(is), cert(NULL)
192         {
193         }
194 };
195
196 struct BufferedSocketFingerprintSubmission : public Request
197 {
198         Extensible* const item;
199         ssl_cert* const cert;
200         BufferedSocketFingerprintSubmission(Extensible* is, Module* Me, Module* Target, ssl_cert* Cert)
201                 : Request(Me, Target, "SET_CERT"), item(is), cert(Cert)
202         {
203         }
204 };
205
206 #endif