Skip to content

Commit

Permalink
Update SSLConnectionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 27, 2024
1 parent b1ef3b4 commit c062ed8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
17 changes: 1 addition & 16 deletions swift/src/Ice/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,7 @@ public final class SSLConnectionInfo: ConnectionInfo {
/// The certificate chain.
public let peerCertificate: SecCertificate?

internal init(underlying: ConnectionInfo, peerCertificate: String) {
let beginPrefix = "-----BEGIN CERTIFICATE-----\n"
let endPrefix = "\n-----END CERTIFICATE-----\n"

var raw = peerCertificate
if raw.hasPrefix(beginPrefix) {
raw = String(raw.dropFirst(beginPrefix.count))
raw = String(raw.dropLast(endPrefix.count))
}

var peerCertificate: SecCertificate? = nil
if let data = NSData(base64Encoded: raw, options: .ignoreUnknownCharacters) {
if let cert = SecCertificateCreateWithData(kCFAllocatorDefault, data) {
peerCertificate = cert
}
}
internal init(underlying: ConnectionInfo, peerCertificate: SecCertificate?) {
self.peerCertificate = peerCertificate
super.init(underlying: underlying)
}
Expand Down
18 changes: 17 additions & 1 deletion swift/src/Ice/ConnectionInfoFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,23 @@ class ConnectionInfoFactory: ICEConnectionInfoFactory {
}

static func createSSLConnectionInfo(_ underlying: Any, peerCertificate: String) -> Any {
SSLConnectionInfo(underlying: underlying as! ConnectionInfo, peerCertificate: peerCertificate)
let beginPrefix = "-----BEGIN CERTIFICATE-----\n"
let endPrefix = "\n-----END CERTIFICATE-----\n"

var raw = peerCertificate
if raw.hasPrefix(beginPrefix) {
raw = String(raw.dropFirst(beginPrefix.count))
raw = String(raw.dropLast(endPrefix.count))
}

var decodedPeerCertificate: SecCertificate? = nil
if let data = NSData(base64Encoded: raw, options: .ignoreUnknownCharacters) {
if let cert = SecCertificateCreateWithData(kCFAllocatorDefault, data) {
decodedPeerCertificate = cert
}
}

return SSLConnectionInfo(underlying: underlying as! ConnectionInfo, peerCertificate: decodedPeerCertificate)
}

static func createIAPConnectionInfo(
Expand Down

0 comments on commit c062ed8

Please sign in to comment.