/** * This is used to start the negotation. Once started this will * send a message to the other side, once sent the negotiation * reads the response. However if the response is not yet ready * this will schedule the negotiation for a selectable operation * ensuring that it can resume execution when ready. */ private void begin() { try { resume(); } catch(Exception cause) { trace.trace(ERROR, cause); cancel(); } }
/** * This method is invoked when the negotiation is done and the * next phase of the connection is to take place. If a certificate * challenge was issued then the completion task is executed, if * this was the handshake for the initial connection a transport * is created and handed to the processor. */ public void commit() throws IOException { if(!state.isChallenge()) { dispatch(); } else { complete(); } }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the pipeline. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. */ public void resume() throws IOException { Runnable task = process(); if(task != null) { task.run(); } }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the transport. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. * * @return this returns what is expected next in the negotiation */ private Status exchange() throws IOException { HandshakeStatus status = engine.getHandshakeStatus(); switch(status){ case NEED_WRAP: return write(); case NOT_HANDSHAKING: case NEED_UNWRAP: return read(); } return COMMIT; }
/** * This is used to perform the write part of the negotiation. The * read part is where the this sends information to the other side * and the other side interprets the data and determines what action * to take. After a write the negotiation typically completes or * waits for the next response from the other side. * * @param count this is the number of times a read can repeat * * @return the next action that should be taken by the handshake */ private Status write(int count) throws IOException { while(count > 0) { SSLEngineResult result = engine.wrap(empty, output); HandshakeStatus status = result.getHandshakeStatus(); switch(status) { case NOT_HANDSHAKING: case FINISHED: case NEED_UNWRAP: return PRODUCE; case NEED_WRAP: return write(count-1); case NEED_TASK: execute(); } } return PRODUCE; }
/** * This is used to perform the read part of the negotiation. The * read part is where the other side sends information where it * is consumed and is used to determine what action to take. * Typically it is the SSL engine that determines what action is * to be taken depending on the data send from the other side. * * @param count this is the number of times a read can repeat * * @return the next action that should be taken by the handshake */ private PhaseType read(int count) throws IOException { while(count > 0) { SSLEngineResult result = engine.unwrap(input, output); HandshakeStatus status = result.getHandshakeStatus(); switch(status) { case NOT_HANDSHAKING: return COMMIT; case NEED_WRAP: return PRODUCE; case FINISHED: case NEED_UNWRAP: return read(count-1); case NEED_TASK: execute(); } } return CONSUME; }
/** * This is used to perform the read part of the negotiation. The * read part is where the other side sends information where it * is consumed and is used to determine what action to take. * Typically it is the SSL engine that determines what action is * to be taken depending on the data send from the other side. * * @return the next action that should be taken by the handshake */ private Status read() throws IOException { return read(5); }
/** * This is used to start the negotiation. Once started this will * send a message to the other side, once sent the negotiation * reads the response. However if the response is not yet ready * this will schedule the negotiation for a selectable operation * ensuring that it can resume execution when ready. */ public void run() { if(engine != null) { trace.trace(HANDSHAKE_BEGIN); engine.setUseClientMode(client); input.flip(); } begin(); }
/** * This method is used to create <code>Operation</code> object to * process the next phase of the negotiation. The operations that * are created using this factory ensure the processing can be * done asynchronously, which reduces the overhead the connection * thread has when handing the pipelines over for processing. * * @param socket this is the pipeline that is to be processed * @param engine this is the engine used for SSL negotiations * * @return this returns the operation used for processing */ private Operation getInstance(Socket socket, SSLEngine engine) throws IOException { Transport transport = new SocketTransport(socket, reactor, buffer, threshold); if(engine != null) { return new Handshake(processor, transport, reactor, client); } return new TransportDispatcher(processor, transport); } }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the transport. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. * * @return this returns a task used to execute the next phase */ private Runnable process() throws IOException { PhaseType require = exchange(); if(require == CONSUME) { return new Consumer(this, reactor, trace); } if(require == PRODUCE) { return new Producer(this, reactor, trace); } return new Committer(this, reactor, trace); }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the transport. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. * * @return this returns what is expected next in the negotiation */ private PhaseType exchange() throws IOException { HandshakeStatus status = engine.getHandshakeStatus(); switch(status){ case NEED_WRAP: return write(); case NOT_HANDSHAKING: case NEED_UNWRAP: return read(); } return COMMIT; }
/** * This is used to perform the write part of the negotiation. The * read part is where the this sends information to the other side * and the other side interprets the data and determines what action * to take. After a write the negotiation typically completes or * waits for the next response from the other side. * * @param count this is the number of times a read can repeat * * @return the next action that should be taken by the handshake */ private PhaseType write(int count) throws IOException { while(count > 0) { SSLEngineResult result = engine.wrap(empty, output); HandshakeStatus status = result.getHandshakeStatus(); switch(status) { case NOT_HANDSHAKING: case FINISHED: case NEED_UNWRAP: return PRODUCE; case NEED_WRAP: return write(count-1); case NEED_TASK: execute(); } } return PRODUCE; }
/** * This is used to perform the read part of the negotiation. The * read part is where the other side sends information where it * is consumed and is used to determine what action to take. * Typically it is the SSL engine that determines what action is * to be taken depending on the data send from the other side. * * @param count this is the number of times a read can repeat * * @return the next action that should be taken by the handshake */ private PhaseType read(int count) throws IOException { while(count > 0) { SSLEngineResult result = engine.unwrap(input, output); HandshakeStatus status = result.getHandshakeStatus(); switch(status) { case NOT_HANDSHAKING: return COMMIT; case NEED_WRAP: return PRODUCE; case FINISHED: case NEED_UNWRAP: return read(count-1); case NEED_TASK: execute(); } } return CONSUME; }
/** * This is used to perform the read part of the negotiation. The * read part is where the other side sends information where it * is consumed and is used to determine what action to take. * Typically it is the SSL engine that determines what action is * to be taken depending on the data send from the other side. * * @return the next action that should be taken by the handshake */ private PhaseType read() throws IOException { return read(5); }
/** * This is used to start the negotiation. Once started this will * send a message to the other side, once sent the negotiation * reads the response. However if the response is not yet ready * this will schedule the negotiation for a selectable operation * ensuring that it can resume execution when ready. */ public void run() { if(engine != null) { trace.trace(HANDSHAKE_BEGIN); engine.setUseClientMode(client); input.flip(); } begin(); }
/** * This method is used to create <code>Operation</code> object to * process the next phase of the negotiation. The operations that * are created using this factory ensure the processing can be * done asynchronously, which reduces the overhead the connection * thread has when handing the pipelines over for processing. * * @param socket this is the pipeline that is to be processed * @param engine this is the engine used for SSL negotiations * * @return this returns the operation used for processing */ private Operation getInstance(Socket socket, SSLEngine engine) throws IOException { Transport transport = new SocketTransport(socket, reactor, buffer, threshold); if(engine != null) { return new Handshake(processor, transport, reactor, client); } return new TransportDispatcher(processor, transport); } }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the transport. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. * * @return this returns a task used to execute the next phase */ private Runnable process() throws IOException { Status require = exchange(); if(require == CONSUME) { return new Consumer(this, trace); } if(require == PRODUCE) { return new Producer(this, trace); } return new Committer(this, trace); }
/** * This is used to start the negotation. Once started this will * send a message to the other side, once sent the negotiation * reads the response. However if the response is not yet ready * this will schedule the negotiation for a selectable operation * ensuring that it can resume execution when ready. */ private void begin() { try { resume(); } catch(Exception cause) { trace.trace(ERROR, cause); cancel(); } }
/** * This method is invoked when the negotiation is done and the * next phase of the connection is to take place. If a certificate * challenge was issued then the completion task is executed, if * this was the handshake for the initial connection a transport * is created and handed to the processor. */ public void commit() throws IOException { if(!state.isChallenge()) { dispatch(); } else { complete(); } }
/** * This is the main point of execution within the negotiation. It * is where the negotiation is performed. Negotiations are done * by performing a request response flow, governed by the SSL * engine associated with the transport. Typically the client is * the one to initiate the handshake and the server initiates the * termination sequence. This may be executed several times * depending on whether reading or writing blocks. * * @return this returns what is expected next in the negotiation */ private PhaseType exchange() throws IOException { HandshakeStatus status = engine.getHandshakeStatus(); switch(status){ case NEED_WRAP: return write(); case NOT_HANDSHAKING: case NEED_UNWRAP: return read(); } return COMMIT; }