From dabc496a2b86869b3e559a87efdd74af108a31f5 Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周六, 23 11月 2019 22:48:18 +0800 Subject: [PATCH] signature verified, tests --- src/library/os/openssl/signature_verifier.cpp | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/library/os/linux/verifier.cpp b/src/library/os/openssl/signature_verifier.cpp similarity index 88% rename from src/library/os/linux/verifier.cpp rename to src/library/os/openssl/signature_verifier.cpp index 26bd2d8..9c9f9fb 100644 --- a/src/library/os/linux/verifier.cpp +++ b/src/library/os/openssl/signature_verifier.cpp @@ -12,7 +12,7 @@ #include <public_key.h> -#include "../verifier.hpp" +#include "../signature_verifier.h" namespace license { #include "../../base/logger.h" @@ -26,7 +26,7 @@ } } -Verifier::Verifier() { +static void initialize() { static int initialized = 0; if (initialized == 0) { initialized = 1; @@ -36,13 +36,14 @@ } } -FUNCTION_RETURN Verifier::verifySignature(const std::string& stringToVerify, const std::string& signatureB64) { +FUNCTION_RETURN verify_signature(const std::string& stringToVerify, const std::string& signatureB64) { EVP_MD_CTX* mdctx = NULL; const unsigned char pubKey[] = PUBLIC_KEY; int func_ret = 0; + initialize(); - BIO* bio = BIO_new_mem_buf((void*)(pubKey), PUBLIC_KEY_LEN); - RSA* rsa = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL); + BIO* bio = BIO_new_mem_buf((void*)(pubKey), sizeof(pubKey)); + RSA* rsa = d2i_RSAPublicKey_bio(bio, NULL); BIO_free(bio); if (rsa == NULL) { LOG_ERROR("Error reading public key"); @@ -97,9 +98,6 @@ free_resources(pkey, mdctx); return result; -} - -Verifier::~Verifier() { } } /* namespace license */ -- Gitblit v1.9.1