@@ -14,6 +14,7 @@ import (
14
14
"crypto/rc4"
15
15
"crypto/sha1"
16
16
"crypto/sha256"
17
+ "crypto/sha512"
17
18
"fmt"
18
19
"hash"
19
20
"internal/cpu"
@@ -69,8 +70,12 @@ func CipherSuites() []*CipherSuite {
69
70
{TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 , "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" , supportedOnlyTLS12 , false },
70
71
{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 , "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" , supportedOnlyTLS12 , false },
71
72
{TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 , "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" , supportedOnlyTLS12 , false },
73
+ {TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA , "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" , supportedOnlyTLS12 , false },
74
+ {TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA , "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" , supportedOnlyTLS12 , false },
75
+ {TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 , "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" , supportedOnlyTLS12 , false },
72
76
{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 , "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" , supportedOnlyTLS12 , false },
73
77
{TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 , "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" , supportedOnlyTLS12 , false },
78
+ {TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 , "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" , supportedOnlyTLS12 , false },
74
79
}
75
80
}
76
81
@@ -91,6 +96,7 @@ func InsecureCipherSuites() []*CipherSuite {
91
96
{TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA , "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" , supportedUpToTLS12 , true },
92
97
{TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 , "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" , supportedOnlyTLS12 , true },
93
98
{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 , "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" , supportedOnlyTLS12 , true },
99
+ {TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 , "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" , supportedOnlyTLS12 , true },
94
100
}
95
101
}
96
102
@@ -128,6 +134,9 @@ const (
128
134
// suiteSHA384 indicates that the cipher suite uses SHA384 as the
129
135
// handshake hash.
130
136
suiteSHA384
137
+ // suiteNoCerts indicates that the cipher suite doesn't use certificate exchange
138
+ // (anonymous ciphersuites or pre-shared-secret)
139
+ suiteNoCerts
131
140
)
132
141
133
142
// A cipherSuite is a TLS 1.0–1.2 cipher suite, and defines the key exchange
@@ -169,6 +178,12 @@ var cipherSuites = []*cipherSuite{ // TODO: replace with a map, since the order
169
178
{TLS_RSA_WITH_RC4_128_SHA , 16 , 20 , 0 , rsaKA , 0 , cipherRC4 , macSHA1 , nil },
170
179
{TLS_ECDHE_RSA_WITH_RC4_128_SHA , 16 , 20 , 0 , ecdheRSAKA , suiteECDHE , cipherRC4 , macSHA1 , nil },
171
180
{TLS_ECDHE_ECDSA_WITH_RC4_128_SHA , 16 , 20 , 0 , ecdheECDSAKA , suiteECDHE | suiteECSign , cipherRC4 , macSHA1 , nil },
181
+
182
+ {TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA , 16 , 20 , 16 , ecdhePSKKA , suiteECDHE | suiteTLS12 | suiteNoCerts , cipherAES , macSHA1 , nil },
183
+ {TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 , 16 , 32 , 16 , ecdhePSKKA , suiteECDHE | suiteTLS12 | suiteNoCerts , cipherAES , macSHA256 , nil },
184
+ {TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA , 32 , 20 , 16 , ecdhePSKKA , suiteECDHE | suiteTLS12 | suiteNoCerts , cipherAES , macSHA1 , nil },
185
+ {TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 , 32 , 48 , 16 , ecdhePSKKA , suiteECDHE | suiteTLS12 | suiteSHA384 | suiteNoCerts , cipherAES , macSHA384 , nil },
186
+ {TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 , 32 , 0 , 12 , ecdhePSKKA , suiteECDHE | suiteTLS12 | suiteNoCerts , nil , nil , aeadChaCha20Poly1305 },
172
187
}
173
188
174
189
// selectCipherSuite returns the first TLS 1.0–1.2 cipher suite from ids which
@@ -272,11 +287,12 @@ var cipherSuitesPreferenceOrder = []uint16{
272
287
// AEADs w/ ECDHE
273
288
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 , TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
274
289
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 , TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
275
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 ,
290
+ TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 ,
276
291
277
292
// CBC w/ ECDHE
278
- TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ,
279
- TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
293
+ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA ,
294
+ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA ,
295
+ TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 ,
280
296
281
297
// AEADs w/o ECDHE
282
298
TLS_RSA_WITH_AES_128_GCM_SHA256 ,
@@ -292,6 +308,7 @@ var cipherSuitesPreferenceOrder = []uint16{
292
308
293
309
// CBC_SHA256
294
310
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
311
+ TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 ,
295
312
TLS_RSA_WITH_AES_128_CBC_SHA256 ,
296
313
297
314
// RC4
@@ -301,22 +318,27 @@ var cipherSuitesPreferenceOrder = []uint16{
301
318
302
319
var cipherSuitesPreferenceOrderNoAES = []uint16 {
303
320
// ChaCha20Poly1305
304
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 ,
321
+ TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 , TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 ,
305
322
306
323
// AES-GCM w/ ECDHE
307
324
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 , TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
308
325
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 , TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
309
326
310
327
// The rest of cipherSuitesPreferenceOrder.
311
- TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ,
312
- TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
328
+ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA , TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA ,
329
+ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA , TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA ,
330
+ TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 ,
331
+
313
332
TLS_RSA_WITH_AES_128_GCM_SHA256 ,
314
333
TLS_RSA_WITH_AES_256_GCM_SHA384 ,
315
334
TLS_RSA_WITH_AES_128_CBC_SHA ,
316
335
TLS_RSA_WITH_AES_256_CBC_SHA ,
336
+
317
337
TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA ,
318
338
TLS_RSA_WITH_3DES_EDE_CBC_SHA ,
339
+
319
340
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
341
+ TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 ,
320
342
TLS_RSA_WITH_AES_128_CBC_SHA256 ,
321
343
TLS_ECDHE_ECDSA_WITH_RC4_128_SHA , TLS_ECDHE_RSA_WITH_RC4_128_SHA ,
322
344
TLS_RSA_WITH_RC4_128_SHA ,
@@ -327,6 +349,7 @@ var cipherSuitesPreferenceOrderNoAES = []uint16{
327
349
var disabledCipherSuites = []uint16 {
328
350
// CBC_SHA256
329
351
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 , TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
352
+ TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 ,
330
353
TLS_RSA_WITH_AES_128_CBC_SHA256 ,
331
354
332
355
// RC4
@@ -437,6 +460,11 @@ func macSHA256(key []byte) hash.Hash {
437
460
return hmac .New (sha256 .New , key )
438
461
}
439
462
463
+ // macSHA384 returns a SHA-384 based MAC.
464
+ func macSHA384 (key []byte ) hash.Hash {
465
+ return hmac .New (sha512 .New384 , key )
466
+ }
467
+
440
468
type aead interface {
441
469
cipher.AEAD
442
470
@@ -619,6 +647,12 @@ func ecdheRSAKA(version uint16) keyAgreement {
619
647
}
620
648
}
621
649
650
+ func ecdhePSKKA (version uint16 ) keyAgreement {
651
+ return & ecdhePskKeyAgreement {
652
+ version : version ,
653
+ }
654
+ }
655
+
622
656
// mutualCipherSuite returns a cipherSuite given a list of supported
623
657
// ciphersuites and the id requested by the peer.
624
658
func mutualCipherSuite (have []uint16 , want uint16 ) * cipherSuite {
@@ -683,8 +717,13 @@ const (
683
717
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02b
684
718
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc030
685
719
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc02c
720
+ TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA uint16 = 0xc035
721
+ TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA uint16 = 0xc036
722
+ TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 uint16 = 0xc037
723
+ TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 uint16 = 0xc038
686
724
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca8
687
725
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca9
726
+ TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xccac
688
727
689
728
// TLS 1.3 cipher suites.
690
729
TLS_AES_128_GCM_SHA256 uint16 = 0x1301
0 commit comments