-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEs11FunctionImpl.java
More file actions
116 lines (108 loc) · 6.02 KB
/
Es11FunctionImpl.java
File metadata and controls
116 lines (108 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.eastcompeace.lpa.sdk;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eastcompeace.lpa.sdk.bean.es11.Es11AuthenticateClientBean;
import com.eastcompeace.lpa.sdk.bean.es11.EventEntry;
import com.eastcompeace.lpa.sdk.bean.es9.InitiateAuthenticationBean;
import com.eastcompeace.lpa.sdk.http.CallBack;
import com.eastcompeace.lpa.sdk.http.HttpManager;
import com.eastcompeace.lpa.sdk.http.HttpResponseUtils;
import com.eastcompeace.lpa.sdk.log.ELog;
import com.eastcompeace.lpa.sdk.utils.AppConfig;
import com.eastcompeace.lpa.sdk.utils.Base64Android;
import com.eastcompeace.lpa.sdk.utils.StringUtils;
import java.util.ArrayList;
public class Es11FunctionImpl {
private static final String TAG = "es11FunctionImpl";
private static final String USER_AGENT = "gsma-rsp-lpad";
private static final String X_ADMIN_PROTOCOL = "gsma/rsp/v2.2.2";
private static volatile Es11FunctionImpl es11FunctionImpl;
private String smdsAddress;
private String smdsAddressHttp;
public static Es11FunctionImpl getInstance() {
if (es11FunctionImpl == null) {
synchronized (Es11FunctionImpl.class) {
if (es11FunctionImpl == null) {
es11FunctionImpl = new Es11FunctionImpl();
}
}
}
return es11FunctionImpl;
}
public Es11FunctionImpl smdsAddress(String str) {
this.smdsAddressHttp = AppConfig.filterUrl(str);
this.smdsAddress = str;
return this;
}
public void initiateAuthentication(String str, String str2, final CallBack callBack) {
new HttpManager.Builder().url(this.smdsAddressHttp + "/gsma/rsp2/es11/initiateAuthentication").postBody().addHeader("user-agent", USER_AGENT).addHeader("x-admin-protocol", X_ADMIN_PROTOCOL).addParams("euiccChallenge", str).addParams("euiccInfo1", str2).addParams("smdsAddress", this.smdsAddress).build().asyncExecute(new CallBack<JSONObject>() {
public void onSuccess(JSONObject jSONObject) {
try {
if (HttpResponseUtils.isExecutedSucess(jSONObject)) {
InitiateAuthenticationBean initiateAuthenticationBean = new InitiateAuthenticationBean();
initiateAuthenticationBean.setTransactionId(jSONObject.getString("transactionId"));
String string = jSONObject.getString("serverSigned1");
if (!StringUtils.isEmpty(string)) {
initiateAuthenticationBean.setServerSigned1(Base64Android.decode(string, 0));
}
String string2 = jSONObject.getString("serverSignature1");
if (!StringUtils.isEmpty(string2)) {
initiateAuthenticationBean.setServerSignature1(Base64Android.decode(string2, 0));
}
String string3 = jSONObject.getString("euiccCiPKIdToBeUsed");
if (!StringUtils.isEmpty(string3)) {
initiateAuthenticationBean.setEuiccCiPKIdTobeUsed(Base64Android.decode(string3, 0));
}
String string4 = jSONObject.getString("serverCertificate");
if (!StringUtils.isEmpty(string4)) {
initiateAuthenticationBean.setServerCertificate(Base64Android.decode(string4, 0));
}
callBack.onSuccess(initiateAuthenticationBean);
return;
}
callBack.onError(new Exception(""));
} catch (Exception e) {
ELog.e(Es11FunctionImpl.TAG, "initiateAuthentication onSuccess: ", e);
callBack.onError(e);
}
}
public void onError(Exception exc) {
callBack.onError(exc);
}
});
}
public void authenticateClient(String str, String str2, final CallBack callBack) {
new HttpManager.Builder().url(this.smdsAddressHttp + "/gsma/rsp2/es11/authenticateClient").postBody().addHeader("user-agent", USER_AGENT).addHeader("x-admin-protocol", X_ADMIN_PROTOCOL).addParams("transactionId", str).addParams("authenticateServerResponse", str2).build().asyncExecute(new CallBack<JSONObject>() {
public void onSuccess(JSONObject jSONObject) {
int size;
try {
if (HttpResponseUtils.isExecutedSucess(jSONObject)) {
Es11AuthenticateClientBean es11AuthenticateClientBean = new Es11AuthenticateClientBean();
es11AuthenticateClientBean.setTransactionId(jSONObject.getString("transactionId"));
JSONArray jSONArray = jSONObject.getJSONArray("eventEntries");
if (jSONArray != null && (size = jSONArray.size()) > 0) {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < size; i++) {
JSONObject jSONObject2 = jSONArray.getJSONObject(i);
EventEntry eventEntry = new EventEntry();
eventEntry.setEventId(jSONObject2.getString("eventId"));
eventEntry.setRspServerAddress(jSONObject2.getString("rspServerAddress"));
arrayList.add(eventEntry);
}
es11AuthenticateClientBean.setEventEntries(arrayList);
}
callBack.onSuccess(es11AuthenticateClientBean);
return;
}
callBack.onError(new Exception(""));
} catch (Exception e) {
ELog.e(Es11FunctionImpl.TAG, "authenticateClient onSuccess: ", e);
callBack.onError(e);
}
}
public void onError(Exception exc) {
callBack.onError(exc);
}
});
}
}