summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-07-01 09:19:49 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-07-01 09:19:49 (GMT)
commit2da71a8a85486a494343f1662d64fb5ae5a2a44e (patch)
tree23992f9f2a00bac23b345e5c2cc9c1194efc25be /src/com/isode/stroke/streamstack/TLSLayer.java
downloadstroke-2da71a8a85486a494343f1662d64fb5ae5a2a44e.zip
stroke-2da71a8a85486a494343f1662d64fb5ae5a2a44e.tar.bz2
Initial import
Diffstat (limited to 'src/com/isode/stroke/streamstack/TLSLayer.java')
-rw-r--r--src/com/isode/stroke/streamstack/TLSLayer.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/com/isode/stroke/streamstack/TLSLayer.java b/src/com/isode/stroke/streamstack/TLSLayer.java
new file mode 100644
index 0000000..ecf908d
--- /dev/null
+++ b/src/com/isode/stroke/streamstack/TLSLayer.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010, Remko Tron¨on.
+ * All rights reserved.
+ */
+
+package com.isode.stroke.streamstack;
+
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.signals.Signal;
+import com.isode.stroke.signals.Slot1;
+import com.isode.stroke.tls.Certificate;
+import com.isode.stroke.tls.CertificateVerificationError;
+import com.isode.stroke.tls.PKCS12Certificate;
+import com.isode.stroke.tls.TLSContext;
+import com.isode.stroke.tls.TLSContextFactory;
+
+public class TLSLayer extends StreamLayer {
+
+ public TLSLayer(TLSContextFactory factory) {
+ context = factory.createTLSContext();
+ context.onDataForNetwork.connect(new Slot1<ByteArray>() {
+
+ public void call(ByteArray p1) {
+ writeDataToChildLayer(p1);
+ }
+ });
+ context.onDataForApplication.connect(new Slot1<ByteArray>() {
+
+ public void call(ByteArray p1) {
+ writeDataToParentLayer(p1);
+ }
+ });
+ context.onConnected.connect(onConnected);
+ context.onError.connect(onError);
+ }
+
+ public void connect() {
+ context.connect();
+ }
+
+ public void writeData(ByteArray data) {
+ context.handleDataFromApplication(data);
+ }
+
+ public void handleDataRead(ByteArray data) {
+ context.handleDataFromNetwork(data);
+ }
+
+ public boolean setClientCertificate(PKCS12Certificate certificate) {
+ return context.setClientCertificate(certificate);
+ }
+
+ public Certificate getPeerCertificate() {
+ return context.getPeerCertificate();
+ }
+
+ public CertificateVerificationError getPeerCertificateVerificationError() {
+ return context.getPeerCertificateVerificationError();
+ }
+
+ public TLSContext getContext() {
+ return context;
+ }
+
+ public final Signal onError = new Signal();
+ public final Signal onConnected = new Signal();
+
+ private final TLSContext context;
+}