Skip to content

Commit f3eb931

Browse files
authored
Enhance the cipher suite (#154)
1 parent 2bed8de commit f3eb931

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

internal/service/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func (s *Service) Run() error {
8282
config := &tls.Config{
8383
Certificates: []tls.Certificate{cert},
8484
MinVersion: tls.VersionTLS12,
85+
MaxVersion: tls.VersionTLS13,
86+
CipherSuites: GetSecuredCipherSuites(),
8587
}
8688

8789
server := &http.Server{
@@ -326,3 +328,12 @@ func generateColumns(columns ...string) []map[string]string {
326328
}
327329
return result
328330
}
331+
332+
// GetSecuredCipherSuites returns a set of secure cipher suites.
333+
func GetSecuredCipherSuites() (suites []uint16) {
334+
securedSuite := tls.CipherSuites()
335+
for _, v := range securedSuite {
336+
suites = append(suites, v.ID)
337+
}
338+
return suites
339+
}

internal/service/service_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package service_test
1818

1919
import (
2020
"bytes"
21+
"crypto/tls"
2122
"encoding/json"
2223
"errors"
2324
"io"
@@ -544,3 +545,23 @@ func TestHttpServerStartup(t *testing.T) {
544545
})
545546
}
546547
}
548+
549+
func TestGetSecuredCipherSuites(t *testing.T) {
550+
expectedSuites := tls.CipherSuites()
551+
expectedIDs := make([]uint16, len(expectedSuites))
552+
for i, suite := range expectedSuites {
553+
expectedIDs[i] = suite.ID
554+
}
555+
556+
got := service.GetSecuredCipherSuites()
557+
558+
if len(got) != len(expectedIDs) {
559+
t.Fatalf("Expected %d cipher suites, but got %d", len(expectedIDs), len(got))
560+
}
561+
562+
for i, id := range expectedIDs {
563+
if got[i] != id {
564+
t.Errorf("Expected cipher suite ID %x at index %d, but got %x", id, i, got[i])
565+
}
566+
}
567+
}

0 commit comments

Comments
 (0)