@@ -15,6 +15,10 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
1515/// </summary>
1616internal static class OtlpMtlsCertificateManager
1717{
18+ private const string CaCertificateType = "CA certificate" ;
19+ private const string ClientCertificateType = "Client certificate" ;
20+ private const string ClientPrivateKeyType = "Client private key" ;
21+
1822 /// <summary>
1923 /// Loads a CA certificate from a PEM file.
2024 /// </summary>
@@ -28,27 +32,27 @@ public static X509Certificate2 LoadCaCertificate(
2832 string caCertificatePath ,
2933 bool enableFilePermissionChecks = true )
3034 {
31- ValidateFileExists ( caCertificatePath , "CA certificate" ) ;
35+ ValidateFileExists ( caCertificatePath , CaCertificateType ) ;
3236
3337 if ( enableFilePermissionChecks )
3438 {
35- ValidateFilePermissions ( caCertificatePath , "CA certificate" ) ;
39+ ValidateFilePermissions ( caCertificatePath , CaCertificateType ) ;
3640 }
3741
3842 try
3943 {
4044 var caCertificate = X509Certificate2 . CreateFromPemFile ( caCertificatePath ) ;
4145
4246 OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoaded (
43- "CA certificate" ,
47+ CaCertificateType ,
4448 caCertificatePath ) ;
4549
4650 return caCertificate ;
4751 }
4852 catch ( Exception ex )
4953 {
5054 OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoadFailed (
51- "CA certificate" ,
55+ CaCertificateType ,
5256 caCertificatePath ,
5357 ex . Message ) ;
5458 throw new InvalidOperationException (
@@ -72,13 +76,13 @@ public static X509Certificate2 LoadClientCertificate(
7276 string clientKeyPath ,
7377 bool enableFilePermissionChecks = true )
7478 {
75- ValidateFileExists ( clientCertificatePath , "Client certificate" ) ;
76- ValidateFileExists ( clientKeyPath , "Client private key" ) ;
79+ ValidateFileExists ( clientCertificatePath , ClientCertificateType ) ;
80+ ValidateFileExists ( clientKeyPath , ClientPrivateKeyType ) ;
7781
7882 if ( enableFilePermissionChecks )
7983 {
80- ValidateFilePermissions ( clientCertificatePath , "Client certificate" ) ;
81- ValidateFilePermissions ( clientKeyPath , "Client private key" ) ;
84+ ValidateFilePermissions ( clientCertificatePath , ClientCertificateType ) ;
85+ ValidateFilePermissions ( clientKeyPath , ClientPrivateKeyType ) ;
8286 }
8387
8488 try
@@ -94,15 +98,15 @@ public static X509Certificate2 LoadClientCertificate(
9498 }
9599
96100 OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoaded (
97- "Client certificate" ,
101+ ClientCertificateType ,
98102 clientCertificatePath ) ;
99103
100104 return clientCertificate ;
101105 }
102106 catch ( Exception ex )
103107 {
104108 OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoadFailed (
105- "Client certificate" ,
109+ ClientCertificateType ,
106110 clientCertificatePath ,
107111 ex . Message ) ;
108112 throw new InvalidOperationException (
0 commit comments