Skip to content

Commit

Permalink
Merge pull request #24 from lemondark/release/v4.5.0
Browse files Browse the repository at this point in the history
release: v4.5.0
  • Loading branch information
ilovetochangetheworld authored Jul 6, 2023
2 parents ce3ce30 + c014bd6 commit 629c728
Show file tree
Hide file tree
Showing 42 changed files with 704 additions and 2,816 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ add_library( # Sets the name of the library.
src/main/cpp/stack/NetworkStack.cpp
src/main/cpp/Jni.cpp
src/main/cpp/JniHelper.cpp
src/main/cpp/des/des.cpp
src/main/cpp/aes/aes.cpp
src/main/cpp/adapter/HttpDnsBridge.cpp
)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ DnsConfig dnsConfigBuilder = DnsConfig.Builder()
.dnsId("xxx")
//(必填)dns 解析 key,即授权 id 对应的 key(加密密钥),在申请 SDK 后的邮箱里,腾讯云官网(https://console.cloud.tencent.com/httpdns)申请获得,用于域名解析鉴权
.dnsKey("xxx")
//(必填)Channel为desHttp()或aesHttp()时使用 119.29.29.98(默认填写这个就行),channel为https()时使用 119.29.29.99
//(必填)[V4.5.0废弃]由sdk内部调度。Channel为desHttp()或aesHttp()时使用 119.29.29.98(默认填写这个就行),channel为https()时使用 119.29.29.99
.dnsIp("xxx")
//(可选)channel配置:基于 HTTP 请求的 DES 加密形式,默认为 desHttp(),另有 aesHttp()、https() 可选。(注意仅当选择 https 的 channel 需要选择 119.29.29.99 的dnsip并传入token,例如:.dnsIp('119.29.29.99').https().token('....') )。
.desHttp()
Expand All @@ -96,6 +96,8 @@ DnsConfig dnsConfigBuilder = DnsConfig.Builder()
.setUseExpiredIpEnable(true)
//(可选)[V4.3.0] 设置是否启用本地缓存(Room),默认false
.setCachedIpEnable(true)
// (可选)[V4.5.0] DNS 请求的 ECS(EDNS-Client-Subnet)值,默认情况下 HTTPDNS 服务器会查询客户端出口 IP 为 DNS 线路查询 IP,可以指定线路 IP 地址。支持 IPv4/IPv6 地址传入
.routeIp("XXX")
// 以build()结束
.build();

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
release {
minifyEnabled true
buildConfigField("String", "VERSION_NAME", "\"${project.subVersionName}a\"")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Expand Down
73 changes: 0 additions & 73 deletions src/main/cpp/Jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#include "JniHelper.h"
#include "stack/NetworkStack.h"
#include "des/des.h"
#include "aes/aes.h"
#include "adapter/HttpDnsBridge.h"

extern "C" JNIEXPORT int
Expand All @@ -21,77 +19,6 @@ Java_com_tencent_msdk_dns_base_jni_Jni_getNetworkStack(
return self_dns::NetworkStack::get();
}

JNIEXPORT jbyteArray JNICALL
Java_com_tencent_msdk_dns_base_jni_Jni_desCrypt(JNIEnv *env,
jclass cls,
jbyteArray _src,
jstring _key,
jint mode) {
(void)cls;

unsigned char *src = nullptr;
std::size_t srcLen = 0;
unsigned char *output = nullptr;
unsigned int outLen = 0;
self_dns::JniHelper::JbyteArray2byteArray(env, _src, &src, &srcLen);
std::string key = self_dns::JniHelper::Jstring2String(env, _key);

self_dns::des_crypt(src, srcLen, (const unsigned char *) key.c_str(), mode, &output, &outLen);
jbyteArray jarray = nullptr;
if (output != nullptr && outLen > 0) {
self_dns::JniHelper::ClearEnvException(env);
jarray = env->NewByteArray(outLen);
jbyte *bytes = (jbyte *)output;
env->SetByteArrayRegion(jarray, 0, outLen, bytes);
}
// 注意des_crypt使用了malloc
C_SAFE_FREE(output);
// 注意JbyteArray2byteArray使用malloc
C_SAFE_FREE(src);
return jarray;
}

JNIEXPORT jbyteArray JNICALL
Java_com_tencent_msdk_dns_base_jni_Jni_aesCrypt(JNIEnv *env,
jclass cls,
jbyteArray _src,
jstring _key,
jint mode,
jbyteArray _aes_iv) {
(void)cls;

unsigned char *src = nullptr;
size_t src_len = 0;
unsigned char *aes_iv = nullptr;
size_t aes_iv_len = 0;
unsigned char *output = nullptr;
unsigned int outLen = 0;
self_dns::JniHelper::JbyteArray2byteArray(env, _src, &src, &src_len);
std::string key = self_dns::JniHelper::Jstring2String(env, _key);
jbyteArray jarray = nullptr;
outLen = self_dns::AesGetOutLen(src_len, mode);

self_dns::JniHelper::JbyteArray2byteArray(env, _aes_iv, &aes_iv, &aes_iv_len);

if (outLen > 0) {
output = new unsigned char[outLen]();
outLen = self_dns::AesCryptWithKey(src, src_len,
output, mode,
(const unsigned char *) key.c_str(),
(const unsigned char *) aes_iv);
if (output != nullptr && outLen > 0) {
self_dns::JniHelper::ClearEnvException(env);
jarray = env->NewByteArray(outLen);
jbyte *bytes = (jbyte *) output;
env->SetByteArrayRegion(jarray, 0, outLen, bytes);
}
}
C_SAFE_FREE(output);
C_SAFE_FREE(src);
C_SAFE_FREE(aes_iv);
return jarray;
}

JNIEXPORT jint JNICALL Java_com_tencent_msdk_dns_base_jni_Jni_sendToUnity
(JNIEnv *env, jclass cls, jstring _str) {
std::string str_msg = self_dns::JniHelper::Jstring2String(env, _str);
Expand Down
15 changes: 0 additions & 15 deletions src/main/cpp/Jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ extern "C" {
JNIEXPORT jint JNICALL
Java_com_tencent_msdk_dns_base_jni_Jni_getNetworkStack(JNIEnv *env, jclass type);

JNIEXPORT jbyteArray JNICALL
Java_com_tencent_msdk_dns_base_jni_Jni_desCrypt(JNIEnv *env,
jclass cls,
jbyteArray _src,
jstring _key,
jint mode);

JNIEXPORT jbyteArray JNICALL
Java_com_tencent_msdk_dns_base_jni_Jni_aesCrypt(JNIEnv *env,
jclass cls,
jbyteArray _src,
jstring _key,
jint mode,
jbyteArray _aes_iv);

JNIEXPORT jint JNICALL Java_com_tencent_msdk_dns_base_jni_Jni_sendToUnity
(JNIEnv *env, jclass cls, jstring _str);

Expand Down
Loading

0 comments on commit 629c728

Please sign in to comment.