1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

Add regress coverage for tls_peer_cert_common_name()

This commit is contained in:
tb 2024-12-10 08:43:17 +00:00
parent 5ad0d35887
commit 7f9db3f573
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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 {