Giter Site home page Giter Site logo

sslfacade's People

Contributors

kashifrazzaqui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sslfacade's Issues

did not work correctly. incoming TLS packets are lost, if they appear more than one in single api call.

anyway as API aproach GREAT IDEA, but implementation sucks!

check out this:

public interface EazySslOwner {
public void incoming(ByteBuffer data);
public boolean outgoing(ByteBuffer data);
public void handshaked(SSLSession sess);

}

public class EazySsl {
private EazySslOwner owner;
private SSLEngine e;
private boolean notify;
private ByteBuffer partial, io;
private ByteBuffer empty = ByteBuffer.allocate(1);

public EazySsl(SSLContext ctx, EazySslOwner owner) {
e = ctx.createSSLEngine();
e.setUseClientMode(false);
e.setNeedClientAuth(true);
e.setEnableSessionCreation(true); //???
this.owner = owner;
partial = ByteBuffer.allocate(e.getSession().getApplicationBufferSize() + 8192);
io = ByteBuffer.allocate(e.getSession().getPacketBufferSize());
}

public void outgoing(ByteBuffer data) throws Exception {
while (data.remaining() > 0) send(data);
}

public void incoming(ByteBuffer data) throws Exception {
partial.put(data);
partial.flip();
while (partial.remaining() > 0) {
io.clear();
processWrap();
SSLEngineResult res = e.unwrap(partial, io);
if (res.getStatus() == SSLEngineResult.Status.BUFFER_UNDERFLOW) break;
runDelegatedTasks(res);
io.flip();
if (io.remaining() == 0) continue;
if (!notify) {
owner.handshaked(e.getSession());
notify = true;
}
owner.incoming(io);
}
processWrap();
partial.compact();
}

private void send(ByteBuffer data) throws Exception {
io.clear();
SSLEngineResult res = e.wrap(data, io);
runDelegatedTasks(res);
io.flip();
if (io.remaining() == 0) return;
ByteBuffer copy = ByteBuffer.allocate(io.remaining());
copy.put(io);
copy.flip();
owner.outgoing(copy);
}

private void processWrap() throws Exception {
while (e.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP)
send(empty);
}

private void runDelegatedTasks(SSLEngineResult result) throws Exception {
if (result.getHandshakeStatus() != HandshakeStatus.NEED_TASK) return;
Runnable runnable;
while ((runnable = e.getDelegatedTask()) != null)
runnable.run();
}

}

the specific thing ir 8192 extra buffer space - amount of physical buffer for incoming network traffic in server, where i use this code.

Received fatal alert: bad_record_mac

Hi, I am an user of sslfacade, i some times getting a "javax.net.ssl.SSLException: Received fatal alert: bad_record_mac" error when send msg after ssl shakehandcompleted. do you have the same problem?

Thanks very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.