You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
7.7 KiB

  1. diff --git a/lib/net_mosq.c b/lib/net_mosq.c
  2. index bdcaa19..f207e32 100644
  3. --- a/lib/net_mosq.c
  4. +++ b/lib/net_mosq.c
  5. @@ -141,7 +141,9 @@ int net__init(void)
  6. | OPENSSL_INIT_ADD_ALL_DIGESTS \
  7. | OPENSSL_INIT_LOAD_CONFIG, NULL);
  8. # endif
  9. +#if !defined(OPENSSL_NO_ENGINE)
  10. ENGINE_load_builtin_engines();
  11. +#endif
  12. setup_ui_method();
  13. if(tls_ex_index_mosq == -1){
  14. tls_ex_index_mosq = SSL_get_ex_new_index(0, "client context", NULL, NULL, NULL);
  15. @@ -599,6 +601,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  16. SSL_CTX_set_mode(mosq->ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
  17. #endif
  18. +#if !defined(OPENSSL_NO_ENGINE)
  19. if(mosq->tls_engine){
  20. engine = ENGINE_by_id(mosq->tls_engine);
  21. if(!engine){
  22. @@ -615,12 +618,15 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  23. ENGINE_set_default(engine, ENGINE_METHOD_ALL);
  24. ENGINE_free(engine); /* release the structural reference from ENGINE_by_id() */
  25. }
  26. +#endif
  27. if(mosq->tls_ciphers){
  28. ret = SSL_CTX_set_cipher_list(mosq->ssl_ctx, mosq->tls_ciphers);
  29. if(ret == 0){
  30. log__printf(mosq, MOSQ_LOG_ERR, "Error: Unable to set TLS ciphers. Check cipher list \"%s\".", mosq->tls_ciphers);
  31. +#if !defined(OPENSSL_NO_ENGINE)
  32. ENGINE_FINISH(engine);
  33. +#endif
  34. COMPAT_CLOSE(mosq->sock);
  35. mosq->sock = INVALID_SOCKET;
  36. net__print_ssl_error(mosq);
  37. @@ -647,7 +653,9 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  38. log__printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load CA certificates, check capath \"%s\".", mosq->tls_capath);
  39. }
  40. #endif
  41. +#if !defined(OPENSSL_NO_ENGINE)
  42. ENGINE_FINISH(engine);
  43. +#endif
  44. COMPAT_CLOSE(mosq->sock);
  45. mosq->sock = INVALID_SOCKET;
  46. net__print_ssl_error(mosq);
  47. @@ -672,7 +680,9 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  48. #else
  49. log__printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client certificate \"%s\".", mosq->tls_certfile);
  50. #endif
  51. +#if !defined(OPENSSL_NO_ENGINE)
  52. ENGINE_FINISH(engine);
  53. +#endif
  54. COMPAT_CLOSE(mosq->sock);
  55. mosq->sock = INVALID_SOCKET;
  56. net__print_ssl_error(mosq);
  57. @@ -681,6 +691,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  58. }
  59. if(mosq->tls_keyfile){
  60. if(mosq->tls_keyform == mosq_k_engine){
  61. +#if !defined(OPENSSL_NO_ENGINE)
  62. UI_METHOD *ui_method = net__get_ui_method();
  63. if(mosq->tls_engine_kpass_sha1){
  64. if(!ENGINE_ctrl_cmd(engine, ENGINE_SECRET_MODE, ENGINE_SECRET_MODE_SHA, NULL, NULL, 0)){
  65. @@ -714,6 +725,7 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  66. net__print_ssl_error(mosq);
  67. return MOSQ_ERR_TLS;
  68. }
  69. +#endif
  70. }else{
  71. ret = SSL_CTX_use_PrivateKey_file(mosq->ssl_ctx, mosq->tls_keyfile, SSL_FILETYPE_PEM);
  72. if(ret != 1){
  73. @@ -722,7 +734,9 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  74. #else
  75. log__printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client key file \"%s\".", mosq->tls_keyfile);
  76. #endif
  77. +#if !defined(OPENSSL_NO_ENGINE)
  78. ENGINE_FINISH(engine);
  79. +#endif
  80. COMPAT_CLOSE(mosq->sock);
  81. mosq->sock = INVALID_SOCKET;
  82. net__print_ssl_error(mosq);
  83. @@ -732,7 +746,9 @@ static int net__init_ssl_ctx(struct mosquitto *mosq)
  84. ret = SSL_CTX_check_private_key(mosq->ssl_ctx);
  85. if(ret != 1){
  86. log__printf(mosq, MOSQ_LOG_ERR, "Error: Client certificate/key are inconsistent.");
  87. +#if !defined(OPENSSL_NO_ENGINE)
  88. ENGINE_FINISH(engine);
  89. +#endif
  90. COMPAT_CLOSE(mosq->sock);
  91. mosq->sock = INVALID_SOCKET;
  92. net__print_ssl_error(mosq);
  93. diff --git a/lib/options.c b/lib/options.c
  94. index 005b781..6dc4262 100644
  95. --- a/lib/options.c
  96. +++ b/lib/options.c
  97. @@ -255,6 +255,7 @@ int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, cons
  98. switch(option){
  99. case MOSQ_OPT_TLS_ENGINE:
  100. #ifdef WITH_TLS
  101. +# if !defined(OPENSSL_NO_ENGINE)
  102. eng = ENGINE_by_id(value);
  103. if(!eng){
  104. return MOSQ_ERR_INVAL;
  105. @@ -265,6 +266,7 @@ int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, cons
  106. return MOSQ_ERR_NOMEM;
  107. }
  108. return MOSQ_ERR_SUCCESS;
  109. +#endif
  110. #else
  111. return MOSQ_ERR_NOT_SUPPORTED;
  112. #endif
  113. diff --git a/src/net.c b/src/net.c
  114. index 74b4ee8..495f8b2 100644
  115. --- a/src/net.c
  116. +++ b/src/net.c
  117. @@ -534,6 +534,7 @@ int net__socket_listen(struct mosquitto__listener *listener)
  118. return 1;
  119. }
  120. if(listener->tls_engine){
  121. +#if !defined(OPENSSL_NO_ENGINE)
  122. engine = ENGINE_by_id(listener->tls_engine);
  123. if(!engine){
  124. log__printf(NULL, MOSQ_LOG_ERR, "Error loading %s engine\n", listener->tls_engine);
  125. @@ -548,6 +549,7 @@ int net__socket_listen(struct mosquitto__listener *listener)
  126. }
  127. ENGINE_set_default(engine, ENGINE_METHOD_ALL);
  128. ENGINE_free(engine); /* release the structural reference from ENGINE_by_id() */
  129. +#endif
  130. }
  131. /* FIXME user data? */
  132. if(listener->require_certificate){
  133. @@ -560,10 +562,13 @@ int net__socket_listen(struct mosquitto__listener *listener)
  134. log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load server certificate \"%s\". Check certfile.", listener->certfile);
  135. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  136. COMPAT_CLOSE(sock);
  137. +#if !defined(OPENSSL_NO_ENGINE)
  138. ENGINE_FINISH(engine);
  139. +#endif
  140. return 1;
  141. }
  142. if(listener->tls_keyform == mosq_k_engine){
  143. +#if !defined(OPENSSL_NO_ENGINE)
  144. UI_METHOD *ui_method = net__get_ui_method();
  145. if(listener->tls_engine_kpass_sha1){
  146. if(!ENGINE_ctrl_cmd(engine, ENGINE_SECRET_MODE, ENGINE_SECRET_MODE_SHA, NULL, NULL, 0)){
  147. @@ -593,13 +598,16 @@ int net__socket_listen(struct mosquitto__listener *listener)
  148. ENGINE_FINISH(engine);
  149. return 1;
  150. }
  151. +#endif
  152. }else{
  153. rc = SSL_CTX_use_PrivateKey_file(listener->ssl_ctx, listener->keyfile, SSL_FILETYPE_PEM);
  154. if(rc != 1){
  155. log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load server key file \"%s\". Check keyfile.", listener->keyfile);
  156. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  157. COMPAT_CLOSE(sock);
  158. +#if !defined(OPENSSL_NO_ENGINE)
  159. ENGINE_FINISH(engine);
  160. +#endif
  161. return 1;
  162. }
  163. }
  164. @@ -608,7 +616,9 @@ int net__socket_listen(struct mosquitto__listener *listener)
  165. log__printf(NULL, MOSQ_LOG_ERR, "Error: Server certificate/key are inconsistent.");
  166. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  167. COMPAT_CLOSE(sock);
  168. +#if !defined(OPENSSL_NO_ENGINE)
  169. ENGINE_FINISH(engine);
  170. +#endif
  171. return 1;
  172. }
  173. /* Load CRLs if they exist. */
  174. @@ -618,7 +628,9 @@ int net__socket_listen(struct mosquitto__listener *listener)
  175. log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to obtain TLS store.");
  176. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  177. COMPAT_CLOSE(sock);
  178. +#if !defined(OPENSSL_NO_ENGINE)
  179. ENGINE_FINISH(engine);
  180. +#endif
  181. return 1;
  182. }
  183. lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
  184. @@ -627,7 +639,9 @@ int net__socket_listen(struct mosquitto__listener *listener)
  185. log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load certificate revocation file \"%s\". Check crlfile.", listener->crlfile);
  186. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  187. COMPAT_CLOSE(sock);
  188. +#if !defined(OPENSSL_NO_ENGINE)
  189. ENGINE_FINISH(engine);
  190. +#endif
  191. return 1;
  192. }
  193. X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK);
  194. @@ -644,7 +658,9 @@ int net__socket_listen(struct mosquitto__listener *listener)
  195. if(mosquitto__tls_server_ctx(listener)){
  196. COMPAT_CLOSE(sock);
  197. +#if !defined(OPENSSL_NO_ENGINE)
  198. ENGINE_FINISH(engine);
  199. +#endif
  200. return 1;
  201. }
  202. SSL_CTX_set_psk_server_callback(listener->ssl_ctx, psk_server_callback);
  203. @@ -654,7 +670,9 @@ int net__socket_listen(struct mosquitto__listener *listener)
  204. log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to set TLS PSK hint.");
  205. net__print_error(MOSQ_LOG_ERR, "Error: %s");
  206. COMPAT_CLOSE(sock);
  207. +#if !defined(OPENSSL_NO_ENGINE)
  208. ENGINE_FINISH(engine);
  209. +#endif
  210. return 1;
  211. }
  212. }