{"id":5166,"date":"2016-12-22T11:38:28","date_gmt":"2016-12-22T09:38:28","guid":{"rendered":"https:\/\/www.limilabs.com\/blog\/?p=5166"},"modified":"2016-12-22T11:38:36","modified_gmt":"2016-12-22T09:38:36","slug":"create-code-signing-certificate-pfx","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/create-code-signing-certificate-pfx","title":{"rendered":"Create code signing certificate"},"content":{"rendered":"<h2>Management summary<\/h2>\n<ol>\n<li>You generate <strong>certificate signing request<\/strong> on your machine (using certmgr or ActiveX component).<\/li>\n<li><strong>Private\/public key pair<\/strong> is generated along with the request (<strong>on your machine<\/strong>).<\/li>\n<li>You export certificate that represents the request from your certificate key store.<\/li>\n<li>You <strong>extract private key<\/strong> from the certificate that represents the request.<\/li>\n<li>You send the request (it contains <strong>public key only<\/strong>) to CA (or ActiveX does this automatically).<\/li>\n<li>CA sends your <strong>certificate <\/strong>back (crt file that is basically your public key, signed with CA&#8217;s keys).<\/li>\n<li>Finally you need to <strong>combine the private key and the crt to create a pfx<\/strong>, that contains both private key and the certificate.<\/li>\n<\/ol>\n<h2>Important points<\/h2>\n<ul>\n<li>Private key is generated along with the certificate request.<\/li>\n<li>Private key is generated on <strong>your machine<\/strong>.<\/li>\n<li><strong>Private key is never sent to CA<\/strong> (Certificate Authority).<\/li>\n<li>Certificate received from the CA (*.crt file) doesn&#8217;t contain your private key.<\/li>\n<ul>\n<h2>Generate CSR &#038; private key &#8211; ActiveX<\/h2>\n<p>Some vendors, like Comodo, use Active X component, that runs on your machine and creates certificate request along with private\/public key pair generation on your machine:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_01.png\" alt=\"activex_01\" width=\"741\" height=\"948\" class=\"aligncenter size-full wp-image-5173\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_01.png 741w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_01-234x300.png 234w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><\/p>\n<p>Private key can be found in the certmgr of the <strong>local account<\/strong> (not machine&#8217;s):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02.png\" alt=\"activex_02\" width=\"392\" height=\"640\" class=\"aligncenter size-full wp-image-5174\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02.png 392w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02-184x300.png 184w\" sizes=\"(max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>Later on it must be exported as a pfx (e.g. &#8220;Request.pfx&#8221;).<\/p>\n<h2>Generate CSR &#038; private key &#8211; CertMgr<\/h2>\n<p>In MMC (certmgr), expand Certificates (Local Computer) and then Personal.<br \/>\nRight-click Certificates, and then go to the following menus: All Tasks > Advanced Operations > Create Custom Request:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_00.png\" alt=\"certmgr_00\" width=\"757\" height=\"590\" class=\"aligncenter size-full wp-image-5176\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_00.png 757w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_00-300x234.png 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/p>\n<p>Click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_01.png\" alt=\"certmgr_01\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5177\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_01.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_01-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_02.png\" alt=\"certmgr_02\" width=\"629\" height=\"461\" class=\"aligncenter size-full wp-image-5178\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_02.png 629w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_02-300x220.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>Click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_03.png\" alt=\"certmgr_03\" width=\"629\" height=\"461\" class=\"aligncenter size-full wp-image-5179\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_03.png 629w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_03-300x220.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>Ensure the Request format is PKCS #10, and then click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_04.png\" alt=\"certmgr_04\" width=\"629\" height=\"461\" class=\"aligncenter size-full wp-image-5180\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_04.png 629w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_04-300x220.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>Click the downward-facing arrow next to Details, and then click Properties.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_06.png\" alt=\"certmgr_06\" width=\"629\" height=\"461\" class=\"aligncenter size-full wp-image-5182\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_06.png 629w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_06-300x220.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>On the subject type, select the following values, enter the corresponding Value, and then click Add:<\/p>\n<ul>\n<li>Common name &#8211; Your business or organization&#8217;s name<\/li>\n<li>Organization &#8211; Your business or organization&#8217;s name<\/li>\n<li>Locality &#8211; Your business or organization&#8217;s address<\/li>\n<li>State &#8211; The state where your business or organization resides<\/li>\n<li>Country &#8211; The country where your business or organization resides<\/li>\n<\/ul>\n<p>Go to the Private Key tab, click Key type, and then select Make private key exportable:<br \/>\nClick OK, and then click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_07.png\" alt=\"certmgr_07\" width=\"502\" height=\"507\" class=\"aligncenter size-full wp-image-5183\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_07.png 502w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_07-150x150.png 150w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_07-297x300.png 297w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<p>Browse for the location where you want to save the file, enter a File Name (&#8220;Request.csr&#8221;), and then click Finish.<br \/>\nYour CSR is now stored in the file you saved it to on your local machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_05.png\" alt=\"certmgr_05\" width=\"629\" height=\"461\" class=\"aligncenter size-full wp-image-5181\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_05.png 629w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_05-300x220.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>Request file is regular text file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_15.png\" alt=\"certmgr_15\" width=\"528\" height=\"261\" class=\"aligncenter size-full wp-image-5191\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_15.png 528w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_15-300x148.png 300w\" sizes=\"(max-width: 528px) 100vw, 528px\" \/><\/p>\n<p>This process also creates a private key, which you will need to use later to create a PFX file to sign your code or driver.<\/p>\n<h2>Export certificate that represents the request<\/h2>\n<p>If you were using ActiveX  to generate certificate request,   certificate that represents the request (including private key) is stored in certmgr of the local account (not machine&#8217;s):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02.png\" alt=\"activex_02\" width=\"392\" height=\"640\" class=\"aligncenter size-full wp-image-5174\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02.png 392w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/ActiveX_02-184x300.png 184w\" sizes=\"(max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>Go to &#8220;Certificate Enrollment Requests&#8221;\/ &#8220;Certificates&#8221; (Hit refresh if it is empty):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_08.png\" alt=\"certmgr_08\" width=\"655\" height=\"590\" class=\"aligncenter size-full wp-image-5184\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_08.png 655w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_08-300x270.png 300w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/p>\n<p>Right-click the certificate and then go to the following menus: All Tasks > Export:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_09.png\" alt=\"certmgr_09\" width=\"655\" height=\"590\" class=\"aligncenter size-full wp-image-5185\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_09.png 655w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_09-300x270.png 300w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/p>\n<p>Select export private key and hit Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_10.png\" alt=\"certmgr_10\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5186\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_10.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_10-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Ensure the Request format is PKCS #12, and then click Next:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_11.png\" alt=\"certmgr_11\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5187\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_11.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_11-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Specify password:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_12.png\" alt=\"certmgr_12\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5188\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_12.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_12-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Browse for the location where you want to save the file, enter a File Name (&#8220;Request.pfx&#8221;), and then click Finish.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_13.png\" alt=\"certmgr_13\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5189\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_13.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_13-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Click Finish:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_14.png\" alt=\"certmgr_14\" width=\"535\" height=\"523\" class=\"aligncenter size-full wp-image-5190\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_14.png 535w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/certmgr_14-300x293.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Certificate that represents your request is now stored in the file you saved on your local machine. <strong>It contains both private and public key<\/strong>.<\/p>\n<h2>Extract private key<\/h2>\n<p>First you&#8217;ll need to install OpenSSL.<\/p>\n<p>To extract private key from the request, issue following command:<\/p>\n<p><code>openssl pkcs12 -in Request.pfx -out Request_PrivateKey.pem -nocerts -nodes<\/code><\/p>\n<p>nocerts = private key only,<br \/>\nnodes = no password<\/p>\n<h2>Generate CSR &#038; private key &#8211; OpenSSL<\/h2>\n<p>You can use following command to create certificate request and key using OpenSSL:<\/p>\n<p><code>openssl req -new -newkey rsa:2048 -nodes -keyout Request_PrivateKey.key -out Request.csr<\/code><\/p>\n<p>You may need to convert to convert the key (BEGIN PRIVATE KEY) to PKCS#1 format (BEGIN RSA PRIVATE KEY):<\/p>\n<p><code>openssl rsa -outform pem -in Request_PrivateKey.key -out Request_PrivateKey.pem<\/code><\/p>\n<h2>CA creates a certificate<\/h2>\n<p>Now you should upload -or- copy&#038;paste request file (&#8220;Request.csr&#8221;) to your CA, and in return, they should create the certificate for you:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_00.png\" alt=\"generated_00\" width=\"561\" height=\"384\" class=\"aligncenter size-full wp-image-5199\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_00.png 561w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_00-300x205.png 300w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/p>\n<p>What you receive from your CA looks more or less like this:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_01.png\" alt=\"generated_01\" width=\"558\" height=\"124\" class=\"aligncenter size-full wp-image-5200\" srcset=\"https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_01.png 558w, https:\/\/www.limilabs.com\/blog\/wp-content\/uploads\/2016\/12\/Generated_01-300x67.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/p>\n<p>Most important file is the crt file which contains your certificate (<strong>it includes public key only<\/strong>).<\/p>\n<h2>Combine private key with cert to create pfx<\/h2>\n<p>To combine private key from the request and certificate from CA into one pfx certificate, issue following command:<\/p>\n<p><code>openssl pkcs12 -inkey Request_PrivateKey.pem -in 00\u202670.crt -export -out 00\u202670.pfx<\/code><\/p>\n<p>The pfx file you created <strong>contains both private key and the certificate<\/strong> and can be used to sign your code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Management summary You generate certificate signing request on your machine (using certmgr or ActiveX component). Private\/public key pair is generated along with the request (on your machine). You export certificate that represents the request from your certificate key store. You extract private key from the certificate that represents the request. You send the request (it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-5166","post","type-post","status-publish","format-standard","hentry","category-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5166"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=5166"}],"version-history":[{"count":41,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5166\/revisions"}],"predecessor-version":[{"id":5227,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/5166\/revisions\/5227"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=5166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=5166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=5166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}