You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

66 lines
1.2 KiB

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