Skip to content

Commit

Permalink
Pass the native SecCertificate to Swift SSL ConnectionInfo - Fix #3283 (
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Jan 21, 2025
1 parent 624dbf4 commit 2ce28f6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
20 changes: 2 additions & 18 deletions swift/src/Ice/ConnectionInfoFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,9 @@ class ConnectionInfoFactory: ICEConnectionInfoFactory {
WSConnectionInfo(underlying: underlying as! ConnectionInfo, headers: headers)
}

static func createSSLConnectionInfo(_ underlying: Any, peerCertificate: String) -> Any {
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
}
}

static func createSSLConnectionInfo(_ underlying: Any, peerCertificate: SecCertificate) -> Any {
return SSLConnectionInfo(
underlying: underlying as! ConnectionInfo, peerCertificate: decodedPeerCertificate)
underlying: underlying as! ConnectionInfo, peerCertificate: peerCertificate)
}

static func createIAPConnectionInfo(
Expand Down
10 changes: 1 addition & 9 deletions swift/src/IceImpl/Connection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,7 @@ - (BOOL)throwException:(NSError**)error
auto sslInfo = std::dynamic_pointer_cast<Ice::SSL::ConnectionInfo>(infoPtr);
if (sslInfo)
{
std::string encoded;
// See https://github.com/zeroc-ice/ice/issues/3283
#if TARGET_OS_IPHONE == 0
if (sslInfo->peerCertificate)
{
encoded = Ice::SSL::encodeCertificate(sslInfo->peerCertificate);
}
#endif
return [factory createSSLConnectionInfo:underlying peerCertificate:toNSString(encoded)];
return [factory createSSLConnectionInfo:underlying peerCertificate:sslInfo->peerCertificate];
}

auto iapInfo = std::dynamic_pointer_cast<Ice::IAPConnectionInfo>(infoPtr);
Expand Down
2 changes: 1 addition & 1 deletion swift/src/IceImpl/include/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ICEIMPL_API @protocol ICEConnectionInfoFactory

+ (id)createWSConnectionInfo:(id)underlying headers:(NSDictionary<NSString*, NSString*>*)headers;

+ (id)createSSLConnectionInfo:(id)underlying peerCertificate:(NSString*)peerCertificate;
+ (id)createSSLConnectionInfo:(id)underlying peerCertificate:(SecCertificateRef)peerCertificate;

+ (id)createIAPConnectionInfo:(BOOL)incoming
adapterName:(NSString*)adapterName
Expand Down

0 comments on commit 2ce28f6

Please sign in to comment.