LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
SignerInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_PE_SIGNER_INFO_H
17#define LIEF_PE_SIGNER_INFO_H
18#include <memory>
19
20#include "LIEF/Object.hpp"
21#include "LIEF/visibility.h"
22#include "LIEF/span.hpp"
23
25#include "LIEF/iterators.hpp"
26#include "LIEF/PE/enums.hpp"
28
29namespace LIEF {
30namespace PE {
31
32class Signature;
33class Attribute;
34class Parser;
35class SignatureParser;
36class x509;
37
54class LIEF_API SignerInfo : public Object {
55 friend class Parser;
56 friend class SignatureParser;
57 friend class Signature;
58
59 public:
60 using encrypted_digest_t = std::vector<uint8_t>;
61 using attributes_t = std::vector<std::unique_ptr<Attribute>>;
65 using it_const_attributes_t = const_ref_iterator<const attributes_t&, const Attribute*>;
68
70
71 SignerInfo(const SignerInfo& other);
72 SignerInfo& operator=(SignerInfo other);
73
74 SignerInfo(SignerInfo&&);
75 SignerInfo& operator=(SignerInfo&&);
76
77 void swap(SignerInfo& other);
78 uint32_t version() const {
81 return version_;
82 }
83 span<const uint8_t> serial_number() const {
91 return serialno_;
92 }
93 const std::string& issuer() const {
96 return issuer_;
97 }
98 ALGORITHMS digest_algorithm() const {
104 return digest_algorithm_;
105 }
106 ALGORITHMS encryption_algorithm() const {
110 return digest_enc_algorithm_;
111 }
112 const encrypted_digest_t& encrypted_digest() const {
116 return encrypted_digest_;
117 }
118 it_const_attributes_t authenticated_attributes() const {
121 return authenticated_attributes_;
122 }
123 it_const_attributes_t unauthenticated_attributes() const {
126 return unauthenticated_attributes_;
127 }
128 const Attribute* get_attribute(Attribute::TYPE type) const;
135 const Attribute* get_auth_attribute(Attribute::TYPE type) const;
141 const Attribute* get_unauth_attribute(Attribute::TYPE type) const;
147 const x509* cert() const {
150 return cert_.get();
151 }
152 x509* cert() {
155 return cert_.get();
156 }
157 span<const uint8_t> raw_auth_data() const {
160 return raw_auth_data_;
161 }
162
163 void accept(Visitor& visitor) const override;
164
165 ~SignerInfo() override;
166
167 LIEF_API friend std::ostream& operator<<(std::ostream& os, const SignerInfo& signer_info);
168
169 private:
170 uint32_t version_ = 0;
171 std::string issuer_;
172 std::vector<uint8_t> serialno_;
173
174 ALGORITHMS digest_algorithm_ = ALGORITHMS::UNKNOWN;
175 ALGORITHMS digest_enc_algorithm_ = ALGORITHMS::UNKNOWN;
176
177 encrypted_digest_t encrypted_digest_;
178
179 std::vector<uint8_t> raw_auth_data_;
180
181 attributes_t authenticated_attributes_;
182 attributes_t unauthenticated_attributes_;
183
184 std::unique_ptr<x509> cert_;
185};
186
187}
188}
189
190#endif
Object.hpp
enums.hpp
Attribute.hpp
types.hpp
LIEF::PE::Attribute
Interface over PKCS #7 attribute.
Definition PE/signature/Attribute.hpp:29
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
LIEF::PE::SignatureParser
Definition SignatureParser.hpp:37
LIEF::PE::Signature
Main interface for the PKCS #7 signature scheme.
Definition Signature.hpp:39
LIEF::PE::SignerInfo
Definition SignerInfo.hpp:54
LIEF::PE::SignerInfo::SignerInfo
SignerInfo()
LIEF::PE::SignerInfo::get_attribute
const Attribute * get_attribute(Attribute::TYPE type) const
Return the authenticated or un-authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
LIEF::PE::SignerInfo::get_auth_attribute
const Attribute * get_auth_attribute(Attribute::TYPE type) const
Return the authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
LIEF::PE::SignerInfo::operator=
SignerInfo & operator=(SignerInfo other)
LIEF::PE::SignerInfo::get_unauth_attribute
const Attribute * get_unauth_attribute(Attribute::TYPE type) const
Return the un-authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
LIEF::PE::SignerInfo::unauthenticated_attributes
it_const_attributes_t unauthenticated_attributes() const
Iterator over LIEF::PE::Attribute for unauthenticated attributes.
Definition SignerInfo.hpp:125
LIEF::PE::SignerInfo::SignerInfo
SignerInfo(const SignerInfo &other)
LIEF::PE::SignerInfo::accept
void accept(Visitor &visitor) const override
LIEF::PE::SignerInfo::cert
const x509 * cert() const
x509 certificate used by this signer. If it can't be found, it returns a nullptr
Definition SignerInfo.hpp:149
LIEF::PE::SignerInfo::raw_auth_data
span< const uint8_t > raw_auth_data() const
Raw blob that is signed by the signer certificate.
Definition SignerInfo.hpp:159
LIEF::PE::SignerInfo::swap
void swap(SignerInfo &other)
LIEF::PE::SignerInfo::serial_number
span< const uint8_t > serial_number() const
Return the serial number associated with the x509 certificate used by this signer.
Definition SignerInfo.hpp:90
LIEF::PE::SignerInfo::operator<<
friend std::ostream & operator<<(std::ostream &os, const SignerInfo &signer_info)
LIEF::PE::SignerInfo::operator=
SignerInfo & operator=(SignerInfo &&)
LIEF::PE::SignerInfo::issuer
const std::string & issuer() const
Return the x509::issuer used by this signer.
Definition SignerInfo.hpp:95
LIEF::PE::SignerInfo::~SignerInfo
~SignerInfo() override
LIEF::PE::SignerInfo::authenticated_attributes
it_const_attributes_t authenticated_attributes() const
Iterator over LIEF::PE::Attribute for authenticated attributes.
Definition SignerInfo.hpp:120
LIEF::PE::SignerInfo::encrypted_digest
const encrypted_digest_t & encrypted_digest() const
Return the signature created by the signing certificate's private key.
Definition SignerInfo.hpp:115
LIEF::PE::SignerInfo::version
uint32_t version() const
Should be 1.
Definition SignerInfo.hpp:80
LIEF::PE::SignerInfo::digest_algorithm
ALGORITHMS digest_algorithm() const
Algorithm (OID) used to hash the file.
Definition SignerInfo.hpp:103
LIEF::PE::SignerInfo::encryption_algorithm
ALGORITHMS encryption_algorithm() const
Return the (public-key) algorithm used to encrypt the signature.
Definition SignerInfo.hpp:109
LIEF::PE::SignerInfo::cert
x509 * cert()
x509 certificate used by this signer. If it can't be found, it returns a nullptr
Definition SignerInfo.hpp:154
LIEF::PE::SignerInfo::SignerInfo
SignerInfo(SignerInfo &&)
LIEF::PE::x509
Interface over a x509 certificate.
Definition x509.hpp:43
iterators.hpp
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ALGORITHMS
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:686
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41