Adjust to reworked exception API.
This commit is contained in:
parent
fd21d0c65d
commit
bdd815ec47
5 changed files with 36 additions and 65 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -28,14 +28,12 @@
|
|||
#import <ObjFW/macros.h>
|
||||
|
||||
@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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
Reference in a new issue