1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.http;
20
21 import javax.net.ssl.HostnameVerifier;
22 import javax.net.ssl.SSLContext;
23
24 import java.util.Arrays;
25 import java.util.Objects;
26
27 import org.eclipse.aether.RepositorySystemSession;
28 import org.eclipse.aether.repository.AuthenticationContext;
29 import org.eclipse.aether.util.ConfigUtils;
30
31
32
33
34 final class SslConfig {
35
36 private static final String CIPHER_SUITES = "https.cipherSuites";
37
38 private static final String PROTOCOLS = "https.protocols";
39
40 final SSLContext context;
41
42 final HostnameVerifier verifier;
43
44 final String[] cipherSuites;
45
46 final String[] protocols;
47
48 final String httpsSecurityMode;
49
50 SslConfig(RepositorySystemSession session, AuthenticationContext authContext, String httpsSecurityMode) {
51 context = (authContext != null) ? authContext.get(AuthenticationContext.SSL_CONTEXT, SSLContext.class) : null;
52 verifier = (authContext != null)
53 ? authContext.get(AuthenticationContext.SSL_HOSTNAME_VERIFIER, HostnameVerifier.class)
54 : null;
55
56 cipherSuites = split(get(session, CIPHER_SUITES));
57 protocols = split(get(session, PROTOCOLS));
58 this.httpsSecurityMode = httpsSecurityMode;
59 }
60
61 private static String get(RepositorySystemSession session, String key) {
62 String value = ConfigUtils.getString(session, null, "aether.connector." + key, key);
63 if (value == null) {
64 value = System.getProperty(key);
65 }
66 return value;
67 }
68
69 private static String[] split(String value) {
70 if (value == null || value.isEmpty()) {
71 return null;
72 }
73 return value.split(",+");
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null || !getClass().equals(obj.getClass())) {
82 return false;
83 }
84 SslConfig that = (SslConfig) obj;
85 return Objects.equals(context, that.context)
86 && Objects.equals(verifier, that.verifier)
87 && Arrays.equals(cipherSuites, that.cipherSuites)
88 && Arrays.equals(protocols, that.protocols);
89 }
90
91 @Override
92 public int hashCode() {
93 int hash = 17;
94 hash = hash * 31 + hash(context);
95 hash = hash * 31 + hash(verifier);
96 hash = hash * 31 + Arrays.hashCode(cipherSuites);
97 hash = hash * 31 + Arrays.hashCode(protocols);
98 return hash;
99 }
100
101 private static int hash(Object obj) {
102 return obj != null ? obj.hashCode() : 0;
103 }
104 }