Skip to content

Commit a3f6e0b

Browse files
authored
Add support for xgspon to cigpassword_gpon
1 parent d08c04c commit a3f6e0b

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

assets/js/cigpassword.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@ function hexToBytes(hex) {
66
return bytes;
77
}
88

9-
function cigpassword_gpon(ont_serial, ont_user) {
9+
function cigpassword_gpon(ont_serial, ont_user, length = 0, xgspon = false) {
1010
const hardcoded_key = '01030a1013051764c8061419b49d0500';
1111
const hardcoded_seed = '2345679abcdefghijkmnpqrstuvwxyzACDEFGHJKLMNPQRSTUVWXYZ';
1212

1313
let ont_vendor = ont_serial.substring(0, 4).toUpperCase();
1414
let ont_id = ont_serial.substring(4).toLowerCase();
15+
16+
if (xgspon) {
17+
ont_id = ont_id.toUpperCase();
18+
}
19+
1520
let formatted_serial = `${ont_vendor}${ont_id}`;
1621

17-
let key_bytes = CryptoJS.enc.Hex.parse(hardcoded_key);
18-
let hmac = CryptoJS.HmacMD5(`${formatted_serial}-${ont_user}`, key_bytes);
22+
let key_bytes = new Uint8Array(hardcoded_key.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
23+
if (length > 0) {
24+
key_bytes[15] = length;
25+
}
26+
27+
let formatted_serial_user = formatted_serial;
28+
if (ont_user) {
29+
formatted_serial_user += `-${ont_user}`;
30+
}
31+
32+
let hmac = CryptoJS.HmacMD5(formatted_serial_user, CryptoJS.lib.WordArray.create(key_bytes));
1933
let pw_md5_hmac = hexToBytes(hmac.toString(CryptoJS.enc.Hex));
2034

2135
let output = Array(pw_md5_hmac.length);
@@ -24,5 +38,9 @@ function cigpassword_gpon(ont_serial, ont_user) {
2438
output[i] = hardcoded_seed[pw_md5_hmac[i] % 0x36];
2539
}
2640

27-
return output.join('');
41+
if (length > 0) {
42+
return output.slice(0, length).join('');
43+
} else {
44+
return output.join('');
45+
}
2846
}

0 commit comments

Comments
 (0)