{"id":522,"date":"2006-08-12T01:34:53","date_gmt":"2006-08-12T09:34:53","guid":{"rendered":"\/?p=522"},"modified":"2006-08-12T02:01:45","modified_gmt":"2006-08-12T10:01:45","slug":"william-tay-on-converting-public-key-pair-formats","status":"publish","type":"post","link":"https:\/\/www.identityblog.com\/?p=522","title":{"rendered":"William Tay on converting public key pair formats"},"content":{"rendered":"<p><a href=\"http:\/\/www.softwaremaker.net\/blog\/UsingOpenSSLForCardspaceDemoOnPHP.aspx\" class=\"broken_link\">William Tay<\/a> has a very interesting technical blog and has solved the riddle of how to take a public key pair that he produced in a Microsoft environoment, and export it to PEM so it can by used by PHP.&nbsp; I didn&#39;t have this particular problem, because I created my site&#39;s key using OpenSSL in the first place.&nbsp; However, I&#39;ve spent many hours with the OpenSSL utility trying &#8211; so far unsuccessfully &#8211; to go the other way (PEM to pfx).&nbsp; It shouldn&#39;t matter&nbsp;which platform you create your key on &#8211;&nbsp;if you have a mix of platforms you want to be able to take the key in both directions.&nbsp; Anyway, for those who have William&#39;s problem, here&#39;s how he dealt with it:<\/p>\n<blockquote><p>I believe some hardcore <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fwinfx%2freference%2finfocard%2fdefault.aspx\" target=\"_blank\" class=\"broken_link\">Windows CardSpace<\/a> fanatics out there may have tried out <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=https%3A%2F%2Fwww.identityblog.com%2f\" target=\"_blank\" class=\"broken_link\">Kim Cameron&#39;s IdentityBlog<\/a>&nbsp;Cardspace demo on <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=https%3a%2f%2fwww.identityblog.com%2finfocard-demo.php\" target=\"_blank\" class=\"broken_link\">php<\/a>. The tutorials can code samples can be found via his blog <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=https%3A%2F%2Fwww.identityblog.com%2f%3fpage_id%3d430\" target=\"_blank\" class=\"broken_link\">here<\/a>. As of this time, I dont think he has updated it to work with the WinFX July CTP drop.<\/p>\n<p>If you had played with those php samples, you will realize that nothing much has changed for the WinFX July CTP drop, we are still using the same version of <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=http%3a%2f%2fmsdn.microsoft.com%2flibrary%2fen-us%2fdnglobspec%2fhtml%2fws-trust.asp\" target=\"_blank\" class=\"broken_link\">WS-Trust<\/a> and <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=http%3a%2f%2fdocs.oasis-open.org%2fwss%2f2004%2f01%2foasis-200401-wss-soap-message-security-1.0.pdf\" target=\"_blank\" class=\"broken_link\">WS-Security Specifications<\/a> specifications. While WS-Security has been pretty much baked, as the advanced WS-* specifications reach a better level of maturity and acceptance, it won&#39;t change as&nbsp;frequently anymore.<\/p>\n<p>The only change to take note is the OBJECT element in the html page. The way claims are presented on a html page is now space-delimited and not comma-delimited as it was before.<\/p>\n<p>I have been showing the php demos in my presentations around the Asia-Pacific&nbsp;circuits for some time now. One of the questions I frequently get asked is how do we get the RSA private key of the https site (<em>Relying party<\/em>) we are using to authenticate our users. While Kim has shown some briefs snippets of his php code <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=https%3A%2F%2Fwww.identityblog.com%2fcodesample.php%3fsimple-infocard-demo%2fdemo_token\" target=\"_blank\" class=\"broken_link\">here<\/a>&nbsp;(It is fairly obvious why the entire Private Key cannot be disclosed here),<\/p>\n<p>\/\/ Cardspace_demoprocessing.php<br \/>\n\/\/ Put your own PEM private key here and<br \/>\n\/\/ use the right password (for the demo<br \/>\n\/\/ we don&#39;t use MySql to store this stufffunction get_settings($key)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; if ($key == &#8220;infocard_key&#8221;) {<\/p>\n<p>$retVal = <strong><em>&#8220;&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br \/>\nProc-Type: 4,ENCRYPTED<br \/>\nDEK-Info: DES-EDE3-CBC,9266952B733BFBE0<\/em><\/strong><\/p>\n<p><strong><em>Z4WmpirV4dXvYjNmfSN99Iu4iYzUWa4\/CPZG0NParYSVHMOhb4lsS6iISjgniGG9<br \/>\nzhA862KDwsYUjgoyAIXfJAd5Z3hXiyJYdkygF\/DUgeQFcwQjsWmkguq27EDHW6nS<br \/>\n.<br \/>\n.<br \/>\n.<br \/>\n3GkQxPLzTMFZYm7haU3WH+QYnNxz2bG0esUmB\/YECXDCqFTbrUm\/DUPd4YiI2HiL<br \/>\n+j40vRpPzY6ngd1QNOfd5jkin7sjW1YlsEsRPV8OzEJvNmBZF274Cw==<\/em><\/strong><br \/>\n<strong><em>&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;<\/em><\/strong>&#8220;;<\/p>\n<p>&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; else if ($key == &#8220;infocard_opener&#8221;){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $retVal = &#8220;xY8O< |aBB\";\n&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp; else {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $retVal = NULL;\n&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp; return($retVal);\n}\nhe did not show how he got that RSA Key.\n\nThere are, of course, a few ways to get that key. But since we are on the subject of <a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fOpen_source\" target=\"_blank\" class=\"broken_link\">Open-source and php being the flavour of the day, I thought why not show the readers how to get it using another popular utility out there called &#8220;<a href=\"http:\/\/www.softwaremaker.net\/blog\/ct.ashx?id=24341bfc-b0f6-447f-90c6-0b4a5026c546&#038;url=http%3a%2f%2fwww.openssl.org%2f\" target=\"_blank\">OpenSSL<\/a>&#8220;.&nbsp;I am&nbsp;using version&nbsp;0.9.8b&nbsp;the OpenSSL binaries\/executables.<\/p>\n<p>Once that is all downloaded, installed and setup &#8211; I used this command to retreive the RSA Private Key into a PEM file:<\/p>\n<p><strong>Openssl pkcs12 -in Softwaremaker.NET.Pte.Ltd_300607_SSLCert.pfx -out cert.pem -nodes<\/strong><\/p>\n<p>You will, of course,&nbsp;replace the &#8220;<strong>Softwaremaker.NET.Pte.Ltd_300607_SSLCert.pfx<\/strong>&#8221; with your own site&#39;s SSL digital certificate. The <strong>-nodes<\/strong> flag just tells the output not to have a passphase lock on the resulting PEM file. Of course, you can if you want to&nbsp;if you are afraid of others being able to view&nbsp;your site&#39;s&nbsp;Private Key from the php code file. The output cert.pem will contain the output:<\/p>\n<p>Bag Attributes<br \/>\n&nbsp;&nbsp;&nbsp; 1.3.6.1.4.1.311.17.2:<br \/>\n&nbsp;&nbsp;&nbsp; localKeyID: 01 00 00 00<br \/>\n&nbsp;&nbsp;&nbsp; Microsoft CSP Name: Microsoft RSA SChannel Cryptographic Provider<br \/>\n&nbsp;&nbsp;&nbsp; friendlyName: 1a9c651d1153bf0e58ac3ff34c9fce1f_615cbd1c-54d4-4ea0-b0d4-5c14115c3abb<br \/>\nKey Attributes<br \/>\n&nbsp;&nbsp;&nbsp; X509v3 Key Usage: 10<br \/>\n<em>&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br \/>\nMIICXgIBAAKBgQDElLoxJcOzWT0jHT6uvdDHpDBnZLa4AE\/gznjcKuSIT880MAmL<br \/>\nADVIoDP\/0MPDucexjWCtJ33msRCmi2TOQ86dPhyc\/kfrmpTnjG+Kwi7tR5x07rAM<br \/>\n&#8230;<br \/>\nXLj+knD7VxrZvE\/CBJP5PgjuvqfcbiSGf4R8dVB\/nVm6tw==<br \/>\n&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;<\/em><br \/>\nBag Attributes<br \/>\n&nbsp;&nbsp;&nbsp; localKeyID: 01 00 00 00<br \/>\n&nbsp;&nbsp;&nbsp; friendlyName: Default Web Site<br \/>\nsubject=\/C=SG\/ST=Singapore\/L=Singapore\/O=Softwaremaker.NET Pte Ltd\/OU=Software Development and Architecture Research Unit\/CN=swmvm2k3<br \/>\nissuer=\/CN=Softwaremaker.NET Pte Ltd<br \/>\n&#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211;<br \/>\nMIIE1DCCA7ygAwIBAgIKYVFrDgABAAAACDANBgkqhkiG9w0BAQUFADAkMSIwIAYD<br \/>\nVQQDExlTb2Z0d2FyZW1ha2VyLk5FVCBQdGUgTHRkMB4XDTA2MDYzMDAyMjkyNFoX<br \/>\n&#8230;<br \/>\nGl+c093\/wY1RT9FhAyK0vpP\/H9rFzyrCZbuyL69tWkTI1DGTuZHW5g==<br \/>\n&#8212;&#8211;END CERTIFICATE&#8212;&#8211;<br \/>\nOnce you got the above output, you just have to&nbsp;replace the <strong><em>&#8220;&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;&#8230;&#8221;<\/em><\/strong> until the <strong><em>&#8220;&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;&#8220;<\/em><\/strong> with your own in the php code file (Cardspace_demoprocessing.php).<\/p>\n<p>Hope this helps someone out there.<\/p><\/blockquote>\n<p>Yeah.&nbsp; It&#39;s true that I was unclear, when writing my&nbsp;demo PHP code, how to best store and retrieve secret keys&nbsp;in a LAMP environment.&nbsp; In Windows, I would use the system-provided routines for protecting and accessing&nbsp;secret keys, but&nbsp;I don&#39;t know the equivalents one would use&nbsp;in LAMP.<\/p>\n<p>I ended up&nbsp;just storing my keys in&nbsp;mySql (the code William shows above is a&nbsp;simplification to make the issues as easy to understand as possible) &#8211; but I&#39;d appreciate&nbsp;hearing from someone who&nbsp;knows&nbsp;the proper way to do&nbsp;this.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the proper way to store secret keys in a LAMP environment?<\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.identityblog.com\/index.php?rest_route=\/wp\/v2\/posts\/522"}],"collection":[{"href":"https:\/\/www.identityblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.identityblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.identityblog.com\/index.php?rest_route=\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.identityblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=522"}],"version-history":[{"count":0,"href":"https:\/\/www.identityblog.com\/index.php?rest_route=\/wp\/v2\/posts\/522\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.identityblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.identityblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.identityblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}