1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 module hunt.proton.engine.SslDomain;
12 
13 //import javax.net.ssl.SSLContext;
14 import hunt.proton.engine.impl.ssl.SslDomainImpl;
15 import hunt.Exceptions;
16 
17 /**
18  * I store the details used to create SSL sessions.
19  */
20 interface SslDomain
21 {
22 
23     class Factory
24     {
25         public static SslDomain create() {
26             implementationMissing(false);
27            // return new SslDomainImpl();
28             return null;
29         }
30     }
31 
32     /**
33      * Determines whether the endpoint acts as a client or server.
34      */
35     enum Mode
36     {
37         /** Local connection endpoint is an SSL client */
38         CLIENT,
39 
40         /** Local connection endpoint is an SSL server */
41         SERVER
42     }
43 
44     /**
45      * Determines the level of peer validation.
46      *
47      * {@link #VERIFY_PEER_NAME} is used by default in {@link Mode#CLIENT client}
48      * mode if not configured otherwise, with {@link #ANONYMOUS_PEER} used for
49      * {@link Mode#SERVER server} mode if not configured otherwise.
50      */
51     public enum VerifyMode
52     {
53         /**
54          * Requires peers provide a valid identifying certificate signed by
55          * a trusted certificate. Does not verify hostname details of the
56          * peer certificate, use {@link #VERIFY_PEER_NAME} for this instead.
57          */
58         VERIFY_PEER,
59         /**
60          * Requires peers provide a valid identifying certificate signed
61          * by a trusted certificate, including verifying hostname details
62          * of the certificate using peer details provided when configuring
63          * TLS via {@link Transport#ssl(SslDomain, SslPeerDetails)}.
64          */
65         VERIFY_PEER_NAME,
66         /**
67          * does not require a valid certificate, and permits use of ciphers that
68          * do not provide authentication
69          */
70         ANONYMOUS_PEER,
71     }
72 
73     /**
74      * Initialize the ssl domain object.
75      *
76      * An SSL object be either an SSL server or an SSL client. It cannot be both. Those
77      * transports that will be used to accept incoming connection requests must be configured
78      * as an SSL server. Those transports that will be used to initiate outbound connections
79      * must be configured as an SSL client.
80      *
81      */
82     void init(Mode mode);
83 
84     Mode getMode();
85 
86     /**
87      * Set the certificate that identifies the local node to the remote.
88      *
89      * This certificate establishes the identity for the local node. It will be sent to the
90      * remote if the remote needs to verify the identity of this node. This may be used for
91      * both SSL servers and SSL clients (if client authentication is required by the server).
92      *
93      * @param certificateFile path to file/database containing the identifying
94      * certificate.
95      * @param privateKeyFile path to file/database containing the private key used to
96      * sign the certificate
97      * @param password the password used to sign the key, else null if key is not
98      * protected.
99      */
100     void setCredentials(string certificateFile, string privateKeyFile, string password);
101 
102     string getPrivateKeyFile();
103 
104     string getPrivateKeyPassword();
105 
106     string getCertificateFile();
107 
108     /**
109      * Configure the set of trusted CA certificates used by this node to verify peers.
110      *
111      * If the local SSL client/server needs to verify the identity of the remote, it must
112      * validate the signature of the remote's certificate. This function sets the database of
113      * trusted CAs that will be used to verify the signature of the remote's certificate.
114      *
115      * @param certificateDb database of trusted CAs, used to authenticate the peer.
116      */
117     void setTrustedCaDb(string certificateDb);
118 
119     string getTrustedCaDb();
120 
121     /**
122      * Configure the level of verification used on the peer certificate.
123      *
124      * This method controls how the peer's certificate is validated, if at all. By default,
125      * neither servers nor clients attempt to verify their peers ({@link VerifyMode#ANONYMOUS_PEER}).
126      * Once certificates and trusted CAs are configured, peer verification can be enabled.
127      *
128      * In order to verify a peer, a trusted CA must be configured. See
129      * {@link #setTrustedCaDb(String)}.
130      *
131      * NOTE: Servers must provide their own certificate when verifying a peer. See
132      * {@link #setCredentials(String, String, String)}).
133      *
134      * @param mode the level of validation to apply to the peer
135      */
136     void setPeerAuthentication(VerifyMode mode);
137 
138     VerifyMode getPeerAuthentication();
139 
140     /**
141      * Permit a server to accept connection requests from non-SSL clients.
142      *
143      * This configures the server to "sniff" the incoming client data stream, and dynamically
144      * determine whether SSL/TLS is being used. This option is disabled by default: only
145      * clients using SSL/TLS are accepted.
146      */
147     void allowUnsecuredClient(bool allowUnsecured);
148 
149     bool allowUnsecuredClient();
150 
151     /**
152      * Sets an SSLContext for use when establishing SSL transport. Setting a context this way overrides alternate
153      * configuration that might otherwise have been used to create a context, such as key and trust store paths.
154      *
155      *@param sslContext the context to use
156      */
157     //TODO
158    // void setSslContext(SSLContext sslContext);
159 
160     /**
161      * Returns the SSLContext set by {@link #setSslContext(SSLContext)}.
162      *
163      * @return the SSLContext, or null if none was set.
164      */
165     //TODO
166    // SSLContext getSslContext();
167 }