实现公钥的导入

serial
Matthew 1 year ago
parent ae120b0bd2
commit 4f961e7434

@ -33,6 +33,10 @@ bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
}
#endif
#ifdef USING_NRSEC
#include <Client/NrsecPort.h>
#endif
static jmethodID mRegisterTimerMid = 0;
static jmethodID mRegisterHeartbeatMid = 0;
@ -691,3 +695,28 @@ Java_com_xypower_mpapp_MicroPhotoService_getSerialNumber(
return env->NewStringUTF(value);
}
extern "C" JNIEXPORT void JNICALL
Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
JNIEnv* env,
jclass cls, jstring path, jstring md5) {
#ifdef USING_NRSEC
NrsecPort nrsec;
nrsec.Open("/dev/");
const char *pathStr = env->GetStringUTFChars(path, 0);
const char *md5Str = env->GetStringUTFChars(md5, 0);
std::vector<unsigned char> data;
if (readFile(pathStr, data) && !data.empty())
{
nrsec.SM2InportPublicKey(1, &data[0]);
}
env->ReleaseStringUTFChars(path, pathStr);
env->ReleaseStringUTFChars(md5, md5Str);
#endif
}

@ -98,6 +98,8 @@ public class MicroPhotoService extends Service {
private static final String ACTION_HEARTBEAT = "com.xypower.mpapp.ACT_HB";
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
private static final String ACTION_IMP_PUBKRY = "com.xypower.mpapp.ACT_IMP_PUBKEY";
private static final String ACTION_TAKE_PHOTO_MANUALLY = "com.xypower.mpapp.ACT_TP_M";
private static final String ACTION_HEARTBEAT_MANUALLY = "com.xypower.mpapp.ACT_HB_M";
private static final String ACTION_UPDATE_CONFIGS = "com.xypower.mpapp.ACT_UPD_CFG";
@ -170,7 +172,7 @@ public class MicroPhotoService extends Service {
IntentFilter intentFilter = new IntentFilter(ACTION_HEARTBEAT);
intentFilter.addAction(ACTION_TAKE_PHOTO);
intentFilter.addAction(ACTION_UPDATE_CONFIGS);
// intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
intentFilter.addAction(ACTION_IMP_PUBKRY);
// intentFilter.addAction(ACTION_HEARTBEAT_MANUALLY);
// intentFilter.addAction(ACTION_MSG_BROADCAST);
// intentFilter.addAction(ACTION_VIDEO_FINISHED);
@ -375,6 +377,9 @@ public class MicroPhotoService extends Service {
mService.recordingFinished(mService.mNativeHandle, result, path, videoId);
} else if (TextUtils.equals(ACTION_STOP, action)) {
mService.stopTerminalService();
} else if (TextUtils.equals(ACTION_IMP_PUBKRY, action)) {
String path = intent.getStringExtra("path");
String md5 = intent.getStringExtra("md5");
}
}
}
@ -1068,6 +1073,7 @@ cellSignalStrengthGsm.getDbm();
public static native void setOtgState(boolean enabled);
public static native void setCam3V3Enable(boolean enabled);
public static native String getSerialNumber();
public static native void importPublicKey(String path, String md5);
////////////////////////GPS////////////////////
// private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;

@ -0,0 +1,32 @@
package com.xypower.common;
import java.security.MessageDigest;
/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/util/MD5Util.class */
public class MD5Util {
public static String md5(String input) {
try {
byte[] bytes = MessageDigest.getInstance("MD5").digest(input.getBytes());
return printHexBinary(bytes);
} catch (Exception e) {
return input;
}
}
public static String md5(byte[] data) {
try {
byte[] bytes = MessageDigest.getInstance("MD5").digest(data);
return printHexBinary(bytes);
} catch (Exception e) {
return null;
}
}
public static String printHexBinary(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(String.format("%x", new Integer(b & 255)));
}
return r.toString();
}
}

@ -1,6 +1,8 @@
package com.xypower.mpmaster;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
@ -21,6 +23,7 @@ import com.xypower.common.FileUploader;
import com.xypower.common.HttpRequest;
import com.xypower.common.InetAddressUtils;
import com.xypower.common.JSONUtils;
import com.xypower.common.MD5Util;
import com.xypower.common.MicroPhotoContext;
import com.xypower.common.ThermalInfoUtil;
import com.xypower.common.ZipUtils;
@ -69,6 +72,8 @@ public class AppMaster {
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
public static final String CMD_IMPORT_PUB_KEY = "imp_pub_key";
public AppMaster(MpMasterService service, String masterUrl, String cmdid) {
mService = service;
@ -459,6 +464,52 @@ public class AppMaster {
} else if (TextUtils.equals(cmd, CMD_DELETE_FILE)) {
String path = jsonObject.optString("path", null);
deleteFile(path);
} else if (TextUtils.equals(cmd, CMD_IMPORT_PUB_KEY)) {
}
}
private void importPublicKey(JSONObject jsonObject) {
String content = jsonObject.optString("pubkey", null);
String md5 = jsonObject.optString("md5", null);
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()) + "keys/");
if (!path.exists()) {
path.mkdirs();
}
File file = new File(path, "pubkey.cert");
byte[] data = null;
try {
data = Base64.decode(content, Base64.DEFAULT);
} catch (Exception ex) {
}
if (data != null) {
if (TextUtils.equals(MD5Util.md5(data), md5)) {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(data);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception ex) {
}
}
}
Intent intent = new Intent(MpMasterService.ACTION_IMP_PUBKRY);
intent.putExtra("path", file.getAbsolutePath());
intent.putExtra("md5", md5);
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
mService.getApplicationContext().sendBroadcast(intent);
}
}
}

@ -70,6 +70,9 @@ public class MpMasterService extends Service {
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
public static final String ACTION_IMP_PUBKRY = "com.xypower.mpapp.ACT_IMP_PUBKEY";
private static final String EXTRA_PARAM_SCHEDULES = "Schedules";
private static final String EXTRA_PARAM_SCHEDULE = "Schedule_";
private static final String EXTRA_PARAM_TIME = "Time";

Loading…
Cancel
Save