CertificateRequestHandler extends HandshakeMessageHandler<CertificateRequestMessage> { @Override public void adjustTLSContext(CertificateRequestMessage message) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { adjustCertifiateRequestContext(message); adjustServerSupportedSignatureAndHashAlgorithms(message); } else { adjustClientCertificateTypes(message); adjustDistinguishedNames(message); if (tlsContext.getChooser().getSelectedProtocolVersion() == ProtocolVersion.TLS12 || tlsContext.getChooser().getSelectedProtocolVersion() == ProtocolVersion.DTLS12) { adjustServerSupportedSignatureAndHashAlgorithms(message); } } } CertificateRequestHandler(TlsContext tlsContext); @Override CertificateRequestParser getParser(byte[] message, int pointer); @Override CertificateRequestPreparator getPreparator(CertificateRequestMessage message); @Override CertificateRequestSerializer getSerializer(CertificateRequestMessage message); @Override void adjustTLSContext(CertificateRequestMessage message);  }
@Test public void testAdjustTLSContextTLS12() { CertificateRequestMessage message = new CertificateRequestMessage(); message.setClientCertificateTypes(new byte[] { 1, 2, 3, 4, 5, 6 }); message.setDistinguishedNames(new byte[] { 0, 1, 2, 3, }); message.setSignatureHashAlgorithms(new byte[] { 03, 01, 01, 03 }); handler.adjustTLSContext(message); assertArrayEquals(context.getDistinguishedNames(), ArrayConverter.hexStringToByteArray("00010203")); assertTrue(context.getClientCertificateTypes().size() == 6); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.DSS_EPHEMERAL_DH_RESERVED)); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.DSS_FIXED_DH)); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.DSS_SIGN)); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.RSA_EPHEMERAL_DH_RESERVED)); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.RSA_FIXED_DH)); assertTrue(context.getClientCertificateTypes().contains(ClientCertificateType.RSA_SIGN)); assertTrue(context.getServerSupportedSignatureAndHashAlgorithms().size() == 2); }
@Test public void testAdjustTLSContextTLS13() { CertificateRequestMessage message = new CertificateRequestMessage(); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); message.setCertificateRequestContext(new byte[] { 1, 2, 3, 4, 5, 6 }); message.setSignatureHashAlgorithms(new byte[] { 03, 01, 01, 03 }); handler.adjustTLSContext(message); assertArrayEquals(context.getCertificateRequestContext(), ArrayConverter.hexStringToByteArray("010203040506")); assertTrue(context.getServerSupportedSignatureAndHashAlgorithms().size() == 2); }
@Test public void testAdjustTLSContextUnadjustable() { CertificateRequestMessage message = new CertificateRequestMessage(); message.setClientCertificateTypes(new byte[] { 50, 51, 52, 53, 54, 55 }); message.setDistinguishedNames(new byte[] {}); message.setSignatureHashAlgorithms(new byte[] { 123, 123, 127 }); handler.adjustTLSContext(message); assertArrayEquals(context.getDistinguishedNames(), new byte[0]); assertTrue(context.getClientCertificateTypes().isEmpty()); assertTrue(context.getServerSupportedSignatureAndHashAlgorithms().isEmpty()); }