Skip to content

Commit

Permalink
Fix TLS connections not working over SOCKS.
Browse files Browse the repository at this point in the history
Thanks to Mark Oeltjenbruns.
  • Loading branch information
ralight committed Feb 8, 2019
1 parent a2b78d8 commit e8320cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Broker:
- Fixed comment handling for config options that have optional arguments.

Library:
- Fix TLS connections not working over SOCKS.

Build:
- Fix comparison of boolean values in CMake build. Closes #1101.
- Fix compilation when openssl deprecated APIs are not available.
Expand Down
11 changes: 8 additions & 3 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
#endif


int net__socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking)
int net__socket_connect_step3(struct mosquitto *mosq, const char *host)
{
#ifdef WITH_TLS
BIO *bio;
Expand Down Expand Up @@ -671,8 +671,13 @@ int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port,

mosq->sock = sock;

rc = net__socket_connect_step3(mosq, host, port, bind_address, blocking);
if(rc) return rc;
#ifdef WITH_SOCKS
if(!mosq->socks5_host)
#endif
{
rc = net__socket_connect_step3(mosq, host);
if(rc) return rc;
}

return MOSQ_ERR_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/net_mosq.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int net__socket_close(struct mosquitto *mosq);
int net__try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking);
int net__try_connect_step1(struct mosquitto *mosq, const char *host);
int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock);
int net__socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);
int net__socket_connect_step3(struct mosquitto *mosq, const char *host);
int net__socket_nonblock(mosq_sock_t *sock);
int net__socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2);

Expand Down
4 changes: 4 additions & 0 deletions lib/socks_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ int socks5__read(struct mosquitto *mosq)
/* Auth passed */
packet__cleanup(&mosq->in_packet);
mosq->state = mosq_cs_new;
if(mosq->socks5_host){
int rc = net__socket_connect_step3(mosq, mosq->host);
if(rc) return rc;
}
return send__connect(mosq, mosq->keepalive, mosq->clean_session);
}else{
i = mosq->in_packet.payload[1];
Expand Down

0 comments on commit e8320cb

Please sign in to comment.