mirror of
https://github.com/aria2/aria2.git
synced 2025-02-26 08:22:11 +00:00
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}
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#include "DHKeyExchange.h"
|
|
#include "Exception.h"
|
|
#include "Util.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class DHKeyExchangeTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(DHKeyExchangeTest);
|
|
CPPUNIT_TEST(testHandshake);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testHandshake();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHKeyExchangeTest);
|
|
|
|
void DHKeyExchangeTest::testHandshake()
|
|
{
|
|
DHKeyExchange dhA;
|
|
DHKeyExchange dhB;
|
|
|
|
const unsigned char* PRIME = reinterpret_cast<const unsigned char*>("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A36210000000000090563");
|
|
|
|
const unsigned char* GENERATOR = reinterpret_cast<const unsigned char*>("2");
|
|
|
|
dhA.init(PRIME, GENERATOR, 160);
|
|
dhB.init(PRIME, GENERATOR, 160);
|
|
|
|
dhA.generatePublicKey();
|
|
dhB.generatePublicKey();
|
|
|
|
unsigned char publicKeyA[96];
|
|
unsigned char publicKeyB[96];
|
|
dhA.getPublicKey(publicKeyA, sizeof(publicKeyA));
|
|
dhB.getPublicKey(publicKeyB, sizeof(publicKeyB));
|
|
|
|
unsigned char secretA[96];
|
|
unsigned char secretB[96];
|
|
dhA.computeSecret(secretA, sizeof(secretA), publicKeyB, sizeof(publicKeyB));
|
|
dhB.computeSecret(secretB, sizeof(secretB), publicKeyA, sizeof(publicKeyA));
|
|
|
|
CPPUNIT_ASSERT(memcmp(secretA, secretB, sizeof(secretA)) == 0);
|
|
}
|
|
|
|
} // namespace aria2
|