View Javadoc
1   package org.eclipse.aether.transport.http;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * SSL-related configuration and cache key for connection pools (whose scheme registries are derived from this config).
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 }