tttls1.3 0.3.5 → 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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +2 -2
  4. data/README.md +1 -1
  5. data/lib/tttls1.3/client.rb +11 -5
  6. data/lib/tttls1.3/ech.rb +31 -90
  7. data/lib/tttls1.3/message/alert.rb +1 -0
  8. data/lib/tttls1.3/sslkeylogfile.rb +22 -0
  9. data/lib/tttls1.3/version.rb +1 -1
  10. data/lib/tttls1.3.rb +1 -0
  11. data/tttls1.3.gemspec +7 -4
  12. metadata +11 -121
  13. data/.github/workflows/ci.yml +0 -39
  14. data/.gitignore +0 -17
  15. data/spec/aead_spec.rb +0 -95
  16. data/spec/alert_spec.rb +0 -54
  17. data/spec/alpn_spec.rb +0 -55
  18. data/spec/application_data_spec.rb +0 -26
  19. data/spec/certificate_spec.rb +0 -82
  20. data/spec/certificate_verify_spec.rb +0 -51
  21. data/spec/change_cipher_spec_spec.rb +0 -26
  22. data/spec/cipher_suites_spec.rb +0 -39
  23. data/spec/client_hello_spec.rb +0 -105
  24. data/spec/client_spec.rb +0 -274
  25. data/spec/compress_certificate_spec.rb +0 -54
  26. data/spec/cookie_spec.rb +0 -98
  27. data/spec/early_data_indication_spec.rb +0 -64
  28. data/spec/ech_outer_extensions_spec.rb +0 -42
  29. data/spec/ech_spec.rb +0 -122
  30. data/spec/encrypted_extensions_spec.rb +0 -94
  31. data/spec/end_of_early_data_spec.rb +0 -28
  32. data/spec/endpoint_spec.rb +0 -167
  33. data/spec/error_spec.rb +0 -18
  34. data/spec/extensions_spec.rb +0 -250
  35. data/spec/finished_spec.rb +0 -55
  36. data/spec/fixtures/rsa_ca.crt +0 -18
  37. data/spec/fixtures/rsa_ca.key +0 -27
  38. data/spec/fixtures/rsa_rsa.crt +0 -18
  39. data/spec/fixtures/rsa_rsa.key +0 -27
  40. data/spec/fixtures/rsa_rsa_ocsp.crt +0 -18
  41. data/spec/fixtures/rsa_rsa_ocsp.key +0 -27
  42. data/spec/fixtures/rsa_rsassaPss.crt +0 -20
  43. data/spec/fixtures/rsa_rsassaPss.key +0 -27
  44. data/spec/fixtures/rsa_secp256r1.crt +0 -14
  45. data/spec/fixtures/rsa_secp256r1.key +0 -5
  46. data/spec/fixtures/rsa_secp384r1.crt +0 -14
  47. data/spec/fixtures/rsa_secp384r1.key +0 -6
  48. data/spec/fixtures/rsa_secp521r1.crt +0 -15
  49. data/spec/fixtures/rsa_secp521r1.key +0 -7
  50. data/spec/key_schedule_spec.rb +0 -221
  51. data/spec/key_share_spec.rb +0 -199
  52. data/spec/new_session_ticket_spec.rb +0 -80
  53. data/spec/pre_shared_key_spec.rb +0 -167
  54. data/spec/psk_key_exchange_modes_spec.rb +0 -45
  55. data/spec/record_size_limit_spec.rb +0 -61
  56. data/spec/record_spec.rb +0 -105
  57. data/spec/server_hello_spec.rb +0 -200
  58. data/spec/server_name_spec.rb +0 -110
  59. data/spec/server_spec.rb +0 -232
  60. data/spec/signature_algorithms_cert_spec.rb +0 -77
  61. data/spec/signature_algorithms_spec.rb +0 -104
  62. data/spec/spec_helper.rb +0 -990
  63. data/spec/status_request_spec.rb +0 -140
  64. data/spec/supported_groups_spec.rb +0 -79
  65. data/spec/supported_versions_spec.rb +0 -136
  66. data/spec/transcript_spec.rb +0 -83
  67. data/spec/unknown_extension_spec.rb +0 -90
  68. data/spec/utils_spec.rb +0 -235
@@ -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
@@ -1,104 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe SignatureAlgorithms 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
- SignatureAlgorithms.new(supported_signature_algorithms)
24
- end
25
-
26
- it 'should be generated' do
27
- expect(extension).to be_a(SignatureAlgorithms)
28
-
29
- expect(extension.extension_type).to eq ExtensionType::SIGNATURE_ALGORITHMS
30
- expect(extension.supported_signature_algorithms)
31
- .to eq supported_signature_algorithms
32
- end
33
-
34
- it 'should be serialized' do
35
- expect(extension.serialize).to eq ExtensionType::SIGNATURE_ALGORITHMS \
36
- + 18.to_uint16 \
37
- + 16.to_uint16 \
38
- + supported_signature_algorithms.join
39
- end
40
- end
41
-
42
- context 'invalid signature_algorithms, empty,' do
43
- let(:extension) do
44
- SignatureAlgorithms.new([])
45
- end
46
-
47
- it 'should not be generated' do
48
- expect { extension }.to raise_error(ErrorAlerts)
49
- end
50
- end
51
-
52
- context 'invalid signature_algorithms, too long,' do
53
- let(:extension) do
54
- SignatureAlgorithms.new((0..2**15 - 2).to_a.map(&:to_uint16))
55
- end
56
-
57
- it 'should not be generated' do
58
- expect { extension }.to raise_error(ErrorAlerts)
59
- end
60
- end
61
-
62
- context 'valid signature_algorithms binary' do
63
- let(:extension) do
64
- SignatureAlgorithms.deserialize(TESTBINARY_SIGNATURE_ALGORITHMS)
65
- end
66
-
67
- let(:supported_signature_algorithms) do
68
- [
69
- SignatureScheme::ECDSA_SECP256R1_SHA256,
70
- SignatureScheme::RSA_PSS_RSAE_SHA256,
71
- SignatureScheme::RSA_PKCS1_SHA256,
72
- SignatureScheme::ECDSA_SECP384R1_SHA384,
73
- SignatureScheme::RSA_PSS_RSAE_SHA384,
74
- SignatureScheme::RSA_PKCS1_SHA384,
75
- SignatureScheme::RSA_PSS_RSAE_SHA512,
76
- SignatureScheme::RSA_PKCS1_SHA512
77
- ]
78
- end
79
-
80
- it 'should generate valid object' do
81
- expect(extension).to be_a(SignatureAlgorithms)
82
-
83
- expect(extension.extension_type).to eq ExtensionType::SIGNATURE_ALGORITHMS
84
- expect(extension.supported_signature_algorithms)
85
- .to eq supported_signature_algorithms
86
- end
87
-
88
- it 'should generate serializable object' do
89
- expect(extension.serialize)
90
- .to eq ExtensionType::SIGNATURE_ALGORITHMS \
91
- + TESTBINARY_SIGNATURE_ALGORITHMS.prefix_uint16_length
92
- end
93
- end
94
-
95
- context 'invalid signature_algorithms binary, malformed binary,' do
96
- let(:extension) do
97
- SignatureAlgorithms.deserialize(TESTBINARY_SIGNATURE_ALGORITHMS[0...-1])
98
- end
99
-
100
- it 'should return nil' do
101
- expect(extension).to be nil
102
- end
103
- end
104
- end