-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CipherSuites and InsecureCipherSuites
As part of Go 1.14 the CipherSuites and InsecureCipherSuites functions got added to the TLS package, returning a slice of *tls.CipherSuite. Relates to #148
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// +build go1.14 | ||
|
||
package dtls | ||
|
||
import ( | ||
"crypto/tls" | ||
) | ||
|
||
// Convert from our cipherSuite interface to a tls.CipherSuite struct | ||
func toTLSCipherSuite(c cipherSuite) *tls.CipherSuite { | ||
return &tls.CipherSuite{ | ||
ID: uint16(c.ID()), | ||
Name: c.String(), | ||
SupportedVersions: []uint16{VersionDTLS12}, | ||
Insecure: false, | ||
} | ||
} | ||
|
||
// CipherSuites returns a list of cipher suites currently implemented by this | ||
// package, excluding those with security issues, which are returned by | ||
// InsecureCipherSuites. | ||
func CipherSuites() []*tls.CipherSuite { | ||
suites := allCipherSuites() | ||
res := make([]*tls.CipherSuite, len(suites)) | ||
for i, c := range suites { | ||
res[i] = toTLSCipherSuite(c) | ||
} | ||
return res | ||
} | ||
|
||
// InsecureCipherSuites returns a list of cipher suites currently implemented by | ||
// this package and which have security issues. | ||
func InsecureCipherSuites() []*tls.CipherSuite { | ||
var res []*tls.CipherSuite | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// +build go1.14 | ||
|
||
package dtls | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestInsecureCipherSuites(t *testing.T) { | ||
r := InsecureCipherSuites() | ||
|
||
if len(r) != 0 { | ||
t.Fatalf("Expected no insecure ciphersuites, got %d", len(r)) | ||
} | ||
} | ||
|
||
func TestCipherSuites(t *testing.T) { | ||
ours := allCipherSuites() | ||
theirs := CipherSuites() | ||
|
||
if len(ours) != len(theirs) { | ||
t.Fatalf("Expected %d CipherSuites, got %d", len(ours), len(theirs)) | ||
} | ||
|
||
for i, s := range ours { | ||
i := i | ||
s := s | ||
t.Run(s.String(), func(t *testing.T) { | ||
c := theirs[i] | ||
if c.ID != uint16(s.ID()) { | ||
t.Fatalf("Expected ID: 0x%04X, got 0x%04X", s.ID(), c.ID) | ||
} | ||
|
||
if c.Name != s.String() { | ||
t.Fatalf("Expected Name: %s, got %s", s.String(), c.Name) | ||
} | ||
|
||
if len(c.SupportedVersions) != 1 { | ||
t.Fatalf("Expected %d SupportedVersion, got %d", 1, len(c.SupportedVersions)) | ||
} | ||
|
||
if c.SupportedVersions[0] != VersionDTLS12 { | ||
t.Fatalf("Expected SupportedVersions 0x%04X, got 0x%04X", VersionDTLS12, c.SupportedVersions[0]) | ||
} | ||
|
||
if c.Insecure { | ||
t.Fatalf("Expected Insecure %t, got %t", false, c.Insecure) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters