@@ -60,19 +60,27 @@ export type GeneratedCertificate = {
6060 * as HTTPS options to a Mockttp server.
6161 */
6262export async function generateCACertificate ( options : {
63- commonName ?: string ,
64- organizationName ?: string ,
65- countryName ?: string ,
63+ subject ?: {
64+ commonName ?: string ,
65+ organizationName ?: string ,
66+ countryName ?: string ,
67+ [ key : string ] : string | undefined // Add any other subject field you like
68+ } ,
6669 bits ?: number ,
6770 nameConstraints ?: {
6871 permitted ?: string [ ]
6972 }
7073} = { } ) {
7174 options = _ . defaults ( { } , options , {
75+ bits : 2048 ,
76+ } ) ;
77+
78+ const subjectOptions = _ . defaults ( { } , options . subject , {
79+ // These subject fields are required for a fully valid CA cert that will be
80+ // accepted when imported anywhere:
7281 commonName : 'Mockttp Testing CA - DO NOT TRUST - TESTING ONLY' ,
7382 organizationName : 'Mockttp' ,
7483 countryName : 'XX' , // ISO-3166-1 alpha-2 'unknown country' code
75- bits : 2048 ,
7684 } ) ;
7785
7886 const keyPair = await new Promise < forge . pki . rsa . KeyPair > ( ( resolve , reject ) => {
@@ -94,12 +102,10 @@ export async function generateCACertificate(options: {
94102 // Valid for the next year by default.
95103 cert . validity . notAfter . setFullYear ( cert . validity . notAfter . getFullYear ( ) + 1 ) ;
96104
97- cert . setSubject ( [
98- // All of these are required for a fully valid CA cert that will be accepted when imported anywhere:
99- { name : 'commonName' , value : options . commonName } ,
100- { name : 'countryName' , value : options . countryName } ,
101- { name : 'organizationName' , value : options . organizationName }
102- ] ) ;
105+ cert . setSubject ( Object . entries ( subjectOptions ) . map ( ( [ key , value ] ) => ( {
106+ name : key ,
107+ value : value
108+ } ) ) ) ;
103109
104110 const extensions : any [ ] = [
105111 { name : 'basicConstraints' , cA : true , critical : true } ,
0 commit comments