1 module hunt.net.secure.conscrypt.AbstractConscryptEngine;
2 
3 // dfmt off
4 version(WITH_HUNT_SECURITY):
5 // dfmt on
6 
7 import hunt.net.secure.conscrypt.AllocatedBuffer;
8 import hunt.net.secure.conscrypt.ApplicationProtocolSelector;
9 import hunt.net.ssl;
10 
11 import hunt.io.ByteBuffer;
12 import hunt.Functions;
13 // import hunt.security.Key;
14 
15 alias HandshakeListener = Action;
16 
17 
18 /**
19  * Abstract base class for all Conscrypt {@link SSLEngine} classes.
20  */
21 abstract class AbstractConscryptEngine : SSLEngine {
22     // abstract void setBufferAllocator(BufferAllocator bufferAllocator);
23 
24     /**
25      * Returns the maximum overhead, in bytes, of sealing a record with SSL.
26      */
27     abstract int maxSealOverhead();
28 
29 //     /**
30 //      * Enables/disables TLS Channel ID for this server engine.
31 //      *
32 //      * <p>This method needs to be invoked before the handshake starts.
33 //      *
34 //      * @throws IllegalStateException if this is a client engine or if the handshake has already
35 //      *         started.
36 //      */
37 //     abstract void setChannelIdEnabled(bool enabled);
38 
39 //     /**
40 //      * Gets the TLS Channel ID for this server engine. Channel ID is only available once the
41 //      * handshake completes.
42 //      *
43 //      * @return channel ID or {@code null} if not available.
44 //      *
45 //      * @throws IllegalStateException if this is a client engine or if the handshake has not yet
46 //      * completed.
47 //      * @ if channel ID is available but could not be obtained.
48 //      */
49 //     abstract byte[] getChannelId() ;
50 
51     /**
52      * Sets the {@link PrivateKey} to be used for TLS Channel ID by this client engine.
53      *
54      * <p>This method needs to be invoked before the handshake starts.
55      *
56      * @param privateKey private key (enables TLS Channel ID) or {@code null} for no key (disables
57      *        TLS Channel ID). The private key must be an Elliptic Curve (EC) key based on the NIST
58      *        P-256 curve (aka SECG secp256r1 or ANSI X9.62 prime256v1).
59      *
60      * @throws IllegalStateException if this is a server engine or if the handshake has already
61      *         started.
62      */
63     // abstract void setChannelIdPrivateKey(PrivateKey privateKey);
64 
65     /**
66      * Sets the listener for the completion of the TLS handshake.
67      */
68     abstract void setHandshakeListener(HandshakeListener handshakeListener);
69 
70     /**
71      * This method enables Server Name Indication (SNI) and overrides the {@link PeerInfoProvider}
72      * supplied during engine creation.
73      */
74     abstract void setHostname(string hostname);
75 
76     /**
77      * Returns the hostname from {@link #setHostname(string)} or supplied by the
78      * {@link PeerInfoProvider} upon creation. No DNS resolution is attempted before
79      * returning the hostname.
80      */
81     abstract string getHostname();
82 
83     override abstract string getPeerHost();
84 
85     override abstract int getPeerPort();
86 
87 //     /* override */
88 //     @SuppressWarnings("MissingOverride") // For compilation with Java 6.
89 //     SSLSession getHandshakeSession() {
90 //         return handshakeSession();
91 //     }
92 
93     /**
94      * Work-around to allow this method to be called on older versions of Android.
95      */
96     abstract SSLSession handshakeSession();
97 
98     override
99     abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst);
100 
101     override
102     abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts);
103 
104     override
105     abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
106             int offset, int length) ;
107 
108     abstract SSLEngineResult unwrap(ByteBuffer[] srcs, ByteBuffer[] dsts);
109 
110     abstract SSLEngineResult unwrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength,
111             ByteBuffer[] dsts, int dstsOffset, int dstsLength);
112 
113     override
114     abstract SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst) ;
115 
116     override
117     abstract SSLEngineResult wrap(
118             ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer dst) ;
119 
120     /**
121      * This method enables session ticket support.
122      *
123      * @param useSessionTickets True to enable session tickets
124      */
125     abstract void setUseSessionTickets(bool useSessionTickets);
126 
127     /**
128      * Sets the list of ALPN protocols.
129      *
130      * @param protocols the list of ALPN protocols
131      */
132     abstract void setApplicationProtocols(string[] protocols);
133 
134     /**
135      * Returns the list of supported ALPN protocols.
136      */
137     abstract string[] getApplicationProtocols();
138 
139     abstract string getApplicationProtocol();
140 
141     abstract string getHandshakeApplicationProtocol();
142 
143 //     /**
144 //      * Sets an application-provided ALPN protocol selector. If provided, this will override
145 //      * the list of protocols set by {@link #setApplicationProtocols(string[])}.
146 //      */
147     abstract void setApplicationProtocolSelector(ApplicationProtocolSelector selector);
148 
149 //     /**
150 //      * Returns the tls-unique channel binding value for this connection, per RFC 5929.  This
151 //      * will return {@code null} if there is no such value available, such as if the handshake
152 //      * has not yet completed or this connection is closed.
153 //      */
154 //     abstract byte[] getTlsUnique();
155 
156 //     /**
157 //      * Enables token binding parameter negotiation on this engine, or disables it if an
158 //      * empty set of parameters are provided.
159 //      *
160 //      * <p>This method needs to be invoked before the handshake starts.
161 //      *
162 //      * @param params a list of Token Binding key parameters in descending order of preference,
163 //      * as described in draft-ietf-tokbind-negotiation-09.
164 //      * @throws IllegalStateException if the handshake has already started.
165 //      * @ if the setting could not be applied.
166 //      */
167 // //     abstract void setTokenBindingParams(int... params) ;
168 
169 //     /**
170 //      * Returns the token binding parameters that were negotiated during the handshake, or -1 if
171 //      * token binding parameters were not negotiated, the handshake has not yet completed,
172 //      * or the connection has been closed.
173 //      */
174 // //     abstract int getTokenBindingParams();
175 
176 //     /**
177 //      * Exports a value derived from the TLS master secret as described in RFC 5705.
178 //      *
179 //      * @param label the label to use in calculating the exported value.  This must be
180 //      * an ASCII-only string.
181 //      * @param context the application-specific context value to use in calculating the
182 //      * exported value.  This may be {@code null} to use no application context, which is
183 //      * treated differently than an empty byte array.
184 //      * @param length the number of bytes of keying material to return.
185 //      * @return a value of the specified length, or {@code null} if the handshake has not yet
186 //      * completed or the connection has been closed.
187 //      * @ if the value could not be exported.
188 //      */
189 //     abstract byte[] exportKeyingMaterial(string label, byte[] context, int length);
190 }