-
-
Notifications
You must be signed in to change notification settings - Fork 590
/
ContentInfo.hpp
148 lines (124 loc) · 3.75 KB
/
ContentInfo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* Copyright 2017 - 2024 R. Thomas
* Copyright 2017 - 2024 Quarkslab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LIEF_PE_CONTENT_INFO_H
#define LIEF_PE_CONTENT_INFO_H
#include <vector>
#include <ostream>
#include <memory>
#include "LIEF/Object.hpp"
#include "LIEF/visibility.h"
#include "LIEF/PE/signature/types.hpp"
#include "LIEF/PE/enums.hpp"
namespace LIEF {
namespace PE {
class Parser;
class SignatureParser;
/**
* ContentInfo as described in the RFC2315 (https://tools.ietf.org/html/rfc2315#section-7)
*
* ```text
* ContentInfo ::= SEQUENCE {
* contentType ContentType,
* content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
* }
*
* ContentType ::= OBJECT IDENTIFIER
* ```
*
* In the case of PE signature, ContentType **must** be set to SPC_INDIRECT_DATA_OBJID
* OID: ``1.3.6.1.4.1.311.2.1.4`` and content is defined by the structure: ``SpcIndirectDataContent``
*
* ```text
* SpcIndirectDataContent ::= SEQUENCE {
* data SpcAttributeTypeAndOptionalValue,
* messageDigest DigestInfo
* }
*
* SpcAttributeTypeAndOptionalValue ::= SEQUENCE {
* type ObjectID,
* value [0] EXPLICIT ANY OPTIONAL
* }
* ```
*
* For PE signature, ``SpcAttributeTypeAndOptionalValue.type``
* is set to ``SPC_PE_IMAGE_DATAOBJ`` (OID: ``1.3.6.1.4.1.311.2.1.15``) and the value is defined by
* ``SpcPeImageData``
*
* ```text
* DigestInfo ::= SEQUENCE {
* digestAlgorithm AlgorithmIdentifier,
* digest OCTETSTRING
* }
*
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm ObjectID,
* parameters [0] EXPLICIT ANY OPTIONAL
* }
* ```
*/
class LIEF_API ContentInfo : public Object {
friend class Parser;
friend class SignatureParser;
public:
class Content : public Object {
public:
Content(oid_t oid) :
type_(std::move(oid))
{}
const oid_t& content_type() const {
return type_;
}
virtual std::unique_ptr<Content> clone() const = 0;
virtual void print(std::ostream& os) const = 0;
LIEF_API friend std::ostream& operator<<(std::ostream& os, const Content& content) {
content.print(os);
return os;
}
~Content() override = default;
private:
oid_t type_;
};
ContentInfo();
ContentInfo(const ContentInfo& other);
ContentInfo(ContentInfo&& other) noexcept = default;
ContentInfo& operator=(ContentInfo other);
void swap(ContentInfo& other) noexcept;
//! Return the OID that describes the content wrapped by this object.
//! It should match SPC_INDIRECT_DATA_OBJID (1.3.6.1.4.1.311.2.1.4)
oid_t content_type() const {
return value_->content_type();
}
Content& value() {
return *value_;
}
const Content& value() const {
return *value_;
}
/// Return the digest (authentihash) if the underlying content type is `SPC_INDIRECT_DATA_OBJID`
/// Otherwise, return an empty vector
std::vector<uint8_t> digest() const;
/// Return the OID algorithm if the underlying content type is `SPC_INDIRECT_DATA_OBJID`
/// Otherwise, return an empty oid
ALGORITHMS digest_algorithm() const;
void accept(Visitor& visitor) const override;
~ContentInfo() override = default;
LIEF_API friend std::ostream& operator<<(std::ostream& os, const ContentInfo& content_info);
private:
std::unique_ptr<Content> value_;
};
}
}
#endif