Add -[initWithSocket:].
This commit is contained in:
parent
47f4dd4fdb
commit
a4158274c3
2 changed files with 42 additions and 8 deletions
|
@ -9,6 +9,8 @@
|
||||||
BOOL handsShaken;
|
BOOL handsShaken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- initWithSocket: (OFTCPSocket*)socket;
|
||||||
|
|
||||||
/* Change the return type */
|
/* Change the return type */
|
||||||
- (SSLSocket*)accept;
|
- (SSLSocket*)accept;
|
||||||
@end
|
@end
|
||||||
|
|
48
SSLSocket.m
48
SSLSocket.m
|
@ -1,4 +1,6 @@
|
||||||
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#import <ObjFW/OFHTTPRequest.h>
|
#import <ObjFW/OFHTTPRequest.h>
|
||||||
|
|
||||||
|
@ -37,10 +39,40 @@
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
newWithClass: isa];
|
newWithClass: isa];
|
||||||
|
|
||||||
// if ((SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) &
|
if ((SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) &
|
||||||
// SSL_OP_NO_SSLv2) == 0)
|
SSL_OP_NO_SSLv2) == 0)
|
||||||
// @throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
// newWithClass: isa];
|
newWithClass: isa];
|
||||||
|
} @catch (id e) {
|
||||||
|
[self release];
|
||||||
|
@throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- initWithSocket: (OFTCPSocket*)socket
|
||||||
|
{
|
||||||
|
self = [self init];
|
||||||
|
|
||||||
|
@try {
|
||||||
|
sock = dup(socket->sock);
|
||||||
|
|
||||||
|
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
||||||
|
close(sock);
|
||||||
|
sock = INVALID_SOCKET;
|
||||||
|
@throw [OFInitializationFailedException
|
||||||
|
newWithClass: isa];
|
||||||
|
}
|
||||||
|
|
||||||
|
SSL_set_connect_state(ssl);
|
||||||
|
|
||||||
|
if (SSL_connect(ssl) != 1) {
|
||||||
|
close(sock);
|
||||||
|
sock = INVALID_SOCKET;
|
||||||
|
@throw [OFInitializationFailedException
|
||||||
|
newWithClass: isa];
|
||||||
|
}
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -69,7 +101,7 @@
|
||||||
onPort: port];
|
onPort: port];
|
||||||
|
|
||||||
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
||||||
[self close];
|
[super close];
|
||||||
@throw [OFConnectionFailedException newWithClass: isa
|
@throw [OFConnectionFailedException newWithClass: isa
|
||||||
socket: self
|
socket: self
|
||||||
host: host
|
host: host
|
||||||
|
@ -79,7 +111,7 @@
|
||||||
SSL_set_connect_state(ssl);
|
SSL_set_connect_state(ssl);
|
||||||
|
|
||||||
if (SSL_connect(ssl) != 1) {
|
if (SSL_connect(ssl) != 1) {
|
||||||
[self close];
|
[super close];
|
||||||
@throw [OFConnectionFailedException newWithClass: isa
|
@throw [OFConnectionFailedException newWithClass: isa
|
||||||
socket: self
|
socket: self
|
||||||
host: host
|
host: host
|
||||||
|
@ -92,7 +124,7 @@
|
||||||
SSLSocket *newsock = (SSLSocket*)[super accept];
|
SSLSocket *newsock = (SSLSocket*)[super accept];
|
||||||
|
|
||||||
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
||||||
[self close];
|
[super close];
|
||||||
@throw [OFAcceptFailedException newWithClass: isa
|
@throw [OFAcceptFailedException newWithClass: isa
|
||||||
socket: self];
|
socket: self];
|
||||||
}
|
}
|
||||||
|
@ -100,7 +132,7 @@
|
||||||
SSL_set_accept_state(ssl);
|
SSL_set_accept_state(ssl);
|
||||||
|
|
||||||
if (SSL_connect(ssl) != 1) {
|
if (SSL_connect(ssl) != 1) {
|
||||||
[self close];
|
[super close];
|
||||||
@throw [OFAcceptFailedException newWithClass: isa
|
@throw [OFAcceptFailedException newWithClass: isa
|
||||||
socket: self];
|
socket: self];
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue