Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify SubjectPublicKeyInfo validation to reduce code bloat. #913

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions services/system/AuthSig/src/Spki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ namespace SystemService
{
bool SubjectPublicKeyInfo::validate(const std::vector<unsigned char>& data)
{
Botan::X509::load_key({data.data(), data.size()}); // Throws if decoding fails
Botan::AlgorithmIdentifier algorithm;
std::vector<std::uint8_t> key;

Botan::BER_Decoder(data)
.start_sequence()
.decode(algorithm)
.decode(key, Botan::ASN1_Type::BitString)
.end_cons();
return true;
}

Expand All @@ -29,12 +36,9 @@ namespace SystemService
"Pem->SPKI: Expected label \"PUBLIC KEY\", got label: " + label_got);
}

Botan::BER_Decoder(ber)
.start_sequence()
.decode(algorithm)
.decode(key, Botan::ASN1_Type::BitString)
.end_cons();
return std::vector<unsigned char>(ber.begin(), ber.end());
auto result = std::vector<unsigned char>(ber.begin(), ber.end());
SubjectPublicKeyInfo::validate(result);
return result;
}

std::vector<unsigned char> parseSubjectPublicKeyInfo(std::string_view s)
Expand Down Expand Up @@ -73,4 +77,4 @@ namespace SystemService
return result;
}
} // namespace AuthSig
} // namespace SystemService
} // namespace SystemService
Loading