Skip to content

Commit

Permalink
We now force encryption
Browse files Browse the repository at this point in the history
- Updated Voice.md to reflect requirements
  • Loading branch information
David Cole committed Apr 9, 2016
1 parent 3d0f435 commit 56dfd32
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
31 changes: 28 additions & 3 deletions Voice.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
## Voice

Voice in DiscordPHP has 2 main requirements:
Voice in DiscordPHP has 3 main requirements:

- FFmpeg
- DCA (Packaged with DiscordPHP)
- libsodium-php

### Encryption

Currently, encryption is only enabled if you have `libsodium` as well as `libsodium-php` installed. If you don't, your audio will be unencrypted.
Since Discord will be removing `plain` voice at the end of April, DiscordPHP requires libsodium and libsodium-php to be installed to encrypt the audio packets.

Unencrypted audio will be removed in the near future. It will throw an exception if it is not installed.
#### Mac

1. Get [Homebrew](http://brew.sh/).
2. Install PHP with Homebrew if you haven't already.
3. `brew install libsodium`
4. `brew install homebrew/php/php**-libsodium`

#### Ubuntu

1. `wget https://github.com/jedisct1/libsodium/releases/download/1.0.10/libsodium-1.0.10.tar.gz`
2. `tar -xvzf libsodium-1.0.10.tar.gz && cd libsodium-1.0.10`
3. `./configure`
4. `make && sudo make install`

If you have PECL installed:

- `pecl install libsodium`

Otherwise:

1. `wget https://github.com/jedisct1/libsodium-php/archive/1.0.5.tar.gz`
2. `tar -xvzf 1.0.5.tar.gz && cd libsodium-php-1.0.5`
3. `phpize && ./configure`
4. `make && sudo make install`
5. `sudo sh -c 'echo "extension="$PWD"/modules/libsodium.so" >> $(php -r "echo php_ini_loaded_file(), PHP_EOL;")'`

### Installations

Expand Down
19 changes: 19 additions & 0 deletions src/Discord/Exceptions/LibSodiumNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is apart of the DiscordPHP project.
*
* Copyright (c) 2016 David Cole <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Exceptions;

/**
* Thrown when libsodium or libsodium-php cannot be found.
*/
class LibSodiumNotFoundException extends \Exception
{
}
19 changes: 18 additions & 1 deletion src/Discord/Voice/VoiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Discord\Exceptions\FFmpegNotFoundException;
use Discord\Exceptions\FileNotFoundException;
use Discord\Exceptions\OutdatedDCAException;
use Discord\Exceptions\LibSodiumNotFoundException;
use Discord\Helpers\Collection;
use Discord\Helpers\Process;
use Discord\Parts\Channel\Channel;
Expand Down Expand Up @@ -392,7 +393,23 @@ public function initSockets($loop)
$port = substr($message, strlen($message) - 2);
$port = unpack('v', $port)[1];

if (function_exists('\Sodium\crypto_secretbox')) {
if (! function_exists('\Sodium\crypto_secretbox')) {
$this->emit('error', [new LibSodiumNotFoundException('libsodium-php was not found.')]);

$this->client->close();
$this->voiceWebsocket->close();
$this->mainWebsocket->send([
'op' => 4,
'd' => [
'guild_id' => null,
'channel_id' => null,
'self_mute' => false,
'self_deaf' => false,
],
]);

return;
} else {
$this->mode = 'xsalsa20_poly1305'; // voice encryption!
$this->encrypted = true;
}
Expand Down

0 comments on commit 56dfd32

Please sign in to comment.