Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/security: support client TLS verifies CommonName of server (#53358) #53464

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix some conflicts.
  • Loading branch information
3AceShowHand committed May 22, 2024
commit a60cb5e2d5f35640c04337d6bac43136feda9bb4
28 changes: 5 additions & 23 deletions pkg/util/security_test.go
Original file line number Diff line number Diff line change
@@ -74,17 +74,11 @@ func TestVerifyCommonNameAndRotate(t *testing.T) {
util.WithVerifyCommonName([]string{"client1"}),
)
require.NoError(t, err)
<<<<<<< HEAD
port := 9292
url := fmt.Sprintf("https://127.0.0.1:%d", port)
ctx, cancel := context.WithCancel(context.Background())
server := runServer(ctx, serverTLS, port, t)
=======
server, port := runServer(serverTLS, t)
>>>>>>> 397a460dd06 (util/security: support client TLS verifies CommonName of server (#53358))
defer func() {
server.Close()
}()
url := fmt.Sprintf("https://127.0.0.1:%d", port)

clientTLS1, err := util.NewTLSConfig(
util.WithCAContent(caData),
@@ -147,8 +141,6 @@ func TestVerifyCommonNameAndRotate(t *testing.T) {
require.NoError(t, resp.Body.Close())
}

<<<<<<< HEAD
=======
func TestTLSVersion(t *testing.T) {
caData, certs, keys := generateCerts(t, []string{"server", "client"})
serverCert, serverKey := certs[0], keys[0]
@@ -203,7 +195,6 @@ func TestTLSVersion(t *testing.T) {
require.Equal(t, uint16(tls.VersionTLS13), clientTLS2.MinVersion)
}

>>>>>>> 397a460dd06 (util/security: support client TLS verifies CommonName of server (#53358))
func TestCA(t *testing.T) {
caData, certs, keys := generateCerts(t, []string{"server", "client"})
serverCert, serverKey := certs[0], keys[0]
@@ -216,17 +207,11 @@ func TestCA(t *testing.T) {
util.WithCertAndKeyContent(serverCert, serverKey),
)
require.NoError(t, err)
<<<<<<< HEAD
port := 9293
url := fmt.Sprintf("https://127.0.0.1:%d", port)
ctx, cancel := context.WithCancel(context.Background())
server := runServer(ctx, serverTLS, port, t)
=======
server, port := runServer(serverTLS, t)
>>>>>>> 397a460dd06 (util/security: support client TLS verifies CommonName of server (#53358))
defer func() {
server.Close()
}()
url := fmt.Sprintf("https://127.0.0.1:%d", port)

// test only CA
clientTLS1, err := util.NewTLSConfig(
@@ -278,22 +263,19 @@ func handler(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("This an example server"))
}

<<<<<<< HEAD
func runServer(ctx context.Context, tlsCfg *tls.Config, port int, t *testing.T) *http.Server {
=======
func runServer(tlsCfg *tls.Config, t *testing.T) (*http.Server, int) {
>>>>>>> 397a460dd06 (util/security: support client TLS verifies CommonName of server (#53358))
http.HandleFunc("/", handler)
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: nil}
server := &http.Server{Addr: ":0", Handler: nil}

conn, err := net.Listen("tcp", server.Addr)
if err != nil {
require.NoError(t, err)
}
port := conn.Addr().(*net.TCPAddr).Port

tlsListener := tls.NewListener(conn, tlsCfg)
go server.Serve(tlsListener)
return server
return server, port
}

// generateCerts returns the PEM contents of a CA certificate and some certificates and private keys per Common Name in