diff --git a/regress/lib/libtls/gotls/tls.go b/regress/lib/libtls/gotls/tls.go index cf3e84c0309..36018288844 100644 --- a/regress/lib/libtls/gotls/tls.go +++ b/regress/lib/libtls/gotls/tls.go @@ -202,6 +202,15 @@ func (t *TLS) PeerCertIssuer() (string, error) { return C.GoString(issuer), nil } +// PeerCertCommonName returns the common name of the peer certificate. +func (t *TLS) PeerCertCommonName() (string, error) { + commonName := C.tls_peer_cert_common_name(t.ctx) + if commonName == nil { + return "", errors.New("no peer cert common name returned") + } + return C.GoString(commonName), nil +} + // PeerCertSubject returns the subject of the peer certificate. func (t *TLS) PeerCertSubject() (string, error) { subject := C.tls_peer_cert_subject(t.ctx) diff --git a/regress/lib/libtls/gotls/tls_test.go b/regress/lib/libtls/gotls/tls_test.go index 2b7ce2c19eb..20240e05804 100644 --- a/regress/lib/libtls/gotls/tls_test.go +++ b/regress/lib/libtls/gotls/tls_test.go @@ -418,6 +418,9 @@ func TestTLSInfo(t *testing.T) { if _, err := tls.PeerCertSubject(); err == nil { t.Error("PeerCertSubject() returned nil error, want error") } + if _, err := tls.PeerCertCommonName(); err == nil { + t.Error("PeerCertCommonName() returned nil error, want error") + } if _, err := tls.PeerCertHash(); err == nil { t.Error("PeerCertHash() returned nil error, want error") } @@ -468,6 +471,11 @@ func TestTLSInfo(t *testing.T) { } else { t.Logf("Subject: %v", subject) } + if commonName, err := tls.PeerCertCommonName(); err != nil { + t.Errorf("PeerCertCommonName() returned error: %v", err) + } else { + t.Logf("Subject: %v", commonName) + } if hash, err := tls.PeerCertHash(); err != nil { t.Errorf("PeerCertHash() returned error: %v", err) } else if hash != certHash {