You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
67 lines
2.4 KiB
function test_aliecc() {
|
|
let headers = {
|
|
"content-type": "application/json;charset=UTF-8",
|
|
"origin": "https://www.aliyundrive.com",
|
|
"referer": "https://www.aliyundrive.com/",
|
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41"
|
|
};
|
|
let appId = "5dde4e1bdf9e4966b387ba58f4b3fdc3";
|
|
let nonce = 0;
|
|
/*
|
|
// 生成私钥和公钥
|
|
let private_key = BigInt(Math.floor(Math.random() * 2 ** 32));
|
|
let ecc_pri = new ECDSA.ECDSA(private_key, "secp256k1");
|
|
let ecc_pub = ecc_pri.getVerifyingKey();
|
|
let public_key = "04" + ecc_pub.toString();
|
|
|
|
function r(appId, deviceId, userId, nonce) {
|
|
return `${appId}:${deviceId}:${userId}:${nonce}`;
|
|
}
|
|
|
|
function sign(appId, deviceId, userId, nonce) {
|
|
let sign_dat = ecc_pri.sign(
|
|
r(appId, deviceId, userId, nonce).getBytes('utf-8'),
|
|
ECDSA.sha256
|
|
);
|
|
return sign_dat.toString() + "01";
|
|
}
|
|
*/
|
|
// 生成私钥和公钥
|
|
let private_key = new Uint8Array(32); // 32 个随机字节
|
|
let public_key = new Uint8Array(64); // 64 个随机字节
|
|
|
|
function r(appId, deviceId, userId, nonce) {
|
|
return `${appId}:${deviceId}:${userId}:${nonce}`;
|
|
}
|
|
|
|
function sign(appId, deviceId, userId, nonce) {
|
|
eval(getCryptoJS());
|
|
let msg = r(appId, deviceId, userId, nonce);
|
|
let hash = CryptoJS.subtle.digest("SHA-256", new TextEncoder().encode(msg));
|
|
let signature = CryptoJS.subtle.sign(
|
|
{
|
|
name: "ECDSA",
|
|
hash: { name: "SHA-256" },
|
|
},
|
|
private_key,
|
|
hash
|
|
);
|
|
return new Uint8Array(signature);
|
|
}
|
|
let signature = sign(appId, "3a9935208f4b4fce95a9655c7725d640", "3426ad8ebaa04e1ea9ee01bd998d06d4", nonce);
|
|
log(signature);
|
|
headers['x-signature'] = signature;
|
|
let data = {
|
|
"deviceName": "Edge浏览器",
|
|
"modelName": "Windows网页版",
|
|
"pubKey": public_key,
|
|
}
|
|
if (signature && public_key) {
|
|
let req = JSON.parse(request("https://api.aliyundrive.com/users/v1/users/device/create_session", { headers: headers, body: data, timeout: 3000 }));
|
|
log(req);
|
|
if (req.success) {
|
|
return { "signature": signature, "success": 1 }
|
|
}
|
|
}
|
|
return { "success": 0 }
|
|
} |