tttls1.3 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/tttls1.3/version.rb +1 -1
- data/lib/tttls1.3.rb +1 -0
- data/tttls1.3.gemspec +5 -2
- metadata +3 -113
- data/.github/workflows/ci.yml +0 -39
- data/.gitignore +0 -17
- data/spec/aead_spec.rb +0 -95
- data/spec/alert_spec.rb +0 -54
- data/spec/alpn_spec.rb +0 -55
- data/spec/application_data_spec.rb +0 -26
- data/spec/certificate_spec.rb +0 -82
- data/spec/certificate_verify_spec.rb +0 -51
- data/spec/change_cipher_spec_spec.rb +0 -26
- data/spec/cipher_suites_spec.rb +0 -39
- data/spec/client_hello_spec.rb +0 -105
- data/spec/client_spec.rb +0 -274
- data/spec/compress_certificate_spec.rb +0 -54
- data/spec/cookie_spec.rb +0 -98
- data/spec/early_data_indication_spec.rb +0 -64
- data/spec/ech_outer_extensions_spec.rb +0 -42
- data/spec/ech_spec.rb +0 -122
- data/spec/encrypted_extensions_spec.rb +0 -94
- data/spec/end_of_early_data_spec.rb +0 -28
- data/spec/endpoint_spec.rb +0 -167
- data/spec/error_spec.rb +0 -18
- data/spec/extensions_spec.rb +0 -250
- data/spec/finished_spec.rb +0 -55
- data/spec/fixtures/rsa_ca.crt +0 -18
- data/spec/fixtures/rsa_ca.key +0 -27
- data/spec/fixtures/rsa_rsa.crt +0 -18
- data/spec/fixtures/rsa_rsa.key +0 -27
- data/spec/fixtures/rsa_rsa_ocsp.crt +0 -18
- data/spec/fixtures/rsa_rsa_ocsp.key +0 -27
- data/spec/fixtures/rsa_rsassaPss.crt +0 -20
- data/spec/fixtures/rsa_rsassaPss.key +0 -27
- data/spec/fixtures/rsa_secp256r1.crt +0 -14
- data/spec/fixtures/rsa_secp256r1.key +0 -5
- data/spec/fixtures/rsa_secp384r1.crt +0 -14
- data/spec/fixtures/rsa_secp384r1.key +0 -6
- data/spec/fixtures/rsa_secp521r1.crt +0 -15
- data/spec/fixtures/rsa_secp521r1.key +0 -7
- data/spec/key_schedule_spec.rb +0 -221
- data/spec/key_share_spec.rb +0 -199
- data/spec/new_session_ticket_spec.rb +0 -80
- data/spec/pre_shared_key_spec.rb +0 -167
- data/spec/psk_key_exchange_modes_spec.rb +0 -45
- data/spec/record_size_limit_spec.rb +0 -61
- data/spec/record_spec.rb +0 -105
- data/spec/server_hello_spec.rb +0 -200
- data/spec/server_name_spec.rb +0 -110
- data/spec/server_spec.rb +0 -232
- data/spec/signature_algorithms_cert_spec.rb +0 -77
- data/spec/signature_algorithms_spec.rb +0 -104
- data/spec/spec_helper.rb +0 -990
- data/spec/status_request_spec.rb +0 -140
- data/spec/supported_groups_spec.rb +0 -79
- data/spec/supported_versions_spec.rb +0 -136
- data/spec/transcript_spec.rb +0 -83
- data/spec/unknown_extension_spec.rb +0 -90
- data/spec/utils_spec.rb +0 -235
data/spec/server_hello_spec.rb
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
# encoding: ascii-8bit
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative 'spec_helper'
|
|
5
|
-
using Refinements
|
|
6
|
-
|
|
7
|
-
RSpec.describe ServerHello do
|
|
8
|
-
context 'default server_hello' do
|
|
9
|
-
let(:random) do
|
|
10
|
-
OpenSSL::Random.random_bytes(32)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
let(:legacy_session_id_echo) do
|
|
14
|
-
Array.new(32, 0).map(&:chr).join
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:cipher_suite) do
|
|
18
|
-
CipherSuite::TLS_AES_256_GCM_SHA384
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:message) do
|
|
22
|
-
ServerHello.new(random:,
|
|
23
|
-
legacy_session_id_echo:,
|
|
24
|
-
cipher_suite:)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'should be generated' do
|
|
28
|
-
expect(message.msg_type).to eq HandshakeType::SERVER_HELLO
|
|
29
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
30
|
-
expect(message.random).to eq random
|
|
31
|
-
expect(message.legacy_session_id_echo).to eq legacy_session_id_echo
|
|
32
|
-
expect(message.cipher_suite).to eq CipherSuite::TLS_AES_256_GCM_SHA384
|
|
33
|
-
expect(message.legacy_compression_method).to eq "\x00"
|
|
34
|
-
expect(message.extensions).to be_empty
|
|
35
|
-
expect(message.hrr?).to be false
|
|
36
|
-
expect(message.appearable_extensions?).to be true
|
|
37
|
-
expect(message.negotiated_tls_1_3?).to be false
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'should be serialized' do
|
|
41
|
-
expect(message.serialize).to eq HandshakeType::SERVER_HELLO \
|
|
42
|
-
+ 72.to_uint24 \
|
|
43
|
-
+ ProtocolVersion::TLS_1_2 \
|
|
44
|
-
+ random \
|
|
45
|
-
+ legacy_session_id_echo.length.to_uint8 \
|
|
46
|
-
+ legacy_session_id_echo \
|
|
47
|
-
+ cipher_suite \
|
|
48
|
-
+ "\x00" \
|
|
49
|
-
+ Extensions.new.serialize
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'valid server_hello binary' do
|
|
54
|
-
let(:message) do
|
|
55
|
-
ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'should generate valid object' do
|
|
59
|
-
expect(message.msg_type).to eq HandshakeType::SERVER_HELLO
|
|
60
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
61
|
-
expect(message.cipher_suite).to eq CipherSuite::TLS_AES_128_GCM_SHA256
|
|
62
|
-
expect(message.legacy_compression_method).to eq "\x00"
|
|
63
|
-
expect(message.hrr?).to be false
|
|
64
|
-
expect(message.appearable_extensions?).to be true
|
|
65
|
-
expect(message.negotiated_tls_1_3?).to be true
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'should generate valid serializable object' do
|
|
69
|
-
expect(message.serialize).to eq TESTBINARY_SERVER_HELLO
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context 'hello_retry_request binary' do
|
|
74
|
-
let(:message) do
|
|
75
|
-
ServerHello.deserialize(TESTBINARY_HRR_HELLO_RETRY_REQUEST)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'should generate valid object' do
|
|
79
|
-
expect(message.msg_type).to eq HandshakeType::SERVER_HELLO
|
|
80
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
81
|
-
expect(message.cipher_suite).to eq CipherSuite::TLS_AES_128_GCM_SHA256
|
|
82
|
-
expect(message.legacy_compression_method).to eq "\x00"
|
|
83
|
-
expect(message.hrr?).to be true
|
|
84
|
-
expect(message.appearable_extensions?).to be true
|
|
85
|
-
expect(message.negotiated_tls_1_3?).to be true
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'should generate valid serializable object' do
|
|
89
|
-
expect(message.serialize).to eq TESTBINARY_HRR_HELLO_RETRY_REQUEST
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
context 'valid server_hello binary, 0-RTT,' do
|
|
94
|
-
let(:message) do
|
|
95
|
-
ServerHello.deserialize(TESTBINARY_0_RTT_SERVER_HELLO)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'should generate valid object' do
|
|
99
|
-
expect(message.msg_type).to eq HandshakeType::SERVER_HELLO
|
|
100
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
101
|
-
expect(message.cipher_suite).to eq CipherSuite::TLS_AES_128_GCM_SHA256
|
|
102
|
-
expect(message.legacy_compression_method).to eq "\x00"
|
|
103
|
-
expect(message.hrr?).to be false
|
|
104
|
-
expect(message.appearable_extensions?).to be true
|
|
105
|
-
expect(message.negotiated_tls_1_3?).to be true
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it 'should generate valid serializable object' do
|
|
109
|
-
expect(message.serialize).to eq TESTBINARY_0_RTT_SERVER_HELLO
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context 'default hello_retry_request' do
|
|
114
|
-
let(:legacy_session_id_echo) do
|
|
115
|
-
Array.new(32, 0).map(&:chr).join
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
let(:cipher_suite) do
|
|
119
|
-
CipherSuite::TLS_AES_256_GCM_SHA384
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
let(:message) do
|
|
123
|
-
ServerHello.new(random: Message::HRR_RANDOM,
|
|
124
|
-
legacy_session_id_echo:,
|
|
125
|
-
cipher_suite:)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'should be generated' do
|
|
129
|
-
expect(message.msg_type).to eq HandshakeType::SERVER_HELLO
|
|
130
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
131
|
-
expect(message.random).to eq Message::HRR_RANDOM
|
|
132
|
-
expect(message.legacy_session_id_echo).to eq legacy_session_id_echo
|
|
133
|
-
expect(message.cipher_suite).to eq CipherSuite::TLS_AES_256_GCM_SHA384
|
|
134
|
-
expect(message.legacy_compression_method).to eq "\x00"
|
|
135
|
-
expect(message.extensions).to be_empty
|
|
136
|
-
expect(message.hrr?).to eq true
|
|
137
|
-
expect(message.appearable_extensions?).to be true
|
|
138
|
-
expect(message.negotiated_tls_1_3?).to be false
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it 'should be serialized' do
|
|
142
|
-
expect(message.serialize).to eq HandshakeType::SERVER_HELLO \
|
|
143
|
-
+ 72.to_uint24 \
|
|
144
|
-
+ ProtocolVersion::TLS_1_2 \
|
|
145
|
-
+ Message::HRR_RANDOM \
|
|
146
|
-
+ legacy_session_id_echo.length.to_uint8 \
|
|
147
|
-
+ legacy_session_id_echo \
|
|
148
|
-
+ cipher_suite \
|
|
149
|
-
+ "\x00" \
|
|
150
|
-
+ Extensions.new.serialize
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
context 'server_hello with random[-8..] == downgrade protection ' \
|
|
155
|
-
'value(TLS 1.2)' do
|
|
156
|
-
let(:message) do
|
|
157
|
-
sh = ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
158
|
-
random = OpenSSL::Random.random_bytes(24) + \
|
|
159
|
-
ServerHello.const_get(:DOWNGRADE_PROTECTION_TLS_1_2)
|
|
160
|
-
sh.instance_variable_set(:@random, random)
|
|
161
|
-
sh
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it 'should check downgrade protection value' do
|
|
165
|
-
expect(message.negotiated_tls_1_3?).to be true
|
|
166
|
-
expect(message.downgraded?).to be true
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
context 'server_hello with random[-8..] == downgrade protection ' \
|
|
171
|
-
'value(TLS 1.2)' do
|
|
172
|
-
let(:message) do
|
|
173
|
-
sh = ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
174
|
-
random = OpenSSL::Random.random_bytes(24) + \
|
|
175
|
-
ServerHello.const_get(:DOWNGRADE_PROTECTION_TLS_1_1)
|
|
176
|
-
sh.instance_variable_set(:@random, random)
|
|
177
|
-
sh
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it 'should check downgrade protection value' do
|
|
181
|
-
expect(message.negotiated_tls_1_3?).to be true
|
|
182
|
-
expect(message.downgraded?).to be true
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
context 'server_hello with supported_versions not including "\x03\x04"' do
|
|
187
|
-
let(:message) do
|
|
188
|
-
sh = ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
189
|
-
extensions = sh.instance_variable_get(:@extensions)
|
|
190
|
-
extensions.delete(ExtensionType::SUPPORTED_VERSIONS)
|
|
191
|
-
sh.instance_variable_set(:@extensions, extensions)
|
|
192
|
-
sh
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
it 'should check downgrade protection value' do
|
|
196
|
-
expect(message.negotiated_tls_1_3?).to be false
|
|
197
|
-
expect(message.downgraded?).to be false
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
end
|
data/spec/server_name_spec.rb
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# encoding: ascii-8bit
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative 'spec_helper'
|
|
5
|
-
using Refinements
|
|
6
|
-
|
|
7
|
-
RSpec.describe ServerName do
|
|
8
|
-
context 'valid server_name, example.com,' do
|
|
9
|
-
let(:extension) do
|
|
10
|
-
ServerName.new('example.com')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'should be generated' do
|
|
14
|
-
expect(extension.extension_type).to eq ExtensionType::SERVER_NAME
|
|
15
|
-
expect(extension.server_name).to eq 'example.com'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'should be serialized' do
|
|
19
|
-
expect(extension.serialize).to eq ExtensionType::SERVER_NAME \
|
|
20
|
-
+ 16.to_uint16 \
|
|
21
|
-
+ 14.to_uint16 \
|
|
22
|
-
+ NameType::HOST_NAME \
|
|
23
|
-
+ 11.to_uint16 \
|
|
24
|
-
+ 'example.com'
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'valid server_name, empty HostName,' do
|
|
29
|
-
let(:extension) do
|
|
30
|
-
ServerName.new('')
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'should be generated' do
|
|
34
|
-
expect(extension.extension_type).to eq ExtensionType::SERVER_NAME
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'should be serialized' do
|
|
38
|
-
expect(extension.serialize).to eq ExtensionType::SERVER_NAME \
|
|
39
|
-
+ 0.to_uint16
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context 'invalid server_name, too long HostName,' do
|
|
44
|
-
let(:extension) do
|
|
45
|
-
ServerName.new('a' * (2**16 - 4))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'should not be generated' do
|
|
49
|
-
expect { extension }.to raise_error(ErrorAlerts)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'valid server_name binary' do
|
|
54
|
-
let(:extension) do
|
|
55
|
-
ServerName.deserialize(TESTBINARY_SERVER_NAME)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'should generate valid object' do
|
|
59
|
-
expect(extension.extension_type).to eq ExtensionType::SERVER_NAME
|
|
60
|
-
expect(extension.server_name).to eq 'github.com'
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'should generate serializable object' do
|
|
64
|
-
expect(extension.serialize)
|
|
65
|
-
.to eq ExtensionType::SERVER_NAME \
|
|
66
|
-
+ TESTBINARY_SERVER_NAME.prefix_uint16_length
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
context 'invalid server_name binary, malformed binary,' do
|
|
71
|
-
let(:extension) do
|
|
72
|
-
ServerName.deserialize(TESTBINARY_SERVER_NAME[0...-1])
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'should return nil' do
|
|
76
|
-
expect(extension).to be nil
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'invalid server_name binary, unknown NameType,' do
|
|
81
|
-
let(:testbinary) do
|
|
82
|
-
name_type = "\xff"
|
|
83
|
-
binary = name_type + 'example.com'.prefix_uint16_length
|
|
84
|
-
binary.prefix_uint16_length.prefix_uint16_length
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
let(:extension) do
|
|
88
|
-
ServerName.deserialize(testbinary)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'should return nil' do
|
|
92
|
-
expect(extension).to be nil
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context 'invalid server_name binary, empty HostName,' do
|
|
97
|
-
let(:testbinary) do
|
|
98
|
-
binary = NameType::HOST_NAME + ''.prefix_uint16_length
|
|
99
|
-
binary.prefix_uint16_length.prefix_uint16_length
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
let(:extension) do
|
|
103
|
-
ServerName.deserialize(testbinary)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'should return nil' do
|
|
107
|
-
expect(extension).to be nil
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
data/spec/server_spec.rb
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
# encoding: ascii-8bit
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative 'spec_helper'
|
|
5
|
-
using Refinements
|
|
6
|
-
|
|
7
|
-
RSpec.describe Server do
|
|
8
|
-
context 'server' do
|
|
9
|
-
let(:message) do
|
|
10
|
-
msg_len = TESTBINARY_CLIENT_HELLO.length
|
|
11
|
-
mock_socket = SimpleStream.new
|
|
12
|
-
mock_socket.write(ContentType::HANDSHAKE \
|
|
13
|
-
+ ProtocolVersion::TLS_1_2 \
|
|
14
|
-
+ msg_len.to_uint16 \
|
|
15
|
-
+ TESTBINARY_CLIENT_HELLO)
|
|
16
|
-
server = Server.new(mock_socket)
|
|
17
|
-
server.send(:recv_client_hello, true).first
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'should receive ClientHello' do
|
|
21
|
-
expect(message.msg_type).to eq HandshakeType::CLIENT_HELLO
|
|
22
|
-
expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
|
|
23
|
-
expect(message.legacy_compression_methods).to eq ["\x00"]
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'server' do
|
|
28
|
-
let(:crt) do
|
|
29
|
-
OpenSSL::X509::Certificate.new(
|
|
30
|
-
File.read(__dir__ + '/fixtures/rsa_rsa.crt')
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
let(:ch) do
|
|
35
|
-
ch = ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
|
|
36
|
-
|
|
37
|
-
key_share = KeyShare.new(
|
|
38
|
-
msg_type: HandshakeType::CLIENT_HELLO,
|
|
39
|
-
key_share_entry: [
|
|
40
|
-
KeyShareEntry.new(
|
|
41
|
-
group: NamedGroup::SECP256R1,
|
|
42
|
-
key_exchange: "\x04" + OpenSSL::Random.random_bytes(64)
|
|
43
|
-
)
|
|
44
|
-
]
|
|
45
|
-
)
|
|
46
|
-
ch.extensions[ExtensionType::KEY_SHARE] = key_share
|
|
47
|
-
ch
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
let(:server) do
|
|
51
|
-
Server.new(nil)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'should select parameters' do
|
|
55
|
-
expect(server.send(:select_cipher_suite, ch))
|
|
56
|
-
.to eq CipherSuite::TLS_AES_128_GCM_SHA256
|
|
57
|
-
expect(server.send(:select_named_group, ch)).to eq NamedGroup::SECP256R1
|
|
58
|
-
expect(server.send(:select_signature_scheme, ch, crt))
|
|
59
|
-
.to eq SignatureScheme::RSA_PSS_RSAE_SHA256
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'server' do
|
|
64
|
-
let(:ch) do
|
|
65
|
-
ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
let(:server) do
|
|
69
|
-
Server.new(nil)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it 'should generate EncryptedExtensions' do
|
|
73
|
-
ee = server.send(:gen_encrypted_extensions, ch)
|
|
74
|
-
expect(ee).to be_a_kind_of(EncryptedExtensions)
|
|
75
|
-
expect(ee.extensions).to include(ExtensionType::SERVER_NAME)
|
|
76
|
-
expect(ee.extensions[ExtensionType::SERVER_NAME].server_name).to eq ''
|
|
77
|
-
expect(ee.extensions).to include(ExtensionType::SUPPORTED_GROUPS)
|
|
78
|
-
expect(ee.extensions[ExtensionType::SUPPORTED_GROUPS].named_group_list)
|
|
79
|
-
.to eq [NamedGroup::X25519,
|
|
80
|
-
NamedGroup::SECP256R1,
|
|
81
|
-
NamedGroup::SECP384R1,
|
|
82
|
-
NamedGroup::SECP521R1]
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context 'server' do
|
|
87
|
-
let(:crt) do
|
|
88
|
-
OpenSSL::X509::Certificate.new(
|
|
89
|
-
File.read(__dir__ + '/fixtures/rsa_rsa.crt')
|
|
90
|
-
)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
let(:ch) do
|
|
94
|
-
ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
let(:server) do
|
|
98
|
-
Server.new(nil)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it 'should generate Certificate' do
|
|
102
|
-
ct = server.send(:gen_certificate, crt, ch)
|
|
103
|
-
expect(ct).to be_a_kind_of(Certificate)
|
|
104
|
-
|
|
105
|
-
certificate_entry = ct.certificate_list.first
|
|
106
|
-
expect(certificate_entry.cert_data.subject.to_s).to eq '/CN=localhost'
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context 'server' do
|
|
111
|
-
let(:key) do
|
|
112
|
-
n = OpenSSL::BN.new(TESTBINARY_PKEY_MODULUS, 2)
|
|
113
|
-
e = OpenSSL::BN.new(TESTBINARY_PKEY_PUBLIC_EXPONENT, 2)
|
|
114
|
-
d = OpenSSL::BN.new(TESTBINARY_PKEY_PRIVATE_EXPONENT, 2)
|
|
115
|
-
p = OpenSSL::BN.new(TESTBINARY_PKEY_PRIME1, 2)
|
|
116
|
-
q = OpenSSL::BN.new(TESTBINARY_PKEY_PRIME2, 2)
|
|
117
|
-
dmp1 = d % (p - 1.to_bn)
|
|
118
|
-
dmq1 = d % (q - 1.to_bn)
|
|
119
|
-
iqmp = q**-1.to_bn % p
|
|
120
|
-
asn1 = OpenSSL::ASN1::Sequence(
|
|
121
|
-
[
|
|
122
|
-
OpenSSL::ASN1::Integer(0),
|
|
123
|
-
OpenSSL::ASN1::Integer(n),
|
|
124
|
-
OpenSSL::ASN1::Integer(e),
|
|
125
|
-
OpenSSL::ASN1::Integer(d),
|
|
126
|
-
OpenSSL::ASN1::Integer(p),
|
|
127
|
-
OpenSSL::ASN1::Integer(q),
|
|
128
|
-
OpenSSL::ASN1::Integer(dmp1),
|
|
129
|
-
OpenSSL::ASN1::Integer(dmq1),
|
|
130
|
-
OpenSSL::ASN1::Integer(iqmp)
|
|
131
|
-
]
|
|
132
|
-
)
|
|
133
|
-
OpenSSL::PKey::RSA.new(asn1)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
let(:ct) do
|
|
137
|
-
Certificate.deserialize(TESTBINARY_CERTIFICATE)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
let(:transcript) do
|
|
141
|
-
ch = ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
|
|
142
|
-
sh = ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
143
|
-
ee = EncryptedExtensions.deserialize(TESTBINARY_ENCRYPTED_EXTENSIONS)
|
|
144
|
-
transcript = Transcript.new
|
|
145
|
-
transcript.merge!(
|
|
146
|
-
CH => [ch, TESTBINARY_CLIENT_HELLO],
|
|
147
|
-
SH => [sh, TESTBINARY_SERVER_HELLO],
|
|
148
|
-
EE => [ee, TESTBINARY_ENCRYPTED_EXTENSIONS],
|
|
149
|
-
CT => [ct, TESTBINARY_CERTIFICATE]
|
|
150
|
-
)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
let(:cipher_suite) do
|
|
154
|
-
CipherSuite::TLS_AES_128_GCM_SHA256
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
let(:signature_scheme) do
|
|
158
|
-
SignatureScheme::RSA_PSS_RSAE_SHA256
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
let(:server) do
|
|
162
|
-
Server.new(nil)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it 'should generate CertificateVerify' do
|
|
166
|
-
digest = CipherSuite.digest(cipher_suite)
|
|
167
|
-
hash = transcript.hash(digest, CT)
|
|
168
|
-
cv = server.send(:gen_certificate_verify, key, signature_scheme, hash)
|
|
169
|
-
expect(cv).to be_a_kind_of(CertificateVerify)
|
|
170
|
-
|
|
171
|
-
# used RSASSA-PSS signature_scheme, salt is a random sequence.
|
|
172
|
-
# CertificateVerify.signature is random.
|
|
173
|
-
public_key = ct.certificate_list.first.cert_data.public_key
|
|
174
|
-
signature_scheme = cv.signature_scheme
|
|
175
|
-
signature = cv.signature
|
|
176
|
-
digest = CipherSuite.digest(cipher_suite)
|
|
177
|
-
expect(Endpoint.verified_certificate_verify?(
|
|
178
|
-
public_key:,
|
|
179
|
-
signature_scheme:,
|
|
180
|
-
signature:,
|
|
181
|
-
context: 'TLS 1.3, server CertificateVerify',
|
|
182
|
-
hash: transcript.hash(digest, CT)
|
|
183
|
-
)).to be true
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
context 'server' do
|
|
188
|
-
let(:cipher_suite) do
|
|
189
|
-
CipherSuite::TLS_AES_128_GCM_SHA256
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
let(:transcript) do
|
|
193
|
-
ch = ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
|
|
194
|
-
sh = ServerHello.deserialize(TESTBINARY_SERVER_HELLO)
|
|
195
|
-
ee = EncryptedExtensions.deserialize(TESTBINARY_ENCRYPTED_EXTENSIONS)
|
|
196
|
-
ct = Certificate.deserialize(TESTBINARY_CERTIFICATE)
|
|
197
|
-
cv = CertificateVerify.deserialize(TESTBINARY_CERTIFICATE_VERIFY)
|
|
198
|
-
transcript = Transcript.new
|
|
199
|
-
transcript.merge!(
|
|
200
|
-
CH => [ch, TESTBINARY_CLIENT_HELLO],
|
|
201
|
-
SH => [sh, TESTBINARY_SERVER_HELLO],
|
|
202
|
-
EE => [ee, TESTBINARY_ENCRYPTED_EXTENSIONS],
|
|
203
|
-
CT => [ct, TESTBINARY_CERTIFICATE],
|
|
204
|
-
CV => [cv, TESTBINARY_CERTIFICATE_VERIFY]
|
|
205
|
-
)
|
|
206
|
-
transcript
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
let(:key_schedule) do
|
|
210
|
-
KeySchedule.new(shared_secret: TESTBINARY_SHARED_SECRET,
|
|
211
|
-
cipher_suite:,
|
|
212
|
-
transcript:)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
let(:signature) do
|
|
216
|
-
digest = CipherSuite.digest(cipher_suite)
|
|
217
|
-
Endpoint.sign_finished(
|
|
218
|
-
digest:,
|
|
219
|
-
finished_key: key_schedule.server_finished_key,
|
|
220
|
-
hash: transcript.hash(digest, CV)
|
|
221
|
-
)
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
let(:sf) do
|
|
225
|
-
Finished.deserialize(TESTBINARY_SERVER_FINISHED)
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
it 'should generate Finished' do
|
|
229
|
-
expect(signature).to eq sf.verify_data
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
end
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# encoding: ascii-8bit
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative 'spec_helper'
|
|
5
|
-
using Refinements
|
|
6
|
-
|
|
7
|
-
RSpec.describe SignatureAlgorithmsCert do
|
|
8
|
-
context 'valid signature_algorithms' do
|
|
9
|
-
let(:supported_signature_algorithms) do
|
|
10
|
-
[
|
|
11
|
-
SignatureScheme::ECDSA_SECP256R1_SHA256,
|
|
12
|
-
SignatureScheme::RSA_PSS_RSAE_SHA256,
|
|
13
|
-
SignatureScheme::RSA_PKCS1_SHA256,
|
|
14
|
-
SignatureScheme::ECDSA_SECP384R1_SHA384,
|
|
15
|
-
SignatureScheme::RSA_PSS_RSAE_SHA384,
|
|
16
|
-
SignatureScheme::RSA_PKCS1_SHA384,
|
|
17
|
-
SignatureScheme::RSA_PSS_RSAE_SHA512,
|
|
18
|
-
SignatureScheme::RSA_PKCS1_SHA512
|
|
19
|
-
]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
let(:extension) do
|
|
23
|
-
SignatureAlgorithmsCert.new(supported_signature_algorithms)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'should be generated' do
|
|
27
|
-
expect(extension).to be_a(SignatureAlgorithmsCert)
|
|
28
|
-
|
|
29
|
-
expect(extension.extension_type)
|
|
30
|
-
.to eq ExtensionType::SIGNATURE_ALGORITHMS_CERT
|
|
31
|
-
expect(extension.supported_signature_algorithms)
|
|
32
|
-
.to eq supported_signature_algorithms
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'should be serialized' do
|
|
36
|
-
expect(extension.serialize)
|
|
37
|
-
.to eq ExtensionType::SIGNATURE_ALGORITHMS_CERT \
|
|
38
|
-
+ 18.to_uint16 \
|
|
39
|
-
+ 16.to_uint16 \
|
|
40
|
-
+ supported_signature_algorithms.join
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'valid signature_algorithms binary' do
|
|
45
|
-
let(:extension) do
|
|
46
|
-
SignatureAlgorithmsCert.deserialize(TESTBINARY_SIGNATURE_ALGORITHMS_CERT)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
let(:supported_signature_algorithms) do
|
|
50
|
-
[
|
|
51
|
-
SignatureScheme::ECDSA_SECP256R1_SHA256,
|
|
52
|
-
SignatureScheme::RSA_PSS_RSAE_SHA256,
|
|
53
|
-
SignatureScheme::RSA_PKCS1_SHA256,
|
|
54
|
-
SignatureScheme::ECDSA_SECP384R1_SHA384,
|
|
55
|
-
SignatureScheme::RSA_PSS_RSAE_SHA384,
|
|
56
|
-
SignatureScheme::RSA_PKCS1_SHA384,
|
|
57
|
-
SignatureScheme::RSA_PSS_RSAE_SHA512,
|
|
58
|
-
SignatureScheme::RSA_PKCS1_SHA512
|
|
59
|
-
]
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'should generate valid object' do
|
|
63
|
-
expect(extension).to be_a(SignatureAlgorithmsCert)
|
|
64
|
-
|
|
65
|
-
expect(extension.extension_type)
|
|
66
|
-
.to eq ExtensionType::SIGNATURE_ALGORITHMS_CERT
|
|
67
|
-
expect(extension.supported_signature_algorithms)
|
|
68
|
-
.to eq supported_signature_algorithms
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'should generate serializable object' do
|
|
72
|
-
expect(extension.serialize)
|
|
73
|
-
.to eq ExtensionType::SIGNATURE_ALGORITHMS_CERT \
|
|
74
|
-
+ TESTBINARY_SIGNATURE_ALGORITHMS_CERT.prefix_uint16_length
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|