The other day I did a post on how to create a self-signed certificate using PKI.js in that sample we included a Basic Constraints extension but we could have also just as easily defined a custom or new certificate extension. For example thanks to #heartbleed folks are talking about MUST STAPLE again, this is an extension that was proposed several years ago that when present would indicate that clients should hard-fail instead of soft-fail with OCSP.
This proposal is based on a generic concept of expressing a security policy within the certificate. While the OIDs for this extension and the associated policy have not been defined yet one can easily construct a certificate using this extension with PKI.js:
cert_simpl.extensions.push(new org.pkijs.simpl.EXTENSION({ extnID: "1.2.3", // No OIDs assigned yet critical: false, extnValue: (new org.pkijs.asn1.SEQUENCE({ value: [ new org.pkijs.asn1.INTEGER({ value: 4 }), new org.pkijs.asn1.INTEGER({ value: 5 }), new org.pkijs.asn1.INTEGER({ value: 6 }) ] })).toBER(false) }));
NOTE: In the above snip-it we just made up two OID values, hopefully IANA will assign OIDs soon so it is possible for browsers and CAs to implement this extension formally.