Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 94cf799

Browse files
davidorbelianJonJam
authored andcommitted
Fix issue with X509VerificationFlags.AllowUnknownCertificateAuthority behavior (kubernetes-client#174)
* Fix issue with X509VerificationFlags.AllowUnknownCertificateAuthority behavior * Add CertificateValidationTests
1 parent dc5a15c commit 94cf799

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/KubernetesClient/Kubernetes.ConfigInit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
3+
using System.Linq;
34
using System.Net;
45
using System.Net.Http;
56
using System.Net.Security;
@@ -181,6 +182,10 @@ public static bool CertificateValidationCallBack(
181182
chain.ChainPolicy.ExtraStore.Add(caCert);
182183
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority;
183184
var isValid = chain.Build((X509Certificate2) certificate);
185+
186+
var rootCert = chain.ChainElements[chain.ChainElements.Count - 1].Certificate;
187+
isValid = isValid && rootCert.RawData.SequenceEqual(caCert.RawData);
188+
184189
return isValid;
185190
}
186191

tests/KubernetesClient.Tests/CertificateValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Security.Cryptography.X509Certificates;
55
using Xunit;
66

7-
namespace k8s.Tests
7+
namespace k8s.tests
88
{
99
public class CertificateValidationTests
1010
{

0 commit comments

Comments
 (0)