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:
richard 2000-07-04 14:37:18 +00:00
parent 705958575c
commit 1df9368648
8 changed files with 96 additions and 30 deletions

View file

@ -187,10 +187,14 @@ GS_EXPORT NSString *ConnectionBecameInvalidNotification;
- (NSConnection*) connection: (NSConnection*)ancestorConn
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;
- (NSData*) authenticationDataForComponents: (NSArray*)components;
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components;
@end

View file

@ -43,9 +43,6 @@
BOOL _encodingRoot;
BOOL _initialPass;
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 _eValImp; /* Method to encode others. */
#ifndef _IN_PORT_CODER_M

View file

@ -517,6 +517,7 @@ static Class runLoopClass;
[pm setMsgid: rId];
rId = 0;
DESTROY(rItems);
NSDebugMLLog(@"GSTcpHandle", @"got message %@", pm);
[rp handlePortMessage: pm];
RELEASE(pm);
}
@ -664,6 +665,7 @@ static Class runLoopClass;
* For a zero-length data chunk, we create an empty
* data object and add it to the current message.
*/
rType = GSP_NONE; /* ready for a new item */
rLength -= rWant;
if (rLength > 0)
{
@ -699,7 +701,7 @@ static Class runLoopClass;
{
GSPortMsgHeader *h;
rType = GSP_NONE;
rType = GSP_NONE; /* ready for a new item */
/*
* We have read a message header - set up to read the
* remainder of the message.
@ -756,7 +758,7 @@ static Class runLoopClass;
{
NSData *d;
rType = GSP_NONE;
rType = GSP_NONE; /* ready for a new item */
d = [mutableDataClass allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: rWant];
[rItems addObject: d];
@ -777,7 +779,7 @@ static Class runLoopClass;
{
GSTcpPort *p;
rType = GSP_NONE;
rType = GSP_NONE; /* ready for a new item */
p = decodePort(rData);
/*
* Set up to read another item header.
@ -931,8 +933,8 @@ static Class runLoopClass;
BOOL sent = NO;
NSAssert([components count] > 0, NSInternalInconsistencyException);
NSDebugMLLog(@"GSTcpHandle", @"Sending message 0x%x on 0x%x(%d) before %@",
components, self, desc, when);
NSDebugMLLog(@"GSTcpHandle", @"Sending message 0x%x %@ on 0x%x(%d) before %@",
components, components, self, desc, when);
[wMsgs addObject: components];
l = [runLoopClass currentRunLoop];

View file

@ -1458,19 +1458,22 @@ static NSLock *global_proxies_gate;
return;
}
if (_authenticateIn == YES)
if (conn->_authenticateIn == YES
&& (type == METHOD_REQUEST || type == METHOD_REPLY))
{
NSData *d;
unsigned count = [components count];
d = AUTORELEASE(RETAIN([components objectAtIndex: --count]));
d = RETAIN([components objectAtIndex: --count]);
[components removeObjectAtIndex: count];
if ([[self delegate] authenticateComponents: components
if ([[conn delegate] authenticateComponents: components
withData: d] == NO)
{
RELEASE(d);
[NSException raise: NSFailedAuthenticationException
format: @"message not authenticated by delegate"];
}
RELEASE(d);
}
rmc = [conn _makeInRmc: components];
@ -1995,7 +1998,8 @@ static NSLock *global_proxies_gate;
BOOL needsReply = NO;
NSMutableArray *components = [c _components];
if (_authenticateOut == YES)
if (_authenticateOut == YES
&& (msgid == METHOD_REQUEST || msgid == METHOD_REPLY))
{
NSData *d;

View file

@ -295,18 +295,27 @@ typeCheck(char t1, char t2)
@implementation NSPortCoder
@class NSMutableDataMalloc;
static Class connectionClass;
static Class mutableArrayClass;
static Class mutableDataClass;
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
{
if (self == [NSPortCoder class])
{
connectionClass = [NSConnection 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];
}
}
@ -330,6 +339,7 @@ static Class mutableDictionaryClass;
- (void) dealloc
{
RELEASE(_dst); /* Decoders retain their output data object. */
RELEASE(_comp);
RELEASE(_conn);
RELEASE(_cInfo);
@ -1683,14 +1693,10 @@ static Class mutableDictionaryClass;
_dst = [mutableDataClass allocWithZone: _zone];
_dst = [_dst initWithLength: _cursor];
[_comp addObject: _dst];
RELEASE(_dst);
/*
* 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];
_eValImp = [self methodForSelector: eValSel];
@ -1709,16 +1715,14 @@ static Class mutableDictionaryClass;
}
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];
while (count-- > 1)
{
[_comp removeObjectAtIndex: count];
}
[_comp removeAllObjects];
[_comp addObject: _dst];
[_dst setLength: _cursor];
GSIMapCleanMap(_clsMap);
GSIMapCleanMap(_cIdMap);

View file

@ -41,8 +41,8 @@
- (NSString*) description
{
return [NSString stringWithFormat:
@"NSPortMessage (Id %u)\n Send: %@\n Recv: %@\n Components -\n%@",
_msgid, _send, _recv, _components];
@"NSPortMessage 0x%x (Id %u)\n Send: %@\n Recv: %@\n Components -\n%@",
self, _msgid, _send, _recv, _components];
}
/* PortMessages MUST be initialised with ports and data. */

View file

@ -5,12 +5,41 @@
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSData.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSDebug.h>
#include <assert.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[])
{
@ -36,6 +65,7 @@ int main (int argc, char *argv[])
BOOL b;
const char *type;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
Auth *auth = [Auth new];
GSDebugAllocationActive(YES);
[NSConnection setDebug: 10];
@ -59,6 +89,7 @@ printf("oneway %d\n", _F_ONEWAY);
p = [NSConnection rootProxyForConnectionWithRegisteredName:@"test2server"
host:nil];
c = [p connectionForProxy];
[c setDelegate:auth];
[c setRequestTimeout:180.0];
[c setReplyTimeout:180.0];
localObj = [[NSObject alloc] init];

View file

@ -5,12 +5,36 @@
#include <Foundation/NSDistantObject.h>
#include <Foundation/NSString.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSData.h>
#include <Foundation/NSRunLoop.h>
#include <base/BinaryCStream.h>
#include <Foundation/NSAutoreleasePool.h>
#include "server.h"
@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
{
the_array = [[NSMutableArray alloc] init];