Drop "Box" from error codes

This commit is contained in:
Davide De Rosa 2019-05-19 12:03:46 +02:00
parent ee4a446fa5
commit 5b81aa6a78
7 changed files with 32 additions and 32 deletions

View File

@ -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:

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -41,7 +41,7 @@
#define TUNNEL_CRYPTO_RETURN_STATUS(ret)\
if (ret <= 0) {\
if (error) {\
*error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoBoxEncryption);\
*error = TunnelKitErrorWithCode(TunnelKitErrorCodeCryptoEncryption);\
}\
return NO;\
}\

View File

@ -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;
}