Skip to content

Commit 4975807

Browse files
committed
chore(sdk-core): remove gpg encryption of passkey access token
Ticket: WP-3021 TICKET: WP-3021
1 parent 850d035 commit 4975807

File tree

2 files changed

+4
-126
lines changed

2 files changed

+4
-126
lines changed

modules/bitgo/test/unit/bitgo.ts

Lines changed: 3 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as nock from 'nock';
77
import * as should from 'should';
88
import assert = require('assert');
99

10-
import { common, generateGPGKeyPair, encryptAndSignText } from '@bitgo/sdk-core';
10+
import { common, generateGPGKeyPair } from '@bitgo/sdk-core';
1111
import { bip32, ECPair } from '@bitgo/utxo-lib';
1212
import * as _ from 'lodash';
1313
import * as BitGoJS from '../../src/index';
@@ -709,19 +709,12 @@ describe('BitGo Prototype Methods', function () {
709709
.post('/api/auth/v1/session')
710710
.reply(200, async (uri, requestBody) => {
711711
assert(typeof requestBody === 'object');
712-
should.exist(requestBody.publicKey);
713712
should.exist(requestBody.userId);
714713
should.exist(requestBody.passkey);
715714
requestBody.userId.should.equal(userId);
716715
requestBody.passkey.should.equal(passkey);
717-
const encryptedToken = (await encryptAndSignText(
718-
'access_token',
719-
requestBody.publicKey,
720-
keyPair.privateKey
721-
)) as string;
722-
723716
return {
724-
encryptedToken: encryptedToken,
717+
access_token: 'access_token',
725718
user: { username: '[email protected]' },
726719
};
727720
});
@@ -732,105 +725,6 @@ describe('BitGo Prototype Methods', function () {
732725
response.access_token.should.equal('access_token');
733726
});
734727

735-
it('should not authenticate with wrong encryption key', async () => {
736-
const keyPair = await generateGPGKeyPair('secp256k1');
737-
738-
nock('https://bitgo.fakeurl')
739-
.persist()
740-
.get('/api/v1/client/constants')
741-
.reply(200, { ttl: 3600, constants: { passkeyBitGoGpgKey: keyPair.publicKey } });
742-
nock('https://bitgo.fakeurl')
743-
.post('/api/auth/v1/session')
744-
.reply(200, async () => {
745-
const keyPair = await generateGPGKeyPair('secp256k1');
746-
const encryptedToken = (await encryptAndSignText(
747-
'access_token',
748-
keyPair.publicKey,
749-
keyPair.privateKey
750-
)) as string;
751-
return {
752-
encryptedToken: encryptedToken,
753-
user: { username: '[email protected]' },
754-
};
755-
});
756-
757-
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' });
758-
try {
759-
await bitgo.authenticateWithPasskey(
760-
'{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "123"}}'
761-
);
762-
assert.fail('Expected error not thrown');
763-
} catch (e) {
764-
assert.equal(e.message, 'Error decrypting message: Session key decryption failed.');
765-
}
766-
});
767-
768-
it('should not authenticate with wrong signing key', async () => {
769-
const userId = '123';
770-
const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "${userId}"}}`;
771-
const badKeyPair = await generateGPGKeyPair('secp256k1');
772-
const bitgoKeyPair = await generateGPGKeyPair('secp256k1');
773-
774-
nock('https://bitgo.fakeurl')
775-
.persist()
776-
.get('/api/v1/client/constants')
777-
.reply(200, { ttl: 3600, constants: { passkeyBitGoGpgKey: bitgoKeyPair.publicKey } });
778-
779-
nock('https://bitgo.fakeurl')
780-
.post('/api/auth/v1/session')
781-
.reply(200, async (uri, requestBody) => {
782-
assert(typeof requestBody === 'object');
783-
const encryptedToken = (await encryptAndSignText(
784-
'access_token',
785-
requestBody.publicKey,
786-
badKeyPair.privateKey
787-
)) as string;
788-
789-
return {
790-
encryptedToken: encryptedToken,
791-
user: { username: '[email protected]' },
792-
};
793-
});
794-
795-
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' });
796-
try {
797-
await bitgo.authenticateWithPasskey(passkey);
798-
assert.fail('Expected error not thrown');
799-
} catch (e) {
800-
assert(e.message.startsWith('Error decrypting message: Could not find signing key with key ID'));
801-
}
802-
});
803-
it('should throw - missing bitgo public key', async () => {
804-
const userId = '123';
805-
const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "${userId}"}}`;
806-
const keyPair = await generateGPGKeyPair('secp256k1');
807-
808-
nock('https://bitgo.fakeurl').persist().get('/api/v1/client/constants').reply(200, { ttl: 3600, constants: {} });
809-
810-
nock('https://bitgo.fakeurl')
811-
.post('/api/auth/v1/session')
812-
.reply(200, async (uri, requestBody) => {
813-
assert(typeof requestBody === 'object');
814-
const encryptedToken = (await encryptAndSignText(
815-
'access_token',
816-
requestBody.publicKey,
817-
keyPair.privateKey
818-
)) as string;
819-
820-
return {
821-
encryptedToken: encryptedToken,
822-
user: { username: '[email protected]' },
823-
};
824-
});
825-
826-
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' });
827-
try {
828-
await bitgo.authenticateWithPasskey(passkey);
829-
assert.fail('Expected error not thrown');
830-
} catch (e) {
831-
assert.equal(e.message, 'Unable to get passkeyBitGoGpgKey');
832-
}
833-
});
834728
it('should throw - invalid userHandle', async () => {
835729
const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": 123}}`;
836730
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' });
@@ -862,7 +756,7 @@ describe('BitGo Prototype Methods', function () {
862756
assert(e.message.includes('JSON'));
863757
}
864758
});
865-
it('should throw - missing encrypted token', async () => {
759+
it('should throw - missing access token', async () => {
866760
const passkey = `{"id": "id", "response": { "authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "123"}}`;
867761
nock('https://bitgo.fakeurl')
868762
.post('/api/auth/v1/session')

modules/sdk-api/src/bitgoAPI.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import {
2020
IRequestTracer,
2121
makeRandomKey,
2222
sanitizeLegacyPath,
23-
generateGPGKeyPair,
24-
readSignedMessage,
2523
} from '@bitgo/sdk-core';
2624
import * as sjcl from '@bitgo/sjcl';
2725
import * as utxolib from '@bitgo/utxo-lib';
@@ -958,31 +956,17 @@ export class BitGoAPI implements BitGoBase {
958956
this.validatePasskeyResponse(passkey);
959957
const userId = JSON.parse(passkey).response.userHandle;
960958

961-
const userGpgKey = await generateGPGKeyPair('secp256k1');
962959
const response: superagent.Response = await request.send({
963960
passkey: passkey,
964961
userId: userId,
965-
publicKey: userGpgKey.publicKey,
966962
});
967963
// extract body and user information
968964
const body = response.body;
969965
this._user = body.user;
970966

971967
if (body.access_token) {
972968
this._token = body.access_token;
973-
} else if (body.encryptedToken) {
974-
const constants = await this.fetchConstants();
975-
976-
if (!constants.passkeyBitGoGpgKey) {
977-
throw new Error('Unable to get passkeyBitGoGpgKey');
978-
}
979-
980-
const access_token = await readSignedMessage(
981-
body.encryptedToken,
982-
constants.passkeyBitGoGpgKey,
983-
userGpgKey.privateKey
984-
);
985-
response.body.access_token = access_token;
969+
response.body.access_token = body.access_token;
986970
} else {
987971
throw new Error('Failed to login. Please contact [email protected]');
988972
}

0 commit comments

Comments
 (0)