Overview
Comment: | Implement setting the private key and certificate. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ce85c1fa591a7455cbb55ff44932b4ff |
User & Date: | js on 2011-03-28 22:23:32 |
Other Links: | manifest | tags |
Context
2011-03-28
| ||
23:59 | Fix stupid typo in Makefile. check-in: 10eba7be60 user: js tags: trunk | |
22:23 | Implement setting the private key and certificate. check-in: ce85c1fa59 user: js tags: trunk | |
21:38 | Have one global ctx. check-in: daea63b67c user: js tags: trunk | |
Changes
Modified src/SSLSocket.h from [2bdb858cf2] to [9b9ce91e67].
1 2 3 4 5 6 7 8 9 | #include <openssl/ssl.h> #import <ObjFW/OFTCPSocket.h> @interface SSLSocket: OFTCPSocket { SSL *ssl; } | > > < > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <openssl/ssl.h> #import <ObjFW/OFTCPSocket.h> @interface SSLSocket: OFTCPSocket { SSL *ssl; OFString *privateKeyFile; OFString *certificateFile; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *privateKeyFile; @property (copy) OFString *certificateFile; #endif - initWithSocket: (OFTCPSocket*)socket; /* Change the return type */ - (SSLSocket*)accept; - (void)setPrivateKeyFile: (OFString*)file; - (OFString*)privateKeyFile; - (void)setCertificateFile: (OFString*)file; - (OFString*)certificateFile; @end |
Modified src/SSLSocket.m from [cc5dffdd1c] to [3aca96c73c].
︙ | ︙ | |||
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | } - (void)dealloc { SSL_CTX *ctx_ = ctx; SSL *ssl_ = ssl; [super dealloc]; if (ssl_ != NULL) SSL_free(ssl_); if (ctx_ != NULL) SSL_CTX_free(ctx_); } | > > > | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | } - (void)dealloc { SSL_CTX *ctx_ = ctx; SSL *ssl_ = ssl; [privateKeyFile release]; [certificateFile release]; [super dealloc]; if (ssl_ != NULL) SSL_free(ssl_); if (ctx_ != NULL) SSL_CTX_free(ctx_); } |
︙ | ︙ | |||
108 109 110 111 112 113 114 | } } - (SSLSocket*)accept { SSLSocket *newsock = (SSLSocket*)[super accept]; | | > > > | > > | > > > | > > | > > | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | } } - (SSLSocket*)accept { SSLSocket *newsock = (SSLSocket*)[super accept]; if ((newsock->ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(newsock->ssl, newsock->sock)) { /* We only want to close the OFTCPSocket */ newsock->isa = [OFTCPSocket class]; [newsock close]; newsock->isa = isa; @throw [OFAcceptFailedException newWithClass: isa socket: self]; } SSL_set_accept_state(newsock->ssl); if (!SSL_use_PrivateKey_file(newsock->ssl, [privateKeyFile cString], SSL_FILETYPE_PEM) || !SSL_use_certificate_file(newsock->ssl, [certificateFile cString], SSL_FILETYPE_PEM) || SSL_accept(newsock->ssl) != 1) { /* We only want to close the OFTCPSocket */ newsock->isa = [OFTCPSocket class]; [newsock close]; newsock->isa = isa; @throw [OFAcceptFailedException newWithClass: isa socket: self]; } return newsock; } |
︙ | ︙ | |||
205 206 207 208 209 210 211 212 | if ((ret = SSL_write(ssl, buf, (int)size)) < 1) @throw [OFWriteFailedException newWithClass: isa stream: self requestedSize: size]; return ret; } @end | > > > > > > > > > > > > > > > > > > > > > > > > | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | if ((ret = SSL_write(ssl, buf, (int)size)) < 1) @throw [OFWriteFailedException newWithClass: isa stream: self requestedSize: size]; return ret; } - (void)setPrivateKeyFile: (OFString*)file { OFString *old = privateKeyFile; privateKeyFile = [file copy]; [old release]; } - (OFString*)privateKeyFile { return [[privateKeyFile copy] autorelease]; } - (void)setCertificateFile: (OFString*)file { OFString *old = certificateFile; certificateFile = [file copy]; [old release]; } - (OFString*)certificateFile { return [[certificateFile copy] autorelease]; } @end |