openpgp: reject revoked subkeys and use newest binding signature
What changed, and why it matters
This change fixes how the Monero GUI reads OpenPGP public keys. Previously, the software might accept a revoked (cancelled) subkey or use an older signature that allowed signing even when a newer one did not. After the patch, revoked subkeys are rejected and only the newest valid binding signature is used to decide whether a subkey can sign. This prevents an attacker who controls an OpenPGP key file from tricking the wallet into trusting a subkey that should not be trusted.
Treat this commit as a security fix. Backport to supported branches, verify that OpenPGP key validation tests cover revoked subkeys and multiple binding signatures with conflicting creation times, and review whether other OpenPGP consumers in the project share the old logic.
Security signals we found
OpenPGP subkey revocation now enforced
Binding signature selection changed from first-match to newest-by-creation-time
Marker and Trust packets now explicitly skipped without terminating subkey signature sequence
Signature parsing now extracts signature creation time subpacket (type 2)
Subkey acceptance now gated on both non-revoked status and latest signing-capable binding signature
Evidence from the diff
The patch refactors subkey signature parsing in src/openpgp/openpgp.cpp. It introduces a read_subkey_signature helper that records the signature type, creation time, and whether key flags permit signing. The public_key_block parser now collects all signature packets following a public subkey (ignoring Marker/Trust packets), detects signature_type_subkey_revocation (0x28), and selects the newest binding signature (0x18) by creation_time. It only accepts the subkey if the newest binding signature allows signing. Previously, the code accepted the first binding signature and ignored revocation signatures, so an older signing-capable binding could persist after revocation, or a revoked subkey could still be used.
Changed components
src/openpgp/openpgp.cppsrc/openpgp/serialization.hMonero GUI OpenPGP public key import / verification pathInspect captured patch +74 / −20
### src/openpgp/openpgp.cpp
@@ -49,6 +49,8 @@ namespace
{
constexpr const uint8_t signature_type_subkey_binding = 0x18;
+constexpr const uint8_t signature_type_subkey_revocation = 0x28;
+constexpr const uint8_t subpacket_type_creation_time = 2;
constexpr const uint8_t subpacket_type_key_flags = 27;
constexpr const uint8_t key_flag_sign_data = 0x02;
@@ -276,16 +278,27 @@ public_key_rsa read_public_key(const std::vector<uint8_t> &data)
gcry_mpi_get_nbits(public_key_n.get()));
}
-bool subkey_binding_allows_signing(const std::vector<uint8_t> &data)
+struct subkey_signature
+{
+ uint8_t type;
+ uint32_t creation_time;
+ bool allows_signing;
+};
+
+// Returns false for signature versions other than 4
+bool read_subkey_signature(const std::vector<uint8_t> &data, subkey_signature &result)
{
deserializer<epee::span<const uint8_t>> signature(epee::to_span(data));
- if (signature.read_big_endian<uint8_t>() != 4 ||
- signature.read_big_endian<uint8_t>() != signature_type_subkey_binding)
+ if (signature.read_big_endian<uint8_t>() != 4)
{
return false;
}
+ result.type = signature.read_big_endian<uint8_t>();
+ result.creation_time = 0;
+ result.allows_signing = false;
+
/* const auto algorithm = */ signature.read_big_endian<uint8_t>();
/* const auto hash_algorithm = */ signature.read_big_endian<uint8_t>();
@@ -300,14 +313,18 @@ bool subkey_binding_allows_signing(const std::vector<uint8_t> &data)
}
const uint8_t type = subpackets.read_big_endian<uint8_t>() & 0x7f;
- const epee::span<const uint8_t> subpacket = subpackets.read_span(length - 1);
- if (type == subpacket_type_key_flags)
+ deserializer<epee::span<const uint8_t>> subpacket(subpackets.read_span(length - 1));
+ if (type == subpacket_type_creation_time)
+ {
+ result.creation_time = subpacket.read_big_endian<uint32_t>();
+ }
+ else if (type == subpacket_type_key_flags)
{
- return subpacket.size() > 0 && (subpacket[0] & key_flag_sign_data) != 0;
+ result.allows_signing = !subpacket.empty() && (subpacket.read_big_endian<uint8_t>() & key_flag_sign_data) != 0;
}
}
- return false;
+ return true;
}
} // namespace
@@ -362,38 +379,73 @@ public_key_block::public_key_block(const epee::span<const uint8_t> buffer)
}
m_user_id.assign(data->begin(), data->end());
- // Only use subkeys allowed to sign
+ // Only use non-revoked subkeys whose most recent binding signature allows signing.
+ // A subkey's signatures are all the signature packets following it, up to the next packet that is not a
+ // signature, Marker or Trust packet.
bool primary_key_found = false;
const std::vector<uint8_t> *subkey = nullptr;
- packets.for_each([this, &primary_key_found, &subkey](packet_tag::type type, const std::vector<uint8_t> &packet) {
+ bool subkey_revoked = false;
+ bool subkey_binding_found = false;
+ subkey_signature subkey_binding{};
+
+ const auto finish_subkey = [&]() {
+ if (subkey != nullptr && !subkey_revoked && subkey_binding_found && subkey_binding.allows_signing &&
+ is_rsa_public_key(*subkey))
+ {
+ push_back(read_public_key(*subkey));
+ }
+ subkey = nullptr;
+ subkey_revoked = false;
+ subkey_binding_found = false;
+ };
+
+ packets.for_each([&](packet_tag::type type, const std::vector<uint8_t> &packet) {
switch (type)
{
+ case packet_tag::type::signature:
+ if (subkey != nullptr)
+ {
+ subkey_signature signature;
+ if (!read_subkey_signature(packet, signature))
+ {
+ break;
+ }
+ if (signature.type == signature_type_subkey_revocation)
+ {
+ subkey_revoked = true;
+ }
+ else if (
+ signature.type == signature_type_subkey_binding &&
+ (!subkey_binding_found || signature.creation_time >= subkey_binding.creation_time))
+ {
+ subkey_binding = signature;
+ subkey_binding_found = true;
+ }
+ }
+ break;
+ // Marker and Trust packets carry no certificate data and must be ignored without ending the subkey
+ case packet_tag::type::marker:
+ case packet_tag::type::trust:
+ break;
case packet_tag::type::public_key:
+ finish_subkey();
if (primary_key_found)
{
throw std::runtime_error("multiple public keys");
}
push_back(read_public_key(packet));
primary_key_found = true;
- subkey = nullptr;
break;
case packet_tag::type::public_subkey:
+ finish_subkey();
subkey = &packet;
break;
- case packet_tag::type::signature:
- if (subkey != nullptr)
- {
- if (is_rsa_public_key(*subkey) && subkey_binding_allows_signing(packet))
- {
- push_back(read_public_key(*subkey));
- }
- subkey = nullptr;
- }
- break;
default:
+ finish_subkey();
break;
}
});
+ finish_subkey();
if (!primary_key_found)
{
### src/openpgp/serialization.h
@@ -53,6 +53,8 @@ struct packet_tag
{
signature = 2,
public_key = 6,
+ marker = 10,
+ trust = 12,
user_id = 13,
public_subkey = 14,
};Why this scored 61/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.