createCertificate.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. const selfsigned = require('selfsigned');
  3. function createCertificate(attributes) {
  4. return selfsigned.generate(attributes, {
  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: 'extKeyUsage',
  23. serverAuth: true,
  24. clientAuth: true,
  25. codeSigning: true,
  26. timeStamping: true,
  27. },
  28. {
  29. name: 'subjectAltName',
  30. altNames: [
  31. {
  32. // type 2 is DNS
  33. type: 2,
  34. value: 'localhost',
  35. },
  36. {
  37. type: 2,
  38. value: 'localhost.localdomain',
  39. },
  40. {
  41. type: 2,
  42. value: 'lvh.me',
  43. },
  44. {
  45. type: 2,
  46. value: '*.lvh.me',
  47. },
  48. {
  49. type: 2,
  50. value: '[::1]',
  51. },
  52. {
  53. // type 7 is IP
  54. type: 7,
  55. ip: '127.0.0.1',
  56. },
  57. {
  58. type: 7,
  59. ip: 'fe80::1',
  60. },
  61. ],
  62. },
  63. ],
  64. });
  65. }
  66. module.exports = createCertificate;