Skip to content

Commit 66d6b6c

Browse files
committed
Authentication ZMQ
1 parent 8f1a5ea commit 66d6b6c

11 files changed

+111
-0
lines changed

authzmq/auth_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
import zmq
4+
import zmq.auth
5+
6+
context = zmq.Context()
7+
8+
socket = context.socket(zmq.REQ)
9+
socket.curve_publickey, socket.curve_secretkey = zmq.auth.load_certificate('keys/client.key_secret')
10+
socket.curve_serverkey, _ = zmq.auth.load_certificate('keys/server.key')
11+
socket.connect ("tcp://localhost:{}".format(53487))
12+
13+
socket.send(b'Hello')
14+
print(socket.recv())

authzmq/auth_server.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import zmq
4+
import zmq.auth
5+
from zmq.auth.thread import ThreadAuthenticator
6+
7+
context = zmq.Context()
8+
auth = ThreadAuthenticator(context)
9+
auth.start()
10+
#auth.configure_curve(domain='*', location=zmq.auth.CURVE_ALLOW_ANY)
11+
auth.configure_curve(domain='*', location='authorized_keys')
12+
13+
socket = context.socket(zmq.REP)
14+
socket.curve_server = True
15+
socket.curve_publickey, socket.curve_secretkey = zmq.auth.load_certificate('keys/server.key_secret')
16+
socket.bind("tcp://*:{}".format(53487))
17+
18+
while True:
19+
msg = socket.recv()
20+
print("Received request: ", msg)
21+
socket.send(b'ok')
22+
23+
auth.stop()

authzmq/authorized_keys/client.key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# **** Generated on 2014-05-13 17:36:45.315366 by pyzmq ****
2+
# ZeroMQ CURVE Public Certificate
3+
# Exchange securely, or use a secure mechanism to verify the contents
4+
# of this file after exchange. Store public certificates in your home
5+
# directory, in the .curve subdirectory.
6+
7+
metadata
8+
curve
9+
public-key = "25m(@z#)Z:nkaJyXvhC)lS!vHgz8[ZXg=jMgi{+W"

authzmq/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
3+
import zmq
4+
5+
context = zmq.Context()
6+
socket = context.socket(zmq.REQ)
7+
socket.connect ("tcp://localhost:{}".format(53487))
8+
9+
socket.send(b'Hello')
10+
print(socket.recv())

authzmq/gen_keys.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
3+
import zmq.auth
4+
5+
keys_dir = 'keys'
6+
zmq.auth.create_certificates(keys_dir, 'server')
7+
zmq.auth.create_certificates(keys_dir, 'client')

authzmq/keys/client.key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# **** Generated on 2014-05-13 17:36:45.315366 by pyzmq ****
2+
# ZeroMQ CURVE Public Certificate
3+
# Exchange securely, or use a secure mechanism to verify the contents
4+
# of this file after exchange. Store public certificates in your home
5+
# directory, in the .curve subdirectory.
6+
7+
metadata
8+
curve
9+
public-key = "25m(@z#)Z:nkaJyXvhC)lS!vHgz8[ZXg=jMgi{+W"

authzmq/keys/client.key_secret

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# **** Generated on 2014-05-13 17:36:45.315366 by pyzmq ****
2+
# ZeroMQ CURVE **Secret** Certificate
3+
# DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.
4+
5+
metadata
6+
curve
7+
public-key = "25m(@z#)Z:nkaJyXvhC)lS!vHgz8[ZXg=jMgi{+W"
8+
secret-key = "(<fK!2s%ZJ<ebKd?IF5l!kJJ(PPwk-cwOJUIEmAm"

authzmq/keys/server.key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# **** Generated on 2014-05-13 17:36:45.314747 by pyzmq ****
2+
# ZeroMQ CURVE Public Certificate
3+
# Exchange securely, or use a secure mechanism to verify the contents
4+
# of this file after exchange. Store public certificates in your home
5+
# directory, in the .curve subdirectory.
6+
7+
metadata
8+
curve
9+
public-key = "-zB.*[8*RUhCmp{[w0!R&n.E<fah.(wHo+dpuuvA"

authzmq/keys/server.key_secret

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# **** Generated on 2014-05-13 17:36:45.314747 by pyzmq ****
2+
# ZeroMQ CURVE **Secret** Certificate
3+
# DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.
4+
5+
metadata
6+
curve
7+
public-key = "-zB.*[8*RUhCmp{[w0!R&n.E<fah.(wHo+dpuuvA"
8+
secret-key = "aZ2Xu7-StY[4Sa(!+.1WHsV<bE$t+PB%(uQD&Fq?"

authzmq/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyzmq==14.3.0

authzmq/server.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
import zmq
4+
5+
context = zmq.Context()
6+
socket = context.socket(zmq.REP)
7+
#socket.bind("tcp://*:{}".format(53487))
8+
socket.bind("tcp://127.0.0.1:{}".format(53487))
9+
10+
while True:
11+
msg = socket.recv()
12+
print("Received request: ", msg)
13+
socket.send(b'ok')

0 commit comments

Comments
 (0)