* Use Native libsodium when available

* add newline

* fix typo of exports

* add to webpack ignore

* Update Secretbox.js
This commit is contained in:
Jacob
2017-02-06 01:24:54 -05:00
committed by Schuyler Cebulskie
parent 02c23a8b53
commit 49944747ae
4 changed files with 21 additions and 4 deletions

View File

@@ -45,6 +45,7 @@
"erlpack": "hammerandchisel/erlpack",
"node-opus": "^0.2.0",
"opusscript": "^0.0.2",
"sodium": "^2.0.1",
"uws": "^0.12.0"
},
"devDependencies": {
@@ -65,6 +66,7 @@
"opusscript": false,
"node-opus": false,
"tweet-nacl": false,
"sodium": false,
"src/sharding/Shard.js": false,
"src/sharding/ShardClientUtil.js": false,
"src/sharding/ShardingManager.js": false,
@@ -82,6 +84,7 @@
"src/client/voice/receiver/VoiceReadable.js": false,
"src/client/voice/receiver/VoiceReceiver.js": false,
"src/client/voice/util/SecretKey.js": false,
"src/client/voice/util/Secretbox.js": false,
"src/client/voice/ClientVoiceManager.js": false,
"src/client/voice/VoiceConnection.js": false,
"src/client/voice/VoiceUDPClient.js": false,

View File

@@ -1,7 +1,8 @@
const VolumeInterface = require('../util/VolumeInterface');
const NaCl = require('tweetnacl');
const VoiceBroadcast = require('../VoiceBroadcast');
const secretbox = require('../util/Secretbox');
const nonce = Buffer.alloc(24);
nonce.fill(0);
@@ -149,7 +150,7 @@ class StreamDispatcher extends VolumeInterface {
packetBuffer.writeUIntBE(this.player.voiceConnection.authentication.ssrc, 8, 4);
packetBuffer.copy(nonce, 0, 0, 12);
buffer = NaCl.secretbox(buffer, nonce, this.player.voiceConnection.authentication.secretKey.key);
buffer = secretbox.close(buffer, nonce, this.player.voiceConnection.authentication.secretKey.key);
for (let i = 0; i < buffer.length; i++) packetBuffer[i + 12] = buffer[i];
return packetBuffer;

View File

@@ -1,5 +1,5 @@
const EventEmitter = require('events').EventEmitter;
const NaCl = require('tweetnacl');
const secretbox = require('../util/Secretbox');
const Readable = require('./VoiceReadable');
const OpusEncoders = require('../opus/OpusEngineList');
@@ -123,7 +123,7 @@ class VoiceReceiver extends EventEmitter {
handlePacket(msg, user) {
msg.copy(nonce, 0, 0, 12);
let data = NaCl.secretbox.open(msg.slice(12), nonce, this.voiceConnection.authentication.secretKey.key);
let data = secretbox.open(msg.slice(12), nonce, this.voiceConnection.authentication.secretKey.key);
if (!data) {
/**
* Emitted whenever a voice packet experiences a problem.

View File

@@ -0,0 +1,13 @@
try {
const sodium = require('sodium');
module.exports = {
open: sodium.api.crypto_secretbox_open,
close: sodium.api.crypto_secretbox,
};
} catch (err) {
const tweetnacl = require('tweetnacl');
module.exports = {
open: tweetnacl.secretbox.open,
close: tweetnacl.secretbox,
};
}