aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

Connection Error with SSLHandshake failed -8210 #725

Closed chaunnt closed 6 years ago

chaunnt commented 7 years ago

I'm trying to use AWS-IOT-SDK-IOS Some background info:

I run this sample with steps as below:

  1. Create policy on AWS Console
  2. Create certificates with policy
  3. Download certs file
  4. Convert certs file to .p12 file by using command of OpenSLL

openssl pkcs12 -export -in e550256c49-certificate.pem.crt -inkey e550256c49-private.pem.key -out awsiot-identity.p12

  1. copy .p12 file to SupportingFiles folder of project
  2. Config plist.info (add "TLSv1.2" & set "HOSTNAME"=IOT_ENDPOINT or amazonaws.com
NSAppTransportSecurity
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>amazonaws.com</key>
        <dict>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>amazonaws.com.cn</key>
        <dict>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
  1. Modify Constants.swift

let AwsRegion = AWSRegionType.APNortheast1 // e.g. AWSRegionType.USEast1 let CognitoIdentityPoolId = "" let CertificateSigningRequestCommonName = "AWS IoT Certificate" let CertificateSigningRequestCountryName = "US" let CertificateSigningRequestOrganizationName = "Amazon.com Inc." let CertificateSigningRequestOrganizationalUnitName = "Amazon Web Services" let PolicyName = "MyPolicy" //This is the endpoint in your AWS IoT console. eg: https://xxxxxxxxxx.iot..amazonaws.com let IOT_ENDPOINT = "My Endpoint from Console -> Setting -> Endpoint"

  1. Run sample ===> Error show as below:

2017-08-16 18:15:36:100 IoTSampleSwift[15037:5553738] hostName: (null) 2017-08-16 18:15:36:100 IoTSampleSwift[15037:5553738] URL: a11sbx995fbvb0.iot.ap-northeast-1.amazonaws.com 2017-08-16 18:15:36:120 IoTSampleSwift[15037:5553738] -[MQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:runLoop:forMode:] [Line 167], Thread:<NSThread: 0x170072540>{number = 1, name = main} 2017-08-16 18:15:36:121 IoTSampleSwift[15037:5553738] +[MQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 66], Thread:<NSThread: 0x170072540>{number = 1, name = main} 2017-08-16 18:15:36:121 IoTSampleSwift[15037:5553738] Creating MQTTMessage with raw data >>>>> <00044d51 54540402 003c0024 46373739 34303337 2d334541 332d3433 37342d38 3142382d 36363738 31353346 42383743> <<<<< 2017-08-16 18:15:36:129 IoTSampleSwift[15037:5553738] Initializing MQTTEncoder and MQTTDecoder streams 2017-08-16 18:15:36:129 IoTSampleSwift[15037:5553738] opening encoder stream. 2017-08-16 18:15:36:131 IoTSampleSwift[15037:5553738] opening decoder stream. connection status = 1 Connecting... 2017-08-16 18:15:36.145127 IoTSampleSwift[15037:5553738] CFNetwork SSLHandshake failed (-9810) 2017-08-16 18:15:36:145 IoTSampleSwift[15037:5553738] MQTT session error, code: 3 2017-08-16 18:15:36:146 IoTSampleSwift[15037:5553738] closing encoder stream. 2017-08-16 18:15:36:146 IoTSampleSwift[15037:5553738] closing decoder stream. 2017-08-16 18:15:37:147 IoTSampleSwift[15037:5553738] MQTT session connection error connection status = 5 Connection Error

Please help us check if anything wrong :( :(

Note: we also copy libssl.a, libcrypto.a to "Supporting Files" folder

bxpan commented 6 years ago

Hi chaunnt,

The IoT endpoint must start with "https://" in constants.swift file, could you check if that is the case?

Thanks.

chaunnt commented 6 years ago

Thank you. That's the point :) we fixed it

NaiyerAghaz commented 5 years ago

Hi bpx I am getting this error when I connect AWS IOT

error 2019-01-08 15:18:30.912996+0530 My Taxi Ride[1450:821680] TCP Conn 0x2803de580 SSLHandshake failed (-9807) call@1 connectionError! 5 Please help me out