mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
tweaks
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35607 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8bbbd4a946
commit
9661855ac5
4 changed files with 58 additions and 38 deletions
|
@ -536,8 +536,7 @@ GSTLSPush(gnutls_transport_ptr_t handle, const void *buffer, size_t len)
|
||||||
direction: (server ? NO : YES)
|
direction: (server ? NO : YES)
|
||||||
transport: (void*)self
|
transport: (void*)self
|
||||||
push: GSTLSPush
|
push: GSTLSPush
|
||||||
pull: GSTLSPull
|
pull: GSTLSPull];
|
||||||
host: nil];
|
|
||||||
initialised = YES;
|
initialised = YES;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,14 @@
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
#undef id
|
#undef id
|
||||||
|
|
||||||
|
extern NSString * const GSTLSCAFile;
|
||||||
|
extern NSString * const GSTLSCertificateFile;
|
||||||
|
extern NSString * const GSTLSCertificateKeyFile;
|
||||||
|
extern NSString * const GSTLSCertificateKeyPassword;
|
||||||
|
extern NSString * const GSTLSDebug;
|
||||||
|
extern NSString * const GSTLSCAVerify;
|
||||||
|
extern NSString * const GSTLSRemoteHosts;
|
||||||
|
|
||||||
/* This class is used to ensure that the GNUTLS system is initialised
|
/* This class is used to ensure that the GNUTLS system is initialised
|
||||||
* and thread-safe.
|
* and thread-safe.
|
||||||
*/
|
*/
|
||||||
|
@ -112,13 +120,11 @@ typedef ssize_t (*GSTLSIOW)(gnutls_transport_ptr_t, const void *, size_t);
|
||||||
/* This class encapsulates a session to a remote system.
|
/* This class encapsulates a session to a remote system.
|
||||||
* Sessions are created with a direction and an options dictionary,
|
* Sessions are created with a direction and an options dictionary,
|
||||||
* defining how they will operate. The handle, pushFunc and pullFunc
|
* defining how they will operate. The handle, pushFunc and pullFunc
|
||||||
* provide the I/O mechanism, and the host specifies the host that the
|
* provide the I/O mechanism.
|
||||||
* session is connected to.
|
|
||||||
*/
|
*/
|
||||||
@interface GSTLSSession : GSTLSObject
|
@interface GSTLSSession : GSTLSObject
|
||||||
{
|
{
|
||||||
NSDictionary *opts;
|
NSDictionary *opts;
|
||||||
NSHost *host;
|
|
||||||
GSTLSPrivateKey *key;
|
GSTLSPrivateKey *key;
|
||||||
GSTLSCertificateList *list;
|
GSTLSCertificateList *list;
|
||||||
GSTLSDHParams *dhParams;
|
GSTLSDHParams *dhParams;
|
||||||
|
@ -134,15 +140,13 @@ typedef ssize_t (*GSTLSIOW)(gnutls_transport_ptr_t, const void *, size_t);
|
||||||
direction: (BOOL)isOutgoing
|
direction: (BOOL)isOutgoing
|
||||||
transport: (void*)handle
|
transport: (void*)handle
|
||||||
push: (GSTLSIOW)pushFunc
|
push: (GSTLSIOW)pushFunc
|
||||||
pull: (GSTLSIOR)pullFunc
|
pull: (GSTLSIOR)pullFunc;
|
||||||
host: (NSHost*)remote;
|
|
||||||
|
|
||||||
- (id) initWithOptions: (NSDictionary*)options
|
- (id) initWithOptions: (NSDictionary*)options
|
||||||
direction: (BOOL)isOutgoing
|
direction: (BOOL)isOutgoing
|
||||||
transport: (void*)handle
|
transport: (void*)handle
|
||||||
push: (GSTLSIOW)pushFunc
|
push: (GSTLSIOW)pushFunc
|
||||||
pull: (GSTLSIOR)pullFunc
|
pull: (GSTLSIOR)pullFunc;
|
||||||
host: (NSHost*)remote;
|
|
||||||
|
|
||||||
/* Return YES if the session is active (handshake has succeeded and the
|
/* Return YES if the session is active (handshake has succeeded and the
|
||||||
* session has not been disconnected), NO otherwise.
|
* session has not been disconnected), NO otherwise.
|
||||||
|
|
|
@ -709,7 +709,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
transport: (void*)handle
|
transport: (void*)handle
|
||||||
push: (GSTLSIOW)pushFunc
|
push: (GSTLSIOW)pushFunc
|
||||||
pull: (GSTLSIOR)pullFunc
|
pull: (GSTLSIOR)pullFunc
|
||||||
host: (NSHost*)host
|
|
||||||
{
|
{
|
||||||
GSTLSSession *sess;
|
GSTLSSession *sess;
|
||||||
|
|
||||||
|
@ -717,8 +716,7 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
direction: isOutgoing
|
direction: isOutgoing
|
||||||
transport: handle
|
transport: handle
|
||||||
push: pushFunc
|
push: pushFunc
|
||||||
pull: pullFunc
|
pull: pullFunc];
|
||||||
host: host];
|
|
||||||
return [sess autorelease];
|
return [sess autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,7 +729,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
{
|
{
|
||||||
[self finalize];
|
[self finalize];
|
||||||
DESTROY(opts);
|
DESTROY(opts);
|
||||||
DESTROY(host);
|
|
||||||
DESTROY(list);
|
DESTROY(list);
|
||||||
DESTROY(key);
|
DESTROY(key);
|
||||||
DESTROY(dhParams);
|
DESTROY(dhParams);
|
||||||
|
@ -766,7 +763,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
transport: (void*)handle
|
transport: (void*)handle
|
||||||
push: (GSTLSIOW)pushFunc
|
push: (GSTLSIOW)pushFunc
|
||||||
pull: (GSTLSIOR)pullFunc
|
pull: (GSTLSIOR)pullFunc
|
||||||
host: (NSHost*)remote
|
|
||||||
{
|
{
|
||||||
if (nil != (self = [super init]))
|
if (nil != (self = [super init]))
|
||||||
{
|
{
|
||||||
|
@ -779,7 +775,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
BOOL debug = (globalDebug > 0) ? YES : NO;
|
BOOL debug = (globalDebug > 0) ? YES : NO;
|
||||||
|
|
||||||
opts = [options copy];
|
opts = [options copy];
|
||||||
host = [remote copy];
|
|
||||||
outgoing = isOutgoing ? YES : NO;
|
outgoing = isOutgoing ? YES : NO;
|
||||||
|
|
||||||
if (NO == debug)
|
if (NO == debug)
|
||||||
|
@ -1157,19 +1152,20 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
if (cert_list_size > 0
|
if (cert_list_size > 0
|
||||||
&& gnutls_certificate_type_get(session) == GNUTLS_CRT_X509)
|
&& gnutls_certificate_type_get(session) == GNUTLS_CRT_X509)
|
||||||
{
|
{
|
||||||
char dn[128];
|
|
||||||
char serial[40];
|
|
||||||
size_t dn_size = sizeof(dn);
|
|
||||||
size_t serial_size = sizeof(serial);
|
|
||||||
time_t expiret;
|
|
||||||
time_t activet;
|
|
||||||
int algo;
|
|
||||||
unsigned int bits;
|
|
||||||
int i;
|
|
||||||
int cert_num;
|
int cert_num;
|
||||||
|
|
||||||
for (cert_num = 0; cert_num < cert_list_size; cert_num++)
|
for (cert_num = 0; cert_num < cert_list_size; cert_num++)
|
||||||
{
|
{
|
||||||
|
char dn[1024];
|
||||||
|
size_t dn_size = sizeof(dn);
|
||||||
|
char serial[40];
|
||||||
|
size_t serial_size = sizeof(serial);
|
||||||
|
time_t expiret;
|
||||||
|
time_t activet;
|
||||||
|
int algo;
|
||||||
|
unsigned int bits;
|
||||||
|
int i;
|
||||||
|
|
||||||
gnutls_x509_crt_init(&cert);
|
gnutls_x509_crt_init(&cert);
|
||||||
/* NB. the list of peer certificate is in memory in native
|
/* NB. the list of peer certificate is in memory in native
|
||||||
* format (DER) rather than the normal file format (PEM).
|
* format (DER) rather than the normal file format (PEM).
|
||||||
|
@ -1177,6 +1173,7 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
gnutls_x509_crt_import(cert,
|
gnutls_x509_crt_import(cert,
|
||||||
&cert_list[cert_num], GNUTLS_X509_FMT_DER);
|
&cert_list[cert_num], GNUTLS_X509_FMT_DER);
|
||||||
|
|
||||||
|
[str appendString: @"\n"];
|
||||||
[str appendFormat: _(@"- Certificate %d info:\n"), cert_num];
|
[str appendFormat: _(@"- Certificate %d info:\n"), cert_num];
|
||||||
|
|
||||||
expiret = gnutls_x509_crt_get_expiration_time(cert);
|
expiret = gnutls_x509_crt_get_expiration_time(cert);
|
||||||
|
@ -1233,11 +1230,17 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
[str appendFormat: _(@"- Certificate version: #%d\n"),
|
[str appendFormat: _(@"- Certificate version: #%d\n"),
|
||||||
gnutls_x509_crt_get_version(cert)];
|
gnutls_x509_crt_get_version(cert)];
|
||||||
|
|
||||||
|
dn_size = sizeof(dn);
|
||||||
gnutls_x509_crt_get_dn(cert, dn, &dn_size);
|
gnutls_x509_crt_get_dn(cert, dn, &dn_size);
|
||||||
[str appendFormat: @"- Certificate DN: %s\n", dn];
|
dn[dn_size - 1] = '\0';
|
||||||
|
[str appendFormat: @"- Certificate DN: %@\n",
|
||||||
|
[NSString stringWithUTF8String: dn]];
|
||||||
|
|
||||||
|
dn_size = sizeof(dn);
|
||||||
gnutls_x509_crt_get_issuer_dn(cert, dn, &dn_size);
|
gnutls_x509_crt_get_issuer_dn(cert, dn, &dn_size);
|
||||||
[str appendFormat: _(@"- Certificate Issuer's DN: %s\n"), dn];
|
dn[dn_size - 1] = '\0';
|
||||||
|
[str appendFormat: _(@"- Certificate Issuer's DN: %@\n"),
|
||||||
|
[NSString stringWithUTF8String: dn]];
|
||||||
|
|
||||||
gnutls_x509_crt_deinit(cert);
|
gnutls_x509_crt_deinit(cert);
|
||||||
}
|
}
|
||||||
|
@ -1371,15 +1374,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
str = [opts objectForKey: GSTLSRemoteHosts];
|
str = [opts objectForKey: GSTLSRemoteHosts];
|
||||||
if (nil == str)
|
if (nil == str)
|
||||||
{
|
{
|
||||||
/* No names specified ... use all known names for the host we are
|
|
||||||
* connecting to.
|
|
||||||
*/
|
|
||||||
names = [host names];
|
|
||||||
}
|
|
||||||
else if ([str length] == 0)
|
|
||||||
{
|
|
||||||
/* Empty name ... disable host name checking.
|
|
||||||
*/
|
|
||||||
names = nil;
|
names = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -28,10 +28,12 @@
|
||||||
#import "common.h"
|
#import "common.h"
|
||||||
#define EXPOSE_NSFileHandle_IVARS 1
|
#define EXPOSE_NSFileHandle_IVARS 1
|
||||||
#import "Foundation/NSData.h"
|
#import "Foundation/NSData.h"
|
||||||
#import "Foundation/NSFileHandle.h"
|
|
||||||
#import "Foundation/NSException.h"
|
#import "Foundation/NSException.h"
|
||||||
|
#import "Foundation/NSHost.h"
|
||||||
|
#import "Foundation/NSFileHandle.h"
|
||||||
#import "Foundation/NSPathUtilities.h"
|
#import "Foundation/NSPathUtilities.h"
|
||||||
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
||||||
|
#import "GNUstepBase/NSString+GNUstepBase.h"
|
||||||
#import "GSPrivate.h"
|
#import "GSPrivate.h"
|
||||||
#import "GSNetwork.h"
|
#import "GSNetwork.h"
|
||||||
|
|
||||||
|
@ -991,12 +993,33 @@ GSTLSHandlePush(gnutls_transport_ptr_t handle, const void *buffer, size_t len)
|
||||||
*/
|
*/
|
||||||
if (nil == session)
|
if (nil == session)
|
||||||
{
|
{
|
||||||
|
/* If No value is specified for GSTLSRemoteHosts, make a comma separated
|
||||||
|
* list of all known names for the remote host and use that.
|
||||||
|
*/
|
||||||
|
if (nil == [opts objectForKey: GSTLSRemoteHosts])
|
||||||
|
{
|
||||||
|
NSHost *host = [NSHost hostWithAddress: [self socketAddress]];
|
||||||
|
NSString *s = [[host names] description];
|
||||||
|
|
||||||
|
s = [s stringByReplacingString: @"\"" withString: @""];
|
||||||
|
if ([s length] > 1)
|
||||||
|
{
|
||||||
|
s = [s substringWithRange: NSMakeRange(1, [s length] - 2)];
|
||||||
|
}
|
||||||
|
if ([s length] > 0)
|
||||||
|
{
|
||||||
|
NSMutableDictionary *d = [opts mutableCopy];
|
||||||
|
|
||||||
|
[d setObject:s forKey: GSTLSRemoteHosts];
|
||||||
|
ASSIGNCOPY(opts, d);
|
||||||
|
[d release];
|
||||||
|
}
|
||||||
|
}
|
||||||
session = [[GSTLSSession alloc] initWithOptions: opts
|
session = [[GSTLSSession alloc] initWithOptions: opts
|
||||||
direction: isOutgoing
|
direction: isOutgoing
|
||||||
transport: (void*)self
|
transport: (void*)self
|
||||||
push: GSTLSHandlePush
|
push: GSTLSHandlePush
|
||||||
pull: GSTLSHandlePull
|
pull: GSTLSHandlePull];
|
||||||
host: nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NO == [session handshake])
|
if (NO == [session handshake])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue