@@ -21299,14 +21299,19 @@ print_dn() {
2129921299# distinguished names that are in the CA list.
2130021300extract_calist() {
2130121301 local response="$1"
21302- local is_tls13=false
21302+ local is_tls12=false is_tls13=false
2130321303 local certreq calist="" certtypes sigalgs dn
2130421304 local calist_string=""
2130521305 local -i len type
2130621306
21307- # Determine whether this is a TLS 1.3 response, since the information
21308- # is encoded in a different place for TLS 1.3.
21309- [[ "$response" =~ \<\<\<\ TLS\ 1.3[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]] && is_tls13=true
21307+ # Determine whether this is a TLS 1.2 or TLS 1.3 response, since the information
21308+ # is encoded in a different place for TLS 1.3 and the CertificateRequest message
21309+ # differs between TLS 1.2 and TLS 1.1 and earlier.
21310+ if [[ "$response" =~ \<\<\<\ TLS\ 1.3[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]]; then
21311+ is_tls13=true
21312+ elif [[ "$response" =~ \<\<\<\ TLS\ 1.2[\,]?\ Handshake\ \[length\ [0-9a-fA-F]*\]\,\ CertificateRequest ]]; then
21313+ is_tls12=true
21314+ fi
2131021315
2131121316 # Extract just the CertificateRequest message as an ASCII-HEX string.
2131221317 certreq="${response##*CertificateRequest}"
@@ -21342,15 +21347,17 @@ extract_calist() {
2134221347 # struct {
2134321348 # ClientCertificateType certificate_types<1..2^8-1>;
2134421349 # SignatureAndHashAlgorithm
21345- # supported_signature_algorithms<2^16-1>;
21350+ # supported_signature_algorithms<2^16-1>; - only present in TLS 1.2
2134621351 # DistinguishedName certificate_authorities<0..2^16-1>;
2134721352 # } CertificateRequest;
2134821353 len=2*$(hex2dec "${certreq:0:2}")
2134921354 certtypes="${certreq:2:len}"
2135021355 certreq="${certreq:$((len+2))}"
21351- len=2*$(hex2dec "${certreq:0:4}")
21352- sigalgs="${certreq:4:len}"
21353- certreq="${certreq:$((len+4))}"
21356+ if "$is_tls12"; then
21357+ len=2*$(hex2dec "${certreq:0:4}")
21358+ sigalgs="${certreq:4:len}"
21359+ certreq="${certreq:$((len+4))}"
21360+ fi
2135421361 len=2*$(hex2dec "${certreq:0:4}")
2135521362 calist="${certreq:4:len}"
2135621363 fi
0 commit comments