29
29
import org .apache .tomcat .util .buf .HexUtils ;
30
30
import org .apache .tomcat .util .http .parser .HttpParser ;
31
31
import org .apache .tomcat .util .net .openssl .ciphers .Cipher ;
32
+ import org .apache .tomcat .util .net .openssl .ciphers .Group ;
33
+ import org .apache .tomcat .util .net .openssl .ciphers .SignatureAlgorithm ;
32
34
import org .apache .tomcat .util .res .StringManager ;
33
35
34
36
/**
@@ -45,10 +47,14 @@ public class TLSClientHelloExtractor {
45
47
private final String sniValue ;
46
48
private final List <String > clientRequestedApplicationProtocols ;
47
49
private final List <String > clientRequestedProtocols ;
50
+ private final List <Group > clientSupportedGroups ;
51
+ private final List <SignatureAlgorithm > clientSignatureAlgorithms ;
48
52
49
53
private static final int TLS_RECORD_HEADER_LEN = 5 ;
50
54
51
55
private static final int TLS_EXTENSION_SERVER_NAME = 0 ;
56
+ private static final int TLS_EXTENSION_SUPPORTED_GROUPS = 10 ;
57
+ private static final int TLS_EXTENSION_SIGNATURE_ALGORITHMS = 13 ;
52
58
private static final int TLS_EXTENSION_ALPN = 16 ;
53
59
private static final int TLS_EXTENSION_SUPPORTED_VERSION = 43 ;
54
60
@@ -77,6 +83,8 @@ public TLSClientHelloExtractor(ByteBuffer netInBuffer) throws IOException {
77
83
List <String > clientRequestedCipherNames = new ArrayList <>();
78
84
List <String > clientRequestedApplicationProtocols = new ArrayList <>();
79
85
List <String > clientRequestedProtocols = new ArrayList <>();
86
+ List <Group > clientSupportedGroups = new ArrayList <>();
87
+ List <SignatureAlgorithm > clientSignatureAlgorithms = new ArrayList <>();
80
88
String sniValue = null ;
81
89
try {
82
90
// Switch to read mode.
@@ -158,6 +166,12 @@ public TLSClientHelloExtractor(ByteBuffer netInBuffer) throws IOException {
158
166
sniValue = readSniExtension (netInBuffer );
159
167
break ;
160
168
}
169
+ case TLS_EXTENSION_SUPPORTED_GROUPS :
170
+ readSupportedGroups (netInBuffer , clientSupportedGroups );
171
+ break ;
172
+ case TLS_EXTENSION_SIGNATURE_ALGORITHMS :
173
+ readSignatureAlgorithms (netInBuffer , clientSignatureAlgorithms );
174
+ break ;
161
175
case TLS_EXTENSION_ALPN :
162
176
readAlpnExtension (netInBuffer , clientRequestedApplicationProtocols );
163
177
break ;
@@ -182,6 +196,14 @@ public TLSClientHelloExtractor(ByteBuffer netInBuffer) throws IOException {
182
196
this .clientRequestedApplicationProtocols = clientRequestedApplicationProtocols ;
183
197
this .sniValue = sniValue ;
184
198
this .clientRequestedProtocols = clientRequestedProtocols ;
199
+ this .clientSupportedGroups = clientSupportedGroups ;
200
+ this .clientSignatureAlgorithms = clientSignatureAlgorithms ;
201
+ if (log .isTraceEnabled ()) {
202
+ log .trace ("TLS Client Hello: " + clientRequestedCiphers + " Names " + clientRequestedCipherNames +
203
+ " Protocols " + clientRequestedApplicationProtocols + " sniValue " + sniValue +
204
+ " clientRequestedProtocols " + clientRequestedProtocols + " clientSupportedGroups " + clientSupportedGroups +
205
+ " clientSignatureAlgorithms " + clientSignatureAlgorithms );
206
+ }
185
207
// Whatever happens, return the buffer to its original state
186
208
netInBuffer .limit (limit );
187
209
netInBuffer .position (pos );
@@ -413,6 +435,34 @@ private static void readSupportedVersions(ByteBuffer bb, List<String> protocolNa
413
435
}
414
436
415
437
438
+ private static void readSupportedGroups (ByteBuffer bb , List <Group > groups ) {
439
+ // First 2 bytes are size of the group list
440
+ int toRead = bb .getChar () / 2 ;
441
+ // Then the list of protocols
442
+ for (int i = 0 ; i < toRead ; i ++) {
443
+ char id = bb .getChar ();
444
+ Group group = Group .valueOf (id );
445
+ if (group != null ) {
446
+ groups .add (group );
447
+ }
448
+ }
449
+ }
450
+
451
+
452
+ private static void readSignatureAlgorithms (ByteBuffer bb , List <SignatureAlgorithm > signatureAlgorithms ) {
453
+ // First 2 bytes are size of the signature algorithm list
454
+ int toRead = bb .getChar () / 2 ;
455
+ // Then the list of protocols
456
+ for (int i = 0 ; i < toRead ; i ++) {
457
+ char id = bb .getChar ();
458
+ SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm .valueOf (id );
459
+ if (signatureAlgorithm != null ) {
460
+ signatureAlgorithms .add (signatureAlgorithm );
461
+ }
462
+ }
463
+ }
464
+
465
+
416
466
public enum ExtractorResult {
417
467
COMPLETE ,
418
468
NOT_PRESENT ,
0 commit comments