Skip to content

Commit a3344e2

Browse files
committed
feat: can allow trust a untrust CA certificate
1 parent 9f5fe49 commit a3344e2

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CocoaMQTT.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "CocoaMQTT"
3-
s.version = "1.0.16"
3+
s.version = "1.0.17"
44
s.summary = "MQTT v3.1.1 client library for iOS and OS X written with Swift 3"
55
s.homepage = "https://github.com/emqtt/CocoaMQTT"
66
s.license = { :type => "MIT" }
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
1111
s.ios.deployment_target = "8.0"
1212
s.tvos.deployment_target = "9.0"
1313
# s.watchos.deployment_target = "2.0"
14-
s.source = { :git => "https://github.com/emqtt/CocoaMQTT.git", :tag => "1.0.16"}
14+
s.source = { :git => "https://github.com/emqtt/CocoaMQTT.git", :tag => "1.0.17"}
1515
s.source_files = "Source/{*.h}", "Source/*.swift"
1616
s.dependency "CocoaAsyncSocket", "~> 7.5.1"
1717
s.dependency "SwiftyTimer", "~> 2.0.0"

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ mqtt.connect()
7676

7777
```
7878

79+
## SSL Secure
80+
81+
1. One-way certification
82+
83+
No certificate is required locally.
84+
If you want to trust all untrust CA certificates, you can do this:
85+
86+
```swift
87+
mqtt.allowUntrustCACert = true
88+
```
89+
90+
2. Two-way certification
91+
92+
Need a .p12 file which is generated by a public key file and a private key file. You can generate the p12 file in the terminal:
93+
94+
```
95+
openssl pkcs12 -export -clcerts -in client-cert.pem -inkey client-key.pem -out client.p12
96+
```
97+
98+
7999

80100
CocoaMQTT
81101
==========

Source/CocoaMQTT.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ open class CocoaMQTT: NSObject, CocoaMQTTClient, CocoaMQTTFrameBufferProtocol {
162162
// ssl
163163
open var enableSSL = false
164164
open var sslSettings: [String: NSObject]?
165+
open var allowUntrustCACertificate = false
165166

166167
// subscribed topics. (dictionary structure -> [msgid: [topicString: QoS]])
167168
open var subscriptions: [UInt16: [String: CocoaMQTTQOS]] = [:]
@@ -329,7 +330,11 @@ extension CocoaMQTT: GCDAsyncSocketDelegate {
329330

330331
if enableSSL {
331332
if sslSettings == nil {
332-
sock.startTLS(nil)
333+
if allowUntrustCACertificate {
334+
sock.startTLS([GCDAsyncSocketManuallyEvaluateTrust: true as NSObject]) }
335+
else {
336+
sock.startTLS(nil)
337+
}
333338
} else {
334339
sslSettings![GCDAsyncSocketManuallyEvaluateTrust as String] = NSNumber(value: true)
335340
sock.startTLS(sslSettings!)

0 commit comments

Comments
 (0)