From 875a4aca3218340fd4d3141950c82c2ff45b343d Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 27 May 2016 10:53:16 -0400 Subject: [PATCH] (fix) improved previous commit for attributes stripping and UID generation (fixes #3695 and #3696) --- .../Appointments/SOGoCalendarComponent.m | 43 +++++++++++-------- SoObjects/SOGo/SOGoUserSettings.h | 3 +- SoObjects/SOGo/SOGoUserSettings.m | 28 +++++++++++- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index eb6ccebaf..49a779bec 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -41,12 +41,14 @@ #import #import #import +#import #import #import #import #import #import #import +#import #import #import #import @@ -202,14 +204,21 @@ - (void) _filterComponent: (iCalEntityObject *) component { - NSString *type, *summary, *tag; - NSArray *children; + NSString *type, *summary, *tag, *uid; + SOGoUserSettings *settings; + SOGoUser *calendarOwner; + NSEnumerator *children; + CardElement *element; + NSArray *tags; - int classification, i; + int classification; type = @"vtodo"; classification = 0; + calendarOwner = [SOGoUser userWithLogin: [self ownerInContext: context]]; + settings = [calendarOwner userSettings]; + if ([component isKindOfClass: [iCalEvent class]]) type = @"vevent"; @@ -221,25 +230,23 @@ summary = [self labelForKey: [NSString stringWithFormat: @"%@_class%d", type, classification] inContext: context]; - [component setSummary: summary]; - [component setComment: @""]; - [component setUserComment: @""]; - [component setLocation: @""]; - [component setCategories: [NSArray array]]; - [component setUrl: @""]; - [component setOrganizer: nil]; - [component removeAllAttendees]; - [component removeAllAlarms]; - // We strip all X- tags - children = [component children]; + tags = [NSArray arrayWithObjects: @"DTSTAMP", @"DTSTART", @"DTEND", @"DUE", @"EXDATE", @"EXRULE", @"RRULE", nil]; + uid = [[component uid] asCryptedPassUsingScheme: @"ssha256" + withSalt: [[settings userSalt] dataUsingEncoding: NSASCIIStringEncoding] + andEncoding: encHex]; - for (i = 0; i < [children count]; i++) + children = [[[[component children] copy] autorelease] objectEnumerator]; + + while ((element = [children nextObject])) { - tag = [[children objectAtIndex: i] tag]; - if ([[tag uppercaseString] hasPrefix: @"X-"]) - [component removeChild: [children objectAtIndex: i]]; + tag = [element tag]; + if (![tags containsObject: [tag uppercaseString]]) + [component removeChild: element]; } + + [component setSummary: summary]; + [component setUid: uid]; } - (NSString *) secureContentAsString diff --git a/SoObjects/SOGo/SOGoUserSettings.h b/SoObjects/SOGo/SOGoUserSettings.h index 25de5aaea..7a3958ae3 100644 --- a/SoObjects/SOGo/SOGoUserSettings.h +++ b/SoObjects/SOGo/SOGoUserSettings.h @@ -1,6 +1,6 @@ /* SOGoUserSettings.h - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2016 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ - (NSArray *) subscribedCalendars; - (NSArray *) subscribedAddressBooks; +- (NSString *) userSalt; @end diff --git a/SoObjects/SOGo/SOGoUserSettings.m b/SoObjects/SOGo/SOGoUserSettings.m index 7f0af9bc4..eb71d84c1 100644 --- a/SoObjects/SOGo/SOGoUserSettings.m +++ b/SoObjects/SOGo/SOGoUserSettings.m @@ -1,6 +1,6 @@ /* SOGoUserSettings.m - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2016 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,9 +19,11 @@ */ #import +#import #import #import "SOGoUserProfile.h" +#import "NSString+Crypto.h" #import "SOGoUserSettings.h" @@ -68,4 +70,28 @@ static Class SOGoUserProfileKlass = Nil; return [self _subscribedFoldersForModule: @"Contacts"]; } +- (NSString *) userSalt +{ + NSMutableDictionary *values; + NSString *salt; + + salt = [[self dictionaryForKey: @"General"] objectForKey: @"Salt"]; + + if (!salt) + { + salt = [[[NSProcessInfo processInfo] globallyUniqueString] asSHA1String]; + values = [self objectForKey: @"General"]; + + if (!values) + values = [NSMutableDictionary dictionary]; + + [values setObject: salt forKey: @"Salt"]; + [self setObject: values forKey: @"General"]; + [self synchronize]; + } + + return salt; +} + + @end