{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/344","repository_url":"https://api.github.com/repos/eclipse/paho.mqtt.c","labels_url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/344/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/344/comments","events_url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/344/events","html_url":"https://github.com/eclipse/paho.mqtt.c/issues/344","id":268156576,"number":344,"title":"SSL: handshake failure","user":{"login":"dontsovcmc","id":6192152,"avatar_url":"https://avatars3.githubusercontent.com/u/6192152?v=4","gravatar_id":"","url":"https://api.github.com/users/dontsovcmc","html_url":"https://github.com/dontsovcmc","followers_url":"https://api.github.com/users/dontsovcmc/followers","following_url":"https://api.github.com/users/dontsovcmc/following{/other_user}","gists_url":"https://api.github.com/users/dontsovcmc/gists{/gist_id}","starred_url":"https://api.github.com/users/dontsovcmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dontsovcmc/subscriptions","organizations_url":"https://api.github.com/users/dontsovcmc/orgs","repos_url":"https://api.github.com/users/dontsovcmc/repos","events_url":"https://api.github.com/users/dontsovcmc/events{/privacy}","received_events_url":"https://api.github.com/users/dontsovcmc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-10-24T19:26:59Z","updated_at":"2017-10-26T15:23:58Z","closed_at":null,"author_association":"NONE","body":"I start to work with SSL for the first time and got error in MQTTClient_connect.\r\n\r\nEnvironment:\r\nWindows 10, x64, Visual Studio 12.0, openssl-1.0.2k.gz\r\n\r\nLibrary compile script:\r\n```\r\nrmdir /s /q build.paho\r\nmkdir build.paho\r\ncd build.paho\r\ncall \"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\vcvarsall.bat\" x64\r\ncmake -G \"Visual Studio 12 2013\" -DPAHO_BUILD_STATIC=FALSE -DPAHO_WITH_SSL=TRUE -DOPENSSL_SEARCH_PATH=\"D:\\CODE\\adapters\\var\\env\\win32_vs2012\"  -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_CONFIGURATION_TYPES=\"Debug;Release\" -DCMAKE_VERBOSE_MAKEFILE=TRUE .. \r\n```\r\n\r\nI have CA file (ca.crt), Client Certificate File (client.crt), Client Key File (client.key) in PEM format.\r\nI run broker with cafile (ca.crt), certfile (server.crt), keyfile (server.key)\r\n\r\nI connect with MQTT.FX correctly using certificates, login, password.\r\n\r\nWhen I connect by my application I see:\r\n```\r\n1508873022: New connection from 192.168.50.10 on port 8883.\r\n1508873022: OpenSSL Error: error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure\r\n1508873022: Socket error on client <unknown>, disconnectin\r\n```\r\n\r\n\r\nWhat I do:\r\n\r\n```\r\nMQTTClient_init_options opt = MQTTClient_init_options_initializer;\r\nopt.do_openssl_init = true;\r\nMQTTClient_global_init(&opt);\r\n\r\nerror_ = MQTTClient_create(&client,  \"ssl://192.168.1.1:8883\",  \"XXXXX_id\",\r\n            MQTTCLIENT_PERSISTENCE_NONE, NULL);\r\n\r\nMQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;\r\n MQTTClient_SSLOptions ssl = MQTTClient_SSLOptions_initializer;\r\n\r\nssl.trustStore = \"ca.crt\";  //placed near exe file\r\nssl.keyStore = \"client.crt\";\r\nssl.privateKey = \"client.key\";\r\n//ssl.enabledCipherSuites = \"TLSv1.2\";  //OpenSSL Error: error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure with and without this field\r\nssl.enableServerCertAuth = true;\r\n\r\nconn_opts.ssl = &ssl;\r\nconn_opts.keepAliveInterval = 20;\r\nconn_opts.cleansession = true;\r\nconn_opts.username = \"user\";\r\nconn_opts.password = \"pwd\";\r\nconn_opts.MQTTVersion = MQTTVERSION_DEFAULT;\r\nconn_opts.connectTimeout = 10;\r\n\r\nerror_ = MQTTClient_setCallbacks(client, (void*)this, connection_lost, message_arrived, delivery_complete);\r\nif (error_ == MQTTCLIENT_SUCCESS)\r\n{\r\n       error_ = MQTTClient_connect(client, &conn_opts);   //return -1 after ~7 sec\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/comments/339702655","html_url":"https://github.com/eclipse/paho.mqtt.c/issues/344#issuecomment-339702655","issue_url":"https://api.github.com/repos/eclipse/paho.mqtt.c/issues/344","id":339702655,"user":{"login":"dontsovcmc","id":6192152,"avatar_url":"https://avatars3.githubusercontent.com/u/6192152?v=4","gravatar_id":"","url":"https://api.github.com/users/dontsovcmc","html_url":"https://github.com/dontsovcmc","followers_url":"https://api.github.com/users/dontsovcmc/followers","following_url":"https://api.github.com/users/dontsovcmc/following{/other_user}","gists_url":"https://api.github.com/users/dontsovcmc/gists{/gist_id}","starred_url":"https://api.github.com/users/dontsovcmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dontsovcmc/subscriptions","organizations_url":"https://api.github.com/users/dontsovcmc/orgs","repos_url":"https://api.github.com/users/dontsovcmc/repos","events_url":"https://api.github.com/users/dontsovcmc/events{/privacy}","received_events_url":"https://api.github.com/users/dontsovcmc/received_events","type":"User","site_admin":false},"created_at":"2017-10-26T15:23:58Z","updated_at":"2017-10-26T15:23:58Z","author_association":"NONE","body":"A \"good\" news: async client failed same way :/.\r\nI see in output\r\n```\r\n10468:error:20074002:BIO routines:FILE_CTRL:system lib:.\\crypto\\bio\\bss_file.c:404:\r\n10468:error:140DC002:SSL routines:SSL_CTX_use_certificate_chain_file:system lib:.\\ssl\\ssl_rsa.c:701:\r\n10468:error:20074002:BIO routines:FILE_CTRL:system lib:.\\crypto\\bio\\bss_file.c:404:\r\n10468:error:140DC002:SSL routines:SSL_CTX_use_certificate_chain_file:system lib:.\\ssl\\ssl_rsa.c:701:\r\nConnect failed, rc 0\r\n```\r\n\r\nThe socket_error is here:\r\n![screenshot_7](https://user-images.githubusercontent.com/6192152/32061607-c375f288-ba7a-11e7-8df6-6c32ae53d670.jpg)\r\naClient->net->ctx is null ( SSLSocket_setSocketForSSL returns 0\r\n\r\n"}}
{"actor":{"display_login":"dontsovcmc"}}