@@ -33,10 +33,12 @@ export function getCertNotBefore(): Date {
33
33
* @returns The Not After Date for the Certificate
34
34
*/
35
35
export function getCertNotAfter ( notBefore : Date ) : Date {
36
- const ninetyDaysLater = new Date ( notBefore . getTime ( ) + 60 * 60 * 24 * 90 * 1000 )
37
- const year = ninetyDaysLater . getFullYear ( )
38
- const month = ( ninetyDaysLater . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , '0' )
39
- const day = ninetyDaysLater . getDate ( ) . toString ( ) . padStart ( 2 , '0' )
36
+ const validityDays = config . validityDays // defaults to 180 days
37
+ const daysInMillis = validityDays * 60 * 60 * 24 * 1000
38
+ const notAfterDate = new Date ( notBefore . getTime ( ) + daysInMillis )
39
+ const year = notAfterDate . getFullYear ( )
40
+ const month = ( notAfterDate . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , '0' )
41
+ const day = notAfterDate . getDate ( ) . toString ( ) . padStart ( 2 , '0' )
40
42
41
43
return new Date ( `${ year } -${ month } -${ day } T23:59:59Z` )
42
44
}
@@ -54,11 +56,6 @@ export function getCANotAfter(notBefore: Date): Date {
54
56
return new Date ( `${ year } -${ month } -${ day } T23:59:59Z` )
55
57
}
56
58
57
- export const DEFAULT_C = 'US'
58
- export const DEFAULT_ST = 'California'
59
- export const DEFAULT_L = 'Playa Vista'
60
- export const DEFAULT_O : string = config ?. organizationName ?? 'stacksjs.org'
61
-
62
59
/**
63
60
* Create a new Root CA Certificate
64
61
* @returns The Root CA Certificate
@@ -69,10 +66,10 @@ export async function createRootCA(): Promise<GenerateCertReturn> {
69
66
70
67
// Define the attributes for the new Root CA
71
68
const attributes = [
72
- { shortName : 'C' , value : DEFAULT_C } ,
73
- { shortName : 'ST' , value : DEFAULT_ST } ,
74
- { shortName : 'L' , value : DEFAULT_L } ,
75
- { shortName : 'CN' , value : DEFAULT_O } ,
69
+ { shortName : 'C' , value : config . countryName } ,
70
+ { shortName : 'ST' , value : config . stateName } ,
71
+ { shortName : 'L' , value : config . localityName } ,
72
+ { shortName : 'CN' , value : config . commonName } ,
76
73
]
77
74
78
75
const extensions = [
@@ -132,10 +129,10 @@ export async function generateCert(options?: CertOption): Promise<GenerateCertRe
132
129
133
130
// Define the attributes/properties for the Host Certificate
134
131
const attributes = [
135
- { shortName : 'C' , value : DEFAULT_C } ,
136
- { shortName : 'ST' , value : DEFAULT_ST } ,
137
- { shortName : 'L' , value : DEFAULT_L } ,
138
- { shortName : 'CN' , value : DEFAULT_O } ,
132
+ { shortName : 'C' , value : config . countryName } ,
133
+ { shortName : 'ST' , value : config . stateName } ,
134
+ { shortName : 'L' , value : config . localityName } ,
135
+ { shortName : 'CN' , value : config . commonName } ,
139
136
]
140
137
141
138
const extensions = [
@@ -205,15 +202,15 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
205
202
for ( const folder of foldersWithFile ) {
206
203
try {
207
204
// delete existing cert from system trust store
208
- await runCommand ( `certutil -d sql:${ folder } -D -n ${ DEFAULT_O } ` )
205
+ await runCommand ( `certutil -d sql:${ folder } -D -n ${ config . commonName } ` )
209
206
}
210
207
catch ( error ) {
211
208
// ignore error if no cert exists
212
209
console . warn ( `Error deleting existing cert: ${ error } ` )
213
210
}
214
211
215
212
// add new cert to system trust store
216
- await runCommand ( `certutil -d sql:${ folder } -A -t ${ args } -n ${ DEFAULT_O } -i ${ caCertPath } ` )
213
+ await runCommand ( `certutil -d sql:${ folder } -A -t ${ args } -n ${ config . commonName } -i ${ caCertPath } ` )
217
214
218
215
log . info ( `Cert added to ${ folder } ` )
219
216
}
@@ -222,13 +219,13 @@ export async function addCertToSystemTrustStoreAndSaveCerts(
222
219
// `sudo cp ${certPath} /usr/local/share/ca-certificates/`,
223
220
224
221
// // add new cert to system trust store
225
- // `certutil -d sql:${os.homedir()}/.pki/nssdb -A -t ${args} -n ${DEFAULT_O } -i ${caCertPath}`,
222
+ // `certutil -d sql:${os.homedir()}/.pki/nssdb -A -t ${args} -n ${config.commonName } -i ${caCertPath}`,
226
223
227
224
// // add new cert to system trust store for Brave
228
- // `certutil -d sql:${os.homedir()}/snap/brave/411/.pki/nssdb -A -t ${args} -n ${DEFAULT_O } -i ${caCertPath}`,
225
+ // `certutil -d sql:${os.homedir()}/snap/brave/411/.pki/nssdb -A -t ${args} -n ${config.commonName } -i ${caCertPath}`,
229
226
230
227
// // add new cert to system trust store for Firefox
231
- // `certutil -d sql:${os.homedir()}/snap/firefox/common/.mozilla/firefox/3l148raz.default -A -t ${args} -n ${DEFAULT_O } -i ${caCertPath}`,
228
+ // `certutil -d sql:${os.homedir()}/snap/firefox/common/.mozilla/firefox/3l148raz.default -A -t ${args} -n ${config.commonName } -i ${caCertPath}`,
232
229
233
230
// // reload system trust store
234
231
// `sudo update-ca-certificates`,
0 commit comments