Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of how to create a custom x509 extension #38

Open
CMCDragonkai opened this issue Sep 20, 2022 · 1 comment
Open

Example of how to create a custom x509 extension #38

CMCDragonkai opened this issue Sep 20, 2022 · 1 comment

Comments

@CMCDragonkai
Copy link

I'm coming from using node-forge, where it was relatively easy to create custom extensions.

  extensions.push({
    name: 'nodeSignature',
    id: config.oids.extensions.nodeSignature,
    critical: true,
    value: asn1.create(
      asn1.Class.APPLICATION,
      asn1.Type.OCTETSTRING, // or asn1.type.IA5STRING
      false,
      nodeSignature,
    ),
  });

I'm looking for a way to create a custom extension with this library.

I found that most of the extensions classes extend the Extension class.

However they all seem to take values that are already encoded ASN1 objects as buffer sources.

The @peculiar/asn1-schema doesn't have a lot of documentation. The only example is KeyUsage which ends up using @peculiar/asn1-x509 https://github.com/PeculiarVentures/asn1-schema/blob/master/packages/x509/src/extensions/key_usage.ts. But it's not clear if BitString is supposed to be a raw byte string that is already encoded.

Is there an ASN1 builder available to be used here that can do the above?

@CMCDragonkai
Copy link
Author

I have found that it's possible to do this:

import * as asn1js from 'asn1js';

const stringPrimitive = new asn1js.IA5String({
  value: 'abc',
  idBlock: {
    tagClass: 0x56,
    tagNumber: 22
  }
});

const stringPrimitiveEncoded = stringPrimitive.toBER();

This ends up creating the IA5String value I'm looking for.

One thing I noticed is that using the @AsnProp decorators, I end up with a sequence all the time.

If I use AsnTypeTypes.Choice I get what I want, but I just want a primitive structure here.

How does one use asn1-schema to set the APPLICATION class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant