1 module hunt.net.ssl.SSLContextSpi;
2 
3 // dfmt off
4 version(WITH_HUNT_SECURITY):
5 // dfmt on
6 
7 // import hunt.net.ssl.KeyManager;
8 import hunt.net.ssl.SSLEngine;
9 import hunt.net.ssl.SSLSessionContext;
10 import hunt.net.ssl.SSLParameters;
11 
12 import hunt.net.KeyCertOptions;
13 
14 import hunt.Exceptions;
15 
16 /**
17  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
18  * for the <code>SSLContext</code> class.
19  *
20  * <p> All the abstract methods in this class must be implemented by each
21  * cryptographic service provider who wishes to supply the implementation
22  * of a particular SSL context.
23  *
24  * @see SSLContext
25  */
26 abstract class SSLContextSpi {
27     /**
28      * Initializes this context.
29      *
30      * @param km the sources of authentication keys
31      * @param tm the sources of peer authentication trust decisions
32      * @param sr the source of randomness
33      * @throws KeyManagementException if this operation fails
34      * @see SSLContext#init(KeyManager [], TrustManager [], SecureRandom)
35      */
36     // abstract void engineInit(KeyManager[] km, TrustManager[] tm) ;
37     
38     abstract void engineInit(KeyCertOptions options);
39 
40     /**
41      * Returns a <code>SocketFactory</code> object for this
42      * context.
43      *
44      * @return the <code>SocketFactory</code> object
45      * @throws IllegalStateException if the SSLContextImpl requires
46      *         initialization and the <code>engineInit()</code>
47      *         has not been called
48      */
49     // abstract SSLSocketFactory engineGetSocketFactory();
50 
51     /**
52      * Returns a <code>ServerSocketFactory</code> object for
53      * this context.
54      *
55      * @return the <code>ServerSocketFactory</code> object
56      * @throws IllegalStateException if the SSLContextImpl requires
57      *         initialization and the <code>engineInit()</code>
58      *         has not been called
59      */
60     // abstract SSLServerSocketFactory engineGetServerSocketFactory();
61 
62     /**
63      * Creates a new <code>SSLEngine</code> using this context.
64      * <P>
65      * Applications using this factory method are providing no hints
66      * for an internal session reuse strategy. If hints are desired,
67      * {@link #engineCreateSSLEngine(string, int)} should be used
68      * instead.
69      * <P>
70      * Some cipher suites (such as Kerberos) require remote hostname
71      * information, in which case this factory method should not be used.
72      *
73      * @return  the <code>SSLEngine</code> Object
74      * @throws IllegalStateException if the SSLContextImpl requires
75      *         initialization and the <code>engineInit()</code>
76      *         has not been called
77      *
78      * @see     SSLContext#createSSLEngine()
79      *
80      * @since   1.5
81      */
82     abstract SSLEngine engineCreateSSLEngine(bool clientMode);
83 
84     /**
85      * Creates a <code>SSLEngine</code> using this context.
86      * <P>
87      * Applications using this factory method are providing hints
88      * for an internal session reuse strategy.
89      * <P>
90      * Some cipher suites (such as Kerberos) require remote hostname
91      * information, in which case peerHost needs to be specified.
92      *
93      * @param host the non-authoritative name of the host
94      * @param port the non-authoritative port
95      * @return  the <code>SSLEngine</code> Object
96      * @throws IllegalStateException if the SSLContextImpl requires
97      *         initialization and the <code>engineInit()</code>
98      *         has not been called
99      *
100      * @see     SSLContext#createSSLEngine(string, int)
101      *
102      * @since   1.5
103      */
104     abstract SSLEngine engineCreateSSLEngine(bool clientMode, string host, int port);
105 
106     /**
107      * Returns a server <code>SSLSessionContext</code> object for
108      * this context.
109      *
110      * @return the <code>SSLSessionContext</code> object
111      */
112     abstract SSLSessionContext engineGetServerSessionContext();
113 
114     /**
115      * Returns a client <code>SSLSessionContext</code> object for
116      * this context.
117      *
118      * @return the <code>SSLSessionContext</code> object
119      */
120     abstract SSLSessionContext engineGetClientSessionContext();
121 
122     // private SSLSocket getDefaultSocket() {
123     //     implementationMissing(false);
124     //     return null;
125     //     // try {
126     //     //     SSLSocketFactory factory = engineGetSocketFactory();
127     //     //     return cast(SSLSocket)factory.createSocket();
128     //     // } catch (IOException e) {
129     //     //     throw new UnsupportedOperationException("Could not obtain parameters", e);
130     //     // }
131     // }
132 
133     /**
134      * Returns a copy of the SSLParameters indicating the default
135      * settings for this SSL context.
136      *
137      * <p>The parameters will always have the ciphersuite and protocols
138      * arrays set to non-null values.
139      *
140      * <p>The default implementation obtains the parameters from an
141      * SSLSocket created by calling the
142      * {@linkplain javax.net.SocketFactory#createSocket
143      * SocketFactory.createSocket()} method of this context's SocketFactory.
144      *
145      * @return a copy of the SSLParameters object with the default settings
146      * @throws UnsupportedOperationException if the default SSL parameters
147      *   could not be obtained.
148      *
149      */
150     // SSLParameters engineGetDefaultSSLParameters() {
151     //     SSLSocket socket = getDefaultSocket();
152     //     // return socket.getSSLParameters();
153     //     implementationMissing(false);
154     //     return null;
155     // }
156 
157     /**
158      * Returns a copy of the SSLParameters indicating the maximum supported
159      * settings for this SSL context.
160      *
161      * <p>The parameters will always have the ciphersuite and protocols
162      * arrays set to non-null values.
163      *
164      * <p>The default implementation obtains the parameters from an
165      * SSLSocket created by calling the
166      * {@linkplain javax.net.SocketFactory#createSocket
167      * SocketFactory.createSocket()} method of this context's SocketFactory.
168      *
169      * @return a copy of the SSLParameters object with the maximum supported
170      *   settings
171      * @throws UnsupportedOperationException if the supported SSL parameters
172      *   could not be obtained.
173      *
174      */
175     // SSLParameters engineGetSupportedSSLParameters() {
176     //     SSLSocket socket = getDefaultSocket();
177     //     SSLParameters params = new SSLParameters();
178     //     implementationMissing(false);
179     //     // params.setCipherSuites(socket.getSupportedCipherSuites());
180     //     // params.setProtocols(socket.getSupportedProtocols());
181     //     return params;
182     // }
183 
184 }
185 
186