Skip to content

Commit c4a873f

Browse files
Merge pull request #400 from reaae4/patch-1
Add support for xgspon to cigpassword_gpon
2 parents abd0cad + 7367ad8 commit c4a873f

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

_includes/cig_password_xgspon.html

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<label for="result" class="form-label">Password</label>
2929
</div>
3030
</form>
31+
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
32+
<script type="text/javascript" src="/assets/js/cigpassword.js"></script>
3133
<script>
3234
var cigPassword = document.getElementById('cig-password');
3335
cigPassword.addEventListener('submit', (event) => {
@@ -36,16 +38,10 @@
3638
event.preventDefault();
3739
} else {
3840
const data = new URLSearchParams(new FormData(cigPassword));
39-
var url = new URL("https://cigpassword.hack-gpon.org/xgspon/");
40-
url.search = data.toString();
41-
fetch(url, {mode: 'cors'}).then(response => response.json()).then(json => {
42-
document.getElementById('result').value = json.password;
43-
document.getElementById('username').value = json.username;
44-
}).catch((error) => {
45-
document.getElementById('result').value = "Error!"
46-
});
41+
document.getElementById('result').value = cigpassword_gpon(data.get("serial"), null, data.get("password_len"), true);
42+
document.getElementById('username').value = data.get("serial");
4743
}
4844
[...cigPassword.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true));
4945
});
5046
</script>
51-
</div>
47+
</div>

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)