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
24 import javax.net.ssl.HostnameVerifier;
25 import javax.net.ssl.SSLContext;
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
37 private static final String CIPHER_SUITES = "https.cipherSuites";
38
39 private static final String PROTOCOLS = "https.protocols";
40
41 final SSLContext context;
42
43 final HostnameVerifier verifier;
44
45 final String[] cipherSuites;
46
47 final String[] protocols;
48
49 SslConfig( RepositorySystemSession session, AuthenticationContext authContext )
50 {
51 context =
52 ( authContext != null ) ? authContext.get( AuthenticationContext.SSL_CONTEXT, SSLContext.class ) : null;
53 verifier =
54 ( authContext != null ) ? authContext.get( AuthenticationContext.SSL_HOSTNAME_VERIFIER,
55 HostnameVerifier.class ) : null;
56
57 cipherSuites = split( get( session, CIPHER_SUITES ) );
58 protocols = split( get( session, PROTOCOLS ) );
59 }
60
61 private static String get( RepositorySystemSession session, String key )
62 {
63 String value = ConfigUtils.getString( session, null, "aether.connector." + key, key );
64 if ( value == null )
65 {
66 value = System.getProperty( key );
67 }
68 return value;
69 }
70
71 private static String[] split( String value )
72 {
73 if ( value == null || value.length() <= 0 )
74 {
75 return null;
76 }
77 return value.split( ",+" );
78 }
79
80 @Override
81 public boolean equals( Object obj )
82 {
83 if ( this == obj )
84 {
85 return true;
86 }
87 if ( obj == null || !getClass().equals( obj.getClass() ) )
88 {
89 return false;
90 }
91 SslConfig that = (SslConfig) obj;
92 return eq( context, that.context ) && eq( verifier, that.verifier )
93 && Arrays.equals( cipherSuites, that.cipherSuites ) && Arrays.equals( protocols, that.protocols );
94 }
95
96 private static <T> boolean eq( T s1, T s2 )
97 {
98 return s1 != null ? s1.equals( s2 ) : s2 == null;
99 }
100
101 @Override
102 public int hashCode()
103 {
104 int hash = 17;
105 hash = hash * 31 + hash( context );
106 hash = hash * 31 + hash( verifier );
107 hash = hash * 31 + Arrays.hashCode( cipherSuites );
108 hash = hash * 31 + Arrays.hashCode( protocols );
109 return hash;
110 }
111
112 private static int hash( Object obj )
113 {
114 return obj != null ? obj.hashCode() : 0;
115 }
116
117 }