Expose GNU TLS wrappers and add methods to get certificate expiry

This commit is contained in:
Richard Frith-Macdonald 2019-01-16 09:56:08 +00:00
parent a31506564e
commit 6f3bd6ac97
11 changed files with 111 additions and 12 deletions

View file

@ -1,3 +1,17 @@
2019-01-06 Armando Pesenti Gritti <armando.pesentigritti@theengagehub.com>
* Headers/GNUstepBase/GSTLS.h: Header moved to provide public
exposure of TLS classes giving ObjC interface to GNU TLS.
* Source/GSTLS.m: New methods to provide certificate expiry times.
* Source/DocMakefile: Make documentation from GSTLS.h
* Source/GNUmakefile: Install GSTLS.h
* Source/GSHTTPURLHandle.m: Adjust location of GSTLS header
* Source/GSSocketStream.m: Adjust location of GSTLS header
* Source/NSFileHandle.m: Adjust location of GSTLS header
* Source/NSURLProtocol.m: Adjust location of GSTLS header
* Tests/base/GSTLS: Add tests for certificate expiry
Patch by Armando, adjusted by RFM.
2019-01-06 Fred Kiefer <fredkiefer@gmx.de>
* Source/Additions/Unicode.m: Move variable u to the correct scope

View file

@ -126,6 +126,13 @@ extern NSString * const GSTLSVerify;
*/
- (unsigned int) count;
/* Return the earliest expiry date of any certificate in the list.
*/
- (NSDate*) expiresAt;
/* Return the date when a certificate in the list expires.
*/
- (NSDate*) expiresAt: (unsigned int)index;
@end
/* This encapsulates private keys used to unlock certificates

View file

@ -136,18 +136,19 @@ NSZone.h
BaseAdditions_AGSDOC_FILES = \
../Documentation/BaseAdditions.gsdoc \
GNUstep.h \
GCObject.h \
GSBlocks.h \
GSVersionMacros.h \
GSObjCRuntime.h \
GSUnion.h \
GSIArray.h \
GSIMap.h \
GCObject.h \
GSLocale.h \
GSLock.h \
GSFunctions.h \
GSMime.h \
GSTLS.h \
GSXML.h \
GSLocale.h \
NSArray+GNUstepBase.h \
NSAttributedString+GNUstepBase.h \
NSBundle+GNUstepBase.h \

View file

@ -120,18 +120,19 @@ win32-def.top \
libgnustep-base.def
GNUSTEPBASE_HEADERS = \
GCObject.h \
GSBlocks.h \
GSVersionMacros.h \
GSObjCRuntime.h \
GSUnion.h \
GSIArray.h \
GSIMap.h \
GCObject.h \
GSLock.h \
GSFunctions.h \
GSMime.h \
GSXML.h \
GSLocale.h \
GSLock.h \
GSMime.h \
GSTLS.h \
GSXML.h \
NSArray+GNUstepBase.h \
NSAttributedString+GNUstepBase.h \
NSBundle+GNUstepBase.h \

View file

@ -43,13 +43,13 @@
#import "Foundation/NSValue.h"
#import "GNUstepBase/GSMime.h"
#import "GNUstepBase/GSLock.h"
#import "GNUstepBase/GSTLS.h"
#import "GNUstepBase/NSData+GNUstepBase.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
#import "GNUstepBase/NSURL+GNUstepBase.h"
#import "NSCallBacks.h"
#import "GSURLPrivate.h"
#import "GSPrivate.h"
#import "GSTLS.h"
#ifdef HAVE_SYS_FILE_H
# include <sys/file.h>

View file

@ -41,7 +41,7 @@
#import "GSStream.h"
#import "GSSocketStream.h"
#import "GSTLS.h"
#import "GNUstepBase/GSTLS.h"
#ifndef SHUT_RD
# ifdef SD_RECEIVE

View file

@ -38,7 +38,7 @@
#import "Foundation/NSThread.h"
#import "Foundation/NSUserDefaults.h"
#import "GSTLS.h"
#import "GNUstepBase/GSTLS.h"
#import "GSPrivate.h"
@ -794,6 +794,61 @@ static NSMutableDictionary *certificateListCache = nil;
return count;
}
- (NSDate*) expiresAt
{
unsigned index = count;
time_t expiret;
if (index-- == 0)
{
return nil;
}
expiret = gnutls_x509_crt_get_expiration_time(crts[index]);
if (expiret < 0)
{
return nil;
}
while (index > 0)
{
time_t t = gnutls_x509_crt_get_expiration_time(crts[--index]);
if (t < 0)
{
return nil;
}
if (t < expiret)
{
expiret = t;
}
}
return [NSDate dateWithTimeIntervalSince1970: expiret];
}
- (NSDate*) expiresAt: (unsigned)index
{
time_t expiret;
if (count == 0 || index > count - 1)
{
return nil;
}
expiret = gnutls_x509_crt_get_expiration_time(crts[index]);
if (expiret < 0)
{
return nil;
}
else
{
return [NSDate dateWithTimeIntervalSince1970: expiret];
}
}
- (void) dealloc
{
if (nil != path)

View file

@ -32,10 +32,10 @@
#import "Foundation/NSHost.h"
#import "Foundation/NSFileHandle.h"
#import "Foundation/NSPathUtilities.h"
#import "GNUstepBase/GSTLS.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
#import "GSPrivate.h"
#import "GSNetwork.h"
#import "GSTLS.h"
#define EXPOSE_GSFileHandle_IVARS 1

View file

@ -2027,9 +2027,10 @@ GSRunLoopInfoForThread(NSThread *aThread)
if (nil == lock)
{
NSLog(@"*** NSRunLoop ignoring exception '%@' (reason '%@') "
@"raised during perform in other thread... with receiver %p "
@"raised during perform in other thread... with receiver %p (%s) "
@"and selector '%s'",
[localException name], [localException reason], receiver,
class_getName(object_getClass(receiver)),
sel_getName(selector));
}
}

View file

@ -33,9 +33,9 @@
#import "Foundation/NSValue.h"
#import "GSPrivate.h"
#import "GSTLS.h"
#import "GSURLPrivate.h"
#import "GNUstepBase/GSMime.h"
#import "GNUstepBase/GSTLS.h"
#import "GNUstepBase/NSData+GNUstepBase.h"
#import "GNUstepBase/NSStream+GNUstepBase.h"
#import "GNUstepBase/NSString+GNUstepBase.h"

20
Tests/base/GSTLS/test.crt Normal file
View file

@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDWTCCAkGgAwIBAgIJAMJ2jmXj+OR0MA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV
BAYTAlVLMQ8wDQYDVQQHDAZMb25kb24xEDAOBgNVBAoMB0dOVXN0ZXAxEDAOBgNV
BAMMB0dOVXN0ZXAwIBcNMTkwMTA3MTUzNTExWhgPMjExODEyMTQxNTM1MTFaMEIx
CzAJBgNVBAYTAlVLMQ8wDQYDVQQHDAZMb25kb24xEDAOBgNVBAoMB0dOVXN0ZXAx
EDAOBgNVBAMMB0dOVXN0ZXAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQCqu1ged59B24uPCWxnS8QJug9yumiT0A+FqP6OF08RIf+rUArbSin5WecIYr5K
8sQF2P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