Skip to content

Commit cdf5299

Browse files
committed
chore(): Decoupling OTEL_EXPORTER_OTLP_CERTIFICATE from mTLS
1 parent 1080291 commit cdf5299

File tree

10 files changed

+642
-213
lines changed

10 files changed

+642
-213
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,28 @@ internal void MtlsHttpClientCreationFailed(Exception ex)
325325
Level = EventLevel.Error)]
326326
internal void MtlsHttpClientCreationFailed(string exception) =>
327327
this.WriteEvent(34, exception);
328+
329+
[Event(
330+
35,
331+
Message = "CA certificate configured for server validation. Subject: '{0}'.",
332+
Level = EventLevel.Informational)]
333+
internal void CaCertificateConfigured(string subject) =>
334+
this.WriteEvent(35, subject);
335+
336+
[NonEvent]
337+
internal void SecureHttpClientCreationFailed(Exception ex)
338+
{
339+
if (Log.IsEnabled(EventLevel.Error, EventKeywords.All))
340+
{
341+
this.SecureHttpClientCreationFailed(ex.ToInvariantString());
342+
}
343+
}
344+
345+
[Event(
346+
36,
347+
Message = "Failed to create secure HttpClient. Exception: {0}",
348+
Level = EventLevel.Error)]
349+
internal void SecureHttpClientCreationFailed(string exception) =>
350+
this.WriteEvent(36, exception);
328351
#endif
329352
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpMtlsCertificateManager.cs renamed to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpCertificateManager.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
1111

1212
/// <summary>
13-
/// Manages certificate loading, validation, and security checks for mTLS connections.
13+
/// Manages certificate loading, validation, and security checks for TLS connections.
1414
/// </summary>
15-
internal static class OtlpMtlsCertificateManager
15+
/// <remarks>
16+
/// This class provides functionality for both simple server certificate trust
17+
/// (for self-signed certificates) and mTLS client authentication scenarios.
18+
/// </remarks>
19+
internal static class OtlpCertificateManager
1620
{
1721
internal const string CaCertificateType = "CA certificate";
1822
internal const string ClientCertificateType = "Client certificate";
@@ -21,8 +25,8 @@ internal static class OtlpMtlsCertificateManager
2125
/// <summary>
2226
/// Loads a CA certificate from a PEM file.
2327
/// </summary>
24-
/// <param name="caCertificatePath">Path to the CA certificate file.</param>
25-
/// <returns>The loaded CA certificate.</returns>
28+
/// <param name="caCertificatePath">Path to the certificate file.</param>
29+
/// <returns>The loaded certificate.</returns>
2630
/// <exception cref="FileNotFoundException">Thrown when the certificate file is not found.</exception>
2731
/// <exception cref="InvalidOperationException">Thrown when the certificate cannot be loaded.</exception>
2832
public static X509Certificate2 LoadCaCertificate(string caCertificatePath)
@@ -218,6 +222,10 @@ public static bool ValidateCertificateChain(
218222
/// <param name="sslPolicyErrors">The SSL policy errors.</param>
219223
/// <param name="caCertificate">The CA certificate to validate against.</param>
220224
/// <returns>True if the certificate is valid; otherwise, false.</returns>
225+
/// <remarks>
226+
/// This method is used to validate server certificates against a CA certificate.
227+
/// Common use case: connecting to a server with a self-signed certificate.
228+
/// </remarks>
221229
internal static bool ValidateServerCertificate(
222230
X509Certificate2 serverCert,
223231
X509Chain chain,
@@ -232,7 +240,7 @@ internal static bool ValidateServerCertificate(
232240
return true;
233241
}
234242

235-
// If the only error is an untrusted root, validate against our CA
243+
// If the only error is an untrusted root, validate against our CA certificate
236244
if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors))
237245
{
238246
// Add our CA certificate to the chain
@@ -248,7 +256,7 @@ internal static bool ValidateServerCertificate(
248256

249257
if (isValid)
250258
{
251-
// Verify that the chain terminates with our CA
259+
// Verify that the chain terminates with our CA certificate
252260
var rootCert = chain.ChainElements[^1].Certificate;
253261
if (
254262
string.Equals(

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpMtlsHttpClientFactory.cs

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)