{"id":2083,"date":"2006-08-18T17:13:00","date_gmt":"2006-08-18T17:13:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2006\/08\/18\/digital-signatures-in-windows-installer\/"},"modified":"2006-08-18T17:13:00","modified_gmt":"2006-08-18T17:13:00","slug":"digital-signatures-in-windows-installer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/digital-signatures-in-windows-installer\/","title":{"rendered":"Digital Signatures in Windows Installer"},"content":{"rendered":"<p>Digitally signing files helps protect against changes to a file (or any data, really) by validating that a hash of the current file matches the hash stored in the digital signature. Digital signatures also help verify that a package came from a particular publisher by encrypting the hash with the publisher&#8217;s private key. Verifying the signature using the publisher&#8217;s public key or a trusted certificate authority that signed their public key validates the publisher.<\/p>\n<p>You can <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/msi\/setup\/digital_signatures_and_windows_installer.asp\">sign Windows Installer packages<\/a>, such as <em>.msi<\/em> and <em>.msp<\/em> files, to help guarantee that users know if your files have been modified and that they came from you, the publisher. Windows Installer validates that a package hasn&#8217;t been changed if it contains a digital signature when attempting to install it. It does this by calling the <code><\/code><a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/seccrypto\/security\/winverifytrust.asp\"><code>WinVerifyTrust<\/code> function<\/a> both directly and indirectly. Signing a patch can also enable privileged installs for non-privileged users. This was called LUA patching and is now known as <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/msi\/setup\/user_account_control__uac__patching.asp\">UAC patching<\/a>.<\/p>\n<p>But how does Windows Installer know if a package is signed? Many different file types can be signed, including <em>.exe<\/em> and <em>.dll<\/em>, <em>.cab<\/em>, <em>.msi<\/em> and <em>.msp<\/em>, and more. The basic file types all store digital signatures differently. PE\/COFF executables store signatures in the virtual certificates directory in the optional headers. Signatures fill reserved space within a cabinet file. With a simple <a href=\"http:\/\/hstewart.members.winisp.net\/downloads\/msix2.zip\">modification<\/a> to my <a href=\"http:\/\/blogs.msdn.com\/heaths\/archive\/2006\/04\/07\/571138.aspx\">patch files extractor<\/a>, you can see both a _SummaryInformation stream and &#8211; in signed files &#8211; a _DigitalSignature stream. (The tool actually changes the character 05 to an underscore for readability, so the digital signature stream is actually named 05DigitalSignature.)<\/p>\n<p>So how does <code>WinVerifyTrust<\/code> determine how to find the signature? <a href=\"http:\/\/www.sysinternals.com\/utilities\/regmon.html\">Download<\/a> and run <em>regmon.exe<\/em> from Sysinternals and run the following command from within a Platform SDK (now Windows SDK) command shell:<\/p>\n<p><font face=\"monospace\">signtool verify \/pa &lt;signed.msp&gt;<\/font><\/p>\n<p>You&#8217;ll noticed a lot of requests to registry keys under <em>HKEY_LOCAL_MACHINESoftwareMicrosoftCryptographyOIDEncodingType 0<\/em>, including the sub-key <em>CryptSIPDllIsMyFileType2<\/em> and more. SIPs, or Subject Interface Packages, implement exported callback functions to help determine if a file type is supported, to get the signature from a supported file type, and more. You can see such a file, listed as <em>msisip.dll<\/em>, and various entry points, each under a different sub-key. Looking in the Windows SDK in <em>mssip.h<\/em>, you can see signatures and comments for these functions. Using SIPs, <code>WinVerifyTrust<\/code> can get and verify the signature for any given file type that has an associated SIP provider. You can even add your own providers using the <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/seccrypto\/security\/cryptsipaddprovider.asp\"><code>CryptSIPAddProvider<\/code> function<\/a>.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Digitally signing files helps protect against changes to a file (or any data, really) by validating that a hash of the current file matches the hash stored in the digital signature. Digital signatures also help verify that a package came from a particular publisher by encrypting the hash with the publisher&#8217;s private key. Verifying the [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[14,20],"class_list":["post-2083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-development","tag-installation"],"acf":[],"blog_post_summary":"<p>Digitally signing files helps protect against changes to a file (or any data, really) by validating that a hash of the current file matches the hash stored in the digital signature. Digital signatures also help verify that a package came from a particular publisher by encrypting the hash with the publisher&#8217;s private key. Verifying the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=2083"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/2083\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=2083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=2083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=2083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}