Skip to content

Commit

Permalink
feat: Implement functions to (de)serialize RSA and ECDH keys
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Jan 16, 2020
1 parent ce6de8d commit 851aa17
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setEngine('nodeEngine', webcrypto, cryptoEngine);
//region Exports

export { default as RelaynetError } from './lib/RelaynetError';
export * from './lib/crypto_wrappers/keyGenerators';
export * from './lib/crypto_wrappers/keys';

// PKI
export { default as Certificate } from './lib/crypto_wrappers/x509/Certificate';
Expand Down
20 changes: 9 additions & 11 deletions src/integration_tests/channelSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import bufferToArray from 'buffer-to-arraybuffer';
import * as pkijs from 'pkijs';

import { expectBuffersToEqual } from '../lib/_test_utils';
import { getPkijsCrypto } from '../lib/crypto_wrappers/_utils';
import { SessionEnvelopedData } from '../lib/crypto_wrappers/cms/envelopedData';
import { generateECDHKeyPair, generateRSAKeyPair } from '../lib/crypto_wrappers/keyGenerators';
import {
derDeserializeECDHPublicKey,
generateECDHKeyPair,
generateRSAKeyPair,
} from '../lib/crypto_wrappers/keys';
import Certificate from '../lib/crypto_wrappers/x509/Certificate';
import { issueInitialDHKeyCertificate, issueNodeCertificate } from '../lib/pki';

const cryptoEngine = getPkijsCrypto();

const TOMORROW = new Date();
TOMORROW.setDate(TOMORROW.getDate() + 1);

Expand Down Expand Up @@ -104,13 +105,10 @@ test('Encryption and decryption with subsequent DH keys', async () => {
});

async function deserializeDhPublicKey(publicKeyDer: ArrayBuffer): Promise<CryptoKey> {
return cryptoEngine.importKey(
'spki',
publicKeyDer,
{ name: 'ECDH', namedCurve: 'P-256' },
true,
[],
);
return derDeserializeECDHPublicKey(Buffer.from(publicKeyDer), {
name: 'ECDH',
namedCurve: 'P-256',
});
}

function checkRecipientInfo(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Parcel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import bufferToArray from 'buffer-to-arraybuffer';

import { generateStubCert, getMockContext } from './_test_utils';
import { generateRSAKeyPair } from './crypto_wrappers/keyGenerators';
import { generateRSAKeyPair } from './crypto_wrappers/keys';
import Parcel from './Parcel';
import * as serialization from './ramf/serialization';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/_test_utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash } from 'crypto';
import * as pkijs from 'pkijs';

import { generateRSAKeyPair } from './crypto_wrappers/keyGenerators';
import { generateRSAKeyPair } from './crypto_wrappers/keys';
import Certificate from './crypto_wrappers/x509/Certificate';
import CertificateOptions from './crypto_wrappers/x509/CertificateOptions';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto_wrappers/cms/envelopedData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../_test_utils';
import * as oids from '../../oids';
import { issueInitialDHKeyCertificate } from '../../pki';
import { generateECDHKeyPair, generateRSAKeyPair } from '../keyGenerators';
import { generateECDHKeyPair, generateRSAKeyPair } from '../keys';
import Certificate from '../x509/Certificate';
import { deserializeContentInfo } from './_test_utils';
import CMSError from './CMSError';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto_wrappers/cms/signedData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
sha256Hex,
} from '../../_test_utils';
import * as oids from '../../oids';
import { generateRSAKeyPair } from '../keyGenerators';
import { generateRSAKeyPair } from '../keys';
import Certificate from '../x509/Certificate';
import { deserializeContentInfo } from './_test_utils';
import CMSError from './CMSError';
Expand Down
142 changes: 0 additions & 142 deletions src/lib/crypto_wrappers/keyGenerators.spec.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/lib/crypto_wrappers/keyGenerators.ts

This file was deleted.

Loading

0 comments on commit 851aa17

Please sign in to comment.