mosquitto/test/lib/cpp/08-ssl-connect-cert-auth.cpp

67 lines
1.2 KiB
C++
Raw Normal View History

#include <cassert>
2023-12-23 13:59:58 +01:00
#include <mosquitto/libmosquittopp.h>
#include "path_helper.h"
2014-05-08 00:27:00 +02:00
static int run = -1;
class mosquittopp_test : public mosqpp::mosquittopp
{
public:
mosquittopp_test(const char *id);
void on_connect(int rc);
void on_disconnect(int rc);
};
mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
{
}
void mosquittopp_test::on_connect(int rc)
{
if(rc){
exit(1);
}else{
disconnect();
}
}
void mosquittopp_test::on_disconnect(int rc)
{
run = rc;
}
int main(int argc, char *argv[])
{
2024-02-26 01:19:49 +01:00
mosquittopp_test *mosq;
2014-05-08 00:27:00 +02:00
assert(argc == 2);
int port = atoi(argv[1]);
2014-05-08 00:27:00 +02:00
mosqpp::lib_init();
mosq = new mosquittopp_test("08-ssl-connect-crt-auth");
char cafile[4096];
cat_sourcedir_with_relpath(cafile, "/../../ssl/test-root-ca.crt");
char capath[4096];
cat_sourcedir_with_relpath(capath, "/../../ssl/certs");
char certfile[4096];
cat_sourcedir_with_relpath(certfile, "/../../ssl/client.crt");
char keyfile[4096];
cat_sourcedir_with_relpath(keyfile, "/../../ssl/client.key");
mosq->tls_set(cafile, capath, certfile, keyfile);
mosq->connect("localhost", port, 60);
2014-05-08 00:27:00 +02:00
while(run == -1){
mosq->loop();
}
2020-08-12 12:01:28 +02:00
delete mosq;
2014-05-08 00:27:00 +02:00
2020-05-05 12:56:10 +02:00
delete mosq;
2014-05-08 00:27:00 +02:00
mosqpp::lib_cleanup();
return run;
}