kashifrazzaqui / sslfacade Goto Github PK
View Code? Open in Web Editor NEWAn attempt to make the use of Java's SSLEngine easier.
License: MIT License
An attempt to make the use of Java's SSLEngine easier.
License: MIT License
anyway as API aproach GREAT IDEA, but implementation sucks!
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.
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.