mirror of
https://github.com/aria2/aria2.git
synced 2025-01-10 03:52:01 +00:00
c0d2223c77
Added Message Stream Encryption(MSE) support. Currently, aria2 accepts incoming connections with Obfuscation Header and legacy BitTorrent Header and establishes connections with Obfuscation Header first and if failed then retry with legacy BitTorrent header. If plain text and ARC4 is provided, aria2 always choose ARC4. The new option to change the default behavior is planned. For tracker extension, "supportcrypto=1" is added statically. * src/PeerInitiateConnectionCommand.{h, cc} * src/PeerConnection.{h, cc} * src/HandleRegistry.h * src/SocketCore.h * src/PeerReceiveHandshakeCommand.{h, cc} * src/BtRegistry.{h, cc} * src/PeerListenCommand.cc * src/InitiatorMSEHandshakeCommand.{h, cc} * src/ReceiverMSEHandshakeCommand.{h, cc} * src/MSEHandshake.{h, cc} * src/ARC4Encryptor.h * src/ARC4Decryptor.h * src/LibgcryptARC4Encryptor.h * src/LibgcryptARC4Decryptor.h * src/LibgcryptARC4Context.h * src/LibsslARC4Encryptor.h * src/LibsslARC4Decryptor.h * src/LibsslARC4Context.h * src/DHKeyExchange.h * src/LibgcryptDHKeyExchange.h * src/LibsslDHKeyExchange.h * src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter. * test/DefaultBtAnnounceTest.cc * test/ARC4Test.cc * test/DHKeyExchangeTest.cc Removed prepareForRetry() because it is not used. * src/PeerAbstractCommand.{h, cc} * src/PeerInteractionCommand.{h, cc} * src/PeerInitiateConnectionCommand.{h, cc}
52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#include "ARC4Encryptor.h"
|
|
#include "ARC4Decryptor.h"
|
|
#include "Exception.h"
|
|
#include "Util.h"
|
|
#include "DHTUtil.h"
|
|
#include <cstring>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class ARC4Test:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(ARC4Test);
|
|
CPPUNIT_TEST(testEncryptDecrypt);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testEncryptDecrypt();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ARC4Test);
|
|
|
|
void ARC4Test::testEncryptDecrypt()
|
|
{
|
|
ARC4Encryptor enc;
|
|
ARC4Decryptor dec;
|
|
const size_t LEN = 20;
|
|
unsigned char key[LEN];
|
|
memset(key, 0, LEN);
|
|
DHTUtil::generateRandomData(key, sizeof(key));
|
|
enc.init(key, sizeof(key));
|
|
dec.init(key, sizeof(key));
|
|
|
|
unsigned char encrypted[LEN];
|
|
unsigned char decrypted[LEN];
|
|
enc.encrypt(encrypted, LEN, key, LEN);
|
|
dec.decrypt(decrypted, LEN, encrypted, LEN);
|
|
|
|
CPPUNIT_ASSERT(memcmp(key, decrypted, LEN) == 0);
|
|
// once more
|
|
enc.encrypt(encrypted, LEN, key, LEN);
|
|
dec.decrypt(decrypted, LEN, encrypted, LEN);
|
|
|
|
CPPUNIT_ASSERT(memcmp(key, decrypted, LEN) == 0);
|
|
}
|
|
|
|
} // namespace aria2
|