-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis Cloud Connection Example #98
Conversation
Codecov ReportPatch and project coverage have no change.
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #98 +/- ##
=======================================
Coverage 93.27% 93.27%
=======================================
Files 77 77
Lines 4582 4582
Branches 424 424
=======================================
Hits 4274 4274
Misses 186 186
Partials 122 122 ☔ View full report in Codecov by Sentry. |
@shacharPash - this will still break until the .pem/.crt/.key file are all deployed along side the binary (you might need to do a cURL to the appropriate spots the test runner executes from In a real-world scenario you would NOT be building your own certificate chain in your program, rather certificates would be managed by the admin responsible for overseeing the machine and either installed with GPO on windows, your keychain on mac, or pick your flavor of cert-store on Linux. There are several steps here:
var redisUserCertificate = new X509Certificate2(File.ReadAllBytes(redisUserCrtPath));
var redisUserPrivateKeyText = File.ReadAllText(redisUserPrivateKeyPath);
var pemFileData = File.ReadAllLines(redisUserPrivateKeyPath).Where(x => !x.StartsWith("-"));
var binaryEncoding = Convert.FromBase64String(string.Join(null, pemFileData));
rsa.ImportRSAPrivateKey(binaryEncoding, out _);
redisUserCertificate.CopyWithPrivateKey(rsa);
rsa.ImportFromPem(redisUserPrivateKeyText.ToCharArray());
var clientCert = redisUserCertificate.CopyWithPrivateKey(rsa);
var redisCaCertificate = new X509Certificate2(File.ReadAllBytes(redisCaPath));
(_, cert, _, errors) =>
{
if (errors == SslPolicyErrors.None)
{
return true;
}
var privateChain = new X509Chain();
privateChain.ChainPolicy = new X509ChainPolicy { RevocationMode = X509RevocationMode.NoCheck };
X509Certificate2 cert2 = new X509Certificate2(cert!);
privateChain.ChainPolicy.ExtraStore.Add(redisCaCertificate);
privateChain.Build(cert2);
bool isValid = true;
// we're establishing the trust chain so if the only complaint is that that the root CA is untrusted, and the root CA root
// matches our certificate, we know it's ok
foreach (X509ChainStatus chainStatus in privateChain.ChainStatus.Where(x=>x.Status != X509ChainStatusFlags.UntrustedRoot))
{
if (chainStatus.Status != X509ChainStatusFlags.NoError)
{
isValid = false;
break;
}
}
return isValid;
} The logic is equivalent regardless of which method you use, you just use slightly different components of the configuration. |
Btw @chayim - is the instance we're pointing to here shared for doing TLS validation across the other peer clients? From what I can tell they are all just using a specially spun up TLS enabled version for Redis? |
f450a89
to
e646964
Compare
Fixed the .NET Framework examples. Pre .NET Core 3.1 this was a very manual process where you had to interact with openSSL almost directly via bouncy-castle. It looks like a later version of Bouncy Castle might have changed the types it was bubbling back up from when the now very old examples you'd find online were created. After making those couple of adjustments, and re-exporting the cert each time, and trimming the key (it was getting pulled in with an extra newline or whitespace or something - this all works now. |
…tack into Issue96/TlsExample
Closes #96