Skip to content

Commit

Permalink
refactor: replace big-number usage with jsbi
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed Oct 16, 2019
1 parent 5ad0666 commit 943d8a3
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/ntlm-payload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import WritableTrackingBuffer from './tracking-buffer/writable-tracking-buffer';
import * as crypto from 'crypto';

const BigInteger = require('big-number');

const hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
import JSBI from 'jsbi';

type Options = {
domain: string,
Expand Down Expand Up @@ -111,24 +108,15 @@ class NTLMResponsePayload {
}

createTimestamp(time: number) {
const tenthsOfAMicrosecond = BigInteger(time).plus(11644473600).multiply(10000000);
const hexArray = [];

let pair = [];
while (tenthsOfAMicrosecond.val() !== '0') {
const idx = tenthsOfAMicrosecond.mod(16);
pair.unshift(hex[idx]);
if (pair.length === 2) {
hexArray.push(pair.join(''));
pair = [];
}
}
const tenthsOfAMicrosecond = JSBI.multiply(JSBI.add(JSBI.BigInt(time), JSBI.BigInt(11644473600)), JSBI.BigInt(10000000));

if (pair.length > 0) {
hexArray.push(pair[0] + '0');
}
const lo = JSBI.toNumber(JSBI.bitwiseAnd(tenthsOfAMicrosecond, JSBI.BigInt(0xffffffff)));
const hi = JSBI.toNumber(JSBI.bitwiseAnd(JSBI.signedRightShift(tenthsOfAMicrosecond, JSBI.BigInt(32)), JSBI.BigInt(0xffffffff)));

return Buffer.from(hexArray.join(''), 'hex');
const result = Buffer.alloc(8);
result.writeUInt32LE(lo, 0);
result.writeUInt32LE(hi, 4);
return result;
}

lmv2Response(domain: string, user: string, password: string, serverNonce: Buffer, clientNonce: Buffer) {
Expand Down

0 comments on commit 943d8a3

Please sign in to comment.