@@ -475,13 +475,29 @@ protected DTLSTransport serverHandshake13(ServerHandshakeState state, DTLSReliab
475475 byte [] serverFinishedTranscriptHash = send13ServerHelloCoda (state , handshake , afterHelloRetryRequest );
476476
477477 /*
478- * RFC 8446 4.4. With no CertificateRequest sent, the client's flight is its Finished alone; a
479- * Certificate or CertificateVerify here is unexpected, which is what receiveMessageDelayedDigest
480- * reports.
481- *
482- * TODO[dtls13] Task 6 adds in-handshake client authentication (CertificateRequest, then the
483- * client's Certificate and CertificateVerify ahead of its Finished).
478+ * RFC 8446 4.4.2. A client that was sent a CertificateRequest always answers with a Certificate,
479+ * carrying an empty certificate list when it declines, and follows it with a CertificateVerify only
480+ * when that list is not empty. With no CertificateRequest sent, the client's flight is its Finished
481+ * alone, and a Certificate or CertificateVerify here is unexpected - which is what the type check in
482+ * receiveMessageDelayedDigest reports. This is the counterpart of TlsServerProtocol's
483+ * skip13ClientCertificate and skip13ClientCertificateVerify, which make the same two rules explicit
484+ * because its dispatcher reaches the Finished handler from either state.
484485 */
486+ if (null != state .certificateRequest )
487+ {
488+ receive13ClientCertificate (state , handshake .receiveMessageBody (HandshakeType .certificate ));
489+
490+ if (expectCertificateVerifyMessage (state ))
491+ {
492+ // NOTE: Verified over the transcript excluding the CertificateVerify message itself
493+ DTLSReliableHandshake .Message certificateVerifyMessage = handshake .receiveMessageDelayedDigest (
494+ HandshakeType .certificate_verify );
495+ receive13ClientCertificateVerify (state , certificateVerifyMessage .getBody (),
496+ handshake .getHandshakeHash ());
497+ handshake .updateHandshakeMessagesDigest (certificateVerifyMessage );
498+ }
499+ }
500+
485501 {
486502 // NOTE: Calculated exclusive of the actual Finished message from the client
487503 DTLSReliableHandshake .Message finishedMessage = handshake .receiveMessageDelayedDigest (
@@ -566,16 +582,22 @@ protected byte[] send13ServerHelloCoda(ServerHandshakeState state, DTLSReliableH
566582 {
567583 // CertificateRequest
568584 {
569- /*
570- * TODO[dtls13] Task 6 sends the CertificateRequest here and processes the client's
571- * Certificate/CertificateVerify. Until then a server configured to request client
572- * authentication must fail rather than silently complete an unauthenticated handshake.
573- */
574585 state .certificateRequest = server .getCertificateRequest ();
575586 if (null != state .certificateRequest )
576587 {
577- throw new TlsFatalAlert (AlertDescription .internal_error ,
578- "DTLS 1.3 client authentication is not implemented" );
588+ /*
589+ * RFC 8446 4.3.2. In a handshake the 'certificate_request_context' is zero length; a
590+ * non-empty one belongs to post-handshake authentication, which this does not support.
591+ */
592+ if (!state .certificateRequest .hasCertificateRequestContext (TlsUtils .EMPTY_BYTES ))
593+ {
594+ throw new TlsFatalAlert (AlertDescription .internal_error );
595+ }
596+
597+ TlsUtils .establishServerSigAlgs (securityParameters , state .certificateRequest );
598+
599+ handshake .sendMessage (HandshakeType .certificate_request ,
600+ generateCertificateRequest (state , state .certificateRequest ));
579601 }
580602 }
581603
@@ -1026,6 +1048,45 @@ protected byte[] generateCertificateVerify(ServerHandshakeState state, Digitally
10261048 return buf .toByteArray ();
10271049 }
10281050
1051+ /**
1052+ * Mirrors TlsServerProtocol.receive13ClientCertificate. The message is parsed exactly as the DTLS 1.2
1053+ * path parses it; RFC 8446 4.4.2's extra rule is only that the client must not send one unasked.
1054+ */
1055+ protected void receive13ClientCertificate (ServerHandshakeState state , byte [] body )
1056+ throws IOException
1057+ {
1058+ if (null == state .certificateRequest )
1059+ {
1060+ throw new TlsFatalAlert (AlertDescription .unexpected_message );
1061+ }
1062+
1063+ processClientCertificate (state , body );
1064+ }
1065+
1066+ /**
1067+ * Mirrors TlsServerProtocol.receive13ClientCertificateVerify. The transcript passed in must exclude the
1068+ * CertificateVerify message itself, which is why it is read with a delayed digest.
1069+ */
1070+ protected void receive13ClientCertificateVerify (ServerHandshakeState state , byte [] body ,
1071+ TlsHandshakeHash handshakeHash ) throws IOException
1072+ {
1073+ TlsServerContextImpl serverContext = state .serverContext ;
1074+
1075+ Certificate clientCertificate = serverContext .getSecurityParametersHandshake ().getPeerCertificate ();
1076+ if (null == clientCertificate || clientCertificate .isEmpty ())
1077+ {
1078+ throw new TlsFatalAlert (AlertDescription .internal_error );
1079+ }
1080+
1081+ ByteArrayInputStream buf = new ByteArrayInputStream (body );
1082+
1083+ CertificateVerify certificateVerify = CertificateVerify .parse (serverContext , buf );
1084+
1085+ TlsProtocol .assertEmpty (buf );
1086+
1087+ TlsUtils .verify13CertificateVerifyClient (serverContext , handshakeHash , certificateVerify );
1088+ }
1089+
10291090 /**
10301091 * Mirrors TlsServerProtocol.receive13ClientFinished (TlsProtocol.process13FinishedMessage). The
10311092 * transcript passed in must exclude the Finished message itself.
0 commit comments