<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — Unable to generate certificates]]></title>
		<link>https://www.wolfssl.com/forums/topic171-unable-to-generate-certificates.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic171.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Unable to generate certificates.]]></description>
		<lastBuildDate>Fri, 30 Dec 2011 21:02:38 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post377.html#p377</link>
			<description><![CDATA[<p>Hi Todd,</p><p>Thanks for looking into it. I&#039;m using openssl version 0.9.8. In case you do comeup with a patch, please inform me. I really appreciate your support.</p><p>Thanks,</p><p>Nitin</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Fri, 30 Dec 2011 21:02:38 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post377.html#p377</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post376.html#p376</link>
			<description><![CDATA[<p>Hi Nitin,</p><p>Thanks for sending the CA (rootcert) and generated certs.&nbsp; wolfSSL is setting the correct issuer information but in a different order than the OpenSSL generated one.&nbsp; I&#039;ve never seen OpenSSL do this before (with that order that is), what version are you using?&nbsp; My understanding is that the name information should go</p><p>C (Country)<br />ST (State)<br />L (Locality)<br />O (Organization)<br />OU (O Unit)<br />CN (Common Name)<br />/optional like email</p><p>In the short term I guess you&#039;ll have to use the same SSL package to do the CA and issued certificates, which is pretty common I suppose.&nbsp; If we can confirm that OpenSSL is correct in varying the order of the issuer information we&#039;ll have to patch wolfSSL to copy the issuer information verbatim instead of trying to interpret it and reorder it.</p><p>Thanks for the report.&nbsp; </p><p>-Todd</p>]]></description>
			<author><![CDATA[null@example.com (todd)]]></author>
			<pubDate>Fri, 30 Dec 2011 19:31:12 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post376.html#p376</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post375.html#p375</link>
			<description><![CDATA[<p>Hi Todd,</p><p>The mismatch was due to various iterations. So I set up CA from the scratch , but i&#039;m not able to find out where the problem is. I just feel that i&#039;m missing something either in key generation or in the echo server/echo client examples..</p><p>I&#039;ve attached the codebase i&#039;m using for echo server and echo client. Clicert.pem and Clikey.pem are generated from openssl while new_key.pem and new_cert.pem are generated using the code i&#039;ve posted earlier.</p><p>Could you please look at it and help me?</p><p>Nitin</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Fri, 30 Dec 2011 05:20:46 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post375.html#p375</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post374.html#p374</link>
			<description><![CDATA[<p>Nitin,</p><p>I&#039;ve tested code generated keys and certs on our end and they&#039;re working fine here.</p><p>Notes:&nbsp; your uploaded certs differ in another major way.&nbsp; The openssl one is self-signed, look at the issuer and subject, they match.&nbsp; You can look at the metadata of a certificate by adding -text to the openssl command.&nbsp; The wolfSSL one is not self signed, it&#039;s issued by:</p><p>Issuer: C=US, ST=Arizona, L=Tucson, O=Root Certification Authority, OU=UA, CN=Root CA/emailAddress=ca@provenance.edu</p><p>Which is not the same as wolfSSL&#039;s test ca-cert.pem.&nbsp; I have a feeling that the CA certificate you&#039;re trying to tell echoserver to load_verify with isn&#039;t the right one (either because of naming, working directory, many different iterations, etc...&nbsp; It&#039;s hard to know exactly)&nbsp; Can you give it another look?</p><p>-Todd</p>]]></description>
			<author><![CDATA[null@example.com (todd)]]></author>
			<pubDate>Thu, 29 Dec 2011 23:28:55 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post374.html#p374</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post373.html#p373</link>
			<description><![CDATA[<p>Hi Todd,</p><p>In fact I have used CyaSSL_CTX_load_verify_locations() with ca-cert.pem on the echo server. Now i also tried using different names for and certs than what wolfSSL uses in the examples. But, still i&#039;m stuck with the same problem. Keys and certificates generated from code don&#039;t seem to work.</p><p>Nitin</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Thu, 29 Dec 2011 18:33:01 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post373.html#p373</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post372.html#p372</link>
			<description><![CDATA[<p>Nitin,</p><p>You need to tell the echoserver about the CA of the client cert you&#039;ve created.&nbsp; The echoserver has no way to verify the client cert you&#039;ve created without it, that&#039;s why you&#039;re getting failure to verify signature.</p><p>You can use CyaSSL_CTX_load_verify_locations() with the ca-cert.pem CA on the echoserver.</p><p>You should also note the echoserver changes directory upon startup.&nbsp; I&#039;d also recommend using different names for keys and certs than wolfSSL uses for its tests ones, just to keep everything clear.</p><p>-Todd</p>]]></description>
			<author><![CDATA[null@example.com (todd)]]></author>
			<pubDate>Thu, 29 Dec 2011 17:48:34 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post372.html#p372</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post370.html#p370</link>
			<description><![CDATA[<p>I have attached the client files from openssl and via the code above. The only difference i can see is in the start and end dates and version.</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Wed, 28 Dec 2011 23:43:00 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post370.html#p370</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post369.html#p369</link>
			<description><![CDATA[<p>Hi Chris,</p><p>Well that didn&#039;t help much.&nbsp; Using the ca-key and ca-cert, I want to generate client keys from code. Then I want to authenticate the client when it tries to connect to the server. I have included the key generation and other required code below.</p><p>Here is what I did:</p><p>1) Generate CA key and certificate as you have specified<br />2) Generate Server key and certificate as specified<br />3) Use the CA key and CA certificate in the below code to generate Client certificate and key<br /></p><div class="codebox"><pre><code>// Key generation

RsaKey genkey;
    RNG rng;
    int ret;
    FILE* fp;

    InitRng(&amp;rng);
    InitRsaKey(&amp;genkey, 0);

    ret = MakeRsaKey(&amp;genkey,1024,65537,&amp;rng);

    byte der[4096];
    byte pem[4096];

    int derSz = RsaKeyToDer(&amp;genkey,der,sizeof(der));

    if(derSz &lt; 0)
        printf(&quot;DER error\n&quot;);

    int pemSz = DerToPem(der,derSz,pem,sizeof(pem),PRIVATEKEY_TYPE);

    if(pemSz &lt; 0)
        printf(&quot;PEM error\n&quot;);

    fp = fopen(&quot;client-key.pem&quot;,&quot;w+&quot;);

    fwrite(pem,1,sizeof(pem),fp);

    fclose(fp);
    
    fp = fopen(&quot;client-key.der&quot;,&quot;w+&quot;);

    fwrite(der,1,sizeof(der),fp);

    fclose(fp);

    printf(&quot;Now time for certificate..\n&quot;);

// Certificate Generation and signing by CA certificate

RsaKey      caKey;
        Cert        myCert;
        byte        derCert[4096];
        byte        pemCert[4096];
        FILE*       derFile;
        FILE*       pemFile;
        int         certSz;
        
        byte        tmp[2048];
        size_t      bytes;
        word32      idx = 0;

    FILE*  file = fopen(&quot;ca-key.der&quot;, &quot;rb&quot;);

        if (!file)
            return -412;

        bytes = fread(tmp, 1, sizeof(tmp), file);
  

        InitRsaKey(&amp;caKey, 0);  
        ret = RsaPrivateKeyDecode(tmp, &amp;idx, &amp;caKey, (word32)bytes);
        if (ret != 0) 
    {
        printf(&quot;Problem decoding private key\n&quot;);    
        return -413;
    }
        InitCert(&amp;myCert);

    strncpy(myCert.subject.country, &quot;US&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.state, &quot;Arizona&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.locality, &quot;Tucson&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.org, &quot;Certificate Authority&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.unit, &quot;UA&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.commonName, &quot;Client&quot;, CTC_NAME_SIZE);
        strncpy(myCert.subject.email, &quot;ca@provenance.edu&quot;, CTC_NAME_SIZE);
    myCert.selfSigned = 0;
    myCert.daysValid = 30;
    ret = SetIssuer(&amp;myCert,&quot;ca-cert.pem&quot;);

    if(ret &lt; 0)
    printf(&quot;Problem setting issuer..\n&quot;);

    certSz = MakeCert(&amp;myCert, derCert, sizeof(derCert), &amp;genkey, &amp;rng); 
        if (certSz &lt; 0)
    {
        printf(&quot;Problem with Make cert\n&quot;);            
        return -407;
    }

        certSz = SignCert(&amp;myCert, derCert, sizeof(derCert), &amp;caKey, &amp;rng);
        if (certSz &lt; 0)
    {
        printf(&quot;Problem with signing certificate\n&quot;);            
        return -408;
    }

    int someSz = -1;
    someSz = DerToPem(derCert,certSz,pemCert,sizeof(pemCert),CERT_TYPE);
       if (someSz &lt; 0)
    {
        printf(&quot;Problem in conversion from DER to PEM\n&quot;);            
        return -409;
    }
    else
        printf(&quot;Size is %d\n&quot;,someSz);
    FILE* certfp;
    certfp = fopen(&quot;client-cert.pem&quot;,&quot;w+&quot;);
    fwrite(pemCert,1,sizeof(pemCert),certfp);

    fclose(certfp);

    certfp = fopen(&quot;client-cert.der&quot;,&quot;w+&quot;);
    fwrite(derCert,1,sizeof(derCert),certfp);

    fclose(certfp);
    </code></pre></div><br /><p>4) In EchoClient, I add the following code block before creating socket file descriptor:<br /></p><div class="codebox"><pre><code>if (CyaSSL_CTX_use_certificate_file(ctx,&quot;./client-cert.pem&quot;,SSL_FILETYPE_PEM)!= SSL_SUCCESS) {
       fprintf(stderr, &quot;Error loading ./clientcert.pem, please check the file.\n&quot;);
       exit(EXIT_FAILURE);
    }

    if (CyaSSL_CTX_use_PrivateKey_file(ctx,&quot;./client-key.pem&quot;, 
                SSL_FILETYPE_PEM) != SSL_SUCCESS) {
       fprintf(stderr, &quot;Error loading ./clientkey.pem, please check the file.\n&quot;);
       exit(EXIT_FAILURE);
    }
    
    CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER |  SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);    </code></pre></div><br /><p>5) In EchoServer, I add the following line before the socket file descriptor:<br /></p><div class="codebox"><pre><code>CyaSSL_CTX_set_verify(ctx,SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);    </code></pre></div><p>As soon as I type something in echo client and press Enter, I get read error -155.</p><p>If I create the client key and client certificate using openssl (i.e., the way we created server key and server certificate), everything works.</p><p>So I believe there is something wrong in my key and certificate generation code, but i&#039;m unable to figure it out.</p><p>Nitin</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Wed, 28 Dec 2011 23:31:39 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post369.html#p369</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post368.html#p368</link>
			<description><![CDATA[<p>Hi Nitin,</p><div class="quotebox"><blockquote><p>Just as pure guess work, I tried converting this key from PEM to DER and it worked !.. But, I&#039;m not able to use these keys with the echo client and echo server examples..</p></blockquote></div><p>The RsaPrivateKeyDecode() function only accepts keys in DER format (raw data).&nbsp; To use the example echo client and echo server with DER-formatted keys, you will need to use the SSL_FILETYPE_ASN1 format instead of the SSL_FILETYPE_PEM format.&nbsp; For example, the echo server would load a private key like this (where svrKey is a RSA key in DER format):</p><div class="codebox"><pre><code>CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_ASN1)</code></pre></div><p>Here are the OpenSSL commands that we typically use to generate test CA keys and certificates and create test CA-signed certs.&nbsp; To create a CA key and certificate:</p><div class="codebox"><pre><code>1.  openssl genrsa 1024 &gt; ca-key.pem
2.  openssl req -new -x509 -nodes -sha1 -days 1000 -key ca-key.pem &gt; ca-cert.pem</code></pre></div><p>To create a server key and CA-signed server cert:</p><div class="codebox"><pre><code>1.  openssl req -newkey rsa:1024 -sha1 -days 1000 -nodes -keyout server-key.pem &gt; server-req.pem
2.  openssl x509 -req -in server-req.pem -days 1000 -sha1 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 &gt; server-cert.pem</code></pre></div><p>Does this help?</p><p>- Chris</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Wed, 28 Dec 2011 18:43:11 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post368.html#p368</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post367.html#p367</link>
			<description><![CDATA[<p>Hi Chris,</p><p>Here are the commands used to generate the CA key and certificate:</p><p>$ openssl req -newkey rsa:1024 -sha1 -keyout rootkey.pem -out rootreq.pem<br />$ openssl x509 -req -in rootreq.pem -sha1 -extfile provenance.cnf -extensions certificate_extensions -signkey rootkey.pem -out rootcert.pem</p><p>Just as pure guess work, I tried converting this key from PEM to DER and it worked !.. But, I&#039;m not able to use these keys with the echo client and echo server examples..</p><p>If you need more info. i can share it with you.. Currently, I have a rootCA which creates and signs a serverCA. I have done this using openssl. After this, the rootCA creates and signs client certificates and keys. The serverCA creates and signs server certificates and keys. Though i&#039;m able to generate the keys after using DER format for the private key, i&#039;m unable to use it with the echoclient and echoserver examples. I get a write failed and read error at the two ends.</p><p>Using openssl to generate the same client and server keys work. So I think i&#039;m missing something while generating the keys and certificates. (Self signed certificates work seamlessly. )</p><p>Looking for your insight on this as i&#039;m relatively new to ssl.</p><p>Nitin</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Tue, 27 Dec 2011 19:46:03 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post367.html#p367</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post366.html#p366</link>
			<description><![CDATA[<p>Hi Nitin,</p><p>What command and parameters did you use to generate your CA key using OpenSSL?</p><p>- Chris</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Tue, 27 Dec 2011 17:51:25 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post366.html#p366</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post364.html#p364</link>
			<description><![CDATA[<p>ok thanks..another question..if I try to self sign the generated&nbsp; certificates everything is fine. But, if I try to sign it with a CA private key,(i setup a ca using openssl and am trying to use its private key) i get an error while trying to decode the private key..</p><p>specifically i get an error here :</p><p>ret = RsaPrivateKeyDecode(tmp,&amp;idx,&amp;caKey,(word32)bytes);</p><p>Is there anything wrong is using the private key of ca from openssl??</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Sat, 24 Dec 2011 00:13:48 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post364.html#p364</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post363.html#p363</link>
			<description><![CDATA[<p>Not necessarily - you could define it in your source code as well if that was your preferred way.</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Fri, 23 Dec 2011 21:32:24 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post363.html#p363</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post362.html#p362</link>
			<description><![CDATA[<p>Thanks Chris..it worked.. Is there any reason why I have to add this during the build process??</p>]]></description>
			<author><![CDATA[null@example.com (nsindhe)]]></author>
			<pubDate>Thu, 22 Dec 2011 23:38:54 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post362.html#p362</guid>
		</item>
		<item>
			<title><![CDATA[Re: Unable to generate certificates]]></title>
			<link>https://www.wolfssl.com/forums/post361.html#p361</link>
			<description><![CDATA[<p>Hi Nitin,</p><div class="quotebox"><blockquote><p>I get &quot;Cert undeclared&quot; error. I&#039;m unable to figure out why this is happening. Generating RSA keys works fine, but as soon as I declare a variable to generate certificate, I get this error.</p></blockquote></div><p>You could be seeing this error if CYASSL_CERT_GEN is not defined.&nbsp; Can you try defining -DCYASSL_CERT_GEN this when building your application and see if it resolves your error?</p><p>Regards,<br />Chris</p>]]></description>
			<author><![CDATA[null@example.com (chrisc)]]></author>
			<pubDate>Thu, 22 Dec 2011 22:12:51 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post361.html#p361</guid>
		</item>
	</channel>
</rss>
