Mutual SSL Handshake .NET, SSL Client Authentication
Few days back I was working on this Mutual SSL Handshake Issue. I was stuck on this for quite sometime. Lack of information and very limited number people actually using this, caused me to work for lot of hours, which was supposed to be a very tiny piece of work.
I was supposed to talk to a webserver from my webserver (IIS 7.5) using the SSL certificate client authentication.
Because of limited information out there I figured few things on my own and thought of creating this blog about it so that people who are working on this can get some benefit out of it.
Once the certificate part is done use the following code to perform the Client authentication in code. HttpWebRequest will take care of everything else. Please feel free to comment.
I was supposed to talk to a webserver from my webserver (IIS 7.5) using the SSL certificate client authentication.
Because of limited information out there I figured few things on my own and thought of creating this blog about it so that people who are working on this can get some benefit out of it.
- Client certificate should have following Key Usages. Digital Certificate, Key Encipherment and extended usage of Client Authentication.
- The private key should be exportable and not protected.
- The root signers of your certificate should be on the target webserver’s trust store.
- Server certificate’s root signers should be on your server’s trust store.
- You don’t need to import your certificate to your certificate store. Instead I recommend to use the .PFX file instead. Because your IIS server’s users don’t have enough permission to read the private key of your certificate. Whereas by using the PFX file we don’t need any permission whatsoever. PFX file contains all the certificates Root, Intermediate, Shared and Client Certificate.
Once the certificate part is done use the following code to perform the Client authentication in code. HttpWebRequest will take care of everything else. Please feel free to comment.
private static void FromFile() { var certificate = "CertificateFile.pfx"; var certpwd = "password"; var URL = "Host_URL"; var certs = new X509Certificate2Collection(); certs.Import(certificate, certpwd, X509KeyStorageFlags.DefaultKeySet); var webrequest = WebRequest.Create(URL) as HttpWebRequest; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; ServicePointManager.Expect100Continue = false; ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCert); webrequest.ClientCertificates.Add(certs[3]); webrequest.Credentials = CredentialCache.DefaultNetworkCredentials; webrequest.Method = WebRequestMethods.Http.Get; webrequest.ContentType = "application/json; charset=utf-8"; var responseStream = webrequest.GetResponse().GetResponseStream(); } private static bool AlwaysGoodCert(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors) { return true; }
Thanks for writing this. It works for me too. :)
ReplyDeleteKarayolu yurtdışı kargo
ReplyDeleteDenizyolu yurtdışı kargo
Havayolu yurtdışı kargo
Demiryolu yurtdışı kargo
Avusturya yurtdışı kargo
1ZU
Antalya
ReplyDeleteKonya
Adana
Ankara
Van
CSN2YV
ankara
ReplyDeletesakarya
tekirdağ
kastamonu
amasya
AJ2QHT
9F190
ReplyDeleteAnkara Boya Ustası
Eryaman Alkollü Mekanlar
Sakarya Şehir İçi Nakliyat
Diyarbakır Evden Eve Nakliyat
Ağrı Evden Eve Nakliyat
Antep Şehirler Arası Nakliyat
Tokat Parça Eşya Taşıma
Kırklareli Şehirler Arası Nakliyat
Etlik Fayans Ustası
D2D58
ReplyDeleteMuğla Şehir İçi Nakliyat
Ağrı Parça Eşya Taşıma
Etlik Boya Ustası
Antep Evden Eve Nakliyat
AAX Güvenilir mi
Sivas Şehirler Arası Nakliyat
Batman Şehirler Arası Nakliyat
Konya Şehir İçi Nakliyat
Adana Evden Eve Nakliyat
978FC
ReplyDeleteTwitch İzlenme Hilesi
Qlc Coin Hangi Borsada
Twitch İzlenme Satın Al
Bitcoin Kazanma
Bonk Coin Hangi Borsada
Chat Gpt Coin Hangi Borsada
Kripto Para Madenciliği Nasıl Yapılır
Bitcoin Kazanma
Caw Coin Hangi Borsada
FBDE8
ReplyDeleteeigenlayer
pancakeswap
thorchain
bscpad
shapeshift
quickswap
uwulend finance
avalaunch
dexscreener
44E31
ReplyDelete----
----
----
----
----
----
matadorbet
----
----
53CCA
ReplyDeletecanlı şov
2E46E
ReplyDeletegüvenilir ücretli show
92B36
ReplyDeletegörüntülü ücretli show
D756D
ReplyDeletegörüntülü şov whatsapp numarası
45516
ReplyDeletewhatsapp görüntülü show güvenilir
589AFA592A
ReplyDeleteereksiyon hapı
novagra
skype show
sildegra
görüntülü show
canli cam show
skype şov
sertleştirici
degra
577C68D242
ReplyDeleteyapay kızlık zarı
telegram show
green temptation
vigrande
themra macun
lifta
bayan azdırıcı damla
whatsapp görüntülü şov
görüntülü şov whatsapp numarası
2FB8E80C73
ReplyDeleteyoutube türk beğeni satın al