Commit 912ed191 authored by martin hou's avatar martin hou

fix: 更换md5实现,以及增加签名重复的二次验证

parent c9718024
......@@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"js-md5": "^0.8.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
......@@ -1035,6 +1036,11 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/js-md5": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.8.3.tgz",
"integrity": "sha512-qR0HB5uP6wCuRMrWPTrkMaev7MJZwJuuw4fnwAzRgP4J4/F8RwtodOKpGp4XpqsLBFzzgqIO42efFAyz2Et6KQ=="
},
"node_modules/nanoid": {
"version": "3.3.8",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.8.tgz",
......
......@@ -24,6 +24,7 @@
"vite": "^6.0.3"
},
"dependencies": {
"js-md5": "^0.8.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
......
import { Logger as internalLogger, formatTime, shortcutKeys, sliceTime } from './utils';
import md5 from 'js-md5';
const INVAILD = 0x00;
const QUERY_DEVICE_INFO = 0x01;
......@@ -779,7 +780,7 @@ Jensen.prototype.listFiles = async function () {
length: flen,
signature: sign2
});
console.log(`Sign1: ${sign.join('')}, Sign2: ${sign2}`);
// console.log(`Sign1: ${sign.join('')}, Sign2: ${sign2}`);
}
// if (fcount == -1 && (fc))
// 如果没有判断数量的依据
......@@ -787,8 +788,17 @@ Jensen.prototype.listFiles = async function () {
// return [];
}
// 理论上,应该不要等太久,如果已经接近总量,但是等待的时间有点长,可以考虑提前退出了
//
// 如果files有重复的signature,那就持续改为不重复的为止
let seen = new Set();
for (let i = 0; i < files.length; i++) {
let file = files[i];
while (seen.has(file.signature)) {
// Append a random number to make signature unique
file.signature = md5(file.signature + Math.random());
}
seen.add(file.signature);
}
// 如果已经等待过长的时间了,那就直接返回好了
let kv = tag + '-timer';
let now = new Date().getTime();
......@@ -1461,75 +1471,3 @@ Jensen.registerHandler(REQUEST_UAC_UPDATE, (msg) => {
Jensen.registerHandler(UAC_UPDATE, commonMessageParser);
export { Jensen };
const md5 = (str) => {
function md5cycle(x, k) {
let [a, b, c, d] = x;
a = ff(a, b, c, d, k[0], 7, -680876936);
d = ff(d, a, b, c, k[1], 12, -389564586);
c = ff(c, d, a, b, k[2], 17, 606105819);
b = ff(b, c, d, a, k[3], 22, -1044525330);
// ...(共64轮运算,此处省略,完整见对应源码)
x[0] = (a + x[0]) | 0;
x[1] = (b + x[1]) | 0;
x[2] = (c + x[2]) | 0;
x[3] = (d + x[3]) | 0;
}
function cmn(q, a, b, x, s, t) {
return ((a + q + x + t) << s | (a + q + x + t) >>> (32 - s)) + b;
}
function ff(a, b, c, d, x, s, t) { return cmn((b & c) | (~b & d), a, b, x, s, t); }
function gg(a, b, c, d, x, s, t) { return cmn((b & d) | (c & ~d), a, b, x, s, t); }
function hh(a, b, c, d, x, s, t) { return cmn(b ^ c ^ d, a, b, x, s, t); }
function ii(a, b, c, d, x, s, t) { return cmn(c ^ (b | ~d), a, b, x, s, t); }
function md5blk(s) {
const md5blks = [];
for (let i = 0; i < 64; i += 4) {
md5blks[i >> 2] =
s.charCodeAt(i)
+ (s.charCodeAt(i + 1) << 8)
+ (s.charCodeAt(i + 2) << 16)
+ (s.charCodeAt(i + 3) << 24);
}
return md5blks;
}
function md51(s) {
const n = s.length;
const state = [1732584193, -271733879, -1732584194, 271733878];
let i;
for (i = 64; i <= n; i += 64) {
md5cycle(state, md5blk(s.substring(i - 64, i)));
}
s = s.substring(i - 64);
const tail = Array(16).fill(0);
for (i = 0; i < s.length; i++) {
tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
}
tail[i >> 2] |= 0x80 << ((i % 4) << 3);
if (i > 55) {
md5cycle(state, tail);
tail.fill(0);
}
tail[14] = n * 8;
md5cycle(state, tail);
return state;
}
function rhex(n) {
let s = '', j;
for (j = 0; j < 4; j++) {
s += ('0' + ((n >> (j * 8 + 4)) & 0x0F).toString(16)).slice(-2) +
('0' + ((n >> (j * 8)) & 0x0F).toString(16)).slice(-2);
}
return s;
}
function hex(md5array) {
return md5array.map(rhex).join('');
}
return hex(md51(str));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment