Skip to content

Commit 125fcec

Browse files
committed
FEAT: using only cipher modes, which are really supported in the TLS protocol
1 parent a530698 commit 125fcec

File tree

1 file changed

+80
-47
lines changed

1 file changed

+80
-47
lines changed

src/mezz/prot-tls.reb

+80-47
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,18 @@ TLS-context: context [
280280
] 'TLS-Cipher-suite
281281

282282
*EllipticCurves: enum [
283-
secp192r1: #{0013}
284-
secp224k1: #{0014}
285-
secp224r1: #{0015}
286-
secp256k1: #{0016}
287-
secp256r1: #{0017}
288-
secp384r1: #{0018}
289-
secp521r1: #{0019}
290-
x25519: #{001D}
283+
secp192r1: 19 ;#{0013}
284+
secp224k1: 20 ;#{0014}
285+
secp224r1: 21 ;#{0015}
286+
secp256k1: 22 ;#{0016}
287+
secp256r1: 23 ;#{0017}
288+
secp384r1: 24 ;#{0018}
289+
secp521r1: 25 ;#{0019}
290+
bp256r1: 26 ;#{001A}
291+
bp384r1: 27 ;#{001B}
292+
bp512r1: 28 ;#{001C}
293+
curve25519: 29 ;#{001D} ;? or x25519
294+
curve448: 30 ;#{001E} ;? or x448
291295
] 'EllipticCurves
292296

293297
*HashAlgorithm: enum [
@@ -444,41 +448,59 @@ decode-extensions: function[
444448
;-- list of supported suites as a single binary
445449
; This list is sent to the server when negotiating which one to use. Hence
446450
; it should be ORDERED BY CLIENT PREFERENCE (more preferred suites first).
447-
;@@ TODO: use only ciphers which are really available!!!
448-
suported-cipher-suites: decode-cipher-suites suported-cipher-suites-binary: rejoin [
449-
#{CCA9} ;TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
450-
#{CCA8} ;TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
451-
#{C02F} ;TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
452-
#{C030} ;TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
453-
#{C02B} ;TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
454-
#{C02C} ;TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
455-
#{009C} ;TLS-RSA-WITH-AES-128-GCM-SHA256
451+
; Use https://ciphersuite.info for security info!
456452

453+
suported-cipher-suites-binary: make binary! 60
454+
if find system/catalog/ciphers 'chacha20-poly1305 [
455+
binary/write tail suported-cipher-suites-binary [
456+
UI16BE 52393 ;= CCA9 ;TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 ;= recommended
457+
UI16BE 52392 ;= CCA8 ;TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 ;= secure
458+
]
459+
]
460+
if find system/catalog/ciphers 'aes-128-gcm [
461+
binary/write tail suported-cipher-suites-binary [
462+
UI16BE 49195 ;= C02B ;TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ;= recommended
463+
UI16BE 49196 ;= C02C ;TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ;= recommended
464+
UI16BE 49199 ;= C02F ;TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ;= secure
465+
UI16BE 49200 ;= C030 ;TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ;= secure
466+
UI16BE 156 ;= 009C ;TLS_RSA_WITH_AES_128_GCM_SHA256 ;= weak
467+
]
468+
]
469+
if find system/catalog/ciphers 'aes-128-cbc [
470+
binary/write tail suported-cipher-suites-binary [
457471
;- CBC mode is considered to be weak, but still used!
458-
#{C028} ;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
459-
#{C024} ;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
460-
#{C027} ;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
461-
#{C023} ;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
462-
#{C014} ;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
463-
#{C013} ;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
464-
#{C00A} ;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
465-
#{C009} ;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
466-
;#{006A} ;TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
467-
#{006B} ;TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
468-
#{0067} ;TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
469-
#{003D} ;TLS_RSA_WITH_AES_256_CBC_SHA256
470-
#{003C} ;TLS_RSA_WITH_AES_128_CBC_SHA256
471-
#{0035} ;TLS_RSA_WITH_AES_256_CBC_SHA
472-
#{002F} ;TLS_RSA_WITH_AES_128_CBC_SHA
473-
;#{0038} ;TLS_DHE_DSS_WITH_AES_256_CBC_SHA
474-
;#{0032} ;TLS_DHE_DSS_WITH_AES_128_CBC_SHA
475-
#{0039} ;TLS_DHE_RSA_WITH_AES_256_CBC_SHA
476-
#{0033} ;TLS_DHE_RSA_WITH_AES_128_CBC_SHA
477-
;- RC4 is prohibited by https://tools.ietf.org/html/rfc7465 for insufficient security
478-
;#{0004} ;TLS_RSA_WITH_RC4_128_MD5
479-
;#{0005} ;TLS_RSA_WITH_RC4_128_SHA
472+
UI16BE 49192 ;= C028 ;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
473+
UI16BE 49188 ;= C024 ;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
474+
UI16BE 49191 ;= C027 ;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
475+
UI16BE 49187 ;= C023 ;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
476+
UI16BE 49172 ;= C014 ;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
477+
UI16BE 49171 ;= C013 ;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
478+
UI16BE 49162 ;= C00A ;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
479+
UI16BE 49161 ;= C009 ;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
480+
; UI16BE 106 ;= 006A ;TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
481+
UI16BE 107 ;= 006B ;TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
482+
UI16BE 103 ;= 0067 ;TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
483+
UI16BE 61 ;= 003D ;TLS_RSA_WITH_AES_256_CBC_SHA256
484+
UI16BE 60 ;= 003C ;TLS_RSA_WITH_AES_128_CBC_SHA256
485+
UI16BE 53 ;= 0035 ;TLS_RSA_WITH_AES_256_CBC_SHA
486+
UI16BE 47 ;= 002F ;TLS_RSA_WITH_AES_128_CBC_SHA
487+
; UI16BE 56 ;= 0038 ;TLS_DHE_DSS_WITH_AES_256_CBC_SHA
488+
; UI16BE 50 ;= 0032 ;TLS_DHE_DSS_WITH_AES_128_CBC_SHA
489+
UI16BE 57 ;= 0039 ;TLS_DHE_RSA_WITH_AES_256_CBC_SHA
490+
UI16BE 51 ;= 0033 ;TLS_DHE_RSA_WITH_AES_128_CBC_SHA
491+
]
480492
]
481493

494+
;- RC4 is prohibited by https://tools.ietf.org/html/rfc7465 for insufficient security
495+
;if native? :rc4 [
496+
; binary/write tail suported-cipher-suites-binary [
497+
; UI16BE 4 ;= 0004 ;TLS_RSA_WITH_RC4_128_MD5
498+
; UI16BE 5 ;= 0005 ;TLS_RSA_WITH_RC4_128_SHA
499+
; ]
500+
;]
501+
502+
suported-cipher-suites: decode-cipher-suites suported-cipher-suites-binary
503+
482504
supported-signature-algorithms: rejoin [
483505
;@@ TODO: review this list!
484506
;#{0703} ; curve25519 (EdDSA algorithm)
@@ -499,14 +521,25 @@ supported-signature-algorithms: rejoin [
499521
;#{0203} ; ecdsa_sha1
500522
]
501523

502-
supported-elliptic-curves: rejoin [
503-
;#{001D} ; x25519
504-
;#{0019} ; secp521r1
505-
;#{0018} ; secp384r1
506-
#{0017} ; secp256r1
507-
#{0015} ; secp224r1
508-
#{0014} ; secp224k1
509-
#{0013} ; secp192r1
524+
supported-elliptic-curves: make binary! 22
525+
foreach [curve id] [
526+
;; curves in the prefered order!
527+
; curve448 30 ;#{001E}
528+
; curve25519 29 ;#{001D} ;= needs some work - signature-algorithm 0703 not done!
529+
secp521r1 25 ;#{0019}
530+
; bp512r1 28 ; ;= needs tests!
531+
; bp384r1 27 ; ;= needs tests!
532+
; bp256r1 26 ; ;= needs tests!
533+
secp384r1 24 ;#{0018}
534+
secp256r1 23 ;#{0017}
535+
secp256k1 22 ;#{0016}
536+
secp224r1 21 ;#{0015}
537+
secp224k1 20 ;#{0014}
538+
secp192r1 19 ;#{0013}
539+
][
540+
if find system/catalog/elliptic-curves curve [
541+
binary/write tail supported-elliptic-curves [UI16BE :id]
542+
]
510543
]
511544

512545

0 commit comments

Comments
 (0)