From c0d2223c778ae9719fd13d1fde6dc2fbf4faa82b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 17 Feb 2008 15:56:47 +0000 Subject: 2008-02-16 Tatsuhiro Tsujikawa 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} --- src/LibgcryptARC4Encryptor.h | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/LibgcryptARC4Encryptor.h (limited to 'src/LibgcryptARC4Encryptor.h') diff --git a/src/LibgcryptARC4Encryptor.h b/src/LibgcryptARC4Encryptor.h new file mode 100644 index 00000000..2e0c7a16 --- /dev/null +++ b/src/LibgcryptARC4Encryptor.h @@ -0,0 +1,77 @@ +/* */ +#ifndef _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_ +#define _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_ + +#include "common.h" +#include "DlAbortEx.h" +#include "LibgcryptARC4Context.h" +#include + +namespace aria2 { + +class ARC4Encryptor { +private: + LibgcryptARC4Context _ctx; + + void handleError(gcry_error_t errno) const + { + throw new DlAbortEx("Exception in libgcrypt routine(ARC4Encryptor class): %s", + gcry_strerror(errno)); + } +public: + ARC4Encryptor() {} + + ~ARC4Encryptor() {} + + void init(const unsigned char* key, size_t keyLength) + { + _ctx.init(key, keyLength); + } + + void encrypt(unsigned char* out, size_t outLength, + const unsigned char* in, size_t inLength) + { + gcry_error_t r = gcry_cipher_encrypt(_ctx.getCipherContext(), + out, outLength, in, inLength); + if(r) { + handleError(r); + } + } +}; + +} // namespace aria2 + +#endif // _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_ -- cgit