Commit accab653 authored by arufu's avatar arufu
Browse files

. modified several places to add v3 support

. added 'todo auth' comments to mark places to be changed for v3 auth
parent a656ef16
......@@ -33,8 +33,7 @@
#include "ContactIDValidator.h"
// 2-7, not 0-9, as base32 only contains A-Z 2-7
static QRegularExpression regex(QStringLiteral("(torsion|ricochet):([a-z2-7]{16})"));
static QRegularExpression regexV3(QStringLiteral("(torsion|ricochet):([a-z2-7]{56})"));
static QRegularExpression regex(QStringLiteral("(torsion|ricochet):([a-z2-7]{56}|[a-z2-7]{16})"));
ContactIDValidator::ContactIDValidator(QObject *parent)
: QRegularExpressionValidator(parent), m_uniqueIdentity(0)
......@@ -84,7 +83,7 @@ void ContactIDValidator::fixup(QString &text) const
bool ContactIDValidator::isValidID(const QString &text)
{
return (regex.match(text).hasMatch() || regexV3.match(text).hasMatch());
return (regex.match(text).hasMatch());
}
QString ContactIDValidator::hostnameFromID(const QString &ID)
......
......@@ -159,6 +159,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());
connect(m_outgoingSocket, &Protocol::OutboundConnector::ready, this,
[this]() {
......
......@@ -89,6 +89,7 @@ void AuthHiddenServiceChannel::setPrivateKey(const CryptoKey &key)
return;
}
//todo auth change condition to add V3 support
if (!key.isLoaded() || !key.isPrivate()) {
BUG() << "AuthHiddenServiceChannel cannot authenticate without a valid private key";
return;
......@@ -148,6 +149,7 @@ bool AuthHiddenServiceChannel::allowOutboundChannelRequest(Data::Control::OpenCh
{
Q_D(AuthHiddenServiceChannel);
//todo auth change condition to add V3 support
if (!d->privateKey.isLoaded()) {
BUG() << "AuthHiddenServiceChannel can't be opened without a private key";
return false;
......@@ -164,6 +166,7 @@ bool AuthHiddenServiceChannel::processChannelOpenResult(const Data::Control::Cha
{
Q_D(AuthHiddenServiceChannel);
// cookies are randomly generated with length 16
if (result->opened()) {
std::string cookie = result->GetExtension(Data::AuthHiddenService::server_cookie);
if (cookie.size() != 16) {
......@@ -194,6 +197,7 @@ void AuthHiddenServiceChannel::sendAuthMessage()
if (!isOpened())
return;
// cookie length is 16 for both v2 and v3
if (d->clientCookie.size() != 16 || d->serverCookie.size() != 16) {
BUG() << "AuthHiddenServiceChannel can't create a proof without valid cookies";
closeChannel();
......@@ -201,6 +205,7 @@ void AuthHiddenServiceChannel::sendAuthMessage()
}
// get the public key
//todo auth check here to see if the key is a v3 service id, to get the v3 public key
QByteArray publicKey = d->privateKey.encodedPublicKey(CryptoKey::DER);
if (publicKey.size() > 150) {
BUG() << "Unexpected size for encoded public key";
......@@ -217,6 +222,7 @@ void AuthHiddenServiceChannel::sendAuthMessage()
// message: proof data
QByteArray signature;
//FIXME: d->privateKey is a CryptoKey instance with v3serviceID=""
//todo auth check here to see if the key is a v3 service id, to get the v3 public key
QByteArray proofData = d->getProofData(d->privateKey.torServiceID());
if (!proofData.isEmpty()) {
// make a HMAC of the proof data
......@@ -260,7 +266,8 @@ QByteArray AuthHiddenServiceChannelPrivate::getProofData(const QString &client)
QByteArray serverHostname = connection->serverHostname().toLatin1().mid(0, 16);
QByteArray clientHostname = client.toLatin1();
if (clientHostname.size() != 16 || serverHostname.size() != 16) {
if ((clientHostname.size() != 16 || serverHostname.size() != 16) ||
(clientHostname.size() != 56 || serverHostname.size() != 56)) {
BUG() << "AuthHiddenServiceChannel can't figure out the client and server hostnames";
return QByteArray();
}
......
......@@ -92,6 +92,7 @@ OutboundConnector::~OutboundConnector()
void OutboundConnector::setAuthPrivateKey(const CryptoKey &key)
{
//todo auth change condition to add V3 support
if (!key.isLoaded() || !key.isPrivate()) {
BUG() << "Cannot make outbound connection without a valid private key";
return;
......
......@@ -4,7 +4,7 @@ import QtQuick.Layouts 1.0
ApplicationWindow {
id: addContactWindow
width: 400
width: 640
height: 300
minimumWidth: width
maximumWidth: width
......
......@@ -29,6 +29,7 @@ FocusScope {
placeholderText: "ricochet:"
focus: true
onTextChanged: errorBubble.clear()
ContactIDValidator {
......
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