13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
+
+
-
+
-
-
-
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
|
#import <ObjFW/OFOutOfRangeException.h>
#import <ObjFW/OFReadFailedException.h>
#import <ObjFW/OFWriteFailedException.h>
#ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
#endif
static SSL_CTX *ctx;
@implementation SSLSocket
+ (void)load
{
of_http_request_tls_socket_class = self;
}
+ (void)initialize
{
if (self == [SSLSocket class])
if (self != [SSLSocket class])
SSL_library_init();
}
return;
- init
{
self = [super init];
SSL_library_init();
@try {
if ((ctx = SSL_CTX_new(SSLv23_method())) == NULL)
@throw [OFInitializationFailedException
if ((ctx = SSL_CTX_new(SSLv23_method())) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
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: self];
newWithClass: isa];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- initWithSocket: (OFTCPSocket*)socket
{
self = [self init];
@try {
|