1 /* 2 * Copyright (C) 2016 The Android Open Source Project 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 * http://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 com.android.server.wifi.hotspot2; 18 19 import android.content.Context; 20 import android.net.wifi.hotspot2.PasspointConfiguration; 21 22 import com.android.org.conscrypt.TrustManagerImpl; 23 import com.android.server.wifi.Clock; 24 import com.android.server.wifi.SIMAccessor; 25 import com.android.server.wifi.WifiKeyStore; 26 import com.android.server.wifi.WifiNative; 27 28 import java.security.KeyStore; 29 import java.security.NoSuchAlgorithmException; 30 31 import javax.net.ssl.SSLContext; 32 33 /** 34 * Factory class for creating Passpoint related objects. Useful for mocking object creations 35 * in the unit tests. 36 */ 37 public class PasspointObjectFactory{ 38 /** 39 * Create a PasspointEventHandler instance. 40 * 41 * @param wifiNative Instance of {@link WifiNative} 42 * @param callbacks Instance of {@link PasspointEventHandler.Callbacks} 43 * @return {@link PasspointEventHandler} 44 */ 45 public PasspointEventHandler makePasspointEventHandler(WifiNative wifiNative, 46 PasspointEventHandler.Callbacks callbacks) { 47 return new PasspointEventHandler(wifiNative, callbacks); 48 } 49 50 /** 51 * Create a PasspointProvider instance. 52 * 53 * @param keyStore Instance of {@link WifiKeyStore} 54 * @param config Configuration for the provider 55 * @param providerId Unique identifier for the provider 56 * @return {@link PasspointProvider} 57 */ 58 public PasspointProvider makePasspointProvider(PasspointConfiguration config, 59 WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid) { 60 return new PasspointProvider(config, keyStore, simAccessor, providerId, creatorUid); 61 } 62 63 /** 64 * Create a {@link PasspointConfigStoreData} instance. 65 * 66 * @param keyStore Instance of {@link WifiKeyStore} 67 * @param simAccessor Instance of {@link SIMAccessor} 68 * @param dataSource Passpoint configuration data source 69 * @return {@link PasspointConfigStoreData} 70 */ 71 public PasspointConfigStoreData makePasspointConfigStoreData(WifiKeyStore keyStore, 72 SIMAccessor simAccessor, PasspointConfigStoreData.DataSource dataSource) { 73 return new PasspointConfigStoreData(keyStore, simAccessor, dataSource); 74 } 75 76 /** 77 * Create a AnqpCache instance. 78 * 79 * @param clock Instance of {@link Clock} 80 * @return {@link AnqpCache} 81 */ 82 public AnqpCache makeAnqpCache(Clock clock) { 83 return new AnqpCache(clock); 84 } 85 86 /** 87 * Create an instance of {@link ANQPRequestManager}. 88 * 89 * @param handler Instance of {@link PasspointEventHandler} 90 * @param clock Instance of {@link Clock} 91 * @return {@link ANQPRequestManager} 92 */ 93 public ANQPRequestManager makeANQPRequestManager(PasspointEventHandler handler, Clock clock) { 94 return new ANQPRequestManager(handler, clock); 95 } 96 97 /** 98 * Create an instance of {@link CertificateVerifier}. 99 * 100 * @return {@link CertificateVerifier} 101 */ 102 public CertificateVerifier makeCertificateVerifier() { 103 return new CertificateVerifier(); 104 } 105 106 /** 107 * Create an instance of {@link PasspointProvisioner}. 108 * 109 * @param context 110 * @return {@link PasspointProvisioner} 111 */ 112 public PasspointProvisioner makePasspointProvisioner(Context context) { 113 return new PasspointProvisioner(context, this); 114 } 115 116 /** 117 * Create an instance of {@link OsuNetworkConnection}. 118 * 119 * @param context 120 * @return {@link OsuNetworkConnection} 121 */ 122 public OsuNetworkConnection makeOsuNetworkConnection(Context context) { 123 return new OsuNetworkConnection(context); 124 } 125 126 /** 127 * Create an instance of {@link OsuServerConnection}. 128 * 129 * @return {@link OsuServerConnection} 130 */ 131 public OsuServerConnection makeOsuServerConnection() { 132 return new OsuServerConnection(); 133 } 134 135 136 /** 137 * Create an instance of {@link WfaKeyStore}. 138 * 139 * @return WfaKeyStore {@link WfaKeyStore} 140 */ 141 public WfaKeyStore makeWfaKeyStore() { 142 return new WfaKeyStore(); 143 } 144 145 /** 146 * Create an instance of {@link SSLContext}. 147 * 148 * @param tlsVersion String indicate TLS version 149 * @return SSLContext an instance, corresponding to the TLS version 150 */ 151 public SSLContext getSSLContext(String tlsVersion) { 152 SSLContext tlsContext = null; 153 try { 154 tlsContext = SSLContext.getInstance(tlsVersion); 155 } catch (NoSuchAlgorithmException e) { 156 e.printStackTrace(); 157 } 158 return tlsContext; 159 } 160 161 /** 162 * Create an instance of {@link TrustManagerImpl}. 163 * 164 * @param ks KeyStore used to get root certs 165 * @return TrustManagerImpl an instance for delegating root cert validation 166 */ 167 public TrustManagerImpl getTrustManagerImpl(KeyStore ks) { 168 return new TrustManagerImpl(ks); 169 } 170 } 171