@@ -64,7 +64,9 @@ export async function generateCACertificate(options: {
64
64
organizationName ?: string ,
65
65
countryName ?: string ,
66
66
bits ?: number ,
67
- contrainToDomains ?: string [ ]
67
+ nameConstraints ?: {
68
+ permitted ?: string [ ]
69
+ }
68
70
} = { } ) {
69
71
options = _ . defaults ( { } , options , {
70
72
commonName : 'Mockttp Testing CA - DO NOT TRUST - TESTING ONLY' ,
@@ -104,12 +106,13 @@ export async function generateCACertificate(options: {
104
106
{ name : 'keyUsage' , keyCertSign : true , digitalSignature : true , nonRepudiation : true , cRLSign : true , critical : true } ,
105
107
{ name : 'subjectKeyIdentifier' } ,
106
108
] ;
107
- if ( options . contrainToDomains && options . contrainToDomains . length > 0 ) {
109
+ const permittedDomains = options . nameConstraints ?. permitted || [ ] ;
110
+ if ( permittedDomains . length > 0 ) {
108
111
extensions . push ( {
109
112
critical : true ,
110
113
name : 'nameConstraints' ,
111
114
value : generateNameConstraints ( {
112
- permitted : options . contrainToDomains ,
115
+ permitted : permittedDomains ,
113
116
} ) ,
114
117
} )
115
118
}
@@ -129,11 +132,6 @@ export async function generateCACertificate(options: {
129
132
130
133
131
134
type GenerateNameConstraintsInput = {
132
- /**
133
- * Array of excluded domains
134
- */
135
- excluded ?: string [ ] ;
136
-
137
135
/**
138
136
* Array of permitted domains
139
137
*/
@@ -147,7 +145,7 @@ type GenerateNameConstraintsInput = {
147
145
function generateNameConstraints (
148
146
input : GenerateNameConstraintsInput
149
147
) : forge . asn1 . Asn1 {
150
- const ipsToSequence = ( ips : string [ ] ) =>
148
+ const domainsToSequence = ( ips : string [ ] ) =>
151
149
ips . map ( ( domain ) => {
152
150
return asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
153
151
asn1 . create (
@@ -161,24 +159,13 @@ function generateNameConstraints(
161
159
162
160
const permittedAndExcluded : forge . asn1 . Asn1 [ ] = [ ] ;
163
161
164
- if ( input . permitted !== undefined ) {
162
+ if ( input . permitted && input . permitted . length > 0 ) {
165
163
permittedAndExcluded . push (
166
164
asn1 . create (
167
165
asn1 . Class . CONTEXT_SPECIFIC ,
168
166
0 ,
169
167
true ,
170
- ipsToSequence ( input . permitted )
171
- )
172
- ) ;
173
- }
174
-
175
- if ( input . excluded !== undefined ) {
176
- permittedAndExcluded . push (
177
- asn1 . create (
178
- asn1 . Class . CONTEXT_SPECIFIC ,
179
- 1 ,
180
- true ,
181
- ipsToSequence ( input . excluded )
168
+ domainsToSequence ( input . permitted )
182
169
)
183
170
) ;
184
171
}
0 commit comments