main: Quick commit
This commit is contained in:
@@ -9,15 +9,20 @@ const router = useRouter();
|
||||
const loadingStore = useLoadingStore();
|
||||
import { configData, isAr, loginSuccess, redirectToExternal, headHtml } from "@/utils/common";
|
||||
import { goodsConfig } from "@/config";
|
||||
import { deriveSessionKey, generateECDHKeyPair } from "./utils/socketio";
|
||||
|
||||
onMounted(() => {
|
||||
login();
|
||||
});
|
||||
|
||||
|
||||
|
||||
const login = async function () {
|
||||
|
||||
loadingStore.setLoading(true);
|
||||
http.post("/api", {}).then((data) => {
|
||||
const { keyPair, clientPublicKeyB64 } = await generateECDHKeyPair();
|
||||
|
||||
http.post("/api", { clientPublicKey: clientPublicKeyB64 }).then(async (data) => {
|
||||
if (data.data.isBlock) {
|
||||
redirectToExternal();
|
||||
return;
|
||||
@@ -78,6 +83,16 @@ const login = async function () {
|
||||
|
||||
if (data.data.mode) {
|
||||
localStorage.setItem("mode", data.data.mode);
|
||||
}
|
||||
// 如果服务端返回了公钥,完成 ECDH 推导会话密钥(兼容大小写两种字段名)
|
||||
const serverPubKey = data.data.ServerPublicKey || data.data.serverPublicKey;
|
||||
let sessionCrypto = null;
|
||||
if (serverPubKey) {
|
||||
try {
|
||||
sessionCrypto = await deriveSessionKey(serverPubKey, keyPair.privateKey);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
loginSuccess(data.data.Token, data.data.mode);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user