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/spec/lib/rex/proto/crypto_asn/x509_spec.rb
Views: 11789
1
# -*- coding:binary -*-
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::CryptoAsn1::X509::OtherName do
5
let(:encoded) do
6
"\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20" +
7
"\x0c\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +
8
"\x43\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"
9
end
10
11
describe '.parse' do
12
let(:decoded) { described_class.parse(encoded) }
13
14
it 'decodes otherName correctly' do
15
expect(decoded[:type_id].value?).to be_truthy
16
expect(decoded[:type_id]).to be_a RASN1::Types::ObjectId
17
expect(decoded[:value].value?).to be_truthy
18
expect(decoded[:value]).to be_a RASN1::Types::Any
19
end
20
end
21
22
describe '#to_der' do
23
it 'encodes correctly' do
24
instance = described_class.new(
25
type_id: '1.3.6.1.4.1.311.20.2.3',
26
value: "\xA0 \f\[email protected]".b
27
)
28
expect(instance.to_der).to eq encoded
29
end
30
end
31
end
32
33
RSpec.describe Rex::Proto::CryptoAsn1::X509::GeneralName do
34
context 'when otherName is chosen' do
35
let(:encoded) do
36
"\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20\x0c" +
37
"\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45\x43" +
38
"\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"
39
end
40
41
describe '.parse' do
42
let(:decoded) { described_class.parse(encoded) }
43
44
it 'decodes otherName correctly' do
45
expect(decoded[:otherName].value?).to be_truthy
46
expect(decoded[:otherName]).to be_a Rex::Proto::CryptoAsn1::X509::OtherName
47
end
48
end
49
50
describe '#to_der' do
51
it 'encodes correctly' do
52
instance = described_class.new(
53
otherName: {
54
type_id: '1.3.6.1.4.1.311.20.2.3',
55
value: "\xA0 \f\[email protected]".b
56
}
57
).tap { |gn| gn.chosen = 0 }
58
expect(instance.to_der).to eq encoded
59
end
60
end
61
end
62
63
context 'when rfc822Name is chosen' do
64
let(:encoded) do
65
"\x81\x14\x73\x70\x65\x6e\x63\x65\x72\x40\x6d\x73\x66\x6c\x61\x62\x2e" +
66
"\x6c\x6f\x63\x61\x6c".b
67
end
68
69
describe '.parse' do
70
let(:decoded) { described_class.parse(encoded) }
71
72
it 'decodes rfc822Name correctly' do
73
expect(decoded[:rfc822Name].value?).to be_truthy
74
expect(decoded[:rfc822Name]).to be_a RASN1::Types::IA5String
75
expect(decoded[:rfc822Name].value).to eq '[email protected]'
76
end
77
end
78
79
describe '#to_der' do
80
it 'encodes correctly' do
81
instance = described_class.new(
82
rfc822Name: '[email protected]'
83
).tap { |gn| gn.chosen = 1 }
84
expect(instance.to_der).to eq encoded
85
end
86
end
87
end
88
89
context 'when dNSName is chosen' do
90
let(:encoded) do
91
"\x82\x1d\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +
92
"\x43\x2e\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c".b
93
end
94
95
describe '.parse' do
96
let(:decoded) { described_class.parse(encoded) }
97
98
it 'decodes dNSName correctly' do
99
expect(decoded[:dNSName].value?).to be_truthy
100
expect(decoded[:dNSName]).to be_a RASN1::Types::IA5String
101
expect(decoded[:dNSName].value).to eq 'DESKTOP-MWJ9MOEC.msflab.local'
102
end
103
end
104
105
describe '#to_der' do
106
it 'encodes correctly' do
107
instance = described_class.new(
108
dNSName: 'DESKTOP-MWJ9MOEC.msflab.local'
109
).tap { |gn| gn.chosen = 2 }
110
expect(instance.to_der).to eq encoded
111
end
112
end
113
end
114
end
115
116
RSpec.describe Rex::Proto::CryptoAsn1::X509::SubjectAltName do
117
let(:encoded) do
118
"\x30\x30\xa0\x2e\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x14\x02\x03\xa0\x20" +
119
"\x0c\x1e\x44\x45\x53\x4b\x54\x4f\x50\x2d\x4d\x57\x4a\x39\x4d\x4f\x45" +
120
"\x43\x24\x40\x6d\x73\x66\x6c\x61\x62\x2e\x6c\x6f\x63\x61\x6c"
121
end
122
123
describe '.parse' do
124
let(:decoded) { described_class.parse(encoded) }
125
126
it 'decodes GeneralNames correctly' do
127
expect(decoded[:GeneralNames]).to be_a RASN1::Types::SequenceOf
128
expect(decoded[:GeneralNames].length).to eq 1
129
expect(decoded[:GeneralNames].value.first).to be_a Rex::Proto::CryptoAsn1::X509::GeneralName
130
end
131
end
132
133
describe '#to_der' do
134
it 'encodes correctly' do
135
instance = described_class.new(GeneralNames: [{
136
otherName: {
137
type_id: '1.3.6.1.4.1.311.20.2.3',
138
value: "\xA0 \f\[email protected]".b
139
}
140
}]).tap { |san| san[:GeneralNames][0].chosen = 0 }
141
expect(instance.to_der).to eq encoded
142
end
143
end
144
end
145
146