导入证书时会重新加载身份,如果导入证书时有密钥,那这个时候加载时,也要密码的吧

This commit is contained in:
free will
2021-08-05 15:26:17 +08:00
parent cefa3f431a
commit 71d6a12183
2 changed files with 11 additions and 8 deletions
+5 -5
View File
@@ -31,7 +31,7 @@ public class VPNLoginExample {
// 身份信息保存位置
public static String identityPath="D:\\TEST\\Identitys\\";
// 用户名
public static String username="freesajgl111";
public static String username="frwiwawuwh1";
// VMS发送来的证书的密码
public static byte[] certPasswd="123456".getBytes(StandardCharsets.UTF_8);
// 基于用户名的用户身份标识
@@ -39,7 +39,7 @@ public class VPNLoginExample {
// 注册用户的IP
public static String vms_ip="121.15.171.91";
// 注册邮箱
public static String email="25556272asjys111@163.com";
public static String email="25wgjyggys111@163.com";
/**
* 生成本地密钥,持久化存储到本地硬盘
@@ -234,9 +234,9 @@ public class VPNLoginExample {
// 测试注册登录
public static void main(String[] args){
// new VPNLoginExample().testRegister();
new VPNLoginExample().testRegister();
// new VPNLoginExample().testLogin();
VpnServerInfoListExample infoList = new VPNLoginExample().testGetVPNInfo();
System.out.println(infoList);
// VpnServerInfoListExample infoList = new VPNLoginExample().testGetVPNInfo();
// System.out.println(infoList);
}
}
+6 -3
View File
@@ -311,10 +311,10 @@ public class IdentityManager {
* @author hongyu guo
* @date 2021/5/21
**/
public boolean loadCert(String identityName, Certificate cert) throws Exception {
public boolean loadCert(String identityName, Certificate cert,String passwd) throws Exception {
if(existIdentity(identityName)) {
// 已经存在
Identity id = Persist.getIdentityByNameFromStorage(identityName, "");
Identity id = Persist.getIdentityByNameFromStorage(identityName, passwd);
if(id == null)
throw new IdentifyManagerException("can not find identity by name [" + identityName + "] in sqlite");
Certificate oldCert = id.getCert();
@@ -338,6 +338,9 @@ public class IdentityManager {
}
return true;
}
public boolean loadCert(String identityName, Certificate cert) throws Exception {
return loadCert(identityName,cert,"");
}
/**
* 使用指定的网络身份给自己签发一个自签证书
@@ -472,7 +475,7 @@ public class IdentityManager {
public boolean importCert(byte[] bytesOfCert,byte[] passwd) throws Exception {
Certificate cert = CertUtils.fromPem(new String(bytesOfCert), passwd, Common.SM4ECB);
LoggerHelper.info("importing cert: "+cert.toString());
return loadCert(cert.getIssueTo(), cert);
return loadCert(cert.getIssueTo(), cert,new String(passwd));
}
public ConcurrentMap<String, Identity> getIdentifies() {