How to use the asn1.js.define function in asn1

To help you get started, we’ve selected a few asn1 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dstucrypt / jkurwa / lib / spec / dstszi2010.js View on Github external
/**
  http://tools.ietf.org/html/rfc2315#section-9.1

  SignedData ::= SEQUENCE {
    version Version,
    digestAlgorithms DigestAlgorithmIdentifiers,
    contentInfo ContentInfo,
    certificates
       [0] IMPLICIT ExtendedCertificatesAndCertificates
         OPTIONAL,
    crls
      [1] IMPLICIT CertificateRevocationLists OPTIONAL,
    signerInfos SignerInfos }
*/
var SignedData = asn1.define('SignedData', function() {
    this.seq().obj(
        this.key('version').int(),
        this.key('digestAlgorithms').use(DigestAlgorithmIdentifiers),
        this.key('contentInfo').use(ContentInfo),
        this.key('certificate').optional().implicit(0).use(Certificates),
        this.key('crls').optional().implicit(1).set(), // NOT PARSED
        this.key('signerInfos').use(SignerInfos)
    );
});


var RecipientKeyIdentifier = asn1.define('RecipientKeyIdentifier', function() {
    this.seq().obj(
        this.key('subjectKeyIdentifier').octstr(),
        this.key('date').use(rfc3280.Time).optional(),
        this.key('other').optional().any()
github blockstack / key-encoder-js / src / key-encoder.ts View on Github external
import { ec as EC } from 'elliptic'
// @ts-ignore
import * as asn1 from 'asn1.js'
const BN = require('bn.js')

/**
 * Use types for the `bn.js` lib, e.g. `@types/bn.js`
 */
type BNjs = any

const ECPrivateKeyASN = asn1.define('ECPrivateKey', function () {
    // @ts-ignore
    const self = this as any
    self.seq().obj(
        self.key('version').int(),
        self.key('privateKey').octstr(),
        self.key('parameters').explicit(0).objid().optional(),
        self.key('publicKey').explicit(1).bitstr().optional()
    )
})

const SubjectPublicKeyInfoASN = asn1.define('SubjectPublicKeyInfo', function () {
    // @ts-ignore
    const self = this as any
    self.seq().obj(
        self.key('algorithm').seq().obj(
            self.key("id").objid(),
github jamesshore / lets_code_javascript / node_modules / browserify / node_modules / crypto-browserify / node_modules / public-encrypt / node_modules / parse-asn1 / node_modules / asn1.js / rfc / 3280 / index.js View on Github external
// TODO(indutny): validate that version is v3
    this.key('extensions').optional().explicit(3).use(Extensions)
  );
});
exports.TBSCertificate = TBSCertificate;

var Version = asn1.define('Version', function() {
  this.int({
    0: 'v1',
    1: 'v2',
    2: 'v3'
  });
});
exports.Version = Version;

var CertificateSerialNumber = asn1.define('CertificateSerialNumber',
                                          function() {
  this.int();
});
exports.CertificateSerialNumber = CertificateSerialNumber;

var Validity = asn1.define('Validity', function() {
  this.seq().obj(
    this.key('notBefore').use(Time),
    this.key('notAfter').use(Time)
  );
});
exports.Validity = Validity;

var Time = asn1.define('Time', function() {
  this.choice({
    utcTime: this.utctime(),
github anvilresearch / webcrypto / src / asn1 / ECDSA.js View on Github external
});
  text = text.slice(1, -1).join('');
  return new Buffer(text.replace(/[^\w\d\+\/=]+/g, ''), 'base64');
}

var ECDSAPublicKey = asn.define('ECDSAPublicKey', function () {
  this.seq().obj(
    /*this.key('ECpoint').octstr()
      /*
      // TODO Figure out this format/sequence
      this.key('x').int(),
      this.key('y').int()*/
  )
})

var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  this.seq().obj(
    this.key('algorithm').objid(),
    this.key('parameters').optional().any()
  )
})

var PublicKeyInfo = asn.define('PublicKeyInfo', function () {
  this.seq().obj(
    this.key('algorithm').use(AlgorithmIdentifier),
    this.key('subjectPublicKey').bitstr()
  )
})

var Version = asn.define('Version', function () {
  this.int({
    0: 'two-prime',
github tlsnotary / pagesigner / webextension / content / verifychain / verifychain.js View on Github external
this.seqof(RelativeDistinguishedName);
});

var RelativeDistinguishedName = asn1.define('RelativeDistinguishedName',
                                            function() {
  this.setof(AttributeTypeAndValue);
});

var AttributeTypeAndValue = asn1.define('AttributeTypeAndValue', function() {
  this.seq().obj(
    this.key('type').use(AttributeType),
    this.key('value').use(AttributeValue)
  );
});

var AttributeType = asn1.define('AttributeType', function() {
  this.objid();
});

var AttributeValue = asn1.define('AttributeValue', function() {
  this.any();
});
//-----END copied from https://github.com/indutny/asn1.js/blob/master/rfc/3280/index.js


function pem2der(certpem){
	var lines = certpem.split('\n');
	var stripped = ''; //strip ascii armor and newlines
	for(var i = 1; i < lines.length-2; i++){
	  stripped += lines[i];
	}
	stripped = stripped.replace(/\n/g, '');
github jamesshore / automatopia / node_modules / browserify / node_modules / crypto-browserify / node_modules / browserify-sign / node_modules / parse-asn1 / node_modules / asn1.js / rfc / 2560 / index.js View on Github external
this.key('responses').seqof(SingleResponse),
    this.key('responseExtensions').optional().explicit(0)
        .use(rfc5280.Extensions)
  );
});
exports.ResponseData = ResponseData;

var ResponderID = asn1.define('ResponderId', function() {
  this.choice({
    byName: this.explicit(1).use(rfc5280.Name),
    byKey: this.explicit(2).use(KeyHash)
  });
});
exports.ResponderID = ResponderID;

var KeyHash = asn1.define('KeyHash', function() {
  this.octstr();
});
exports.KeyHash = KeyHash;

var SingleResponse = asn1.define('SingleResponse', function() {
  this.seq().obj(
    this.key('certId').use(CertID),
    this.key('certStatus').use(CertStatus),
    this.key('thisUpdate').gentime(),
    this.key('nextUpdate').optional().explicit(0).gentime(),
    this.key('singleExtensions').optional().explicit(1).use(rfc5280.Extensions)
  );
});
exports.SingleResponse = SingleResponse;

var CertStatus = asn1.define('CertStatus', function() {
github tlsnotary / pagesigner / webextension / content / verifychain / verifychain.js View on Github external
'use strict';

var asn1 = require('asn1.js');
var Buffer = require('buffer').Buffer;
var origcerts = certs;

//--------BEGIN copied from https://github.com/indutny/asn1.js/blob/master/rfc/3280/index.js
var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function() {
  this.seq().obj(
    this.key('algorithm').objid(),
    this.key('parameters').optional().any()
  );
});

var Certificate = asn1.define('Certificate', function() {
  this.seq().obj(
    this.key('tbsCertificate').use(TBSCertificate),
    this.key('signatureAlgorithm').use(AlgorithmIdentifier),
    this.key('signature').bitstr()
  );
});

const BasicConstraints = asn1.define('BasicConstraints', function() {
  this.seq().obj(
github anvilresearch / webcrypto / src / asn1 / RSA.js View on Github external
var Version = asn.define('Version', function () {
  this.int({
    0: 'two-prime',
    1: 'multi'
  })
})

var OtherPrimeInfos = asn.define('OtherPrimeInfos', function () {
  this.seq().obj(
    this.key('ri').int(),
    this.key('di').int(),
    this.key('ti').int()
  )
})

let RSAPublicKey = asn.define('RSAPublicKey', function () {
  this.seq().obj(
    this.key('n').int(),
    this.key('e').int()
  )
})

var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  this.seq().obj(
    this.key('algorithm').objid(),
    this.key('parameters').optional().any()
  )
})



var RSAPrivateKey = asn.define('RSAPrivateKey', function () {
github sx1989827 / DOClever / node_modules / parse-asn1 / asn1.js View on Github external
this.key('p').int(),
      this.key('q').int(),
      this.key('g').int()
    ).optional()
  )
})

var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  this.seq().obj(
    this.key('version').int(),
    this.key('algorithm').use(AlgorithmIdentifier),
    this.key('subjectPrivateKey').octstr()
  )
})
exports.PrivateKey = PrivateKeyInfo
var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  this.seq().obj(
    this.key('algorithm').seq().obj(
      this.key('id').objid(),
      this.key('decrypt').seq().obj(
        this.key('kde').seq().obj(
          this.key('id').objid(),
          this.key('kdeparams').seq().obj(
            this.key('salt').octstr(),
            this.key('iters').int()
          )
        ),
        this.key('cipher').seq().obj(
          this.key('algo').objid(),
          this.key('iv').octstr()
        )
      )
github jamesshore / lets_code_javascript / node_modules / browserify / node_modules / crypto-browserify / node_modules / public-encrypt / node_modules / parse-asn1 / node_modules / asn1.js / rfc / 3280 / index.js View on Github external
exports.UniqueIdentifier = UniqueIdentifier;

var SubjectPublicKeyInfo = asn1.define('SubjectPublicKeyInfo', function() {
  this.seq().obj(
    this.key('algorithm').use(AlgorithmIdentifier),
    this.key('subjectPublicKey').bitstr()
  );
});
exports.SubjectPublicKeyInfo = SubjectPublicKeyInfo;

var Extensions = asn1.define('Extensions', function() {
  this.seqof(Extension);
});
exports.Extensions = Extensions;

var Extension = asn1.define('Extension', function() {
  this.seq().obj(
    this.key('extnID').objid(),
    this.key('critical').bool().def(false),
    this.key('extnValue').octstr()
  );
});
exports.Extension = Extension;

var Name = asn1.define('Name', function() {
  this.choice({
    rdn: this.use(RDNSequence)
  });
});
exports.Name = Name;

var RDNSequence = asn1.define('RDNSequence', function() {