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
data/spec/aead_spec.rb DELETED
@@ -1,95 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
-
6
- RSpec.describe Aead do
7
- context 'aead using CipherSuite::TLS_AES_128_GCM_SHA256' do
8
- let(:cipher) do
9
- Aead.new(cipher_suite: CipherSuite::TLS_AES_128_GCM_SHA256,
10
- write_key: TESTBINARY_SERVER_PARAMETERS_WRITE_KEY,
11
- write_iv: TESTBINARY_SERVER_PARAMETERS_WRITE_IV,
12
- sequence_number: SequenceNumber.new)
13
- end
14
-
15
- let(:content) do
16
- TESTBINARY_SERVER_PARAMETERS
17
- end
18
-
19
- let(:encrypted_record) do
20
- TESTBINARY_SERVER_PARAMETERS_RECORD[5..]
21
- end
22
-
23
- let(:record_header) do
24
- TESTBINARY_SERVER_PARAMETERS_RECORD[0...5]
25
- end
26
-
27
- it 'should encrypt content of server parameters' do
28
- expect(cipher.encrypt(content, ContentType::HANDSHAKE))
29
- .to eq encrypted_record
30
- end
31
-
32
- it 'should decrypt encrypted_record server parameters' do
33
- expect(cipher.decrypt(encrypted_record, record_header))
34
- .to eq [content, ContentType::HANDSHAKE]
35
- end
36
- end
37
-
38
- context 'aead using CipherSuite::TLS_AES_128_GCM_SHA256' do
39
- let(:cipher) do
40
- Aead.new(cipher_suite: CipherSuite::TLS_AES_128_GCM_SHA256,
41
- write_key: TESTBINARY_CLIENT_FINISHED_WRITE_KEY,
42
- write_iv: TESTBINARY_CLIENT_FINISHED_WRITE_IV,
43
- sequence_number: SequenceNumber.new)
44
- end
45
-
46
- let(:content) do
47
- TESTBINARY_CLIENT_FINISHED
48
- end
49
-
50
- let(:encrypted_record) do
51
- TESTBINARY_CLIENT_FINISHED_RECORD[5..]
52
- end
53
-
54
- let(:record_header) do
55
- TESTBINARY_CLIENT_FINISHED_RECORD[0...5]
56
- end
57
-
58
- it 'should encrypt content of client finished' do
59
- expect(cipher.encrypt(content, ContentType::HANDSHAKE))
60
- .to eq encrypted_record
61
- end
62
-
63
- it 'should decrypt encrypted_record client finished' do
64
- expect(cipher.decrypt(encrypted_record, record_header))
65
- .to eq [content, ContentType::HANDSHAKE]
66
- end
67
- end
68
-
69
- context 'aead using CipherSuite::TLS_AES_128_GCM_SHA256, ' \
70
- 'HelloRetryRequest,' do
71
- let(:cipher) do
72
- Aead.new(cipher_suite: CipherSuite::TLS_AES_128_GCM_SHA256,
73
- write_key: TESTBINARY_HRR_SERVER_PARAMETERS_WRITE_KEY,
74
- write_iv: TESTBINARY_HRR_SERVER_PARAMETERS_WRITE_IV,
75
- sequence_number: SequenceNumber.new)
76
- end
77
-
78
- let(:content) do
79
- TESTBINARY_HRR_SERVER_PARAMETERS
80
- end
81
-
82
- let(:encrypted_record) do
83
- TESTBINARY_HRR_SERVER_PARAMETERS_RECORD[5..]
84
- end
85
-
86
- let(:record_header) do
87
- TESTBINARY_HRR_SERVER_PARAMETERS_RECORD[0...5]
88
- end
89
-
90
- it 'should decrypt encrypted_record server parameters' do
91
- expect(cipher.decrypt(encrypted_record, record_header))
92
- .to eq [content, ContentType::HANDSHAKE]
93
- end
94
- end
95
- end
data/spec/alert_spec.rb DELETED
@@ -1,54 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
-
6
- RSpec.describe Alert do
7
- context 'unexpected_message alert' do
8
- let(:message) do
9
- Alert.new(level: AlertLevel::FATAL,
10
- description: ALERT_DESCRIPTION[:unexpected_message])
11
- end
12
-
13
- it 'should be serialized' do
14
- expect(message.serialize).to eq AlertLevel::FATAL \
15
- + ALERT_DESCRIPTION[:unexpected_message]
16
- end
17
-
18
- it 'should return error' do
19
- expect(message.to_error).to be_a_kind_of(ErrorAlerts)
20
- expect(message.to_error.message).to eq 'unexpected_message'
21
- end
22
- end
23
-
24
- context 'unexpected_message alert, not given level' do
25
- let(:message) do
26
- Alert.new(description: ALERT_DESCRIPTION[:unexpected_message])
27
- end
28
-
29
- it 'should be serialized' do
30
- expect(message.serialize).to eq AlertLevel::FATAL \
31
- + ALERT_DESCRIPTION[:unexpected_message]
32
- end
33
-
34
- it 'should return error' do
35
- expect(message.to_error).to be_a_kind_of(ErrorAlerts)
36
- expect(message.to_error.message).to eq 'unexpected_message'
37
- end
38
- end
39
-
40
- context 'valid alert binary' do
41
- let(:message) do
42
- Alert.deserialize(TESTBINARY_ALERT)
43
- end
44
-
45
- it 'should generate object' do
46
- expect(message.level).to eq AlertLevel::WARNING
47
- expect(message.description).to eq ALERT_DESCRIPTION[:close_notify]
48
- end
49
-
50
- it 'should generate serializable object' do
51
- expect(message.serialize).to eq TESTBINARY_ALERT
52
- end
53
- end
54
- end
data/spec/alpn_spec.rb DELETED
@@ -1,55 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe Alpn do
8
- context 'valid alpn' do
9
- let(:protocol_name_list) do
10
- ['h2', 'http/1.1', 'http/1.0']
11
- end
12
-
13
- let(:extension) do
14
- Alpn.new(protocol_name_list)
15
- end
16
-
17
- it 'should be generated' do
18
- expect(extension.extension_type)
19
- .to eq ExtensionType::APPLICATION_LAYER_PROTOCOL_NEGOTIATION
20
- expect(extension.protocol_name_list).to eq protocol_name_list
21
- end
22
-
23
- it 'should be serialized' do
24
- expect(extension.serialize)
25
- .to eq ExtensionType::APPLICATION_LAYER_PROTOCOL_NEGOTIATION \
26
- + 23.to_uint16 \
27
- + 21.to_uint16 \
28
- + 'h2'.prefix_uint8_length \
29
- + 'http/1.1'.prefix_uint8_length \
30
- + 'http/1.0'.prefix_uint8_length
31
- end
32
- end
33
-
34
- context 'invalid alpn, empty,' do
35
- let(:extension) do
36
- Alpn.new([])
37
- end
38
-
39
- it 'should not be generated' do
40
- expect { extension }.to raise_error(ErrorAlerts)
41
- end
42
- end
43
-
44
- context 'valid alpn binary' do
45
- let(:extension) do
46
- Alpn.deserialize(TESTBINARY_ALPN)
47
- end
48
-
49
- it 'should generate valid object' do
50
- expect(extension.extension_type)
51
- .to eq ExtensionType::APPLICATION_LAYER_PROTOCOL_NEGOTIATION
52
- expect(extension.protocol_name_list).to eq ['h2', 'http/1.1']
53
- end
54
- end
55
- end
@@ -1,26 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
-
6
- RSpec.describe ApplicationData do
7
- context 'application_data' do
8
- let(:message) do
9
- ApplicationData.new(TESTBINARY_CLIENT_APPLICATION_DATA)
10
- end
11
-
12
- it 'should be serialized' do
13
- expect(message.serialize).to eq TESTBINARY_CLIENT_APPLICATION_DATA
14
- end
15
- end
16
-
17
- context 'valid application_data binary' do
18
- let(:message) do
19
- ApplicationData.deserialize(TESTBINARY_CLIENT_APPLICATION_DATA)
20
- end
21
-
22
- it 'should generate valid serializable object' do
23
- expect(message.serialize).to eq TESTBINARY_CLIENT_APPLICATION_DATA
24
- end
25
- end
26
- end
@@ -1,82 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe Certificate do
8
- context 'valid certificate' do
9
- let(:certificate) do
10
- OpenSSL::X509::Certificate.new(
11
- File.read(__dir__ + '/fixtures/rsa_rsa.crt')
12
- )
13
- end
14
-
15
- let(:message) do
16
- Certificate.new(certificate_list: [CertificateEntry.new(certificate)])
17
- end
18
-
19
- it 'should be generated' do
20
- expect(message.msg_type).to eq HandshakeType::CERTIFICATE
21
- expect(message.certificate_request_context).to be_empty
22
-
23
- certificate_entry = message.certificate_list.first
24
- expect(certificate_entry.cert_data.subject.to_s).to eq '/CN=localhost'
25
- expect(certificate_entry.extensions).to be_empty
26
- end
27
-
28
- it 'should be serialized' do
29
- expect(message.serialize).to eq HandshakeType::CERTIFICATE \
30
- + 742.to_uint24 \
31
- + 0.to_uint8 \
32
- + 738.to_uint24 \
33
- + 733.to_uint24 \
34
- + certificate.to_der \
35
- + 0.to_uint16
36
- end
37
- end
38
-
39
- context 'valid certificate binary' do
40
- let(:message) do
41
- Certificate.deserialize(TESTBINARY_CERTIFICATE)
42
- end
43
-
44
- it 'should generate valid object' do
45
- expect(message.msg_type).to eq HandshakeType::CERTIFICATE
46
- expect(message.certificate_request_context).to be_empty
47
-
48
- certificate_entry = message.certificate_list.first
49
- expect(certificate_entry.cert_data.subject.to_s).to eq '/CN=rsa'
50
- expect(certificate_entry.extensions).to be_empty
51
- end
52
-
53
- it 'should generate serializable object' do
54
- expect(message.serialize).to eq TESTBINARY_CERTIFICATE
55
- end
56
- end
57
-
58
- context 'invalid certificate, including forbidden extension type,' do
59
- let(:certificate) do
60
- OpenSSL::X509::Certificate.new(
61
- File.read(__dir__ + '/fixtures/rsa_rsa.crt')
62
- )
63
- end
64
-
65
- let(:server_name) do
66
- ServerName.new('')
67
- end
68
-
69
- let(:message) do
70
- Certificate.new(
71
- certificate_list: [
72
- CertificateEntry.new(certificate, Extensions.new([server_name]))
73
- ]
74
- )
75
- end
76
-
77
- it 'should be generated' do
78
- expect(message.msg_type).to eq HandshakeType::CERTIFICATE
79
- expect(message.appearable_extensions?).to be false
80
- end
81
- end
82
- end
@@ -1,51 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe CertificateVerify do
8
- context 'valid certificate_verify' do
9
- let(:signature) do
10
- OpenSSL::Random.random_bytes(128)
11
- end
12
-
13
- let(:message) do
14
- CertificateVerify.new(
15
- signature_scheme: SignatureScheme::RSA_PSS_RSAE_SHA256,
16
- signature:
17
- )
18
- end
19
-
20
- it 'should be generated' do
21
- expect(message.msg_type).to eq HandshakeType::CERTIFICATE_VERIFY
22
- expect(message.signature_scheme) \
23
- .to eq SignatureScheme::RSA_PSS_RSAE_SHA256
24
- expect(message.signature).to eq signature
25
- end
26
-
27
- it 'should be serialized' do
28
- expect(message.serialize).to eq HandshakeType::CERTIFICATE_VERIFY \
29
- + 132.to_uint24 \
30
- + SignatureScheme::RSA_PSS_RSAE_SHA256 \
31
- + signature.prefix_uint16_length
32
- end
33
- end
34
-
35
- context 'valid certificate_verify binary' do
36
- let(:message) do
37
- CertificateVerify.deserialize(TESTBINARY_CERTIFICATE_VERIFY)
38
- end
39
-
40
- it 'should generate valid object' do
41
- expect(message.msg_type).to eq HandshakeType::CERTIFICATE_VERIFY
42
- expect(message.signature_scheme) \
43
- .to eq SignatureScheme::RSA_PSS_RSAE_SHA256
44
- expect(message.signature.length).to eq 128
45
- end
46
-
47
- it 'should generate serializable object' do
48
- expect(message.serialize).to eq TESTBINARY_CERTIFICATE_VERIFY
49
- end
50
- end
51
- end
@@ -1,26 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
-
6
- RSpec.describe ChangeCipherSpec do
7
- context 'change_cipher_spec' do
8
- let(:message) do
9
- ChangeCipherSpec.new
10
- end
11
-
12
- it 'should be serialized' do
13
- expect(message.serialize).to eq "\x01"
14
- end
15
- end
16
-
17
- context 'valid change_cipher_spec binary' do
18
- let(:message) do
19
- ChangeCipherSpec.deserialize(TESTBINARY_CHANGE_CIPHER_SPEC)
20
- end
21
-
22
- it 'should generate valid serializable object' do
23
- expect(message.serialize).to eq "\x01"
24
- end
25
- end
26
- end
@@ -1,39 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe CipherSuites do
8
- context 'valid cipher suites binary' do
9
- let(:cs) do
10
- CipherSuites.deserialize(TESTBINARY_CIPHER_SUITES)
11
- end
12
-
13
- it 'should generate valid object' do
14
- expect(cs).to eq [CipherSuite::TLS_AES_256_GCM_SHA384,
15
- CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
16
- CipherSuite::TLS_AES_128_GCM_SHA256]
17
- end
18
- end
19
-
20
- context 'invalid cipher suites binary, too short' do
21
- let(:cs) do
22
- CipherSuites.deserialize(TESTBINARY_CIPHER_SUITES[0...-1])
23
- end
24
-
25
- it 'should not generate object' do
26
- expect { cs }.to raise_error(ErrorAlerts)
27
- end
28
- end
29
-
30
- context 'invalid cipher suites binary, binary is nil' do
31
- let(:cs) do
32
- CipherSuites.deserialize(nil)
33
- end
34
-
35
- it 'should not generate object' do
36
- expect { cs }.to raise_error(ErrorAlerts)
37
- end
38
- end
39
- end
@@ -1,105 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require_relative 'spec_helper'
5
- using Refinements
6
-
7
- RSpec.describe ClientHello do
8
- context 'default client_hello' do
9
- let(:random) do
10
- OpenSSL::Random.random_bytes(32)
11
- end
12
-
13
- let(:legacy_session_id) do
14
- Array.new(32, 0).map(&:chr).join
15
- end
16
-
17
- let(:cipher_suites) do
18
- CipherSuites.new([TLS_AES_256_GCM_SHA384,
19
- TLS_CHACHA20_POLY1305_SHA256,
20
- TLS_AES_128_GCM_SHA256])
21
- end
22
-
23
- let(:message) do
24
- ClientHello.new(random:,
25
- legacy_session_id:,
26
- cipher_suites:)
27
- end
28
-
29
- it 'should be generated' do
30
- expect(message.msg_type).to eq HandshakeType::CLIENT_HELLO
31
- expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
32
- expect(message.random).to eq random
33
- expect(message.legacy_session_id).to eq legacy_session_id
34
- expect(message.cipher_suites).to eq [TLS_AES_256_GCM_SHA384,
35
- TLS_CHACHA20_POLY1305_SHA256,
36
- TLS_AES_128_GCM_SHA256]
37
- expect(message.legacy_compression_methods).to eq ["\x00"]
38
- expect(message.extensions).to be_empty
39
- expect(message.negotiated_tls_1_3?).to be false
40
- expect(message.ch_inner?).to be false
41
- end
42
-
43
- it 'should be serialized' do
44
- expect(message.serialize).to eq HandshakeType::CLIENT_HELLO \
45
- + 79.to_uint24 \
46
- + ProtocolVersion::TLS_1_2 \
47
- + random \
48
- + legacy_session_id.length.to_uint8 \
49
- + legacy_session_id \
50
- + cipher_suites.serialize \
51
- + "\x01\x00" \
52
- + Extensions.new.serialize
53
- end
54
- end
55
-
56
- context 'valid client_hello binary' do
57
- let(:message) do
58
- ClientHello.deserialize(TESTBINARY_CLIENT_HELLO)
59
- end
60
-
61
- it 'should generate valid object' do
62
- expect(message.msg_type).to eq HandshakeType::CLIENT_HELLO
63
- expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
64
- expect(message.negotiated_tls_1_3?).to be true
65
- end
66
-
67
- it 'should generate valid serializable object' do
68
- expect(message.serialize).to eq TESTBINARY_CLIENT_HELLO
69
- end
70
- end
71
-
72
- context 'valid client_hello binary, 0-RTT,' do
73
- let(:message) do
74
- ClientHello.deserialize(TESTBINARY_0_RTT_CLIENT_HELLO)
75
- end
76
-
77
- it 'should generate valid object' do
78
- expect(message.msg_type).to eq HandshakeType::CLIENT_HELLO
79
- expect(message.legacy_version).to eq ProtocolVersion::TLS_1_2
80
- expect(message.negotiated_tls_1_3?).to be true
81
- end
82
-
83
- it 'should generate valid serializable object' do
84
- expect(message.serialize).to eq TESTBINARY_0_RTT_CLIENT_HELLO
85
- end
86
- end
87
-
88
- context 'valid inner client_hello' do
89
- let(:message) do
90
- cipher_suites = CipherSuites.new([TLS_AES_256_GCM_SHA384,
91
- TLS_CHACHA20_POLY1305_SHA256,
92
- TLS_AES_128_GCM_SHA256])
93
- ch = ClientHello.new(random: OpenSSL::Random.random_bytes(32),
94
- legacy_session_id: Array.new(32, 0).map(&:chr).join,
95
- cipher_suites:)
96
- ch.extensions[Message::ExtensionType::ENCRYPTED_CLIENT_HELLO] \
97
- = Message::Extension::ECHClientHello.new_inner
98
- ch
99
- end
100
-
101
- it 'should generate ClientHelloInner' do
102
- expect(message.ch_inner?).to be true
103
- end
104
- end
105
- end