-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'HSM-432/hardcode-pub-gpg-keys'
- Loading branch information
Showing
11 changed files
with
365 additions
and
40 deletions.
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
modules/bitgo/test/v2/unit/internal/tssUtils/bitgoMpcGpgPubKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import { | ||
BitgoMpcGpgPubKeys, | ||
common, | ||
ECDSAUtils, | ||
EddsaUtils, | ||
EnvironmentName, | ||
IRequestTracer, | ||
Wallet, | ||
} from '@bitgo/sdk-core'; | ||
import { TestBitGo } from '@bitgo/sdk-test'; | ||
|
||
import { BitGo } from '../../../../../src'; | ||
import * as openpgp from 'openpgp'; | ||
import nock = require('nock'); | ||
import assert = require('assert'); | ||
|
||
class TestEcdsaMpcv2Utils extends ECDSAUtils.EcdsaMPCv2Utils { | ||
public async testPickBitgoPubGpgKeyForSigning( | ||
isMpcv2: boolean, | ||
reqId?: IRequestTracer, | ||
enterpriseId?: string | ||
): Promise<openpgp.Key> { | ||
return this.pickBitgoPubGpgKeyForSigning(isMpcv2, reqId, enterpriseId); | ||
} | ||
} | ||
|
||
class TestEddsaMpcv1Utils extends EddsaUtils { | ||
public async testPickBitgoPubGpgKeyForSigning( | ||
isMpcv2: boolean, | ||
reqId?: IRequestTracer, | ||
enterpriseId?: string | ||
): Promise<openpgp.Key> { | ||
return this.pickBitgoPubGpgKeyForSigning(isMpcv2, reqId, enterpriseId); | ||
} | ||
} | ||
|
||
describe('TSS MPC Pick BitGo GPG Pub Key Utils:', function () { | ||
const walletId = '5b34252f1bf349930e34020a00000000'; | ||
const enterpriseId = '6449153a6f6bc20006d66771cdbe15d3'; | ||
const ecdsaCoinName = 'hteth'; | ||
const eddsaCoinName = 'tsol'; | ||
const ecdsaWalletData = { | ||
id: walletId, | ||
enterprise: enterpriseId, | ||
coin: ecdsaCoinName, | ||
coinSpecific: {}, | ||
multisigType: 'tss', | ||
keys: ['key1', 'key2', 'key3'], | ||
}; | ||
const eddsaWalletData = { | ||
id: walletId, | ||
enterprise: enterpriseId, | ||
coin: eddsaCoinName, | ||
coinSpecific: {}, | ||
multisigType: 'tss', | ||
keys: ['key1', 'key2', 'key3'], | ||
}; | ||
const envs: EnvironmentName[] = ['test', 'staging', 'prod']; | ||
const ecdsaMpcv2Utils: TestEcdsaMpcv2Utils[] = []; | ||
const eddsaMpcv1Utils: TestEddsaMpcv1Utils[] = []; | ||
|
||
before(async function () { | ||
nock.cleanAll(); | ||
for (const env of envs) { | ||
const bitgoInstance = TestBitGo.decorate(BitGo, { env }); | ||
bitgoInstance.initializeTestVars(); | ||
let coinInstance = bitgoInstance.coin(ecdsaCoinName); | ||
ecdsaMpcv2Utils.push( | ||
new TestEcdsaMpcv2Utils(bitgoInstance, coinInstance, new Wallet(bitgoInstance, coinInstance, ecdsaWalletData)) | ||
); | ||
coinInstance = bitgoInstance.coin(eddsaCoinName); | ||
eddsaMpcv1Utils.push( | ||
new TestEddsaMpcv1Utils(bitgoInstance, coinInstance, new Wallet(bitgoInstance, coinInstance, eddsaWalletData)) | ||
); | ||
} | ||
}); | ||
|
||
beforeEach(async function () { | ||
for (const env of envs) { | ||
const bgUrl = common.Environments[env].uri; | ||
nock(bgUrl).get(`/api/v2/${ecdsaCoinName}/key/key3`).times(envs.length).reply(200, { hsmType: 'onprem' }); | ||
nock(bgUrl).get(`/api/v2/${eddsaCoinName}/key/key3`).times(envs.length).reply(200, { hsmType: 'nitro' }); | ||
} | ||
}); | ||
|
||
envs.forEach(async function (env, index) { | ||
it(`should pick correct Mpcv2 BitGo GPG Pub Key for ${env} env`, async function () { | ||
const bitgoGpgPubKey = await ecdsaMpcv2Utils[index].testPickBitgoPubGpgKeyForSigning(true); | ||
bitgoGpgPubKey | ||
.armor() | ||
.should.equal(BitgoMpcGpgPubKeys.bitgoMpcGpgPubKeys['mpcv2']['onprem'][env === 'staging' ? 'test' : env]); | ||
}); | ||
}); | ||
|
||
envs.forEach(async function (env, index) { | ||
it(`should pick correct Mpcv1 BitGo GPG Pub Key for ${env} env`, async function () { | ||
const bitgoGpgPubKey = await eddsaMpcv1Utils[index].testPickBitgoPubGpgKeyForSigning(false); | ||
bitgoGpgPubKey | ||
.armor() | ||
.should.equal(BitgoMpcGpgPubKeys.bitgoMpcGpgPubKeys['mpcv1']['nitro'][env === 'staging' ? 'test' : env]); | ||
}); | ||
}); | ||
|
||
it(`should pick BitGo GPG Pub Key based on enterprise flag for mock env`, async function () { | ||
const bgUrl = common.Environments['mock'].uri; | ||
const testBitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
const testCoin = testBitgo.coin(ecdsaCoinName); | ||
const bitgoGPGKey = await openpgp.generateKey({ | ||
userIDs: [ | ||
{ | ||
name: 'bitgo', | ||
email: '[email protected]', | ||
}, | ||
], | ||
}); | ||
nock(bgUrl) | ||
.get(`/api/v2/${ecdsaCoinName}/tss/pubkey`) | ||
.query({ enterpriseId }) | ||
.reply(200, { mpcv2PublicKey: bitgoGPGKey.publicKey }); | ||
const ecdsaMpcv2Util = new TestEcdsaMpcv2Utils( | ||
testBitgo, | ||
testCoin, | ||
new Wallet(testBitgo, testCoin, ecdsaWalletData) | ||
); | ||
const bitgoGpgPubKey = await ecdsaMpcv2Util.testPickBitgoPubGpgKeyForSigning(true, undefined, enterpriseId); | ||
bitgoGpgPubKey.armor().should.equal(bitgoGPGKey.publicKey); | ||
}); | ||
|
||
it(`should pick BitGo GPG Pub Key based on constants api for mock env if enterprise flag based fetch fails`, async function () { | ||
nock.cleanAll(); | ||
const bgUrl = common.Environments['mock'].uri; | ||
const testBitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
const testCoin = testBitgo.coin(ecdsaCoinName); | ||
const bitgoGPGKey = await openpgp.generateKey({ | ||
userIDs: [ | ||
{ | ||
name: 'bitgo', | ||
email: '[email protected]', | ||
}, | ||
], | ||
}); | ||
const constants = { | ||
mpc: { | ||
bitgoMPCv2PublicKey: bitgoGPGKey.publicKey, | ||
bitgoPublicKey: bitgoGPGKey.publicKey, | ||
}, | ||
}; | ||
nock(bgUrl).get('/api/v1/client/constants').times(2).reply(200, { ttl: 3600, constants }); | ||
const ecdsaMpcv2Util = new TestEcdsaMpcv2Utils( | ||
testBitgo, | ||
testCoin, | ||
new Wallet(testBitgo, testCoin, ecdsaWalletData) | ||
); | ||
const bitgoGpgPubKey = await ecdsaMpcv2Util.testPickBitgoPubGpgKeyForSigning(true, undefined, enterpriseId); | ||
bitgoGpgPubKey.armor().should.equal(bitgoGPGKey.publicKey); | ||
}); | ||
|
||
it(`should throw an error if config is not available in one of test, staging, or prod`, async function () { | ||
nock.cleanAll(); | ||
const testBitgo = TestBitGo.decorate(BitGo, { env: 'test' }); | ||
const testCoin = testBitgo.coin(ecdsaCoinName); | ||
const ecdsaMpcv2Util = new TestEcdsaMpcv2Utils( | ||
testBitgo, | ||
testCoin, | ||
new Wallet(testBitgo, testCoin, ecdsaWalletData) | ||
); | ||
await assert.rejects(async () => await ecdsaMpcv2Util.testPickBitgoPubGpgKeyForSigning(true)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import assert from 'assert'; | ||
import { EnvironmentName } from '../environments'; | ||
|
||
export const bitgoMpcGpgPubKeys = { | ||
mpc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iEEAh1+UsErh14eiT6B\nCjAeAEwOVe0AAEcSAP9H96t/z9uKe9lAoq2d9Dt3Hrq9eM6sLQ2+cVblngP+\nDQD/dCqHYQzDdsuc9Y3HmWbhCK1Um6ewppkct1v5lmbaJ1bOTwRmYfIoEwUr\ngQQACgIDBJDIofWOLj/JkBFkZDh3a++LNEH8TBNlDZvU7tNfURXWApxV2VAb\nFBKYddN03Q1SBpMR0GkPl42rH7whYdeaEBHCwEoEGBMIALwFAmZh8ioCCwkJ\nEAowHgBMDlXtAhUIAhYAAhsCAh4BhSAEGBMIADYFAmZh8ioCCwkJEGAfBsMT\nFzVjAhUIAhYAAhsCAh4BFiEE2zAGHSaLnswqIvBrYB8GwxMXNWMAANroAP0f\ntFPumKFwQrCf7OMHQWsesrQYpKT6Z65VbewBoGaGigD/UkeeygTtlyzTV2YF\nNAjWAzaQtXWmmzRgnOj0IKub39MWIQQCHX5SwSuHXh6JPoEKMB4ATA5V7QAA\nTjMA/jDSVXJNblr/kSLNFTordgDjKP0nN1aElvFUFh/QEVT0AP9lmf2Fc/o7\nyYOGPPg4OvvU6odrTsuNgljvPqBlaCc2EA==\n=ZLkt\n-----END PGP PUBLIC KEY BLOCK-----\n', | ||
}, | ||
}, | ||
}; | ||
|
||
export function getBitgoMpcGpgPubKey( | ||
env: EnvironmentName, | ||
pubKeyType: 'nitro' | 'onprem', | ||
mpcVersion: 'mpcv1' | 'mpcv2' | ||
): string { | ||
assert( | ||
mpcVersion in bitgoMpcGpgPubKeys, | ||
`Invalid mpcVersion in getBitgoMpcGpgPubKey, got: ${mpcVersion}, expected: mpcv1 or mpcv2` | ||
); | ||
assert( | ||
pubKeyType in bitgoMpcGpgPubKeys[mpcVersion], | ||
`Invalid pubKeyType in getBitgoMpcGpgPubKey, got: ${pubKeyType}, expected: nitro or onprem` | ||
); | ||
if (env !== 'prod' && env !== 'test' && env !== 'staging' && env !== 'adminProd' && env !== 'adminTest') { | ||
throw new Error('Invalid environment to get a BitGo MPC GPG public key'); | ||
} | ||
if (env !== 'prod' && env !== 'adminProd') { | ||
// default to test gpg keys if not in prod | ||
env = 'test'; | ||
} | ||
if (env === 'adminProd') { | ||
env = 'prod'; | ||
} | ||
if (pubKeyType === 'nitro' && env === 'prod' && mpcVersion === 'mpcv2') { | ||
throw new Error('Nitro mpcv2 pub key is not available in production environments yet.'); | ||
} | ||
if (pubKeyType !== 'nitro') { | ||
// This will be the default key type | ||
pubKeyType = 'onprem'; | ||
} | ||
return bitgoMpcGpgPubKeys[mpcVersion][pubKeyType][env]; | ||
} | ||
|
||
export function isBitgoMpcPubKey(key: string, mpcvVersion: 'mpcv1' | 'mpcv2'): boolean { | ||
return Object.values(bitgoMpcGpgPubKeys[mpcvVersion]).some((envKeys) => Object.values(envKeys).includes(key)); | ||
} | ||
|
||
export function envRequiresBitgoPubGpgKeyConfig(env: EnvironmentName): boolean { | ||
return env === 'prod' || env === 'test' || env === 'staging' || env === 'adminProd' || env === 'adminTest'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.