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
53bc53da
Commit
53bc53da
authored
Jul 18, 2013
by
Martin Hurton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PLAIN mechanism to the latest ZAP revision
parent
d65231be
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
11 deletions
+32
-11
plain_mechanism.cpp
src/plain_mechanism.cpp
+22
-9
plain_mechanism.hpp
src/plain_mechanism.hpp
+3
-0
stream_engine.cpp
src/stream_engine.cpp
+2
-1
test_security.cpp
tests/test_security.cpp
+5
-1
No files found.
src/plain_mechanism.cpp
View file @
53bc53da
...
...
@@ -32,9 +32,11 @@
#include "wire.hpp"
zmq
::
plain_mechanism_t
::
plain_mechanism_t
(
session_base_t
*
session_
,
const
std
::
string
&
peer_address_
,
const
options_t
&
options_
)
:
mechanism_t
(
options_
),
session
(
session_
),
peer_address
(
peer_address_
),
expecting_zap_reply
(
false
),
state
(
options
.
as_server
?
waiting_for_hello
:
sending_hello
)
{
...
...
@@ -355,7 +357,7 @@ void zmq::plain_mechanism_t::send_zap_request (const std::string &username,
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
//
Sequence
frame
//
Request id
frame
rc
=
msg
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1"
,
1
);
...
...
@@ -370,6 +372,14 @@ void zmq::plain_mechanism_t::send_zap_request (const std::string &username,
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Address frame
rc
=
msg
.
init_size
(
peer_address
.
length
());
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
peer_address
.
c_str
(),
peer_address
.
length
());
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
5
);
errno_assert
(
rc
==
0
);
...
...
@@ -397,18 +407,19 @@ void zmq::plain_mechanism_t::send_zap_request (const std::string &username,
int
zmq
::
plain_mechanism_t
::
receive_and_process_zap_reply
()
{
int
rc
=
0
;
msg_t
msg
[
6
];
msg_t
msg
[
7
];
// ZAP reply consists of 7 frames
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
// Initialize all reply frames
for
(
int
i
=
0
;
i
<
7
;
i
++
)
{
rc
=
msg
[
i
].
init
();
errno_assert
(
rc
==
0
);
}
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
for
(
int
i
=
0
;
i
<
7
;
i
++
)
{
rc
=
session
->
read_zap_msg
(
&
msg
[
i
]);
if
(
rc
==
-
1
)
break
;
if
((
msg
[
i
].
flags
()
&
msg_t
::
more
)
==
(
i
<
5
?
0
:
msg_t
::
more
))
{
if
((
msg
[
i
].
flags
()
&
msg_t
::
more
)
==
(
i
<
6
?
0
:
msg_t
::
more
))
{
errno
=
EPROTO
;
rc
=
-
1
;
break
;
...
...
@@ -418,8 +429,6 @@ int zmq::plain_mechanism_t::receive_and_process_zap_reply ()
if
(
rc
!=
0
)
goto
error
;
return
0
;
// Address delimiter frame
if
(
msg
[
0
].
size
()
>
0
)
{
errno
=
EPROTO
;
...
...
@@ -432,7 +441,7 @@ int zmq::plain_mechanism_t::receive_and_process_zap_reply ()
goto
error
;
}
//
Sequence number
frame
//
Request id
frame
if
(
msg
[
2
].
size
()
!=
1
||
memcmp
(
msg
[
2
].
data
(),
"1"
,
1
))
{
errno
=
EPROTO
;
goto
error
;
...
...
@@ -444,8 +453,12 @@ int zmq::plain_mechanism_t::receive_and_process_zap_reply ()
goto
error
;
}
// Process metadata frame
rc
=
parse_metadata
(
static_cast
<
const
unsigned
char
*>
(
msg
[
6
].
data
()),
msg
[
6
].
size
());
error
:
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
for
(
int
i
=
0
;
i
<
7
;
i
++
)
{
const
int
rc2
=
msg
[
i
].
close
();
errno_assert
(
rc2
==
0
);
}
...
...
src/plain_mechanism.hpp
View file @
53bc53da
...
...
@@ -34,6 +34,7 @@ namespace zmq
public
:
plain_mechanism_t
(
session_base_t
*
session_
,
const
std
::
string
&
peer_address_
,
const
options_t
&
options_
);
virtual
~
plain_mechanism_t
();
...
...
@@ -60,6 +61,8 @@ namespace zmq
session_base_t
*
const
session
;
const
std
::
string
peer_address
;
// True iff we are awaiting reply from ZAP reply.
bool
expecting_zap_reply
;
...
...
src/stream_engine.cpp
View file @
53bc53da
...
...
@@ -530,7 +530,8 @@ bool zmq::stream_engine_t::handshake ()
}
else
if
(
memcmp
(
greeting_recv
+
12
,
"PLAIN
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
,
20
)
==
0
)
{
mechanism
=
new
(
std
::
nothrow
)
plain_mechanism_t
(
session
,
options
);
mechanism
=
new
(
std
::
nothrow
)
plain_mechanism_t
(
session
,
peer_address
,
options
);
alloc_assert
(
mechanism
);
}
#ifdef HAVE_LIBSODIUM
...
...
tests/test_security.cpp
View file @
53bc53da
...
...
@@ -28,6 +28,7 @@ zap_handler (void *zap)
char
*
version
=
s_recv
(
zap
);
char
*
sequence
=
s_recv
(
zap
);
char
*
domain
=
s_recv
(
zap
);
char
*
address
=
s_recv
(
zap
);
char
*
mechanism
=
s_recv
(
zap
);
char
*
username
=
s_recv
(
zap
);
char
*
password
=
s_recv
(
zap
);
...
...
@@ -41,17 +42,20 @@ zap_handler (void *zap)
&&
streq
(
password
,
"password"
))
{
s_sendmore
(
zap
,
"200"
);
s_sendmore
(
zap
,
"OK"
);
s_send
(
zap
,
"anonymous"
);
s_sendmore
(
zap
,
"anonymous"
);
s_send
(
zap
,
""
);
}
else
{
s_sendmore
(
zap
,
"400"
);
s_sendmore
(
zap
,
"Invalid username or password"
);
s_sendmore
(
zap
,
""
);
s_send
(
zap
,
""
);
}
free
(
version
);
free
(
sequence
);
free
(
domain
);
free
(
address
);
free
(
mechanism
);
free
(
username
);
free
(
password
);
...
...
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