%3CLINGO-SUB%20id%3D%22lingo-sub-815200%22%20slang%3D%22en-US%22%3EAbout%20HTTPS%2C%20SChannel%2C%20TLS%2C%20CAPI%2C%20SSL%20Certificates%20and%20their%20keys%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-815200%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20you%20want%20your%20site%20to%20be%20available%20over%20secure%20HTTP%20and%20you%20already%20know%20that%20you%20need%20an%20SSL%20certificate.%20Still%2C%20many%20things%20can%20go%20wrong.%20I%E2%80%99m%20not%20going%20to%20document%20a%20specific%20error%3B%20rather%20I%E2%80%99d%20say%20how%20SChannel%2C%20TLS%2C%20keys%20and%20CAPI%20fit%20in%2C%20and%20where%20to%20look%20for%20problems.%3C%2FP%3E%0A%3CP%3EBecause%20we%20set%20the%20HTTPS%20binding%20and%20certificate%20for%20a%20site%20in%20IIS%20Manager%2C%20we%20might%20be%20tempted%20to%20think%20that%20IIS%20is%20managing%20the%20Secure%20Channel%2C%20or%20SChannel%2C%20through%20which%20HTTP%20traffic%20takes%20place.%20But%20that%E2%80%99s%20wrong.%20IIS%20Manager%20is%20going%20to%20configure%20the%20HTTP.SYS%20driver%2C%20specifying%20the%20certificates%20to%20be%20used%20for%20HTTPS%20traffic.%20And%20then%2C%20HTTP.SYS%20is%20going%20to%20take%20care%20of%20the%20TLS%20channel%20for%20HTTPS%20communication.%20Look%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127817i07775575BAFBB8FF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22IIS%20sits%20on%20top%20of%20HTTP.SYS.PNG%22%20title%3D%22IIS%20sits%20on%20top%20of%20HTTP.SYS.PNG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EIIS%20sits%20on%20top%20of%20HTTP.SYS%2C%20which%20in%20turn%20relies%20on%20SChannel%20provider%20for%20HTTPS%20communication%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20any%20HTTPS%20traffic%20can%20happen%2C%20a%20TLS%20SChannel%20has%20to%20be%20established.%20Then%2C%20through%20that%20channel%2C%20normal%20HTTP%20requests%20and%20responses%20would%20travel.%20The%20secure%20channel%20is%20initiated%20by%20HTTP.SYS%2C%20which%20sits%20below%20IIS.%20If%20the%20SChannel%20fails%2C%20then%20requests%20don%E2%80%99t%20reach%20to%20IIS%2C%20they%20will%20not%20show%20up%20in%20IIS%20logs.%20With%20SChannel%20failures%2C%20HTTPS%20requests%20don%E2%80%99t%20even%20make%20it%20to%20HTTP.SYS.%20Why%3F%C2%AD%3C%2FP%3E%0A%3CP%3EThe%20HTTP.SYS%20driver%20is%20going%20to%20call%20the%20SChannel%20provider%20to%20create%20the%20secure%20tunnel.%20SChannel%20will%20use%20the%20CAPI%2C%20the%20Cryptographic%20API%20of%20Windows.%20The%20certificate%E2%80%99s%20public%20and%20%3CSTRONG%3Eprivate%3C%2FSTRONG%3Ekeys%20are%20going%20to%20be%20used%20by%20CAPI2.%20Notice%20my%20highlight%3A%20the%20private%20key%20of%20the%20certificate%20is%20needed%20for%20the%20SChannel.%20If%20that%20private%20key%20is%20missing%20or%20inaccessible%20due%20to%20ACL%20(Access%20Control%20List)%2C%20then%20%E2%80%9Cgame%20over%E2%80%9D%20%E2%80%93%20no%20tunnel%20can%20be%20created%2C%20HTTPS%20traffic%20would%20fail.%20And%20there%20are%20other%20reasons%20too%20for%20which%20the%20certificate%20may%20be%20rejected%20by%20the%20SChannel%20provider%3B%20see%20later%20in%20this%20article.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_1%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20405px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127820iB3A87F5DEE667C28%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Certificate%20-%20private%20key.png%22%20title%3D%22Certificate%20-%20private%20key.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EA%20certificate%20that%20is%20paired%20with%20its%20private%20key%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20SChannel%20provider%20is%20logging%20into%20the%20Windows%20Events%20%E2%80%93%20look%20inside%20the%20System%20log%20with%20the%20Event%20Viewer%2C%20looking%20for%20source%20SChannel.%20Here%20are%20some%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fwindows%2Fit-pro%2Fwindows-server-2012-R2-and-2012%2Fdn786445(v%3Dws.11)%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ecommon%20SChannel%20events%3C%2FA%3Eand%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fkaushal%2F2012%2F10%2F05%2Fssltls-alert-protocol-the-alert-codes%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ESSL%2FTLS%20protocol%20alerts%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EThe%20logging%20of%20the%20Crypto%20API%20is%20not%20turned%20on%20by%20default.%20If%20you%20want%20to%20troubleshoot%2C%20you%E2%80%99ll%20need%20to%20%3CA%20href%3D%22https%3A%2F%2Fbenperk.github.io%2Fmsdn%2F2013%2F2013-09-enable-capi2-event-logging-to-troubleshoot-pki-and-ssl-certificate-issues.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eturn%20on%20the%20CAPI2%20logging%20in%20the%20Windows%20Events%20Viewer%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22TLS%22%20target%3D%22_blank%22%20name%3D%22TLS%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1817430740%22%20id%3D%22toc-hId-1817430740%22%3EThe%20TLS%20handshake%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20see%20the%20steps%20of%20the%20TLS%20negotiation%2C%20how%20the%20secure%20channel%20is%20being%20established%20between%20the%20client%20and%20the%20server%20before%20any%20HTTPS%20traffic%20can%20happen.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ETCP%20handshake%3C%2FSTRONG%3Eis%20performed%20between%20client%20and%20server%2C%20then...%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EClient%20Hello%3C%2FSTRONG%3E%3A%20The%20client%20sends%20to%20server%20the%20versions%20of%20TLS%20protocol%20supported%2C%20as%20well%20as%20the%20suite%20of%20ciphers%20(encryption%2Fdecryption%20algorithms%20it%20supports%20for%20key%20exchange%2C%20data%20encryption%20and%20handshake%20security)%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EServer%20Hello%3C%2FSTRONG%3E%3A%20After%20the%20server%20compares%20what%20the%20client%20sends%20with%20its%20own%20supported%20TLS%20versions%20and%20ciphers%2C%20the%20server%20decides%20which%20ones%20will%20be%20used%20and%20sends%20the%20selection%20to%20the%20client.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EServer%20certificate%3C%2FSTRONG%3E%3A%20The%20server%20has%20to%20authenticate%20itself%20to%20the%20client%2C%20so%20it%20sends%20its%20certificate.%20The%20keys%20will%20be%20used%20for%20encryption.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EClient%20switches%20to%20encrypted%3C%2FSTRONG%3E%3B%20all%20following%20messages%20from%20client%20will%20be%20encrypted%20from%20this%20point.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EServer%20switches%20to%20encrypted%3C%2FSTRONG%3E%2C%20too.%20From%20this%20point%2C%20normal%20HTTP%20requests%20and%20response%20can%20travel%20via%20the%20encrypted%20channel.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIn%20fact%2C%20the%20TLS%20handshake%20is%20a%20bit%20more%20complicated%2C%20so%20I%20recommend%20the%20Pluralsight%20training%20%3CA%20href%3D%22https%3A%2F%2Fapp.pluralsight.com%2Flibrary%2Fcourses%2Fwireshark-troubleshooting-analyzing-decrypting-tls-traffic%2Ftable-of-contents%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAnalyzing%20and%20Decrypting%20TLS%20Traffic%3C%2FA%3Efor%20details.%20But%20the%20above%20steps%20are%20enough%20to%20illustrate%20what%20could%20go%20wrong%20and%20where%20to%20look%20for%20problems.%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22TCP%22%20target%3D%22_blank%22%20name%3D%22TCP%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--734726221%22%20id%3D%22toc-hId--734726221%22%3ETCP%20handshake%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECondition%3A%20The%20client%20(browser)%20has%20to%20be%20able%20to%20resolve%20the%20name%20of%20a%20site%20(the%20hostname)%20to%20an%20IP%20address.%20For%20that%2C%20needed%20DNS%20records%20must%20be%20in%20place.%20Do%20you%20have%20a%20DNS%20A%20or%20CNAME%20record%20in%20place%3F%20Can%20the%20IP%20address%20of%20the%20hosting%20environment%20be%20determined%20for%20the%20site%2Fhost%20name%20specified%20in%20the%20browser%E2%80%99s%20address%20bar%3F%20You%20can%20check%20with%20%3CEM%3Enslookup%3C%2FEM%3Ecommand-line%20tool%3A%3C%2FP%3E%0A%3CPRE%3EC%3A%26gt%3B%20nslookup%20duckduckgo.com%3C%2FPRE%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20440px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127815i83861C91EF1F5BB9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22nslookup%20duckduckgo.com.png%22%20title%3D%22nslookup%20duckduckgo.com.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EChecking%20name%20resolution%20to%20IP%20addresses%20with%20nslookup%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22Hello%22%20target%3D%22_blank%22%20name%3D%22Hello%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1008084114%22%20id%3D%22toc-hId-1008084114%22%3EClient%20Hello%20and%20Server%20Hello%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20client%20is%20sending%20to%20the%20server%20its%20supported%20TLS%20versions%20and%20cipher%20suites.%20The%20server%20compares%20the%20list%20with%20its%20own%20%E2%80%9Crecords%E2%80%9D.%20If%20the%20server%20does%20not%20support%20any%20of%20the%20TLS%20versions%20specified%20by%20client%3A%20fail.%20If%20or%20none%20of%20server's%20cipher%20suites%20matches%20one%20from%20the%20client%E2%80%99s%20list%2C%20boom!%20Look%20into%20Windows%20Events%2C%20in%20the%20System%20log%2C%20for%20entries%20sourced%20SChannel.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_3%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20895px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127818i2A9A3142E1593499%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22TLS%20negotiation%20in%20Wireshark.png%22%20title%3D%22TLS%20negotiation%20in%20Wireshark.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EA%20network%20trace%20capturing%20TLS%20negotiation%2C%20Client%20Hello%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20suspect%20problems%20with%20the%20encryption%2C%20then%20that%E2%80%99s%20the%20domain%20of%20CAPI2%20-%20Cryptographic%20API%20logging%20must%20be%20enabled%2C%20then%20events%20must%20be%20studied.%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22Certificate%22%20target%3D%22_blank%22%20name%3D%22Certificate%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1544072847%22%20id%3D%22toc-hId--1544072847%22%3EServer%20Certificate%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20server%20authenticates%20first%3B%20then%2C%20optionally%2C%20the%20client.%20But%20before%20the%20server%20sends%20its%20certificate%2C%20that%20must%20be%20usable.%20The%20SChannel%20provider%20performs%20some%20validation%20on%20the%20certificate%2C%20before%20using%20it.%3C%2FP%3E%0A%3CP%3EThe%20private%20key%20of%20the%20certificate%20must%20be%20present%20on%20the%20server%20and%20accessible%20to%20SChannel%20provider.%20There%20is%20common%20misconception%20that%20the%20private%20key%20of%20a%20certificate%20stays%20within%20the%20certificate.%20That%E2%80%99s%20wrong%3B%20the%20private%20key%20belongs%20to%20a%20certificate%2C%20but%20it%20is%20stored%20separately.%20Certificates%20are%20held%20in%20Registry%2C%20while%20their%20private%20keys%20have%20various%20repositories%2C%20depending%20on%20where%20the%20certificate%20is%20found%20in%20the%20Certificate%20Manager%3A%20read%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fseccng%2Fkey-storage-and-retrieval%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ekey%20storage%20and%20retrieval%3C%2FA%3Eand%20%3CA%20href%3D%22https%3A%2F%2Fredcircle.blog%2F2010%2F09%2F13%2Fpublic-key-certificate-locations-in-windows%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecertificate%20locations%20in%20Windows%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EThe%20issuing%20authority%20of%20the%20certificate%20must%20be%20trusted%20by%20the%20server.%20The%20certificate%20of%20the%20issuing%20authority%20must%20be%20present%20in%20the%20Computer%E2%80%99s%20Trusted%20Root%20Certification%20Authorities.%20If%20there%20are%20intermediate%20certification%20authorities%2C%20their%20certificates%20must%20be%20present%20in%20the%20Computer%E2%80%99s%20Intermediate%20Certification%20Authorities.%20The%20certificate%20chain%20must%20be%20trusted.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127822i7FE9A47BD36CD8BF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Certificate%20-%20trust%20chain.png%22%20title%3D%22Certificate%20-%20trust%20chain.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EBoth%20client%20and%20server%20should%20trust%20the%20certification%20chain.%20Issuing%20root%20and%20intermediate%20certification%20autorities%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20certificate%20must%20not%20be%20revoked.%20And%20its%20Key%20Usage%20flags%20must%20allow%20for%20Digital%20Signature%20and%20Key%20Encipherment.%20Working%20with%20SSL%20certificates%20using%20IIS%20Manager%20helps%20avoid%20many%20of%20the%20pitfalls%20commonly%20seen%20when%20setting%20up%20HTTPS.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20405px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127819i5828B9FCD1F76B4C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Certificate%20-%20key%20usage%20flags.png%22%20title%3D%22Certificate%20-%20key%20usage%20flags.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EKey%20usage%20flags%20needed%20for%20HTTPS%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22Encrypted%22%20target%3D%22_blank%22%20name%3D%22Encrypted%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-198737488%22%20id%3D%22toc-hId-198737488%22%3EEncrypted%20communication%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFinally%2C%20before%20the%20communication%20is%20being%20switched%20to%20encrypted%20%E2%80%93%20Change%20Cipher%20Spec%20%E2%80%93%20the%20client%20has%20to%20accept%20the%20server%E2%80%99s%20certificate.%20Some%20browsers%2C%20like%20Internet%20Explorer%2C%20would%20display%20warnings%20for%20sites%20presenting%20improper%20certificates%20-%20but%20would%20still%20allow%20you%20to%20navigate%3B%20after%20all%2C%20technically%20the%20encryption%20of%20the%20tunnel%20can%20still%20happen.%20But%20other%20browsers%20or%20other%20client%20applications%20might%20be%20more%E2%80%A6%20stubborn%2C%20should%20I%20say%3F%20They%20would%20not%20allow%20continuing%20navigation%20or%20sending%20requests%20if%20the%20certificate%20is%20%E2%80%9Csmelly%E2%80%9D.%3C%2FP%3E%0A%3CP%3EIf%20the%20certificate%20is%20expired%2C%20not%20valid%20anymore%3A%20reject.%20If%20it%20was%20revoked%20by%20its%20issuing%20authority%3A%20reject.%20If%20the%20site%2Fserver%2Fhost%20name%20of%20the%20URL%20does%20not%20accommodate%20the%20certificate%E2%80%99s%20subject%20(%3CEM%3Eissued%20to%3C%2FEM%3Efield)%3A%20reject.%20If%20the%20client%20does%20not%20trust%20the%20issuing%20authority%20of%20a%20certificate%3A%20reject%20(on%20Windows%2C%20the%20certificate%20of%20the%20issuing%20authority%20must%20be%20present%20in%20the%20Computer%E2%80%99s%20Trusted%20Root%20Certification%20Authorities%20%2F%20Intermediate%20Certification%20Authorities).%3C%2FP%3E%0A%3CP%3EIn%20all%20these%20cases%2C%20the%20encryption%20of%20the%20secure%20channel%20would%20work%2C%20technically%3B%20but%20the%20clients%2Fbrowsers%20simply%20don%E2%80%99t%20like%20the%20certificate%20presented%20by%20the%20server%20-%20the%20server%20is%20not%20authenticated.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20405px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127821iFE539480F7843EB1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Certificate%20-%20validation%20by%20client.png%22%20title%3D%22Certificate%20-%20validation%20by%20client.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EWhen%20a%20client%20checks%20a%20certificate.%20It%20also%20checks%20for%20revocation.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EOn%20a%20side%20note%2C%20only%20the%20key%20exchange%20relies%20on%20the%20computationally%20expensive%20asymmetric%20encryption%2C%20during%20the%20TLS%20handshake%20(let%E2%80%99s%20say%20with%20the%20certificate%E2%80%99s%20public%20and%20private%20key).%20Once%20the%20client%20and%20the%20server%20have%20established%20the%20secure%20channel%2C%20the%20data%20exchange%20will%20rely%20on%20symmetric%20encryption.%20This%20is%20why%20the%20certificate%E2%80%99s%20Key%20Usage%20flag%20must%20include%20Key%20Encipherment%20%E2%80%93%20it%E2%80%99s%20for%20the%20key%20exchange.%3C%2FP%3E%0A%3CP%3E%3CA%20id%3D%22Handling%22%20target%3D%22_blank%22%20name%3D%22Handling%22%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1941547823%22%20id%3D%22toc-hId-1941547823%22%3EHandling%20certificates%20and%20their%20private%20keys%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20keep%20saying%20about%20certificate%20private%20keys%20because%20their%20absence%20is%20one%20of%20the%20most%20common%20issues.%20Failing%20to%20have%20the%20private%20key%20of%20a%20certificate%20leads%20to%20frustration%3A%20IIS%20Manager%20would%20not%20even%20bother%20to%20display%20a%20server%20certificate%20if%20its%20private%20key%20is%20not%20present.%20So%2C%20in%20the%20HTTPS%20binding%2C%20one%20cannot%20pick%20a%20certificate%20if%20its%20private%20key%20is%20missing.%20Further%20on%2C%20if%20the%20private%20key%20is%20accidentally%20deleted%2C%20corrupted%20or%20becomes%20inaccessible%20due%20to%20rights%2C%20SChannel%20issues%20immediately%20appear.%20Same%20happens%20if%20the%20certificate%20chain%20is%20not%20trusted%20(somehow%20the%20certificate%20of%20the%20issuing%20authority%20is%20missing%20from%20trusted%2C%20or%20that%20certificate%20is%20expired).%3C%2FP%3E%0A%3CP%3ESo%20how%20do%20we%20handle%20this%20private%20key%3F%3C%2FP%3E%0A%3CP%3EThe%20%E2%80%9Cbirth%E2%80%9D%20of%20a%20certificate%20starts%20with%20a%20Certificate%20Request%2C%20a%20CSR.%20One%20creates%20a%20CSR%2C%20then%20a%20certification%20authority%20(CA)%20approves%20it%20and%20generates%20a%20certificate%20file.%3C%2FP%3E%0A%3CP%3EWhen%20creating%20CSR%2C%20a%20key%20pair%20is%20generated%3A%20public%20and%20private%20key.%20The%20public%20key%20is%2C%20well%2C%20public%2C%20anyone%20could%20see%20it.%20But%20the%20private%20key%20remains%20securely%20stored%20on%20the%20machine%20where%20the%20CSR%20was%20generated.%3C%2FP%3E%0A%3CP%3EOnce%20the%20CA%20issues%20the%20certificate%2C%20we%20could%20install%20that%20certificate%20on%20a%20different%20machine.%20But%20wait%2C%20where%20is%20the%20private%20key%3F%20Oh%2C%20the%20certificate%20must%20be%20paired%20with%20its%20private%20key%20on%20the%20machine%20where%20the%20CSR%20was%20created.%20Once%20this%20pairing%20is%20done%2C%20both%20certificate%20and%20its%20private%20key%20can%20be%20exported%20in%20a%20PFX%20container.%20The%20PFX%20file%20may%20contain%20the%20certificate%2C%20its%20private%20key%2C%20and%20all%20the%20trust%20chain%20%E2%80%93%20certificate%20of%20the%20root%20authority%20and%20any%20intermediate%20authorities.%20Then%20the%20PFX%20can%20be%20imported%20on%20other%20machines%20if%20needed.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20535px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F127816i812E2EA30175A679%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Export%20private%20key.png%22%20title%3D%22Export%20private%20key.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EA%20certificate%20needs%20its%20private%20key%20to%20be%20usable%20for%20HTTPS%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20recommend%20using%20IIS%20Manager%20only%20for%20creating%20certificates%20to%20be%20used%20for%20sites%20and%20web%20applications.%20IIS%20Manager%20ensures%20that%20the%20private%20key%20is%20exportable%20once%20the%20certificate%20was%20paired%20with%20it%20and%20it%20sets%20the%20proper%20key%20usage%20flags.%20It%20also%20ensures%20that%20the%20certificate%20is%20placed%20in%20the%20proper%20repository%20%E2%80%93%20Computer%E2%80%99s%20certificates.%20When%20exporting%20a%20certificate%20from%20IIS%20Manager%2C%20the%20entire%20trust%20chain%20of%20certificates%20is%20included%20in%20the%20PFX%20too.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-815200%22%20slang%3D%22en-US%22%3E%3CP%3EBefore%20a%20browser%20or%20client%20can%20send%20an%20HTTPS%20request%2C%20a%20secure%20channel%20must%20be%20established%20with%20the%20server.%20If%20that%20fails%2C%20the%20request%20does%20not%20reach%20to%20IIS.%20Here%20are%20some%20considerations%20on%20involved%20components%2C%20what%20might%20go%20wrong%2C%20and%20where%20to%20look%20during%20an%20investigation.%3C%2FP%3E%3C%2FLINGO-TEASER%3E

So you want your site to be available over secure HTTP and you already know that you need an SSL certificate. Still, many things can go wrong. I’m not going to document a specific error; rather I’d say how SChannel, TLS, keys and CAPI fit in, and where to look for problems.

Because we set the HTTPS binding and certificate for a site in IIS Manager, we might be tempted to think that IIS is managing the Secure Channel, or SChannel, through which HTTP traffic takes place. But that’s wrong. IIS Manager is going to configure the HTTP.SYS driver, specifying the certificates to be used for HTTPS traffic. And then, HTTP.SYS is going to take care of the TLS channel for HTTPS communication. Look:

 

IIS sits on top of HTTP.SYS, which in turn relies on SChannel provider for HTTPS communicationIIS sits on top of HTTP.SYS, which in turn relies on SChannel provider for HTTPS communication

 

Before any HTTPS traffic can happen, a TLS SChannel has to be established. Then, through that channel, normal HTTP requests and responses would travel. The secure channel is initiated by HTTP.SYS, which sits below IIS. If the SChannel fails, then requests don’t reach to IIS, they will not show up in IIS logs. With SChannel failures, HTTPS requests don’t even make it to HTTP.SYS. Why?­

The HTTP.SYS driver is going to call the SChannel provider to create the secure tunnel. SChannel will use the CAPI, the Cryptographic API of Windows. The certificate’s public and private keys are going to be used by CAPI2. Notice my highlight: the private key of the certificate is needed for the SChannel. If that private key is missing or inaccessible due to ACL (Access Control List), then “game over” – no tunnel can be created, HTTPS traffic would fail. And there are other reasons too for which the certificate may be rejected by the SChannel provider; see later in this article.

 

A certificate that is paired with its private keyA certificate that is paired with its private key

 

The SChannel provider is logging into the Windows Events – look inside the System log with the Event Viewer, looking for source SChannel. Here are some common SChannel events and SSL/TLS protocol alerts.

The logging of the Crypto API is not turned on by default. If you want to troubleshoot, you’ll need to turn on the CAPI2 logging in the Windows Events Viewer.

 

 

 

The TLS handshake

 

Let’s see the steps of the TLS negotiation, how the secure channel is being established between the client and the server before any HTTPS traffic can happen.

  1. TCP handshake is performed between client and server, then...
  2. Client Hello: The client sends to server the versions of TLS protocol supported, as well as the suite of ciphers (encryption/decryption algorithms it supports for key exchange, data encryption and handshake security);
  3. Server Hello: After the server compares what the client sends with its own supported TLS versions and ciphers, the server decides which ones will be used and sends the selection to the client.
  4. Server certificate: The server has to authenticate itself to the client, so it sends its certificate. The keys will be used for encryption.
  5. Client switches to encrypted; all following messages from client will be encrypted from this point.
  6. Server switches to encrypted, too. From this point, normal HTTP requests and response can travel via the encrypted channel.

In fact, the TLS handshake is a bit more complicated, so I recommend the Pluralsight training Analyzing and Decrypting TLS Traffic for details. But the above steps are enough to illustrate what could go wrong and where to look for problems.

 

 

 

TCP handshake

 

Condition: The client (browser) has to be able to resolve the name of a site (the hostname) to an IP address. For that, needed DNS records must be in place. Do you have a DNS A or CNAME record in place? Can the IP address of the hosting environment be determined for the site/host name specified in the browser’s address bar? You can check with nslookup command-line tool:

C:> nslookup duckduckgo.com
 

Checking name resolution to IP addresses with nslookupChecking name resolution to IP addresses with nslookup

 

 

 

Client Hello and Server Hello

 

The client is sending to the server its supported TLS versions and cipher suites. The server compares the list with its own “records”. If the server does not support any of the TLS versions specified by client: fail. If or none of server's cipher suites matches one from the client’s list, boom! Look into Windows Events, in the System log, for entries sourced SChannel.

 

A network trace capturing TLS negotiation, Client HelloA network trace capturing TLS negotiation, Client Hello

If you suspect problems with the encryption, then that’s the domain of CAPI2 - Cryptographic API logging must be enabled, then events must be studied.

 

 

 

Server Certificate

 

The server authenticates first; then, optionally, the client. But before the server sends its certificate, that must be usable. The SChannel provider performs some validation on the certificate, before using it.

The private key of the certificate must be present on the server and accessible to SChannel provider. There is common misconception that the private key of a certificate stays within the certificate. That’s wrong; the private key belongs to a certificate, but it is stored separately. Certificates are held in Registry, while their private keys have various repositories, depending on where the certificate is found in the Certificate Manager: read key storage and retrieval and certificate locations in Windows.

The issuing authority of the certificate must be trusted by the server. The certificate of the issuing authority must be present in the Computer’s Trusted Root Certification Authorities. If there are intermediate certification authorities, their certificates must be present in the Computer’s Intermediate Certification Authorities. The certificate chain must be trusted.
 

Both client and server should trust the certification chain. Issuing root and intermediate certification autoritiesBoth client and server should trust the certification chain. Issuing root and intermediate certification autorities

The certificate must not be revoked. And its Key Usage flags must allow for Digital Signature and Key Encipherment. Working with SSL certificates using IIS Manager helps avoid many of the pitfalls commonly seen when setting up HTTPS.
 

Key usage flags needed for HTTPSKey usage flags needed for HTTPS

 

 

 

Encrypted communication

 

Finally, before the communication is being switched to encrypted – Change Cipher Spec – the client has to accept the server’s certificate. Some browsers, like Internet Explorer, would display warnings for sites presenting improper certificates - but would still allow you to navigate; after all, technically the encryption of the tunnel can still happen. But other browsers or other client applications might be more… stubborn, should I say? They would not allow continuing navigation or sending requests if the certificate is “smelly”.

If the certificate is expired, not valid anymore: reject. If it was revoked by its issuing authority: reject. If the site/server/host name of the URL does not accommodate the certificate’s subject (issued to field): reject. If the client does not trust the issuing authority of a certificate: reject (on Windows, the certificate of the issuing authority must be present in the Computer’s Trusted Root Certification Authorities / Intermediate Certification Authorities).

In all these cases, the encryption of the secure channel would work, technically; but the clients/browsers simply don’t like the certificate presented by the server - the server is not authenticated.
 

When a client checks a certificate. It also checks for revocation.When a client checks a certificate. It also checks for revocation.

On a side note, only the key exchange relies on the computationally expensive asymmetric encryption, during the TLS handshake (let’s say with the certificate’s public and private key). Once the client and the server have established the secure channel, the data exchange will rely on symmetric encryption. This is why the certificate’s Key Usage flag must include Key Encipherment – it’s for the key exchange.

 

 

 

Handling certificates and their private keys

 

I keep saying about certificate private keys because their absence is one of the most common issues. Failing to have the private key of a certificate leads to frustration: IIS Manager would not even bother to display a server certificate if its private key is not present. So, in the HTTPS binding, one cannot pick a certificate if its private key is missing. Further on, if the private key is accidentally deleted, corrupted or becomes inaccessible due to rights, SChannel issues immediately appear. Same happens if the certificate chain is not trusted (somehow the certificate of the issuing authority is missing from trusted, or that certificate is expired).

So how do we handle this private key?

The “birth” of a certificate starts with a Certificate Request, a CSR. One creates a CSR, then a certification authority (CA) approves it and generates a certificate file.

When creating CSR, a key pair is generated: public and private key. The public key is, well, public, anyone could see it. But the private key remains securely stored on the machine where the CSR was generated.

Once the CA issues the certificate, we could install that certificate on a different machine. But wait, where is the private key? Oh, the certificate must be paired with its private key on the machine where the CSR was created. Once this pairing is done, both certificate and its private key can be exported in a PFX container. The PFX file may contain the certificate, its private key, and all the trust chain – certificate of the root authority and any intermediate authorities. Then the PFX can be imported on other machines if needed.
 

A certificate needs its private key to be usable for HTTPSA certificate needs its private key to be usable for HTTPS

 

I recommend using IIS Manager only for creating certificates to be used for sites and web applications. IIS Manager ensures that the private key is exportable once the certificate was paired with it and it sets the proper key usage flags. It also ensures that the certificate is placed in the proper repository – Computer’s certificates. When exporting a certificate from IIS Manager, the entire trust chain of certificates is included in the PFX too.