1 /**
2  * SSL support.
3  *
4  * License:
5  *   This Source Code Form is subject to the terms of
6  *   the Mozilla Public License, v. 2.0. If a copy of
7  *   the MPL was not distributed with this file, You
8  *   can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Authors:
11  *   Vladimir Panteleev <vladimir@thecybershadow.net>
12  */
13 
14 module ae.net.ssl;
15 
16 import ae.net.asockets : IConnection, ConnectionAdapter;
17 
18 class SSLProvider
19 {
20 	abstract SSLContext createContext(SSLContext.Kind kind);
21 	abstract SSLAdapter createAdapter(SSLContext context, IConnection next);
22 }
23 
24 class NoSSLProvider : SSLProvider
25 {
26 	override SSLContext createContext(SSLContext.Kind kind)
27 	{
28 		assert(false, "SSL implementation not set");
29 	}
30 
31 	override SSLAdapter createAdapter(SSLContext context, IConnection next)
32 	{
33 		assert(false, "SSL implementation not set");
34 	}
35 }
36 
37 abstract class SSLContext
38 {
39 	enum Kind { client, server }
40 	enum Verify { none, verify, require }
41 
42 	abstract void setCipherList(string[] ciphers);
43 	abstract void enableDH(int bits);
44 	abstract void enableECDH();
45 	abstract void setCertificate(string path);
46 	abstract void setPrivateKey(string path);
47 	abstract void setPeerVerify(Verify verify);
48 	abstract void setPeerRootCertificate(string path);
49 	abstract void setFlags(int); // implementation-specific
50 }
51 
52 abstract class SSLAdapter : ConnectionAdapter
53 {
54 	this(IConnection next) { super(next); }
55 	abstract void setHostName(string hostname);
56 	abstract SSLCertificate getHostCertificate();
57 	abstract SSLCertificate getPeerCertificate();
58 }
59 
60 abstract class SSLCertificate
61 {
62 	string getSubjectName();
63 }
64 
65 SSLProvider ssl;
66 
67 static this()
68 {
69 	assert(!ssl);
70 	ssl = new NoSSLProvider();
71 }