Skip to content

Commit 6dd5340

Browse files
author
ehowlsla
committed
통계 암호화 로직 추가
1 parent b5ae4b8 commit 6dd5340

File tree

8 files changed

+177
-27
lines changed

8 files changed

+177
-27
lines changed

bootpay/src/main/java/kr/co/bootpay/BootpayAnalytics.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public static void login(
131131
}
132132

133133

134-
public static void start() {
135-
start(new ArrayList<StatItem>());
134+
public static void start(String url, String page_type) {
135+
start(url, page_type, new ArrayList<StatItem>());
136136
}
137137

138-
public static void start(@NonNull List<StatItem> items) {
138+
public static void start(String url, String page_type, @NonNull List<StatItem> items) {
139139
if (presenter == null) throw new IllegalStateException("Analytics is not initialized.");
140-
else presenter.call(items);
140+
else presenter.call(url, page_type, items);
141141
}
142142
}
143143

bootpay/src/main/java/kr/co/bootpay/BootpayWebView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import java.net.URISyntaxException
2424
internal class BootpayWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0): WebView(context, attrs, defStyleAttr) {
2525

2626
companion object {
27-
private const val BOOTPAY = "https://inapp.bootpay.co.kr/2.0.5/production.html"
27+
private const val BOOTPAY = "https://inapp.bootpay.co.kr/2.0.6/production.html"
2828

2929
private const val ERROR = -2
3030

bootpay/src/main/java/kr/co/bootpay/analytics/BootpayAnalyticsPresenter.kt

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package kr.co.bootpay.analytics
22

33
import android.content.Context
44
import android.util.Log
5+
import com.google.gson.Gson
6+
import kr.co.bootpay.model.StatCall
57
import kr.co.bootpay.model.StatItem
8+
import kr.co.bootpay.model.StatLogin
69
import kr.co.bootpay.pref.UserInfo
10+
import kr.co.bootpay.secure.BootpaySimpleAES256
711
import rx.Scheduler
812
import rx.schedulers.Schedulers
913
import java.util.concurrent.Executors
@@ -21,29 +25,53 @@ internal class BootpayAnalyticsPresenter(context: Context) {
2125
birth: String?,
2226
phone: String?,
2327
area: String?) {
24-
rest.api.login(
28+
29+
val login = StatLogin(
30+
"2.0.6",
2531
UserInfo.bootpay_application_id,
2632
id ?: "",
2733
email ?: "",
2834
username ?: "",
2935
if (gender?.trim()?.isEmpty() != false) -1 else gender.toInt(),
3036
birth ?: "",
3137
phone ?:"",
32-
area ?: "")
38+
area ?: ""
39+
)
40+
val json = Gson().toJson(login)
41+
val aes = BootpaySimpleAES256()
42+
43+
44+
45+
rest.api.login(
46+
aes.strEncode(json),
47+
aes.sessionKey)
3348
.subscribeOn(executor)
3449
.subscribe({
3550
UserInfo.bootpay_user_id = it.data?.user_id ?: ""
3651
}, Throwable::printStackTrace)
3752
}
3853

39-
fun call(items: MutableList<StatItem>) {
40-
rest.api.call(
54+
fun call(url: String, page_type: String, items: MutableList<StatItem>) {
55+
56+
val call = StatCall(
57+
"2.0.6",
4158
UserInfo.bootpay_application_id,
4259
UserInfo.bootpay_uuid,
60+
url,
61+
page_type,
4362
items,
4463
UserInfo.bootpay_sk,
4564
UserInfo.bootpay_user_id,
46-
"")
65+
""
66+
)
67+
68+
val json = Gson().toJson(call)
69+
val aes = BootpaySimpleAES256()
70+
71+
72+
rest.api.call(
73+
aes.strEncode(json),
74+
aes.sessionKey)
4775
.subscribeOn(executor)
4876
.subscribe({
4977
Log.d("BootpayAnalytics", "call")
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package kr.co.bootpay.analytics
22

3-
import kr.co.bootpay.model.StatItem
43
import retrofit2.http.Field
54
import retrofit2.http.FormUrlEncoded
65
import retrofit2.http.POST
@@ -10,25 +9,35 @@ internal interface RestApi {
109
@FormUrlEncoded
1110
@POST("/login")
1211
fun login(
13-
@Field("application_id") applicationId: String,
14-
@Field("id") userId: String,
15-
@Field("email") email: String,
16-
@Field("username") userName: String,
17-
@Field("gender") gender: Int,
18-
@Field("birth") birth: String,
19-
@Field("phone") phone: String,
20-
@Field("area") area: String
12+
@Field("data") data: String,
13+
@Field("session_key") sessionKey: String
2114
): Observable<LoginResult>
15+
// fun login(
16+
// @Field("application_id") applicationId: String,
17+
// @Field("id") userId: String,
18+
// @Field("email") email: String,
19+
// @Field("username") userName: String,
20+
// @Field("gender") gender: Int,
21+
// @Field("birth") birth: String,
22+
// @Field("phone") phone: String,
23+
// @Field("area") area: String
24+
// ): Observable<LoginResult>
2225

2326
@FormUrlEncoded
2427
@POST("/call")
2528
fun call(
26-
@Field("application_id") applicationId: String,
27-
@Field("uuid") uuid: String,
28-
@Field("items") items: MutableList<StatItem>,
29-
@Field("sk") sk: String,
30-
@Field("user_id") userId: String,
31-
@Field("referer") referer: String
29+
@Field("data") data: String,
30+
@Field("session_key") sessionKey: String
3231
): Observable<LoginResult>
32+
// fun call(
33+
// @Field("application_id") applicationId: String,
34+
// @Field("uuid") uuid: String,
35+
// @Field("url") url: String,
36+
// @Field("page_type") pageType: String,
37+
// @Field("items") items: String,
38+
// @Field("sk") sk: String,
39+
// @Field("user_id") userId: String,
40+
// @Field("referer") referer: String
41+
// ): Observable<LoginResult>
3342

3443
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kr.co.bootpay.model
2+
3+
class StatCall(
4+
val ver: String,
5+
val application_id: String,
6+
val uuid: String,
7+
val url: String,
8+
val page_type: String,
9+
val items: List<StatItem>,
10+
val sk: String,
11+
val user_id: String,
12+
val referer: String
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kr.co.bootpay.model
2+
3+
class StatLogin(
4+
val ver: String,
5+
val application_id: String,
6+
val id: String,
7+
val email: String,
8+
val username: String,
9+
val gender: Int,
10+
val birth: String,
11+
val phone: String,
12+
val area: String
13+
)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package kr.co.bootpay.secure;
2+
3+
import android.util.Base64;
4+
import android.util.Log;
5+
6+
import java.security.InvalidAlgorithmParameterException;
7+
import java.security.InvalidKeyException;
8+
import java.security.NoSuchAlgorithmException;
9+
import java.security.spec.AlgorithmParameterSpec;
10+
import java.util.Random;
11+
12+
import javax.crypto.BadPaddingException;
13+
import javax.crypto.Cipher;
14+
import javax.crypto.IllegalBlockSizeException;
15+
import javax.crypto.NoSuchPaddingException;
16+
import javax.crypto.spec.IvParameterSpec;
17+
import javax.crypto.spec.SecretKeySpec;
18+
19+
20+
public class BootpaySimpleAES256 {
21+
// public static byte[] ivBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
22+
23+
String key = "";
24+
String iv = "";
25+
26+
public BootpaySimpleAES256() {
27+
this.key = getRandomKey(32);
28+
this.iv = getRandomKey(16);
29+
}
30+
31+
public String getSessionKey() {
32+
String baseKey = Base64.encodeToString(this.key.getBytes(), 2);
33+
String baseIV = Base64.encodeToString(this.iv.getBytes(), 2);
34+
return baseKey + "##" + baseIV;
35+
}
36+
37+
38+
public String strEncode(String str) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
39+
// String key = getRandomKey(32);
40+
// String iv = getRandomKey(16);
41+
Log.d("aes", this.key);
42+
Log.d("aes", this.iv);
43+
return strEncode(str, this.key, this.iv);
44+
}
45+
46+
47+
public String strEncode(String str, String key, String iv) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
48+
49+
byte[] textBytes = str.getBytes("UTF-8");
50+
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
51+
SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
52+
Cipher cipher = null;
53+
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
54+
cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec);
55+
return Base64.encodeToString(cipher.doFinal(textBytes), 2);
56+
}
57+
58+
59+
public String strDecode(String str, String key, String iv) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
60+
61+
// byte[] textBytes = Base64.decodeBase64(str);
62+
byte[] textBytes = Base64.decode(str, Base64.NO_WRAP);
63+
64+
//byte[] textBytes = str.getBytes("UTF-8");
65+
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
66+
SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
67+
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
68+
cipher.init(Cipher.DECRYPT_MODE, newKey, ivSpec);
69+
return new String(cipher.doFinal(textBytes), "UTF-8");
70+
}
71+
72+
private static String getRandomKey(int size) {
73+
String result = "";
74+
String keys = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
75+
for(int i=0; i<size; i++) {
76+
Random ran = new Random();
77+
result += String.valueOf(keys.charAt(ran.nextInt(keys.length())));
78+
}
79+
return result;
80+
}
81+
}

sample/src/main/java/bootpay/co/kr/samplepayment/MainActivity.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ protected void onCreate(Bundle savedInstanceState) {
4242
"861014", // user 생년월일 앞자리
4343
"01012345678", // user 휴대폰 번호
4444
"충청"); // 서울|인천|대구|대전|광주|부산|울산|경기|강원|충청북도|충북|충청남도|충남|전라북도|전북|전라남도|전남|경상북도|경북|경상남도|경남|제주|세종 중 택 1
45+
46+
startTrace();
4547
}
4648

47-
public void onClick_request(View v) {
49+
public void startTrace() {
50+
4851
// 통계 - 페이지 추적
4952
List<StatItem> items = new ArrayList<>();
5053
items.add(new StatItem("마우스", "https://image.mouse.com/1234", "ITEM_CODE_MOUSE", "", "", ""));
5154
items.add(new StatItem("키보드", "https://image.keyboard.com/12345", "ITEM_CODE_KEYBOARD", "패션", "여성상의", "블라우스"));
52-
BootpayAnalytics.start(items);
55+
BootpayAnalytics.start("ItemListActivity", "item_list", items);
56+
}
57+
58+
public void onClick_request(View v) {
5359

5460
// 결제호출
5561
Bootpay.init(getFragmentManager())

0 commit comments

Comments
 (0)