1

I need to test a parser of PEM formatted certificates. Thus, I need to generate many variations including variations that are invalid for various reasons. Obviously I can use openssl or a library like Bouncy Castle to create valid certificates, but what about forcing errors? Can anyone point me to tools that can help?

More specifically, the kinds of errors I want to be able to generate are primarily valid PEM files that parse to the DER structure, but the DER is invalid in some way. Such as bad length values, undefined tag values, incorrect version, invalid signature, etc... Of secondary interest to me (at least right now) are corrupted PEM files and PEM files of something that isn't a DER cert.

  • Generating DER and PEM are easy enough I haven't looked for tools. But I would note there are three (or four) categories of invalidness that would probably require different tools and you don't say which one or ones. (1) not valid PEM of anything: missing/bad/wrong header/trailer, bad base64, bad body linelengths (some folks use the true PEM 64, some use the MIME 76, some allow variation); (2) PEM of something that isn't valid DER of a cert, which can be subdivided into not valid DER ever or valid something not a cert, however these blur a little like implicit tags so I would combine them; ... – dave_thompson_085 Jan 31 '15 at 3:12
  • ... (3) PEM of DER that parses to the Certificate structure but semantically invalid: illegal version, contents inconsistent with version, signature invalid (requires parent key also except for root), alg params not matching alg OID, sig value not matching alg&key, repeated OID within one RDN, KU impossible or EKU impossible or KU-EKU inconsistent, BC.ca=false but BC.path not omitted, etc etc. And then of course we have certs which are valid as far as the content of the cert itself (and the file it came from), but have expired or been revoked, determinable only by external data. – dave_thompson_085 Jan 31 '15 at 3:18
  • Thank you neubert for the example certs. However, I finally came across a tool that generates bad certs: github.com/sumanj/frankencert – Erik Shreve Apr 8 '16 at 3:21
1

A few attempts I made at making bad X.509 certs using phpseclib, a pure PHP X.509 parser.

Adding random characters at the end of a SEQUENCE:

http://pastebin.com/5Jcy0d90

Replace the RSA / DSA part of an X509 cert with another X509 cert:

http://pastebin.com/570bR2jz

A cert with the same extension multiple times:

http://pastebin.com/acmcXbAg

Invalid OID:

http://pastebin.com/3svVQyP3

A bazillion nested SEQUENCEs:

http://pastebin.com/fKw6XAEp

Non-constructed sequences:

http://pastebin.com/kpajfQyD

Having a signature that doesn't match the signature algorithm:

http://pastebin.com/GAED5xQe

To get that last one working you'll need to do http://pastebin.com/Dq2XAAGG to get it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.