LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
SignerInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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
55class LIEF_API SignerInfo : public Object {
56 friend class Parser;
57 friend class SignatureParser;
58 friend class Signature;
59
60 public:
61 using encrypted_digest_t = std::vector<uint8_t>;
62
65 using attributes_t = std::vector<std::unique_ptr<Attribute>>;
66
70
72
73 SignerInfo(const SignerInfo& other);
75
78
79 void swap(SignerInfo& other);
80
82 uint32_t version() const {
83 return version_;
84 }
85
93 return serialno_;
94 }
95
97 const std::string& issuer() const {
98 return issuer_;
99 }
100
106 return digest_algorithm_;
107 }
108
112 return digest_enc_algorithm_;
113 }
114
118 return encrypted_digest_;
119 }
120
123 return authenticated_attributes_;
124 }
125
128 return unauthenticated_attributes_;
129 }
130
137
144
151
154 const x509* cert() const {
155 return cert_.get();
156 }
157
161 return cert_.get();
162 }
163
166 return raw_auth_data_;
167 }
168
169 void accept(Visitor& visitor) const override;
170
171 ~SignerInfo() override;
172
173 LIEF_API friend std::ostream& operator<<(std::ostream& os,
174 const SignerInfo& signer_info);
175
176 private:
177 uint32_t version_ = 0;
178 std::string issuer_;
179 std::vector<uint8_t> serialno_;
180
181 ALGORITHMS digest_algorithm_ = ALGORITHMS::UNKNOWN;
182 ALGORITHMS digest_enc_algorithm_ = ALGORITHMS::UNKNOWN;
183
184 encrypted_digest_t encrypted_digest_;
185
186 std::vector<uint8_t> raw_auth_data_;
187
188 attributes_t authenticated_attributes_;
189 attributes_t unauthenticated_attributes_;
190
191 std::unique_ptr<x509> cert_;
192};
193
194}
195}
196
197#endif
Interface over PKCS #7 attribute.
Definition PE/signature/Attribute.hpp:29
TYPE
Definition PE/signature/Attribute.hpp:35
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:52
Definition SignatureParser.hpp:37
Main interface for the PKCS #7 signature scheme.
Definition Signature.hpp:39
friend class Signature
Definition SignerInfo.hpp:58
const Attribute * get_attribute(Attribute::TYPE type) const
Return the authenticated or un-authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
const Attribute * get_auth_attribute(Attribute::TYPE type) const
Return the authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
SignerInfo & operator=(SignerInfo other)
const Attribute * get_unauth_attribute(Attribute::TYPE type) const
Return the un-authenticated attribute matching the given PE::SIG_ATTRIBUTE_TYPES.
it_const_attributes_t unauthenticated_attributes() const
Iterator over LIEF::PE::Attribute for unauthenticated attributes.
Definition SignerInfo.hpp:127
SignerInfo(const SignerInfo &other)
void accept(Visitor &visitor) const override
const x509 * cert() const
x509 certificate used by this signer. If it can't be found, it returns a nullptr
Definition SignerInfo.hpp:154
span< const uint8_t > raw_auth_data() const
Raw blob that is signed by the signer certificate.
Definition SignerInfo.hpp:165
std::vector< std::unique_ptr< Attribute > > attributes_t
Internal container used to store both authenticated and unauthenticated attributes.
Definition SignerInfo.hpp:65
friend class SignatureParser
Definition SignerInfo.hpp:57
void swap(SignerInfo &other)
std::vector< uint8_t > encrypted_digest_t
Definition SignerInfo.hpp:61
span< const uint8_t > serial_number() const
Return the serial number associated with the x509 certificate used by this signer.
Definition SignerInfo.hpp:92
friend std::ostream & operator<<(std::ostream &os, const SignerInfo &signer_info)
SignerInfo & operator=(SignerInfo &&)
const std::string & issuer() const
Return the x509::issuer used by this signer.
Definition SignerInfo.hpp:97
friend class Parser
Definition SignerInfo.hpp:56
~SignerInfo() override
it_const_attributes_t authenticated_attributes() const
Iterator over LIEF::PE::Attribute for authenticated attributes.
Definition SignerInfo.hpp:122
const encrypted_digest_t & encrypted_digest() const
Return the signature created by the signing certificate's private key.
Definition SignerInfo.hpp:117
uint32_t version() const
Should be 1.
Definition SignerInfo.hpp:82
ALGORITHMS digest_algorithm() const
Algorithm (OID) used to hash the file.
Definition SignerInfo.hpp:105
ALGORITHMS encryption_algorithm() const
Return the (public-key) algorithm used to encrypt the signature.
Definition SignerInfo.hpp:111
const_ref_iterator< const attributes_t &, const Attribute * > it_const_attributes_t
Iterator which outputs const Attribute&.
Definition SignerInfo.hpp:68
x509 * cert()
x509 certificate used by this signer. If it can't be found, it returns a nullptr
Definition SignerInfo.hpp:160
SignerInfo(SignerInfo &&)
Interface over a x509 certificate.
Definition x509.hpp:43
Definition Visitor.hpp:212
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:28
@ UNKNOWN
Definition PE/enums.hpp:29
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:286
#define LIEF_API
Definition visibility.h:43