-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
46 lines (35 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const ntlm = require('httpntlm/ntlm');
module.exports = async ctx => {
let cfg = ctx.auth.credentials.options || {};
let authMessage = ntlm.createType1Message({
domain: cfg.domain || '',
workstation: cfg.workstation || ''
});
let cmd;
cmd = await ctx.sendCommand('AUTH ' + authMessage);
if (cmd.status !== 334) {
throw new Error('Invalid login sequence while waiting for server challenge string');
}
let challengeString = cmd.text;
if (!/^NTLM/i.test(challengeString)) {
challengeString = 'NTLM ' + challengeString;
}
let type2Message = ntlm.parseType2Message(challengeString, err => {
// parseType2Message handles callback synchronously to return an error response
throw err;
});
let type3Message = ntlm.createType3Message(type2Message, {
domain: cfg.domain || '',
workstation: cfg.workstation || '',
username: ctx.auth.credentials.user,
password: ctx.auth.credentials.pass
});
type3Message = type3Message.substring(5); // remove the "NTLM " prefix
cmd = await ctx.sendCommand(type3Message);
if (cmd.status !== 235) {
throw new Error('Invalid login sequence while waiting for "235"');
}
// authenticated!
return true;
};