HandlerFactory { public static ExtensionHandler getExtensionHandler(TlsContext context, ExtensionType type, HandshakeMessageType handshakeMessageType) { try { switch (type) { case ALPN: return new AlpnExtensionHandler(context); case CACHED_INFO: return new CachedInfoExtensionHandler(context); case CERT_TYPE: return new CertificateTypeExtensionHandler(context); case CLIENT_AUTHZ: return new ClientAuthzExtensionHandler(context); case CLIENT_CERTIFICATE_TYPE: return new ClientCertificateTypeExtensionHandler(context); case CLIENT_CERTIFICATE_URL: return new ClientCertificateUrlExtensionHandler(context); case EARLY_DATA: return new EarlyDataExtensionHandler(context); case EC_POINT_FORMATS: return new EcPointFormatExtensionHandler(context); case ELLIPTIC_CURVES: return new EllipticCurvesExtensionHandler(context); case ENCRYPT_THEN_MAC: return new EncryptThenMacExtensionHandler(context); case ENCRYPTED_SERVER_NAME_INDICATION: return new EncryptedServerNameIndicationExtensionHandler(context); case EXTENDED_MASTER_SECRET: return new ExtendedMasterSecretExtensionHandler(context); case HEARTBEAT: return new HeartbeatExtensionHandler(context); case EXTENDED_RANDOM: return new ExtendedRandomExtensionHandler(context); case KEY_SHARE_OLD: case KEY_SHARE: if (handshakeMessageType == HandshakeMessageType.HELLO_RETRY_REQUEST) { return new HrrKeyShareExtensionHandler(context); } return new KeyShareExtensionHandler(context, type); case MAX_FRAGMENT_LENGTH: return new MaxFragmentLengthExtensionHandler(context); case PADDING: return new PaddingExtensionHandler(context); case PRE_SHARED_KEY: return new PreSharedKeyExtensionHandler(context); case PSK_KEY_EXCHANGE_MODES: return new PSKKeyExchangeModesExtensionHandler(context); case RENEGOTIATION_INFO: return new RenegotiationInfoExtensionHandler(context); case SERVER_AUTHZ: return new ServerAuthzExtensionHandler(context); case SERVER_CERTIFICATE_TYPE: return new ServerCertificateTypeExtensionHandler(context); case SERVER_NAME_INDICATION: return new ServerNameIndicationExtensionHandler(context); case SESSION_TICKET: return new SessionTicketTlsExtensionHandler(context); case SIGNATURE_AND_HASH_ALGORITHMS: return new SignatureAndHashAlgorithmsExtensionHandler(context); case SIGNED_CERTIFICATE_TIMESTAMP: return new SignedCertificateTimestampExtensionHandler(context); case SRP: return new SrpExtensionHandler(context); case STATUS_REQUEST: return new CertificateStatusRequestExtensionHandler(context); case STATUS_REQUEST_V2: return new CertificateStatusRequestV2ExtensionHandler(context); case SUPPORTED_VERSIONS: return new SupportedVersionsExtensionHandler(context); case TOKEN_BINDING: return new TokenBindingExtensionHandler(context); case TRUNCATED_HMAC: return new TruncatedHmacExtensionHandler(context); case TRUSTED_CA_KEYS: return new TrustedCaIndicationExtensionHandler(context); case UNKNOWN: return new UnknownExtensionHandler(context); case USER_MAPPING: return new UserMappingExtensionHandler(context); case USE_SRTP: return new SrtpExtensionHandler(context); case PWD_PROTECT: return new PWDProtectExtensionHandler(context); case PWD_CLEAR: return new PWDClearExtensionHandler(context); case PASSWORD_SALT: return new PasswordSaltExtensionHandler(context); default: throw new UnsupportedOperationException(type.name() + " Extension are not supported yet"); } } catch (UnsupportedOperationException E) { LOGGER.debug("Could not retrieve correct Handler, returning UnknownExtensionHandler", E); } return new UnknownExtensionHandler(context); } private  HandlerFactory(); static ProtocolMessageHandler getHandler(TlsContext context, ProtocolMessageType protocolType,
            HandshakeMessageType handshakeType); static HandshakeMessageHandler getHandshakeHandler(TlsContext context, HandshakeMessageType type); static ExtensionHandler getExtensionHandler(TlsContext context, ExtensionType type,
            HandshakeMessageType handshakeMessageType);  }
@Test public void getExtensionHandler() { assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.ALPN, null) instanceof AlpnExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.CACHED_INFO, null) instanceof CachedInfoExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.CERT_TYPE, null) instanceof CertificateTypeExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.CLIENT_AUTHZ, null) instanceof ClientAuthzExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.CLIENT_CERTIFICATE_TYPE, null) instanceof ClientCertificateTypeExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.CLIENT_CERTIFICATE_URL, null) instanceof ClientCertificateUrlExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.EARLY_DATA, null) instanceof EarlyDataExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.EC_POINT_FORMATS, null) instanceof EcPointFormatExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.ELLIPTIC_CURVES, null) instanceof EllipticCurvesExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.ENCRYPT_THEN_MAC, null) instanceof EncryptThenMacExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.EXTENDED_MASTER_SECRET, null) instanceof ExtendedMasterSecretExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.HEARTBEAT, null) instanceof HeartbeatExtensionHandler); context.getConfig().setParseKeyShareOld(true); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.KEY_SHARE_OLD, HandshakeMessageType.HELLO_RETRY_REQUEST) instanceof HrrKeyShareExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.KEY_SHARE, HandshakeMessageType.HELLO_RETRY_REQUEST) instanceof HrrKeyShareExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.KEY_SHARE_OLD, null) instanceof KeyShareExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.KEY_SHARE, null) instanceof KeyShareExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.MAX_FRAGMENT_LENGTH, null) instanceof MaxFragmentLengthExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PADDING, null) instanceof PaddingExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PRE_SHARED_KEY, null) instanceof PreSharedKeyExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PSK_KEY_EXCHANGE_MODES, null) instanceof PSKKeyExchangeModesExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.RENEGOTIATION_INFO, null) instanceof RenegotiationInfoExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SERVER_AUTHZ, null) instanceof ServerAuthzExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SERVER_CERTIFICATE_TYPE, null) instanceof ServerCertificateTypeExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SERVER_NAME_INDICATION, null) instanceof ServerNameIndicationExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SESSION_TICKET, null) instanceof SessionTicketTlsExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SIGNATURE_AND_HASH_ALGORITHMS, null) instanceof SignatureAndHashAlgorithmsExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SIGNED_CERTIFICATE_TIMESTAMP, null) instanceof SignedCertificateTimestampExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SRP, null) instanceof SrpExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.STATUS_REQUEST, null) instanceof CertificateStatusRequestExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.STATUS_REQUEST_V2, null) instanceof CertificateStatusRequestV2ExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.SUPPORTED_VERSIONS, null) instanceof SupportedVersionsExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.TOKEN_BINDING, null) instanceof TokenBindingExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.TRUNCATED_HMAC, null) instanceof TruncatedHmacExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.TRUSTED_CA_KEYS, null) instanceof TrustedCaIndicationExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.UNKNOWN, null) instanceof UnknownExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.USER_MAPPING, null) instanceof UserMappingExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.USE_SRTP, null) instanceof SrtpExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PWD_PROTECT, null) instanceof PWDProtectExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PWD_CLEAR, null) instanceof PWDClearExtensionHandler); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.PASSWORD_SALT, null) instanceof PasswordSaltExtensionHandler); context.getConfig().setParseKeyShareOld(false); assertTrue(HandlerFactory.getExtensionHandler(context, ExtensionType.EXTENDED_RANDOM, null) instanceof ExtendedRandomExtensionHandler); }