createCertificate.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const selfsigned = require('selfsigned');
  3. function createCertificate(attrs) {
  4. return selfsigned.generate(attrs, {
  5. algorithm: 'sha256',
  6. days: 30,
  7. keySize: 2048,
  8. extensions: [
  9. {
  10. name: 'basicConstraints',
  11. cA: true,
  12. },
  13. {
  14. name: 'keyUsage',
  15. keyCertSign: true,
  16. digitalSignature: true,
  17. nonRepudiation: true,
  18. keyEncipherment: true,
  19. dataEncipherment: true,
  20. },
  21. {
  22. name: 'subjectAltName',
  23. altNames: [
  24. {
  25. // type 2 is DNS
  26. type: 2,
  27. value: 'localhost',
  28. },
  29. {
  30. type: 2,
  31. value: 'localhost.localdomain',
  32. },
  33. {
  34. type: 2,
  35. value: 'lvh.me',
  36. },
  37. {
  38. type: 2,
  39. value: '*.lvh.me',
  40. },
  41. {
  42. type: 2,
  43. value: '[::1]',
  44. },
  45. {
  46. // type 7 is IP
  47. type: 7,
  48. ip: '127.0.0.1',
  49. },
  50. {
  51. type: 7,
  52. ip: 'fe80::1',
  53. },
  54. ],
  55. },
  56. ],
  57. });
  58. }
  59. module.exports = createCertificate;