@@ -68,6 +68,10 @@ export function parseCACerts(
68
68
try {
69
69
parsed = new X509Certificate ( pem ) ;
70
70
} catch ( err : unknown ) {
71
+ // Most definitely should happen never or extremely rarely, in case it
72
+ // does, if this cert will affect the TLS connection verification, the
73
+ // connection will most definitely fail and we'll se it in the logs. For
74
+ // that reason we're just logging, but not throwing an error here
71
75
messages . push (
72
76
`Unable to parse certificate: ${
73
77
err && typeof err === 'object' && 'message' in err
@@ -80,15 +84,14 @@ export function parseCACerts(
80
84
} ) ;
81
85
}
82
86
83
- function doesCertificateHasMatchingIssuer (
84
- { parsed } : ParsedX509Cert ,
87
+ function certificateHasMatchingIssuer (
88
+ cert : X509Certificate ,
85
89
certs : ParsedX509Cert [ ]
86
90
) {
87
91
return (
88
- ! parsed ||
89
- parsed . checkIssued ( parsed ) ||
92
+ cert . checkIssued ( cert ) ||
90
93
certs . some ( ( { parsed : issuer } ) => {
91
- return issuer && parsed . checkIssued ( issuer ) ;
94
+ return issuer && cert . checkIssued ( issuer ) ;
92
95
} )
93
96
) ;
94
97
}
@@ -123,7 +126,11 @@ export function removeCertificatesWithoutIssuer(
123
126
124
127
const _messages : string [ ] = [ ] ;
125
128
const filteredCAlist = ca . filter ( ( cert ) => {
126
- const keep = doesCertificateHasMatchingIssuer ( cert , ca ) ;
129
+ // If cert was not parsed, we want to keep it in the list. The case should
130
+ // be generally very rare, but in case it happens and this cert will affect
131
+ // the TLS handshake, it will show up in the logs as the connection error
132
+ // anyway, so it's safe to keep it
133
+ const keep = ! cert . parsed || certificateHasMatchingIssuer ( cert . parsed , ca ) ;
127
134
if ( ! keep && cert . parsed ) {
128
135
const { parsed } = cert ;
129
136
_messages . push (
0 commit comments