mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-24 14:35:51 +00:00
test(fuzz): add fuzz tests
This commit is contained in:
parent
aeb467a2f6
commit
eab3b8f6b5
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
npm*
|
npm*
|
||||||
test/lib/
|
test/lib/
|
||||||
test/typescript/definitions.js
|
|
||||||
dist/
|
dist/
|
||||||
openpgp.store/
|
openpgp.store/
|
||||||
coverage
|
coverage
|
||||||
|
test/fuzz/reports
|
||||||
|
|||||||
@ -47,6 +47,8 @@
|
|||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"test": "mocha --timeout 120000 test/unittests.js",
|
"test": "mocha --timeout 120000 test/unittests.js",
|
||||||
"test-type-definitions": "node --loader ts-node/esm test/typescript/definitions.ts",
|
"test-type-definitions": "node --loader ts-node/esm test/typescript/definitions.ts",
|
||||||
|
"fuzz": "jazzer test/fuzz/$TARGET.cjs -- -artifact_prefix=test/fuzz/reports/",
|
||||||
|
"fuzz-coverage": "jazzer test/fuzz/$TARGET.cjs --coverage --cov_dir=test/fuzz/coverage -- -artifact_prefix=test/fuzz/reports/",
|
||||||
"benchmark-time": "node test/benchmarks/time.js",
|
"benchmark-time": "node test/benchmarks/time.js",
|
||||||
"benchmark-memory-usage": "node test/benchmarks/memory_usage.js",
|
"benchmark-memory-usage": "node test/benchmarks/memory_usage.js",
|
||||||
"start": "http-server",
|
"start": "http-server",
|
||||||
|
|||||||
15
test/fuzz/createCleartextMessage.cjs
Normal file
15
test/fuzz/createCleartextMessage.cjs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const { FuzzedDataProvider } = require('@jazzer.js/core');
|
||||||
|
|
||||||
|
const MAX_MESSAGE_LENGTH = 9000;
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const data = new FuzzedDataProvider(inputData);
|
||||||
|
const text = data.bufToPrintableString(inputData, 2, MAX_MESSAGE_LENGTH, 'utf-8');
|
||||||
|
return openpgp.default.createCleartextMessage({ text });
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
9
test/fuzz/createMessageBinary.cjs
Normal file
9
test/fuzz/createMessageBinary.cjs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
return openpgp.default.createMessage({ binary: new Uint8Array(inputData) });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
13
test/fuzz/createMessageText.cjs
Normal file
13
test/fuzz/createMessageText.cjs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const { FuzzedDataProvider } = require('@jazzer.js/core');
|
||||||
|
|
||||||
|
const MAX_MESSAGE_LENGTH = 9000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const data = new FuzzedDataProvider(inputData);
|
||||||
|
return openpgp.default.createMessage({ text: data.consumeString(MAX_MESSAGE_LENGTH, 'utf-8') });
|
||||||
|
});
|
||||||
|
};
|
||||||
25
test/fuzz/generateKey.cjs
Normal file
25
test/fuzz/generateKey.cjs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const { FuzzedDataProvider } = require('@jazzer.js/core');
|
||||||
|
|
||||||
|
const MAX_NAME_LENGTH = 30;
|
||||||
|
const MAX_COMMENT_LENGTH = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const data = new FuzzedDataProvider(inputData);
|
||||||
|
const asciiString = data.consumeString(MAX_COMMENT_LENGTH);
|
||||||
|
const utf8String = data.consumeString(MAX_NAME_LENGTH, 'utf-8');
|
||||||
|
|
||||||
|
return openpgp.default.generateKey({ userIDs: [
|
||||||
|
{ name: utf8String },
|
||||||
|
{ email: utf8String },
|
||||||
|
{ comment: asciiString },
|
||||||
|
{ name: utf8String, email: utf8String, comment: asciiString }
|
||||||
|
],
|
||||||
|
passphrase: asciiString,
|
||||||
|
format: 'object' });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
27
test/fuzz/readKeyArmored.cjs
Normal file
27
test/fuzz/readKeyArmored.cjs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const { FuzzedDataProvider } = require('@jazzer.js/core');
|
||||||
|
|
||||||
|
const ignored = ['Misformed armored text'];
|
||||||
|
const MAX_MESSAGE_LENGTH = 9000;
|
||||||
|
|
||||||
|
function ignoredError(error) {
|
||||||
|
return ignored.some(message => error.message.includes(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const data = new FuzzedDataProvider(inputData);
|
||||||
|
const fuzzedText = data.consumeString(MAX_MESSAGE_LENGTH, 'utf-8');
|
||||||
|
const armoredKey = `-----BEGIN PGP PRIVATE KEY BLOCK----- ${fuzzedText} -----END PGP PRIVATE KEY BLOCK-----`;
|
||||||
|
|
||||||
|
return openpgp.default.readKey({ armoredKey })
|
||||||
|
.catch(error => {
|
||||||
|
if (error.message && !ignoredError(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
22
test/fuzz/readKeyBinary.cjs
Normal file
22
test/fuzz/readKeyBinary.cjs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const ignored = ['This message / key probably does not conform to a valid OpenPGP format'];
|
||||||
|
|
||||||
|
function ignoredError(error) {
|
||||||
|
return ignored.some(message => error.message.includes(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const binaryKey = new Uint8Array(`-----BEGIN PGP PRIVATE KEY BLOCK----- ${inputData} -----END PGP PRIVATE KEY BLOCK-----`);
|
||||||
|
|
||||||
|
return openpgp.default.readKey({ binaryKey })
|
||||||
|
.catch(error => {
|
||||||
|
if (error.message && !ignoredError(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
22
test/fuzz/readMessageBinary.cjs
Normal file
22
test/fuzz/readMessageBinary.cjs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const ignored = ['This message / key probably does not conform to a valid OpenPGP format'];
|
||||||
|
|
||||||
|
function ignoredError(error) {
|
||||||
|
return ignored.some(message => error.message.includes(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const binaryMessage = new Uint8Array(`-----BEGIN PGP MESSAGE----- ${inputData} -----END PGP MESSAGE-----`);
|
||||||
|
|
||||||
|
return openpgp.default.readMessage({ binaryMessage })
|
||||||
|
.catch(error => {
|
||||||
|
if (error.message && !ignoredError(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
27
test/fuzz/readMessageText.cjs
Normal file
27
test/fuzz/readMessageText.cjs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const { FuzzedDataProvider } = require('@jazzer.js/core');
|
||||||
|
|
||||||
|
const ignored = ['Misformed armored text'];
|
||||||
|
const MAX_MESSAGE_LENGTH = 9000;
|
||||||
|
|
||||||
|
function ignoredError(error) {
|
||||||
|
return ignored.some(message => error.message.includes(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { Buffer } inputData
|
||||||
|
*/
|
||||||
|
module.exports.fuzz = function(inputData) {
|
||||||
|
import('../initOpenpgp.js').then(openpgp => {
|
||||||
|
const data = new FuzzedDataProvider(inputData);
|
||||||
|
const fuzzedText = data.consumeString(MAX_MESSAGE_LENGTH, 'utf-8');
|
||||||
|
const armoredMessage = `-----BEGIN PGP MESSAGE----- ${fuzzedText} -----END PGP MESSAGE-----`;
|
||||||
|
|
||||||
|
return openpgp.default.readMessage({ armoredMessage })
|
||||||
|
.catch(error => {
|
||||||
|
if (error.message && !ignoredError(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user