Fix tests on IE11
This commit is contained in:
parent
29271accef
commit
61a0e3fa69
|
@ -138,6 +138,7 @@ describe('Elliptic Curve Cryptography', function () {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
signature_data.hashed = openpgp.crypto.hash.digest(8, signature_data.message);
|
||||||
describe('Basic Operations', function () {
|
describe('Basic Operations', function () {
|
||||||
it('Creating curve from name or oid', function (done) {
|
it('Creating curve from name or oid', function (done) {
|
||||||
for (let name_or_oid in openpgp.enums.curves) {
|
for (let name_or_oid in openpgp.enums.curves) {
|
||||||
|
@ -171,24 +172,24 @@ describe('Elliptic Curve Cryptography', function () {
|
||||||
const curve = new elliptic_curves.Curve('p256');
|
const curve = new elliptic_curves.Curve('p256');
|
||||||
const key = curve.keyFromPublic(signature_data.pub);
|
const key = curve.keyFromPublic(signature_data.pub);
|
||||||
expect(
|
expect(
|
||||||
key.verify(signature_data.message, signature_data.signature, 8)
|
key.verify(signature_data.message, signature_data.signature, 8, signature_data.hashed)
|
||||||
).to.eventually.be.true.notify(done);
|
).to.eventually.be.true.notify(done);
|
||||||
});
|
});
|
||||||
it('Invalid signature', function (done) {
|
it('Invalid signature', function (done) {
|
||||||
const curve = new elliptic_curves.Curve('p256');
|
const curve = new elliptic_curves.Curve('p256');
|
||||||
const key = curve.keyFromPublic(key_data.p256.pub);
|
const key = curve.keyFromPublic(key_data.p256.pub);
|
||||||
expect(
|
expect(
|
||||||
key.verify(signature_data.message, signature_data.signature, 8)
|
key.verify(signature_data.message, signature_data.signature, 8, signature_data.hashed)
|
||||||
).to.eventually.be.false.notify(done);
|
).to.eventually.be.false.notify(done);
|
||||||
});
|
});
|
||||||
it('Signature generation', function () {
|
it('Signature generation', function () {
|
||||||
const curve = new elliptic_curves.Curve('p256');
|
const curve = new elliptic_curves.Curve('p256');
|
||||||
let key = curve.keyFromPrivate(key_data.p256.priv);
|
let key = curve.keyFromPrivate(key_data.p256.priv);
|
||||||
return key.sign(signature_data.message, 8).then(async ({ r, s }) => {
|
return key.sign(signature_data.message, 8, signature_data.hashed).then(async ({ r, s }) => {
|
||||||
const signature = { r: new Uint8Array(r.toArray()), s: new Uint8Array(s.toArray()) };
|
const signature = { r: new Uint8Array(r.toArray()), s: new Uint8Array(s.toArray()) };
|
||||||
key = curve.keyFromPublic(key_data.p256.pub);
|
key = curve.keyFromPublic(key_data.p256.pub);
|
||||||
await expect(
|
await expect(
|
||||||
key.verify(signature_data.message, signature, 8)
|
key.verify(signature_data.message, signature, 8, signature_data.hashed)
|
||||||
).to.eventually.be.true;
|
).to.eventually.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -213,7 +214,7 @@ describe('Elliptic Curve Cryptography', function () {
|
||||||
}
|
}
|
||||||
const ecdsa = elliptic_curves.ecdsa;
|
const ecdsa = elliptic_curves.ecdsa;
|
||||||
return ecdsa.verify(
|
return ecdsa.verify(
|
||||||
oid, hash, { r: new Uint8Array(r), s: new Uint8Array(s) }, message, new Uint8Array(pub)
|
oid, hash, { r: new Uint8Array(r), s: new Uint8Array(s) }, message, new Uint8Array(pub), openpgp.crypto.hash.digest(hash, message)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const secp256k1_dummy_value = new Uint8Array([
|
const secp256k1_dummy_value = new Uint8Array([
|
||||||
|
@ -295,8 +296,8 @@ describe('Elliptic Curve Cryptography', function () {
|
||||||
const keyPrivate = new Uint8Array(keyPair.getPrivate());
|
const keyPrivate = new Uint8Array(keyPair.getPrivate());
|
||||||
const oid = curve.oid;
|
const oid = curve.oid;
|
||||||
const message = p384_message;
|
const message = p384_message;
|
||||||
return elliptic_curves.ecdsa.sign(oid, 10, message, keyPrivate).then(async signature => {
|
return elliptic_curves.ecdsa.sign(oid, 10, message, keyPrivate, openpgp.crypto.hash.digest(10, message)).then(async signature => {
|
||||||
await expect(elliptic_curves.ecdsa.verify(oid, 10, signature, message, keyPublic))
|
await expect(elliptic_curves.ecdsa.verify(oid, 10, signature, message, keyPublic, openpgp.crypto.hash.digest(10, message)))
|
||||||
.to.eventually.be.true;
|
.to.eventually.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,27 +7,17 @@ chai.use(require('chai-as-promised'));
|
||||||
const { expect } = chai;
|
const { expect } = chai;
|
||||||
|
|
||||||
describe('Key', function() {
|
describe('Key', function() {
|
||||||
let webCrypto = openpgp.util.getWebCryptoAll();
|
let rsaGenStub;
|
||||||
|
let rsaGenValue = openpgp.crypto.publicKey.rsa.generate(openpgp.util.getWebCryptoAll() ? 2048 : 512, "10001");
|
||||||
|
|
||||||
if (webCrypto) {
|
beforeEach(function() {
|
||||||
let generateKey = webCrypto.generateKey;
|
rsaGenStub = stub(openpgp.crypto.publicKey.rsa, 'generate');
|
||||||
let keyGenStub;
|
rsaGenStub.returns(rsaGenValue);
|
||||||
let keyGenValue;
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
afterEach(function() {
|
||||||
keyGenStub = stub(webCrypto, 'generateKey');
|
rsaGenStub.restore();
|
||||||
keyGenStub.callsFake(function() {
|
});
|
||||||
if (!keyGenValue) {
|
|
||||||
keyGenValue = generateKey.apply(webCrypto, arguments);
|
|
||||||
}
|
|
||||||
return keyGenValue;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
keyGenStub.restore();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('V4', tests);
|
describe('V4', tests);
|
||||||
|
|
||||||
|
@ -1763,10 +1753,12 @@ VYGdb3eNlV8CfoEC
|
||||||
it('Generate key - setting date to the past', function() {
|
it('Generate key - setting date to the past', function() {
|
||||||
const past = new Date(0);
|
const past = new Date(0);
|
||||||
const opt = {
|
const opt = {
|
||||||
|
numBits: 512,
|
||||||
userIds: { name: 'Test User', email: 'text@example.com' },
|
userIds: { name: 'Test User', email: 'text@example.com' },
|
||||||
passphrase: 'secret',
|
passphrase: 'secret',
|
||||||
date: past
|
date: past
|
||||||
};
|
};
|
||||||
|
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
||||||
|
|
||||||
return openpgp.generateKey(opt).then(function(newKey) {
|
return openpgp.generateKey(opt).then(function(newKey) {
|
||||||
expect(newKey.key).to.exist;
|
expect(newKey.key).to.exist;
|
||||||
|
@ -1821,7 +1813,8 @@ VYGdb3eNlV8CfoEC
|
||||||
|
|
||||||
it('Generate key - override main key options for subkey', function() {
|
it('Generate key - override main key options for subkey', function() {
|
||||||
const userId = 'test <a@b.com>';
|
const userId = 'test <a@b.com>';
|
||||||
const opt = {numBits: 2048, userIds: [userId], passphrase: '123', subkeys:[{curve: 'curve25519'}]};
|
const opt = {numBits: 512, userIds: [userId], passphrase: '123', subkeys:[{curve: 'curve25519'}]};
|
||||||
|
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
||||||
return openpgp.generateKey(opt).then(function(key) {
|
return openpgp.generateKey(opt).then(function(key) {
|
||||||
key = key.key;
|
key = key.key;
|
||||||
expect(key.users.length).to.equal(1);
|
expect(key.users.length).to.equal(1);
|
||||||
|
|
|
@ -374,7 +374,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
|
|
||||||
describe('generateKey - validate user ids', function() {
|
describe('generateKey - validate user ids', function() {
|
||||||
let rsaGenStub;
|
let rsaGenStub;
|
||||||
let rsaGenValue = openpgp.crypto.publicKey.rsa.generate(2048, "10001");
|
let rsaGenValue = openpgp.crypto.publicKey.rsa.generate(openpgp.util.getWebCryptoAll() ? 2048 : 512, "10001");
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
rsaGenStub = stub(openpgp.crypto.publicKey.rsa, 'generate');
|
rsaGenStub = stub(openpgp.crypto.publicKey.rsa, 'generate');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user