<p>I recently came across an issue with Windows 2003 (apparently it also exists in other versions too), where if an SSL/TLS server is requesting client certificate authentication and it has more than 16KB of trusted certificate DNs, Internet Explorer (or any other app that uses schannel.dll) is unable to complete the SSL handshake. (In a nutshell, the server breaks the message into chunks of 2^14 bytes, as per RFC 2246 sec. 6.2.1, but Schannel wasn't written to support that. I've gotten confirmation from Microsoft support that this is a flaw in Schannel and that they're considering fixing it in a future release.)</p>

<p>So I'm trying to find a way to easily parse through my trusted certificates (I use Apache as my server, so all of them are in PEM format) to get the total ASN.1-format length of the DNs (which is how they get sent over the wire during the handshake), and thereby see if I'm getting too close to the limit. I haven't yet been able to find a way to do this, though: the OpenSSL asn1parse function comes close, but it doesn't seem to provide a way to get the ASN.1 sequence for just the issuer name, which is what I need.</p>

<p>Any suggestions?</p>

[{'answer_id': 86714, 'author': 'qbeuek', 'author_id': 5348, 'author_profile': 'https://Stackoverflow.com/users/5348', 'pm_score': 3, 'selected': True, 'text': '<p>Since ASN.1 is self describing, it\'s fairly easy to write an ASN.1 parser. As you probably know, ASN.1 data contains a tree of values, where each value type is identified by a globally assigned OID (Object ID). You can find a free ASN.1 decoder with source code at: <a href="http://www.geocities.co.jp/SiliconValley-SanJose/3377/asn1JS.html" rel="nofollow noreferrer"><a href="http://www.geocities.co.jp/SiliconValley-SanJose/3377/asn1JS.html" rel="nofollow noreferrer">http://www.geocities.co.jp/SiliconValley-SanJose/3377/asn1JS.html</a></a>. It;\'s written in javascript so you can play with it directly in your browser.</p>\n\n<p>As to your exact question - I would:</p>\n\n<ol>\n<li>Use the supplied parser, find another one or write my own</li>\n<li>Find the OID of trusted DNs (check the specification or simply decode a certificate using the supplied ASN.1 decoder page)</li>\n<li>Combine the two above to extract the size of trusted DNs inside a certificate.</li>\n</ol>\n'}, {'answer_id': 189109, 'author': 'Seth', 'author_id': 20503, 'author_profile': 'https://Stackoverflow.com/users/20503', 'pm_score': 0, 'selected': False, 'text': "<p>openssl asn1parse will do it, but you'll need to do some manual parsing to figure out where the issuer sequence begins. Per RFC 5280, it's the 4th item in the TBSCertificate sequence (potentially 3rd if it's a v1 certificate), immediately following the signature algorithm. In the following example:</p>\n\n<pre><code>    0:d=0  hl=4 l= 621 cons: SEQUENCE\n    4:d=1  hl=4 l= 470 cons:  SEQUENCE\n    8:d=2  hl=2 l=   3 cons:   cont [ 0 ]\n   10:d=3  hl=2 l=   1 prim:    INTEGER           :02\n   13:d=2  hl=2 l=   1 prim:   INTEGER           :02\n   16:d=2  hl=2 l=  13 cons:   SEQUENCE\n   18:d=3  hl=2 l=   9 prim:    OBJECT            :sha1WithRSAEncryption\n   29:d=3  hl=2 l=   0 prim:    NULL\n   31:d=2  hl=2 l=  64 cons:   SEQUENCE\n   33:d=3  hl=2 l=  11 cons:    SET\n   35:d=4  hl=2 l=   9 cons:     SEQUENCE\n   37:d=5  hl=2 l=   3 prim:      OBJECT            :countryName\n   42:d=5  hl=2 l=   2 prim:      PRINTABLESTRING   :US\n   46:d=3  hl=2 l=  26 cons:    SET\n   48:d=4  hl=2 l=  24 cons:     SEQUENCE\n   50:d=5  hl=2 l=   3 prim:      OBJECT            :organizationName\n   55:d=5  hl=2 l=  17 prim:      PRINTABLESTRING   :Test Certificates\n   74:d=3  hl=2 l=  21 cons:    SET\n   76:d=4  hl=2 l=  19 cons:     SEQUENCE\n   78:d=5  hl=2 l=   3 prim:      OBJECT            :commonName\n   83:d=5  hl=2 l=  12 prim:      PRINTABLESTRING   :Trust Anchor\n   97:d=2  hl=2 l=  30 cons:   SEQUENCE\n   99:d=3  hl=2 l=  13 prim:    UTCTIME           :010419145720Z\n  114:d=3  hl=2 l=  13 prim:    UTCTIME           :110419145720Z\n  129:d=2  hl=2 l=  59 cons:   SEQUENCE\n</code></pre>\n\n<p>the Issuer DN starts at offset 31 and has a header-length of two and a value length of 64, for a total length of 66 bytes. This isn't so easy to script, of course...</p>\n"}]
['https://Stackoverflow.com/questions/72237', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12204/']