3 #include <openssl/asn1.h>
4 #include <openssl/asn1t.h>
5 #include <openssl/crypto.h>
6 #include <openssl/x509.h>
7 #include <pe-parse/parse.h>
59 using
BIO_ptr = std::unique_ptr<BIO, decltype(&BIO_free)>;
60 using
ASN1_OBJECT_ptr = std::unique_ptr<ASN1_OBJECT, decltype(&ASN1_OBJECT_free)>;
61 using
ASN1_TYPE_ptr = std::unique_ptr<ASN1_TYPE, decltype(&ASN1_TYPE_free)>;
63 using
BN_ptr = std::unique_ptr<BIGNUM, decltype(&BN_free)>;
66 using
SectionList = std::vector<const peparse::bounded_buffer *>;
114 using Checksum = std::tuple<checksum_kind, std::string>;
153 return serial_number_;
159 #ifndef UTHENTICODE_DEFAULT_XN_FLAGS
160 static constexpr
unsigned long const default_xn_flags =
161 XN_FLAG_RFC2253 | ASN1_STRFLGS_UTF8_CONVERT;
163 static constexpr
unsigned long const default_xn_flags = (UTHENTICODE_DEFAULT_XN_FLAGS);
165 static_assert((default_xn_flags & XN_FLAG_COMPAT) == 0,
166 "Logic is incompatible with XN_FLAG_COMPAT");
170 std::string subject_;
172 std::string serial_number_;
185 SignedData(std::vector<std::uint8_t> cert_buf);
195 bool verify_signature()
const;
209 std::vector<Certificate> get_signers()
const;
216 std::vector<Certificate> get_certificates()
const;
222 std::optional<SignedData> get_nested_signed_data()
const;
227 std::vector<std::uint8_t>
const &get_raw_data()
const;
232 std::vector<std::uint8_t> cert_buf_;
248 : revision_(revision), type_(type), cert_buf_(cert_buf) {
255 return cert_buf_.size();
276 std::optional<SignedData> as_signed_data()
const;
281 std::vector<std::uint8_t> cert_buf_;
290 std::vector<WinCert>
read_certs(peparse::parsed_pe *pe);
324 bool verify(peparse::parsed_pe *pe);
Definition: uthenticode.h:131
const std::string & get_serial_number() const
Definition: uthenticode.h:152
const std::string & get_issuer() const
Definition: uthenticode.h:145
const std::string & get_subject() const
Definition: uthenticode.h:138
Definition: uthenticode.h:178
SignedData(const SignedData &)=delete
Definition: uthenticode.h:245
certificate_revision get_revision() const
Definition: uthenticode.h:261
std::size_t get_length() const
Definition: uthenticode.h:254
WinCert(certificate_revision revision, certificate_type type, std::vector< std::uint8_t > cert_buf)
Definition: uthenticode.h:247
certificate_type get_type() const
Definition: uthenticode.h:268
std::unique_ptr< ASN1_TYPE, decltype(&ASN1_TYPE_free)> ASN1_TYPE_ptr
Definition: uthenticode.h:61
std::unique_ptr< char, decltype(&OpenSSL_free)> OpenSSL_ptr
Definition: uthenticode.h:62
void SK_X509_free(stack_st_X509 *ptr)
void OpenSSL_free(void *ptr)
std::unique_ptr< ASN1_OBJECT, decltype(&ASN1_OBJECT_free)> ASN1_OBJECT_ptr
Definition: uthenticode.h:60
std::vector< const peparse::bounded_buffer * > SectionList
Definition: uthenticode.h:66
std::unique_ptr< BIGNUM, decltype(&BN_free)> BN_ptr
Definition: uthenticode.h:63
std::unique_ptr< BIO, decltype(&BIO_free)> BIO_ptr
Definition: uthenticode.h:59
constexpr auto SPC_NESTED_SIGNATURE_OID
Definition: uthenticode.h:69
std::unique_ptr< STACK_OF(X509), decltype(&SK_X509_free)> STACK_OF_X509_ptr
Definition: uthenticode.h:64
constexpr auto SPC_INDIRECT_DATA_OID
Definition: uthenticode.h:68
Definition: uthenticode.h:20
certificate_revision
Definition: uthenticode.h:80
std::optional< std::string > calculate_checksum(peparse::parsed_pe *pe, checksum_kind kind)
Definition: uthenticode.cpp:498
certificate_type
Definition: uthenticode.h:91
@ CERT_TYPE_PKCS_SIGNED_DATA
std::ostream & operator<<(std::ostream &os, checksum_kind kind)
Definition: uthenticode.cpp:130
bool verify(peparse::parsed_pe *pe)
Definition: uthenticode.cpp:647
checksum_kind
Definition: uthenticode.h:101
std::tuple< checksum_kind, std::string > Checksum
Definition: uthenticode.h:114
std::vector< WinCert > read_certs(peparse::parsed_pe *pe)
Definition: uthenticode.cpp:432
std::vector< Checksum > get_checksums(peparse::parsed_pe *pe)
Definition: uthenticode.cpp:479
Definition: uthenticode.h:31
X509_ALGOR * digestAlgorithm
Definition: uthenticode.h:32
ASN1_OCTET_STRING * digest
Definition: uthenticode.h:33
Definition: uthenticode.h:26
ASN1_TYPE * value
Definition: uthenticode.h:28
ASN1_OBJECT * type
Definition: uthenticode.h:27
Definition: uthenticode.h:36
Authenticode_DigestInfo * messageDigest
Definition: uthenticode.h:38
Authenticode_SpcAttributeTypeAndOptionalValue * data
Definition: uthenticode.h:37