From fd2bc4ce1866aedf684bebf29e9e9c543a9dfbe7 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 28 Oct 2021 12:12:00 +0800 Subject: [PATCH] Qt/CommaApi: cache private key (#22715) * cache private key * space * no need to check mtime * call_once * simplify old-commit-hash: 3f4cc9a246e2a244e219f9766cd0edec93a54e26 --- selfdrive/ui/qt/api.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index 0c344056ff..af959e6cd9 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -19,14 +19,12 @@ namespace CommaApi { QByteArray rsa_sign(const QByteArray &data) { - auto file = QFile(Path::rsa_file().c_str()); - if (!file.open(QIODevice::ReadOnly)) { + static std::string key = util::read_file(Path::rsa_file()); + if (key.empty()) { qDebug() << "No RSA private key found, please run manager.py or registration.py"; - return QByteArray(); + return {}; } - auto key = file.readAll(); - file.close(); - file.deleteLater(); + BIO* mem = BIO_new_mem_buf(key.data(), key.size()); assert(mem); RSA* rsa_private = PEM_read_bio_RSAPrivateKey(mem, NULL, NULL, NULL);