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.
- package/build/core.js +60 -51
- package/build/core.worker.js +53 -44
- package/build/front.js +60 -51
- package/build/http.js +60 -51
- package/build/http.worker.js +1 -1
- package/build/storage.cluster.js +54 -45
- package/build/storage.js +60 -51
- package/build/storage.worker.js +54 -45
- package/build/websocket.js +35556 -0
- package/build/ws.worker.js +46222 -0
- package/index.js +3 -2
- package/package.json +1 -1
- package/readme.md +41 -44
package/build/core.js
CHANGED
|
@@ -823,60 +823,69 @@ var hasRequiredCrypto;
|
|
|
823
823
|
function requireCrypto() {
|
|
824
824
|
if (hasRequiredCrypto) return crypto;
|
|
825
825
|
hasRequiredCrypto = 1;
|
|
826
|
-
|
|
827
|
-
let
|
|
828
|
-
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
829
|
-
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
830
|
-
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
831
|
-
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
826
|
+
const loadSodium = cryptoLib => {
|
|
827
|
+
let sodiumLib = {};
|
|
832
828
|
let SodiumNative, NaCl;
|
|
833
829
|
switch (cryptoLib) {
|
|
834
830
|
case "sodiumnative":
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
};
|
|
844
|
-
exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
845
|
-
exports.secretbox = (message, nonce, secretKey) => {
|
|
846
|
-
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
847
|
-
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
848
|
-
return secretBox;
|
|
849
|
-
};
|
|
850
|
-
exports.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
851
|
-
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
852
|
-
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
831
|
+
try {
|
|
832
|
+
SodiumNative = require("sodium-native");
|
|
833
|
+
sodiumLib.sigVerify = (signedMessage, validateKey) => {
|
|
834
|
+
let msg = signedMessage.subarray(64);
|
|
835
|
+
let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
|
|
836
|
+
if (!ok) {
|
|
837
|
+
return false;
|
|
838
|
+
}
|
|
853
839
|
return msg;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
840
|
+
};
|
|
841
|
+
sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
842
|
+
sodiumLib.secretbox = (message, nonce, secretKey) => {
|
|
843
|
+
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
844
|
+
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
845
|
+
return secretBox;
|
|
846
|
+
};
|
|
847
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
848
|
+
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
849
|
+
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
850
|
+
return msg;
|
|
851
|
+
} else {
|
|
852
|
+
return void 0;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => {
|
|
856
|
+
let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
|
|
857
|
+
SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
|
|
858
|
+
return pk;
|
|
859
|
+
};
|
|
860
|
+
sodiumLib.hash = message => {
|
|
861
|
+
let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
|
|
862
|
+
SodiumNative.crypto_hash_sha512(out, message);
|
|
863
|
+
return out;
|
|
864
|
+
};
|
|
865
|
+
} catch (err) {
|
|
866
|
+
console.error("Error in loading sodium-native: fallback on tweetnacl");
|
|
867
|
+
return loadSodium("");
|
|
868
|
+
}
|
|
868
869
|
break;
|
|
869
870
|
|
|
870
871
|
default:
|
|
871
872
|
NaCl = require$$0$1;
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
873
|
+
sodiumLib.sigVerify = NaCl.sign.open;
|
|
874
|
+
sodiumLib.detachedVerify = NaCl.sign.detached.verify;
|
|
875
|
+
sodiumLib.secretbox = NaCl.secretbox;
|
|
876
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
|
|
877
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
|
|
878
|
+
sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
|
|
878
879
|
break;
|
|
879
880
|
}
|
|
881
|
+
return sodiumLib;
|
|
882
|
+
};
|
|
883
|
+
crypto = cryptoLib => {
|
|
884
|
+
const exports = loadSodium(cryptoLib);
|
|
885
|
+
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
886
|
+
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
887
|
+
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
888
|
+
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
880
889
|
return exports;
|
|
881
890
|
};
|
|
882
891
|
return crypto;
|
|
@@ -934,13 +943,13 @@ function require_interface() {
|
|
|
934
943
|
return;
|
|
935
944
|
}
|
|
936
945
|
const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
|
|
937
|
-
const challenge = new Uint8Array(
|
|
938
|
-
const nonce = new Uint8Array(
|
|
946
|
+
const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
|
|
947
|
+
const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
|
|
939
948
|
if (ctx.ChallengesCache[challengeBase64]) {
|
|
940
949
|
other.disconnect();
|
|
941
950
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
|
|
942
951
|
}
|
|
943
|
-
const msg =
|
|
952
|
+
const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
|
|
944
953
|
if (!msg) {
|
|
945
954
|
other.disconnect();
|
|
946
955
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
|
|
@@ -1015,13 +1024,13 @@ function require_interface() {
|
|
|
1015
1024
|
let uid = Util.guid(ctx.pendingConnections);
|
|
1016
1025
|
ctx.pendingConnections[uid] = coreId;
|
|
1017
1026
|
const nonce = NodeCrypto.randomBytes(24);
|
|
1018
|
-
const msg =
|
|
1019
|
-
const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key)
|
|
1027
|
+
const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
|
|
1028
|
+
const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
|
|
1020
1029
|
createHandlers(ctx, other);
|
|
1021
1030
|
other.send([ uid, "IDENTITY", {
|
|
1022
1031
|
type: ctx.myType,
|
|
1023
1032
|
idx: ctx.myNumber,
|
|
1024
|
-
nonce:
|
|
1033
|
+
nonce: Crypto.encodeBase64(nonce),
|
|
1025
1034
|
challenge
|
|
1026
1035
|
} ]);
|
|
1027
1036
|
};
|
|
@@ -7687,7 +7696,7 @@ function requireHttpCommands() {
|
|
|
7687
7696
|
return httpCommands;
|
|
7688
7697
|
}
|
|
7689
7698
|
|
|
7690
|
-
var version = "0.0.
|
|
7699
|
+
var version = "0.0.2";
|
|
7691
7700
|
|
|
7692
7701
|
var require$$2 = {
|
|
7693
7702
|
version
|
package/build/core.worker.js
CHANGED
|
@@ -813,60 +813,69 @@ var hasRequiredCrypto;
|
|
|
813
813
|
function requireCrypto() {
|
|
814
814
|
if (hasRequiredCrypto) return crypto;
|
|
815
815
|
hasRequiredCrypto = 1;
|
|
816
|
-
|
|
817
|
-
let
|
|
818
|
-
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
819
|
-
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
820
|
-
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
821
|
-
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
816
|
+
const loadSodium = cryptoLib => {
|
|
817
|
+
let sodiumLib = {};
|
|
822
818
|
let SodiumNative, NaCl;
|
|
823
819
|
switch (cryptoLib) {
|
|
824
820
|
case "sodiumnative":
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
};
|
|
834
|
-
exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
835
|
-
exports.secretbox = (message, nonce, secretKey) => {
|
|
836
|
-
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
837
|
-
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
838
|
-
return secretBox;
|
|
839
|
-
};
|
|
840
|
-
exports.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
841
|
-
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
842
|
-
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
821
|
+
try {
|
|
822
|
+
SodiumNative = require("sodium-native");
|
|
823
|
+
sodiumLib.sigVerify = (signedMessage, validateKey) => {
|
|
824
|
+
let msg = signedMessage.subarray(64);
|
|
825
|
+
let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
|
|
826
|
+
if (!ok) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
843
829
|
return msg;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
830
|
+
};
|
|
831
|
+
sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
832
|
+
sodiumLib.secretbox = (message, nonce, secretKey) => {
|
|
833
|
+
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
834
|
+
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
835
|
+
return secretBox;
|
|
836
|
+
};
|
|
837
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
838
|
+
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
839
|
+
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
840
|
+
return msg;
|
|
841
|
+
} else {
|
|
842
|
+
return void 0;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => {
|
|
846
|
+
let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
|
|
847
|
+
SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
|
|
848
|
+
return pk;
|
|
849
|
+
};
|
|
850
|
+
sodiumLib.hash = message => {
|
|
851
|
+
let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
|
|
852
|
+
SodiumNative.crypto_hash_sha512(out, message);
|
|
853
|
+
return out;
|
|
854
|
+
};
|
|
855
|
+
} catch (err) {
|
|
856
|
+
console.error("Error in loading sodium-native: fallback on tweetnacl");
|
|
857
|
+
return loadSodium("");
|
|
858
|
+
}
|
|
858
859
|
break;
|
|
859
860
|
|
|
860
861
|
default:
|
|
861
862
|
NaCl = require$$0$1;
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
863
|
+
sodiumLib.sigVerify = NaCl.sign.open;
|
|
864
|
+
sodiumLib.detachedVerify = NaCl.sign.detached.verify;
|
|
865
|
+
sodiumLib.secretbox = NaCl.secretbox;
|
|
866
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
|
|
867
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
|
|
868
|
+
sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
|
|
868
869
|
break;
|
|
869
870
|
}
|
|
871
|
+
return sodiumLib;
|
|
872
|
+
};
|
|
873
|
+
crypto = cryptoLib => {
|
|
874
|
+
const exports = loadSodium(cryptoLib);
|
|
875
|
+
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
876
|
+
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
877
|
+
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
878
|
+
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
870
879
|
return exports;
|
|
871
880
|
};
|
|
872
881
|
return crypto;
|
package/build/front.js
CHANGED
|
@@ -829,60 +829,69 @@ var hasRequiredCrypto;
|
|
|
829
829
|
function requireCrypto() {
|
|
830
830
|
if (hasRequiredCrypto) return crypto;
|
|
831
831
|
hasRequiredCrypto = 1;
|
|
832
|
-
|
|
833
|
-
let
|
|
834
|
-
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
835
|
-
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
836
|
-
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
837
|
-
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
832
|
+
const loadSodium = cryptoLib => {
|
|
833
|
+
let sodiumLib = {};
|
|
838
834
|
let SodiumNative, NaCl;
|
|
839
835
|
switch (cryptoLib) {
|
|
840
836
|
case "sodiumnative":
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
};
|
|
850
|
-
exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
851
|
-
exports.secretbox = (message, nonce, secretKey) => {
|
|
852
|
-
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
853
|
-
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
854
|
-
return secretBox;
|
|
855
|
-
};
|
|
856
|
-
exports.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
857
|
-
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
858
|
-
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
837
|
+
try {
|
|
838
|
+
SodiumNative = require("sodium-native");
|
|
839
|
+
sodiumLib.sigVerify = (signedMessage, validateKey) => {
|
|
840
|
+
let msg = signedMessage.subarray(64);
|
|
841
|
+
let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
|
|
842
|
+
if (!ok) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
859
845
|
return msg;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
846
|
+
};
|
|
847
|
+
sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
848
|
+
sodiumLib.secretbox = (message, nonce, secretKey) => {
|
|
849
|
+
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
850
|
+
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
851
|
+
return secretBox;
|
|
852
|
+
};
|
|
853
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
854
|
+
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
855
|
+
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
856
|
+
return msg;
|
|
857
|
+
} else {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => {
|
|
862
|
+
let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
|
|
863
|
+
SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
|
|
864
|
+
return pk;
|
|
865
|
+
};
|
|
866
|
+
sodiumLib.hash = message => {
|
|
867
|
+
let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
|
|
868
|
+
SodiumNative.crypto_hash_sha512(out, message);
|
|
869
|
+
return out;
|
|
870
|
+
};
|
|
871
|
+
} catch (err) {
|
|
872
|
+
console.error("Error in loading sodium-native: fallback on tweetnacl");
|
|
873
|
+
return loadSodium("");
|
|
874
|
+
}
|
|
874
875
|
break;
|
|
875
876
|
|
|
876
877
|
default:
|
|
877
878
|
NaCl = require$$0$1;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
879
|
+
sodiumLib.sigVerify = NaCl.sign.open;
|
|
880
|
+
sodiumLib.detachedVerify = NaCl.sign.detached.verify;
|
|
881
|
+
sodiumLib.secretbox = NaCl.secretbox;
|
|
882
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
|
|
883
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
|
|
884
|
+
sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
|
|
884
885
|
break;
|
|
885
886
|
}
|
|
887
|
+
return sodiumLib;
|
|
888
|
+
};
|
|
889
|
+
crypto = cryptoLib => {
|
|
890
|
+
const exports = loadSodium(cryptoLib);
|
|
891
|
+
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
892
|
+
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
893
|
+
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
894
|
+
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
886
895
|
return exports;
|
|
887
896
|
};
|
|
888
897
|
return crypto;
|
|
@@ -940,13 +949,13 @@ function require_interface() {
|
|
|
940
949
|
return;
|
|
941
950
|
}
|
|
942
951
|
const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
|
|
943
|
-
const challenge = new Uint8Array(
|
|
944
|
-
const nonce = new Uint8Array(
|
|
952
|
+
const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
|
|
953
|
+
const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
|
|
945
954
|
if (ctx.ChallengesCache[challengeBase64]) {
|
|
946
955
|
other.disconnect();
|
|
947
956
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
|
|
948
957
|
}
|
|
949
|
-
const msg =
|
|
958
|
+
const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
|
|
950
959
|
if (!msg) {
|
|
951
960
|
other.disconnect();
|
|
952
961
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
|
|
@@ -1021,13 +1030,13 @@ function require_interface() {
|
|
|
1021
1030
|
let uid = Util.guid(ctx.pendingConnections);
|
|
1022
1031
|
ctx.pendingConnections[uid] = coreId;
|
|
1023
1032
|
const nonce = NodeCrypto.randomBytes(24);
|
|
1024
|
-
const msg =
|
|
1025
|
-
const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key)
|
|
1033
|
+
const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
|
|
1034
|
+
const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
|
|
1026
1035
|
createHandlers(ctx, other);
|
|
1027
1036
|
other.send([ uid, "IDENTITY", {
|
|
1028
1037
|
type: ctx.myType,
|
|
1029
1038
|
idx: ctx.myNumber,
|
|
1030
|
-
nonce:
|
|
1039
|
+
nonce: Crypto.encodeBase64(nonce),
|
|
1031
1040
|
challenge
|
|
1032
1041
|
} ]);
|
|
1033
1042
|
};
|
|
@@ -4044,7 +4053,7 @@ function requireLogger() {
|
|
|
4044
4053
|
return logger;
|
|
4045
4054
|
}
|
|
4046
4055
|
|
|
4047
|
-
var version = "0.0.
|
|
4056
|
+
var version = "0.0.2";
|
|
4048
4057
|
|
|
4049
4058
|
var require$$2 = {
|
|
4050
4059
|
version
|
package/build/http.js
CHANGED
|
@@ -3479,7 +3479,7 @@ function requireLogger() {
|
|
|
3479
3479
|
return logger;
|
|
3480
3480
|
}
|
|
3481
3481
|
|
|
3482
|
-
var version = "0.0.
|
|
3482
|
+
var version = "0.0.2";
|
|
3483
3483
|
|
|
3484
3484
|
var require$$2 = {
|
|
3485
3485
|
version
|
|
@@ -4649,60 +4649,69 @@ var hasRequiredCrypto;
|
|
|
4649
4649
|
function requireCrypto() {
|
|
4650
4650
|
if (hasRequiredCrypto) return crypto;
|
|
4651
4651
|
hasRequiredCrypto = 1;
|
|
4652
|
-
|
|
4653
|
-
let
|
|
4654
|
-
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
4655
|
-
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
4656
|
-
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
4657
|
-
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
4652
|
+
const loadSodium = cryptoLib => {
|
|
4653
|
+
let sodiumLib = {};
|
|
4658
4654
|
let SodiumNative, NaCl;
|
|
4659
4655
|
switch (cryptoLib) {
|
|
4660
4656
|
case "sodiumnative":
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
};
|
|
4670
|
-
exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
4671
|
-
exports.secretbox = (message, nonce, secretKey) => {
|
|
4672
|
-
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
4673
|
-
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
4674
|
-
return secretBox;
|
|
4675
|
-
};
|
|
4676
|
-
exports.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
4677
|
-
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
4678
|
-
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
4657
|
+
try {
|
|
4658
|
+
SodiumNative = require("sodium-native");
|
|
4659
|
+
sodiumLib.sigVerify = (signedMessage, validateKey) => {
|
|
4660
|
+
let msg = signedMessage.subarray(64);
|
|
4661
|
+
let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
|
|
4662
|
+
if (!ok) {
|
|
4663
|
+
return false;
|
|
4664
|
+
}
|
|
4679
4665
|
return msg;
|
|
4680
|
-
}
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4666
|
+
};
|
|
4667
|
+
sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
|
|
4668
|
+
sodiumLib.secretbox = (message, nonce, secretKey) => {
|
|
4669
|
+
let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
|
|
4670
|
+
SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
|
|
4671
|
+
return secretBox;
|
|
4672
|
+
};
|
|
4673
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
|
|
4674
|
+
let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
|
|
4675
|
+
if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
|
|
4676
|
+
return msg;
|
|
4677
|
+
} else {
|
|
4678
|
+
return void 0;
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4681
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => {
|
|
4682
|
+
let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
|
|
4683
|
+
SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
|
|
4684
|
+
return pk;
|
|
4685
|
+
};
|
|
4686
|
+
sodiumLib.hash = message => {
|
|
4687
|
+
let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
|
|
4688
|
+
SodiumNative.crypto_hash_sha512(out, message);
|
|
4689
|
+
return out;
|
|
4690
|
+
};
|
|
4691
|
+
} catch (err) {
|
|
4692
|
+
console.error("Error in loading sodium-native: fallback on tweetnacl");
|
|
4693
|
+
return loadSodium("");
|
|
4694
|
+
}
|
|
4694
4695
|
break;
|
|
4695
4696
|
|
|
4696
4697
|
default:
|
|
4697
4698
|
NaCl = require$$0$2;
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4699
|
+
sodiumLib.sigVerify = NaCl.sign.open;
|
|
4700
|
+
sodiumLib.detachedVerify = NaCl.sign.detached.verify;
|
|
4701
|
+
sodiumLib.secretbox = NaCl.secretbox;
|
|
4702
|
+
sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
|
|
4703
|
+
sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
|
|
4704
|
+
sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
|
|
4704
4705
|
break;
|
|
4705
4706
|
}
|
|
4707
|
+
return sodiumLib;
|
|
4708
|
+
};
|
|
4709
|
+
crypto = cryptoLib => {
|
|
4710
|
+
const exports = loadSodium(cryptoLib);
|
|
4711
|
+
exports.decodeBase64 = msg => Buffer.from(msg, "base64");
|
|
4712
|
+
exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
|
|
4713
|
+
exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
|
|
4714
|
+
exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
|
|
4706
4715
|
return exports;
|
|
4707
4716
|
};
|
|
4708
4717
|
return crypto;
|
|
@@ -4754,13 +4763,13 @@ function require_interface() {
|
|
|
4754
4763
|
return;
|
|
4755
4764
|
}
|
|
4756
4765
|
const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
|
|
4757
|
-
const challenge = new Uint8Array(
|
|
4758
|
-
const nonce = new Uint8Array(
|
|
4766
|
+
const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
|
|
4767
|
+
const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
|
|
4759
4768
|
if (ctx.ChallengesCache[challengeBase64]) {
|
|
4760
4769
|
other.disconnect();
|
|
4761
4770
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
|
|
4762
4771
|
}
|
|
4763
|
-
const msg =
|
|
4772
|
+
const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
|
|
4764
4773
|
if (!msg) {
|
|
4765
4774
|
other.disconnect();
|
|
4766
4775
|
return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
|
|
@@ -4835,13 +4844,13 @@ function require_interface() {
|
|
|
4835
4844
|
let uid = Util.guid(ctx.pendingConnections);
|
|
4836
4845
|
ctx.pendingConnections[uid] = coreId;
|
|
4837
4846
|
const nonce = NodeCrypto.randomBytes(24);
|
|
4838
|
-
const msg =
|
|
4839
|
-
const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key)
|
|
4847
|
+
const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
|
|
4848
|
+
const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
|
|
4840
4849
|
createHandlers(ctx, other);
|
|
4841
4850
|
other.send([ uid, "IDENTITY", {
|
|
4842
4851
|
type: ctx.myType,
|
|
4843
4852
|
idx: ctx.myNumber,
|
|
4844
|
-
nonce:
|
|
4853
|
+
nonce: Crypto.encodeBase64(nonce),
|
|
4845
4854
|
challenge
|
|
4846
4855
|
} ]);
|
|
4847
4856
|
};
|