From 5d74049c86f7c7164cdf470af364e5f54d423e76 Mon Sep 17 00:00:00 2001 From: src48597962 <48597962@qq.com> Date: Thu, 25 Apr 2024 12:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'test=5Faliecc.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_aliecc.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test_aliecc.js diff --git a/test_aliecc.js b/test_aliecc.js new file mode 100644 index 0000000..a665349 --- /dev/null +++ b/test_aliecc.js @@ -0,0 +1,67 @@ +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 } +} \ No newline at end of file