]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/transport.h
f4cf3f4a5e70c1d07527fa1d86d7bba57e02cd78
[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 Extensible::Extend() and the
27  * key 'ssl_cert'.
28  */
29 class ssl_cert
30 {
31  public:
32         std::string dn;
33         std::string issuer;
34         std::string error;
35         std::string fingerprint;
36         bool trusted, invalid, unknownsigner, revoked;
37
38         /** Get certificate distinguished name
39          * @return Certificate DN
40          */
41         const std::string& GetDN()
42         {
43                 return dn;
44         }
45
46         /** Get Certificate issuer
47          * @return Certificate issuer
48          */
49         const std::string& GetIssuer()
50         {
51                 return issuer;
52         }
53
54         /** Get error string if an error has occured
55          * @return The error associated with this users certificate,
56          * or an empty string if there is no error.
57          */
58         const std::string& GetError()
59         {
60                 return error;
61         }
62
63         /** Get key fingerprint.
64          * @return The key fingerprint as a hex string.
65          */
66         const std::string& GetFingerprint()
67         {
68                 return fingerprint;
69         }
70
71         /** Get trust status
72          * @return True if this is a trusted certificate
73          * (the certificate chain validates)
74          */
75         bool IsTrusted()
76         {
77                 return trusted;
78         }
79
80         /** Get validity status
81          * @return True if the certificate itself is
82          * correctly formed.
83          */
84         bool IsInvalid()
85         {
86                 return invalid;
87         }
88
89         /** Get signer status
90          * @return True if the certificate appears to be
91          * self-signed.
92          */
93         bool IsUnknownSigner()
94         {
95                 return unknownsigner;
96         }
97
98         /** Get revokation status.
99          * @return True if the certificate is revoked.
100          * Note that this only works properly for GnuTLS
101          * right now.
102          */
103         bool IsRevoked()
104         {
105                 return revoked;
106         }
107 };
108
109 /** Used to represent a request to a transport provider module
110  */
111 class ISHRequest : public Request
112 {
113  public:
114         BufferedSocket* Sock;
115
116         ISHRequest(Module* Me, Module* Target, const char* rtype, BufferedSocket* sock) : Request(Me, Target, rtype), Sock(sock)
117         {
118         }
119 };
120
121 /** Used to represent a request to attach a cert to an BufferedSocket
122  */
123 class BufferedSocketAttachCertRequest : public ISHRequest
124 {
125  public:
126         /** Initialize the request as an attach cert message */
127         BufferedSocketAttachCertRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_ATTACH", is)
128         {
129         }
130 };
131
132 /** Used to check if a handshake is complete on an BufferedSocket yet
133  */
134 class BufferedSocketHSCompleteRequest : public ISHRequest
135 {
136  public:
137         /** Initialize the request as a 'handshake complete?' message */
138         BufferedSocketHSCompleteRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HSDONE", is)
139         {
140         }
141 };
142
143 /** Used to hook a transport provider to an BufferedSocket
144  */
145 class BufferedSocketHookRequest : public ISHRequest
146 {
147  public:
148         /** Initialize request as a hook message */
149         BufferedSocketHookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HOOK", is)
150         {
151         }
152 };
153
154 /** Used to unhook a transport provider from an BufferedSocket
155  */
156 class BufferedSocketUnhookRequest : public ISHRequest
157 {
158  public:
159         /** Initialize request as an unhook message */
160         BufferedSocketUnhookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_UNHOOK", is)
161         {
162         }
163 };
164
165 class BufferedSocketNameRequest : public ISHRequest
166 {
167  public:
168         /** Initialize request as a get name message */
169         BufferedSocketNameRequest(Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_NAME", NULL)
170         {
171         }
172 };
173
174 class BufferedSocketFingerprintRequest : public ISHRequest
175 {
176  public:
177         /** Initialize request as a fingerprint message */
178         BufferedSocketFingerprintRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "GET_FP", is)
179         {
180         }
181 };
182
183 #endif