Skip to content

Commit

Permalink
Enhance the cipher suite (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishH-DELL authored Jun 15, 2024
1 parent 2bed8de commit f3eb931
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func (s *Service) Run() error {
config := &tls.Config{
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12,
MaxVersion: tls.VersionTLS13,
CipherSuites: GetSecuredCipherSuites(),
}

server := &http.Server{
Expand Down Expand Up @@ -326,3 +328,12 @@ func generateColumns(columns ...string) []map[string]string {
}
return result
}

// GetSecuredCipherSuites returns a set of secure cipher suites.
func GetSecuredCipherSuites() (suites []uint16) {
securedSuite := tls.CipherSuites()
for _, v := range securedSuite {
suites = append(suites, v.ID)
}
return suites
}
21 changes: 21 additions & 0 deletions internal/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service_test

import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"io"
Expand Down Expand Up @@ -544,3 +545,23 @@ func TestHttpServerStartup(t *testing.T) {
})
}
}

func TestGetSecuredCipherSuites(t *testing.T) {
expectedSuites := tls.CipherSuites()
expectedIDs := make([]uint16, len(expectedSuites))
for i, suite := range expectedSuites {
expectedIDs[i] = suite.ID
}

got := service.GetSecuredCipherSuites()

if len(got) != len(expectedIDs) {
t.Fatalf("Expected %d cipher suites, but got %d", len(expectedIDs), len(got))
}

for i, id := range expectedIDs {
if got[i] != id {
t.Errorf("Expected cipher suite ID %x at index %d, but got %x", id, i, got[i])
}
}
}

0 comments on commit f3eb931

Please sign in to comment.