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