Skip to content

Commit 6d88e0e

Browse files
authored
Merge pull request SAP#2047 from SAP/pr-jdk-17.0.17+4
Merge to tag jdk-17.0.17+4
2 parents 12c280f + 9b71cd6 commit 6d88e0e

File tree

68 files changed

+4635
-1110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4635
-1110
lines changed

src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.math.BigInteger;
3131
import java.net.InetAddress;
3232
import java.nio.ByteBuffer;
33+
import java.nio.charset.StandardCharsets;
3334
import java.security.Principal;
3435
import java.security.PrivateKey;
3536
import java.security.cert.X509Certificate;
@@ -309,108 +310,85 @@ final class SSLSessionImpl extends ExtendedSSLSession {
309310
SSLSessionImpl(HandshakeContext hc, ByteBuffer buf) throws IOException {
310311
boundValues = new ConcurrentHashMap<>();
311312
this.protocolVersion =
312-
ProtocolVersion.valueOf(Short.toUnsignedInt(buf.getShort()));
313+
ProtocolVersion.valueOf(Record.getInt16(buf));
313314

314315
// The CH session id may reset this if it's provided
315316
this.sessionId = new SessionId(true,
316317
hc.sslContext.getSecureRandom());
317318

318319
this.cipherSuite =
319-
CipherSuite.valueOf(Short.toUnsignedInt(buf.getShort()));
320+
CipherSuite.valueOf(Record.getInt16(buf));
320321

321322
// Local Supported signature algorithms
322323
ArrayList<SignatureScheme> list = new ArrayList<>();
323-
int i = Byte.toUnsignedInt(buf.get());
324+
int i = Record.getInt8(buf);
324325
while (i-- > 0) {
325326
list.add(SignatureScheme.valueOf(
326-
Short.toUnsignedInt(buf.getShort())));
327+
Record.getInt16(buf)));
327328
}
328329
this.localSupportedSignAlgs = Collections.unmodifiableCollection(list);
329330

330331
// Peer Supported signature algorithms
331-
i = Byte.toUnsignedInt(buf.get());
332+
i = Record.getInt8(buf);
332333
list.clear();
333334
while (i-- > 0) {
334335
list.add(SignatureScheme.valueOf(
335-
Short.toUnsignedInt(buf.getShort())));
336+
Record.getInt16(buf)));
336337
}
337338
this.peerSupportedSignAlgs = Collections.unmodifiableCollection(list);
338339

339340
// PSK
340-
byte[] b;
341-
i = Short.toUnsignedInt(buf.getShort());
342-
if (i > 0) {
343-
b = new byte[i];
344-
// Get algorithm string
345-
buf.get(b, 0, i);
346-
// Encoded length
347-
i = Short.toUnsignedInt(buf.getShort());
348-
// Encoded SecretKey
349-
b = new byte[i];
350-
buf.get(b);
341+
byte[] b = Record.getBytes16(buf);
342+
if (b.length > 0) {
343+
b = Record.getBytes16(buf);
351344
this.preSharedKey = new SecretKeySpec(b, "TlsMasterSecret");
352345
} else {
353346
this.preSharedKey = null;
354347
}
355348

356349
// PSK identity
357-
i = buf.get();
358-
if (i > 0) {
359-
b = new byte[i];
360-
buf.get(b);
350+
b = Record.getBytes8(buf);
351+
if (b.length > 0) {
361352
this.pskIdentity = b;
362353
} else {
363354
this.pskIdentity = null;
364355
}
365356

366357
// Master secret length of secret key algorithm (one byte)
367-
i = buf.get();
368-
if (i > 0) {
369-
b = new byte[i];
370-
// Get algorithm string
371-
buf.get(b, 0, i);
372-
// Encoded length
373-
i = Short.toUnsignedInt(buf.getShort());
374-
// Encoded SecretKey
375-
b = new byte[i];
376-
buf.get(b);
358+
b = Record.getBytes8(buf);
359+
if (b.length > 0) {
360+
b = Record.getBytes16(buf);
377361
this.masterSecret = new SecretKeySpec(b, "TlsMasterSecret");
378362
} else {
379363
this.masterSecret = null;
380364
}
381365
// Use extended master secret
382-
this.useExtendedMasterSecret = (buf.get() != 0);
366+
this.useExtendedMasterSecret = (Record.getInt8(buf) != 0);
383367

384368
// Identification Protocol
385-
i = buf.get();
386-
if (i == 0) {
369+
b = Record.getBytes8(buf);
370+
if (b.length == 0) {
387371
identificationProtocol = null;
388372
} else {
389-
b = new byte[i];
390-
buf.get(b);
391373
identificationProtocol = new String(b);
392374
}
393375

394376
// SNI
395-
i = buf.get(); // length
396-
if (i == 0) {
377+
b = Record.getBytes8(buf);
378+
if (b.length == 0) {
397379
serverNameIndication = null;
398380
} else {
399-
b = new byte[i];
400-
buf.get(b, 0, b.length);
401381
serverNameIndication = new SNIHostName(b);
402382
}
403383

404384
// List of SNIServerName
405-
int len = Short.toUnsignedInt(buf.getShort());
385+
int len = Record.getInt16(buf);
406386
if (len == 0) {
407387
this.requestedServerNames = Collections.<SNIServerName>emptyList();
408388
} else {
409389
requestedServerNames = new ArrayList<>();
410390
while (len > 0) {
411-
int l = buf.get();
412-
b = new byte[l];
413-
buf.get(b, 0, l);
391+
b = Record.getBytes8(buf);
414392
requestedServerNames.add(new SNIHostName(new String(b)));
415393
len--;
416394
}
@@ -425,31 +403,28 @@ final class SSLSessionImpl extends ExtendedSSLSession {
425403
// Get Buffer sizes
426404

427405
// Status Response
428-
len = Short.toUnsignedInt(buf.getShort());
406+
len = Record.getInt16(buf);
429407
if (len == 0) {
430408
statusResponses = Collections.emptyList();
431409
} else {
432410
statusResponses = new ArrayList<>();
433411
}
434412
while (len-- > 0) {
435-
b = new byte[Short.toUnsignedInt(buf.getShort())];
436-
buf.get(b);
413+
b = Record.getBytes16(buf);
437414
statusResponses.add(b);
438415
}
439416

440417
// Get Peer host & port
441-
i = Byte.toUnsignedInt(buf.get());
442-
if (i == 0) {
418+
b = Record.getBytes8(buf);
419+
if (b.length == 0) {
443420
this.host = new String();
444421
} else {
445-
b = new byte[i];
446-
buf.get(b, 0, i);
447422
this.host = new String(b);
448423
}
449-
this.port = Short.toUnsignedInt(buf.getShort());
424+
this.port = Record.getInt16(buf);
450425

451426
// Peer certs
452-
i = buf.get();
427+
i = Record.getInt8(buf);
453428
if (i == 0) {
454429
this.peerCerts = null;
455430
} else {
@@ -468,7 +443,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
468443
}
469444

470445
// Get local certs of PSK
471-
switch (buf.get()) {
446+
switch (Record.getInt8(buf)) {
472447
case 0:
473448
break;
474449
case 1:
@@ -490,19 +465,13 @@ final class SSLSessionImpl extends ExtendedSSLSession {
490465
case 2:
491466
// pre-shared key
492467
// Length of pre-shared key algorithm (one byte)
493-
i = buf.get();
494-
b = new byte[i];
495-
buf.get(b, 0 , i);
468+
b = Record.getBytes8(buf);
496469
String alg = new String(b);
497-
// Get length of encoding
498-
i = Short.toUnsignedInt(buf.getShort());
499470
// Get encoding
500-
b = new byte[i];
501-
buf.get(b);
471+
b = Record.getBytes16(buf);
502472
this.preSharedKey = new SecretKeySpec(b, alg);
503473
// Get identity len
504-
this.pskIdentity = new byte[buf.get()];
505-
buf.get(pskIdentity);
474+
this.pskIdentity = Record.getBytes8(buf);
506475
break;
507476
default:
508477
throw new SSLException("Failed local certs of session.");
@@ -513,6 +482,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
513482
this.lastUsedTime = System.currentTimeMillis();
514483
}
515484

485+
516486
// Some situations we cannot provide a stateless ticket, but after it
517487
// has been negotiated
518488
boolean isStatelessable() {

src/java.base/share/classes/sun/security/ssl/SignatureAlgorithmsExtension.java

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package sun.security.ssl;
2727

28+
import static sun.security.ssl.SignatureScheme.CERTIFICATE_SCOPE;
2829
import static sun.security.ssl.SignatureScheme.HANDSHAKE_SCOPE;
2930

3031
import java.io.IOException;
@@ -33,6 +34,7 @@
3334
import java.util.Arrays;
3435
import java.util.List;
3536
import java.util.Locale;
37+
import javax.net.ssl.SSLException;
3638
import javax.net.ssl.SSLProtocolException;
3739
import sun.security.ssl.SSLExtension.ExtensionConsumer;
3840
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
@@ -276,30 +278,8 @@ public void consume(ConnectionContext context,
276278
return;
277279
}
278280

279-
// update the context
280-
List<SignatureScheme> sss =
281-
SignatureScheme.getSupportedAlgorithms(
282-
shc.sslConfig,
283-
shc.algorithmConstraints, shc.negotiatedProtocol,
284-
spec.signatureSchemes,
285-
HANDSHAKE_SCOPE);
286-
287-
if (sss == null || sss.isEmpty()) {
288-
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
289-
"No supported signature algorithm");
290-
}
291-
shc.peerRequestedSignatureSchemes = sss;
292-
293-
// If no "signature_algorithms_cert" extension is present, then
294-
// the "signature_algorithms" extension also applies to
295-
// signatures appearing in certificates.
296-
SignatureSchemesSpec certSpec =
297-
(SignatureSchemesSpec)shc.handshakeExtensions.get(
298-
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
299-
if (certSpec == null) {
300-
shc.peerRequestedCertSignSchemes = sss;
301-
shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
302-
}
281+
updateHandshakeContext(shc, spec.signatureSchemes,
282+
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
303283

304284
if (!shc.isResumption &&
305285
shc.negotiatedProtocol.useTLS13PlusSpec()) {
@@ -507,30 +487,8 @@ public void consume(ConnectionContext context,
507487
return;
508488
}
509489

510-
// update the context
511-
List<SignatureScheme> sss =
512-
SignatureScheme.getSupportedAlgorithms(
513-
chc.sslConfig,
514-
chc.algorithmConstraints, chc.negotiatedProtocol,
515-
spec.signatureSchemes,
516-
HANDSHAKE_SCOPE);
517-
518-
if (sss == null || sss.isEmpty()) {
519-
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
520-
"No supported signature algorithm");
521-
}
522-
chc.peerRequestedSignatureSchemes = sss;
523-
524-
// If no "signature_algorithms_cert" extension is present, then
525-
// the "signature_algorithms" extension also applies to
526-
// signatures appearing in certificates.
527-
SignatureSchemesSpec certSpec =
528-
(SignatureSchemesSpec)chc.handshakeExtensions.get(
529-
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
530-
if (certSpec == null) {
531-
chc.peerRequestedCertSignSchemes = sss;
532-
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
533-
}
490+
updateHandshakeContext(chc, spec.signatureSchemes,
491+
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
534492
}
535493
}
536494

@@ -553,4 +511,49 @@ public void absent(ConnectionContext context,
553511
"received CertificateRequest handshake message");
554512
}
555513
}
514+
515+
// Updates given HandshakeContext with peer signature schemes.
516+
private static void updateHandshakeContext(HandshakeContext hc,
517+
int[] signatureSchemes, SSLExtension signatureAlgorithmsCertExt)
518+
throws SSLException {
519+
List<SignatureScheme> handshakeSS =
520+
SignatureScheme.getSupportedAlgorithms(
521+
hc.sslConfig,
522+
hc.algorithmConstraints,
523+
hc.negotiatedProtocol,
524+
signatureSchemes,
525+
HANDSHAKE_SCOPE);
526+
527+
if (handshakeSS.isEmpty()) {
528+
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
529+
"No supported signature algorithm");
530+
}
531+
532+
hc.peerRequestedSignatureSchemes = handshakeSS;
533+
534+
// If no "signature_algorithms_cert" extension is present, then
535+
// the "signature_algorithms" extension also applies to
536+
// signatures appearing in certificates.
537+
SignatureSchemesSpec certSpec =
538+
(SignatureSchemesSpec) hc.handshakeExtensions.get(
539+
signatureAlgorithmsCertExt);
540+
541+
if (certSpec == null) {
542+
List<SignatureScheme> certSS =
543+
SignatureScheme.getSupportedAlgorithms(
544+
hc.sslConfig,
545+
hc.algorithmConstraints,
546+
hc.negotiatedProtocol,
547+
signatureSchemes,
548+
CERTIFICATE_SCOPE);
549+
550+
if (certSS.isEmpty()) {
551+
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
552+
"No supported signature algorithm");
553+
}
554+
555+
hc.peerRequestedCertSignSchemes = certSS;
556+
hc.handshakeSession.setPeerSupportedSignatureAlgorithms(certSS);
557+
}
558+
}
556559
}

0 commit comments

Comments
 (0)