@Override public JDK9ALPNMethods run() { try { Method setApplicationProtocols = SSLParameters.class.getMethod("setApplicationProtocols", String[].class); Method getApplicationProtocol = SSLEngine.class.getMethod("getApplicationProtocol"); UndertowLogger.ROOT_LOGGER.debug("Using JDK9 ALPN"); return new JDK9ALPNMethods(setApplicationProtocols, getApplicationProtocol); } catch (Exception e) { UndertowLogger.ROOT_LOGGER.debug("JDK9 ALPN not supported"); return null; } } });
public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange exchange, final SecurityContext securityContext) { final FormDataParser parser = formParserFactory.createParser(exchange); if (parser == null) { UndertowLogger.SECURITY_LOGGER.debug("Could not authenticate as no form parser is present");
@Override public OpenSSLALPNMethods run() { try { Class<?> openSSLEngine = Class.forName(OPENSSL_ENGINE, true, OpenSSLAlpnProvider.class.getClassLoader()); Method setApplicationProtocols = openSSLEngine.getMethod("setApplicationProtocols", String[].class); Method getApplicationProtocol = openSSLEngine.getMethod("getSelectedApplicationProtocol"); UndertowLogger.ROOT_LOGGER.debug("OpenSSL ALPN Enabled"); return new OpenSSLALPNMethods(setApplicationProtocols, getApplicationProtocol); } catch (Throwable e) { UndertowLogger.ROOT_LOGGER.debug("OpenSSL ALPN disabled", e); return null; } } });
@Override public void handleException(final StreamSourceChannel channel, final IOException e) { //make sure the listeners have been invoked //unless the connection has been killed this is a no-op invokeExchangeCompleteListeners(); UndertowLogger.REQUEST_LOGGER.debug("Exception draining request stream", e); IoUtils.safeClose(connection); } }
@Override public void handleException(final Channel channel, final IOException exception) { //make sure the listeners have been invoked invokeExchangeCompleteListeners(); UndertowLogger.REQUEST_LOGGER.debug("Exception ending request", exception); IoUtils.safeClose(connection); } }
static ALPNHackServerByteArrayOutputStream replaceServerByteOutput(SSLEngine sslEngine, String selectedAlpnProtocol) { try { Object handshaker = HANDSHAKER.get(sslEngine); Object hash = HANDSHAKE_HASH.get(handshaker); ByteArrayOutputStream existing = (ByteArrayOutputStream) HANDSHAKE_HASH_DATA.get(hash); ALPNHackServerByteArrayOutputStream out = new ALPNHackServerByteArrayOutputStream(sslEngine, existing.toByteArray(), selectedAlpnProtocol); HANDSHAKE_HASH_DATA.set(hash, out); return out; } catch (Exception e) { UndertowLogger.ROOT_LOGGER.debug("Failed to replace hash output stream ", e); return null; } }
static ALPNHackClientByteArrayOutputStream replaceClientByteOutput(SSLEngine sslEngine) { try { Object handshaker = HANDSHAKER.get(sslEngine); Object hash = HANDSHAKE_HASH.get(handshaker); ALPNHackClientByteArrayOutputStream out = new ALPNHackClientByteArrayOutputStream(sslEngine); HANDSHAKE_HASH_DATA.set(hash, out); return out; } catch (Exception e) { UndertowLogger.ROOT_LOGGER.debug("Failed to replace hash output stream ", e); return null; } } static void regenerateHashes(SSLEngine sslEngineToHack, ByteArrayOutputStream data, byte[]... hashBytes) {
@Override public void failed(IOException e) { if (!exclusive) { data.connections--; } UndertowLogger.REQUEST_LOGGER.debug("Failed to connect", e); if (!connectionPoolManager.handleError()) { redistributeQueued(getData()); scheduleFailedHostRetry(exchange); } callback.failed(exchange); } }, bindAddress, getUri(), exchange.getIoThread(), ssl, exchange.getConnection().getByteBufferPool(), options);
UndertowLogger.REQUEST_IO_LOGGER.debug("Failed to parse address", e); return null;
private void handleSchedule(long timeout) { //no current timeout, clear the expire time if(timeout == -1) { this.expireTime = -1; return; } //calculate the new expire time long newExpireTime = System.currentTimeMillis() + timeout; long oldExpireTime = this.expireTime; this.expireTime = newExpireTime; //if the new one is less than the current one we need to schedule a new timer, so cancel the old one if(newExpireTime < oldExpireTime) { if(handle != null) { handle.remove(); handle = null; } } if(handle == null) { try { handle = WorkerUtils.executeAfter(connection.getIoThread(), this, timeout + FUZZ_FACTOR, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException e) { UndertowLogger.REQUEST_LOGGER.debug("Failed to schedule parse timeout, server is probably shutting down", e); } } }
public void handleWindowUpdate(int streamId, int deltaWindowSize) throws IOException { if (streamId == 0) { if (deltaWindowSize == 0) { UndertowLogger.REQUEST_IO_LOGGER.debug("Invalid flow-control window increment of 0 received with WINDOW_UPDATE frame for connection"); sendGoAway(ERROR_PROTOCOL_ERROR); return; UndertowLogger.REQUEST_IO_LOGGER.debug("Invalid flow-control window increment of 0 received with WINDOW_UPDATE frame for stream " + streamId); sendRstStream(streamId, ERROR_PROTOCOL_ERROR); return;
void sendPing(byte[] data, final ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler, boolean ack) { Http2PingStreamSinkChannel ping = new Http2PingStreamSinkChannel(this, data, ack); try { ping.shutdownWrites(); if (!ping.flush()) { ping.getWriteSetter().set(ChannelListeners.flushingChannelListener(null, exceptionHandler)); ping.resumeWrites(); } } catch (IOException e) { if(exceptionHandler != null) { exceptionHandler.handleException(ping, e); } else { UndertowLogger.REQUEST_LOGGER.debug("Failed to send ping and no exception handler set", e); } } catch (Throwable t) { if(exceptionHandler != null) { exceptionHandler.handleException(ping, new IOException(t)); } else { UndertowLogger.REQUEST_LOGGER.debug("Failed to send ping and no exception handler set", t); } } }
@Override protected FrameHeaderData parseFrame(ByteBuffer data) throws IOException { ajpParser.parse(data); if (ajpParser.isComplete()) { try { AjpResponseParser parser = ajpParser; if (parser.prefix == FRAME_TYPE_SEND_HEADERS) { return new SendHeadersResponse(parser.statusCode, parser.reasonPhrase, parser.headers); } else if (parser.prefix == FRAME_TYPE_REQUEST_BODY_CHUNK) { return new RequestBodyChunk(parser.readBodyChunkSize); } else if (parser.prefix == FRAME_TYPE_SEND_BODY_CHUNK) { return new SendBodyChunk(parser.currentIntegerPart + 1); //+1 for the null terminator } else if (parser.prefix == FRAME_TYPE_END_RESPONSE) { boolean persistent = parser.currentIntegerPart != 0; if (!persistent) { lastFrameReceived = true; lastFrameSent = true; } return new EndResponse(); } else if (parser.prefix == FRAME_TYPE_CPONG) { return new CpongResponse(); } else { UndertowLogger.ROOT_LOGGER.debug("UNKOWN FRAME"); } } finally { ajpParser.reset(); } } return null; }
@Override public void handleException(Channel channel, IOException exception) { IoUtils.safeClose(channel); IoUtils.safeClose(clientConnection); if (exchange.isResponseStarted()) { UndertowLogger.REQUEST_IO_LOGGER.debug("Exception reading from target server", exception); if (!exchange.isResponseStarted()) { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.endExchange(); } else { IoUtils.safeClose(exchange.getConnection()); } } else { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.endExchange(); } } }
UndertowLogger.REQUEST_IO_LOGGER.debug("Invalid value received for SETTINGS_MAX_FRAME_SIZE " + setting.getValue()); sendGoAway(ERROR_PROTOCOL_ERROR); return false; } else if(result != 1) { UndertowLogger.REQUEST_IO_LOGGER.debug("Invalid value received for SETTINGS_ENABLE_PUSH " + result); sendGoAway(ERROR_PROTOCOL_ERROR); return false;
UndertowLogger.REQUEST_IO_LOGGER.debug("Exception parsing data", e); exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.endExchange();
Connectors.setExchangeRequestPath(exchange, path, getUndertowOptions().get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name()), getUndertowOptions().get(UndertowOptions.DECODE_URL, true), getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false), new StringBuilder(), getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_HEADERS)); } catch (ParameterLimitException e) { UndertowLogger.REQUEST_IO_LOGGER.debug("Too many parameters in HTTP/2 request", e); exchange.setStatusCode(StatusCodes.BAD_REQUEST); exchange.endExchange();
if(anyAreClear(flags, Http2Channel.HEADERS_FLAG_END_STREAM)) { UndertowLogger.REQUEST_IO_LOGGER.debug("Received HTTP/2 trailers header without end stream set"); http2Channel.sendGoAway(Http2Channel.ERROR_PROTOCOL_ERROR);
executor.execute(dispatchTask); } catch (RejectedExecutionException e) { UndertowLogger.REQUEST_LOGGER.debug("Failed to dispatch to worker", e); exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE); exchange.endExchange();