UI for Zipcoin Blue

certificate.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  2. // thanks to @Rantanen
  3. 'use strict'
  4. var asn = require('asn1.js')
  5. var Time = asn.define('Time', function () {
  6. this.choice({
  7. utcTime: this.utctime(),
  8. generalTime: this.gentime()
  9. })
  10. })
  11. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  12. this.seq().obj(
  13. this.key('type').objid(),
  14. this.key('value').any()
  15. )
  16. })
  17. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  18. this.seq().obj(
  19. this.key('algorithm').objid(),
  20. this.key('parameters').optional()
  21. )
  22. })
  23. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  24. this.seq().obj(
  25. this.key('algorithm').use(AlgorithmIdentifier),
  26. this.key('subjectPublicKey').bitstr()
  27. )
  28. })
  29. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  30. this.setof(AttributeTypeValue)
  31. })
  32. var RDNSequence = asn.define('RDNSequence', function () {
  33. this.seqof(RelativeDistinguishedName)
  34. })
  35. var Name = asn.define('Name', function () {
  36. this.choice({
  37. rdnSequence: this.use(RDNSequence)
  38. })
  39. })
  40. var Validity = asn.define('Validity', function () {
  41. this.seq().obj(
  42. this.key('notBefore').use(Time),
  43. this.key('notAfter').use(Time)
  44. )
  45. })
  46. var Extension = asn.define('Extension', function () {
  47. this.seq().obj(
  48. this.key('extnID').objid(),
  49. this.key('critical').bool().def(false),
  50. this.key('extnValue').octstr()
  51. )
  52. })
  53. var TBSCertificate = asn.define('TBSCertificate', function () {
  54. this.seq().obj(
  55. this.key('version').explicit(0).int(),
  56. this.key('serialNumber').int(),
  57. this.key('signature').use(AlgorithmIdentifier),
  58. this.key('issuer').use(Name),
  59. this.key('validity').use(Validity),
  60. this.key('subject').use(Name),
  61. this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo),
  62. this.key('issuerUniqueID').implicit(1).bitstr().optional(),
  63. this.key('subjectUniqueID').implicit(2).bitstr().optional(),
  64. this.key('extensions').explicit(3).seqof(Extension).optional()
  65. )
  66. })
  67. var X509Certificate = asn.define('X509Certificate', function () {
  68. this.seq().obj(
  69. this.key('tbsCertificate').use(TBSCertificate),
  70. this.key('signatureAlgorithm').use(AlgorithmIdentifier),
  71. this.key('signatureValue').bitstr()
  72. )
  73. })
  74. module.exports = X509Certificate