openpgp: reject unsupported hash algorithms
This commit is contained in:
2 files changed
+14
No files matched your search
@@ -28,6 +28,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <gcrypt.h>
|
||||
@@ -51,6 +52,11 @@ public:
|
||||
: algo(algorithm)
|
||||
, consumed(0)
|
||||
{
|
||||
if (gcry_md_test_algo(algo) != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
throw std::runtime_error("unsupported hash algorithm");
|
||||
}
|
||||
|
||||
if (gcry_md_open(&md, algo, 0) != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
throw std::runtime_error("failed to create message digest object");
|
||||
|
||||
@@ -225,6 +225,10 @@ signature_rsa signature_rsa::from_buffer(const epee::span<const uint8_t> input)
|
||||
}
|
||||
|
||||
const auto hash_algorithm = buffer.read_big_endian<uint8_t>();
|
||||
if (hash_algorithm != openpgp::hash::algorithm::sha256)
|
||||
{
|
||||
throw std::runtime_error("unsupported signature hash algorithm");
|
||||
}
|
||||
|
||||
const auto hashed_data_length = buffer.read_big_endian<uint16_t>();
|
||||
std::vector<uint8_t> hashed_data = buffer.read(hashed_data_length);
|
||||
@@ -295,6 +299,10 @@ std::vector<uint8_t> signature_rsa::hash_asn_object_id() const
|
||||
{
|
||||
throw std::runtime_error("failed to get ASN.1 Object Identifier (OID) size");
|
||||
}
|
||||
if (size == 0)
|
||||
{
|
||||
throw std::runtime_error("hash algorithm has no ASN.1 Object Identifier (OID)");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> asn_object_id(size);
|
||||
if (gcry_md_algo_info(m_hash_algorithm, GCRYCTL_GET_ASNOID, &asn_object_id[0], &size) != GPG_ERR_NO_ERROR)
|
||||
|
||||
Reference in new issue
Block a user