Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
5eb8d99a
Commit
5eb8d99a
authored
2 years ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
Add TLS support
parent
a76c6d0e
No related branches found
No related tags found
1 merge request
!463
MRC mods by Codefenix (2024-10-20)
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/mqtt.c
+34
-1
34 additions, 1 deletion
src/sbbs3/mqtt.c
with
34 additions
and
1 deletion
src/sbbs3/mqtt.c
+
34
−
1
View file @
5eb8d99a
...
@@ -240,7 +240,7 @@ int mqtt_open(struct mqtt* mqtt)
...
@@ -240,7 +240,7 @@ int mqtt_open(struct mqtt* mqtt)
return
MQTT_FAILURE
;
return
MQTT_FAILURE
;
SAFEPRINTF
(
client_id
,
"sbbs-%s"
,
mqtt
->
host
);
SAFEPRINTF
(
client_id
,
"sbbs-%s"
,
mqtt
->
host
);
#ifdef USE_MOSQUITTO
#ifdef USE_MOSQUITTO
mqtt
->
handle
=
mosquitto_new
(
client_id
,
/* clean_session: */
true
,
/*
obj: */
NULL
);
mqtt
->
handle
=
mosquitto_new
(
client_id
,
/* clean_session: */
true
,
/*
userdata: */
mqtt
);
return
mqtt
->
handle
==
NULL
?
MQTT_FAILURE
:
MQTT_SUCCESS
;
return
mqtt
->
handle
==
NULL
?
MQTT_FAILURE
:
MQTT_SUCCESS
;
#else
#else
return
MQTT_FAILURE
;
return
MQTT_FAILURE
;
...
@@ -257,6 +257,14 @@ void mqtt_close(struct mqtt* mqtt)
...
@@ -257,6 +257,14 @@ void mqtt_close(struct mqtt* mqtt)
#endif
#endif
}
}
static
int
pw_callback
(
char
*
buf
,
int
size
,
int
rwflag
,
void
*
userdata
)
{
struct
mqtt
*
mqtt
=
(
struct
mqtt
*
)
userdata
;
strncpy
(
buf
,
mqtt
->
cfg
->
mqtt
.
tls
.
keypass
,
size
);
return
strlen
(
mqtt
->
cfg
->
mqtt
.
tls
.
keypass
);
}
int
mqtt_connect
(
struct
mqtt
*
mqtt
,
const
char
*
bind_address
)
int
mqtt_connect
(
struct
mqtt
*
mqtt
,
const
char
*
bind_address
)
{
{
if
(
mqtt
==
NULL
||
mqtt
->
handle
==
NULL
||
mqtt
->
cfg
==
NULL
)
if
(
mqtt
==
NULL
||
mqtt
->
handle
==
NULL
||
mqtt
->
cfg
==
NULL
)
...
@@ -271,6 +279,31 @@ int mqtt_connect(struct mqtt* mqtt, const char* bind_address)
...
@@ -271,6 +279,31 @@ int mqtt_connect(struct mqtt* mqtt, const char* bind_address)
password
=
NULL
;
password
=
NULL
;
mosquitto_int_option
(
mqtt
->
handle
,
MOSQ_OPT_PROTOCOL_VERSION
,
mqtt
->
cfg
->
mqtt
.
protocol_version
);
mosquitto_int_option
(
mqtt
->
handle
,
MOSQ_OPT_PROTOCOL_VERSION
,
mqtt
->
cfg
->
mqtt
.
protocol_version
);
mosquitto_username_pw_set
(
mqtt
->
handle
,
username
,
password
);
mosquitto_username_pw_set
(
mqtt
->
handle
,
username
,
password
);
if
(
mqtt
->
cfg
->
mqtt
.
tls
.
mode
==
MQTT_TLS_CERT
)
{
char
*
certfile
=
NULL
;
char
*
keyfile
=
NULL
;
if
(
mqtt
->
cfg
->
mqtt
.
tls
.
certfile
[
0
]
&&
mqtt
->
cfg
->
mqtt
.
tls
.
keyfile
[
0
])
{
certfile
=
mqtt
->
cfg
->
mqtt
.
tls
.
certfile
;
keyfile
=
mqtt
->
cfg
->
mqtt
.
tls
.
keyfile
;
}
int
result
=
mosquitto_tls_set
(
mqtt
->
handle
,
mqtt
->
cfg
->
mqtt
.
tls
.
cafile
,
NULL
,
// capath
certfile
,
keyfile
,
pw_callback
);
if
(
result
!=
MOSQ_ERR_SUCCESS
)
return
result
;
}
else
if
(
mqtt
->
cfg
->
mqtt
.
tls
.
mode
==
MQTT_TLS_PSK
)
{
int
result
=
mosquitto_tls_psk_set
(
mqtt
->
handle
,
mqtt
->
cfg
->
mqtt
.
tls
.
psk
,
mqtt
->
cfg
->
mqtt
.
tls
.
identity
,
NULL
// ciphers (default)
);
if
(
result
!=
MOSQ_ERR_SUCCESS
)
return
result
;
}
return
mosquitto_connect_bind
(
mqtt
->
handle
,
return
mosquitto_connect_bind
(
mqtt
->
handle
,
mqtt
->
cfg
->
mqtt
.
broker_addr
,
mqtt
->
cfg
->
mqtt
.
broker_addr
,
mqtt
->
cfg
->
mqtt
.
broker_port
,
mqtt
->
cfg
->
mqtt
.
broker_port
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment