|
|
|
@ -1,16 +1,15 @@ |
|
|
|
|
#include "selfdrive/ui/qt/api.h" |
|
|
|
|
|
|
|
|
|
#include <openssl/bio.h> |
|
|
|
|
#include <openssl/pem.h> |
|
|
|
|
#include <openssl/rsa.h> |
|
|
|
|
|
|
|
|
|
#include <QCryptographicHash> |
|
|
|
|
#include <QDateTime> |
|
|
|
|
#include <QDebug> |
|
|
|
|
#include <QFile> |
|
|
|
|
#include <QJsonDocument> |
|
|
|
|
#include <QJsonObject> |
|
|
|
|
#include <QNetworkReply> |
|
|
|
|
#include <QNetworkRequest> |
|
|
|
|
#include <QRandomGenerator> |
|
|
|
|
#include <QString> |
|
|
|
|
#include <QTimer> |
|
|
|
|
#include <QWidget> |
|
|
|
|
|
|
|
|
|
#include "selfdrive/common/params.h" |
|
|
|
|
#include "selfdrive/common/util.h" |
|
|
|
@ -44,21 +43,14 @@ QByteArray CommaApi::rsa_sign(const QByteArray &data) { |
|
|
|
|
return sig; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString CommaApi::create_jwt(const QVector<QPair<QString, QJsonValue>> &payloads, int expiry) { |
|
|
|
|
QString dongle_id = QString::fromStdString(Params().get("DongleId")); |
|
|
|
|
|
|
|
|
|
QJsonObject header; |
|
|
|
|
header.insert("alg", "RS256"); |
|
|
|
|
|
|
|
|
|
QJsonObject payload; |
|
|
|
|
payload.insert("identity", dongle_id); |
|
|
|
|
QString CommaApi::create_jwt(const QJsonObject &payloads, int expiry) { |
|
|
|
|
QJsonObject header = {{"alg", "RS256"}}; |
|
|
|
|
|
|
|
|
|
QString dongle_id = QString::fromStdString(Params().get("DongleId")); |
|
|
|
|
auto t = QDateTime::currentSecsSinceEpoch(); |
|
|
|
|
payload.insert("nbf", t); |
|
|
|
|
payload.insert("iat", t); |
|
|
|
|
payload.insert("exp", t + expiry); |
|
|
|
|
for (auto &load : payloads) { |
|
|
|
|
payload.insert(load.first, load.second); |
|
|
|
|
QJsonObject payload = {{"identity", dongle_id}, {"nbf", t}, {"iat", t}, {"exp", t + expiry}}; |
|
|
|
|
for (auto it = payloads.begin(); it != payloads.end(); ++it) { |
|
|
|
|
payload.insert(it.key(), it.value()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto b64_opts = QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals; |
|
|
|
|