Prefix all ivars with an underscore.
This commit is contained in:
parent
fa191aa0dd
commit
bb240ea8aa
6 changed files with 147 additions and 142 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
||||||
|
* Copyright (c) 2013, Jonathan Schleifer <js@webkeks.org>
|
||||||
*
|
*
|
||||||
* https://webkeks.org/git/?p=objopenssl.git
|
* https://webkeks.org/git/?p=objopenssl.git
|
||||||
*
|
*
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
|
|
||||||
@interface SSLInvalidCertificateException: OFException
|
@interface SSLInvalidCertificateException: OFException
|
||||||
{
|
{
|
||||||
OFString *reason;
|
OFString *_reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
#ifdef OF_HAVE_PROPERTIES
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
||||||
|
* Copyright (c) 2013, Jonathan Schleifer <js@webkeks.org>
|
||||||
*
|
*
|
||||||
* https://webkeks.org/git/?p=objopenssl.git
|
* https://webkeks.org/git/?p=objopenssl.git
|
||||||
*
|
*
|
||||||
|
@ -22,17 +23,19 @@
|
||||||
|
|
||||||
#import "SSLInvalidCertificateException.h"
|
#import "SSLInvalidCertificateException.h"
|
||||||
|
|
||||||
|
#import <ObjFW/macros.h>
|
||||||
|
|
||||||
#import <ObjFW/OFNotImplementedException.h>
|
#import <ObjFW/OFNotImplementedException.h>
|
||||||
|
|
||||||
@implementation SSLInvalidCertificateException
|
@implementation SSLInvalidCertificateException
|
||||||
+ exceptionWithClass: (Class)class_
|
+ exceptionWithClass: (Class)class
|
||||||
reason: (OFString*)reason_
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithClass: class_
|
return [[[self alloc] initWithClass: class
|
||||||
reason: reason_] autorelease];
|
reason: reason] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithClass: (Class)class_
|
- initWithClass: (Class)class
|
||||||
{
|
{
|
||||||
Class c = [self class];
|
Class c = [self class];
|
||||||
[self release];
|
[self release];
|
||||||
|
@ -40,13 +43,13 @@
|
||||||
selector: _cmd];
|
selector: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithClass: (Class)class_
|
- initWithClass: (Class)class
|
||||||
reason: (OFString*)reason_
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
self = [super initWithClass: class_];
|
self = [super initWithClass: class];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
reason = [reason_ copy];
|
_reason = [reason copy];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -57,24 +60,24 @@
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[reason release];
|
[_reason release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)description
|
- (OFString*)description
|
||||||
{
|
{
|
||||||
if (description != nil)
|
if (_description != nil)
|
||||||
return description;
|
return _description;
|
||||||
|
|
||||||
description = [[OFString alloc] initWithFormat:
|
_description = [[OFString alloc] initWithFormat:
|
||||||
@"Invalid certificate! Reason: %@", reason];
|
@"Invalid certificate! Reason: %@", _reason];
|
||||||
|
|
||||||
return description;
|
return _description;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)reason
|
- (OFString*)reason
|
||||||
{
|
{
|
||||||
return reason;
|
OF_GETTER(_reason, NO)
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -29,15 +29,13 @@
|
||||||
|
|
||||||
@interface SSLSocket: OFTCPSocket
|
@interface SSLSocket: OFTCPSocket
|
||||||
{
|
{
|
||||||
SSL *ssl;
|
SSL *_SSL;
|
||||||
OFString *privateKeyFile;
|
OFString *_privateKeyFile, *_certificateFile;
|
||||||
OFString *certificateFile;
|
BOOL _requestsClientCertificates;
|
||||||
BOOL requestsClientCertificates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
#ifdef OF_HAVE_PROPERTIES
|
||||||
@property (copy) OFString *privateKeyFile;
|
@property (copy) OFString *privateKeyFile, *certificateFile;
|
||||||
@property (copy) OFString *certificateFile;
|
|
||||||
@property BOOL requestsClientCertificates;
|
@property BOOL requestsClientCertificates;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
151
src/SSLSocket.m
151
src/SSLSocket.m
|
@ -121,37 +121,38 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithSocket: (OFTCPSocket*)socket
|
- initWithSocket: (OFTCPSocket*)socket
|
||||||
privateKeyFile: (OFString*)privateKeyFile_
|
privateKeyFile: (OFString*)privateKeyFile
|
||||||
certificateFile: (OFString*)certificateFile_
|
certificateFile: (OFString*)certificateFile
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
/* FIXME: Also allow with accepted sockets */
|
/* FIXME: Also allow with accepted sockets */
|
||||||
|
|
||||||
privateKeyFile = [privateKeyFile_ copy];
|
_privateKeyFile = [privateKeyFile copy];
|
||||||
certificateFile = [certificateFile_ copy];
|
_certificateFile = [certificateFile copy];
|
||||||
|
|
||||||
sock = dup(socket->sock);
|
_socket = dup(socket->_socket);
|
||||||
|
|
||||||
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
if ((_SSL = SSL_new(ctx)) == NULL ||
|
||||||
close(sock);
|
!SSL_set_fd(_SSL, _socket)) {
|
||||||
sock = INVALID_SOCKET;
|
close(_socket);
|
||||||
|
_socket = INVALID_SOCKET;
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: [self class]];
|
exceptionWithClass: [self class]];
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_set_connect_state(ssl);
|
SSL_set_connect_state(_SSL);
|
||||||
|
|
||||||
if ((privateKeyFile != nil && !SSL_use_PrivateKey_file(ssl,
|
if ((_privateKeyFile != nil && !SSL_use_PrivateKey_file(_SSL,
|
||||||
[privateKeyFile cStringWithEncoding:
|
[_privateKeyFile cStringWithEncoding:
|
||||||
OF_STRING_ENCODING_NATIVE], SSL_FILETYPE_PEM)) ||
|
OF_STRING_ENCODING_NATIVE], SSL_FILETYPE_PEM)) ||
|
||||||
(certificateFile != nil && !SSL_use_certificate_file(ssl,
|
(_certificateFile != nil && !SSL_use_certificate_file(_SSL,
|
||||||
[certificateFile cStringWithEncoding:
|
[_certificateFile cStringWithEncoding:
|
||||||
OF_STRING_ENCODING_NATIVE], SSL_FILETYPE_PEM)) ||
|
OF_STRING_ENCODING_NATIVE], SSL_FILETYPE_PEM)) ||
|
||||||
SSL_connect(ssl) != 1) {
|
SSL_connect(_SSL) != 1) {
|
||||||
close(sock);
|
close(_socket);
|
||||||
sock = INVALID_SOCKET;
|
_socket = INVALID_SOCKET;
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: [self class]];
|
exceptionWithClass: [self class]];
|
||||||
}
|
}
|
||||||
|
@ -165,15 +166,15 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
SSL *ssl_ = ssl;
|
SSL *SSL_ = _SSL;
|
||||||
|
|
||||||
[privateKeyFile release];
|
[_privateKeyFile release];
|
||||||
[certificateFile release];
|
[_certificateFile release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
|
||||||
if (ssl_ != NULL)
|
if (SSL_ != NULL)
|
||||||
SSL_free(ssl_);
|
SSL_free(SSL_);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connectToHost: (OFString*)host
|
- (void)connectToHost: (OFString*)host
|
||||||
|
@ -182,7 +183,7 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
[super connectToHost: host
|
[super connectToHost: host
|
||||||
port: port];
|
port: port];
|
||||||
|
|
||||||
if ((ssl = SSL_new(ctx)) == NULL || !SSL_set_fd(ssl, sock)) {
|
if ((_SSL = SSL_new(ctx)) == NULL || !SSL_set_fd(_SSL, _socket)) {
|
||||||
[super close];
|
[super close];
|
||||||
@throw [OFConnectionFailedException
|
@throw [OFConnectionFailedException
|
||||||
exceptionWithClass: [self class]
|
exceptionWithClass: [self class]
|
||||||
|
@ -191,14 +192,14 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
port: port];
|
port: port];
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_set_connect_state(ssl);
|
SSL_set_connect_state(_SSL);
|
||||||
|
|
||||||
if ((privateKeyFile != nil && !SSL_use_PrivateKey_file(ssl,
|
if ((_privateKeyFile != nil && !SSL_use_PrivateKey_file(_SSL,
|
||||||
[privateKeyFile cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
[_privateKeyFile cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
||||||
SSL_FILETYPE_PEM)) || (certificateFile != nil &&
|
SSL_FILETYPE_PEM)) || (_certificateFile != nil &&
|
||||||
!SSL_use_certificate_file(ssl, [certificateFile
|
!SSL_use_certificate_file(_SSL, [_certificateFile
|
||||||
cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
||||||
SSL_FILETYPE_PEM)) || SSL_connect(ssl) != 1) {
|
SSL_FILETYPE_PEM)) || SSL_connect(_SSL) != 1) {
|
||||||
[super close];
|
[super close];
|
||||||
@throw [OFConnectionFailedException
|
@throw [OFConnectionFailedException
|
||||||
exceptionWithClass: [self class]
|
exceptionWithClass: [self class]
|
||||||
|
@ -210,45 +211,45 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
|
|
||||||
- (SSLSocket*)accept
|
- (SSLSocket*)accept
|
||||||
{
|
{
|
||||||
SSLSocket *newSocket = (SSLSocket*)[super accept];
|
SSLSocket *client = (SSLSocket*)[super accept];
|
||||||
|
|
||||||
if ((newSocket->ssl = SSL_new(ctx)) == NULL ||
|
if ((client->_SSL = SSL_new(ctx)) == NULL ||
|
||||||
!SSL_set_fd(newSocket->ssl, newSocket->sock)) {
|
!SSL_set_fd(client->_SSL, client->_socket)) {
|
||||||
/* We only want to close the OFTCPSocket */
|
/* We only want to close the OFTCPSocket */
|
||||||
object_setClass(newSocket, [OFTCPSocket class]);
|
object_setClass(client, [OFTCPSocket class]);
|
||||||
[newSocket close];
|
[client close];
|
||||||
object_setClass(newSocket, object_getClass(self));
|
object_setClass(client, object_getClass(self));
|
||||||
|
|
||||||
@throw [OFAcceptFailedException exceptionWithClass: [self class]
|
@throw [OFAcceptFailedException exceptionWithClass: [self class]
|
||||||
socket: self];
|
socket: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestsClientCertificates)
|
if (_requestsClientCertificates)
|
||||||
SSL_set_verify(newSocket->ssl, SSL_VERIFY_PEER, NULL);
|
SSL_set_verify(client->_SSL, SSL_VERIFY_PEER, NULL);
|
||||||
|
|
||||||
SSL_set_accept_state(newSocket->ssl);
|
SSL_set_accept_state(client->_SSL);
|
||||||
|
|
||||||
if (!SSL_use_PrivateKey_file(newSocket->ssl, [privateKeyFile
|
if (!SSL_use_PrivateKey_file(client->_SSL, [_privateKeyFile
|
||||||
cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
||||||
SSL_FILETYPE_PEM) || !SSL_use_certificate_file(newSocket->ssl,
|
SSL_FILETYPE_PEM) || !SSL_use_certificate_file(client->_SSL,
|
||||||
[certificateFile cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
[_certificateFile cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
|
||||||
SSL_FILETYPE_PEM) || SSL_accept(newSocket->ssl) != 1) {
|
SSL_FILETYPE_PEM) || SSL_accept(client->_SSL) != 1) {
|
||||||
/* We only want to close the OFTCPSocket */
|
/* We only want to close the OFTCPSocket */
|
||||||
object_setClass(newSocket, [OFTCPSocket class]);
|
object_setClass(client, [OFTCPSocket class]);
|
||||||
[newSocket close];
|
[client close];
|
||||||
object_setClass(newSocket, object_getClass(self));
|
object_setClass(client, object_getClass(self));
|
||||||
|
|
||||||
@throw [OFAcceptFailedException exceptionWithClass: [self class]
|
@throw [OFAcceptFailedException exceptionWithClass: [self class]
|
||||||
socket: self];
|
socket: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
return newSocket;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
if (ssl != NULL)
|
if (_SSL != NULL)
|
||||||
SSL_shutdown(ssl);
|
SSL_shutdown(_SSL);
|
||||||
|
|
||||||
[super close];
|
[super close];
|
||||||
}
|
}
|
||||||
|
@ -261,27 +262,27 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
if (length > INT_MAX)
|
if (length > INT_MAX)
|
||||||
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
||||||
|
|
||||||
if (sock == INVALID_SOCKET)
|
if (_socket == INVALID_SOCKET)
|
||||||
@throw [OFNotConnectedException exceptionWithClass: [self class]
|
@throw [OFNotConnectedException exceptionWithClass: [self class]
|
||||||
socket: self];
|
socket: self];
|
||||||
|
|
||||||
if (atEndOfStream) {
|
if (_atEndOfStream) {
|
||||||
OFReadFailedException *e;
|
OFReadFailedException *e;
|
||||||
|
|
||||||
e = [OFReadFailedException exceptionWithClass: [self class]
|
e = [OFReadFailedException exceptionWithClass: [self class]
|
||||||
stream: self
|
stream: self
|
||||||
requestedLength: length];
|
requestedLength: length];
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
e->errNo = ENOTCONN;
|
e->_errNo = ENOTCONN;
|
||||||
#else
|
#else
|
||||||
e->errNo = WSAENOTCONN;
|
e->_errNo = WSAENOTCONN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@throw e;
|
@throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = SSL_read(ssl, buffer, (int)length)) < 0) {
|
if ((ret = SSL_read(_SSL, buffer, (int)length)) < 0) {
|
||||||
if (SSL_get_error(ssl, ret) == SSL_ERROR_WANT_READ)
|
if (SSL_get_error(_SSL, ret) == SSL_ERROR_WANT_READ)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@throw [OFReadFailedException exceptionWithClass: [self class]
|
@throw [OFReadFailedException exceptionWithClass: [self class]
|
||||||
|
@ -290,7 +291,7 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
atEndOfStream = YES;
|
_atEndOfStream = YES;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -301,11 +302,11 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
if (length > INT_MAX)
|
if (length > INT_MAX)
|
||||||
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
||||||
|
|
||||||
if (sock == INVALID_SOCKET)
|
if (_socket == INVALID_SOCKET)
|
||||||
@throw [OFNotConnectedException exceptionWithClass: [self class]
|
@throw [OFNotConnectedException exceptionWithClass: [self class]
|
||||||
socket: self];
|
socket: self];
|
||||||
|
|
||||||
if (atEndOfStream) {
|
if (_atEndOfStream) {
|
||||||
OFWriteFailedException *e;
|
OFWriteFailedException *e;
|
||||||
|
|
||||||
e = [OFWriteFailedException exceptionWithClass: [self class]
|
e = [OFWriteFailedException exceptionWithClass: [self class]
|
||||||
|
@ -313,15 +314,15 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
requestedLength: length];
|
requestedLength: length];
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
e->errNo = ENOTCONN;
|
e->_errNo = ENOTCONN;
|
||||||
#else
|
#else
|
||||||
e->errNo = WSAENOTCONN;
|
e->_errNo = WSAENOTCONN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@throw e;
|
@throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_write(ssl, buffer, (int)length) < length)
|
if (SSL_write(_SSL, buffer, (int)length) < length)
|
||||||
@throw [OFWriteFailedException exceptionWithClass: [self class]
|
@throw [OFWriteFailedException exceptionWithClass: [self class]
|
||||||
stream: self
|
stream: self
|
||||||
requestedLength: length];
|
requestedLength: length];
|
||||||
|
@ -329,40 +330,40 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
|
|
||||||
- (size_t)pendingBytes
|
- (size_t)pendingBytes
|
||||||
{
|
{
|
||||||
if (ssl == NULL)
|
if (_SSL == NULL)
|
||||||
return [super pendingBytes];
|
return [super pendingBytes];
|
||||||
|
|
||||||
return [super pendingBytes] + SSL_pending(ssl);
|
return [super pendingBytes] + SSL_pending(_SSL);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPrivateKeyFile: (OFString*)file
|
- (void)setPrivateKeyFile: (OFString*)privateKeyFile
|
||||||
{
|
{
|
||||||
OF_SETTER(privateKeyFile, file, YES, YES)
|
OF_SETTER(_privateKeyFile, privateKeyFile, YES, YES)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)privateKeyFile
|
- (OFString*)privateKeyFile
|
||||||
{
|
{
|
||||||
OF_GETTER(privateKeyFile, YES)
|
OF_GETTER(_privateKeyFile, YES)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCertificateFile: (OFString*)file
|
- (void)setCertificateFile: (OFString*)certificateFile
|
||||||
{
|
{
|
||||||
OF_SETTER(certificateFile, file, YES, YES)
|
OF_SETTER(_certificateFile, certificateFile, YES, YES)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)certificateFile
|
- (OFString*)certificateFile
|
||||||
{
|
{
|
||||||
OF_GETTER(certificateFile, YES)
|
OF_GETTER(_certificateFile, YES)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRequestsClientCertificates: (BOOL)enabled
|
- (void)setRequestsClientCertificates: (BOOL)enabled
|
||||||
{
|
{
|
||||||
requestsClientCertificates = enabled;
|
_requestsClientCertificates = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)requestsClientCertificates
|
- (BOOL)requestsClientCertificates
|
||||||
{
|
{
|
||||||
return requestsClientCertificates;
|
return _requestsClientCertificates;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDataArray*)channelBindingDataWithType: (OFString*)type
|
- (OFDataArray*)channelBindingDataWithType: (OFString*)type
|
||||||
|
@ -376,15 +377,15 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
exceptionWithClass: [self class]
|
exceptionWithClass: [self class]
|
||||||
selector: _cmd];
|
selector: _cmd];
|
||||||
|
|
||||||
if (SSL_session_reused(ssl) ^ !listening) {
|
if (SSL_session_reused(_SSL) ^ !_listening) {
|
||||||
/*
|
/*
|
||||||
* We are either client or the session has been resumed
|
* We are either client or the session has been resumed
|
||||||
* => we have sent the finished message
|
* => we have sent the finished message
|
||||||
*/
|
*/
|
||||||
length = SSL_get_finished(ssl, buffer, 64);
|
length = SSL_get_finished(_SSL, buffer, 64);
|
||||||
} else {
|
} else {
|
||||||
/* peer sent the finished message */
|
/* peer sent the finished message */
|
||||||
length = SSL_get_peer_finished(ssl, buffer, 64);
|
length = SSL_get_peer_finished(_SSL, buffer, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = [OFDataArray dataArray];
|
data = [OFDataArray dataArray];
|
||||||
|
@ -396,7 +397,7 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
|
|
||||||
- (X509Certificate*)peerCertificate
|
- (X509Certificate*)peerCertificate
|
||||||
{
|
{
|
||||||
X509 *certificate = SSL_get_peer_certificate(ssl);
|
X509 *certificate = SSL_get_peer_certificate(_SSL);
|
||||||
|
|
||||||
if (!certificate)
|
if (!certificate)
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -409,8 +410,8 @@ locking_callback(int mode, int n, const char *file, int line)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
unsigned long ret;
|
||||||
|
|
||||||
if (SSL_get_peer_certificate(ssl) != NULL) {
|
if (SSL_get_peer_certificate(_SSL) != NULL) {
|
||||||
if ((ret = SSL_get_verify_result(ssl)) != X509_V_OK) {
|
if ((ret = SSL_get_verify_result(_SSL)) != X509_V_OK) {
|
||||||
const char *tmp = X509_verify_cert_error_string(ret);
|
const char *tmp = X509_verify_cert_error_string(ret);
|
||||||
OFString *reason = [OFString stringWithUTF8String: tmp];
|
OFString *reason = [OFString stringWithUTF8String: tmp];
|
||||||
@throw [SSLInvalidCertificateException
|
@throw [SSLInvalidCertificateException
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
||||||
|
* Copyright (c) 2013, Jonathan Schleifer <js@webkeks.org>
|
||||||
*
|
*
|
||||||
* https://webkeks.org/git/?p=objopenssl.git
|
* https://webkeks.org/git/?p=objopenssl.git
|
||||||
*
|
*
|
||||||
|
@ -42,18 +43,18 @@
|
||||||
|
|
||||||
@interface X509OID: OFObject <OFCopying>
|
@interface X509OID: OFObject <OFCopying>
|
||||||
{
|
{
|
||||||
OFString *string;
|
OFString *_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithUTF8String: (const char*)str;
|
- initWithUTF8String: (const char*)string;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface X509Certificate: OFObject
|
@interface X509Certificate: OFObject
|
||||||
{
|
{
|
||||||
X509 *crt;
|
X509 *_certificate;
|
||||||
OFDictionary *issuer;
|
OFDictionary *_issuer;
|
||||||
OFDictionary *subject;
|
OFDictionary *_subject;
|
||||||
OFDictionary *subjectAlternativeName;
|
OFDictionary *_subjectAlternativeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
#ifdef OF_HAVE_PROPERTIES
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
|
||||||
* Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org>
|
* Copyright (c) 2011, 2013, Jonathan Schleifer <js@webkeks.org>
|
||||||
*
|
*
|
||||||
* https://webkeks.org/git/?p=objopenssl.git
|
* https://webkeks.org/git/?p=objopenssl.git
|
||||||
*
|
*
|
||||||
|
@ -40,22 +40,22 @@
|
||||||
#import <ObjFW/macros.h>
|
#import <ObjFW/macros.h>
|
||||||
|
|
||||||
@implementation X509Certificate
|
@implementation X509Certificate
|
||||||
- initWithFile: (OFString*)file
|
- initWithFile: (OFString*)path
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||||
OFFile *fd = [OFFile fileWithPath: file
|
OFDataArray *data = [OFDataArray
|
||||||
mode: @"r"];
|
dataArrayWithContentsOfFile: path];
|
||||||
OFDataArray *data = [fd readDataArrayTillEndOfStream];
|
|
||||||
[fd close];
|
|
||||||
const unsigned char *dataCArray = [data items];
|
const unsigned char *dataCArray = [data items];
|
||||||
crt = d2i_X509(NULL, &dataCArray, [data count]);
|
|
||||||
[pool release];
|
_certificate = d2i_X509(NULL, &dataCArray, [data count]);
|
||||||
if (crt == NULL)
|
if (_certificate == NULL)
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: [self class]];
|
exceptionWithClass: [self class]];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -64,13 +64,13 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithX509Struct: (X509*)cert
|
- initWithX509Struct: (X509*)certificate
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
crt = X509_dup(cert);
|
_certificate = X509_dup(certificate);
|
||||||
if (crt == NULL)
|
if (_certificate == NULL)
|
||||||
@throw [OFInitializationFailedException
|
@throw [OFInitializationFailedException
|
||||||
exceptionWithClass: [self class]];
|
exceptionWithClass: [self class]];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
|
@ -83,12 +83,12 @@
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[issuer release];
|
[_issuer release];
|
||||||
[subject release];
|
[_subject release];
|
||||||
[subjectAlternativeName release];
|
[_subjectAlternativeName release];
|
||||||
|
|
||||||
if (crt != NULL)
|
if (_certificate != NULL)
|
||||||
X509_free(crt);
|
X509_free(_certificate);
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -109,26 +109,26 @@
|
||||||
{
|
{
|
||||||
X509_NAME *name;
|
X509_NAME *name;
|
||||||
|
|
||||||
if (issuer != nil)
|
if (_issuer != nil)
|
||||||
return [[issuer copy] autorelease];
|
return [[_issuer copy] autorelease];
|
||||||
|
|
||||||
name = X509_get_issuer_name(crt);
|
name = X509_get_issuer_name(_certificate);
|
||||||
issuer = [[self X509_dictionaryFromX509Name: name] retain];
|
_issuer = [[self X509_dictionaryFromX509Name: name] retain];
|
||||||
|
|
||||||
return issuer;
|
return _issuer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDictionary*)subject
|
- (OFDictionary*)subject
|
||||||
{
|
{
|
||||||
X509_NAME *name;
|
X509_NAME *name;
|
||||||
|
|
||||||
if (subject != nil)
|
if (_subject != nil)
|
||||||
return [[subject copy] autorelease];
|
return [[_subject copy] autorelease];
|
||||||
|
|
||||||
name = X509_get_subject_name(crt);
|
name = X509_get_subject_name(_certificate);
|
||||||
subject = [[self X509_dictionaryFromX509Name: name] retain];
|
_subject = [[self X509_dictionaryFromX509Name: name] retain];
|
||||||
|
|
||||||
return subject;
|
return _subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDictionary*)subjectAlternativeName
|
- (OFDictionary*)subjectAlternativeName
|
||||||
|
@ -137,19 +137,20 @@
|
||||||
OFMutableDictionary *ret;
|
OFMutableDictionary *ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (subjectAlternativeName != nil)
|
if (_subjectAlternativeName != nil)
|
||||||
return [[subjectAlternativeName copy] autorelease];
|
return [[_subjectAlternativeName copy] autorelease];
|
||||||
|
|
||||||
ret = [OFMutableDictionary dictionary];
|
ret = [OFMutableDictionary dictionary];
|
||||||
pool = [[OFAutoreleasePool alloc] init];
|
pool = [[OFAutoreleasePool alloc] init];
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while ((i = X509_get_ext_by_NID(crt, NID_subject_alt_name, i)) != -1) {
|
while ((i = X509_get_ext_by_NID(_certificate,
|
||||||
|
NID_subject_alt_name, i)) != -1) {
|
||||||
X509_EXTENSION *extension;
|
X509_EXTENSION *extension;
|
||||||
STACK_OF(GENERAL_NAME) *values;
|
STACK_OF(GENERAL_NAME) *values;
|
||||||
int j, count;
|
int j, count;
|
||||||
|
|
||||||
if ((extension = X509_get_ext(crt, i)) == NULL)
|
if ((extension = X509_get_ext(_certificate, i)) == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((values = X509V3_EXT_d2i(extension)) == NULL)
|
if ((values = X509V3_EXT_d2i(extension)) == NULL)
|
||||||
|
@ -248,7 +249,7 @@
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
[ret makeImmutable];
|
[ret makeImmutable];
|
||||||
subjectAlternativeName = [ret retain];
|
_subjectAlternativeName = [ret retain];
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -434,12 +435,12 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation X509OID
|
@implementation X509OID
|
||||||
- initWithUTF8String: (const char*) str
|
- initWithUTF8String: (const char*)string
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
string = [[OFString alloc] initWithUTF8String: str];
|
_string = [[OFString alloc] initWithUTF8String: string];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -450,14 +451,14 @@
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[string release];
|
[_string release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)description
|
- (OFString*)description
|
||||||
{
|
{
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
OBJ_obj2txt(tmp, sizeof(tmp), OBJ_txt2obj([string UTF8String], 1), 0);
|
OBJ_obj2txt(tmp, sizeof(tmp), OBJ_txt2obj([_string UTF8String], 1), 0);
|
||||||
return [OFString stringWithUTF8String: tmp];
|
return [OFString stringWithUTF8String: tmp];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,14 +466,14 @@
|
||||||
{
|
{
|
||||||
if (([object isKindOfClass: [OFString class]]) ||
|
if (([object isKindOfClass: [OFString class]]) ||
|
||||||
([object isKindOfClass: [X509OID class]]))
|
([object isKindOfClass: [X509OID class]]))
|
||||||
return [object isEqual: string];
|
return [object isEqual: _string];
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (uint32_t)hash
|
- (uint32_t)hash
|
||||||
{
|
{
|
||||||
return [string hash];
|
return [_string hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
- copy
|
- copy
|
||||||
|
|
Reference in a new issue