优化接口定义和代码

hdrplus
Matthew 1 year ago
parent 763ee34cbf
commit 4eefd56b2a

@ -12,6 +12,8 @@
#include <android/multinetwork.h>
#define NRSEC_PATH "/dev/spidev0.0"
#ifdef USING_BREAK_PAD
#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"
@ -751,25 +753,19 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
#ifdef USING_NRSEC
NrsecPort nrsec;
// const char *port = "/dev/mtkgpioctrl";
const char *port = "/dev/spidev0.0";
int byteCertLen = env->GetArrayLength(cert);
if (byteCertLen <= 0)
{
return JNI_FALSE;
}
if (!nrsec.Open(port))
NrsecPort nrsec;
const char *path = NRSEC_PATH;
if (!nrsec.Open(path))
{
return JNI_FALSE;
}
std::string version = nrsec.Version();
char buf[128] = { 0 };
strcpy(buf, version.c_str());
jbyte* byteCert = env->GetByteArrayElements(cert, 0);
bool res = nrsec.SM2ImportPublicKey(index, (const uint8_t*)byteCert);
@ -795,20 +791,14 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
GpioControl::setSpiBitsPerWord(8);
GpioControl::setSpiMaxSpeedHz(33000000);
const char *port = "/dev/mtkgpioctrl";
// const char *port = "/dev/spidevSE";
const char *path = NRSEC_PATH;
NrsecPort nrsec;
if (!nrsec.Open(port))
if (!nrsec.Open(path))
{
return JNI_FALSE;
}
std::string version = nrsec.Version();
char buf[128] = { 0 };
strcpy(buf, version.c_str());
bool res = nrsec.SM2keypair(index) == 0;
nrsec.Close();
@ -818,61 +808,68 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_queryVersion(
extern "C" JNIEXPORT jstring JNICALL
Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
JNIEnv* env,
jclass cls) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
const char *path = NRSEC_PATH;
NrsecPort nrsec;
if (!nrsec.Open(port))
if (!nrsec.Open(path))
{
return JNI_FALSE;
return NULL;
}
std::string version = nrsec.Version();
char buf[128] = { 0 };
strcpy(buf, version.c_str());
nrsec.Close();
return JNI_TRUE;
return env->NewStringUTF(version.c_str());
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_requestCert(
JNIEnv* env, jclass cls, jint type, jint index, jstring subject) {
JNIEnv* env, jclass cls, jint type, jint index, jstring subject, jstring outputPath) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
if (env->GetStringUTFLength(subject) || env->GetStringUTFLength(outputPath))
{
return JNI_FALSE;
}
const char *path = NRSEC_PATH;
NrsecPort nrsec;
if (!nrsec.Open(port))
if (!nrsec.Open(path))
{
return JNI_FALSE;
}
std::string title_subject = env->GetStringUTFChars(subject, 0);
uint8_t output[1024];
uint16_t len;
bool res = nrsec.SM2cert(type,index,title_subject,output,&len) == 0;
FILE* csr_file = fopen("/sdcard/com.xypower.mpapp/temp/rqcert.csr", "wb");
fwrite(output, sizeof(unsigned char), len, csr_file);
uint8_t output[1024] = { 0 };
uint16_t len = 0;
const char* subjectStr = env->GetStringUTFChars(subject, 0);
bool res = nrsec.SM2cert(type, index, subjectStr, output, &len) == 0;
nrsec.Close();
env->ReleaseStringUTFChars(subject, subjectStr);
if (!res)
{
return JNI_FALSE;
}
fclose(csr_file);
const char* outputPathStr = env->GetStringUTFChars(outputPath, 0);
FILE* file = fopen(outputPathStr, "wb");
env->ReleaseStringUTFChars(outputPath, outputPathStr);
if (file == NULL)
{
return JNI_FALSE;
}
nrsec.Close();
int bytes = fwrite(output, sizeof(unsigned char), len, file);
fclose(file);
return res ? JNI_TRUE : JNI_FALSE;
return bytes == len ? JNI_TRUE : JNI_FALSE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
@ -913,10 +910,10 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
JNIEnv* env, jclass cls, jint index) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
const char *path = NRSEC_PATH;
NrsecPort nrsec;
if (!nrsec.Open(port))
if (!nrsec.Open(path))
{
return JNI_FALSE;
}
@ -925,11 +922,11 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
std::vector<unsigned char> data(64,0);
res = nrsec.SM2ExportPublicKey(index, &data[0]) == 0;
FILE* Expbkey_file = fopen("/sdcard/device_pbkey.cer", "wb");
FILE* file = fopen("/sdcard/device_pbkey.cer", "wb");
fwrite(&data[0], sizeof(unsigned char), data.size(), Expbkey_file);
fwrite(&data[0], sizeof(unsigned char), data.size(), file);
fclose(Expbkey_file);
fclose(file);
nrsec.Close();
@ -943,10 +940,10 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
JNIEnv* env, jclass cls, jint index) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
const char *path = NRSEC_PATH;
NrsecPort nrsec;
if (!nrsec.Open(port))
if (!nrsec.Open(path))
{
return JNI_FALSE;
}

@ -1144,8 +1144,8 @@ cellSignalStrengthGsm.getDbm();
public static native boolean importPublicKey(int index, byte cert[]);
public static native boolean genKeys(int index);
public static native boolean queryVersion();
public static native boolean requestCert(int type, int index, String subject);
public static native String querySecVersion();
public static native boolean requestCert(int type, int index, String subject, String outputPath);
public static native boolean importPrivateKeyFile(int index, String path, String md5);
public static native boolean exportPublicKeyFile(int index);
public static native boolean exportPrivateFile(int index);

Loading…
Cancel
Save