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

build: add separate keypairs for dev environment #73

Merged
merged 5 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions spec/keys.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { SIGNING_KEYS } from '../src/resource/signing-keys'
import { VERIFICATION_KEYS } from '../src/resource/verification-keys'

describe('Key lengths', () => {
// ED25519 key lengths in base64
const PUBLIC_KEY_LENGTH = 44
const SECRET_KEY_LENGTH = 88

describe('Verification keys', () => {
describe('Public keys', () => {
it('should have the correct length for ED25519 public keys', () => {
expect(VERIFICATION_KEYS.development.publicKey).toHaveLength(
PUBLIC_KEY_LENGTH
)
expect(VERIFICATION_KEYS.test.publicKey).toHaveLength(PUBLIC_KEY_LENGTH)
expect(VERIFICATION_KEYS.staging.publicKey).toHaveLength(
PUBLIC_KEY_LENGTH
)
expect(VERIFICATION_KEYS.production.publicKey).toHaveLength(
PUBLIC_KEY_LENGTH
)
})
})

describe('Secret keys', () => {
it('should have the correct length for ED25519 secret keys in test and dev mode', () => {
expect(VERIFICATION_KEYS.development.secretKey).toHaveLength(
SECRET_KEY_LENGTH
)
expect(VERIFICATION_KEYS.test.secretKey).toHaveLength(SECRET_KEY_LENGTH)
})
})
})

describe('Signing keys', () => {
describe('Public keys', () => {
it('should have the correct length for ED25519 public keys', () => {
expect(SIGNING_KEYS.development.publicKey).toHaveLength(
PUBLIC_KEY_LENGTH
)
expect(SIGNING_KEYS.test.publicKey).toHaveLength(PUBLIC_KEY_LENGTH)
expect(SIGNING_KEYS.staging.publicKey).toHaveLength(PUBLIC_KEY_LENGTH)
expect(SIGNING_KEYS.production.publicKey).toHaveLength(
PUBLIC_KEY_LENGTH
)
})
})

describe('Secret keys', () => {
it('should have the correct length for ED25519 secret keys in test and dev mode', () => {
expect(SIGNING_KEYS.development.secretKey).toHaveLength(
SECRET_KEY_LENGTH
)
expect(SIGNING_KEYS.test.secretKey).toHaveLength(SECRET_KEY_LENGTH)
})
})
})
})
5 changes: 3 additions & 2 deletions src/resource/signing-keys.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// keys generated using nacl.sign.keyPair() from tweetnacl
export const SIGNING_KEYS = {
staging: {
// staging must never contain secret keys
publicKey: 'rjv41kYqZwcbe3r6ymMEEKQ+Vd+DPuogN+Gzq3lP2Og=',
},
development: {
// Using the same keys for staging.
publicKey: 'rjv41kYqZwcbe3r6ymMEEKQ+Vd+DPuogN+Gzq3lP2Og=',
publicKey: 'Tl5gfszlKcQj99/0uafLwVpT6JAu4C0dHGvLq1cHzFE=',
secretKey: 'HDBXpu+2/gu10bLHpy8HjpN89xbA6boH9GwibPGJA8BOXmB+zOUpxCP33/S5p8vBWlPokC7gLR0ca8urVwfMUQ==',
},
production: {
// production must never contain secret keys
Expand Down
5 changes: 3 additions & 2 deletions src/resource/verification-keys.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// keys generated using nacl.sign.keyPair() from tweetnacl
export const VERIFICATION_KEYS = {
staging: {
// staging must never contain secret keys
publicKey: 'bDgK1223JbrDNePFIrj7b0z02Z5nSiBzkRYRqDdVPfA=',
},
development: {
// Using the same keys for staging.
publicKey: 'bDgK1223JbrDNePFIrj7b0z02Z5nSiBzkRYRqDdVPfA=',
publicKey: 'SZ4pV0JXgj8dhFU69uHllqYcxTtliYmi+d6Ml56lnQU=',
secretKey: 'iGkfOuI6uxrlfw+7CZFFUZBwk86I+pu6v+g7EWA6qJpJnilXQleCPx2EVTr24eWWphzFO2WJiaL53oyXnqWdBQ==',
},
production: {
// production must never contain secret keys
Expand Down
2 changes: 2 additions & 0 deletions src/util/publicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import STAGE from './stage'
function getSigningPublicKey(mode?: PackageMode) {
switch (mode) {
case STAGE.development:
return SIGNING_KEYS.development.publicKey
case STAGE.staging:
return SIGNING_KEYS.staging.publicKey
case STAGE.test:
Expand All @@ -29,6 +30,7 @@ function getSigningPublicKey(mode?: PackageMode) {
function getVerificationPublicKey(mode?: PackageMode) {
switch (mode) {
case STAGE.development:
return VERIFICATION_KEYS.development.publicKey
case STAGE.staging:
return VERIFICATION_KEYS.staging.publicKey
case STAGE.test:
Expand Down