-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
162 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/cli').cli(); | ||
const authHost = process.env.AUTH_HOST; | ||
const authPort = process.env.AUTH_PORT; | ||
|
||
require('../dist/cli') | ||
.cli({ authHost, authPort }) | ||
.catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { AIMAuthServer } from './AIMAuthServer'; | ||
|
||
export function cli() { | ||
const server = new AIMAuthServer(); | ||
server.listen(); | ||
interface CLIOpts { | ||
authHost?: string; | ||
authPort?: string; | ||
} | ||
|
||
export async function cli(opts: CLIOpts) { | ||
const authServer = new AIMAuthServer({ | ||
host: opts.authHost, | ||
port: (opts.authPort && Number(opts.authPort)) || undefined, | ||
}); | ||
const { host, port } = await authServer.listen(); | ||
console.log(`Auth Service listening on ${host}:${port}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { parseTLVs } from './parseTLVs'; | ||
import { TLVS } from './constants'; | ||
|
||
/** | ||
* @see http://iserverd1.khstu.ru/oscar/snac_17_06.html | ||
*/ | ||
export function parseAuthRequest(data: Buffer) { | ||
const tlvs = parseTLVs(data); | ||
const screennameTLV = tlvs.first(TLVS.SCREENNAME); | ||
|
||
return { | ||
screenname: screennameTLV.value.toString('ascii'), | ||
}; | ||
} | ||
|
||
/** | ||
* @see http://iserverd1.khstu.ru/oscar/snac_17_02.html | ||
*/ | ||
export function parseMD5LoginRequest(data: Buffer) { | ||
const tlvs = parseTLVs(data); | ||
const screenname = tlvs.first(TLVS.SCREENNAME); | ||
const passwordHash = tlvs.first(TLVS.PASSWORD_HASH); | ||
const clientID = tlvs.first(TLVS.CLIENT_ID_STRING); | ||
|
||
return { screenname, passwordHash, clientID }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import assert from 'assert'; | ||
import { TLV } from './types'; | ||
import { MultiMap } from './MultiMap'; | ||
|
||
/** | ||
* @see http://iserverd1.khstu.ru/oscar/basic.html#b0003 | ||
*/ | ||
export function parseTLVs(data: Buffer) { | ||
const tlvs = new MultiMap<number, TLV>(); | ||
|
||
for (let cursor = 0; cursor < data.byteLength /* */; ) { | ||
const type = data.readUInt16BE(cursor); | ||
|
||
const lengthStart = cursor + 2; | ||
const length = data.readUInt16BE(lengthStart); | ||
|
||
const valueStart = lengthStart + 2; | ||
const valueEnd = valueStart + length; | ||
// A TLV's value can be 0 bytes. Odd that they're | ||
// not just excluded from the request, but ¯\_(ツ)_/¯ | ||
const value = length | ||
? data.subarray(valueStart, valueEnd) | ||
: // Empty buffer so we don't have to explicitly handle | ||
// a null/undefined anywhere a TLV type propagates | ||
Buffer.alloc(0); | ||
|
||
tlvs.set(type, { type, length, value }); | ||
|
||
cursor = valueEnd; | ||
assert(cursor <= data.byteLength, 'Overflow that should never happen'); | ||
} | ||
|
||
return tlvs; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import assert from 'assert'; | ||
import { buildSnac } from './snacUtils'; | ||
|
||
/** | ||
* @see http://iserverd1.khstu.ru/oscar/snac_17_07.html | ||
* @param authKey Key for client to use when encrypting password. Size should not exceed u32 int | ||
* @param reqID SNAC Request ID from client auth request | ||
*/ | ||
export function authKeyResponseSnac(authKey: string, reqID: number) { | ||
assert(authKey.length < 0xffff, 'authKey size exceeds u32 int'); | ||
|
||
const authKeyBuf = Buffer.from(authKey, 'ascii'); | ||
const authKeyLen = Buffer.alloc(32); | ||
authKeyLen.writeUInt32BE(authKeyBuf.byteLength, 0); | ||
|
||
return buildSnac({ | ||
family: 0x17, | ||
subtype: 0x7, | ||
reqID, | ||
data: Buffer.concat([authKeyLen, authKeyBuf]), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters