mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
SSL中的两个结构体字段由Pubkey改成Nonce
This commit is contained in:
1 parent
8e33cb9894
commit
bd4199d9c0
4 files changed
+31
-14
No files matched your search
@@ -23,7 +23,7 @@ import java.util.Random;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class SSL_SetupMessage extends BaseStruct {
|
class SSL_SetupMessage extends BaseStruct {
|
||||||
public String Pubkey;
|
public String Nonce;
|
||||||
public String Secretkey;
|
public String Secretkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ class SSL_Message extends BaseStruct {
|
|||||||
public int IsEncrypted=0;
|
public int IsEncrypted=0;
|
||||||
public int MType=0;
|
public int MType=0;
|
||||||
public byte[] Data;
|
public byte[] Data;
|
||||||
public String Pubkey="";
|
public String Nonce ="";
|
||||||
public int Code=0;
|
public int Code=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class SSL {
|
|||||||
.substring(0,16);
|
.substring(0,16);
|
||||||
// 构造SSL_SetupMessage(公钥&密钥)
|
// 构造SSL_SetupMessage(公钥&密钥)
|
||||||
SSL_SetupMessage sm=new SSL_SetupMessage();
|
SSL_SetupMessage sm=new SSL_SetupMessage();
|
||||||
sm.Pubkey=pubKey;
|
sm.Nonce =pubKey;
|
||||||
sm.Secretkey=secretKey;
|
sm.Secretkey=secretKey;
|
||||||
String data;
|
String data;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class TCPConn implements Conn{
|
|||||||
}
|
}
|
||||||
mes.Data=ans;
|
mes.Data=ans;
|
||||||
if(this.role==1){
|
if(this.role==1){
|
||||||
mes.Pubkey=this.key.GetPubkey();
|
mes.Nonce =this.key.GetPubkey();
|
||||||
}
|
}
|
||||||
mes.Code=200;
|
mes.Code=200;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,19 +7,16 @@ import VMSConnection.Security.BC_KeyManager;
|
|||||||
import VMSConnection.TCPNet.Message.NetworkResponse;
|
import VMSConnection.TCPNet.Message.NetworkResponse;
|
||||||
import VMSConnection.Utils.Base64Helper;
|
import VMSConnection.Utils.Base64Helper;
|
||||||
import minsecurity.certificate.cert.CertException;
|
import minsecurity.certificate.cert.CertException;
|
||||||
import minsecurity.certificate.cert.Certificate;
|
|
||||||
import minsecurity.crypto.AsymKeyException;
|
import minsecurity.crypto.AsymKeyException;
|
||||||
import minsecurity.identity.Identity;
|
|
||||||
import minsecurity.identity.IdentityException;
|
import minsecurity.identity.IdentityException;
|
||||||
import org.bouncycastle.crypto.CryptoException;
|
import org.bouncycastle.crypto.CryptoException;
|
||||||
import security.KeyChain;
|
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Author: Wang Feng
|
* @Author: Wang Feng
|
||||||
@@ -33,7 +30,7 @@ public class VPNLoginExample {
|
|||||||
// 身份信息保存位置
|
// 身份信息保存位置
|
||||||
public static String identityPath="D:\\TEST\\Identitys\\";
|
public static String identityPath="D:\\TEST\\Identitys\\";
|
||||||
// 用户名
|
// 用户名
|
||||||
public static String username="/freewill";
|
public static String username="freewill111";
|
||||||
// VMS发送来的证书的密码
|
// VMS发送来的证书的密码
|
||||||
public static byte[] certPasswd="123456".getBytes(StandardCharsets.UTF_8);
|
public static byte[] certPasswd="123456".getBytes(StandardCharsets.UTF_8);
|
||||||
// 基于用户名的用户身份标识
|
// 基于用户名的用户身份标识
|
||||||
@@ -41,7 +38,7 @@ public class VPNLoginExample {
|
|||||||
// 注册用户的IP
|
// 注册用户的IP
|
||||||
public static String vms_ip="121.15.171.91";
|
public static String vms_ip="121.15.171.91";
|
||||||
// 注册邮箱
|
// 注册邮箱
|
||||||
public static String email="2555627323s@163.com";
|
public static String email="2555627323s111@163.com";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成本地密钥,持久化存储到本地硬盘
|
* 生成本地密钥,持久化存储到本地硬盘
|
||||||
@@ -124,12 +121,28 @@ public class VPNLoginExample {
|
|||||||
// 2. 签名(签名用户名) & 公钥(用户本地保存的公钥)
|
// 2. 签名(签名用户名) & 公钥(用户本地保存的公钥)
|
||||||
byte[] registerSign= vpnExample.signBytes(username);
|
byte[] registerSign= vpnExample.signBytes(username);
|
||||||
String pubKey=new String(KeyManagerExample.INSTANCE.getKeyChain().getCurrentIdentity().getPubkey()
|
String pubKey=new String(KeyManagerExample.INSTANCE.getKeyChain().getCurrentIdentity().getPubkey()
|
||||||
.getBytes());
|
.getBytes(),StandardCharsets.UTF_8);
|
||||||
|
System.out.println("pubkey: "+pubKey);
|
||||||
|
// 测试验签
|
||||||
|
try {
|
||||||
|
boolean r=KeyManagerExample.INSTANCE.getKeyChain().getCurrentIdentity().verify(
|
||||||
|
username.getBytes(StandardCharsets.UTF_8),registerSign);
|
||||||
|
System.out.println("测试验签结果:"+r);
|
||||||
|
} catch (IdentityException | AsymKeyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
boolean rr=new BC_KeyManager().Verify(username.getBytes(StandardCharsets.UTF_8),new String(registerSign),pubKey);
|
||||||
|
System.out.println("测试验签结果2:"+rr);
|
||||||
|
|
||||||
// 3. 构造注册请求包
|
// 3. 构造注册请求包
|
||||||
RegisterWithSignRequest request=new RegisterWithSignRequest(1,username,"password",
|
RegisterWithSignRequest request=new RegisterWithSignRequest(1,username,"password",
|
||||||
"15239970973","1234",email,"dev","",
|
"15239970973","1234",email,"dev","",
|
||||||
pubKey,0,0,"1625142358",registerSign);
|
pubKey,0,0,"1625142358",registerSign);
|
||||||
|
try {
|
||||||
|
System.out.println("register request: "+request.toJson());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// 4. 调用bc-api,进行注册
|
// 4. 调用bc-api,进行注册
|
||||||
BC_API bc_api=new BC_API();
|
BC_API bc_api=new BC_API();
|
||||||
@@ -180,6 +193,6 @@ public class VPNLoginExample {
|
|||||||
// 测试注册登录
|
// 测试注册登录
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
new VPNLoginExample().testRegister();
|
new VPNLoginExample().testRegister();
|
||||||
new VPNLoginExample().testLogin();
|
// new VPNLoginExample().testLogin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,8 +34,8 @@ public class TestAPI {
|
|||||||
// System.out.println(res);
|
// System.out.println(res);
|
||||||
// }
|
// }
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
String username="/frasgASJGXUa2";
|
String username="/fssASssJGXUa2ss";
|
||||||
String email="25SAUUKDsiahHk3s@163.com";
|
String email="25SAawhqeDsissssahHk3s@163.com";
|
||||||
int userID=1;
|
int userID=1;
|
||||||
// 模拟客户端生成自己的公钥私钥
|
// 模拟客户端生成自己的公钥私钥
|
||||||
BC_KeyManager bc_keyManager=new BC_KeyManager();
|
BC_KeyManager bc_keyManager=new BC_KeyManager();
|
||||||
@@ -65,6 +65,10 @@ public class TestAPI {
|
|||||||
System.out.println("raw text: "+username);
|
System.out.println("raw text: "+username);
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
|
// 测试验签结果
|
||||||
|
// boolean rr=new BC_KeyManager().Verify(username.getBytes(StandardCharsets.UTF_8),new String(sig),pubkey);
|
||||||
|
// System.out.println("测试验签结果2:"+rr);
|
||||||
|
|
||||||
// 这里对sig进行一次base64编码
|
// 这里对sig进行一次base64编码
|
||||||
// sig=Base64Helper.BlockChain_Base64Encode(sig).getBytes(StandardCharsets.UTF_8);
|
// sig=Base64Helper.BlockChain_Base64Encode(sig).getBytes(StandardCharsets.UTF_8);
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in new issue
Block a user