Skip to content

Commit

Permalink
use tlsuv api correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
scareything committed Sep 1, 2023
1 parent 74104f0 commit b9151e0
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/Ziti.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,31 +416,25 @@ import CZitiPrivate
// setup TLS
let caLen = (id.ca == nil ? 0 : id.ca!.count + 1)
tls = default_tls_context(id.ca?.cString(using: .utf8), caLen)
var tlsStat = tls?.pointee.api.pointee.set_own_cert(tls?.pointee.ctx,
certPEM.cString(using: .utf8),
certPEM.count + 1)

var tlsKey:tlsuv_private_key_t?
var tlsStat = tls?.pointee.api.pointee.load_key(&tlsKey, privKeyPEM.cString(using: .utf8), privKeyPEM.count + 1)
guard tlsStat == 0 else {
let errStr = "unable to configure TLS certificate, error code: \(tlsStat ?? 0)"
let errStr = "unable to load TLS private key, error code: \(tlsStat ?? 0)"
log.error(errStr)
initCallback(ZitiError(errStr, errorCode: Int(tlsStat ?? 0)))
return
}

var pk = tlsuv_private_key_s()
tlsStat = withUnsafeMutablePointer(to: &pk) {
$0.withMemoryRebound(to: tlsuv_private_key_t?.self, capacity: 1) {
tls?.pointee.api.pointee.load_key($0, privKeyPEM.cString(using: .utf8), privKeyPEM.count + 1)
}
}

tlsStat = tls?.pointee.api.pointee.set_own_cert(tls?.pointee.ctx, certPEM.cString(using: .utf8), certPEM.count + 1)
guard tlsStat == 0 else {
let errStr = "unable to load TLS private key, error code: \(tlsStat ?? 0)"
let errStr = "unable to configure TLS certificate, error code: \(tlsStat ?? 0)"
log.error(errStr)
initCallback(ZitiError(errStr, errorCode: Int(tlsStat ?? 0)))
return
}

tlsStat = tls?.pointee.api.pointee.set_own_key(tls?.pointee.ctx, &pk)
tlsStat = tls?.pointee.api.pointee.set_own_key(tls?.pointee.ctx, tlsKey)
guard tlsStat == 0 else {
let errStr = "unable to configure TLS private key, error code: \(tlsStat ?? 0)"
log.error(errStr)
Expand Down

0 comments on commit b9151e0

Please sign in to comment.