nodejs-insta-private-api-mqt 1.3.82 → 1.3.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1138,34 +1138,74 @@ class AccountRepository extends Repository {
|
|
|
1138
1138
|
});
|
|
1139
1139
|
}
|
|
1140
1140
|
|
|
1141
|
-
|
|
1141
|
+
static generateAttestParams(state) {
|
|
1142
|
+
// Emulate Instagram's keystore attestation as closely as possible:
|
|
1143
|
+
// - version: 2
|
|
1144
|
+
// - type: "keystore"
|
|
1145
|
+
// - errors: [0]
|
|
1146
|
+
// - challenge_nonce: random base64url
|
|
1147
|
+
// - signed_nonce: ECDSA signature over the nonce
|
|
1148
|
+
// - key_hash: sha256(spki(publicKey))
|
|
1149
|
+
// - certificate_chain: 4 PEM certificates concatenated (leaf + 2 intermediates + root)
|
|
1150
|
+
//
|
|
1151
|
+
// NOTE: This is *not* a real hardware-backed attestation chain, but it mirrors
|
|
1152
|
+
// the structure of the official app very closely so the server sees the same
|
|
1153
|
+
// shape: a single attestation object with a 4‑certificate chain.
|
|
1142
1154
|
const challengeNonce = crypto.randomBytes(24).toString('base64url');
|
|
1143
1155
|
|
|
1144
1156
|
const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
|
|
1145
1157
|
namedCurve: 'prime256v1',
|
|
1146
1158
|
});
|
|
1147
1159
|
|
|
1160
|
+
// Sign the challenge nonce with the private key (simulating TEE signing).
|
|
1148
1161
|
const signedData = crypto.sign(null, Buffer.from(challengeNonce), privateKey);
|
|
1149
1162
|
const signedNonce = signedData.toString('base64');
|
|
1150
1163
|
|
|
1151
1164
|
const publicKeyDer = publicKey.export({ type: 'spki', format: 'der' });
|
|
1152
1165
|
const keyHash = crypto.createHash('sha256').update(publicKeyDer).digest('hex');
|
|
1153
1166
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1167
|
+
// Build a 4‑certificate chain (leaf + 2 intermediates + root), just like
|
|
1168
|
+
// what we saw in the captured traffic from the real Instagram app.
|
|
1169
|
+
const leafCertPem = AccountRepository._generateSelfSignedCert(
|
|
1170
|
+
privateKey,
|
|
1171
|
+
publicKey,
|
|
1172
|
+
'Android Keystore Key'
|
|
1173
|
+
);
|
|
1174
|
+
const intermediate1Pem = AccountRepository._generateSelfSignedCert(
|
|
1175
|
+
privateKey,
|
|
1176
|
+
publicKey,
|
|
1177
|
+
'Android Keystore Key Attestation'
|
|
1178
|
+
);
|
|
1179
|
+
const intermediate2Pem = AccountRepository._generateSelfSignedCert(
|
|
1180
|
+
privateKey,
|
|
1181
|
+
publicKey,
|
|
1182
|
+
'Android Hardware Keystore'
|
|
1183
|
+
);
|
|
1184
|
+
const rootCertPem = AccountRepository._generateSelfSignedCert(
|
|
1185
|
+
privateKey,
|
|
1186
|
+
publicKey,
|
|
1187
|
+
'Android Keystore Root'
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1190
|
+
const certificateChain = [
|
|
1191
|
+
leafCertPem,
|
|
1192
|
+
intermediate1Pem,
|
|
1193
|
+
intermediate2Pem,
|
|
1194
|
+
rootCertPem,
|
|
1195
|
+
].join('\n');
|
|
1158
1196
|
|
|
1159
1197
|
return {
|
|
1160
|
-
attestation: [
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1198
|
+
attestation: [
|
|
1199
|
+
{
|
|
1200
|
+
version: 2,
|
|
1201
|
+
type: 'keystore',
|
|
1202
|
+
errors: [0],
|
|
1203
|
+
challenge_nonce: challengeNonce,
|
|
1204
|
+
signed_nonce: signedNonce,
|
|
1205
|
+
key_hash: keyHash,
|
|
1206
|
+
certificate_chain: certificateChain,
|
|
1207
|
+
},
|
|
1208
|
+
],
|
|
1169
1209
|
};
|
|
1170
1210
|
}
|
|
1171
1211
|
|
package/package.json
CHANGED