Skip to content

Commit

Permalink
MVHub: improved pseudonym handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-sturm committed Jan 20, 2025
1 parent 4b62b30 commit ccd990a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/MVHub/MVHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ QByteArray MVHub::jsonDataPseudo(QByteArray str)
"}";
}

QByteArray MVHub::parseJsonDataPseudo(QByteArray reply)
QByteArray MVHub::parseJsonDataPseudo(QByteArray reply, QByteArray context)
{
QJsonDocument doc = QJsonDocument::fromJson(reply);
QJsonArray entries = doc.object()["entry"].toArray();
Expand All @@ -181,19 +181,36 @@ QByteArray MVHub::parseJsonDataPseudo(QByteArray reply)
if (!object.contains("resourceType")) continue;
if (object["resourceType"].toString()!="Encounter") continue;

QByteArray encrypted = QByteArray::fromBase64(object["identifier"].toArray()[0].toObject()["value"].toString().toLatin1());

//get base64-encoded string from results
QByteArray str_base64 = object["identifier"].toArray()[0].toObject()["value"].toString().toLatin1().trimmed();
ui_.output->appendPlainText("base64-encoded reply: " + str_base64);

/*
with open(private_key_file, "rb") as f:
rsa_private_key = RSA.importKey(f.read())
rsa_private_key = PKCS1_v1_5.new(rsa_private_key)
sentinel = get_random_bytes(16)
return rsa_private_key.decrypt(base64.b64decode(enc_msg), sentinel).decode('utf-8')
QFile file2("T:\\users\\ahsturm1\\scripts\\2024_05_06_MVH\\encrypted_base64.txt");
file2.open(QIODevice::WriteOnly);
file2.write(str_base64);
file2.close();
QByteArray encrypted = QByteArray::fromBase64(str_base64);
QFile file3("T:\\users\\ahsturm1\\scripts\\2024_05_06_MVH\\encrypted.txt");
file3.open(QIODevice::WriteOnly);
file3.write(encrypted);
file3.close();
*/

//use webserice to decrypt (not easy in C++)
QString url = Settings::string("pseudo_decrypt_webservice");

QFile file(Settings::string("pseudo_key_"+context));
file.open(QIODevice::ReadOnly);
QByteArray data = file.readAll();
file.close();

ui_.output->appendPlainText("base64-encoded key: " +data.toBase64());
HttpHandler handler(true);
QByteArray reply = handler.post(url, "input="+str_base64+"&key="+data.toBase64());

return encrypted;
return reply;
}

THROW(ArgumentException, "Could not parse JSON for pseudonymization: " + reply);
Expand Down Expand Up @@ -364,7 +381,7 @@ void MVHub::test_apiPseudo()
HttpHandler handler(false);
QByteArray data = jsonDataPseudo(str);
QByteArray reply = handler.post(url, data, headers);
pseudo1 = parseJsonDataPseudo(reply);
pseudo1 = parseJsonDataPseudo(reply, "T_F");
}
ui_.output->appendPlainText("Pseudonym 1: " + pseudo1);

Expand Down
2 changes: 1 addition & 1 deletion src/MVHub/MVHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public slots:
//creates JSON input for pseudonymization
static QByteArray jsonDataPseudo(QByteArray str);
//parses JSON output of pseudonymization
static QByteArray parseJsonDataPseudo(QByteArray reply);
QByteArray parseJsonDataPseudo(QByteArray reply, QByteArray context);
};

#endif // MVHUB_H

0 comments on commit ccd990a

Please sign in to comment.