From 1c56a27409ad8bf5aba6c47d53a6278a91d3efb2 Mon Sep 17 00:00:00 2001 From: NLOG Date: Sat, 10 Oct 2020 10:08:51 +0900 Subject: [PATCH 1/6] Add generateAutoLoginToken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 자동 로그인 토큰 만드는 메서드 추가 --- src/api/auth-client.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api/auth-client.ts b/src/api/auth-client.ts index 16976722..991fb8b6 100644 --- a/src/api/auth-client.ts +++ b/src/api/auth-client.ts @@ -228,6 +228,18 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { return hash.digest('hex'); } + + generateAutoLoginToken(): string { + if (!this.accessData) throw new Error('Not logon'); + console.log(this.accessData); + let res = `PITT|${this.accessData.autoLoginEmail}|${this.accessData.refreshToken}|${this.deviceUUID}|INORAN`; + + let hash = crypto.createHash('sha512'); + + hash.update(res); + + return hash.digest('hex'); + } logout() { this.currentLogin = null; From 8cdc072d256dd435bcc4177843387a0360885a47 Mon Sep 17 00:00:00 2001 From: NLOG Date: Sat, 10 Oct 2020 10:14:06 +0900 Subject: [PATCH 2/6] Add generateAutoLoginToken --- src/api/auth-client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/auth-client.ts b/src/api/auth-client.ts index 991fb8b6..34ee0dc5 100644 --- a/src/api/auth-client.ts +++ b/src/api/auth-client.ts @@ -231,8 +231,7 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { generateAutoLoginToken(): string { if (!this.accessData) throw new Error('Not logon'); - console.log(this.accessData); - let res = `PITT|${this.accessData.autoLoginEmail}|${this.accessData.refreshToken}|${this.deviceUUID}|INORAN`; + let res = `PITT|${this.accessData.autoLoginEmail}|${this.accessData.refreshToken}|${this.deviceUUID}|INORAN`; let hash = crypto.createHash('sha512'); From 8fe856ac499ce713026d4cb1081c529992392b0f Mon Sep 17 00:00:00 2001 From: storycraft Date: Tue, 13 Oct 2020 23:10:52 +0900 Subject: [PATCH 3/6] Replace old auth api endpoint url --- src/api/auth-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/auth-client.ts b/src/api/auth-client.ts index 16976722..e19b9497 100644 --- a/src/api/auth-client.ts +++ b/src/api/auth-client.ts @@ -72,7 +72,7 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { } get Host() { - return 'ac-sb-talk.kakao.com'; + return 'katalk.kakao.com'; } get Agent() { From 5b386e2e0679df80dcf5c934eb0a00bfcb57894f Mon Sep 17 00:00:00 2001 From: storycraft Date: Tue, 13 Oct 2020 23:18:55 +0900 Subject: [PATCH 4/6] Add config entry xvcSeedList, loginTokenSeedList for future update --- src/api/auth-client.ts | 17 ++++++++--------- src/config/client-config.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/api/auth-client.ts b/src/api/auth-client.ts index 725f4de8..638fb94f 100644 --- a/src/api/auth-client.ts +++ b/src/api/auth-client.ts @@ -220,23 +220,22 @@ export class AuthClient extends WebApiClient implements AccessDataProvider { } calculateFullXVCKey(userAgent: string, email: string): string { - let res = `HEATH|${userAgent}|DEMIAN|${email}|${this.deviceUUID}`; + let config = this.ConfigProvider.Configuration; - let hash = crypto.createHash('sha512'); - - hash.update(res); + let source = `${config.xvcSeedList[0]}|${userAgent}|${config.xvcSeedList[1]}|${email}|${this.deviceUUID}`; + let hash = crypto.createHash('sha512'); + hash.update(source); return hash.digest('hex'); } generateAutoLoginToken(): string { - if (!this.accessData) throw new Error('Not logon'); - let res = `PITT|${this.accessData.autoLoginEmail}|${this.accessData.refreshToken}|${this.deviceUUID}|INORAN`; + let accessData = this.getLatestAccessData(); + let config = this.ConfigProvider.Configuration; + let source = `${config.loginTokenSeedList[0]}|${accessData.autoLoginEmail}|${accessData.refreshToken}|${this.deviceUUID}|${config.loginTokenSeedList[1]}`; let hash = crypto.createHash('sha512'); - - hash.update(res); - + hash.update(source); return hash.digest('hex'); } diff --git a/src/config/client-config.ts b/src/config/client-config.ts index 208f9f42..318043c3 100644 --- a/src/config/client-config.ts +++ b/src/config/client-config.ts @@ -29,7 +29,11 @@ export const DefaultConfiguration: ClientConfig = { language: 'ko', subDevice: true, - deviceModel: '' + deviceModel: '', + + xvcSeedList: [ 'HEATH', 'DEMIAN' ], + loginTokenSeedList: [ 'PITT', 'INORAN' ] + } export interface ClientConfig { @@ -56,4 +60,7 @@ export interface ClientConfig { subDevice: boolean; deviceModel: string; + xvcSeedList: [ string, string ]; + loginTokenSeedList: [ string, string ]; + } \ No newline at end of file From 3df81276d038d9b42064bd221c76462d90aab040 Mon Sep 17 00:00:00 2001 From: storycraft Date: Thu, 22 Oct 2020 19:55:51 +0900 Subject: [PATCH 5/6] Fix #71 incorrect implemention openlink join --- src/packet/loco-packet-list.ts | 3 ++ src/packet/packet-check-join.ts | 44 +++++++++++++++++++++++++++++ src/packet/packet-join-link.ts | 5 ++-- src/talk/channel/channel-manager.ts | 16 +++++++++-- 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/packet/packet-check-join.ts diff --git a/src/packet/loco-packet-list.ts b/src/packet/loco-packet-list.ts index 10754292..a0b81a5c 100644 --- a/src/packet/loco-packet-list.ts +++ b/src/packet/loco-packet-list.ts @@ -68,6 +68,7 @@ import { PacketKickLeaveRes, PacketKickLeaveReq } from "./packet-kick-leave"; import { PacketMultiPostReq, PacketMultiPostRes } from "./media/packet-multi-post"; import { PacketMultiShipReq, PacketMultiShipRes } from "./packet-multi-ship"; import { PacketForwardReq, PacketForwardRes } from "./packet-forward"; +import { PacketCheckJoinReq, PacketCheckJoinRes } from "./packet-check-join"; /* @@ -145,6 +146,7 @@ export namespace LocoPacketList { requestPacketMap.set('JOININFO', PacketJoinInfoReq); requestPacketMap.set('SETMEMTYPE', PacketSetMemTypeReq); requestPacketMap.set('JOINLINK', PacketJoinLinkReq); + requestPacketMap.set('CHECKJOIN', PacketCheckJoinReq); requestPacketMap.set('UPLINKPROF', PacketUpdateLinkProfileReq); requestPacketMap.set('SYNCMSG', PacketSyncMessageReq); @@ -245,6 +247,7 @@ export namespace LocoPacketList { responsePacketMap.set('SETMEMTYPE', PacketSetMemTypeRes); responsePacketMap.set('LINKKICKED', PacketLinkKickedRes); responsePacketMap.set('JOINLINK', PacketJoinLinkRes); + responsePacketMap.set('CHECKJOIN', PacketCheckJoinRes); responsePacketMap.set('UPLINKPROF', PacketUpdateLinkProfileRes); responsePacketMap.set('SYNCLINKPF', PacketSyncProfileRes); diff --git a/src/packet/packet-check-join.ts b/src/packet/packet-check-join.ts new file mode 100644 index 00000000..217e67c0 --- /dev/null +++ b/src/packet/packet-check-join.ts @@ -0,0 +1,44 @@ +import { Long } from "bson"; +/* + * Created on Thu Oct 22 2020 + * + * Copyright (c) storycraft. Licensed under the MIT Licence. + */ + +import { LocoBsonRequestPacket, LocoBsonResponsePacket } from "./loco-bson-packet"; + +export class PacketCheckJoinReq extends LocoBsonRequestPacket { + + constructor( + public LinkId: Long = Long.ZERO, + public Passcode: string = '' + ) { + super(); + } + + get PacketName() { + return 'CHECKJOIN'; + } + + toBodyJson() { + return { 'li': this.LinkId, 'pc': this.Passcode }; + } +} + +export class PacketCheckJoinRes extends LocoBsonResponsePacket { + + constructor( + status: number, + public Token: string = '' + ) { + super(status); + } + + get PacketName() { + return 'CHECKJOIN'; + } + + readBodyJson(rawBody: any) { + this.Token = rawBody['tk']; + } +} \ No newline at end of file diff --git a/src/packet/packet-join-link.ts b/src/packet/packet-join-link.ts index 22fb437a..fb3d0d8c 100644 --- a/src/packet/packet-join-link.ts +++ b/src/packet/packet-join-link.ts @@ -16,7 +16,7 @@ export class PacketJoinLinkReq extends LocoBsonRequestPacket { constructor( public LinkId: Long = Long.ZERO, public Referer: string = '', - public ChannelKey: string = '', + public JoinToken: string = '', public ProfileType: OpenProfileType = OpenProfileType.MAIN, @@ -36,10 +36,11 @@ export class PacketJoinLinkReq extends LocoBsonRequestPacket { let obj: any = { 'li': this.LinkId, 'ref': this.Referer, - 'tk': this.ChannelKey, 'ptp': this.ProfileType }; + if (this.JoinToken) obj['tk'] = this.JoinToken; + if (this.ProfileType === OpenProfileType.KAKAO_ANON) { if (this.Nickname !== '') obj['nn'] = this.Nickname; diff --git a/src/talk/channel/channel-manager.ts b/src/talk/channel/channel-manager.ts index b0b90eec..b5e137ca 100644 --- a/src/talk/channel/channel-manager.ts +++ b/src/talk/channel/channel-manager.ts @@ -37,6 +37,7 @@ import { OpenProfileTemplates } from "../open/open-link-profile-template"; import { PacketAddMemberReq, PacketAddMemberRes } from "../../packet/packet-add-member"; import { PacketKickLeaveReq, PacketKickLeaveRes } from "../../packet/packet-kick-leave"; import { JsonUtil } from "../../util/json-util"; +import { PacketCheckJoinReq, PacketCheckJoinRes } from "../../packet/packet-check-join"; export class ChannelManager extends IdStore { @@ -182,9 +183,20 @@ export class ChannelManager extends IdStore { } async joinOpenChannel(linkId: Long, profileTemplate: OpenProfileTemplates, passcode: string = ''): Promise> { - let packet = new PacketJoinLinkReq(linkId, 'EW:', passcode, profileTemplate.type, profileTemplate.anonNickname, profileTemplate.anonProfilePath, profileTemplate.profileLinkId); + let joinToken: string = ''; - let res = await this.client.NetworkManager.requestPacketRes(packet); + if (passcode) { + let checkPacket = new PacketCheckJoinReq(linkId, passcode); + let checkRes = await this.client.NetworkManager.requestPacketRes(checkPacket); + + if (checkRes.StatusCode !== StatusCode.SUCCESS) return { status: checkRes.StatusCode }; + + joinToken = checkRes.Token; + } + + let joinPacket = new PacketJoinLinkReq(linkId, 'EW:', joinToken, profileTemplate.type, profileTemplate.anonNickname, profileTemplate.anonProfilePath, profileTemplate.profileLinkId); + + let res = await this.client.NetworkManager.requestPacketRes(joinPacket); if (!res.ChatInfo || !res.LinkInfo) return { status: res.StatusCode }; From 0a14240f2d413cf6ef2f53d59bbf3210ef22cc96 Mon Sep 17 00:00:00 2001 From: storycraft Date: Thu, 22 Oct 2020 19:58:49 +0900 Subject: [PATCH 6/6] Update to 3.1.2 --- package.json | 2 +- src/api/open-chat-client.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d2370ff6..af6877a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-kakao", - "version": "3.1.1", + "version": "3.1.2", "description": "Loco protocol compatible library", "main": "dist/index.js", "scripts": { diff --git a/src/api/open-chat-client.ts b/src/api/open-chat-client.ts index 745f8fba..471dc4c1 100644 --- a/src/api/open-chat-client.ts +++ b/src/api/open-chat-client.ts @@ -47,7 +47,7 @@ export class OpenChatClient extends SessionApiClient { } async requestNewReactionList(): Promise { - return this.requestMapped('GET', OpenChatClient.getProfileApiPath('reacts/newMark'), OpenPostReactNotiStruct.MAPPER); + return this.requestMapped('GET', OpenChatClient.getProfileApiPath('reacts/newMark'), OpenPostReactNotiStruct.MAPPER); } async setRecommend(linkId: Long): Promise {