[go: nahoru, domu]

Skip to content

Commit

Permalink
done trying to figure out where these tlv tags are scoped to
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewML committed Dec 29, 2020
1 parent 51c4335 commit cd211d6
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 98 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ This has only been tested with AIM for Windows version `5.2.3292`, but theoretic
## Things I wish I knew before I started

- The [unofficial docs I was following for SNAC 17,07](http://iserverd1.khstu.ru/oscar/snac_17_07.html) are wrong about the size of the auth key length field (should be 2 byte, docs say 4)
- The list of TLV tags are scoped to each service. In other words, auth and boss servers can both have a TLV with tag 0x1, used for completely different things.
- TLV "tags" (integer used to represent them) seem to be reused often. In other words, auth and boss servers can both have multiple TLV with tag 0x1, used for completely different things. They seem to change per request/response
11 changes: 5 additions & 6 deletions src/AIMAuthServer/clientSnacs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { parseTLVs } from '../parseTLVs';
import { TLV } from '../types';

/**
* @see http://iserverd1.khstu.ru/oscar/snac_17_06.html
*/
export function parseAuthRequest(data: Buffer) {
const tlvs = parseTLVs(data);
const screennameTLV = tlvs.first(TLV.SCREENNAME);
const screennameTLV = tlvs.first(0x1);

return {
screenname: screennameTLV.value.toString('ascii'),
Expand All @@ -18,10 +17,10 @@ export function parseAuthRequest(data: Buffer) {
*/
export function parseMD5LoginRequest(data: Buffer) {
const tlvs = parseTLVs(data);
const screenname = tlvs.first(TLV.SCREENNAME).value.toString('ascii');
const newHashStrategy = tlvs.has(TLV.USE_NEW_HASH_STRATEGY);
const passwordHash = tlvs.first(TLV.PASSWORD_HASH).value;
const clientID = tlvs.first(TLV.CLIENT_ID_STRING).value.toString('ascii');
const screenname = tlvs.first(0x1).value.toString('ascii');
const newHashStrategy = tlvs.has(0x4c);
const passwordHash = tlvs.first(0x25).value;
const clientID = tlvs.first(0x3).value.toString('ascii');

return { screenname, passwordHash, clientID, newHashStrategy };
}
22 changes: 11 additions & 11 deletions src/AIMAuthServer/serverSnacs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TLVBuilder } from '../buildTLV';
import { buildSnac } from '../snacUtils';
import { SNACS } from '../constants';
import { uint16 } from '../buf';
import { TLV, LoginError } from '../types';
import { LoginError } from '../types';

/**
* @see http://iserverd1.khstu.ru/oscar/snac_17_07.html
Expand Down Expand Up @@ -37,9 +37,9 @@ export function loginErrorSnac(opts: {
reqID: number;
}) {
const tlv = new TLVBuilder()
.string(TLV.SCREENNAME, opts.screenname)
.uint16(TLV.ERROR_SUBCODE, opts.errorCode)
.string(TLV.ERROR_DESCRIP_URL, opts.errorURL);
.string(0x1, opts.screenname)
.uint16(0x8, opts.errorCode)
.string(0x4, opts.errorURL);

return buildSnac({
family: SNACS.AUTH.family,
Expand All @@ -63,13 +63,13 @@ export function loginSuccessSnac(opts: {
reqID: number;
}) {
const tlv = new TLVBuilder()
.string(TLV.SCREENNAME, opts.screenname)
.string(TLV.EMAIL, opts.email)
.string(TLV.BOS_ADDRESS, opts.bosAddress)
.string(TLV.AUTH_COOKIE, opts.authCookie)
.string(TLV.LATEST_BETA_VERSION, opts.latestBetaVersion)
.string(TLV.BETA_DIGEST_SIG, opts.latestBetaChecksum)
.string(TLV.CHANGE_PASSWORD_URL, opts.passwordChangeURL);
.string(0x1, opts.screenname)
.string(0x11, opts.email)
.string(0x5, opts.bosAddress)
.string(0x6, opts.authCookie)
.string(0x40, opts.latestBetaVersion)
.string(0x48, opts.latestBetaChecksum)
.string(0x54, opts.passwordChangeURL);

return buildSnac({
family: SNACS.AUTH.family,
Expand Down
3 changes: 1 addition & 2 deletions src/BossServer/clientSnacs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'assert';
import { parseTLVs } from '../parseTLVs';
import { TLV } from '../types';

/**
* @see http://iserverd.khstu.ru/oscar/cli_cookie.html
Expand All @@ -10,7 +9,7 @@ export function parseCookieRequest(data: Buffer) {
assert(flapVersion === 0x1, 'Incorrect client FLAP version');

const tlvs = parseTLVs(data.subarray(4));
const authCookie = tlvs.first(TLV.AUTH_COOKIE).value;
const authCookie = tlvs.first(0x6).value;

return { authCookie };
}
30 changes: 30 additions & 0 deletions src/BossServer/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const enum UserClass {
UNCONFIRMED = 0x1,
ADMIN = 0x2,
AOL_STAFF = 0x4,
AOL_COMMERCIAL = 0x8,
ICQ_FREE = 0x10,
AWAY = 0x20,
ICQ = 0x40,
WIRELESS = 0x80,
}

export const enum UserStatusFlag {
WEBAWARE = 0x1,
SHOWIP = 0x2,
BIRTHDAY = 0x8,
WEBFRONT = 0x20,
DC_DISABLED = 0x100,
DC_WITH_AUTH = 0x1000,
DC_WITH_CONTACTS = 0x2000,
}

export const enum UserStatus {
ONLINE = 0x0,
AWAY = 0x1,
DND = 0x2,
NA = 0x4,
BUSY = 0x10,
FREE_TO_CHAT = 0x20,
INVISIBLE = 0x100,
}
4 changes: 2 additions & 2 deletions src/BossServer/serverSnacs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildSnac } from '../snacUtils';
import { SNACS } from '../constants';
import { uint16 } from '../buf';
import { TLVBuilder } from '../buildTLV';
import { TLV, UserClass, UserStatus } from '../types';
import { UserClass, UserStatus } from './constants';

/**
* @see http://iserverd.khstu.ru/oscar/snac_01_03.html
Expand Down Expand Up @@ -107,7 +107,7 @@ export function selfInfoSnac(opts: {
memberSince: number;
reqID: number;
}) {
const tlv = new TLVBuilder();
// const tlv = new TLVBuilder().uint16(TLV.USER);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/buildTLV.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TLV } from './types';
import { uint16 } from './buf';

/**
Expand Down Expand Up @@ -44,7 +43,7 @@ export class TLVBuilder {
return Buffer.concat(this.tlvs);
}

uint8(tag: TLV, value: number) {
uint8(tag: number, value: number) {
const buf = Buffer.alloc(5);
buf.writeUInt16BE(tag);
buf.writeUInt16BE(1, 2);
Expand All @@ -53,7 +52,7 @@ export class TLVBuilder {
return this;
}

uint16(tag: TLV, value: number) {
uint16(tag: number, value: number) {
const buf = Buffer.alloc(6);
buf.writeUInt16BE(tag);
buf.writeUInt16BE(2, 2);
Expand All @@ -62,7 +61,7 @@ export class TLVBuilder {
return this;
}

uint32(tag: TLV, value: number) {
uint32(tag: number, value: number) {
const buf = Buffer.alloc(8);
buf.writeUInt16BE(tag);
buf.writeUInt16BE(4, 2);
Expand All @@ -71,7 +70,7 @@ export class TLVBuilder {
return this;
}

string(tag: TLV, value: string) {
string(tag: number, value: string) {
const typeAndLength = Buffer.alloc(4);
typeAndLength.writeUInt16BE(tag);
typeAndLength.writeUInt16BE(value.length, 2);
Expand Down
3 changes: 1 addition & 2 deletions src/parseTLVs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from 'assert';
import { TLV as TLVTag } from './types';
import { MultiMap } from './MultiMap';

/**
Expand All @@ -17,7 +16,7 @@ interface TLV {
* @todo Just for fun, should make a lazy variant of this parser
*/
export function parseTLVs(data: Buffer) {
const tlvs = new MultiMap<TLVTag, TLV>();
const tlvs = new MultiMap<number, TLV>();

for (let cursor = 0; cursor < data.byteLength /* */; ) {
const type = data.readUInt16BE(cursor);
Expand Down
69 changes: 0 additions & 69 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,6 @@ export const enum LoginError {
INCORRECT_NICK_OR_PASS = 0x4,
}

/**
* @see http://iserverd1.khstu.ru/oscar/tlv_tags.html
*/
export const enum TLV {
SCREENNAME = 0x1,
NEW_PASSWORD = 0x2,
CLIENT_ID_STRING = 0x3,
ERROR_DESCRIP_URL = 0x4,
BOS_ADDRESS = 0x5,
AUTH_COOKIE = 0x6,
SNAC_VERSION = 0x7,
ERROR_SUBCODE = 0x8,
DISCONNECT_REASON = 0x9,
RECONNECT_HOST = 0xa,
URL = 0xb,
DEBUG_DATA = 0xc,
FAMILY_ID = 0xd,
CLIENT_COUNTRY = 0xe,
CLIENT_LANG = 0xf,
SCRIPT = 0x10,
EMAIL = 0x11,
OLD_PASSWORD = 0x12,
REGISTRATION_STATUS = 0x13,
DISTRIBUTION_NUM = 0x14,
PERSONAL_TEXT = 0x15,
CLIENT_ID = 0x16,
CLIENT_MAJOR = 0x17,
CLIENT_MINOR = 0x18,
CLIENT_LESSER = 0x19,
CLIENT_BUILD = 0x1a,
PASSWORD_HASH = 0x25,
LATEST_BETA_VERSION = 0x40,
BETA_DIGEST_SIG = 0x48,
RELEASE_DIGEST_SIG = 0x49,
CHANGE_PASSWORD_URL = 0x54,
USE_NEW_HASH_STRATEGY = 0x4c,
}

export const enum UserClass {
UNCONFIRMED = 0x1,
ADMIN = 0x2,
AOL_STAFF = 0x4,
AOL_COMMERCIAL = 0x8,
ICQ_FREE = 0x10,
AWAY = 0x20,
ICQ = 0x40,
WIRELESS = 0x80,
}

export const enum UserStatusFlag {
WEBAWARE = 0x1,
SHOWIP = 0x2,
BIRTHDAY = 0x8,
WEBFRONT = 0x20,
DC_DISABLED = 0x100,
DC_WITH_AUTH = 0x1000,
DC_WITH_CONTACTS = 0x2000,
}

export const enum UserStatus {
ONLINE = 0x0,
AWAY = 0x1,
DND = 0x2,
NA = 0x4,
BUSY = 0x10,
FREE_TO_CHAT = 0x20,
INVISIBLE = 0x100,
}

/**
* @see http://web.archive.org/web/20080308233204/http://dev.aol.com/aim/oscar/#FLAP
*/
Expand Down

0 comments on commit cd211d6

Please sign in to comment.