From bdd815ec47c40176bb4bb7aca8c9aadc23339efe Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 23 Jun 2013 12:55:23 +0200 Subject: [PATCH] Adjust to reworked exception API. --- configure.ac | 2 +- src/SSLInvalidCertificateException.h | 6 +-- src/SSLInvalidCertificateException.m | 16 +++---- src/SSLSocket.m | 70 ++++++++++------------------ src/X509Certificate.m | 7 ++- 5 files changed, 36 insertions(+), 65 deletions(-) diff --git a/configure.ac b/configure.ac index 96cfe2f..1ab898a 100644 --- a/configure.ac +++ b/configure.ac @@ -50,7 +50,7 @@ AS_IF([test x"$GOBJC" = x"yes"], [ OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wpointer-arith" dnl We need -Wno-deprecated-declarations as OpenSSL is deprecated on dnl OS X. - OBJCFLAGS="$OBJCFLAGS -Wno-deprecated-declarations" # -Werror + OBJCFLAGS="$OBJCFLAGS -Wno-deprecated-declarations" ]) BUILDSYS_INIT diff --git a/src/SSLInvalidCertificateException.h b/src/SSLInvalidCertificateException.h index b7e8523..5e01af8 100644 --- a/src/SSLInvalidCertificateException.h +++ b/src/SSLInvalidCertificateException.h @@ -33,9 +33,7 @@ @property (readonly, assign) OFString *reason; #endif -+ exceptionWithClass: (Class)class - reason: (OFString*)reason; -- initWithClass: (Class)class - reason: (OFString*)reason; ++ exceptionWithReason: (OFString*)reason; +- initWithReason: (OFString*)reason; - (OFString*)reason; @end diff --git a/src/SSLInvalidCertificateException.m b/src/SSLInvalidCertificateException.m index abfd9f0..bdaca18 100644 --- a/src/SSLInvalidCertificateException.m +++ b/src/SSLInvalidCertificateException.m @@ -28,14 +28,12 @@ #import @implementation SSLInvalidCertificateException -+ exceptionWithClass: (Class)class - reason: (OFString*)reason ++ exceptionWithReason: (OFString*)reason { - return [[[self alloc] initWithClass: class - reason: reason] autorelease]; + return [[[self alloc] initWithReason: reason] autorelease]; } -- initWithClass: (Class)class +- init { @try { [self doesNotRecognizeSelector: _cmd]; @@ -47,10 +45,9 @@ abort(); } -- initWithClass: (Class)class - reason: (OFString*)reason +- initWithReason: (OFString*)reason { - self = [super initWithClass: class]; + self = [super init]; @try { _reason = [reason copy]; @@ -72,8 +69,7 @@ - (OFString*)description { return [OFString stringWithFormat: - @"Invalid certificate in class %@! Reason: %@", [self inClass], - _reason]; + @"Invalid certificate! Reason: %@", _reason]; } - (OFString*)reason diff --git a/src/SSLSocket.m b/src/SSLSocket.m index 9b0010a..e70c6ff 100644 --- a/src/SSLSocket.m +++ b/src/SSLSocket.m @@ -140,10 +140,9 @@ locking_callback(int mode, int n, const char *file, int line) if ((_SSL = SSL_new(ctx)) == NULL || !SSL_set_fd(_SSL, _socket)) { [super close]; @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: nil - port: 0]; + exceptionWithHost: nil + port: 0 + socket: self]; } SSL_set_connect_state(_SSL); @@ -156,10 +155,9 @@ locking_callback(int mode, int n, const char *file, int line) SSL_FILETYPE_PEM)) || SSL_connect(_SSL) != 1) { [super close]; @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: nil - port: 0]; + exceptionWithHost: nil + port: 0 + socket: self]; } } @@ -169,15 +167,7 @@ locking_callback(int mode, int n, const char *file, int line) [super connectToHost: host port: port]; - @try { - [self startTLS]; - } @catch (OFConnectionFailedException *e) { - @throw [OFConnectionFailedException - exceptionWithClass: [self class] - socket: self - host: host - port: port]; - } + [self startTLS]; } - (instancetype)accept @@ -187,8 +177,7 @@ locking_callback(int mode, int n, const char *file, int line) if ((client->_SSL = SSL_new(ctx)) == NULL || !SSL_set_fd(client->_SSL, client->_socket)) { [client SSL_super_close]; - @throw [OFAcceptFailedException exceptionWithClass: [self class] - socket: self]; + @throw [OFAcceptFailedException exceptionWithSocket: self]; } if (_requestsClientCertificates) @@ -202,8 +191,7 @@ locking_callback(int mode, int n, const char *file, int line) [_certificateFile cStringWithEncoding: OF_STRING_ENCODING_NATIVE], SSL_FILETYPE_PEM) || SSL_accept(client->_SSL) != 1) { [client SSL_super_close]; - @throw [OFAcceptFailedException exceptionWithClass: [self class] - socket: self]; + @throw [OFAcceptFailedException exceptionWithSocket: self]; } return client; @@ -228,18 +216,16 @@ locking_callback(int mode, int n, const char *file, int line) ssize_t ret; if (length > INT_MAX) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_socket == INVALID_SOCKET) - @throw [OFNotConnectedException exceptionWithClass: [self class] - socket: self]; + @throw [OFNotConnectedException exceptionWithSocket: self]; if (_atEndOfStream) { OFReadFailedException *e; - e = [OFReadFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + e = [OFReadFailedException exceptionWithStream: self + requestedLength: length]; #ifndef _WIN32 e->_errNo = ENOTCONN; #else @@ -253,9 +239,8 @@ locking_callback(int mode, int n, const char *file, int line) if (SSL_get_error(_SSL, ret) == SSL_ERROR_WANT_READ) return 0; - @throw [OFReadFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + @throw [OFReadFailedException exceptionWithStream: self + requestedLength: length]; } if (ret == 0) @@ -268,18 +253,16 @@ locking_callback(int mode, int n, const char *file, int line) length: (size_t)length { if (length > INT_MAX) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_socket == INVALID_SOCKET) - @throw [OFNotConnectedException exceptionWithClass: [self class] - socket: self]; + @throw [OFNotConnectedException exceptionWithSocket: self]; if (_atEndOfStream) { OFWriteFailedException *e; - e = [OFWriteFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + e = [OFWriteFailedException exceptionWithStream: self + requestedLength: length]; #ifndef _WIN32 e->_errNo = ENOTCONN; @@ -291,9 +274,8 @@ locking_callback(int mode, int n, const char *file, int line) } if (SSL_write(_SSL, buffer, (int)length) < length) - @throw [OFWriteFailedException exceptionWithClass: [self class] - stream: self - requestedLength: length]; + @throw [OFWriteFailedException exceptionWithStream: self + requestedLength: length]; } - (size_t)numberOfBytesInReadBuffer @@ -365,9 +347,7 @@ locking_callback(int mode, int n, const char *file, int line) OFDataArray *data; if (![type isEqual: @"tls-unique"]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; if (SSL_session_reused(_SSL) ^ !_listening) { /* @@ -407,12 +387,10 @@ locking_callback(int mode, int n, const char *file, int line) const char *tmp = X509_verify_cert_error_string(ret); OFString *reason = [OFString stringWithUTF8String: tmp]; @throw [SSLInvalidCertificateException - exceptionWithClass: [self class] - reason: reason]; + exceptionWithReason: reason]; } } else @throw [SSLInvalidCertificateException - exceptionWithClass: [self class] - reason: @"No certificate"]; + exceptionWithReason: @"No certificate"]; } @end diff --git a/src/X509Certificate.m b/src/X509Certificate.m index 9624572..5e7714b 100644 --- a/src/X509Certificate.m +++ b/src/X509Certificate.m @@ -53,7 +53,7 @@ _certificate = d2i_X509(NULL, &dataCArray, [data count]); if (_certificate == NULL) @throw [OFInitializationFailedException - exceptionWithClass: [self class]]; + exceptionWithClass: [self class]]; [pool release]; } @catch (id e) { @@ -72,7 +72,7 @@ _certificate = X509_dup(certificate); if (_certificate == NULL) @throw [OFInitializationFailedException - exceptionWithClass: [self class]]; + exceptionWithClass: [self class]]; } @catch (id e) { [self release]; @throw e; @@ -421,8 +421,7 @@ char *buffer; if (ASN1_STRING_to_UTF8((unsigned char**)&buffer, str) < 0) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; @try { ret = [OFString stringWithUTF8String: buffer];