| 5 |
| 6 | static const char *SIGN = "7B09B0F6F83CCD1543D80A1F078EEC320B0291B4"; |
| 7 |
| 8 | extern "C" { |
| 9 | int verifySign(JNIEnv *env) { |
| 10 | jobject application = getApplication(env); |
| 11 | if (application == nullptr) { |
| 12 | return JNI_ERR; |
| 13 | } |
| 14 | const char *resourcePath = getApkPath(env, application); |
| 15 | env->DeleteLocalRef(application); |
| 16 | intptr_t fd = openAt(AT_FDCWD, resourcePath, O_RDONLY); |
| 17 | if (fd < 0) { |
| 18 | return JNI_ERR; |
| 19 | } |
| 20 | std::string sign = read_certificate(fd); |
| 21 | if (!more_check(fd, resourcePath)) { |
| 22 | return JNI_ERR; |
| 23 | } |
| 24 | close(fd); |
| 25 | std::string s = toolkit::SHA1::encode(sign); |
| 26 | // 使用标准库算法将小写字母转换为大写字母 |
| 27 | for (char &c : s) { |
| 28 | if (c >= 'a' && c <= 'z') { |
| 29 | c = c - 'a' + 'A'; // 转换成大写 |
| 30 | } |
| 31 | } |
| 32 | const char* hex_sha = s.c_str(); |
| 33 |
| 34 | LOGI("应用读取的签名为:%s", hex_sha); |
| 35 | LOGI("应用预置的签名为:%s", SIGN); |
| 36 | int result = strcmp(hex_sha, SIGN); |
| 37 | if (result == 0) { // 签名一致 |
| 38 | LOGI("签名一致"); |
| 39 | return JNI_OK; |
| 40 | } |
| 41 | LOGE("签名校验失败"); |
| 42 | return JNI_ERR; |
| 43 | } |
| 44 | } |
| 45 |