Skip to content

Commit

Permalink
新增功能: 新增弹弹API签名验证拦截器
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyy committed Jan 22, 2025
1 parent 365e24b commit c6ba9d3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Binary file modified common_component/libs/arm64-v8a/libsecurity.so
Binary file not shown.
Binary file modified common_component/libs/armeabi-v7a/libsecurity.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.xyoye.common_component.network.helper.BackupDomainInterceptor
import com.xyoye.common_component.network.helper.DecompressInterceptor
import com.xyoye.common_component.network.helper.DynamicBaseUrlInterceptor
import com.xyoye.common_component.network.helper.LoggerInterceptor
import com.xyoye.common_component.network.helper.SignatureInterceptor
import com.xyoye.common_component.network.service.AlistService
import com.xyoye.common_component.network.service.DanDanService
import com.xyoye.common_component.network.service.ExtendedService
Expand Down Expand Up @@ -43,6 +44,7 @@ class Retrofit private constructor() {
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(4, TimeUnit.SECONDS)
.hostnameVerifier { _, _ -> true }
.addInterceptor(SignatureInterceptor())
.addInterceptor(AgentInterceptor())
.addInterceptor(AuthInterceptor())
.addInterceptor(DecompressInterceptor())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.xyoye.common_component.network.helper

import com.xyoye.common_component.base.app.BaseApplication
import com.xyoye.common_component.utils.SecurityHelper
import okhttp3.Interceptor
import okhttp3.Response


/**
* author: [email protected]
* time : 2025/1/21
* desc : 签名验证拦截器
*/
class SignatureInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val oldRequest = chain.request()
val newRequest = oldRequest.newBuilder()

SecurityHelper.getInstance().getSignatureMap(
oldRequest.url.encodedPath,
BaseApplication.getAppContext()
).forEach {
newRequest.addHeader(it.key, it.value ?: "")
}

return chain.proceed(newRequest.build())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.xyoye.common_component.base.app.BaseApplication;

import java.util.HashMap;
import java.util.Map;

/**
* Created by xyoye on 2021/1/6.
*/
Expand Down Expand Up @@ -52,7 +55,32 @@ public Boolean isOfficialApplication() {
return !ERROR_RESULT.equals(getAppId());
}

public Map<String, String> getSignatureMap(String path, Context context) {
Object signature = getSignature(path, context);
if (signature == null) {
return null;
}

if (signature instanceof Map) {
HashMap<String, String> map = new HashMap<>();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) signature).entrySet()) {
Object key = entry.getKey();
if (key instanceof String) {
Object value = entry.getValue();
if (value instanceof String) {
map.put((String) key, (String) value);
}
}
}
return map;
}

return null;
}

private static native String getKey(int position, Context context);

private static native String buildHash(String hashInfo, Context context);

private static native Object getSignature(String path, Context context);
}

0 comments on commit c6ba9d3

Please sign in to comment.