mirror of
https://gitee.com/willfree/min-vpn-client_v2.git
synced 2026-06-03 15:36:14 +08:00
对用户名字段达成了新的共识,用户名即不含非法字符的唯一ID
This commit is contained in:
@@ -38,3 +38,8 @@
|
||||
可以看出,其中的Username和IdentityName均与用户注册时输入的用户名有关,但不是同一个字符串。
|
||||
密码也是同理,代码运行时候的密码passwd是用户输入的原始密码RawPasswd经过md5哈希之后得到。
|
||||
MINVpnSettingAPI中的用户名和密码是用户输入的RawUsername和RawPasswd,在注册和登录时再进行处理。
|
||||
|
||||
## 用户名及密码说明V2
|
||||
经过简化,用户输入的username将直接作为注册、登录及连接VPN时发送给后台的username而存在,
|
||||
证书则是"/"+username,完全去除Base64编解码化。
|
||||
|
||||
|
||||
@@ -10,6 +10,17 @@ package com.pkusz.min_vpn_client;
|
||||
import android.app.Application;
|
||||
|
||||
import com.pkusz.min_vpn_client.model.MINVpnSettingAPI;
|
||||
import com.pkusz.min_vpn_client.utils.gmutil.sm4.Android_SM4;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
public class APP extends Application {
|
||||
@Override
|
||||
@@ -19,5 +30,20 @@ public class APP extends Application {
|
||||
// 本地配置初始化
|
||||
MINVpnSettingAPI.INSTANCE.init(this);
|
||||
System.out.println(MINVpnSettingAPI.INSTANCE.toString());
|
||||
// 加载BC
|
||||
loadRightBC();
|
||||
}
|
||||
|
||||
private boolean loadRightBC(){
|
||||
try {
|
||||
byte[] enc = Android_SM4.encrypt_ECB_Padding("1234567812345678".getBytes(StandardCharsets.UTF_8),
|
||||
"wefree".getBytes(StandardCharsets.UTF_8));
|
||||
System.out.println("加载到了正确BC: "+Arrays.toString(enc));
|
||||
return true;
|
||||
} catch (InvalidKeyException | NoSuchProviderException | NoSuchPaddingException
|
||||
| IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException e) {
|
||||
System.out.println("不能加载到正确的BC: "+e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,21 +167,22 @@ public class LoginActivity extends MINVpnBaseActivity<LoginActivityPresenter>
|
||||
}
|
||||
|
||||
// 用户名经base64编码
|
||||
String username;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
username = Base64Util.Base64PlusEncode(rawUsername);
|
||||
} else {
|
||||
System.out.println("Base64Util.Base64PlusDecode error");
|
||||
btnLogin.revertAnimation();
|
||||
return;
|
||||
}
|
||||
// String username;
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// username = Base64Util.Base64PlusEncode(rawUsername);
|
||||
// } else {
|
||||
// System.out.println("Base64Util.Base64PlusDecode error");
|
||||
// btnLogin.revertAnimation();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 密码经md5哈希
|
||||
String password =DigestUtilKt.encodeToMD5(rawPassword);
|
||||
// }
|
||||
|
||||
// 传递登录请求信息,执行登录网络请求
|
||||
OriginalLoginRequest loginRequest=new OriginalLoginRequest(username, password);
|
||||
// OriginalLoginRequest loginRequest=new OriginalLoginRequest(username, password);
|
||||
OriginalLoginRequest loginRequest=new OriginalLoginRequest(rawUsername, password);
|
||||
mPresenter.login(loginRequest);
|
||||
});
|
||||
|
||||
|
||||
@@ -162,21 +162,22 @@ public class RegisterActivity extends MINVpnBaseActivity<RegisterActivityPresent
|
||||
}
|
||||
|
||||
// 用户名经base64编码
|
||||
String base64Username;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
base64Username = Base64Util.Base64PlusEncode(username);
|
||||
} else {
|
||||
System.out.println("Base64Util.Base64PlusDecode error");
|
||||
btnRegister.revertAnimation();
|
||||
return;
|
||||
}
|
||||
// String base64Username;
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// base64Username = Base64Util.Base64PlusEncode(username);
|
||||
// } else {
|
||||
// System.out.println("Base64Util.Base64PlusDecode error");
|
||||
// btnRegister.revertAnimation();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 密码经md5哈希
|
||||
String md5Password = DigestUtilKt.encodeToMD5(password);
|
||||
|
||||
// 传递注册请求信息,执行注册网络请求
|
||||
OriginalRegisterRequest original=new OriginalRegisterRequest(
|
||||
base64Username,md5Password,phone,email,inviteCode);
|
||||
// base64Username,md5Password,phone,email,inviteCode);
|
||||
username,md5Password,phone,email,inviteCode);
|
||||
mPresenter.register(original);
|
||||
});
|
||||
|
||||
|
||||
@@ -168,8 +168,9 @@ public enum VMSRequestAPI {
|
||||
* @param identityPath
|
||||
*/
|
||||
private void generateForeverIdentity(String username,String identityPath){
|
||||
// identityName是将username进行base64编码,然后加上"/"
|
||||
String identityName="/"+ Base64Helper.Base64PlusEncode(username);
|
||||
// identityName是将username(不进行base64编码),然后加上"/"
|
||||
// String identityName="/"+ Base64Helper.Base64PlusEncode(username);
|
||||
String identityName="/"+ username;
|
||||
KeyManager.INSTANCE.initKeyChain(identityName,identityPath);
|
||||
}
|
||||
private void generateForeverIdentity(String username){
|
||||
|
||||
@@ -19,6 +19,7 @@ import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.pkusz.min_vpn_client.model.MINVpnSettingAPI;
|
||||
import com.pkusz.min_vpn_client.utils.AESHelperForConnection;
|
||||
import com.pkusz.min_vpn_client.utils.Base64Util;
|
||||
import com.pkusz.min_vpn_client.utils.IPPackageUtil;
|
||||
import com.pkusz.min_vpn_client.utils.KeyManager;
|
||||
import com.pkusz.min_vpn_client.utils.RuleUtil;
|
||||
@@ -67,7 +68,7 @@ public class MINVpnConnection implements Runnable{
|
||||
private final VpnService mService;
|
||||
private final int mConnectionId;
|
||||
// face的注册前缀 格式为:/{边界路由器的服务前缀}/{用户名}/{当前系统时间},
|
||||
// 如:"/min/gdcni19/wefree/"+System.currentTimeMillis();
|
||||
// 如:"/min/gdcni19/Base64Util.Base64PlusEncode(wefree)/"+System.currentTimeMillis();
|
||||
// 在执行initFace的时候初始化
|
||||
private String localFacePrefix;
|
||||
|
||||
@@ -666,9 +667,15 @@ public class MINVpnConnection implements Runnable{
|
||||
// 2. 注册标识
|
||||
RegisterPrefixHelper helper=new RegisterPrefixHelper();
|
||||
try {
|
||||
localFacePrefix =MINVpnSettingAPI.INSTANCE.getFirstRouterPrefix()
|
||||
+"/"+MINVpnSettingAPI.INSTANCE.getUsername()
|
||||
+"/"+System.currentTimeMillis();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
localFacePrefix =MINVpnSettingAPI.INSTANCE.getFirstRouterPrefix()
|
||||
// +"/"+Base64Util.Base64PlusEncode(MINVpnSettingAPI.INSTANCE.getUsername())
|
||||
+"/"+MINVpnSettingAPI.INSTANCE.getUsername()
|
||||
+"/"+System.currentTimeMillis();
|
||||
}else {
|
||||
System.out.println("Base64Util.Base64PlusDecode error");
|
||||
return null;
|
||||
}
|
||||
System.out.println("注册前缀:"+ localFacePrefix);
|
||||
face.registerIdentifier(new Identifier(localFacePrefix),5000,helper);
|
||||
} catch (LogicFaceException | ComponentException e) {
|
||||
|
||||
Reference in New Issue
Block a user