CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/crypto_asn1/x509.rb
Views: 11704
1
# -*- coding: binary -*-
2
require 'rasn1'
3
require 'rex/proto/crypto_asn1/types'
4
5
module Rex::Proto::CryptoAsn1::X509
6
class X121Address < RASN1::Model
7
numeric_string :X121Address
8
end
9
10
class NetworkAddress < X121Address
11
root_options implicit: 0
12
end
13
14
class TerminalIdentifier < RASN1::Model
15
printable_string :TerminalIdentifier, implicit: 1
16
end
17
18
class AdministrationDomainName < RASN1::Model
19
choice :AdministrationDomainName, class: :application, explicit: 2, content: [
20
numeric_string(:numeric),
21
printable_string(:printable)
22
]
23
end
24
25
class AttributeType < RASN1::Types::ObjectId
26
end
27
28
class AttributeValue < RASN1::Types::Any
29
end
30
31
class AttributeTypeAndValue < RASN1::Model
32
sequence :AttributeTypeAndValue, content: [
33
wrapper(model(:type, AttributeType)),
34
wrapper(model(:value, AttributeValue))
35
]
36
end
37
38
class CountryName < RASN1::Model
39
choice :CountryName, class: :application, explicit: 1, content: [
40
numeric_string(:x121_dcc_code),
41
printable_string(:iso_3166_alpha2_code)
42
]
43
end
44
45
class DirectoryString < RASN1::Model
46
choice :DirectoryString, content: [
47
teletex_string(:teletexString, strict_encoding: false),
48
printable_string(:printableString),
49
universal_string(:universalString),
50
utf8_string(:utf8String),
51
bmp_string(:bmpString)
52
]
53
end
54
55
class EDIPartyName < RASN1::Model
56
sequence :EDIPartyName, content: [
57
wrapper(model(:nameAssigner, DirectoryString), implicit: 0, optional: true),
58
wrapper(model(:partyName, DirectoryString), implicit: 1)
59
]
60
end
61
62
class ExtensionAttribute < RASN1::Model
63
sequence :ExtensionAttribute, content: [
64
integer(:extension_attribute_type, implicit: 0),
65
any(:extension_attribute_value, implicit: 1)
66
]
67
end
68
69
class ExtensionAttributes < RASN1::Model
70
set_of(:ExtensionAttributes, ExtensionAttribute)
71
end
72
73
class NumericUserIdentifier < RASN1::Model
74
numeric_string :NumericUserIdentifier, implicit: 4
75
end
76
77
class OrganizationName < RASN1::Model
78
printable_string :OrganizationName, implicit: 3
79
end
80
81
class OrganizationalUnitName < RASN1::Types::PrintableString
82
end
83
84
class OrganizationalUnitNames < RASN1::Model
85
sequence_of(:OrganizationalUnitNames, OrganizationalUnitName)
86
end
87
88
class PersonalName < RASN1::Model
89
set :PersonalName, content: [
90
printable_string(:surname, implicit: 0),
91
printable_string(:given_name, implicit: 1),
92
printable_string(:initials, implicit: 2),
93
printable_string(:generation_qualifier, implicit: 3)
94
]
95
end
96
97
class PrivateDomainName < RASN1::Model
98
choice :PrivateDomainName, content: [
99
numeric_string(:numeric),
100
printable_string(:printable)
101
]
102
end
103
104
class BuiltinDomainDefinedAttribute < RASN1::Model
105
sequence :BuiltinDomainDefinedAttribute, content: [
106
printable_string(:type),
107
printable_string(:value)
108
]
109
end
110
111
class BuiltInDomainDefinedAttributes < RASN1::Model
112
sequence_of(:BuiltInDomainDefinedAttributes, BuiltinDomainDefinedAttribute)
113
end
114
115
class BuiltInStandardAttributes < RASN1::Model
116
sequence :BuiltInStandardAttributes, content: [
117
wrapper(model(:country_name, CountryName), explicit: 0, class: :application, optional: true),
118
wrapper(model(:administration_domain_name, AdministrationDomainName), explicit: 1, class: :application, optional: true),
119
wrapper(model(:network_address, NetworkAddress), implicit: 0, optional: true),
120
wrapper(model(:terminal_identifier, TerminalIdentifier), implicit: 1, optional: false),
121
wrapper(model(:private_domain_name, PrivateDomainName), implicit: 2, optional: true),
122
wrapper(model(:organization_name, OrganizationName), implicit: 3, optional: true),
123
wrapper(model(:numeric_user_identifier, NumericUserIdentifier), implicit: 4, optional: true),
124
wrapper(model(:personal_name, PersonalName), implicit: 5, optional: true),
125
wrapper(model(:organizational_unit_names, OrganizationalUnitNames), implicit: 6, optional: true)
126
]
127
end
128
129
class RelativeDistinguishedName < RASN1::Model
130
set_of(:RelativeDistinguishedName, AttributeTypeAndValue)
131
end
132
133
class RDNSequence < RASN1::Model
134
sequence_of(:RDNSequence, RelativeDistinguishedName)
135
end
136
137
class Name < RASN1::Model
138
choice :Name, content: [
139
wrapper(model(:RDNSequence, RDNSequence))
140
]
141
end
142
143
class ORAddress < RASN1::Model
144
sequence :ORAddress, implicit: 3, content: [
145
wrapper(model(:built_in_standard_attributes, BuiltInStandardAttributes)),
146
wrapper(model(:built_in_domain_defined_attributes, BuiltInDomainDefinedAttributes), optional: true),
147
wrapper(model(:extension_attributes, ExtensionAttributes), optional: true)
148
]
149
end
150
151
class OtherName < RASN1::Model
152
sequence :OtherName, implicit: 0, content: [
153
objectid(:type_id),
154
any(:value, explicit: 0, constructed: true)
155
]
156
end
157
158
class GeneralName < RASN1::Model
159
choice :GeneralName, content: [
160
wrapper(model(:otherName, OtherName), implicit: 0),
161
ia5_string(:rfc822Name, implicit: 1),
162
ia5_string(:dNSName, implicit: 2),
163
wrapper(model(:x400Address, ORAddress), implicit: 3),
164
wrapper(model(:directoryName, Name), implicit: 4),
165
wrapper(model(:ediPartyName, EDIPartyName), implicit: 5),
166
ia5_string(:uniformResourceIdentifier, implicit: 6),
167
octet_string(:iPAddress, implicit: 7),
168
objectid(:registeredID, implicit: 8)
169
]
170
end
171
172
# https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.7
173
class GeneralNames < RASN1::Model
174
sequence_of(:GeneralNames, GeneralName)
175
end
176
177
# https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.7
178
class SubjectAltName < GeneralNames
179
end
180
181
# https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.5
182
class PolicyQualifierInfo < RASN1::Model
183
sequence :PolicyQualifierInfo, content: [
184
objectid(:policyQualifierId),
185
any(:qualifier)
186
]
187
end
188
189
# https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.5
190
class PolicyInformation < RASN1::Model
191
sequence :PolicyInformation, content: [
192
objectid(:policyIdentifier),
193
sequence_of(:policyQualifiers, PolicyQualifierInfo, optional: true)
194
]
195
end
196
197
# https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.5
198
class CertificatePolicies < RASN1::Model
199
sequence_of(:certificatePolicies, PolicyInformation)
200
end
201
end
202
203