Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fixed IG Accounts without a Facebook account failing login due to 400 Bad Request #1752

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions src/repositories/account.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class AccountRepository extends Repository {
if (!this.client.state.passwordEncryptionPubKey) {
await this.client.qe.syncLoginExperiments();
}
const {encrypted, time} = this.encryptPassword(password);
const { encrypted, time } = this.encryptPassword(password);
const response = await Bluebird.try(() =>
this.client.request.send<AccountRepositoryLoginResponseRootObject>({
method: 'POST',
url: '/api/v1/accounts/login/',
url: '/api/v1/web/accounts/login/ajax/',
form: this.client.request.sign({
username,
enc_password: `#PWD_INSTAGRAM:4:${time}:${encrypted}`,
Expand Down Expand Up @@ -76,14 +76,17 @@ export class AccountRepository extends Repository {
return `2${sum}`;
}

public encryptPassword(password: string): { time: string, encrypted: string } {
public encryptPassword(password: string): { time: string; encrypted: string } {
const randKey = crypto.randomBytes(32);
const iv = crypto.randomBytes(12);
const rsaEncrypted = crypto.publicEncrypt({
key: Buffer.from(this.client.state.passwordEncryptionPubKey, 'base64').toString(),
// @ts-ignore
padding: crypto.constants.RSA_PKCS1_PADDING,
}, randKey);
const rsaEncrypted = crypto.publicEncrypt(
{
key: Buffer.from(this.client.state.passwordEncryptionPubKey, 'base64').toString(),
// @ts-ignore
padding: crypto.constants.RSA_PKCS1_PADDING,
},
randKey,
);
const cipher = crypto.createCipheriv('aes-256-gcm', randKey, iv);
const time = Math.floor(Date.now() / 1000).toString();
cipher.setAAD(Buffer.from(time));
Expand All @@ -97,8 +100,10 @@ export class AccountRepository extends Repository {
Buffer.from([1, this.client.state.passwordEncryptionKeyId]),
iv,
sizeBuffer,
rsaEncrypted, authTag, aesEncrypted])
.toString('base64'),
rsaEncrypted,
authTag,
aesEncrypted,
]).toString('base64'),
};
}

Expand All @@ -109,17 +114,15 @@ export class AccountRepository extends Repository {
trustThisDevice: '1',
verificationMethod: '1',
});
const { body } = await this.client.request.send<AccountRepositoryLoginResponseLogged_in_user>({
url: '/api/v1/accounts/two_factor_login/',
const { body } = await this.client.request.send({
url: '/api/v1/web/accounts/login/ajax/two_factor/',
method: 'POST',
form: this.client.request.sign({
verification_code: options.verificationCode,
_csrftoken: this.client.state.cookieCsrfToken,
two_factor_identifier: options.twoFactorIdentifier,
identifier: options.twoFactorIdentifier,
verificationCode: options.verificationCode,
username: options.username,
trust_this_device: options.trustThisDevice,
guid: this.client.state.uuid,
device_id: this.client.state.deviceId,
trust_signal: options.trustThisDevice === '1' ? 'true' : 'false',
verification_method: options.verificationMethod,
}),
});
Expand Down