Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
971b275f
Commit
971b275f
authored
Sep 16, 2013
by
Ian Barber
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #663 from hintjens/master
Fixed random failures in test_security_plain and _curve
parents
276cd1f1
fe9815a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
51 deletions
+49
-51
test_security_curve.cpp
tests/test_security_curve.cpp
+27
-28
test_security_null.cpp
tests/test_security_null.cpp
+22
-23
No files found.
tests/test_security_curve.cpp
View file @
971b275f
...
...
@@ -30,27 +30,21 @@ static char server_secret [] = "JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6";
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
// dest. Size must be a multiple of 4.
static
void
zap_handler
(
void
*
ctx
)
static
void
zap_handler
(
void
*
handler
)
{
// Create and bind ZAP socket
void
*
zap
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
zap
);
int
rc
=
zmq_bind
(
zap
,
"inproc://zeromq.zap.01"
);
assert
(
rc
==
0
);
// Process ZAP requests forever
while
(
true
)
{
char
*
version
=
s_recv
(
zap
);
char
*
version
=
s_recv
(
handler
);
if
(
!
version
)
break
;
// Terminating
char
*
sequence
=
s_recv
(
zap
);
char
*
domain
=
s_recv
(
zap
);
char
*
address
=
s_recv
(
zap
);
char
*
identity
=
s_recv
(
zap
);
char
*
mechanism
=
s_recv
(
zap
);
char
*
sequence
=
s_recv
(
handler
);
char
*
domain
=
s_recv
(
handler
);
char
*
address
=
s_recv
(
handler
);
char
*
identity
=
s_recv
(
handler
);
char
*
mechanism
=
s_recv
(
handler
);
uint8_t
client_key
[
32
];
int
size
=
zmq_recv
(
zap
,
client_key
,
32
,
0
);
int
size
=
zmq_recv
(
handler
,
client_key
,
32
,
0
);
assert
(
size
==
32
);
char
client_key_text
[
41
];
...
...
@@ -60,20 +54,20 @@ static void zap_handler (void *ctx)
assert
(
streq
(
mechanism
,
"CURVE"
));
assert
(
streq
(
identity
,
"IDENT"
));
s_sendmore
(
zap
,
version
);
s_sendmore
(
zap
,
sequence
);
s_sendmore
(
handler
,
version
);
s_sendmore
(
handler
,
sequence
);
if
(
streq
(
client_key_text
,
client_public
))
{
s_sendmore
(
zap
,
"200"
);
s_sendmore
(
zap
,
"OK"
);
s_sendmore
(
zap
,
"anonymous"
);
s_send
(
zap
,
""
);
s_sendmore
(
handler
,
"200"
);
s_sendmore
(
handler
,
"OK"
);
s_sendmore
(
handler
,
"anonymous"
);
s_send
(
handler
,
""
);
}
else
{
s_sendmore
(
zap
,
"400"
);
s_sendmore
(
zap
,
"Invalid client public key"
);
s_sendmore
(
zap
,
""
);
s_send
(
zap
,
""
);
s_sendmore
(
handler
,
"400"
);
s_sendmore
(
handler
,
"Invalid client public key"
);
s_sendmore
(
handler
,
""
);
s_send
(
handler
,
""
);
}
free
(
version
);
free
(
sequence
);
...
...
@@ -82,8 +76,7 @@ static void zap_handler (void *ctx)
free
(
identity
);
free
(
mechanism
);
}
rc
=
zmq_close
(
zap
);
assert
(
rc
==
0
);
zmq_close
(
handler
);
}
...
...
@@ -98,13 +91,19 @@ int main (void)
assert
(
ctx
);
// Spawn ZAP handler
void
*
zap_thread
=
zmq_threadstart
(
&
zap_handler
,
ctx
);
// We create and bind ZAP socket in main thread to avoid case
// where child thread does not start up fast enough.
void
*
handler
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
handler
);
int
rc
=
zmq_bind
(
handler
,
"inproc://zeromq.zap.01"
);
assert
(
rc
==
0
);
void
*
zap_thread
=
zmq_threadstart
(
&
zap_handler
,
handler
);
// Server socket will accept connections
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
int
as_server
=
1
;
int
rc
=
zmq_setsockopt
(
server
,
ZMQ_CURVE_SERVER
,
&
as_server
,
sizeof
(
int
));
rc
=
zmq_setsockopt
(
server
,
ZMQ_CURVE_SERVER
,
&
as_server
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_CURVE_SECRETKEY
,
server_secret
,
40
);
assert
(
rc
==
0
);
...
...
tests/test_security_null.cpp
View file @
971b275f
...
...
@@ -20,36 +20,30 @@
#include "testutil.hpp"
static
void
zap_handler
(
void
*
ctx
)
zap_handler
(
void
*
handler
)
{
// Create and bind ZAP socket
void
*
zap
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
zap
);
int
rc
=
zmq_bind
(
zap
,
"inproc://zeromq.zap.01"
);
assert
(
rc
==
0
);
// Process ZAP requests forever
while
(
true
)
{
char
*
version
=
s_recv
(
zap
);
char
*
version
=
s_recv
(
handler
);
if
(
!
version
)
break
;
// Terminating
char
*
sequence
=
s_recv
(
zap
);
char
*
domain
=
s_recv
(
zap
);
char
*
address
=
s_recv
(
zap
);
char
*
identity
=
s_recv
(
zap
);
char
*
mechanism
=
s_recv
(
zap
);
char
*
sequence
=
s_recv
(
handler
);
char
*
domain
=
s_recv
(
handler
);
char
*
address
=
s_recv
(
handler
);
char
*
identity
=
s_recv
(
handler
);
char
*
mechanism
=
s_recv
(
handler
);
assert
(
streq
(
version
,
"1.0"
));
assert
(
streq
(
mechanism
,
"NULL"
));
assert
(
streq
(
identity
,
"IDENT"
));
s_sendmore
(
zap
,
version
);
s_sendmore
(
zap
,
sequence
);
s_sendmore
(
zap
,
"200"
);
s_sendmore
(
zap
,
"OK"
);
s_sendmore
(
zap
,
"anonymous"
);
s_send
(
zap
,
""
);
s_sendmore
(
handler
,
version
);
s_sendmore
(
handler
,
sequence
);
s_sendmore
(
handler
,
"200"
);
s_sendmore
(
handler
,
"OK"
);
s_sendmore
(
handler
,
"anonymous"
);
s_send
(
handler
,
""
);
free
(
version
);
free
(
sequence
);
...
...
@@ -58,8 +52,7 @@ zap_handler (void *ctx)
free
(
identity
);
free
(
mechanism
);
}
rc
=
zmq_close
(
zap
);
assert
(
rc
==
0
);
zmq_close
(
handler
);
}
int
main
(
void
)
...
...
@@ -69,12 +62,18 @@ int main (void)
assert
(
ctx
);
// Spawn ZAP handler
void
*
zap_thread
=
zmq_threadstart
(
&
zap_handler
,
ctx
);
// We create and bind ZAP socket in main thread to avoid case
// where child thread does not start up fast enough.
void
*
handler
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
handler
);
int
rc
=
zmq_bind
(
handler
,
"inproc://zeromq.zap.01"
);
assert
(
rc
==
0
);
void
*
zap_thread
=
zmq_threadstart
(
&
zap_handler
,
handler
);
// Server socket will accept connections
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
int
rc
=
zmq_setsockopt
(
server
,
ZMQ_IDENTITY
,
"IDENT"
,
6
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_IDENTITY
,
"IDENT"
,
6
);
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_ZAP_DOMAIN
,
"TEST"
,
4
);
assert
(
rc
==
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment