Skip to content

Commit 6133cf0

Browse files
committed
update config name and error msgs
1 parent eb0bbdd commit 6133cf0

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

cns/configuration/cns_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
"PopulateHomeAzCacheRetryIntervalSecs": 60
3737
},
3838
"MinTLSVersion": "TLS 1.2",
39-
"AllowedClientSubjectName": ""
39+
"MtlsClientCertSubjectName": ""
4040
}

cns/configuration/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CNSConfig struct {
5959
WireserverIP string
6060
GRPCSettings GRPCSettings
6161
MinTLSVersion string
62-
AllowedClientSubjectName string
62+
MtlsClientCertSubjectName string
6363
}
6464

6565
type TelemetrySettings struct {

cns/configuration/configuration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func TestSetCNSConfigDefaults(t *testing.T) {
222222
IPAddress: "localhost",
223223
Port: 8080,
224224
},
225-
MinTLSVersion: "TLS 1.2",
226-
AllowedClientSubjectName: "",
225+
MinTLSVersion: "TLS 1.2",
226+
MtlsClientCertSubjectName: "",
227227
},
228228
},
229229
{
@@ -254,8 +254,8 @@ func TestSetCNSConfigDefaults(t *testing.T) {
254254
IPAddress: "192.168.1.1",
255255
Port: 9090,
256256
},
257-
MinTLSVersion: "TLS 1.3",
258-
AllowedClientSubjectName: "example.com",
257+
MinTLSVersion: "TLS 1.3",
258+
MtlsClientCertSubjectName: "example.com",
259259
},
260260
want: CNSConfig{
261261
ChannelMode: "Other",
@@ -285,8 +285,8 @@ func TestSetCNSConfigDefaults(t *testing.T) {
285285
IPAddress: "192.168.1.1",
286286
Port: 9090,
287287
},
288-
MinTLSVersion: "TLS 1.3",
289-
AllowedClientSubjectName: "example.com",
288+
MinTLSVersion: "TLS 1.3",
289+
MtlsClientCertSubjectName: "example.com",
290290
},
291291
},
292292
}

cns/service.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,23 @@ func getTLSConfig(tlsSettings localtls.TlsSettings, errChan chan<- error) (*tls.
158158

159159
// verifyPeerCertificate verifies the client certificate's subject name matches the expected subject name.
160160
func verifyPeerCertificate(rawCerts [][]byte, clientSubjectName string) error {
161-
if len(rawCerts) == 0 {
162-
return errors.New("no client certificate provided")
163-
}
164161
// no client subject name provided, skip verification
165162
if clientSubjectName == "" {
166163
return nil
167164
}
168165

166+
if len(rawCerts) == 0 {
167+
return errors.New("no client certificate provided during mTLS")
168+
}
169+
169170
cert, err := x509.ParseCertificate(rawCerts[0])
170171
if err != nil {
171-
return errors.Errorf("failed to parse certificate: %v", err)
172+
return errors.Errorf("Failed to parse client certificate during mTLS: %v", err)
172173
}
173174

174175
err = cert.VerifyHostname(clientSubjectName)
175176
if err != nil {
176-
return errors.Errorf("failed to verify client certificate hostname: %v", err)
177+
return errors.Errorf("Failed to verify client certificate subject name during mTLS: %v", err)
177178
}
178179
return nil
179180
}

cns/service/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func main() {
810810
KeyVaultCertificateRefreshInterval: time.Duration(cnsconfig.KeyVaultSettings.RefreshIntervalInHrs) * time.Hour,
811811
UseMTLS: cnsconfig.UseMTLS,
812812
MinTLSVersion: cnsconfig.MinTLSVersion,
813-
AllowedClientSubjectName: cnsconfig.AllowedClientSubjectName,
813+
AllowedClientSubjectName: cnsconfig.MtlsClientCertSubjectName,
814814
}
815815
}
816816

cns/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestNewService(t *testing.T) {
187187
})
188188
if handshakeFailureExpected {
189189
require.Error(t, err)
190-
require.ErrorContains(t, err, "failed to verify client certificate hostname")
190+
require.ErrorContains(t, err, "Failed to verify client certificate subject name during mTLS")
191191

192192
} else {
193193
require.NoError(t, err)

0 commit comments

Comments
 (0)