@@ -15,6 +15,10 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
15
15
/// </summary>
16
16
internal static class OtlpMtlsCertificateManager
17
17
{
18
+ private const string CaCertificateType = "CA certificate" ;
19
+ private const string ClientCertificateType = "Client certificate" ;
20
+ private const string ClientPrivateKeyType = "Client private key" ;
21
+
18
22
/// <summary>
19
23
/// Loads a CA certificate from a PEM file.
20
24
/// </summary>
@@ -28,27 +32,27 @@ public static X509Certificate2 LoadCaCertificate(
28
32
string caCertificatePath ,
29
33
bool enableFilePermissionChecks = true )
30
34
{
31
- ValidateFileExists ( caCertificatePath , "CA certificate" ) ;
35
+ ValidateFileExists ( caCertificatePath , CaCertificateType ) ;
32
36
33
37
if ( enableFilePermissionChecks )
34
38
{
35
- ValidateFilePermissions ( caCertificatePath , "CA certificate" ) ;
39
+ ValidateFilePermissions ( caCertificatePath , CaCertificateType ) ;
36
40
}
37
41
38
42
try
39
43
{
40
44
var caCertificate = X509Certificate2 . CreateFromPemFile ( caCertificatePath ) ;
41
45
42
46
OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoaded (
43
- "CA certificate" ,
47
+ CaCertificateType ,
44
48
caCertificatePath ) ;
45
49
46
50
return caCertificate ;
47
51
}
48
52
catch ( Exception ex )
49
53
{
50
54
OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoadFailed (
51
- "CA certificate" ,
55
+ CaCertificateType ,
52
56
caCertificatePath ,
53
57
ex . Message ) ;
54
58
throw new InvalidOperationException (
@@ -72,13 +76,13 @@ public static X509Certificate2 LoadClientCertificate(
72
76
string clientKeyPath ,
73
77
bool enableFilePermissionChecks = true )
74
78
{
75
- ValidateFileExists ( clientCertificatePath , "Client certificate" ) ;
76
- ValidateFileExists ( clientKeyPath , "Client private key" ) ;
79
+ ValidateFileExists ( clientCertificatePath , ClientCertificateType ) ;
80
+ ValidateFileExists ( clientKeyPath , ClientPrivateKeyType ) ;
77
81
78
82
if ( enableFilePermissionChecks )
79
83
{
80
- ValidateFilePermissions ( clientCertificatePath , "Client certificate" ) ;
81
- ValidateFilePermissions ( clientKeyPath , "Client private key" ) ;
84
+ ValidateFilePermissions ( clientCertificatePath , ClientCertificateType ) ;
85
+ ValidateFilePermissions ( clientKeyPath , ClientPrivateKeyType ) ;
82
86
}
83
87
84
88
try
@@ -94,15 +98,15 @@ public static X509Certificate2 LoadClientCertificate(
94
98
}
95
99
96
100
OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoaded (
97
- "Client certificate" ,
101
+ ClientCertificateType ,
98
102
clientCertificatePath ) ;
99
103
100
104
return clientCertificate ;
101
105
}
102
106
catch ( Exception ex )
103
107
{
104
108
OpenTelemetryProtocolExporterEventSource . Log . MtlsCertificateLoadFailed (
105
- "Client certificate" ,
109
+ ClientCertificateType ,
106
110
clientCertificatePath ,
107
111
ex . Message ) ;
108
112
throw new InvalidOperationException (
0 commit comments