tttls1.3 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1951707edb6c1281f07975d9632817a783a0e9f69e9e40da6b1fe45487955c2a
4
- data.tar.gz: 1c4aa360d27a89a9f81dfa6ae3f744115da70189c641618f8d6b9dd0e4519da9
3
+ metadata.gz: e5e95ca87bc146cc9021a42dc44ed5daef30a5d8fc7040ab4531c77045077e82
4
+ data.tar.gz: cae31fb5ec83ac405142d7c67b1b9298d2d0880dbd053e37e7edfd888e70cf9e
5
5
  SHA512:
6
- metadata.gz: b6ee2640200f2384732e9c24c2cdd02aad995b6da04f94a3dcc70cae19ef501f9b90e26cddad399822e9514e2aae1cecf4252d513741234e428f9b94fe8f1de3
7
- data.tar.gz: e5de7b6c20bad449cec2a0fb041db8e4d03a12d6932fcef9ee3b579f9b0e35da80e19604b5b328d292a2cb6393de1f3fe515e4289233b09f6cbff916f6d43735
6
+ metadata.gz: 32080b68a237890982c9407491e754df789460550e7b68a87d1f77a01749da79a7bc463dbb8b53659eb27aa1fc990e168454754fc7b1636ac474e43c61fecd1f
7
+ data.tar.gz: 5a43785680db1cda38f704ac0df711ff10c0d2cded4fc2620c7c5ad8ee15d4f682672983642ce50f4b371cddd93760d06d98839d6c7811323482add07fe7fbc9
@@ -46,6 +46,10 @@ RSpec.describe Client do
46
46
  ' -sigalgs RSA-PSS+SHA512',
47
47
  signature_algorithms_cert: [SignatureScheme::RSA_PKCS1_SHA256],
48
48
  signature_algorithms: [SignatureScheme::RSA_PSS_RSAE_SHA512]
49
+ ],
50
+ [
51
+ ' -record_padding 8446',
52
+ {}
49
53
  ]
50
54
  ].each do |opt, settings|
51
55
  context 'client interop' do
@@ -56,6 +60,7 @@ RSpec.describe Client do
56
60
  + '-key /tmp/server.key ' \
57
61
  + '-tls1_3 ' \
58
62
  + '-www ' \
63
+ + '-quiet ' \
59
64
  + opt
60
65
  pid = spawn(cmd)
61
66
  Process.detach(pid)
@@ -25,9 +25,6 @@ module TTTLS13
25
25
  SignatureScheme::ECDSA_SECP256R1_SHA256,
26
26
  SignatureScheme::ECDSA_SECP384R1_SHA384,
27
27
  SignatureScheme::ECDSA_SECP521R1_SHA512,
28
- SignatureScheme::RSA_PSS_PSS_SHA256,
29
- SignatureScheme::RSA_PSS_PSS_SHA384,
30
- SignatureScheme::RSA_PSS_PSS_SHA512,
31
28
  SignatureScheme::RSA_PSS_RSAE_SHA256,
32
29
  SignatureScheme::RSA_PSS_RSAE_SHA384,
33
30
  SignatureScheme::RSA_PSS_RSAE_SHA512,
@@ -154,6 +151,7 @@ module TTTLS13
154
151
  terminate(:illegal_parameter) unless valid_sh_cipher_suite?
155
152
  terminate(:illegal_parameter) unless valid_sh_compression_method?
156
153
  # only TLS 1.3
154
+ terminate(:illegal_parameter) unless valid_sh_random?
157
155
  terminate(:protocol_version) unless negotiated_tls_1_3?
158
156
 
159
157
  if sh.hrr?
@@ -387,7 +385,7 @@ module TTTLS13
387
385
  # @return [TTTLS13::Message::Extensions]
388
386
  # rubocop: disable Metrics/AbcSize
389
387
  # rubocop: disable Metrics/CyclomaticComplexity
390
- def gen_extensions
388
+ def gen_ch_extensions
391
389
  exs = []
392
390
  # supported_versions: only TLS 1.3
393
391
  exs << Message::Extension::SupportedVersions.new(
@@ -431,7 +429,7 @@ module TTTLS13
431
429
 
432
430
  # @return [TTTLS13::Message::ClientHello]
433
431
  def send_client_hello
434
- exs = gen_extensions
432
+ exs = gen_ch_extensions
435
433
  ch = Message::ClientHello.new(
436
434
  cipher_suites: CipherSuites.new(@settings[:cipher_suites]),
437
435
  extensions: exs
@@ -648,23 +646,23 @@ module TTTLS13
648
646
  # 1. supported_versions == ["\x03\x04"]
649
647
  # 2. legacy_versions == ["\x03\x03"]
650
648
  #
651
- # @raise [TTTLS13::Error::ErrorAlerts]
652
- #
653
649
  # @return [Boolean]
654
650
  def negotiated_tls_1_3?
655
651
  sh = @transcript[SH]
652
+ sh_lv = sh.legacy_version
656
653
  sh_sv = sh.extensions[Message::ExtensionType::SUPPORTED_VERSIONS]
657
654
  &.versions
658
- sh_r8 = sh.random[-8..]
659
- if sh_sv&.first == Message::ProtocolVersion::TLS_1_3 &&
660
- sh_r8 != DOWNGRADE_PROTECTION_TLS_1_2 &&
661
- sh_r8 != DOWNGRADE_PROTECTION_TLS_1_1
662
- true
663
- elsif sh_sv.nil?
664
- false
665
- else
666
- terminate(:illegal_parameter)
667
- end
655
+
656
+ sh_lv == Message::ProtocolVersion::TLS_1_2 &&
657
+ sh_sv&.first == Message::ProtocolVersion::TLS_1_3
658
+ end
659
+
660
+ # @return [Boolean]
661
+ def valid_sh_random?
662
+ sh_r8 = @transcript[SH].random[-8..]
663
+
664
+ sh_r8 != DOWNGRADE_PROTECTION_TLS_1_2 &&
665
+ sh_r8 != DOWNGRADE_PROTECTION_TLS_1_1
668
666
  end
669
667
 
670
668
  # @return [Boolean]
@@ -353,34 +353,35 @@ module TTTLS13
353
353
  #
354
354
  # @return [Boolean]
355
355
  # rubocop: disable Metrics/AbcSize
356
+ # rubocop: disable Metrics/CyclomaticComplexity
356
357
  def certified_certificate?(certificate_list, ca_file = nil, hostname = nil)
357
- store = OpenSSL::X509::Store.new
358
- store.set_default_paths
359
- store.add_file(ca_file) unless ca_file.nil?
360
-
361
358
  cert_bin = certificate_list.first.cert_data
362
359
  cert = OpenSSL::X509::Certificate.new(cert_bin)
363
360
 
364
- chain = certificate_list[1..].map(&:cert_data).map do |c|
365
- OpenSSL::X509::Certificate.new(c)
366
- end
367
- # TODO: parse authorityInfoAccess::CA Issuers
368
-
369
- ctx = OpenSSL::X509::StoreContext.new(store, cert, chain)
370
-
371
361
  # not support CN matching, only support SAN matching
372
362
  unless hostname.nil?
373
363
  san = cert.extensions.find { |ex| ex.oid == 'subjectAltName' }
374
- terminate(:bad_certificate) if san.nil?
364
+ return false if san.nil?
365
+
375
366
  ostr = OpenSSL::ASN1.decode(san.to_der).value.last
376
367
  san_match = OpenSSL::ASN1.decode(ostr.value).map(&:value)
377
368
  .map { |s| s.gsub('.', '\.').gsub('*', '.*') }
378
369
  .any? { |s| hostname.match(/#{s}/) }
379
- return san_match && ctx.verify
370
+ return false unless san_match
380
371
  end
381
- ctx.verify
372
+ store = OpenSSL::X509::Store.new
373
+ store.set_default_paths
374
+ store.add_file(ca_file) unless ca_file.nil?
375
+ chain = certificate_list[1..].map(&:cert_data).map do |c|
376
+ OpenSSL::X509::Certificate.new(c)
377
+ end
378
+ # TODO: parse authorityInfoAccess::CA Issuers
379
+ ctx = OpenSSL::X509::StoreContext.new(store, cert, chain)
380
+ now = Time.now
381
+ ctx.verify && cert.not_before < now && now < cert.not_after
382
382
  end
383
383
  # rubocop: enable Metrics/AbcSize
384
+ # rubocop: enable Metrics/CyclomaticComplexity
384
385
  end
385
386
  # rubocop: enable Metrics/ClassLength
386
387
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTTLS13
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
data/spec/client_spec.rb CHANGED
@@ -230,7 +230,8 @@ RSpec.describe Client do
230
230
  end
231
231
 
232
232
  it 'should check downgrade protection value' do
233
- expect { client.send(:negotiated_tls_1_3?) }.to raise_error(ErrorAlerts)
233
+ expect(client.send(:valid_sh_random?)).to be false
234
+ expect(client.send(:negotiated_tls_1_3?)).to be true
234
235
  end
235
236
  end
236
237
 
@@ -252,7 +253,8 @@ RSpec.describe Client do
252
253
  end
253
254
 
254
255
  it 'should check downgrade protection value' do
255
- expect { client.send(:negotiated_tls_1_3?) }.to raise_error(ErrorAlerts)
256
+ expect(client.send(:valid_sh_random?)).to be false
257
+ expect(client.send(:negotiated_tls_1_3?)).to be true
256
258
  end
257
259
  end
258
260
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tttls1.3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekuwayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-04 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
- rubygems_version: 3.0.1
176
+ rubygems_version: 3.0.3
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: TLS 1.3 implementation in Ruby