[Pkg-privacy-commits] [obfsproxy] 18/353: Support for minimal Dust and obfs3 transports
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:33 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository obfsproxy.
commit e77cec21c318f8196ffb39b8e736fe7a36048a35
Author: Brandon Wiley <brandon at blanu.net>
Date: Tue Jul 17 14:19:34 2012 -0500
Support for minimal Dust and obfs3 transports
---
src/{ => obfsproxy/crypto}/__init__.py | 0
src/obfsproxy/crypto/aes.py | 29 +++++++++++++
src/obfsproxy/framework/managed/client.py | 18 +++++++--
src/obfsproxy/transports/dummy.py | 16 ++++----
src/obfsproxy/transports/dust_transport.py | 63 +++++++++++++++++++++++++++++
src/obfsproxy/transports/obfs3.py | 65 ++++++++++++++++++++++++++++++
src/obfsproxy/transports/rot13.py | 15 +++----
7 files changed, 184 insertions(+), 22 deletions(-)
diff --git a/src/__init__.py b/src/obfsproxy/crypto/__init__.py
similarity index 100%
copy from src/__init__.py
copy to src/obfsproxy/crypto/__init__.py
diff --git a/src/obfsproxy/crypto/aes.py b/src/obfsproxy/crypto/aes.py
new file mode 100644
index 0000000..214dd48
--- /dev/null
+++ b/src/obfsproxy/crypto/aes.py
@@ -0,0 +1,29 @@
+from Crypto.Cipher import AES
+from Crypto.Util import Counter
+import base64
+import os
+
+# the block size for the cipher object; must be 16, 24, or 32 for AES
+BLOCK_SIZE = 32
+
+# the character used for padding--with a block cipher such as AES, the value
+# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
+# used to ensure that your value is always a multiple of BLOCK_SIZE
+PADDING = '{'
+
+# one-liner to sufficiently pad the text to be encrypted
+pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
+
+class AESCoder(object):
+ def __init__(self, key):
+ counterIn=Counter.new(128)
+ self.cipherIn=AES.new(key, mode=AES.MODE_CTR, counter=counterIn)
+
+ counterOut=Counter.new(128)
+ self.cipherOut=AES.new(key, mode=AES.MODE_CTR, counter=counterOut)
+
+ def encrypt(self, data):
+ return self.cipherOut.encrypt(pad(data))
+
+ def decrypt(self, data):
+ return self.cipherIn.decrypt(data).rstrip(PADDING)
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index ad6cb07..c11b666 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -9,7 +9,11 @@ from monocle.stack import eventloop
from monocle.stack.network import add_service, Service
from obfsproxy.framework.socks import SocksHandler
+
from obfsproxy.transports.dummy import DummyClient
+from obfsproxy.transports.rot13 import Rot13Client
+from obfsproxy.transports.dust_transport import DustClient
+from obfsproxy.transports.obfs3 import Obfs3Client
from pyptlib.easy.client import init, reportSuccess, reportFailure, \
reportEnd
@@ -25,9 +29,14 @@ class ManagedClient:
def __init__(self):
self.handler = SocksHandler()
- self.supportedTransports = ['dummy', 'rot13']
+ self.supportedTransports={
+ 'dummy': DummyClient,
+ 'rot13': Rot13Client,
+ 'dust': DustClient,
+ 'obfs3': Obfs3Client,
+ }
- matchedTransports = init(self.supportedTransports)
+ matchedTransports = init(self.supportedTransports.keys())
for transport in matchedTransports:
try:
self.launchClient(transport, 8182)
@@ -40,11 +49,12 @@ class ManagedClient:
eventloop.run()
def launchClient(self, name, port):
- if not name in self.supportedTransports:
+ if not name in self.supportedTransports.keys():
raise TransportLaunchException('Tried to launch unsupported transport %s'
% name)
- client = DummyClient()
+ clientClass=self.supportedTransports[name]
+ client = clientClass(self)
self.handler.setTransport(client)
add_service(Service(self.handler.handle, port=port))
diff --git a/src/obfsproxy/transports/dummy.py b/src/obfsproxy/transports/dummy.py
index 6921704..e1d9e51 100644
--- a/src/obfsproxy/transports/dummy.py
+++ b/src/obfsproxy/transports/dummy.py
@@ -2,7 +2,9 @@
# -*- coding: utf-8 -*-
-class DummyClient:
+class DummyDaemon:
+ def __init__(self, client, server)
+ pass
def encode(self, data):
return data
@@ -10,13 +12,9 @@ class DummyClient:
def decode(self, data):
return data
-
-class DummyServer:
-
- def encode(self, data):
- return data
-
- def decode(self, data):
- return data
+class DummyClient(DummyDaemon:
+ pass
+class DummyServer(DummyDaemon):
+ pass
diff --git a/src/obfsproxy/transports/dust_transport.py b/src/obfsproxy/transports/dust_transport.py
new file mode 100644
index 0000000..9ba511c
--- /dev/null
+++ b/src/obfsproxy/transports/dust_transport.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from dust.extensions.lite.lite_socket2 import lite_socket, makeSession, makeEphemeralSession, createEphemeralKeypair
+from dust.core.dust_packet import IV_SIZE, KEY_SIZE
+
+HANDSHAKE=0
+STREAM=1
+
+HANDSHAKE_SIZE=IV_SIZE+KEY_SIZE
+
+class DustDaemon:
+
+ def __init__(self, client, server):
+ self.client=client
+ self.server=server
+ self.state=HANDSHAKE_WRITE
+ self.encodeBuffer=bytes('')
+ self.decodeBuffer=bytes('')
+ self.ekeypair=createEphemeralKeypair()
+
+ def read(self, data, count):
+ if data:
+ self.decodeBuffer=self.decodeBuffer+data
+ if len(self.decodeBuffer)>=count:
+ data=self.decodeBuffer[:count]
+ self.decodeBuffer=self.decodeBuffer[count:]
+ return data
+ else:
+ return None
+
+ def encode(self, data):
+ if self.state==HANDSHAKE:
+ self.encodeBuffer=self.encodeBuffer+data
+ else:
+ return self.coder.encode(data)
+
+ def decode(self, data):
+ if self.state==HANDSHAKE:
+ epub=self.read(data, HANDSHAKE_SIZE)
+ if epub:
+ esession=makeEphemeralSession(self.ekeypair, epub)
+ self.coder=lite_socket(esession)
+ self.state=STREAM
+ self.server.write(self.encode(self.encodeBuffer))
+ return decode(self.decodeBuffer)
+ else:
+ return None
+ else:
+ return self.coder.decode(data)
+
+ def end(self):
+ pass
+
+class DustClient(DustDaemon):
+
+ def start(self):
+ self.server.write(self.ekeypair.public.bytes)
+
+class DustServer(DustDaemon):
+
+ def start(self):
+ self.client.write(ekeypair.public.bytes)
diff --git a/src/obfsproxy/transports/obfs3.py b/src/obfsproxy/transports/obfs3.py
new file mode 100644
index 0000000..0b314e0
--- /dev/null
+++ b/src/obfsproxy/transports/obfs3.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from dust.extensions.lite.lite_socket2 import makeSession, makeEphemeralSession, createEphemeralKeypair
+from dust.core.dust_packet import IV_SIZE, KEY_SIZE
+
+from obfsproxy.crypto.aes import AESCoder
+
+HANDSHAKE=0
+STREAM=1
+
+HANDSHAKE_SIZE=IV_SIZE+KEY_SIZE
+
+class Obfs3Daemon:
+
+ def __init__(self, client, server):
+ self.client=client
+ self.server=server
+ self.state=HANDSHAKE_WRITE
+ self.encodeBuffer=bytes('')
+ self.decodeBuffer=bytes('')
+ self.ekeypair=createEphemeralKeypair()
+
+ def read(self, data, count):
+ if data:
+ self.decodeBuffer=self.decodeBuffer+data
+ if len(self.decodeBuffer)>=count:
+ data=self.decodeBuffer[:count]
+ self.decodeBuffer=self.decodeBuffer[count:]
+ return data
+ else:
+ return None
+
+ def encode(self, data):
+ if self.state==HANDSHAKE:
+ self.encodeBuffer=self.encodeBuffer+data
+ else:
+ return self.coder.encode(data)
+
+ def decode(self, data):
+ if self.state==HANDSHAKE:
+ epub=self.read(data, HANDSHAKE_SIZE)
+ if epub:
+ esession=makeEphemeralSession(self.ekeypair, epub)
+ self.coder=AESCoder(esession)
+ self.state=STREAM
+ self.server.write(self.encode(self.encodeBuffer))
+ return decode(self.decodeBuffer)
+ else:
+ return None
+ else:
+ return self.coder.decode(data)
+
+ def end(self):
+ pass
+
+class Obfs3Client(Obfs3Daemon):
+
+ def start(self):
+ self.server.write(self.ekeypair.public.bytes)
+
+class Obfs3Server(Obfs3Daemon):
+
+ def start(self):
+ self.client.write(ekeypair.public.bytes)
diff --git a/src/obfsproxy/transports/rot13.py b/src/obfsproxy/transports/rot13.py
index 15f32b1..1539582 100644
--- a/src/obfsproxy/transports/rot13.py
+++ b/src/obfsproxy/transports/rot13.py
@@ -15,7 +15,9 @@ def rot13(data):
return data
-class Rot13Client:
+class Rot13Daemon:
+ def __init__(self, client, server):
+ pass
def encode(self, data):
return rot13(data)
@@ -23,13 +25,8 @@ class Rot13Client:
def decode(self, data):
return rot13(data)
+class Rot13Client(Rot13Daemon):
+ pass
class Rot13Server:
-
- def encode(self, data):
- return rot13(data)
-
- def decode(self, data):
- return rot13(data)
-
-
+ pass
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git
More information about the Pkg-privacy-commits
mailing list