cryptpad-server 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2528,60 +2528,69 @@ var hasRequiredCrypto;
2528
2528
  function requireCrypto() {
2529
2529
  if (hasRequiredCrypto) return crypto;
2530
2530
  hasRequiredCrypto = 1;
2531
- crypto = cryptoLib => {
2532
- let exports = {};
2533
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
2534
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
2535
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
2536
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
2531
+ const loadSodium = cryptoLib => {
2532
+ let sodiumLib = {};
2537
2533
  let SodiumNative, NaCl;
2538
2534
  switch (cryptoLib) {
2539
2535
  case "sodiumnative":
2540
- SodiumNative = require("sodium-native");
2541
- exports.sigVerify = (signedMessage, validateKey) => {
2542
- let msg = signedMessage.subarray(64);
2543
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
2544
- if (!ok) {
2545
- return false;
2546
- }
2547
- return msg;
2548
- };
2549
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
2550
- exports.secretbox = (message, nonce, secretKey) => {
2551
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
2552
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
2553
- return secretBox;
2554
- };
2555
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
2556
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
2557
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
2536
+ try {
2537
+ SodiumNative = require("sodium-native");
2538
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
2539
+ let msg = signedMessage.subarray(64);
2540
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
2541
+ if (!ok) {
2542
+ return false;
2543
+ }
2558
2544
  return msg;
2559
- } else {
2560
- return void 0;
2561
- }
2562
- };
2563
- exports.publicKeyFromSecretKey = secretKey => {
2564
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
2565
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
2566
- return pk;
2567
- };
2568
- exports.hash = message => {
2569
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
2570
- SodiumNative.crypto_hash_sha512(out, message);
2571
- return out;
2572
- };
2545
+ };
2546
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
2547
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
2548
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
2549
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
2550
+ return secretBox;
2551
+ };
2552
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
2553
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
2554
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
2555
+ return msg;
2556
+ } else {
2557
+ return void 0;
2558
+ }
2559
+ };
2560
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
2561
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
2562
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
2563
+ return pk;
2564
+ };
2565
+ sodiumLib.hash = message => {
2566
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
2567
+ SodiumNative.crypto_hash_sha512(out, message);
2568
+ return out;
2569
+ };
2570
+ } catch (err) {
2571
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
2572
+ return loadSodium("");
2573
+ }
2573
2574
  break;
2574
2575
 
2575
2576
  default:
2576
2577
  NaCl = require$$0$2;
2577
- exports.sigVerify = NaCl.sign.open;
2578
- exports.detachedVerify = NaCl.sign.detached.verify;
2579
- exports.secretbox = NaCl.secretbox;
2580
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
2581
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
2582
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
2578
+ sodiumLib.sigVerify = NaCl.sign.open;
2579
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
2580
+ sodiumLib.secretbox = NaCl.secretbox;
2581
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
2582
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
2583
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
2583
2584
  break;
2584
2585
  }
2586
+ return sodiumLib;
2587
+ };
2588
+ crypto = cryptoLib => {
2589
+ const exports = loadSodium(cryptoLib);
2590
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
2591
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
2592
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
2593
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
2585
2594
  return exports;
2586
2595
  };
2587
2596
  return crypto;
@@ -2853,7 +2862,7 @@ function requireMfa() {
2853
2862
  return mfa.exports;
2854
2863
  }
2855
2864
 
2856
- var version = "0.0.1";
2865
+ var version = "0.0.2";
2857
2866
 
2858
2867
  var require$$2 = {
2859
2868
  version
package/build/storage.js CHANGED
@@ -5926,60 +5926,69 @@ var hasRequiredCrypto;
5926
5926
  function requireCrypto() {
5927
5927
  if (hasRequiredCrypto) return crypto;
5928
5928
  hasRequiredCrypto = 1;
5929
- crypto = cryptoLib => {
5930
- let exports = {};
5931
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
5932
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
5933
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
5934
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
5929
+ const loadSodium = cryptoLib => {
5930
+ let sodiumLib = {};
5935
5931
  let SodiumNative, NaCl;
5936
5932
  switch (cryptoLib) {
5937
5933
  case "sodiumnative":
5938
- SodiumNative = require("sodium-native");
5939
- exports.sigVerify = (signedMessage, validateKey) => {
5940
- let msg = signedMessage.subarray(64);
5941
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
5942
- if (!ok) {
5943
- return false;
5944
- }
5945
- return msg;
5946
- };
5947
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
5948
- exports.secretbox = (message, nonce, secretKey) => {
5949
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
5950
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
5951
- return secretBox;
5952
- };
5953
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
5954
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
5955
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
5934
+ try {
5935
+ SodiumNative = require("sodium-native");
5936
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
5937
+ let msg = signedMessage.subarray(64);
5938
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
5939
+ if (!ok) {
5940
+ return false;
5941
+ }
5956
5942
  return msg;
5957
- } else {
5958
- return void 0;
5959
- }
5960
- };
5961
- exports.publicKeyFromSecretKey = secretKey => {
5962
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
5963
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
5964
- return pk;
5965
- };
5966
- exports.hash = message => {
5967
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
5968
- SodiumNative.crypto_hash_sha512(out, message);
5969
- return out;
5970
- };
5943
+ };
5944
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
5945
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
5946
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
5947
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
5948
+ return secretBox;
5949
+ };
5950
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
5951
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
5952
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
5953
+ return msg;
5954
+ } else {
5955
+ return void 0;
5956
+ }
5957
+ };
5958
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
5959
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
5960
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
5961
+ return pk;
5962
+ };
5963
+ sodiumLib.hash = message => {
5964
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
5965
+ SodiumNative.crypto_hash_sha512(out, message);
5966
+ return out;
5967
+ };
5968
+ } catch (err) {
5969
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
5970
+ return loadSodium("");
5971
+ }
5971
5972
  break;
5972
5973
 
5973
5974
  default:
5974
5975
  NaCl = require$$6;
5975
- exports.sigVerify = NaCl.sign.open;
5976
- exports.detachedVerify = NaCl.sign.detached.verify;
5977
- exports.secretbox = NaCl.secretbox;
5978
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
5979
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
5980
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
5976
+ sodiumLib.sigVerify = NaCl.sign.open;
5977
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
5978
+ sodiumLib.secretbox = NaCl.secretbox;
5979
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
5980
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
5981
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
5981
5982
  break;
5982
5983
  }
5984
+ return sodiumLib;
5985
+ };
5986
+ crypto = cryptoLib => {
5987
+ const exports = loadSodium(cryptoLib);
5988
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
5989
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
5990
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
5991
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
5983
5992
  return exports;
5984
5993
  };
5985
5994
  return crypto;
@@ -6667,7 +6676,7 @@ function requireMfaManager() {
6667
6676
  return mfaManager;
6668
6677
  }
6669
6678
 
6670
- var version = "0.0.1";
6679
+ var version = "0.0.2";
6671
6680
 
6672
6681
  var require$$2 = {
6673
6682
  version
@@ -7485,13 +7494,13 @@ function require_interface() {
7485
7494
  return;
7486
7495
  }
7487
7496
  const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
7488
- const challenge = new Uint8Array(Buffer.from(challengeBase64, "base64"));
7489
- const nonce = new Uint8Array(Buffer.from(nonceBase64, "base64"));
7497
+ const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
7498
+ const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
7490
7499
  if (ctx.ChallengesCache[challengeBase64]) {
7491
7500
  other.disconnect();
7492
7501
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
7493
7502
  }
7494
- const msg = Buffer.from(Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key));
7503
+ const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
7495
7504
  if (!msg) {
7496
7505
  other.disconnect();
7497
7506
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
@@ -7566,13 +7575,13 @@ function require_interface() {
7566
7575
  let uid = Util.guid(ctx.pendingConnections);
7567
7576
  ctx.pendingConnections[uid] = coreId;
7568
7577
  const nonce = NodeCrypto.randomBytes(24);
7569
- const msg = Buffer.from(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`, "utf-8");
7570
- const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key).toString("base64");
7578
+ const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
7579
+ const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
7571
7580
  createHandlers(ctx, other);
7572
7581
  other.send([ uid, "IDENTITY", {
7573
7582
  type: ctx.myType,
7574
7583
  idx: ctx.myNumber,
7575
- nonce: nonce.toString("base64"),
7584
+ nonce: Crypto.encodeBase64(nonce),
7576
7585
  challenge
7577
7586
  } ]);
7578
7587
  };
@@ -4733,7 +4733,7 @@ function requireTasks() {
4733
4733
  return tasks.exports;
4734
4734
  }
4735
4735
 
4736
- var version = "0.0.1";
4736
+ var version = "0.0.2";
4737
4737
 
4738
4738
  var require$$2 = {
4739
4739
  version
@@ -5512,60 +5512,69 @@ var hasRequiredCrypto;
5512
5512
  function requireCrypto() {
5513
5513
  if (hasRequiredCrypto) return crypto;
5514
5514
  hasRequiredCrypto = 1;
5515
- crypto = cryptoLib => {
5516
- let exports = {};
5517
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
5518
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
5519
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
5520
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
5515
+ const loadSodium = cryptoLib => {
5516
+ let sodiumLib = {};
5521
5517
  let SodiumNative, NaCl;
5522
5518
  switch (cryptoLib) {
5523
5519
  case "sodiumnative":
5524
- SodiumNative = require("sodium-native");
5525
- exports.sigVerify = (signedMessage, validateKey) => {
5526
- let msg = signedMessage.subarray(64);
5527
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
5528
- if (!ok) {
5529
- return false;
5530
- }
5531
- return msg;
5532
- };
5533
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
5534
- exports.secretbox = (message, nonce, secretKey) => {
5535
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
5536
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
5537
- return secretBox;
5538
- };
5539
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
5540
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
5541
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
5520
+ try {
5521
+ SodiumNative = require("sodium-native");
5522
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
5523
+ let msg = signedMessage.subarray(64);
5524
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
5525
+ if (!ok) {
5526
+ return false;
5527
+ }
5542
5528
  return msg;
5543
- } else {
5544
- return void 0;
5545
- }
5546
- };
5547
- exports.publicKeyFromSecretKey = secretKey => {
5548
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
5549
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
5550
- return pk;
5551
- };
5552
- exports.hash = message => {
5553
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
5554
- SodiumNative.crypto_hash_sha512(out, message);
5555
- return out;
5556
- };
5529
+ };
5530
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
5531
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
5532
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
5533
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
5534
+ return secretBox;
5535
+ };
5536
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
5537
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
5538
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
5539
+ return msg;
5540
+ } else {
5541
+ return void 0;
5542
+ }
5543
+ };
5544
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
5545
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
5546
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
5547
+ return pk;
5548
+ };
5549
+ sodiumLib.hash = message => {
5550
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
5551
+ SodiumNative.crypto_hash_sha512(out, message);
5552
+ return out;
5553
+ };
5554
+ } catch (err) {
5555
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
5556
+ return loadSodium("");
5557
+ }
5557
5558
  break;
5558
5559
 
5559
5560
  default:
5560
5561
  NaCl = require$$3$1;
5561
- exports.sigVerify = NaCl.sign.open;
5562
- exports.detachedVerify = NaCl.sign.detached.verify;
5563
- exports.secretbox = NaCl.secretbox;
5564
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
5565
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
5566
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
5562
+ sodiumLib.sigVerify = NaCl.sign.open;
5563
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
5564
+ sodiumLib.secretbox = NaCl.secretbox;
5565
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
5566
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
5567
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
5567
5568
  break;
5568
5569
  }
5570
+ return sodiumLib;
5571
+ };
5572
+ crypto = cryptoLib => {
5573
+ const exports = loadSodium(cryptoLib);
5574
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
5575
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
5576
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
5577
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
5569
5578
  return exports;
5570
5579
  };
5571
5580
  return crypto;