From 5b81aa6a7866d91c38cc5538d3a9772ba6fcb493 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 19 May 2019 12:03:46 +0200 Subject: [PATCH] Drop "Box" from error codes --- .../AppExtension/TunnelKitProvider.swift | 10 +++++----- TunnelKit/Sources/Core/Errors.h | 20 +++++++++---------- TunnelKit/Sources/OpenVPN/CryptoBox.m | 4 ++-- TunnelKit/Sources/OpenVPN/CryptoCBC.m | 6 +++--- TunnelKit/Sources/OpenVPN/CryptoCTR.m | 2 +- TunnelKit/Sources/OpenVPN/CryptoMacros.h | 2 +- TunnelKit/Sources/OpenVPN/TLSBox.m | 20 +++++++++---------- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index 2ef5a0e..49b0cf2 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -779,19 +779,19 @@ extension TunnelKitProvider { private func unifiedError(from error: Error) -> ProviderError { if let te = error.tunnelKitErrorCode() { switch te { - case .cryptoBoxRandomGenerator, .cryptoBoxAlgorithm: + case .cryptoRandomGenerator, .cryptoAlgorithm: return .encryptionInitialization - case .cryptoBoxEncryption, .cryptoBoxHMAC: + case .cryptoEncryption, .cryptoHMAC: return .encryptionData - case .tlsBoxCA, .tlsBoxClientCertificate, .tlsBoxClientKey: + case .tlsCertificateAuthority, .tlsClientCertificate, .tlsClientKey: return .tlsInitialization - case .tlsBoxServerCertificate, .tlsBoxServerEKU: + case .tlsServerCertificate, .tlsServerEKU: return .tlsServerVerification - case .tlsBoxHandshake: + case .tlsHandshake: return .tlsHandshake case .dataPathOverflow, .dataPathPeerIdMismatch: diff --git a/TunnelKit/Sources/Core/Errors.h b/TunnelKit/Sources/Core/Errors.h index bba47f2..44d71e2 100644 --- a/TunnelKit/Sources/Core/Errors.h +++ b/TunnelKit/Sources/Core/Errors.h @@ -40,16 +40,16 @@ extern NSString *const TunnelKitErrorDomain; extern NSString *const TunnelKitErrorKey; typedef NS_ENUM(NSInteger, TunnelKitErrorCode) { - TunnelKitErrorCodeCryptoBoxRandomGenerator = 101, - TunnelKitErrorCodeCryptoBoxHMAC = 102, - TunnelKitErrorCodeCryptoBoxEncryption = 103, - TunnelKitErrorCodeCryptoBoxAlgorithm = 104, - TunnelKitErrorCodeTLSBoxCA = 201, - TunnelKitErrorCodeTLSBoxHandshake = 202, - TunnelKitErrorCodeTLSBoxClientCertificate = 204, - TunnelKitErrorCodeTLSBoxClientKey = 205, - TunnelKitErrorCodeTLSBoxServerCertificate = 206, - TunnelKitErrorCodeTLSBoxServerEKU = 207, + TunnelKitErrorCodeCryptoRandomGenerator = 101, + TunnelKitErrorCodeCryptoHMAC = 102, + TunnelKitErrorCodeCryptoEncryption = 103, + TunnelKitErrorCodeCryptoAlgorithm = 104, + TunnelKitErrorCodeTLSCertificateAuthority = 201, + TunnelKitErrorCodeTLSHandshake = 202, + TunnelKitErrorCodeTLSClientCertificate = 204, + TunnelKitErrorCodeTLSClientKey = 205, + TunnelKitErrorCodeTLSServerCertificate = 206, + TunnelKitErrorCodeTLSServerEKU = 207, TunnelKitErrorCodeDataPathOverflow = 301, TunnelKitErrorCodeDataPathPeerIdMismatch = 302, TunnelKitErrorCodeDataPathCompression = 303, diff --git a/TunnelKit/Sources/OpenVPN/CryptoBox.m b/TunnelKit/Sources/OpenVPN/CryptoBox.m index 4dbe546..bb13b19 100644 --- a/TunnelKit/Sources/OpenVPN/CryptoBox.m +++ b/TunnelKit/Sources/OpenVPN/CryptoBox.m @@ -111,7 +111,7 @@ if ([self.cipherAlgorithm hasSuffix:@"-cbc"]) { if (!self.digestAlgorithm) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxAlgorithm); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoAlgorithm); } return NO; } @@ -132,7 +132,7 @@ // not supported else { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxAlgorithm); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoAlgorithm); } return NO; } diff --git a/TunnelKit/Sources/OpenVPN/CryptoCBC.m b/TunnelKit/Sources/OpenVPN/CryptoCBC.m index 26f19e8..fc5b2c2 100644 --- a/TunnelKit/Sources/OpenVPN/CryptoCBC.m +++ b/TunnelKit/Sources/OpenVPN/CryptoCBC.m @@ -153,7 +153,7 @@ const NSInteger CryptoCBCMaxHMACLength = 100; if (self.cipher) { if (RAND_bytes(outIV, self.cipherIVLength) != 1) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxRandomGenerator); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoRandomGenerator); } return NO; } @@ -216,7 +216,7 @@ const NSInteger CryptoCBCMaxHMACLength = 100; if (TUNNEL_CRYPTO_SUCCESS(code) && CRYPTO_memcmp(self.bufferDecHMAC, bytes, self.digestLength) != 0) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxHMAC); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoHMAC); } return NO; } @@ -241,7 +241,7 @@ const NSInteger CryptoCBCMaxHMACLength = 100; if (TUNNEL_CRYPTO_SUCCESS(code) && CRYPTO_memcmp(self.bufferDecHMAC, bytes, self.digestLength) != 0) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxHMAC); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoHMAC); } return NO; } diff --git a/TunnelKit/Sources/OpenVPN/CryptoCTR.m b/TunnelKit/Sources/OpenVPN/CryptoCTR.m index dd13dfa..d60ad18 100644 --- a/TunnelKit/Sources/OpenVPN/CryptoCTR.m +++ b/TunnelKit/Sources/OpenVPN/CryptoCTR.m @@ -196,7 +196,7 @@ static const NSInteger CryptoCTRTagLength = 32; if (TUNNEL_CRYPTO_SUCCESS(code) && CRYPTO_memcmp(self.bufferDecHMAC, bytes, CryptoCTRTagLength) != 0) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxHMAC); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoHMAC); } return NO; } diff --git a/TunnelKit/Sources/OpenVPN/CryptoMacros.h b/TunnelKit/Sources/OpenVPN/CryptoMacros.h index 28f48b0..1935d8c 100644 --- a/TunnelKit/Sources/OpenVPN/CryptoMacros.h +++ b/TunnelKit/Sources/OpenVPN/CryptoMacros.h @@ -41,7 +41,7 @@ #define TUNNEL_CRYPTO_RETURN_STATUS(ret)\ if (ret <= 0) {\ if (error) {\ - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxEncryption);\ + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoEncryption);\ }\ return NO;\ }\ diff --git a/TunnelKit/Sources/OpenVPN/TLSBox.m b/TunnelKit/Sources/OpenVPN/TLSBox.m index 003b094..9a29f32 100644 --- a/TunnelKit/Sources/OpenVPN/TLSBox.m +++ b/TunnelKit/Sources/OpenVPN/TLSBox.m @@ -53,7 +53,7 @@ static const char *const TLSBoxServerEKU = "TLS Web Server Authentication"; int TLSBoxVerifyPeer(int ok, X509_STORE_CTX *ctx) { if (!ok) { - NSError *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxCA); + NSError *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSCertificateAuthority); [[NSNotificationCenter defaultCenter] postNotificationName:TLSBoxPeerVerificationErrorNotification object:nil userInfo:@{TunnelKitErrorKey: error}]; @@ -213,7 +213,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; if (!SSL_CTX_load_verify_locations(self.ctx, [self.caPath cStringUsingEncoding:NSASCIIStringEncoding], NULL)) { ERR_print_errors_fp(stdout); if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxCA); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSCertificateAuthority); } return NO; } @@ -222,7 +222,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; if (!SSL_CTX_use_certificate_file(self.ctx, [self.clientCertificatePath cStringUsingEncoding:NSASCIIStringEncoding], SSL_FILETYPE_PEM)) { ERR_print_errors_fp(stdout); if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxClientCertificate); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSClientCertificate); } return NO; } @@ -231,7 +231,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; if (!SSL_CTX_use_PrivateKey_file(self.ctx, [self.clientKeyPath cStringUsingEncoding:NSASCIIStringEncoding], SSL_FILETYPE_PEM)) { ERR_print_errors_fp(stdout); if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxClientKey); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSClientKey); } return NO; } @@ -251,7 +251,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; if (!SSL_do_handshake(self.ssl)) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxHandshake); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSHandshake); } return NO; } @@ -271,7 +271,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; if (self.checksEKU && ![self verifyEKUWithSSL:self.ssl]) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxServerEKU); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSServerEKU); } return nil; } @@ -281,7 +281,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; } if ((ret < 0) && !BIO_should_retry(self.bioCipherTextOut)) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxHandshake); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSHandshake); } } return nil; @@ -299,7 +299,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; } if ((ret < 0) && !BIO_should_retry(self.bioPlainText)) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxHandshake); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSHandshake); } } return NO; @@ -321,7 +321,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; const int ret = BIO_write(self.bioCipherTextIn, text, (int)length); if (ret != length) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxHandshake); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSHandshake); } return NO; } @@ -342,7 +342,7 @@ const NSInteger TLSBoxDefaultSecurityLevel = -1; const int ret = BIO_write(self.bioPlainText, text, (int)length); if (ret != length) { if (error) { - *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSBoxHandshake); + *error = TunnelKitErrorWithCode(TunnelKitErrorCodeTLSHandshake); } return NO; }