Commit a307038e authored by Marco Simonelli's avatar Marco Simonelli Committed by MarcoSi1214
Browse files

Progress on V3:

    - UI Accepts v3 address
    - Attempts to establish connection to v3 contact
    - Hacky fix to handle key management, fix this.
    - Proofs still seem to be broken
parent d1fafed2
......@@ -33,11 +33,7 @@
#include "ContactIDValidator.h"
// 2-7, not 0-9, as base32 only contains A-Z 2-7
<<<<<<< HEAD
static QRegularExpression regex(QStringLiteral("(torsion|ricochet):(([a-z2-7]{56})|([a-z2-7]{16}))"));
=======
static QRegularExpression regex(QStringLiteral("(torsion|ricochet):([a-z2-7]{56}|[a-z2-7]{16})"));
>>>>>>> accab653a2435d2fc15de6b62fe09667bab437c4
ContactIDValidator::ContactIDValidator(QObject *parent)
: QRegularExpressionValidator(parent), m_uniqueIdentity(0)
......@@ -87,11 +83,7 @@ void ContactIDValidator::fixup(QString &text) const
bool ContactIDValidator::isValidID(const QString &text)
{
<<<<<<< HEAD
return regex.match(text).hasMatch();
=======
return (regex.match(text).hasMatch());
>>>>>>> accab653a2435d2fc15de6b62fe09667bab437c4
}
QString ContactIDValidator::hostnameFromID(const QString &ID)
......
......@@ -160,7 +160,7 @@ void ContactUser::updateOutgoingSocket()
if (!m_outgoingSocket) {
m_outgoingSocket = new Protocol::OutboundConnector(this);
//todo auth change here: if v3: pass both private and public key
m_outgoingSocket->setAuthPrivateKey(identity->hiddenService()->privateKey());
m_outgoingSocket->setAuthPrivateKey(identity->hiddenService()->privateKey(), identity->hiddenService()->V3serviceId());
connect(m_outgoingSocket, &Protocol::OutboundConnector::ready, this,
[this]() {
assignConnection(m_outgoingSocket->takeConnection());
......
......@@ -50,6 +50,7 @@ class AuthHiddenServiceChannelPrivate : public ChannelPrivate
{
public:
CryptoKey privateKey;
CryptoKey v3serviceID;
QByteArray clientCookie, serverCookie;
bool accepted;
......@@ -81,7 +82,7 @@ AuthHiddenServiceChannel::AuthHiddenServiceChannel(Direction dir, Connection *co
);
}
void AuthHiddenServiceChannel::setPrivateKey(const CryptoKey &key)
void AuthHiddenServiceChannel::setPrivateKey(const CryptoKey &key, const CryptoKey &v3serviceID)
{
Q_D(AuthHiddenServiceChannel);
if (isOpened()) {
......@@ -94,8 +95,9 @@ void AuthHiddenServiceChannel::setPrivateKey(const CryptoKey &key)
BUG() << "AuthHiddenServiceChannel cannot authenticate without a valid private key";
return;
}
d->privateKey = key;
d->v3serviceID = v3serviceID;
if(key.getDecodedHexV3PrivateKey().data() != "")
d->privateKey.loadFromDataV3(key.getDecodedHexV3PrivateKey().data(), CryptoKey::V3ServiceID);
}
bool AuthHiddenServiceChannel::allowInboundChannelRequest(const Data::Control::OpenChannel *request, Data::Control::ChannelResult *result)
......@@ -149,7 +151,11 @@ bool AuthHiddenServiceChannel::allowOutboundChannelRequest(Data::Control::OpenCh
{
Q_D(AuthHiddenServiceChannel);
//todo auth change condition to add V3 support
//todo THIS NEEDS TO BE FIXED
// IT IS BAD
// DO NOT USE THIS IN PRODUCTION
// PLEASE
d->privateKey.v3privateKey = d->privateKey.v3serviceID;
if (!d->privateKey.isLoaded()) {
BUG() << "AuthHiddenServiceChannel can't be opened without a private key";
return false;
......@@ -205,11 +211,7 @@ void AuthHiddenServiceChannel::sendAuthMessage()
}
// get the public key
<<<<<<< HEAD
// TODO: check if V3 public key is empty, if it isn't then we are using v3
=======
//todo auth check here to see if the key is a v3 service id, to get the v3 public key
>>>>>>> accab653a2435d2fc15de6b62fe09667bab437c4
QByteArray publicKey = d->privateKey.encodedPublicKey(CryptoKey::DER);
if (publicKey.size() > 150) {
BUG() << "Unexpected size for encoded public key";
......@@ -270,11 +272,7 @@ QByteArray AuthHiddenServiceChannelPrivate::getProofData(const QString &client)
QByteArray serverHostname = connection->serverHostname().replace(QLatin1String(".onion"), QLatin1String("")).toLatin1();
QByteArray clientHostname = client.toLatin1();
<<<<<<< HEAD
if ((clientHostname.size() != 16 || serverHostname.size() != 16) ||
=======
if ((clientHostname.size() != 16 || serverHostname.size() != 16) ||
>>>>>>> accab653a2435d2fc15de6b62fe09667bab437c4
(clientHostname.size() != 56 || serverHostname.size() != 56)) {
BUG() << "AuthHiddenServiceChannel can't figure out the client and server hostnames";
return QByteArray();
......
......@@ -51,7 +51,7 @@ class AuthHiddenServiceChannel : public Channel
public:
explicit AuthHiddenServiceChannel(Direction direction, Connection *connection);
void setPrivateKey(const CryptoKey &key);
void setPrivateKey(const CryptoKey &key, const CryptoKey &v3serviceID);
signals:
void authSuccessful();
......
......@@ -54,6 +54,7 @@ public:
quint16 port;
OutboundConnector::Status status;
CryptoKey authPrivateKey;
CryptoKey authV3ServiceID;
QString errorMessage;
QTimer errorRetryTimer;
int errorRetryCount;
......@@ -90,7 +91,7 @@ OutboundConnector::~OutboundConnector()
{
}
void OutboundConnector::setAuthPrivateKey(const CryptoKey &key)
void OutboundConnector::setAuthPrivateKey(const CryptoKey &key, const CryptoKey &v3serviceID)
{
//todo auth change condition to add V3 support
if (!key.isLoaded() || !key.isPrivate()) {
......@@ -99,6 +100,7 @@ void OutboundConnector::setAuthPrivateKey(const CryptoKey &key)
}
d->authPrivateKey = key;
d->authV3ServiceID = v3serviceID;
}
bool OutboundConnector::connectToHost(const QString &hostname, quint16 port)
......@@ -302,7 +304,7 @@ void OutboundConnectorPrivate::startAuthentication()
}
);
authChannel->setPrivateKey(authPrivateKey);
authChannel->setPrivateKey(authPrivateKey, authV3ServiceID);
if (!authChannel->openChannel()) {
setError(QStringLiteral("Unable to open authentication channel"));
}
......
......@@ -77,7 +77,7 @@ public:
QString errorMessage() const;
bool connectToHost(const QString &hostname, quint16 port);
void setAuthPrivateKey(const CryptoKey &key);
void setAuthPrivateKey(const CryptoKey &key, const CryptoKey &v3serviceID);
/* Take ownership of the Connection object when Ready
*
......
......@@ -4,11 +4,7 @@ import QtQuick.Layouts 1.0
ApplicationWindow {
id: addContactWindow
<<<<<<< HEAD
width: 620
=======
width: 640
>>>>>>> accab653a2435d2fc15de6b62fe09667bab437c4
height: 300
minimumWidth: width
maximumWidth: width
......
......@@ -188,8 +188,12 @@ bool CryptoKey::isLoaded() const{
//TODO: for v3
//FIXME: logic for v3 need to be corrected
if (v3privateKey.empty()) {
//if(v3ServiceID.length() == CryptoKey::V3ServiceIDByteLength){
//
//}
// v3 private key is empty. check service id
return v3serviceID.length() == CryptoKey::V3ServiceIDLength;
return (this->v3serviceID.length() == CryptoKey::V3ServiceIDLength) ||
(this->v3serviceID.length() == CryptoKey::V3ServiceIDByteLength);
}
else {
// v3 private key is not empty. check v3 private key
......@@ -299,6 +303,20 @@ QByteArray CryptoKey::getDecodedV3PrivateKey() const{
// }
}
QByteArray CryptoKey::getDecodedHexV3PrivateKey() const{
// if (!isLoaded() || version != V3 || !isPrivate()) {
// return QByteArray();
// } else {
QByteArray stringBytes = QByteArray::fromStdString(this->v3privateKey);
QByteArray bytes(QByteArray::fromHex(stringBytes.toHex()));
// bytes.toHex().constData() will show the char* of the hex representation of decoded key
if (bytes.size() == CryptoKey::V3PrivateKeyByteLength) {
return bytes;
} else {
return QByteArray();
}
//
}
/**
* return the number of bits of s v2 key
* @return number of bits
......@@ -755,3 +773,7 @@ bool base32_decode(char *dest, unsigned int destlen, const char *src, unsigned i
delete[] tmp;
return true;
}
std::string decode_base32(std::string encoded){
}
\ No newline at end of file
......@@ -49,6 +49,7 @@ public:
static const int V3PublicKeyLength = 52;
static const int V3PrivateKeyByteLength = 64;
static const int V3ServiceIDByteLength = 64;
static const int V3PublicKeyByteLength = 32;
static const int V3SignatureByteLength = 64;
......@@ -99,6 +100,7 @@ public:
Version getVersion() const { return this->version; }
QByteArray getDecodedV3PublicKey() const;
QByteArray getDecodedV3PrivateKey() const;
QByteArray getDecodedHexV3PrivateKey() const;
QByteArray publicKeyDigest() const;
QByteArray encodedPublicKey(KeyFormat format) const;
QByteArray encodedPrivateKey(KeyFormat format) const;
......@@ -127,7 +129,7 @@ private:
QExplicitlySharedDataPointer<Data> d;
public:
Version version;
std::string v3privateKey;
std::string v3publicKey;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment