mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Updates to make SSL bundle build standalone.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13026 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1c66398a64
commit
a6777a8ab7
17 changed files with 2599 additions and 683 deletions
92
SSL/GNUmakefile
Normal file
92
SSL/GNUmakefile
Normal file
|
@ -0,0 +1,92 @@
|
|||
#
|
||||
# src makefile for the GNUstep Base Library
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
#
|
||||
|
||||
# Install into the system root by default
|
||||
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
|
||||
|
||||
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
||||
|
||||
-include config.mak
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
srcdir = .
|
||||
PACKAGE_NAME = gnustep-base
|
||||
|
||||
ifeq ($(HAVE_OPENSSL), yes)
|
||||
|
||||
# The bundles to be compiled
|
||||
BUNDLE_NAME=SSL
|
||||
|
||||
# Additional search directories for linking
|
||||
SSL_LIB_DIRS += -L$(GNUSTEP_OBJ_DIR)
|
||||
|
||||
# The bundle Objective-C source files to be compiled
|
||||
SSL_OBJC_FILES = GSUnixSSLHandle.m
|
||||
|
||||
# The principal class in the bundle
|
||||
SSL_PRINCIPAL_CLASS = GSUnixSSLHandle
|
||||
|
||||
SSL_BUNDLE_LIBS = -lgnustep-base -lobjc $(SSLLIBS)
|
||||
|
||||
endif
|
||||
|
||||
# GNUSTEP_INSTALL_PREFIX must be defined here and not in config.h because
|
||||
# the installing person may set it on the `make' command line.
|
||||
|
||||
ifeq ($(GNUSTEP_TARGET_OS), mingw32)
|
||||
|
||||
GNUSTEP_TARGET_INSTALL_PREFIX := \
|
||||
$(shell echo $(GNUSTEP_SYSTEM_ROOT) | sed 's|^[a-zA-Z]:/|/|')
|
||||
GNUSTEP_TARGET_LOCAL_ROOT := \
|
||||
$(shell echo $(GNUSTEP_LOCAL_ROOT) | sed 's|^[a-zA-Z]:/|/|')
|
||||
GNUSTEP_TARGET_NETWORK_ROOT := \
|
||||
$(shell echo $(GNUSTEP_NETWORK_ROOT) | sed 's|^[a-zA-Z]:/|/|')
|
||||
DEFS= -DGNUSTEP_INSTALL_PREFIX=$(GNUSTEP_TARGET_INSTALL_PREFIX) \
|
||||
-DGNUSTEP_LOCAL_ROOT=$(GNUSTEP_TARGET_LOCAL_ROOT) \
|
||||
-DGNUSTEP_NETWORK_ROOT=$(GNUSTEP_TARGET_NETWORK_ROOT) \
|
||||
-DGNUSTEP_TARGET_DIR=\"$(GNUSTEP_TARGET_DIR)\" \
|
||||
-DGNUSTEP_TARGET_CPU=\"$(GNUSTEP_TARGET_CPU)\" \
|
||||
-DGNUSTEP_TARGET_OS=\"$(GNUSTEP_TARGET_OS)\" \
|
||||
-DLIBRARY_COMBO=\"$(LIBRARY_COMBO)\"
|
||||
|
||||
else
|
||||
|
||||
GNUSTEP_INSTALL_PREFIX=$(GNUSTEP_SYSTEM_ROOT)
|
||||
DEFS= -DGNUSTEP_INSTALL_PREFIX=$(GNUSTEP_INSTALL_PREFIX) \
|
||||
-DGNUSTEP_LOCAL_ROOT=$(GNUSTEP_LOCAL_ROOT) \
|
||||
-DGNUSTEP_NETWORK_ROOT=$(GNUSTEP_NETWORK_ROOT) \
|
||||
-DGNUSTEP_TARGET_DIR=\"$(GNUSTEP_TARGET_DIR)\" \
|
||||
-DGNUSTEP_TARGET_CPU=\"$(GNUSTEP_TARGET_CPU)\" \
|
||||
-DGNUSTEP_TARGET_OS=\"$(GNUSTEP_TARGET_OS)\" \
|
||||
-DLIBRARY_COMBO=\"$(LIBRARY_COMBO)\"
|
||||
|
||||
endif
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/bundle.make
|
||||
|
||||
-include Makefile.postamble
|
631
SSL/GSUnixSSLHandle.m
Normal file
631
SSL/GSUnixSSLHandle.m
Normal file
|
@ -0,0 +1,631 @@
|
|||
/** Implementation for GSUnixSSLHandle for GNUStep
|
||||
Copyright (C) 1997-1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: 1997
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined(__WIN32__) || defined(_WIN32) || defined(__MS_WIN32__)
|
||||
#ifndef __WIN32__
|
||||
#define __WIN32__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#ifndef __MINGW__
|
||||
#define __MINGW__
|
||||
#endif
|
||||
#ifndef __WIN32__
|
||||
#define __WIN32__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#include <windows.h>
|
||||
#define GNUSTEP_BASE_SOCKET_MESSAGE (WM_USER + 1)
|
||||
#endif
|
||||
|
||||
/* Because openssl uses `id' as variable name sometime,
|
||||
while it is an Objective-C reserved keyword. */
|
||||
#define id id_x_
|
||||
#include <openssl/ssl.h>
|
||||
#undef id
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include <gnustep/base/UnixFileHandle.h>
|
||||
|
||||
#if defined(__MINGW__)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <signal.h>
|
||||
#endif /* __MINGW__ */
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef __svr4__
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
// Maximum data in single I/O operation
|
||||
#define NETBUF_SIZE 4096
|
||||
|
||||
// Key to info dictionary for operation mode.
|
||||
static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||
|
||||
|
||||
|
||||
@interface GSUnixSSLHandle : UnixFileHandle <GCFinalization>
|
||||
{
|
||||
SSL_CTX *ctx;
|
||||
SSL *ssl;
|
||||
BOOL connected;
|
||||
}
|
||||
- (BOOL) sslConnect;
|
||||
- (void) sslDisconnect;
|
||||
- (void) sslSetCertificate: (NSString*)certFile
|
||||
privateKey: (NSString*)privateKey
|
||||
PEMpasswd: (NSString*)PEMpasswd;
|
||||
@end
|
||||
|
||||
@implementation GSUnixSSLHandle
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GSUnixSSLHandle class])
|
||||
{
|
||||
SSL_library_init();
|
||||
}
|
||||
}
|
||||
|
||||
- (NSData*) availableData
|
||||
{
|
||||
char buf[NETBUF_SIZE];
|
||||
NSMutableData *d;
|
||||
int len;
|
||||
|
||||
[self checkRead];
|
||||
if (isNonBlocking == YES)
|
||||
[self setNonBlocking: NO];
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
if (isStandardFile)
|
||||
{
|
||||
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connected)
|
||||
{
|
||||
if ((len = SSL_read(ssl, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (len < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
- (void) closeFile
|
||||
{
|
||||
[self sslDisconnect];
|
||||
[super closeFile];
|
||||
}
|
||||
|
||||
- (void) gcFinalize
|
||||
{
|
||||
[self sslDisconnect];
|
||||
[super gcFinalize];
|
||||
}
|
||||
|
||||
- (NSData*) readDataOfLength: (unsigned)len
|
||||
{
|
||||
NSMutableData *d;
|
||||
int got;
|
||||
|
||||
[self checkRead];
|
||||
if (isNonBlocking == YES)
|
||||
[self setNonBlocking: NO];
|
||||
if (len <= 65536)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
buf = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
d = [NSMutableData dataWithBytesNoCopy: buf length: len];
|
||||
if ((got = SSL_read(ssl, [d mutableBytes], len)) < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
}
|
||||
[d setLength: got];
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[NETBUF_SIZE];
|
||||
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
do
|
||||
{
|
||||
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
||||
|
||||
if (connected)
|
||||
{
|
||||
got = SSL_read(ssl, buf, chunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
got = read(descriptor, buf, chunk);
|
||||
}
|
||||
if (got > 0)
|
||||
{
|
||||
[d appendBytes: buf length: got];
|
||||
len -= got;
|
||||
}
|
||||
else if (got < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
}
|
||||
}
|
||||
while (len > 0 && got > 0);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
- (NSData*) readDataToEndOfFile
|
||||
{
|
||||
char buf[NETBUF_SIZE];
|
||||
NSMutableData *d;
|
||||
int len;
|
||||
|
||||
[self checkRead];
|
||||
if (isNonBlocking == YES)
|
||||
[self setNonBlocking: NO];
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
if (connected)
|
||||
{
|
||||
while ((len = SSL_read(ssl, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
if (len < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
- (void) receivedEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
extra: (void*)extra
|
||||
forMode: (NSString*)mode
|
||||
{
|
||||
NSString *operation;
|
||||
|
||||
if (isNonBlocking == NO)
|
||||
[self setNonBlocking: YES];
|
||||
if (type == ET_RDESC)
|
||||
{
|
||||
operation = [readInfo objectForKey: NotificationKey];
|
||||
if (operation == NSFileHandleConnectionAcceptedNotification)
|
||||
{
|
||||
struct sockaddr_in buf;
|
||||
int desc;
|
||||
int blen = sizeof(buf);
|
||||
|
||||
desc = accept(descriptor, (struct sockaddr*)&buf, &blen);
|
||||
if (desc < 0)
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [NSString stringWithFormat: @"Accept attempt failed - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
[readInfo setObject: s forKey: GSFileHandleNotificationError];
|
||||
}
|
||||
else
|
||||
{ // Accept attempt completed.
|
||||
UnixFileHandle *h;
|
||||
struct sockaddr_in sin;
|
||||
int size = sizeof(sin);
|
||||
|
||||
h = [[GSUnixSSLHandle alloc] initWithFileDescriptor: desc
|
||||
closeOnDealloc: YES];
|
||||
getpeername(desc, (struct sockaddr*)&sin, &size);
|
||||
[h setAddr: &sin];
|
||||
[readInfo setObject: h
|
||||
forKey: NSFileHandleNotificationFileHandleItem];
|
||||
RELEASE(h);
|
||||
}
|
||||
[self postReadNotification];
|
||||
}
|
||||
else if (operation == NSFileHandleDataAvailableNotification)
|
||||
{
|
||||
[self postReadNotification];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSMutableData *item;
|
||||
int length;
|
||||
int received = 0;
|
||||
char buf[NETBUF_SIZE];
|
||||
|
||||
item = [readInfo objectForKey: NSFileHandleNotificationDataItem];
|
||||
length = [item length];
|
||||
|
||||
if (connected)
|
||||
{
|
||||
received = SSL_read(ssl, buf, sizeof(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
received = read(descriptor, buf, sizeof(buf));
|
||||
}
|
||||
if (received == 0)
|
||||
{ // Read up to end of file.
|
||||
[self postReadNotification];
|
||||
}
|
||||
else if (received < 0)
|
||||
{
|
||||
if (errno != EAGAIN && errno != EINTR)
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [NSString stringWithFormat: @"Read attempt failed - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
[readInfo setObject: s forKey: GSFileHandleNotificationError];
|
||||
[self postReadNotification];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[item appendBytes: buf length: received];
|
||||
if (operation == NSFileHandleReadCompletionNotification)
|
||||
{
|
||||
// Read a single chunk of data
|
||||
[self postReadNotification];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == ET_WDESC)
|
||||
{
|
||||
NSMutableDictionary *info;
|
||||
|
||||
info = [writeInfo objectAtIndex: 0];
|
||||
operation = [info objectForKey: NotificationKey];
|
||||
if (operation == GSFileHandleWriteCompletionNotification)
|
||||
{
|
||||
NSData *item;
|
||||
int length;
|
||||
const void *ptr;
|
||||
|
||||
item = [info objectForKey: NSFileHandleNotificationDataItem];
|
||||
length = [item length];
|
||||
ptr = [item bytes];
|
||||
if (writePos < length)
|
||||
{
|
||||
int written;
|
||||
|
||||
if (connected)
|
||||
{
|
||||
written = SSL_write(ssl, (char*)ptr + writePos,
|
||||
length - writePos);
|
||||
}
|
||||
else
|
||||
{
|
||||
written = write(descriptor, (char*)ptr + writePos,
|
||||
length - writePos);
|
||||
}
|
||||
if (written <= 0)
|
||||
{
|
||||
if (written < 0 && errno != EAGAIN && errno != EINTR)
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [NSString stringWithFormat:
|
||||
@"Write attempt failed - %s", GSLastErrorStr(errno)];
|
||||
[info setObject: s forKey: GSFileHandleNotificationError];
|
||||
[self postWriteNotification];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writePos += written;
|
||||
}
|
||||
}
|
||||
if (writePos >= length)
|
||||
{ // Write operation completed.
|
||||
[self postWriteNotification];
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Connection attempt completed.
|
||||
int result;
|
||||
int len = sizeof(result);
|
||||
|
||||
if (getsockopt(descriptor, SOL_SOCKET, SO_ERROR,
|
||||
(char*)&result, &len) == 0 && result != 0)
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [NSString stringWithFormat: @"Connect attempt failed - %s",
|
||||
GSLastErrorStr(result)];
|
||||
[info setObject: s forKey: GSFileHandleNotificationError];
|
||||
}
|
||||
else
|
||||
{
|
||||
readOK = YES;
|
||||
writeOK = YES;
|
||||
}
|
||||
connectOK = NO;
|
||||
[self postWriteNotification];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) sslConnect
|
||||
{
|
||||
int ret;
|
||||
int err;
|
||||
NSRunLoop *loop;
|
||||
|
||||
if (connected == YES)
|
||||
{
|
||||
return YES; /* Already connected. */
|
||||
}
|
||||
if (isStandardFile == YES)
|
||||
{
|
||||
NSLog(@"Attempt to make ssl connection to a standard file");
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure we have a context and handle to connect with.
|
||||
*/
|
||||
if (ctx == 0)
|
||||
{
|
||||
ctx = SSL_CTX_new(SSLv23_client_method());
|
||||
}
|
||||
if (ssl == 0)
|
||||
{
|
||||
ssl = SSL_new(ctx);
|
||||
}
|
||||
|
||||
ret = SSL_set_fd(ssl, descriptor);
|
||||
loop = [NSRunLoop currentRunLoop];
|
||||
[loop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
|
||||
ret = SSL_connect(ssl);
|
||||
if (ret != 1)
|
||||
{
|
||||
int e = errno;
|
||||
NSDate *final;
|
||||
NSDate *when;
|
||||
NSTimeInterval last = 0.0;
|
||||
NSTimeInterval limit = 0.1;
|
||||
|
||||
final = [[NSDate alloc] initWithTimeIntervalSinceNow: 20.0];
|
||||
when = [NSDate alloc];
|
||||
|
||||
err = SSL_get_error(ssl, ret);
|
||||
while ((err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
|
||||
&& [final timeIntervalSinceNow] > 0.0)
|
||||
{
|
||||
NSTimeInterval tmp = limit;
|
||||
|
||||
limit += last;
|
||||
last = tmp;
|
||||
when = [when initWithTimeIntervalSinceNow: limit];
|
||||
[loop runUntilDate: when];
|
||||
ret = SSL_connect(ssl);
|
||||
if (ret != 1)
|
||||
{
|
||||
e = errno;
|
||||
err = SSL_get_error(ssl, ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = SSL_ERROR_NONE;
|
||||
}
|
||||
}
|
||||
RELEASE(when);
|
||||
RELEASE(final);
|
||||
if (err != SSL_ERROR_NONE)
|
||||
{
|
||||
NSString *str;
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case SSL_ERROR_NONE:
|
||||
str = @"No error: really helpful";
|
||||
break;
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
str = @"Zero Return error";
|
||||
break;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
str = @"Want Read Error";
|
||||
break;
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
str = @"Want Write Error";
|
||||
break;
|
||||
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||
str = @"Want X509 Lookup Error";
|
||||
break;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
str = [NSString stringWithFormat: @"Syscall error %d - %s",
|
||||
e, GSLastErrorStr(e)];
|
||||
break;
|
||||
case SSL_ERROR_SSL:
|
||||
str = @"SSL Error: really helpful";
|
||||
break;
|
||||
default:
|
||||
str = @"Standard Unix Error: really helpful";
|
||||
break;
|
||||
}
|
||||
NSLog(@"unable to make SSL connection to %@:%@ - %@",
|
||||
address, service, str);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
connected = YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) sslDisconnect
|
||||
{
|
||||
if (ssl != 0)
|
||||
{
|
||||
if (connected == YES)
|
||||
{
|
||||
SSL_shutdown(ssl);
|
||||
}
|
||||
SSL_clear(ssl);
|
||||
SSL_free(ssl);
|
||||
ssl = 0;
|
||||
}
|
||||
if (ctx != 0)
|
||||
{
|
||||
SSL_CTX_free(ctx);
|
||||
ctx = 0;
|
||||
}
|
||||
connected = NO;
|
||||
}
|
||||
|
||||
- (void) sslSetCertificate: (NSString*)certFile
|
||||
privateKey: (NSString*)privateKey
|
||||
PEMpasswd: (NSString*)PEMpasswd
|
||||
{
|
||||
if (isStandardFile == YES)
|
||||
{
|
||||
NSLog(@"Attempt to set ssl certificate for a standard file");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Ensure we have a context to set the certificate for.
|
||||
*/
|
||||
if (ctx == 0)
|
||||
{
|
||||
ctx = SSL_CTX_new(SSLv23_client_method());
|
||||
}
|
||||
if ([PEMpasswd length] > 0)
|
||||
{
|
||||
SSL_CTX_set_default_passwd_cb_userdata(ctx, (char*)[PEMpasswd cString]);
|
||||
}
|
||||
if ([certFile length] > 0)
|
||||
{
|
||||
SSL_CTX_use_certificate_file(ctx, [certFile cString], X509_FILETYPE_PEM);
|
||||
}
|
||||
if ([privateKey length] > 0)
|
||||
{
|
||||
SSL_CTX_use_PrivateKey_file(ctx, [privateKey cString], X509_FILETYPE_PEM);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) writeData: (NSData*)item
|
||||
{
|
||||
int rval = 0;
|
||||
const void *ptr = [item bytes];
|
||||
unsigned int len = [item length];
|
||||
unsigned int pos = 0;
|
||||
|
||||
[self checkWrite];
|
||||
if (isNonBlocking == YES)
|
||||
{
|
||||
[self setNonBlocking: NO];
|
||||
}
|
||||
while (pos < len)
|
||||
{
|
||||
int toWrite = len - pos;
|
||||
|
||||
if (toWrite > NETBUF_SIZE)
|
||||
{
|
||||
toWrite = NETBUF_SIZE;
|
||||
}
|
||||
if (connected)
|
||||
{
|
||||
rval = SSL_write(ssl, (char*)ptr+pos, toWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = write(descriptor, (char*)ptr+pos, toWrite);
|
||||
}
|
||||
if (rval < 0)
|
||||
{
|
||||
if (errno == EAGAIN == errno == EINTR)
|
||||
{
|
||||
rval = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos += rval;
|
||||
}
|
||||
if (rval < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to write to descriptor - %s",
|
||||
GSLastErrorStr(errno)];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
87
SSL/Makefile.postamble
Normal file
87
SSL/Makefile.postamble
Normal file
|
@ -0,0 +1,87 @@
|
|||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Project specific makefile rules
|
||||
#
|
||||
# Uncomment the targets you want.
|
||||
# The double colons (::) are important, do not make them single colons
|
||||
# otherwise the normal makefile rules will not be performed.
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
# before-install::
|
||||
|
||||
# Things to do after installing
|
||||
#
|
||||
# Unfortunately the way the header files are placed in relationship
|
||||
# to the source we must install the GNU header manually
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
after-distclean::
|
||||
rm -rf SSL.bundle
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
||||
|
||||
config.mak: config.mak.in
|
||||
./configure
|
||||
|
||||
TAGS: $(DIST_FILES)
|
||||
etags $(DIST_FILES)
|
||||
|
||||
regenerate: $(DIST_FILES)
|
||||
mv AUTHORS ..
|
||||
|
||||
FORCE:
|
58
SSL/Makefile.preamble
Normal file
58
SSL/Makefile.preamble
Normal file
|
@ -0,0 +1,58 @@
|
|||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Project specific makefile variables
|
||||
#
|
||||
# Do not put any Makefile rules in this file, instead they should
|
||||
# be put into Makefile.postamble.
|
||||
#
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS = $(DEFS) $(CONFIG_SYSTEM_DEFS) -Wall
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS = $(SSLFLAGS)
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../Headers/gnustep -I../Headers
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS = -L../Source/$(GNUSTEP_OBJ_DIR)
|
||||
|
55
SSL/config.h.in
Normal file
55
SSL/config.h.in
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* config.h.in. Generated automatically from configure.in by autoheader 2.13. */
|
||||
|
||||
/* Define if you have the <libc.h> header file. */
|
||||
#undef HAVE_LIBC_H
|
||||
|
||||
/* Define if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define if you have the <openssl/ssl.h> header file. */
|
||||
#undef HAVE_OPENSSL_SSL_H
|
||||
|
||||
/* Define if you have the <signal.h> header file. */
|
||||
#undef HAVE_SIGNAL_H
|
||||
|
||||
/* Define if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define if you have the <sys/fcntl.h> header file. */
|
||||
#undef HAVE_SYS_FCNTL_H
|
||||
|
||||
/* Define if you have the <sys/file.h> header file. */
|
||||
#undef HAVE_SYS_FILE_H
|
||||
|
||||
/* Define if you have the <sys/inttypes.h> header file. */
|
||||
#undef HAVE_SYS_INTTYPES_H
|
||||
|
||||
/* Define if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define if you have the <sys/signal.h> header file. */
|
||||
#undef HAVE_SYS_SIGNAL_H
|
||||
|
||||
/* Define if you have the <sys/stropts.h> header file. */
|
||||
#undef HAVE_SYS_STROPTS_H
|
||||
|
||||
/* Define if you have the <sys/wait.h> header file. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
8
SSL/config.mak.in
Normal file
8
SSL/config.mak.in
Normal file
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# Extra make variables for SSL bundle
|
||||
#
|
||||
|
||||
HAVE_OPENSSL=@HAVE_OPENSSL@
|
||||
SSLLIBS=@SSLLIBS@
|
||||
SSLFLAGS=@SSLFLAGS@
|
||||
|
1802
SSL/configure
vendored
Executable file
1802
SSL/configure
vendored
Executable file
File diff suppressed because it is too large
Load diff
165
SSL/configure.in
Normal file
165
SSL/configure.in
Normal file
|
@ -0,0 +1,165 @@
|
|||
AC_INIT(GSUnixSSLHandle.m)
|
||||
|
||||
# configure.in for GNUstep base SSL bundle
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
#
|
||||
# Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||
#
|
||||
# This file is part of the GNU Objective-C library.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
|
||||
|
||||
if test -z "$GNUSTEP_SYSTEM_ROOT"; then
|
||||
{
|
||||
echo "ERROR: You must run the GNUstep initialization script before configuring the SSL bundle!" 1>&2;
|
||||
exit 1;
|
||||
}
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Use a .h file with #define's, instead of -D command-line switches
|
||||
#--------------------------------------------------------------------
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Use config.guess, config.sub and install-sh provided by gnustep-make
|
||||
#--------------------------------------------------------------------
|
||||
AC_CONFIG_AUX_DIR($GNUSTEP_SYSTEM_ROOT/Makefiles)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Determine the host, build, and target systems
|
||||
#--------------------------------------------------------------------
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find the compiler
|
||||
#--------------------------------------------------------------------
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
|
||||
AC_PATH_PROG(WHOAMI, whoami, echo, $PATH:/usr/ucb)
|
||||
|
||||
AC_EXEEXT
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# specific target_os options
|
||||
#--------------------------------------------------------------------
|
||||
case "$target_os" in
|
||||
freebsd*) CPPFLAGS="$CPPFLAGS -I/usr/local/include"
|
||||
LIBS="$LIBS -L/usr/local/lib";;
|
||||
|
||||
esac
|
||||
|
||||
AC_CHECK_HEADERS(libc.h limits.h malloc.h memory.h string.h signal.h sys/signal.h sys/param.h sys/wait.h sys/file.h sys/fcntl.h sys/ioctl.h sys/stropts.h unistd.h utime.h stdint.h sys/inttypes.h)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check OpenSSL for HTTPS support.
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_ENABLE(openssl,
|
||||
[ --disable-openssl Disable support for openssl in URL classes],,
|
||||
enable_openssl=yes)
|
||||
AC_ARG_WITH(openssl-include,
|
||||
[ --with-openssl-include=PATH include path for openssl headers],
|
||||
openssl_incdir="$withval", openssl_incdir="no")
|
||||
AC_ARG_WITH(openssl-library,
|
||||
[ --with-openssl-library=PATH library path for openssl libraries],
|
||||
openssl_libdir="$withval", openssl_libdir="no")
|
||||
|
||||
cppflags_temp="$CPPFLAGS"
|
||||
libs_temp=$LIBS
|
||||
|
||||
if test "$openssl_incdir" != "no"; then
|
||||
CPPFLAGS="$CPPFLAGS -I$openssl_incdir"
|
||||
SSLFLAGS="-I$openssl_incdir"
|
||||
else
|
||||
SSLFLAGS=
|
||||
fi
|
||||
|
||||
if test "$openssl_libdir" != "no"; then
|
||||
LIBS="$LIBS -L$openssl_libdir"
|
||||
SSLLIBS="-L$openssl_libdir"
|
||||
else
|
||||
SSLLIBS=
|
||||
fi
|
||||
|
||||
if test $enable_openssl = yes; then
|
||||
AC_CHECK_HEADERS(openssl/ssl.h)
|
||||
if test $ac_cv_header_openssl_ssl_h = no; then
|
||||
echo "Could not find openssl headers"
|
||||
echo "Check to make sure you have a recent version of openssl installed"
|
||||
echo "The SSL bundle will not be built"
|
||||
AC_MSG_WARN(Could not find openssl headers)
|
||||
AC_MSG_WARN(The SSL bundle will not be built)
|
||||
ssl_ok=no
|
||||
else
|
||||
AC_CHECK_LIB(crypto, CRYPTO_malloc, ssl_ok=yes, ssl_ok=no)
|
||||
if test "$ssl_ok" = yes; then
|
||||
base_libs="$LIBS"
|
||||
LIBS="$LIBS -lcrypto"
|
||||
AC_CHECK_LIB(ssl, ssl2_clear, ssl_ok=yes, ssl_ok=no)
|
||||
if test "$ssl_ok" = yes; then
|
||||
echo "found openssl"
|
||||
LIBS="$base_libs -lssl -lcrypto"
|
||||
SSLLIBS="$SSLLIBS -lssl -lcrypto"
|
||||
else
|
||||
SSLLIBS="$SSLLIBS -lcrypto"
|
||||
echo "Could not find openssl crypto library"
|
||||
echo "Check to make sure you have a recent version of openssl installed"
|
||||
echo "The SSL bundle will not be built"
|
||||
AC_MSG_WARN(Could not find openssl libraries)
|
||||
AC_MSG_WARN(The SSL bundle will not be built)
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(cipher,des_setkey,cipher_ok=yes,cipher_ok=no)
|
||||
if test "$cipher_ok" = yes; then
|
||||
echo "found cipher"
|
||||
LIBS="$LIBS -lcipher"
|
||||
SSLLIBS="$SSLLIBS -lcipher"
|
||||
fi
|
||||
else
|
||||
echo "Could not find openssl library"
|
||||
echo "Check to make sure you have a recent version of openssl installed"
|
||||
echo "The SSL bundle will not be built"
|
||||
AC_MSG_WARN(Could not find openssl libraries)
|
||||
AC_MSG_WARN(The SSL bundle will not be built)
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "The use of openssl was disabled"
|
||||
echo "The SSL bundle will not be built"
|
||||
AC_MSG_WARN(The use of openssl was disabled)
|
||||
AC_MSG_WARN(The SSL bundle will not be built)
|
||||
fi
|
||||
HAVE_OPENSSL=$ssl_ok
|
||||
AC_SUBST(HAVE_OPENSSL)
|
||||
AC_SUBST(SSLFLAGS)
|
||||
AC_SUBST(SSLLIBS)
|
||||
|
||||
CPPFLAGS="$cppflags_temp";
|
||||
LIBS="$libs_temp";
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Write the Makefiles
|
||||
#--------------------------------------------------------------------
|
||||
AC_OUTPUT(config.mak)
|
||||
|
||||
dnl Local Variables:
|
||||
dnl comment-start: "dnl "
|
||||
dnl comment-end: ""
|
||||
dnl comment-start-skip: "\\bdnl\\b\\s *"
|
||||
dnl compile-command: "autoconf"
|
||||
dnl End:
|
Loading…
Add table
Add a link
Reference in a new issue