feat(core): Add mobile provisioning download for Apple's devices

This commit is contained in:
smizrahi
2023-09-27 17:28:29 +02:00
committed by Hivert Quentin
parent 5b73a60aa6
commit 6d16ee7988
15 changed files with 282 additions and 2 deletions
+6 -2
View File
@@ -93,7 +93,9 @@ SOGo_HEADER_FILES = \
\
JWT.h \
\
NGMimeBodyPart+SOGo.h
NGMimeBodyPart+SOGo.h \
\
SOGoMobileProvision.h
all::
@touch SOGoBuild.m
@@ -180,7 +182,9 @@ SOGo_OBJC_FILES = \
\
JWT.m \
\
NGMimeBodyPart+SOGo.m
NGMimeBodyPart+SOGo.m \
\
SOGoMobileProvision.m
SOGo_C_FILES += lmhash.c aes.c crypt_blowfish.c pkcs5_pbkdf2.c
+39
View File
@@ -0,0 +1,39 @@
/* SOGoMobileProvision.h - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* 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
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef SOGOMOBILEPROVISION_H
#define SOGOMOBILEPROVISION_H
#include <SOGo/SOGoObject.h>
@class SOGoMobileProvision;
@class NSString;
@interface SOGoMobileProvision : SOGoObject
{
}
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path;
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path;
@end
#endif /* SOGOMOBILEPROVISION_H */
+125
View File
@@ -0,0 +1,125 @@
/* SOGoMobileProvision.m - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* 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
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/Foundation.h>
#import "SOGoMobileProvision.h"
#import "SOGoUser.h"
typedef NS_ENUM(NSInteger, ProvisioningType) {
ProvisioningTypeCalendar,
ProvisioningTypeContact
};
@implementation SOGoMobileProvision
+ (NSString *)_plistWithContext:(WOContext *)context andPath:(NSString *)path andType:(ProvisioningType) provisioningType
{
NSData *plistData;
SOGoUser *activeUser;
NSURL *serverURL;
NSDictionary *provisioning;
NSError *error;
NSString *payloadType, *prefix, *type;
activeUser = [context activeUser];
serverURL = [context serverURL];
if (!context || !path) {
[self errorWithFormat: @"Invalid provisioning profile - no parameters"];
return nil;
}
switch(provisioningType) {
case ProvisioningTypeCalendar:
payloadType = @"com.apple.caldav.account";
prefix = @"CalDAV";
type = @"Calendar";
break;
case ProvisioningTypeContact:
payloadType = @"com.apple.carddav.account";
prefix = @"CardDAV";
type = @"Contact";
break;
}
provisioning = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@ %@", type, [activeUser login]], [NSString stringWithFormat:@"%@%@", prefix, @"AccountDescription"],
[serverURL host], [NSString stringWithFormat:@"%@%@", prefix, @"HostName"],
[serverURL port], [NSString stringWithFormat:@"%@%@", prefix, @"Port"],
path, [NSString stringWithFormat:@"%@%@", prefix, @"PrincipalURL"],
[NSNumber numberWithBool:[[serverURL scheme] isEqualToString:@"https"]], [NSString stringWithFormat:@"%@%@", prefix, @"UseSSL"],
[activeUser login], [NSString stringWithFormat:@"%@%@", prefix, @"Username"],
[NSString stringWithFormat: @"SOGo %@ provisioning", prefix], @"PayloadDescription",
[NSString stringWithFormat:@"%@ %@", type, [activeUser login]], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.apple.%@", [serverURL host], [prefix lowercaseString]], @"PayloadIdentifier",
[serverURL host], @"PayloadOrganization",
payloadType, @"PayloadType",
[SOGoObject globallyUniqueObjectId], @"PayloadUUID",
[NSNumber numberWithInt: 1], @"PayloadVersion",
nil]], @"PayloadContent",
[NSString stringWithFormat:@"SOGo %@ provisioning", prefix], @"PayloadDescription",
[NSString stringWithFormat: @"%@ (%@)", [activeUser login], type], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.%@.apple", [prefix lowercaseString], [serverURL host]], @"PayloadIdentifier",
@"SOGo", @"PayloadOrganization",
[NSNumber numberWithBool: NO], @"PayloadRemovalDisallowed",
@"Configuration", @"PayloadType",
[SOGoObject globallyUniqueObjectId], @"PayloadUUID",
[NSNumber numberWithInt: 1], @"PayloadVersion",
nil];
return [NSPropertyListSerialization dataWithPropertyList: provisioning
format: NSPropertyListXMLFormat_v1_0
options: 0
error: &error];
}
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path
{
NSData *plistData;
SOGoUser *activeUser;
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeCalendar];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {
[self errorWithFormat: @"Invalid provisioning profile plist for account : %@", [activeUser login]];
return nil;
}
}
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path
{
NSData *plistData;
SOGoUser *activeUser;
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeContact];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {
[self errorWithFormat: @"Invalid provisioning profile plist for account : %@", [activeUser login]];
return nil;
}
}
@end
@@ -193,6 +193,7 @@
"Work" = "Work";
"Mobile" = "Mobile";
"Pager" = "Pager";
"Download configuration profile" = "Download configuration profile";
/* categories */
"contacts_category_labels" = "Colleague, Competitor, Customer, Friend, Family, Business Partner, Provider, Press, VIP";
@@ -193,6 +193,7 @@
"Work" = "Travail";
"Mobile" = "Portable";
"Pager" = "Téléavertisseur";
"Download configuration profile" = "Télécharger le profil de configuration";
/* categories */
"contacts_category_labels" = "Ami, Client, Collègue, Concurrent, Famille, Fournisseur, Partenaire d'affaire, Presse, VIP";
+27
View File
@@ -35,9 +35,11 @@
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoMobileProvision.h>
#import <Contacts/NGVCard+SOGo.h>
#import <Contacts/SOGoContactObject.h>
#import <Contacts/SOGoContactFolders.h>
#import "UIxContactView.h"
@@ -448,4 +450,29 @@
return [NSString stringWithFormat: @"%@/photo", [soURL absoluteString]];
}
- (WOResponse *) mobileconfigAction
{
SOGoContactFolders *folders;
NSString *davURL, *plistContent, *disposition;
WOResponse *response;
folders = [self clientObject];
davURL = [[folders container] davURLAsString];
plistContent = [SOGoMobileProvision plistForContactsWithContext: context andPath: davURL];
if (nil != plistContent) {
response = [self responseWithStatus: 200
andString: plistContent];
[response setHeader: @"application/x-plist; charset=utf-8"
forKey: @"content-type"];
disposition = [NSString stringWithString: @"attachment; filename=\"contacts.mobileconfig\""];
[response setHeader: disposition forKey: @"Content-Disposition"];
} else {
response = [self responseWithStatus: 500
andString: @"Error while generating profile"];
}
return response;
}
@end /* UIxContactView */
+5
View File
@@ -50,6 +50,11 @@
pageName = "UIxContactFoldersView";
actionName = "saveDragHandleState";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxContactView";
actionName = "mobileconfig";
};
};
};
@@ -65,6 +65,7 @@
"A total of %{0} events were imported in the calendar." = "A total of %{0} events were imported in the calendar.";
"Compose E-Mail to All Attendees" = "Compose E-Mail to All Attendees";
"Compose E-Mail to Undecided Attendees" = "Compose E-Mail to Undecided Attendees";
"Download configuration profile" = "Download configuration profile";
/* Relative dates */
"Yesterday" = "Yesterday";
@@ -65,6 +65,7 @@
"A total of %{0} events were imported in the calendar." = "Un total de %{0} événements ont été importés dans le calendrier.";
"Compose E-Mail to All Attendees" = "Rédiger un courriel pour tous les participants";
"Compose E-Mail to Undecided Attendees" = "Rédiger un courriel pour les participants indécis";
"Download configuration profile" = "Télécharger le profil de configuration";
/* Relative dates */
"Yesterday" = "Hier";
+26
View File
@@ -36,6 +36,7 @@
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoMobileProvision.h>
#import <SOGoUI/SOGoAptFormatter.h>
@@ -657,4 +658,29 @@
return r;
}
- (WOResponse *) mobileconfigAction
{
SOGoAppointmentFolders *folders;
NSString *davURL, *plistContent, *disposition;
WOResponse *response;
folders = [self clientObject];
davURL = [[folders container] davURLAsString];
plistContent = [SOGoMobileProvision plistForCalendarsWithContext: context andPath: davURL];
if (nil != plistContent) {
response = [self responseWithStatus: 200
andString: plistContent];
[response setHeader: @"application/x-plist; charset=utf-8"
forKey: @"content-type"];
disposition = [NSString stringWithString: @"attachment; filename=\"calendar.mobileconfig\""];
[response setHeader: disposition forKey: @"Content-Disposition"];
} else {
response = [self responseWithStatus: 500
andString: @"Error while generating profile"];
}
return response;
}
@end /* UIxCalView */
+5
View File
@@ -137,6 +137,11 @@
protectedBy = "View";
pageName = "UIxReminderEditor";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxCalView";
actionName = "mobileconfig";
};
};
};
@@ -117,6 +117,11 @@
</md-button>
</md-menu-item>
</var:if>
<md-menu-item>
<md-button ng-click="folder.downloadProvisioningProfile()">
 <var:string label:value="Download configuration profile"/>
</md-button>
</md-menu-item>
</md-menu-content>
</md-menu>
</md-list-item>
@@ -595,6 +595,12 @@
</md-button>
</md-menu-item>
</var:if>
<md-divider><!-- divider --></md-divider>
<md-menu-item>
<md-button ng-click="$menuCtrl.calendar.downloadProvisioningProfile()">
 <var:string label:value="Download configuration profile"/>
</md-button>
</md-menu-item>
</md-menu-content>
</div>
</script>
@@ -744,6 +744,23 @@
}
};
/**
* @function downloadProvisioningProfile
* @memberof Calendar.prototype
* @desc Download provisioning profile for Apple's devices
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.downloadProvisioningProfile = function () {
var options;
options = {
type: 'application/octet-stream',
filename: 'addressbook.mobileconfig'
}
return AddressBook.$$resource.open('', 'mobileconfig', null, options);
};
/**
* @function $unwrap
* @memberof AddressBook.prototype
@@ -576,6 +576,23 @@
return resource.open(path, 'export', null, options);
};
/**
* @function downloadProvisioningProfile
* @memberof Calendar.prototype
* @desc Download provisioning profile for Apple's devices
* @returns a promise of the HTTP operation
*/
Calendar.prototype.downloadProvisioningProfile = function () {
var options;
options = {
type: 'application/octet-stream',
filename: 'calendar.mobileconfig'
}
return Calendar.$$resource.open('', 'mobileconfig', null, options);
};
/**
* @function $setActivation
* @memberof Calendar.prototype