1
1
package com .yoti .mobile .android .sdk .kernelSDK ;
2
2
3
- import android .content .Context ;
4
3
import android .support .annotation .NonNull ;
5
4
6
5
import com .yoti .mobile .android .sdk .YotiSDKLogger ;
7
- import com .yoti .mobile .android .sdk .model .CustomCertificate ;
8
6
import com .yoti .mobile .android .sdk .model .Scenario ;
9
7
10
8
import java .io .ByteArrayOutputStream ;
11
9
import java .io .IOException ;
12
10
import java .io .InputStream ;
13
11
import java .net .URL ;
14
- import java .security .KeyManagementException ;
15
- import java .security .KeyStore ;
16
- import java .security .KeyStoreException ;
17
- import java .security .NoSuchAlgorithmException ;
18
- import java .security .cert .CertificateException ;
19
12
20
13
import javax .net .ssl .HttpsURLConnection ;
21
- import javax .net .ssl .SSLContext ;
22
- import javax .net .ssl .SSLSocketFactory ;
23
- import javax .net .ssl .TrustManagerFactory ;
24
14
25
15
public class KernelSDK {
26
16
27
- private final Context mContext ;
28
- private final CertificateManager mCertMgr ;
29
-
30
- public KernelSDK (Context context ) {
31
- mContext = context ;
32
-
33
- mCertMgr = new CertificateManager (mContext );
34
- }
35
-
36
17
/**
37
18
* Will make a call to the Yoti Connect API to retrieve the Uri for the provided Scenario
38
19
*
39
20
* @param currentScenario
40
21
* @return the uri of the provided scenario to forward to the Yoti app
41
- * @throws CertificateException
42
- * @throws NoSuchAlgorithmException
43
- * @throws KeyStoreException
44
- * @throws KeyManagementException
45
22
* @throws IOException
46
23
*/
47
- public String retrieveScenarioUri (Scenario currentScenario ) throws CertificateException , NoSuchAlgorithmException , KeyStoreException , KeyManagementException , IOException {
24
+ public String retrieveScenarioUri (Scenario currentScenario ) throws IOException {
48
25
49
26
URL url = new URL (String .format (EnvironmentConfiguration .GET_QR_CODE_URL , currentScenario .getClientSDKId (), currentScenario .getScenarioId ()));
50
27
@@ -66,21 +43,10 @@ public String retrieveScenarioUri(Scenario currentScenario) throws CertificateEx
66
43
public void processShareResult (@ NonNull Scenario currentScenario , @ NonNull ICallbackBackendListener listener ) {
67
44
68
45
try {
69
-
70
46
URL url = new URL (currentScenario .getCallbackBackendUrl ());
71
47
72
- CustomCertificate certificate = currentScenario .getCustomCertificate ();
73
48
HttpsURLConnection urlConnection = (HttpsURLConnection ) url .openConnection ();
74
49
75
- if (certificate != null ) {
76
- mCertMgr .storeCrt (certificate .getCertificateResourceId (),
77
- certificate .getStoreName (),
78
- certificate .getPassword (),
79
- certificate .getAlias ());
80
-
81
- urlConnection .setSSLSocketFactory (getSslSocketFactory (certificate .getStoreName (), certificate .getPassword ()));
82
- }
83
-
84
50
int statusCode = urlConnection .getResponseCode ();
85
51
86
52
byte [] response = getBytes (urlConnection );
@@ -95,7 +61,7 @@ public void processShareResult(@NonNull Scenario currentScenario, @NonNull ICall
95
61
YotiSDKLogger .warning ("ICallbackBackendListener is null" );
96
62
}
97
63
98
- } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e ) {
64
+ } catch (IOException e ) {
99
65
if (listener != null ) {
100
66
listener .onError (-1 , e , null );
101
67
} else {
@@ -104,36 +70,6 @@ public void processShareResult(@NonNull Scenario currentScenario, @NonNull ICall
104
70
}
105
71
}
106
72
107
- /**
108
- * return a SSlSocketFactory for the provided store name
109
- *
110
- * @param storeName
111
- * @param storePassword
112
- * @return
113
- * @throws KeyStoreException
114
- * @throws IOException
115
- * @throws NoSuchAlgorithmException
116
- * @throws CertificateException
117
- * @throws KeyManagementException
118
- */
119
- private SSLSocketFactory getSslSocketFactory (String storeName , String storePassword ) throws KeyStoreException , IOException , NoSuchAlgorithmException , CertificateException , KeyManagementException {
120
-
121
- KeyStore keyStore = KeyStore .getInstance (KeyStore .getDefaultType ());
122
- InputStream fos = mCertMgr .getKeyStoreAr (storeName );
123
- keyStore .load (fos , storePassword .toCharArray ());
124
-
125
- // Create a TrustManager that trusts the CAs in our KeyStore
126
- String tmfAlgorithm = TrustManagerFactory .getDefaultAlgorithm ();
127
- TrustManagerFactory tmf = TrustManagerFactory .getInstance (tmfAlgorithm );
128
- tmf .init (keyStore );
129
-
130
- // Create an SSLContext that uses our TrustManager
131
- SSLContext sslContext = SSLContext .getInstance ("TLS" );
132
- sslContext .init (null , tmf .getTrustManagers (), null );
133
-
134
- return sslContext .getSocketFactory ();
135
- }
136
-
137
73
/**
138
74
* read bytes from a UrlConnection
139
75
*
0 commit comments