mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-27 15:41:05 +08:00
7296fb5b15
Solution: support websocket with tls (wss)
151 lines
7.9 KiB
C++
151 lines
7.9 KiB
C++
/*
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
by the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
As a special exception, the Contributors give you permission to link
|
|
this library with independent modules to produce an executable,
|
|
regardless of the license terms of these independent modules, and to
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
provided that you also meet, for each linked independent module, the
|
|
terms and conditions of the license of that module. An independent
|
|
module is a module which is not derived from or based on this library.
|
|
If you modify this library, you must extend this exception to your
|
|
version of the library.
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include "testutil.hpp"
|
|
#include "testutil_unity.hpp"
|
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
|
|
|
const char *key =
|
|
"-----BEGIN PRIVATE KEY-----\n"
|
|
"MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQCrXKFPWrRqbdNo\n"
|
|
"ltLhL8YYva5au+f3ntrOybMJmhWJdkXL1DxC5F6XDNNzYET+WTrBpwfY1yX6OYZw\n"
|
|
"Bpnh9K/Kb00wJTkd6MxeqEV2eTp7iAt/BzmWNXIausykXuBuWq+M+oFXXlTbgFXL\n"
|
|
"lqV8/B+1klxFuSjNxbDN+IBLgz7k86F2sAa6RoZ2jHW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rwXbtImjVaoelK8LvSwzKc6NLEEHgsa3HMO\n"
|
|
"6z93LtCk+ocCrAABQor1S/fAq5TpL6btaUzAi2qfj5yWgZZnt7LkxLp+tHXtfif+\n"
|
|
"E/XAbpLYzkzTYi50IgEBkS1sjT5IOK9Yr0al2tDcQFGpS25SOz7BhCfnj3+MBD//\n"
|
|
"m4Y13hEvpYRBDnfhXCvwD9/wd6Xq1wA+lueDpwWbrfriTJo=\n"
|
|
"-----END CERTIFICATE-----";
|
|
|
|
void test_roundtrip ()
|
|
{
|
|
void *sb = test_context_socket (ZMQ_REP);
|
|
zmq_setsockopt (sb, ZMQ_WSS_CERT_PEM, cert, strlen (cert));
|
|
zmq_setsockopt (sb, ZMQ_WSS_KEY_PEM, key, strlen (key));
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "wss://*:5556/roundtrip"));
|
|
|
|
void *sc = test_context_socket (ZMQ_REQ);
|
|
zmq_setsockopt (sc, ZMQ_WSS_TRUST_PEM, cert, strlen (cert));
|
|
zmq_setsockopt (sc, ZMQ_WSS_HOSTNAME, "zeromq.org", strlen ("zeromq.org"));
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
zmq_connect (sc, "wss://127.0.0.1:5556/roundtrip"));
|
|
|
|
bounce (sb, sc);
|
|
|
|
test_context_socket_close (sc);
|
|
test_context_socket_close (sb);
|
|
}
|
|
|
|
int main ()
|
|
{
|
|
setup_test_environment ();
|
|
|
|
UNITY_BEGIN ();
|
|
RUN_TEST (test_roundtrip);
|
|
return UNITY_END ();
|
|
}
|