Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Server): move certificate generation to it's own file
- Loading branch information
1 parent
1896fcf
commit 4789ac3
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
space-before-function-paren | ||
*/ | ||
const selfsigned = require('selfsigned'); | ||
|
||
function createCertificate (attrs) { | ||
return selfsigned.generate(attrs, { | ||
algorithm: 'sha256', | ||
days: 30, | ||
keySize: 2048, | ||
extensions: [ | ||
{ | ||
name: 'basicConstraints', | ||
cA: true | ||
}, | ||
{ | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, | ||
{ | ||
name: 'subjectAltName', | ||
altNames: [ | ||
{ | ||
// type 2 is DNS | ||
type: 2, | ||
value: 'localhost' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'localhost.localdomain' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '*.lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '[::1]' | ||
}, | ||
{ | ||
// type 7 is IP | ||
type: 7, | ||
ip: '127.0.0.1' | ||
}, | ||
{ | ||
type: 7, | ||
ip: 'fe80::1' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
} | ||
|
||
module.exports = createCertificate; |