mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:43:31 +02:00
Progress?
This commit is contained in:
parent
a2f2c23337
commit
373ef6c6ce
4 changed files with 16 additions and 10 deletions
|
@ -61,7 +61,7 @@ void Ledger::send(const QString& endpoint, const QString& success, const QString
|
||||||
|
|
||||||
void Ledger::signedSend(const QString& propertyName, const QByteArray& text, const QString& key, const QString& endpoint, const QString& success, const QString& fail, const bool controlled_failure) {
|
void Ledger::signedSend(const QString& propertyName, const QByteArray& text, const QString& key, const QString& endpoint, const QString& success, const QString& fail, const bool controlled_failure) {
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
QString signature = key.isEmpty() ? "" : wallet->signWithKey(text, key);
|
QString signature = wallet->signWithKey(text, key);
|
||||||
QJsonObject request;
|
QJsonObject request;
|
||||||
request[propertyName] = QString(text);
|
request[propertyName] = QString(text);
|
||||||
if (!controlled_failure) {
|
if (!controlled_failure) {
|
||||||
|
|
|
@ -547,13 +547,16 @@ QStringList Wallet::listPublicKeys() {
|
||||||
// the horror of code pages and so on (changing the bytes) by just returning a base64
|
// the horror of code pages and so on (changing the bytes) by just returning a base64
|
||||||
// encoded string representing the signature (suitable for http, etc...)
|
// encoded string representing the signature (suitable for http, etc...)
|
||||||
QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
|
QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
|
||||||
qCInfo(commerce) << "Signing text" << text << "with key" << key;
|
|
||||||
EC_KEY* ecPrivateKey = NULL;
|
EC_KEY* ecPrivateKey = NULL;
|
||||||
|
|
||||||
|
auto keyFilePathString = keyFilePath().toStdString();
|
||||||
if ((ecPrivateKey = readPrivateKey(keyFilePath().toStdString().c_str()))) {
|
if ((ecPrivateKey = readPrivateKey(keyFilePath().toStdString().c_str()))) {
|
||||||
unsigned char* sig = new unsigned char[ECDSA_size(ecPrivateKey)];
|
unsigned char* sig = new unsigned char[ECDSA_size(ecPrivateKey)];
|
||||||
|
|
||||||
unsigned int signatureBytes = 0;
|
unsigned int signatureBytes = 0;
|
||||||
|
|
||||||
|
qCInfo(commerce) << "Signing text" << text << "with key at" << ecPrivateKey;
|
||||||
|
|
||||||
QByteArray hashedPlaintext = QCryptographicHash::hash(text, QCryptographicHash::Sha256);
|
QByteArray hashedPlaintext = QCryptographicHash::hash(text, QCryptographicHash::Sha256);
|
||||||
|
|
||||||
|
|
||||||
|
@ -746,12 +749,10 @@ void Wallet::handleChallengeOwnershipPacket(QSharedPointer<ReceivedMessage> pack
|
||||||
}
|
}
|
||||||
|
|
||||||
EC_KEY_free(ec);
|
EC_KEY_free(ec);
|
||||||
QByteArray ba = sig.toLocal8Bit();
|
|
||||||
const char *sigChar = ba.data();
|
|
||||||
|
|
||||||
QByteArray textByteArray;
|
QByteArray textByteArray;
|
||||||
if (status > -1) {
|
if (status > -1) {
|
||||||
textByteArray = QByteArray(sigChar, (int) strlen(sigChar));
|
textByteArray = sig.toUtf8();
|
||||||
}
|
}
|
||||||
textByteArraySize = textByteArray.size();
|
textByteArraySize = textByteArray.size();
|
||||||
int certIDSize = certID.size();
|
int certIDSize = certID.size();
|
||||||
|
|
|
@ -2540,11 +2540,15 @@ bool EntityItemProperties::verifySignature(const QString& publicKey, const QByte
|
||||||
ec);
|
ec);
|
||||||
long error = ERR_get_error();
|
long error = ERR_get_error();
|
||||||
if (error != 0 || answer == -1) {
|
if (error != 0 || answer == -1) {
|
||||||
const char* error_str = ERR_error_string(error, NULL);
|
qCWarning(entities) << "ERROR while verifying signature!"
|
||||||
qCWarning(entities) << "ERROR while verifying signature! EC error:" << error_str
|
|
||||||
<< "\nKey:" << publicKey << "\nutf8 Key Length:" << keyLength
|
<< "\nKey:" << publicKey << "\nutf8 Key Length:" << keyLength
|
||||||
<< "\nDigest:" << digest << "\nDigest Length:" << digestLength
|
<< "\nDigest:" << digest << "\nDigest Length:" << digestLength
|
||||||
<< "\nSignature:" << signature << "\nSignature Length:" << signatureLength;
|
<< "\nSignature:" << signature << "\nSignature Length:" << signatureLength;
|
||||||
|
while (error != 0) {
|
||||||
|
const char* error_str = ERR_error_string(error, NULL);
|
||||||
|
qCWarning(entities) << "EC error:" << error_str;
|
||||||
|
error = ERR_get_error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EC_KEY_free(ec);
|
EC_KEY_free(ec);
|
||||||
if (bio) {
|
if (bio) {
|
||||||
|
|
|
@ -1189,13 +1189,14 @@ bool EntityTree::verifyNonce(const QString& certID, const QString& nonce, Entity
|
||||||
key = sent.second;
|
key = sent.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString annotatedKey = "-----BEGIN PUBLIC KEY-----\n" + key.insert(64, "\n") + "\n-----END PUBLIC KEY-----";
|
QString annotatedKey = "-----BEGIN PUBLIC KEY-----\n" + key.insert(64, "\n") + "\n-----END PUBLIC KEY-----\n";
|
||||||
bool verificationSuccess = EntityItemProperties::verifySignature(annotatedKey.toUtf8(), actualNonce.toUtf8(), nonce.toUtf8());
|
QByteArray hashedActualNonce = QCryptographicHash::hash(QByteArray::fromBase64(actualNonce.toUtf8()), QCryptographicHash::Sha256);
|
||||||
|
bool verificationSuccess = EntityItemProperties::verifySignature(annotatedKey.toUtf8(), hashedActualNonce, QByteArray::fromBase64(nonce.toUtf8()));
|
||||||
|
|
||||||
if (verificationSuccess) {
|
if (verificationSuccess) {
|
||||||
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "succeeded.";
|
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "succeeded.";
|
||||||
} else {
|
} else {
|
||||||
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "failed for nonce" << actualNonce << "key" << key << "signature" << nonce;
|
qCDebug(entities) << "Ownership challenge for Cert ID" << certID << "failed.\nHashed actual nonce (digest):" << hashedActualNonce << "\nSent nonce (signature)" << nonce << "\nKey" << key;
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationSuccess;
|
return verificationSuccess;
|
||||||
|
|
Loading…
Reference in a new issue