View Javadoc
1   /*
2    * Copyright 2019-2021 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package nl.altindag.ssl.model;
18  
19  import javax.net.ssl.HostnameVerifier;
20  import javax.net.ssl.SSLContext;
21  import javax.net.ssl.SSLParameters;
22  import java.util.List;
23  
24  /**
25   * <p>
26   * <strong>NOTE:</strong>
27   * Please don't use this class directly as it is part of the internal API. Class name and methods can be changed any time.
28   * </p>
29   *
30   * @author Hakan Altindag
31   */
32  public final class SSLMaterial {
33  
34      private SSLContext sslContext;
35      private IdentityMaterial identityMaterial;
36      private TrustMaterial trustMaterial;
37      private HostnameVerifier hostnameVerifier;
38      private SSLParameters sslParameters;
39      private List<String> ciphers;
40      private List<String> protocols;
41  
42      private SSLMaterial() {}
43  
44      public SSLContext getSslContext() {
45          return sslContext;
46      }
47  
48      public IdentityMaterial getIdentityMaterial() {
49          return identityMaterial;
50      }
51  
52      public TrustMaterial getTrustMaterial() {
53          return trustMaterial;
54      }
55  
56      public SSLParameters getSslParameters() {
57          return sslParameters;
58      }
59  
60      public HostnameVerifier getHostnameVerifier() {
61          return hostnameVerifier;
62      }
63  
64      public List<String> getCiphers() {
65          return ciphers;
66      }
67  
68      public List<String> getProtocols() {
69          return protocols;
70      }
71  
72      public static class Builder {
73  
74          private SSLContext sslContext;
75          private IdentityMaterial identityMaterial;
76          private TrustMaterial trustMaterial;
77          private HostnameVerifier hostnameVerifier;
78          private SSLParameters sslParameters;
79          private List<String> ciphers;
80          private List<String> protocols;
81  
82          public Builder withSslContext(SSLContext sslContext) {
83              this.sslContext = sslContext;
84              return this;
85          }
86  
87          public Builder withHostnameVerifier(HostnameVerifier hostnameVerifier) {
88              this.hostnameVerifier = hostnameVerifier;
89              return this;
90          }
91  
92          public Builder withSslParameters(SSLParameters sslParameters) {
93              this.sslParameters = sslParameters;
94              return this;
95          }
96  
97          public Builder withCiphers(List<String> ciphers) {
98              this.ciphers = ciphers;
99              return this;
100         }
101 
102         public Builder withProtocols(List<String> protocols) {
103             this.protocols = protocols;
104             return this;
105         }
106 
107         public Builder withIdentityMaterial(IdentityMaterial identityMaterial) {
108             this.identityMaterial = identityMaterial;
109             return this;
110         }
111 
112         public Builder withTrustMaterial(TrustMaterial trustMaterial) {
113             this.trustMaterial = trustMaterial;
114             return this;
115         }
116 
117         public SSLMaterial build() {
118             SSLMaterial sslMaterial = new SSLMaterial();
119             sslMaterial.sslContext = sslContext;
120             sslMaterial.identityMaterial = identityMaterial;
121             sslMaterial.trustMaterial = trustMaterial;
122             sslMaterial.hostnameVerifier = hostnameVerifier;
123             sslMaterial.sslParameters = sslParameters;
124             sslMaterial.ciphers = ciphers;
125             sslMaterial.protocols = protocols;
126             return sslMaterial;
127         }
128     }
129 
130 }