Skip to content

Commit 8794249

Browse files
committed
fix: #87
1 parent db8691d commit 8794249

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

packages/linejs/base/e2ee/mod.ts

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -888,24 +888,34 @@ export class E2EE {
888888
aes_iv,
889889
message,
890890
});
891-
const decipher = crypto.createDecipheriv(
892-
"aes-256-cbc",
893-
aes_key,
894-
aes_iv,
895-
);
891+
896892
let decrypted: Buffer | undefined;
893+
894+
// 最初の試行
897895
try {
896+
const decipher = crypto.createDecipheriv(
897+
"aes-256-cbc",
898+
aes_key,
899+
aes_iv,
900+
);
898901
decrypted = Buffer.concat([
899902
decipher.update(message),
900903
decipher.final(),
901904
]);
902-
} catch {
903-
decipher.setAutoPadding(false);
905+
} catch (error) {
906+
// エラー時は新しい decipher オブジェクトを作成
907+
const decipher2 = crypto.createDecipheriv(
908+
"aes-256-cbc",
909+
aes_key,
910+
aes_iv,
911+
);
912+
decipher2.setAutoPadding(false);
904913
decrypted = Buffer.concat([
905-
decipher.update(message),
906-
decipher.final(),
914+
decipher2.update(message),
915+
decipher2.final(),
907916
]);
908917
}
918+
909919
this.e2eeLog(
910920
"decryptE2EEMessageV1DecryptedMessage",
911921
decrypted.toString("utf-8"),
@@ -940,32 +950,45 @@ export class E2EE {
940950
contentType,
941951
);
942952

943-
const decipher = crypto.createDecipheriv("aes-256-gcm", gcmKey, sign);
944-
decipher.setAuthTag(tag);
945-
decipher.setAAD(aad);
946953
let decrypted;
954+
955+
// 最初の試行
947956
try {
957+
const decipher = crypto.createDecipheriv(
958+
"aes-256-gcm",
959+
gcmKey,
960+
sign,
961+
);
962+
decipher.setAuthTag(tag);
963+
decipher.setAAD(aad);
964+
decrypted = Buffer.concat([
965+
decipher.update(ciphertext),
966+
decipher.final(),
967+
]);
968+
} catch (error) {
969+
// エラー時は新しい decipher オブジェクトを作成
948970
try {
971+
const decipher2 = crypto.createDecipheriv(
972+
"aes-256-gcm",
973+
gcmKey,
974+
sign,
975+
);
976+
decipher2.setAuthTag(tag);
977+
decipher2.setAAD(aad);
978+
decipher2.setAutoPadding(false);
949979
decrypted = Buffer.concat([
950-
decipher.update(ciphertext),
951-
decipher.final(),
952-
]);
953-
} catch {
954-
decipher.setAutoPadding(false);
955-
decrypted = Buffer.concat([
956-
decipher.update(ciphertext),
957-
decipher.final(),
980+
decipher2.update(ciphertext),
981+
decipher2.final(),
958982
]);
983+
} catch (retryError) {
984+
if (retryError instanceof Error) {
985+
this.e2eeLog(
986+
"decryptE2EEMessageV2DecryptionFailed",
987+
retryError.message,
988+
);
989+
}
990+
throw retryError;
959991
}
960-
} catch (error) {
961-
if (error instanceof Error) {
962-
this.e2eeLog(
963-
"decryptE2EEMessageV2DecryptionFailed",
964-
error.message,
965-
);
966-
}
967-
968-
throw error;
969992
}
970993

971994
this.e2eeLog("decryptE2EEMessageV2DecryptedMessage", decrypted);

packages/linejs/base/service/relation/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class RelationService implements BaseService {
5050
}
5151

5252
async getContactsV3(
53-
options: { mids: string[], checkUserStatusStrictly?: boolean },
53+
options: { mids: string[]; checkUserStatusStrictly?: boolean },
5454
): Promise<LINETypes.getContactsV3_result["success"]> {
5555
return await this.client.request.request(
5656
LINEStruct.getContactsV3_args({
@@ -59,7 +59,7 @@ export class RelationService implements BaseService {
5959
targetUserMid: m,
6060
})),
6161
syncReason: "AUTO_REPAIR",
62-
checkUserStatusStrictly: options.checkUserStatusStrictly
62+
checkUserStatusStrictly: options.checkUserStatusStrictly,
6363
},
6464
}),
6565
"getContactsV3",

0 commit comments

Comments
 (0)