mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Updates for message authentication stuff
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6871 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
705958575c
commit
1df9368648
8 changed files with 96 additions and 30 deletions
|
@ -187,10 +187,14 @@ GS_EXPORT NSString *ConnectionBecameInvalidNotification;
|
||||||
- (NSConnection*) connection: (NSConnection*)ancestorConn
|
- (NSConnection*) connection: (NSConnection*)ancestorConn
|
||||||
didConnect: (NSConnection*)newConn;
|
didConnect: (NSConnection*)newConn;
|
||||||
|
|
||||||
|
/*
|
||||||
- (BOOL) authenticateComponents: (NSArray*)components
|
* These are like the MacOS-X delegate methods, except that we provide the
|
||||||
|
* components in mutable arrays, so that the delegate can alter the data
|
||||||
|
* items in the array. Of course, you must do that WITH CARE.
|
||||||
|
*/
|
||||||
|
- (BOOL) authenticateComponents: (NSMutableArray*)components
|
||||||
withData: (NSData*)authenticationData;
|
withData: (NSData*)authenticationData;
|
||||||
- (NSData*) authenticationDataForComponents: (NSArray*)components;
|
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,6 @@
|
||||||
BOOL _encodingRoot;
|
BOOL _encodingRoot;
|
||||||
BOOL _initialPass;
|
BOOL _initialPass;
|
||||||
id _dst; /* Serialization destination. */
|
id _dst; /* Serialization destination. */
|
||||||
IMP _eSerImp; /* Method to serialize with. */
|
|
||||||
IMP _eTagImp; /* Serialize a type tag. */
|
|
||||||
IMP _xRefImp; /* Serialize a crossref. */
|
|
||||||
IMP _eObjImp; /* Method to encode an id. */
|
IMP _eObjImp; /* Method to encode an id. */
|
||||||
IMP _eValImp; /* Method to encode others. */
|
IMP _eValImp; /* Method to encode others. */
|
||||||
#ifndef _IN_PORT_CODER_M
|
#ifndef _IN_PORT_CODER_M
|
||||||
|
|
|
@ -517,6 +517,7 @@ static Class runLoopClass;
|
||||||
[pm setMsgid: rId];
|
[pm setMsgid: rId];
|
||||||
rId = 0;
|
rId = 0;
|
||||||
DESTROY(rItems);
|
DESTROY(rItems);
|
||||||
|
NSDebugMLLog(@"GSTcpHandle", @"got message %@", pm);
|
||||||
[rp handlePortMessage: pm];
|
[rp handlePortMessage: pm];
|
||||||
RELEASE(pm);
|
RELEASE(pm);
|
||||||
}
|
}
|
||||||
|
@ -664,6 +665,7 @@ static Class runLoopClass;
|
||||||
* For a zero-length data chunk, we create an empty
|
* For a zero-length data chunk, we create an empty
|
||||||
* data object and add it to the current message.
|
* data object and add it to the current message.
|
||||||
*/
|
*/
|
||||||
|
rType = GSP_NONE; /* ready for a new item */
|
||||||
rLength -= rWant;
|
rLength -= rWant;
|
||||||
if (rLength > 0)
|
if (rLength > 0)
|
||||||
{
|
{
|
||||||
|
@ -699,7 +701,7 @@ static Class runLoopClass;
|
||||||
{
|
{
|
||||||
GSPortMsgHeader *h;
|
GSPortMsgHeader *h;
|
||||||
|
|
||||||
rType = GSP_NONE;
|
rType = GSP_NONE; /* ready for a new item */
|
||||||
/*
|
/*
|
||||||
* We have read a message header - set up to read the
|
* We have read a message header - set up to read the
|
||||||
* remainder of the message.
|
* remainder of the message.
|
||||||
|
@ -756,7 +758,7 @@ static Class runLoopClass;
|
||||||
{
|
{
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
rType = GSP_NONE;
|
rType = GSP_NONE; /* ready for a new item */
|
||||||
d = [mutableDataClass allocWithZone: NSDefaultMallocZone()];
|
d = [mutableDataClass allocWithZone: NSDefaultMallocZone()];
|
||||||
d = [d initWithBytes: bytes length: rWant];
|
d = [d initWithBytes: bytes length: rWant];
|
||||||
[rItems addObject: d];
|
[rItems addObject: d];
|
||||||
|
@ -777,7 +779,7 @@ static Class runLoopClass;
|
||||||
{
|
{
|
||||||
GSTcpPort *p;
|
GSTcpPort *p;
|
||||||
|
|
||||||
rType = GSP_NONE;
|
rType = GSP_NONE; /* ready for a new item */
|
||||||
p = decodePort(rData);
|
p = decodePort(rData);
|
||||||
/*
|
/*
|
||||||
* Set up to read another item header.
|
* Set up to read another item header.
|
||||||
|
@ -931,8 +933,8 @@ static Class runLoopClass;
|
||||||
BOOL sent = NO;
|
BOOL sent = NO;
|
||||||
|
|
||||||
NSAssert([components count] > 0, NSInternalInconsistencyException);
|
NSAssert([components count] > 0, NSInternalInconsistencyException);
|
||||||
NSDebugMLLog(@"GSTcpHandle", @"Sending message 0x%x on 0x%x(%d) before %@",
|
NSDebugMLLog(@"GSTcpHandle", @"Sending message 0x%x %@ on 0x%x(%d) before %@",
|
||||||
components, self, desc, when);
|
components, components, self, desc, when);
|
||||||
[wMsgs addObject: components];
|
[wMsgs addObject: components];
|
||||||
|
|
||||||
l = [runLoopClass currentRunLoop];
|
l = [runLoopClass currentRunLoop];
|
||||||
|
|
|
@ -1458,19 +1458,22 @@ static NSLock *global_proxies_gate;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_authenticateIn == YES)
|
if (conn->_authenticateIn == YES
|
||||||
|
&& (type == METHOD_REQUEST || type == METHOD_REPLY))
|
||||||
{
|
{
|
||||||
NSData *d;
|
NSData *d;
|
||||||
unsigned count = [components count];
|
unsigned count = [components count];
|
||||||
|
|
||||||
d = AUTORELEASE(RETAIN([components objectAtIndex: --count]));
|
d = RETAIN([components objectAtIndex: --count]);
|
||||||
[components removeObjectAtIndex: count];
|
[components removeObjectAtIndex: count];
|
||||||
if ([[self delegate] authenticateComponents: components
|
if ([[conn delegate] authenticateComponents: components
|
||||||
withData: d] == NO)
|
withData: d] == NO)
|
||||||
{
|
{
|
||||||
|
RELEASE(d);
|
||||||
[NSException raise: NSFailedAuthenticationException
|
[NSException raise: NSFailedAuthenticationException
|
||||||
format: @"message not authenticated by delegate"];
|
format: @"message not authenticated by delegate"];
|
||||||
}
|
}
|
||||||
|
RELEASE(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
rmc = [conn _makeInRmc: components];
|
rmc = [conn _makeInRmc: components];
|
||||||
|
@ -1995,7 +1998,8 @@ static NSLock *global_proxies_gate;
|
||||||
BOOL needsReply = NO;
|
BOOL needsReply = NO;
|
||||||
NSMutableArray *components = [c _components];
|
NSMutableArray *components = [c _components];
|
||||||
|
|
||||||
if (_authenticateOut == YES)
|
if (_authenticateOut == YES
|
||||||
|
&& (msgid == METHOD_REQUEST || msgid == METHOD_REPLY))
|
||||||
{
|
{
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
|
|
|
@ -295,18 +295,27 @@ typeCheck(char t1, char t2)
|
||||||
|
|
||||||
@implementation NSPortCoder
|
@implementation NSPortCoder
|
||||||
|
|
||||||
|
@class NSMutableDataMalloc;
|
||||||
|
|
||||||
static Class connectionClass;
|
static Class connectionClass;
|
||||||
static Class mutableArrayClass;
|
static Class mutableArrayClass;
|
||||||
static Class mutableDataClass;
|
static Class mutableDataClass;
|
||||||
static Class mutableDictionaryClass;
|
static Class mutableDictionaryClass;
|
||||||
|
|
||||||
|
static IMP _eSerImp; /* Method to serialize with. */
|
||||||
|
static IMP _eTagImp; /* Serialize a type tag. */
|
||||||
|
static IMP _xRefImp; /* Serialize a crossref. */
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSPortCoder class])
|
if (self == [NSPortCoder class])
|
||||||
{
|
{
|
||||||
connectionClass = [NSConnection class];
|
connectionClass = [NSConnection class];
|
||||||
mutableArrayClass = [NSMutableArray class];
|
mutableArrayClass = [NSMutableArray class];
|
||||||
mutableDataClass = [NSMutableData class];
|
mutableDataClass = [NSMutableDataMalloc class];
|
||||||
|
_eSerImp = [mutableDataClass instanceMethodForSelector: eSerSel];
|
||||||
|
_eTagImp = [mutableDataClass instanceMethodForSelector: eTagSel];
|
||||||
|
_xRefImp = [mutableDataClass instanceMethodForSelector: xRefSel];
|
||||||
mutableDictionaryClass = [NSMutableDictionary class];
|
mutableDictionaryClass = [NSMutableDictionary class];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,6 +339,7 @@ static Class mutableDictionaryClass;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
RELEASE(_dst); /* Decoders retain their output data object. */
|
||||||
RELEASE(_comp);
|
RELEASE(_comp);
|
||||||
RELEASE(_conn);
|
RELEASE(_conn);
|
||||||
RELEASE(_cInfo);
|
RELEASE(_cInfo);
|
||||||
|
@ -1683,14 +1693,10 @@ static Class mutableDictionaryClass;
|
||||||
_dst = [mutableDataClass allocWithZone: _zone];
|
_dst = [mutableDataClass allocWithZone: _zone];
|
||||||
_dst = [_dst initWithLength: _cursor];
|
_dst = [_dst initWithLength: _cursor];
|
||||||
[_comp addObject: _dst];
|
[_comp addObject: _dst];
|
||||||
RELEASE(_dst);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cache method implementations for writing into data object etc
|
* Cache method implementations for writing into data object etc
|
||||||
*/
|
*/
|
||||||
_eSerImp = [_dst methodForSelector: eSerSel];
|
|
||||||
_eTagImp = [_dst methodForSelector: eTagSel];
|
|
||||||
_xRefImp = [_dst methodForSelector: xRefSel];
|
|
||||||
_eObjImp = [self methodForSelector: eObjSel];
|
_eObjImp = [self methodForSelector: eObjSel];
|
||||||
_eValImp = [self methodForSelector: eValSel];
|
_eValImp = [self methodForSelector: eValSel];
|
||||||
|
|
||||||
|
@ -1709,16 +1715,14 @@ static Class mutableDictionaryClass;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned count;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If re-initialising, we just need to empty the old stuff.
|
* If re-initialising, we need to empty the old stuff.
|
||||||
|
* NB. Our _dst object may have been removed from the _comp
|
||||||
|
* array elsewhere, so we empty the _comp array and then re-add
|
||||||
|
* _dst
|
||||||
*/
|
*/
|
||||||
count = [_comp count];
|
[_comp removeAllObjects];
|
||||||
while (count-- > 1)
|
[_comp addObject: _dst];
|
||||||
{
|
|
||||||
[_comp removeObjectAtIndex: count];
|
|
||||||
}
|
|
||||||
[_dst setLength: _cursor];
|
[_dst setLength: _cursor];
|
||||||
GSIMapCleanMap(_clsMap);
|
GSIMapCleanMap(_clsMap);
|
||||||
GSIMapCleanMap(_cIdMap);
|
GSIMapCleanMap(_cIdMap);
|
||||||
|
|
|
@ -41,8 +41,8 @@
|
||||||
- (NSString*) description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
return [NSString stringWithFormat:
|
return [NSString stringWithFormat:
|
||||||
@"NSPortMessage (Id %u)\n Send: %@\n Recv: %@\n Components -\n%@",
|
@"NSPortMessage 0x%x (Id %u)\n Send: %@\n Recv: %@\n Components -\n%@",
|
||||||
_msgid, _send, _recv, _components];
|
self, _msgid, _send, _recv, _components];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PortMessages MUST be initialised with ports and data. */
|
/* PortMessages MUST be initialised with ports and data. */
|
||||||
|
|
|
@ -5,12 +5,41 @@
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSRunLoop.h>
|
#include <Foundation/NSRunLoop.h>
|
||||||
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSDate.h>
|
#include <Foundation/NSDate.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
@interface Auth : NSObject
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation Auth
|
||||||
|
- (BOOL) authenticateComponents: (NSMutableArray*)components
|
||||||
|
withData: (NSData*)authData
|
||||||
|
{
|
||||||
|
unsigned count = [components count];
|
||||||
|
|
||||||
|
while (count-- > 0)
|
||||||
|
{
|
||||||
|
id obj = [components objectAtIndex: count];
|
||||||
|
|
||||||
|
if ([obj isKindOfClass: [NSData class]] == YES)
|
||||||
|
{
|
||||||
|
NSMutableData *d = [obj mutableCopy];
|
||||||
|
unsigned l = [d length];
|
||||||
|
char *p = (char*)[d mutableBytes];
|
||||||
|
|
||||||
|
while (l-- > 0)
|
||||||
|
p[l] ^= 42;
|
||||||
|
[components replaceObjectAtIndex: count withObject: d];
|
||||||
|
RELEASE(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -36,6 +65,7 @@ int main (int argc, char *argv[])
|
||||||
BOOL b;
|
BOOL b;
|
||||||
const char *type;
|
const char *type;
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
|
Auth *auth = [Auth new];
|
||||||
|
|
||||||
GSDebugAllocationActive(YES);
|
GSDebugAllocationActive(YES);
|
||||||
[NSConnection setDebug: 10];
|
[NSConnection setDebug: 10];
|
||||||
|
@ -59,6 +89,7 @@ printf("oneway %d\n", _F_ONEWAY);
|
||||||
p = [NSConnection rootProxyForConnectionWithRegisteredName:@"test2server"
|
p = [NSConnection rootProxyForConnectionWithRegisteredName:@"test2server"
|
||||||
host:nil];
|
host:nil];
|
||||||
c = [p connectionForProxy];
|
c = [p connectionForProxy];
|
||||||
|
[c setDelegate:auth];
|
||||||
[c setRequestTimeout:180.0];
|
[c setRequestTimeout:180.0];
|
||||||
[c setReplyTimeout:180.0];
|
[c setReplyTimeout:180.0];
|
||||||
localObj = [[NSObject alloc] init];
|
localObj = [[NSObject alloc] init];
|
||||||
|
|
|
@ -5,12 +5,36 @@
|
||||||
#include <Foundation/NSDistantObject.h>
|
#include <Foundation/NSDistantObject.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSRunLoop.h>
|
#include <Foundation/NSRunLoop.h>
|
||||||
#include <base/BinaryCStream.h>
|
#include <base/BinaryCStream.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
@implementation Server
|
@implementation Server
|
||||||
|
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components
|
||||||
|
{
|
||||||
|
unsigned count = [components count];
|
||||||
|
|
||||||
|
while (count-- > 0)
|
||||||
|
{
|
||||||
|
id obj = [components objectAtIndex: count];
|
||||||
|
|
||||||
|
if ([obj isKindOfClass: [NSData class]] == YES)
|
||||||
|
{
|
||||||
|
NSMutableData *d = [obj mutableCopy];
|
||||||
|
unsigned l = [d length];
|
||||||
|
char *p = (char*)[d mutableBytes];
|
||||||
|
|
||||||
|
while (l-- > 0)
|
||||||
|
p[l] ^= 42;
|
||||||
|
[components replaceObjectAtIndex: count withObject: d];
|
||||||
|
RELEASE(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [NSData data];
|
||||||
|
}
|
||||||
|
|
||||||
- init
|
- init
|
||||||
{
|
{
|
||||||
the_array = [[NSMutableArray alloc] init];
|
the_array = [[NSMutableArray alloc] init];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue