<html><body>
<p><font size="2" face="sans-serif">Thanks..</font><br>
<br>
<font size="2" face="sans-serif">I think I will try with X509_read_xxx and d2i_, then probably do not have to read throu first character as 0x30.</font><br>
<br>
<font size="2" face="sans-serif">I had few more questions.</font><br>
<br>
<tt><font size="2">Are all d2i_xxx type of APIs for DER format.</font></tt><br>
<br>
<tt><font size="2">And if I have to operate on DER formatted certs, do I need to first convert it to PEM and then user PEM APIs. or there are DER specific APIs also, I didn't find though, unless they are d2i_xxx types.</font></tt><br>
<br>
<br>
<font size="2" face="sans-serif">Thanks & Regards,<br>
Nayna Jain</font><br>
<br>
<img width="16" height="16" src="cid:1__=EABBF4F3DF8272118f9e8a93df938@in.ibm.com" border="0" alt="Inactive hide details for Viktor Dukhovni ---06/09/2015 10:34:50 AM---[ Please DO NOT post user questions to openssl-dev, that'"><font size="2" color="#424282" face="sans-serif">Viktor Dukhovni ---06/09/2015 10:34:50 AM---[ Please DO NOT post user questions to openssl-dev, that's rude. ] On Tue, Jun 09, 2015 at 09:51:52A</font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From:      </font><font size="1" face="sans-serif">Viktor Dukhovni <openssl-users@dukhovni.org></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To:        </font><font size="1" face="sans-serif">openssl-users@openssl.org</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date:      </font><font size="1" face="sans-serif">06/09/2015 10:34 AM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject:   </font><font size="1" face="sans-serif">Re: [openssl-users] Is there openssl API to verify certificate content is DER or PEM format ?</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Sent by:   </font><font size="1" face="sans-serif">"openssl-users" <openssl-users-bounces@openssl.org></font><br>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br>
<br>
<br>
<tt><font size="2">[ Please DO NOT post user questions to openssl-dev, that's rude. ]<br>
<br>
On Tue, Jun 09, 2015 at 09:51:52AM +0530, Nayna Jain wrote:<br>
<br>
> I need to verify if the certifiate I have received is having its content in<br>
> PEM/DER format.<br>
> <br>
> Is there any API which if given file pointer like (fp) will tell me whether<br>
> it has valid format of certificate and if yes then whether it is PEM/DER<br>
> format ?<br>
> <br>
> If no API, then what is the other way to verify this ?<br>
<br>
If the first character of the file is 0x30 (ASN.1 sequence) it is<br>
likely in DER form.  With stdio you can peek at that character and<br>
use ungetc() to put it back.<br>
<br>
The only false positives for DER will be files in which the PEM<br>
'-----BEGIN ...-----' line is preceded by "comment" text that<br>
happens to start with a '0'.  If your PEM files contain no "comments",<br>
the test is always accurate.<br>
<br>
A more robust test is to try PEM_read_X509() or PEM_read_bio_X509()<br>
and if that fails, rewind the file, and try d2i_X509_fp() or<br>
d2i_X509_bio().  The latter need not be tried if the first character<br>
of the file is not 0x30.<br>
<br>
-- <br>
                 Viktor.<br>
_______________________________________________<br>
openssl-users mailing list<br>
To unsubscribe: </font></tt><tt><font size="2"><a href="https://mta.openssl.org/mailman/listinfo/openssl-users">https://mta.openssl.org/mailman/listinfo/openssl-users</a></font></tt><tt><font size="2"><br>
<br>
</font></tt><br>
</body></html>