Debian Codegraph @

proton-j/src/main/java/org/apache/qpid/proton/engine/SslDomain.java

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