From 6d7c07ecd47dfd00d636e49bb37bf58cf1fd8087 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 Jul 2018 19:15:19 -0400 Subject: [PATCH] Modify -descriptionForErrorCode: The method is now nonnull and returns "Unknown" for out of range error codes --- Sources/Shared/Headers/RCMSecureTransport.h | 4 +++- Sources/Shared/Library/RCMSecureTransport.m | 6 ++++-- .../Classes/IRC/IRCConnectionSocket.swift | 11 +++++------ .../en.lproj/SecureTransportErrorCodes.strings | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Sources/Shared/Headers/RCMSecureTransport.h b/Sources/Shared/Headers/RCMSecureTransport.h index f8c1066d3..8966918a6 100644 --- a/Sources/Shared/Headers/RCMSecureTransport.h +++ b/Sources/Shared/Headers/RCMSecureTransport.h @@ -32,7 +32,8 @@ typedef NS_ENUM(NSUInteger, RCMCipherSuiteCollection) { + (BOOL)isTLSError:(NSError *)error; + (nullable NSString *)descriptionForError:(NSError *)error; -+ (nullable NSString *)descriptionForErrorCode:(NSInteger)errorCode; +/* -descriptionForErrorCode: returns "Unknown" for out of range error codes */ ++ (NSString *)descriptionForErrorCode:(NSInteger)errorCode; + (nullable NSString *)descriptionForBadCertificateError:(NSError *)error; + (nullable NSString *)descriptionForBadCertificateErrorCode:(NSInteger)errorCode; + (BOOL)isBadCertificateError:(NSError *)error; @@ -45,3 +46,4 @@ typedef NS_ENUM(NSUInteger, RCMCipherSuiteCollection) { @end NS_ASSUME_NONNULL_END + diff --git a/Sources/Shared/Library/RCMSecureTransport.m b/Sources/Shared/Library/RCMSecureTransport.m index bfe288603..eda26e2eb 100644 --- a/Sources/Shared/Library/RCMSecureTransport.m +++ b/Sources/Shared/Library/RCMSecureTransport.m @@ -58,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN +static OSStatus errSSLUnknownError = -9999; + static const int kAEADMACValue = 7; static const int kTLS13KeyExchangeValue = 31; @@ -561,10 +563,10 @@ static const char * _Nonnull kMacNames[] = { return [self descriptionForErrorCode:error.code]; } -+ (nullable NSString *)descriptionForErrorCode:(NSInteger)errorCode ++ (NSString *)descriptionForErrorCode:(NSInteger)errorCode { if (errorCode > (-9800) || errorCode < (-9865)) { - return nil; + errorCode = errSSLUnknownError; } /* Request the heading for the formatted error message. */ diff --git a/XPC Services/IRC Remote Connection Manager/Classes/IRC/IRCConnectionSocket.swift b/XPC Services/IRC Remote Connection Manager/Classes/IRC/IRCConnectionSocket.swift index 219eb72b6..71d2f5958 100644 --- a/XPC Services/IRC Remote Connection Manager/Classes/IRC/IRCConnectionSocket.swift +++ b/XPC Services/IRC Remote Connection Manager/Classes/IRC/IRCConnectionSocket.swift @@ -208,19 +208,18 @@ extension ConnectionError self.init(tlsError: error.code) } - init? (tlsError errorCode: Int) + /// init(tlsError:) returns .unableToSecure("Unknown") for out of range error codes + init (tlsError errorCode: Int) { if let certError = RCMSecureTransport.description(forBadCertificateErrorCode: errorCode) { self = .badCertificate(failureReason: certError) - return - } else if let tlsError = RCMSecureTransport.description(forErrorCode: errorCode) { - self = .unableToSecure(failureReason: tlsError) - return } - return nil + let tlsError = RCMSecureTransport.description(forErrorCode: errorCode) + + self = .unableToSecure(failureReason: tlsError) } } diff --git a/XPC Services/IRC Remote Connection Manager/Resources/Language Files/en.lproj/SecureTransportErrorCodes.strings b/XPC Services/IRC Remote Connection Manager/Resources/Language Files/en.lproj/SecureTransportErrorCodes.strings index 84c6de735..3d9d71369 100644 --- a/XPC Services/IRC Remote Connection Manager/Resources/Language Files/en.lproj/SecureTransportErrorCodes.strings +++ b/XPC Services/IRC Remote Connection Manager/Resources/Language Files/en.lproj/SecureTransportErrorCodes.strings @@ -103,3 +103,6 @@ "-9863" = "Certificate required"; // errSSLCertificateRequired "-9864" = "Unknown PSK identity"; // errSSLUnknownPSKIdentity "-9865" = "Unknown or unrecognized name"; // errSSLUnrecognizedName + +/* errSSLUnknownError is defined by our own library. Not Secure Transport. */ +"-9999" = "Unknown"; // errSSLUnknownError