mirror of https://github.com/aria2/aria2
Removed ARC4Decryptor because ARC4Encryptor can decrypt the message.
parent
30fdb08f40
commit
02b3873e6d
|
@ -1,67 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_ARC4_DECRYPTOR_H
|
||||
#define D_ARC4_DECRYPTOR_H
|
||||
|
||||
#include "common.h"
|
||||
#ifdef HAVE_LIBNETTLE
|
||||
# include "LibnettleARC4Decryptor.h"
|
||||
#elif HAVE_LIBGCRYPT
|
||||
# include "LibgcryptARC4Decryptor.h"
|
||||
#elif HAVE_OPENSSL
|
||||
# include "LibsslARC4Decryptor.h"
|
||||
#else
|
||||
|
||||
// provide empty implementation to compile sources without both libgcrypt and
|
||||
// openssl installed
|
||||
namespace aria2 {
|
||||
|
||||
class ARC4Decryptor {
|
||||
public:
|
||||
ARC4Decryptor() {}
|
||||
|
||||
~ARC4Decryptor() {}
|
||||
|
||||
void init(const unsigned char* key, size_t keyLength) {}
|
||||
|
||||
void decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength) {}
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif
|
||||
|
||||
#endif // D_ARC4_DECRYPTOR_H
|
|
@ -50,7 +50,6 @@
|
|||
#include "Option.h"
|
||||
#include "MSEHandshake.h"
|
||||
#include "ARC4Encryptor.h"
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "bittorrent_helper.h"
|
||||
|
@ -158,7 +157,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
mseHandshake_->getDecryptor());
|
||||
size_t buflen = mseHandshake_->getBufferLength();
|
||||
array_ptr<unsigned char> buffer(new unsigned char[buflen]);
|
||||
mseHandshake_->getDecryptor()->decrypt(buffer, buflen,
|
||||
mseHandshake_->getDecryptor()->encrypt(buffer, buflen,
|
||||
mseHandshake_->getBuffer(),
|
||||
buflen);
|
||||
peerConnection->presetBuffer(buffer, buflen);
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2010 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "LibgcryptARC4Decryptor.h"
|
||||
|
||||
#include <gcrypt.h>
|
||||
|
||||
#include "DlAbortEx.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
namespace {
|
||||
void handleError(gcry_error_t err)
|
||||
{
|
||||
throw DL_ABORT_EX
|
||||
(fmt("Exception in libgcrypt routine(ARC4Decryptor class): %s",
|
||||
gcry_strerror(err)));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ARC4Decryptor::ARC4Decryptor() {}
|
||||
|
||||
ARC4Decryptor::~ARC4Decryptor() {}
|
||||
|
||||
void ARC4Decryptor::init(const unsigned char* key, size_t keyLength)
|
||||
{
|
||||
ctx_.init(key, keyLength);
|
||||
}
|
||||
|
||||
void ARC4Decryptor::decrypt
|
||||
(unsigned char* out, size_t outLength, const unsigned char* in, size_t inLength)
|
||||
{
|
||||
gcry_error_t r = gcry_cipher_decrypt(ctx_.getCipherContext(),
|
||||
out, outLength, in, inLength);
|
||||
if(r) {
|
||||
handleError(r);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,59 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_LIBGCRYPT_ARC4_DECRYPTOR_H
|
||||
#define D_LIBGCRYPT_ARC4_DECRYPTOR_H
|
||||
|
||||
#include "common.h"
|
||||
#include "LibgcryptARC4Context.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ARC4Decryptor {
|
||||
private:
|
||||
LibgcryptARC4Context ctx_;
|
||||
public:
|
||||
ARC4Decryptor();
|
||||
|
||||
~ARC4Decryptor();
|
||||
|
||||
void init(const unsigned char* key, size_t keyLength);
|
||||
|
||||
void decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_LIBGCRYPT_ARC4_DECRYPTOR_H
|
|
@ -1,57 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2011 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "LibnettleARC4Decryptor.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
ARC4Decryptor::ARC4Decryptor() {}
|
||||
|
||||
ARC4Decryptor::~ARC4Decryptor() {}
|
||||
|
||||
void ARC4Decryptor::init(const unsigned char* key, size_t keyLength)
|
||||
{
|
||||
ctx_.init(key, keyLength);
|
||||
}
|
||||
|
||||
void ARC4Decryptor::decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength)
|
||||
{
|
||||
assert(outLength == inLength);
|
||||
arcfour_crypt(ctx_.getCipherContext(), outLength, out, in);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,59 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2011 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_LIBNETTLE_ARC4_DECRYPTOR_H
|
||||
#define D_LIBNETTLE_ARC4_DECRYPTOR_H
|
||||
|
||||
#include "common.h"
|
||||
#include "LibnettleARC4Context.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ARC4Decryptor {
|
||||
private:
|
||||
LibnettleARC4Context ctx_;
|
||||
public:
|
||||
ARC4Decryptor();
|
||||
|
||||
~ARC4Decryptor();
|
||||
|
||||
void init(const unsigned char* key, size_t keyLength);
|
||||
|
||||
void decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_LIBNETTLE_ARC4_DECRYPTOR_H
|
|
@ -1,72 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2010 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "LibsslARC4Decryptor.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "DlAbortEx.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
namespace {
|
||||
void handleError()
|
||||
{
|
||||
throw DL_ABORT_EX
|
||||
(fmt("Exception in libssl routine(ARC4Decryptor class): %s",
|
||||
ERR_error_string(ERR_get_error(), 0)));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ARC4Decryptor::ARC4Decryptor() {}
|
||||
|
||||
ARC4Decryptor::~ARC4Decryptor() {}
|
||||
|
||||
void ARC4Decryptor::init(const unsigned char* key, size_t keyLength)
|
||||
{
|
||||
ctx_.init(key, keyLength, 0);
|
||||
}
|
||||
|
||||
void ARC4Decryptor::decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength)
|
||||
{
|
||||
int soutLength = outLength;
|
||||
if(!EVP_CipherUpdate(ctx_.getCipherContext(), out, &soutLength,
|
||||
in, inLength)) {
|
||||
handleError();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,62 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_LIBSSL_ARC4_DECRYPTOR_H
|
||||
#define D_LIBSSL_ARC4_DECRYPTOR_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "LibsslARC4Context.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ARC4Decryptor {
|
||||
private:
|
||||
LibsslARC4Context ctx_;
|
||||
public:
|
||||
ARC4Decryptor();
|
||||
|
||||
~ARC4Decryptor();
|
||||
|
||||
void init(const unsigned char* key, size_t keyLength);
|
||||
|
||||
void decrypt(unsigned char* out, size_t outLength,
|
||||
const unsigned char* in, size_t inLength);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_LIBSSL_ARC4_DECRYPTOR_H
|
|
@ -46,7 +46,6 @@
|
|||
#include "a2netcompat.h"
|
||||
#include "DHKeyExchange.h"
|
||||
#include "ARC4Encryptor.h"
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "MessageDigest.h"
|
||||
#include "message_digest_helper.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
|
@ -204,14 +203,14 @@ void MSEHandshake::initCipher(const unsigned char* infoHash)
|
|||
sha1_->reset();
|
||||
message_digest::digest(peerCipherKey, sizeof(peerCipherKey),
|
||||
sha1_, s, sizeof(s));
|
||||
decryptor_.reset(new ARC4Decryptor());
|
||||
decryptor_.reset(new ARC4Encryptor());
|
||||
decryptor_->init(peerCipherKey, sizeof(peerCipherKey));
|
||||
|
||||
// discard first 1024 bytes ARC4 output.
|
||||
unsigned char from[1024];
|
||||
unsigned char to[1024];
|
||||
encryptor_->encrypt(to, 1024, from, 1024);
|
||||
decryptor_->decrypt(to, 1024, from, 1024);
|
||||
decryptor_->encrypt(to, 1024, from, 1024);
|
||||
|
||||
if(initiator_) {
|
||||
ARC4Encryptor enc;
|
||||
|
@ -264,7 +263,7 @@ void MSEHandshake::createReq23Hash(unsigned char* md, const unsigned char* infoH
|
|||
uint16_t MSEHandshake::decodeLength16(const unsigned char* buffer)
|
||||
{
|
||||
uint16_t be;
|
||||
decryptor_->decrypt(reinterpret_cast<unsigned char*>(&be),
|
||||
decryptor_->encrypt(reinterpret_cast<unsigned char*>(&be),
|
||||
sizeof(be),
|
||||
buffer, sizeof(be));
|
||||
return ntohs(be);
|
||||
|
@ -355,7 +354,7 @@ bool MSEHandshake::receiveInitiatorCryptoSelectAndPadDLength()
|
|||
unsigned char* rbufptr = rbuf_;
|
||||
{
|
||||
unsigned char cryptoSelect[CRYPTO_BITFIELD_LENGTH];
|
||||
decryptor_->decrypt(cryptoSelect, sizeof(cryptoSelect),
|
||||
decryptor_->encrypt(cryptoSelect, sizeof(cryptoSelect),
|
||||
rbufptr, sizeof(cryptoSelect));
|
||||
if(cryptoSelect[3]&CRYPTO_PLAIN_TEXT &&
|
||||
option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
|
||||
|
@ -392,7 +391,7 @@ bool MSEHandshake::receivePad()
|
|||
return true;
|
||||
}
|
||||
unsigned char temp[MAX_PAD_LENGTH];
|
||||
decryptor_->decrypt(temp, padLength_, rbuf_, padLength_);
|
||||
decryptor_->encrypt(temp, padLength_, rbuf_, padLength_);
|
||||
// shift rbuf_
|
||||
shiftBuffer(padLength_);
|
||||
return true;
|
||||
|
@ -459,7 +458,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
|
|||
rbufptr += VC_LENGTH;
|
||||
{
|
||||
unsigned char cryptoProvide[CRYPTO_BITFIELD_LENGTH];
|
||||
decryptor_->decrypt(cryptoProvide, sizeof(cryptoProvide),
|
||||
decryptor_->encrypt(cryptoProvide, sizeof(cryptoProvide),
|
||||
rbufptr, sizeof(cryptoProvide));
|
||||
// TODO choose the crypto type based on the preference.
|
||||
// For now, choose ARC4.
|
||||
|
@ -514,7 +513,7 @@ bool MSEHandshake::receiveReceiverIA()
|
|||
}
|
||||
delete [] ia_;
|
||||
ia_ = new unsigned char[iaLength_];
|
||||
decryptor_->decrypt(ia_, iaLength_, rbuf_, iaLength_);
|
||||
decryptor_->encrypt(ia_, iaLength_, rbuf_, iaLength_);
|
||||
A2_LOG_DEBUG(fmt("CUID#%lld - IA received.", cuid_));
|
||||
// shift rbuf_
|
||||
shiftBuffer(iaLength_);
|
||||
|
@ -566,7 +565,7 @@ void MSEHandshake::verifyVC(const unsigned char* vcbuf)
|
|||
{
|
||||
A2_LOG_DEBUG(fmt("CUID#%lld - Verifying VC.", cuid_));
|
||||
unsigned char vc[VC_LENGTH];
|
||||
decryptor_->decrypt(vc, sizeof(vc), vcbuf, sizeof(vc));
|
||||
decryptor_->encrypt(vc, sizeof(vc), vcbuf, sizeof(vc));
|
||||
if(memcmp(VC, vc, sizeof(VC)) != 0) {
|
||||
throw DL_ABORT_EX
|
||||
(fmt("Invalid VC: %s", util::toHex(vc, VC_LENGTH).c_str()));
|
||||
|
|
|
@ -50,7 +50,6 @@ class Option;
|
|||
class SocketCore;
|
||||
class DHKeyExchange;
|
||||
class ARC4Encryptor;
|
||||
class ARC4Decryptor;
|
||||
class DownloadContext;
|
||||
class MessageDigest;
|
||||
|
||||
|
@ -90,7 +89,7 @@ private:
|
|||
CRYPTO_TYPE negotiatedCryptoType_;
|
||||
DHKeyExchange* dh_;
|
||||
SharedHandle<ARC4Encryptor> encryptor_;
|
||||
SharedHandle<ARC4Decryptor> decryptor_;
|
||||
SharedHandle<ARC4Encryptor> decryptor_;
|
||||
unsigned char infoHash_[INFO_HASH_LENGTH];
|
||||
unsigned char secret_[KEY_LENGTH];
|
||||
bool initiator_;
|
||||
|
@ -203,7 +202,7 @@ public:
|
|||
return encryptor_;
|
||||
}
|
||||
|
||||
const SharedHandle<ARC4Decryptor>& getDecryptor() const
|
||||
const SharedHandle<ARC4Encryptor>& getDecryptor() const
|
||||
{
|
||||
return decryptor_;
|
||||
}
|
||||
|
|
|
@ -265,7 +265,6 @@ endif # HAVE_LIBGNUTLS
|
|||
if HAVE_LIBGCRYPT
|
||||
SRCS += LibgcryptMessageDigestImpl.cc LibgcryptMessageDigestImpl.h\
|
||||
LibgcryptARC4Context.cc LibgcryptARC4Context.h\
|
||||
LibgcryptARC4Decryptor.cc LibgcryptARC4Decryptor.h\
|
||||
LibgcryptARC4Encryptor.cc LibgcryptARC4Encryptor.h\
|
||||
LibgcryptDHKeyExchange.cc LibgcryptDHKeyExchange.h
|
||||
endif # HAVE_LIBGCRYPT
|
||||
|
@ -273,7 +272,6 @@ endif # HAVE_LIBGCRYPT
|
|||
if HAVE_LIBNETTLE
|
||||
SRCS += LibnettleMessageDigestImpl.cc LibnettleMessageDigestImpl.h\
|
||||
LibnettleARC4Context.cc LibnettleARC4Context.h\
|
||||
LibnettleARC4Decryptor.cc LibnettleARC4Decryptor.h\
|
||||
LibnettleARC4Encryptor.cc LibnettleARC4Encryptor.h
|
||||
endif # HAVE_LIBNETTLE
|
||||
|
||||
|
@ -286,7 +284,6 @@ if HAVE_OPENSSL
|
|||
SRCS += LibsslTLSContext.cc LibsslTLSContext.h\
|
||||
LibsslMessageDigestImpl.cc LibsslMessageDigestImpl.h\
|
||||
LibsslARC4Context.cc LibsslARC4Context.h\
|
||||
LibsslARC4Decryptor.cc LibsslARC4Decryptor.h\
|
||||
LibsslARC4Encryptor.cc LibsslARC4Encryptor.h\
|
||||
LibsslDHKeyExchange.cc LibsslDHKeyExchange.h
|
||||
endif # HAVE_OPENSSL
|
||||
|
@ -466,7 +463,6 @@ SRCS += PeerAbstractCommand.cc PeerAbstractCommand.h\
|
|||
InitiatorMSEHandshakeCommand.cc InitiatorMSEHandshakeCommand.h\
|
||||
ReceiverMSEHandshakeCommand.cc ReceiverMSEHandshakeCommand.h\
|
||||
MSEHandshake.cc MSEHandshake.h\
|
||||
ARC4Decryptor.h\
|
||||
ARC4Encryptor.h\
|
||||
DHKeyExchange.h\
|
||||
BtConstants.h\
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "Socket.h"
|
||||
#include "a2netcompat.h"
|
||||
#include "ARC4Encryptor.h"
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "fmt.h"
|
||||
#include "util.h"
|
||||
#include "Peer.h"
|
||||
|
@ -216,7 +215,7 @@ void PeerConnection::readData
|
|||
unsigned char temp[MAX_PAYLOAD_LEN];
|
||||
assert(MAX_PAYLOAD_LEN >= length);
|
||||
socket_->readData(temp, length);
|
||||
decryptor_->decrypt(data, length, temp, length);
|
||||
decryptor_->encrypt(data, length, temp, length);
|
||||
} else {
|
||||
socket_->readData(data, length);
|
||||
}
|
||||
|
@ -224,7 +223,7 @@ void PeerConnection::readData
|
|||
|
||||
void PeerConnection::enableEncryption
|
||||
(const SharedHandle<ARC4Encryptor>& encryptor,
|
||||
const SharedHandle<ARC4Decryptor>& decryptor)
|
||||
const SharedHandle<ARC4Encryptor>& decryptor)
|
||||
{
|
||||
encryptor_ = encryptor;
|
||||
decryptor_ = decryptor;
|
||||
|
|
|
@ -48,7 +48,6 @@ namespace aria2 {
|
|||
class Peer;
|
||||
class SocketCore;
|
||||
class ARC4Encryptor;
|
||||
class ARC4Decryptor;
|
||||
|
||||
// The maximum length of payload. Messages beyond that length are
|
||||
// dropped.
|
||||
|
@ -70,7 +69,7 @@ private:
|
|||
|
||||
bool encryptionEnabled_;
|
||||
SharedHandle<ARC4Encryptor> encryptor_;
|
||||
SharedHandle<ARC4Decryptor> decryptor_;
|
||||
SharedHandle<ARC4Encryptor> decryptor_;
|
||||
|
||||
bool prevPeek_;
|
||||
|
||||
|
@ -104,7 +103,7 @@ public:
|
|||
(unsigned char* data, size_t& dataLength, bool peek = false);
|
||||
|
||||
void enableEncryption(const SharedHandle<ARC4Encryptor>& encryptor,
|
||||
const SharedHandle<ARC4Decryptor>& decryptor);
|
||||
const SharedHandle<ARC4Encryptor>& decryptor);
|
||||
|
||||
void presetBuffer(const unsigned char* data, size_t length);
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "Option.h"
|
||||
#include "MSEHandshake.h"
|
||||
#include "ARC4Encryptor.h"
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "BtRegistry.h"
|
||||
#include "DownloadContext.h"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <cstring>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "ARC4Decryptor.h"
|
||||
#include "Exception.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -12,23 +11,23 @@ namespace aria2 {
|
|||
class ARC4Test:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(ARC4Test);
|
||||
CPPUNIT_TEST(testEncryptDecrypt);
|
||||
CPPUNIT_TEST(testEncrypt);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
||||
void tearDown() {}
|
||||
|
||||
void testEncryptDecrypt();
|
||||
void testEncrypt();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ARC4Test);
|
||||
|
||||
void ARC4Test::testEncryptDecrypt()
|
||||
void ARC4Test::testEncrypt()
|
||||
{
|
||||
ARC4Encryptor enc;
|
||||
ARC4Decryptor dec;
|
||||
ARC4Encryptor dec;
|
||||
const size_t LEN = 20;
|
||||
unsigned char key[LEN];
|
||||
memset(key, 0, LEN);
|
||||
|
@ -39,12 +38,12 @@ void ARC4Test::testEncryptDecrypt()
|
|||
unsigned char encrypted[LEN];
|
||||
unsigned char decrypted[LEN];
|
||||
enc.encrypt(encrypted, LEN, key, LEN);
|
||||
dec.decrypt(decrypted, LEN, encrypted, LEN);
|
||||
dec.encrypt(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);
|
||||
dec.encrypt(decrypted, LEN, encrypted, LEN);
|
||||
|
||||
CPPUNIT_ASSERT(memcmp(key, decrypted, LEN) == 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue