Skip to content

Commit

Permalink
encryption verification added, sent successful anon transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
proletesseract committed Feb 1, 2016
1 parent dac6cfe commit 8e10f4a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 53 deletions.
2 changes: 1 addition & 1 deletion NavajoCoin-qt.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.4.1, 2016-01-10T22:43:23. -->
<!-- Written by QtCreator 3.4.1, 2016-01-27T12:57:47. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
81 changes: 31 additions & 50 deletions src/qt/sendcoinsdialog.cpp
Expand Up @@ -203,6 +203,7 @@ bool SendCoinsDialog::testServer(QString serverAddress, QString localHash)

if(type == "SUCCESS" && serverHash == localHash) {
selectedServer = jsonData;
selectedServerAddress = serverAddress;
return true;
} else {
return false;
Expand Down Expand Up @@ -281,6 +282,10 @@ QString SendCoinsDialog::encryptAddress(QString userAddress, QString serverPubli
memcpy( publicKey, serverPublicKey.toStdString().c_str() ,serverPublicKey.size());
publicKey[serverPublicKey.size()] = 0;

char plainText[userAddress.size()+1];
memcpy( plainText, userAddress.toStdString().c_str() ,userAddress.size());
plainText[userAddress.size()] = 0;

unsigned char encrypted[4098]={};

int encrypted_length= this->public_encrypt(plainText,strlen(plainText),publicKey,encrypted);
Expand All @@ -289,6 +294,8 @@ QString SendCoinsDialog::encryptAddress(QString userAddress, QString serverPubli
{
qDebug() << QString("Public Encrypt failed");
exit(0);
} else {
QString encryptedString = this->charToString(encrypted);
}

QByteArray convertedString = QByteArray(encrypted);
Expand All @@ -299,57 +306,36 @@ QString SendCoinsDialog::encryptAddress(QString userAddress, QString serverPubli

}

QString SendCoinsDialog::testDecryption(QString txComment, QString serverAddress){
bool SendCoinsDialog::testEncryption(QString txComment){

QSslSocket *socket = new QSslSocket(this);
socket->setPeerVerifyMode(socket->VerifyNone);

socket->connectToHostEncrypted("anon.navajocoin.org", 443);
socket->connectToHostEncrypted(selectedServerAddress, 443);

if(!socket->waitForEncrypted()){
qDebug() << socket->errorString();
exit(0);
return false;
}

QList<SendCoinsRecipient> recipients;
bool valid = true;

if(!model)
return;
QByteArray urlEncoded = QUrl::toPercentEncoding(txComment);

SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
if(entry)
{
if(entry->validate())
{
recipients.append(entry->getValue());
}
else
{
valid = false;
}
}
QString urlEncodedQString = QString(urlEncoded);

QString qAddress;
foreach(const SendCoinsRecipient &rcp, recipients){
qAddress = rcp.address;
}
int contentLength = urlEncoded.length() + 10;

int contentLength = txComment.length() + 8;

QString reqString = QString("POST /api/decrypt-comment HTTP/1.1\r\n" \
QString reqString = QString("POST /api/check-encryption HTTP/1.1\r\n" \
"Host: %1\r\n" \
"Content-Type: application/x-www-form-urlencoded\r\n" \
"Content-Length: %2\r\n" \
"Connection: Close\r\n\r\n" \
"address=%3\r\n").arg(serverAddress).arg(contentLength).arg(txComment);
"encrypted=%3\r\n").arg(selectedServerAddress).arg(contentLength).arg(urlEncodedQString);

socket->write(reqString.toUtf8());

while (socket->waitForReadyRead()){

while(socket->canReadLine()){
//read all the lines
QString line = socket->readLine();
}

Expand All @@ -358,16 +344,10 @@ QString SendCoinsDialog::testDecryption(QString txComment, QString serverAddress
QJsonObject jsonObject = jsonDoc.object();
QString type = jsonObject["type"].toString();

qDebug() << rawReply;

if(type == "SUCCESS"){

QString address = jsonObject["address"].toString();
return address;

if(type == "SUCCESS") {
return true;
} else {
QString message = jsonObject["message"].toString();
return message;
return false;
}
}
}
Expand All @@ -380,7 +360,6 @@ void SendCoinsDialog::on_sendButton_clicked()
this->sendCoins(node);
}else{


QString anonFileContents;
QString anonFilePath = QString("%1%2%3").arg(GetDefaultDataDir().string().c_str()).arg(QDir::separator()).arg("anon.dat");
QFile anonFile(anonFilePath);
Expand All @@ -406,8 +385,9 @@ void SendCoinsDialog::on_sendButton_clicked()
QList<SendCoinsRecipient> recipients;
bool valid = true;

if(!model)
if(!model){
return;
}

SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
if(entry)
Expand Down Expand Up @@ -439,19 +419,20 @@ void SendCoinsDialog::on_sendButton_clicked()

QString publicKey = selectedServer["public_key"].toString();
QString serverAddress = selectedServer["address"].toString();
minAmount = selectedServer["min_amount"].toDouble();
maxAmount = selectedServer["max_amount"].toDouble();
double txFee = selectedServer["transaction_fee"].toDouble();
minAmount = selectedServer["min_amount"].toString().toDouble();
maxAmount = selectedServer["max_amount"].toString().toDouble();
double txFee = selectedServer["transaction_fee"].toString().toDouble();

QString txComment = this->encryptAddress(qAddress, publicKey);

qDebug() << QString("Encrypted Comment %1").arg(txComment);


QString decryptionResult = this->testDecryption(txComment, serverAddress);

qDebug() << decryptionResult;
bool decryptionResult = this->testEncryption(txComment);

if(!decryptionResult) {
QMessageBox::warning(this, tr("Anonymous Transaction"),
tr("Unable to verify encryption, please try again."),
QMessageBox::Ok, QMessageBox::Ok);
return false;
}

model->setAnonDetails(minAmount, maxAmount, txComment);

Expand All @@ -461,7 +442,7 @@ void SendCoinsDialog::on_sendButton_clicked()
reply = QMessageBox::question(this, "Anonymous Transaction", messageString, QMessageBox::Yes|QMessageBox::No);

if(reply == QMessageBox::Yes){
this->sendCoins(address);
this->sendCoins(serverAddress);
}

}//else
Expand Down
4 changes: 2 additions & 2 deletions src/qt/sendcoinsdialog.h
Expand Up @@ -61,6 +61,7 @@ public slots:
double minAmount;
double maxAmount;
QJsonObject selectedServer;
QString selectedServerAddress;

protected:
void sendCoins(QString anonNode);
Expand Down Expand Up @@ -90,8 +91,7 @@ private slots:
RSA * createRSA(unsigned char * key, int isPublic);
void printLastError(char *msg);
QString charToString(unsigned char *originalChar);
QString charToBase64(unsigned char *originalChar);
QString testDecryption(QString txComment, QString serverAddress);
bool testEncryption(QString txComment);
};

#endif // SENDCOINSDIALOG_H

0 comments on commit 8e10f4a

Please sign in to comment.