kbpgp
kbpgp copied to clipboard
Sign node buffer error
Crash sign with buffer large then 1024 * 1024 * 177
<--- Last few GCs --->
1176 ms: Mark-sweep 38.5 (60.2) -> 29.1 (51.6) MB, 36.5 / 0.0 ms (+ 7.2 ms in 2 steps since start of marking, biggest step 7.2 ms) [GC interrupt] [GC in old space requested].
1370 ms: Mark-sweep 316.8 (339.4) -> 230.5 (254.0) MB, 1.6 / 0.0 ms (+ 6.1 ms in 2 steps since start of marking, biggest step 6.1 ms) [GC interrupt] [GC in old space requested].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000162F37CFB61 <JS Object>
2: from_buffer [C:\Users\alg\Desktop\Trusted\trusted-crypto\node_modules\triplesec\lib\wordarray.js:~135] [pc=00000187B44EFE0A] (this=0000027F8AE4FD49 <JS Function WordArray (SharedFunctionInfo 000002F943EA8289)>,b=0000016436921661 <an Uint8Array with map 0000025831806569>)
3: bufhash [C:\Users\alg\Desktop\Trusted\trusted-crypto\node_modules\triplesec\lib\algbase.js:96] [pc=00000187B4...
FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
Full script:
var kbpgp = require("kbpgp");
var fs = require("fs");
var buffer = Buffer.alloc(1024*1024*178);
var alice_pgp_key = [ "-----BEGIN PGP PRIVATE KEY BLOCK-----",
"Version: GnuPG v2.0.19 (GNU/Linux)",
"",
////////
"-----END PGP PRIVATE KEY BLOCK-----"
].join("\n");
var alice_passphrase = "hello world";
kbpgp.KeyManager.import_from_armored_pgp({
armored: alice_pgp_key
}, function(err, alice) {
if (!err) {
if (alice.is_pgp_locked()) {
alice.unlock_pgp({
passphrase: alice_passphrase
}, function(err) {
if (!err) {
console.log("Loaded private key with passphrase");
var params = {
msg: buffer,
sign_with: alice,
};
kbpgp.box(params, function(err, result_string, result_buffer) {
fs.writeFileSync("out.sig", result_string);
});
}
});
} else {
console.log("Loaded private key w/o passphrase");
}
}
});
From kbpgp docs:
In Node.js we can pass a Node.js Buffer instead. This could come from a file. Keep in mind this file's buffer and output need to fit easily in memory. (For arbitrarily large files, streams will come soon in kbpgp's future.)
From node api:
On 32-bit architectures, this value is (2^30)-1 (~1GB). On 64-bit architectures, this value is (2^31)-1 (~2GB).
What maximum bufer size can sign from kbpgp?