certificate.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/parse-asn1/certificate.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}// from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  12. // thanks to @Rantanen
  13. 'use strict'
  14. var asn = require('asn1.js')
  15. var Time = asn.define('Time', function () {
  16. this.choice({
  17. utcTime: this.utctime(),
  18. generalTime: this.gentime()
  19. })
  20. })
  21. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  22. this.seq().obj(
  23. this.key('type').objid(),
  24. this.key('value').any()
  25. )
  26. })
  27. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  28. this.seq().obj(
  29. this.key('algorithm').objid(),
  30. this.key('parameters').optional(),
  31. this.key('curve').objid().optional()
  32. )
  33. })
  34. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  35. this.seq().obj(
  36. this.key('algorithm').use(AlgorithmIdentifier),
  37. this.key('subjectPublicKey').bitstr()
  38. )
  39. })
  40. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  41. this.setof(AttributeTypeValue)
  42. })
  43. var RDNSequence = asn.define('RDNSequence', function () {
  44. this.seqof(RelativeDistinguishedName)
  45. })
  46. var Name = asn.define('Name', function () {
  47. this.choice({
  48. rdnSequence: this.use(RDNSequence)
  49. })
  50. })
  51. var Validity = asn.define('Validity', function () {
  52. this.seq().obj(
  53. this.key('notBefore').use(Time),
  54. this.key('notAfter').use(Time)
  55. )
  56. })
  57. var Extension = asn.define('Extension', function () {
  58. this.seq().obj(
  59. this.key('extnID').objid(),
  60. this.key('critical').bool().def(false),
  61. this.key('extnValue').octstr()
  62. )
  63. })
  64. var TBSCertificate = asn.define('TBSCertificate', function () {
  65. this.seq().obj(
  66. this.key('version').explicit(0).int().optional(),
  67. this.key('serialNumber').int(),
  68. this.key('signature').use(AlgorithmIdentifier),
  69. this.key('issuer').use(Name),
  70. this.key('validity').use(Validity),
  71. this.key('subject').use(Name),
  72. this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo),
  73. this.key('issuerUniqueID').implicit(1).bitstr().optional(),
  74. this.key('subjectUniqueID').implicit(2).bitstr().optional(),
  75. this.key('extensions').explicit(3).seqof(Extension).optional()
  76. )
  77. })
  78. var X509Certificate = asn.define('X509Certificate', function () {
  79. this.seq().obj(
  80. this.key('tbsCertificate').use(TBSCertificate),
  81. this.key('signatureAlgorithm').use(AlgorithmIdentifier),
  82. this.key('signatureValue').bitstr()
  83. )
  84. })
  85. module.exports = X509Certificate
  86. }
  87. if (nodeEnv) {
  88. __define(__module.exports, __require, __module);
  89. }
  90. else {
  91. __quick_compile_project__.registerModuleFunc(__filename, function () {
  92. __define(__module.exports, __require, __module);
  93. });
  94. }
  95. })();