Passed
Push — release_2_0 ( 54acd9...58ed09 )
by Stefan
06:55
created

DeviceConfig::saveLogoFile()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 5
nop 2
dl 0
loc 25
rs 9.584
c 0
b 0
f 0
1
<?php
2
/*
3
 * *****************************************************************************
4
 * Contributions to this work were made on behalf of the GÉANT project, a 
5
 * project that has received funding from the European Union’s Framework 
6
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
7
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
8
 * 691567 (GN4-1) and No. 731122 (GN4-2).
9
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
10
 * of the copyright in all material which was developed by a member of the GÉANT
11
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
12
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
13
 * UK as a branch of GÉANT Vereniging.
14
 * 
15
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
16
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
17
 *
18
 * License: see the web/copyright.inc.php file in the file structure or
19
 *          <base_url>/copyright.php after deploying the software
20
 */
21
22
/**
23
 * This file defines the abstract Device class
24
 *
25
 * @package ModuleWriting
26
 */
27
/**
28
 * 
29
 */
30
31
namespace core;
32
33
use \Exception;
34
35
/**
36
 * This class defines the API for CAT module writers.
37
 *
38
 * A device is a fairly abstract notion. In most cases it represents
39
 * a particular operating system or a set of operationg systems
40
 * like MS Windows Vista and newer.
41
 *
42
 * The purpose of this class is to preapare a setup for the device configurator,
43
 * collect all necessary information from the database, taking into account
44
 * limitations, that a given device may present (like a set of supported EAP methods).
45
 *
46
 * All that is required from the device module is to produce a conigurator
47
 * file and pass its name back to the API.
48
 *
49
 * 
50
 * @author Tomasz Wolniewicz <[email protected]>
51
 *
52
 * @license see LICENSE file in root directory
53
 * 
54
 * @package ModuleWriting
55
 * @abstract
56
 */
57
abstract class DeviceConfig extends \core\common\Entity {
58
59
    /**
60
     * stores the path to the temporary working directory for a module instance
61
     * @var string $FPATH
62
     */
63
    public $FPATH;
64
65
    /**
66
     * array of specialities - will be displayed on the admin download as "footnote"
67
     * @var array specialities
68
     */
69
    public $specialities;
70
71
    /**
72
     * list of supported EAP methods
73
     * @var array EAP methods
74
     */
75
    public $supportedEapMethods;
76
    
77
    /**
78
     * sets the supported EAP methods for a device
79
     * 
80
     * @param array $eapArray the list of EAP methods the device supports
81
     * @return void
82
     */
83
    protected function setSupportedEapMethods($eapArray) {
84
        $this->supportedEapMethods = $eapArray;
85
        $this->loggerInstance->debug(4, "This device (" . __CLASS__ . ") supports the following EAP methods: ");
86
        $this->loggerInstance->debug(4, $this->supportedEapMethods);
87
    }
88
89
    /**
90
     * device module constructor should be defined by each module. 
91
     * The one important thing to do is to call setSupportedEapMethods with an 
92
     * array of EAP methods the device supports
93
     */
94
    public function __construct() {
95
        parent::__construct();
96
    }
97
98
    /**
99
     * Set up working environment for a device module
100
     *
101
     * Sets up the device module environment taking into account the actual profile
102
     * selected by the user in the GUI. The selected profile is passed as the
103
     * Profile $profile argumant.
104
     *
105
     * This method needs to be called after the device instance has been created (the GUI class does that)
106
     *
107
     * setup performs the following tasks:
108
     * - collect profile attributes and pass them as the attributes property;
109
     * - create the temporary working directory
110
     * - process CA certificates and store them as 'internal:CAs' attribute
111
     * - process and save optional info files and store references to them in
112
     *   'internal:info_file' attribute
113
     * @param AbstractProfile $profile        the profile object which will be passed by the caller
114
     * @param string          $token          the invitation token for silverbullet requests
115
     * @param string          $importPassword the PIN for the installer for silverbullet requests
116
     * @return void
117
     * @final not to be redefined
118
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag in function comment
Loading history...
119
    final public function setup(AbstractProfile $profile, $token = NULL, $importPassword = NULL) {
120
        $this->loggerInstance->debug(4, "module setup start\n");
121
        common\Entity::intoThePotatoes();
122
        $purpose = 'installer';
123
        $eaps = $profile->getEapMethodsinOrderOfPreference(1);
124
        $this->calculatePreferredEapType($eaps);
125
        if (count($this->selectedEap) == 0) {
126
            throw new Exception("No EAP type available.");
127
        }
128
        $this->attributes = $this->getProfileAttributes($profile);
129
        $this->deviceUUID = common\Entity::uuid('', 'CAT' . $profile->institution . "-" . $profile->identifier . "-" . $this->device_id);
130
131
132
        // if we are instantiating a Silverbullet profile AND have been given
133
        // a token, attempt to create the client certificate NOW
134
        // then, this is the only instance of the device ever which knows the
135
        // cert and private key. It's not saved anywhere, so it's gone forever
136
        // after code execution!
137
138
        $this->loggerInstance->debug(5, "DeviceConfig->setup() - preliminaries done.\n");
139
        if ($profile instanceof ProfileSilverbullet && $token !== NULL && $importPassword !== NULL) {
140
            $this->clientCert = SilverbulletCertificate::issueCertificate($token, $importPassword, $this->options['clientcert']);
141
            // we need to drag this along; ChromeOS needs it outside the P12 container to encrypt the entire *config* with it.
142
            // Because encrypted private keys are not supported as per spec!
143
            $purpose = 'silverbullet';
144
            // let's keep a record for which device type this token was consumed
145
            $dbInstance = DBConnection::handle("INST");
146
            $certId = $this->clientCert['certObject']->dbId;
147
            $dbInstance->exec("UPDATE `silverbullet_certificate` SET `device` = ? WHERE `id` = ?", "si", $this->device_id, $certId);
148
        }
149
        $this->loggerInstance->debug(5, "DeviceConfig->setup() - silverbullet checks done.\n");
150
        // create temporary directory, its full path will be saved in $this->FPATH;
151
        $tempDir = $this->createTemporaryDirectory($purpose);
152
        $this->FPATH = $tempDir['dir'];
153
        mkdir($tempDir['dir'] . '/tmp');
154
        chdir($tempDir['dir'] . '/tmp');
155
        $caList = [];
156
        $x509 = new \core\common\X509();
157
        if (isset($this->attributes['eap:ca_file'])) {
158
            foreach ($this->attributes['eap:ca_file'] as $ca) {
159
                $processedCert = $x509->processCertificate($ca);
160
                if (is_array($processedCert)) {
161
                    // add a UUID for convenience (some devices refer to their CAs by a UUID value)
162
                    $processedCert['uuid'] = common\Entity::uuid("", $processedCert['pem']);
163
                    $caList[] = $processedCert;
164
                }
165
            }
166
            $this->attributes['internal:CAs'][0] = $caList;
167
        }
168
        
169
        if (isset($this->attributes['support:info_file'])) {
170
            $this->attributes['internal:info_file'][0] = $this->saveInfoFile($this->attributes['support:info_file'][0]);
171
        }
172
        if (isset($this->attributes['general:logo_file'])) {
173
            $this->loggerInstance->debug(5, "saving IDP logo\n");
174
            $this->attributes['internal:logo_file'] = $this->saveLogoFile($this->attributes['general:logo_file'],'idp');
175
        }
176
        if (isset($this->attributes['fed:logo_file'])) {
177
            $this->loggerInstance->debug(5, "saving FED logo\n");
178
            $this->attributes['fed:logo_file'] = $this->saveLogoFile($this->attributes['fed:logo_file'], 'fed');
179
        }
180
        $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];
181
182
        $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];
183
184
        $this->attributes['internal:consortia'] = $this->getConsortia();
185
        
186
        $this->support_email_substitute = sprintf(_("your local %s support"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']);
187
        $this->support_url_substitute = sprintf(_("your local %s support page"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']);
188
189
        if ($this->signer && $this->options['sign']) {
190
            $this->sign = ROOT . '/signer/' . $this->signer;
191
        }
192
        $this->installerBasename = $this->getInstallerBasename();
193
        common\Entity::outOfThePotatoes();
194
    }
195
196
    /**
197
     * Selects the preferred eap method based on profile EAP configuration and device EAP capabilities
198
     *
199
     * @param array $eapArrayofObjects an array of eap methods supported by a given device
200
     * @return void
201
     */
202
    public function calculatePreferredEapType($eapArrayofObjects) {
203
        $this->selectedEap = [];
204
        foreach ($eapArrayofObjects as $eap) {
205
            if (in_array($eap->getArrayRep(), $this->supportedEapMethods)) {
206
                $this->selectedEap = $eap->getArrayRep();
207
                break;
208
            }
209
        }
210
        if ($this->selectedEap != []) {
211
            $this->selectedEapObject = new common\EAP($this->selectedEap);
212
        }
213
    }
214
215
    /**
216
     * prepare usage information for the installer
217
     * every device module should override this method
218
     *
219
     * @return string HTML text to be displayed
220
     */
221
    public function writeDeviceInfo() {
222
        common\Entity::intoThePotatoes();
223
        $retval = _("Sorry, this should not happen - no additional information is available");
224
        common\Entity::outOfThePotatoes();
225
        return $retval;
226
    }
227
    
228
    /**
229
     * function to return exactly one attribute type
230
     * 
231
     * @param string $attrName the attribute to retrieve
232
     * @return array|NULL the attributes
233
     */
234
    public function getAttribute($attrName) {
235
        return empty($this->attributes[$attrName]) ? NULL : $this->attributes[$attrName];
236
    }
237
238
    /**
239
     * some modules have a complex directory structure. This helper finds resources
240
     * in that structure. Mostly used in the Windows modules.
241
     * 
242
     * @param  string $file the filename to search for (without path)
243
     * @return string|boolean the filename as found, with path, or FALSE if it does not exist
244
     */
245
    protected function findSourceFile($file) {
246
        if (is_file($this->module_path . '/Files/' . $this->device_id . '/' . $file)) {
247
            return $this->module_path . '/Files/' . $this->device_id . '/' . $file;
248
        } elseif (is_file($this->module_path . '/Files/' . $file)) {
249
            return $this->module_path . '/Files/' . $file;
250
        } else {
251
            $this->loggerInstance->debug(2, "requested file $file does not exist\n");
252
            return FALSE;
253
        }
254
    }
255
256
    /**
257
     *  Copy a file from the module location to the temporary directory.
258
     *
259
     * If the second argument is provided then the file will be saved under the name 
260
     * taken form this argument. If only one parameter is given, source and destination
261
     * filenames are the same
262
     * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
263
     * named the same as device_id. The second option takes precedence.
264
     *
265
     * @param string $source_name The source file name
266
     * @param string $output_name The destination file name
267
     *
268
     * @return boolean result of the copy operation
269
     * @final not to be redefined
270
     */
271
    final protected function copyFile($source_name, $output_name = NULL) {
272
        if ($output_name === NULL) {
273
            $output_name = $source_name;
274
        }
275
        $this->loggerInstance->debug(5, "fileCopy($source_name, $output_name)\n");
276
        $source = $this->findSourceFile($source_name);
277
        if ($source === FALSE) {
278
            return FALSE;
279
        }
280
        $this->loggerInstance->debug(5, "Copying $source to $output_name\n");
281
        $result = copy($source, "$output_name");
282
        if (!$result) {
283
            $this->loggerInstance->debug(2, "fileCopy($source_name, $output_name) failed\n");
284
        }
285
        return($result);
286
    }
287
288
    /**
289
     * Save certificate files in either DER or PEM format
290
     *
291
     * Certificate files will be saved in the module working directory.
292
     * 
293
     * saved certificate file names are avalable under the 'file' index
294
     * additional array entries are indexed as 'sha1', 'md5', and 'root'.
295
     * sha1 and md5 are correcponding certificate hashes
296
     * root is set to 1 for the CA roor certicicate and 0 otherwise
297
     * 
298
     * @param string $format only "der" and "pem" are currently allowed
299
     * @return array an array of arrays or empty array on error
300
     
301
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag in function comment
Loading history...
302
    final protected function saveCertificateFiles($format) {
303
        switch ($format) {
304
            case "der": // fall-thorugh, same treatment
305
            case "pem":
306
                $iterator = 0;
307
                $caFiles = [];
308
                $caArray = $this->attributes['internal:CAs'][0];
309
                if (!$caArray) {
310
                    return([]);
311
                }
312
                foreach ($caArray as $certAuthority) {
313
                    $fileHandle = fopen("cert-$iterator.crt", "w");
314
                    if (!$fileHandle) {
315
                        throw new Exception("problem opening the file");
316
                    }
317
                    if ($format === "pem") {
318
                        fwrite($fileHandle, $certAuthority['pem']);
319
                    } else {
320
                        fwrite($fileHandle, $certAuthority['der']);
321
                    }
322
                    fclose($fileHandle);
323
                    $certAuthorityProps = [];
324
                    $certAuthorityProps['file'] = "cert-$iterator.crt";
325
                    $certAuthorityProps['sha1'] = $certAuthority['sha1'];
326
                    $certAuthorityProps['md5'] = $certAuthority['md5'];
327
                    $certAuthorityProps['root'] = $certAuthority['root'];
328
                    $caFiles[] = $certAuthorityProps;
329
                    $iterator++;
330
                }
331
                return($caFiles);
332
            default:
333
                $this->loggerInstance->debug(2, 'incorrect format value specified');
334
                return([]);
335
        }
336
    }
337
338
    /**
339
     * set of characters to remove from filename strings
340
     */
341
    private const TRANSLIT_SCRUB = '/[ ()\/\'"]+/';
342
    
343
    /**
344
     * Does a transliteration from UTF-8 to ASCII to get a sane filename
345
     * Takes special characters into account, and always uses English CTYPE
346
     * to avoid introduction of funny characters due to "flying accents"
347
     * 
348
     * @param string $input the input string that is to be transliterated
349
     * @return string the transliterated string
350
     */
351
    private function customTranslit($input) {
352
        $oldlocale = setlocale(LC_CTYPE, 0);
353
        setlocale(LC_CTYPE, "en_US.UTF-8");
354
        $retval = preg_replace(DeviceConfig::TRANSLIT_SCRUB, '_', iconv("UTF-8", "US-ASCII//TRANSLIT", $input));
355
        setlocale(LC_CTYPE, $oldlocale);
356
        return $retval;
357
    }
358
    
359
    /**
360
     * Generate installer filename base.
361
     * Device module should use this name adding an extension.
362
     * Normally the device identifier follows the Consortium name.
363
     * The sting taken for the device identifier equals (by default) to the index in the listDevices array,
364
     * but can be overriden with the 'device_id' device option.
365
     * 
366
     * @return string
367
     */
368
    private function getInstallerBasename() {
369
        
370
        $baseName = $this->customTranslit(CONFIG_CONFASSISTANT['CONSORTIUM']['name']) . "-" . $this->getDeviceId();
371
        if (isset($this->attributes['profile:customsuffix'][1])) { 
372
            // this string will end up as a filename on a filesystem, so always
373
            // take a latin-based language variant if available
374
            // and then scrub non-ASCII just in case
375
            return $baseName . $this->customTranslit($this->attributes['profile:customsuffix'][1]);
376
        }
377
        // Okay, no custom suffix. 
378
        // Use the configured inst name and apply shortening heuristics
379
        $lang_pointer = CONFIG['LANGUAGES'][$this->languageInstance->getLang()]['latin_based'] == TRUE ? 0 : 1;
380
        $this->loggerInstance->debug(5, "getInstallerBasename1:" . $this->attributes['general:instname'][$lang_pointer] . "\n");
381
        $inst = $this->customTranslit($this->attributes['general:instname'][$lang_pointer]);
382
        $this->loggerInstance->debug(4, "getInstallerBasename2:$inst\n");
383
        $Inst_a = explode('_', $inst);
384
        if (count($Inst_a) > 2) {
385
            $inst = '';
386
            foreach ($Inst_a as $i) {
387
                $inst .= $i[0];
388
            }
389
        }
390
        // and if the inst has multiple profiles, add the profile name behin
391
        if ($this->attributes['internal:profile_count'][0] > 1) {
392
            if (!empty($this->attributes['profile:name']) && !empty($this->attributes['profile:name'][$lang_pointer])) {
393
                $profTemp = $this->customTranslit($this->attributes['profile:name'][$lang_pointer]);
394
                $prof = preg_replace('/_+$/', '', $profTemp);
395
                return $baseName . $inst . '-' . $prof;
396
            }
397
        }
398
        return $baseName . $inst;
399
    }
400
401
    /**
402
     * returns the device_id of the current device
403
     * 
404
     * @return string
405
     */
406
    private function getDeviceId() {
407
        $deviceId = $this->device_id;
408
        if (isset($this->options['device_id'])) {
409
            $deviceId = $this->options['device_id'];
410
        }
411
        if ($deviceId !== '') {
412
            $deviceId .= '-';
413
        }
414
        return $deviceId;
415
    }
416
417
    /**
418
     * returns the list of SSIDs that installers should treat. 
419
     * 
420
     * Includes both SSIDs to be set up (and whether it's a TKIP-mixed or AES-only SSID) and SSIDs to be deleted
421
     * 
422
     * @return array
423
     */
424
    private function getSSIDs() {
425
        $ssidList = [];
426
        $ssidList['add'] = [];
427
        $ssidList['del'] = [];
428
        if (isset(CONFIG_CONFASSISTANT['CONSORTIUM']['ssid'])) {
429
            foreach (CONFIG_CONFASSISTANT['CONSORTIUM']['ssid'] as $ssid) {
430
                if (\core\common\Entity::getAttributeValue(CONFIG_CONFASSISTANT, 'CONSORTIUM', 'tkipsupport') == TRUE) {
431
                    $ssidList['add'][$ssid] = 'TKIP';
432
                } else {
433
                    $ssidList['add'][$ssid] = 'AES';
434
                    $ssidList['del'][$ssid] = 'TKIP';
435
                }
436
            }
437
        }
438
        if (isset($this->attributes['media:SSID'])) {
439
            $ssidWpa2 = $this->attributes['media:SSID'];
440
441
            foreach ($ssidWpa2 as $ssid) {
442
                $ssidList['add'][$ssid] = 'AES';
443
            }
444
        }
445
        if (isset($this->attributes['media:SSID_with_legacy'])) {
446
            $ssidTkip = $this->attributes['media:SSID_with_legacy'];
447
            foreach ($ssidTkip as $ssid) {
448
                $ssidList['add'][$ssid] = 'TKIP';
449
            }
450
        }
451
        if (isset($this->attributes['media:remove_SSID'])) {
452
            $ssidRemove = $this->attributes['media:remove_SSID'];
453
            foreach ($ssidRemove as $ssid) {
454
                $ssidList['del'][$ssid] = 'DEL';
455
            }
456
        }
457
        return $ssidList;
458
    }
459
460
    /**
461
     * returns the list of Hotspot 2.0 / Passpoint roaming consortia to set up
462
     * 
463
     * @return array
464
     */
465
    private function getConsortia() {
466
        if(!isset(CONFIG_CONFASSISTANT['CONSORTIUM']['interworking-consortium-oi'])) {
467
            return ([]);
468
        }
469
        $consortia = CONFIG_CONFASSISTANT['CONSORTIUM']['interworking-consortium-oi'];
470
        if (isset($this->attributes['media:consortium_OI'])) {
471
            foreach ($this->attributes['media:consortium_OI'] as $new_oi) {
472
                if(!in_array($new_oi, $consortia)) {
473
                    $consortia[] = $new_oi;
474
                }
475
            }
476
        }
477
        return $consortia;
478
    }
479
480
    /**
481
     * An array with shorthand definitions for MIME types
482
     * @var array
483
     */
484
    private $mime_extensions = [
485
        'text/plain' => 'txt',
486
        'text/rtf' => 'rtf',
487
        'application/pdf' => 'pdf',
488
    ];
489
490
    /**
491
     * saves a number of logos to a cache directory on disk.
492
     * 
493
     * @param array  $logos list of logos (binary strings each)
494
     * @param string $type  a qualifier what type of logo this is
495
     * @return array list of filenames and the mime types
496
     * @throws Exception
497
     */
498
    private function saveLogoFile($logos,$type) {
499
        $iterator = 0;
500
        $returnarray = [];
501
        foreach ($logos as $blob) {
502
            $finfo = new \finfo(FILEINFO_MIME_TYPE);
503
            $mime = $finfo->buffer($blob);
504
            $matches = [];
505
            if (preg_match('/^image\/(.*)/', $mime, $matches)) {
506
                $ext = $matches[1];
507
            } else {
508
                $ext = 'unsupported';
509
            }
510
            $this->loggerInstance->debug(5, "saveLogoFile: $mime : $ext\n");
511
            $fileName = 'logo-' . $type . $iterator . '.' . $ext;
512
            $fileHandle = fopen($fileName, "w");
513
            if (!$fileHandle) {
514
                $this->loggerInstance->debug(2, "saveLogoFile failed for: $fileName\n");
515
                throw new Exception("problem opening the file");
516
            }
517
            fwrite($fileHandle, $blob);
518
            fclose($fileHandle);
519
            $returnarray[] = ['name' => $fileName, 'mime' => $ext];
520
            $iterator++;
521
        }
522
        return($returnarray);
523
    }
524
525
    /**
526
     * saves the Terms of Use file onto disk
527
     * 
528
     * @param string $blob the Terms of Use
529
     * @return array with one entry, containging the filename and mime type
530
     * @throws Exception
531
     */
532
    private function saveInfoFile($blob) {
533
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
534
        $mime = $finfo->buffer($blob);
535
        $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported';
536
        $this->loggerInstance->debug(5, "saveInfoFile: $mime : $ext\n");
537
        $fileHandle = fopen('local-info.' . $ext, "w");
538
        if ($fileHandle === FALSE) {
539
            throw new Exception("problem opening the file");
540
        }
541
        fwrite($fileHandle, $blob);
542
        fclose($fileHandle);
543
        return(['name' => 'local-info.' . $ext, 'mime' => $ext]);
544
    }
545
546
    /**
547
     * returns the attributes of the profile for which to generate an installer
548
     * 
549
     * In condensed notion, and most specific level only (i.e. ignores overriden attributes from a higher level)
550
     * @param \core\AbstractProfile $profile the Profile in question
551
     * @return array
552
     */
553
    private function getProfileAttributes(AbstractProfile $profile) {
554
        $bestMatchEap = $this->selectedEap;
555
        if (count($bestMatchEap) > 0) {
556
            $a = $profile->getCollapsedAttributes($bestMatchEap);
557
            $a['eap'] = $bestMatchEap;
558
            $a['all_eaps'] = $profile->getEapMethodsinOrderOfPreference(1);
559
            return($a);
560
        }
561
        print("No supported eap types found for this profile.\n");
562
        return [];
563
    }
564
565
    /**
566
     * dumps attributes for debugging purposes
567
     *
568
     * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array
569
     * to a file with name passed in the attribute.
570
     * @param string $file the output file name
571
     * @return void
572
     */
573
    protected function dumpAttibutes($file) {
574
        ob_start();
575
        print_r($this->attributes);
576
        $output = ob_get_clean();
577
        file_put_contents($file, $output);
578
    }
579
580
    /**
581
     * placeholder for the main device method
582
     * @return string
583
     */
584
    abstract public function writeInstaller();
585
586
    /**
587
     * collates the string to use as EAP outer ID
588
     * 
589
     * @return string|NULL
590
     */
591
    protected function determineOuterIdString() {
592
        $outerId = NULL;
593
        if (isset($this->attributes['internal:use_anon_outer']) && $this->attributes['internal:use_anon_outer'][0] == "1" && isset($this->attributes['internal:realm'])) {
594
            $outerId = "@" . $this->attributes['internal:realm'][0];
595
            if (isset($this->attributes['internal:anon_local_value'])) {
596
                $outerId = $this->attributes['internal:anon_local_value'][0] . $outerId;
597
            }
598
        }
599
        return $outerId;
600
    }
601
602
    /**
603
     * Array passing all options to the device module.
604
     *
605
     * $attrbutes array contains option values defined for the institution and a particular
606
     * profile (possibly overriding one another) ready for the device module to consume.
607
     * 
608
     * For each of the options the value is another array of vales (even if only one value is present).
609
     * Some attributes may be missing if they have not been configured for a viven institution or profile.
610
     *
611
     * The following attributes are meant to be used by device modules:
612
     * - <b>general:geo_coordinates</b> -  geographical coordinates of the institution or a campus
613
     * - <b>support:info_file</b>  -  consent file displayed to the users                                                         
614
     * - <b>general:logo_file</b>  -  file data containing institution logo                                                      
615
     * - <b>support:eap_types</b>  -  URL to a local support page for a specific eap methiod, not to be confused with general:url 
616
     * - <b>support:email</b>      -  email for users to contact for local instructions                                           
617
     * - <b>support:phone</b>      -  telephone number for users to contact for local instructions                                
618
     * - <b>support:url</b>        -  URL where the user will find local instructions       
619
     * - <b>internal:info_file</b> -  the pathname of the info_file saved in the working directory
620
     * - <b>internal:logo_file</b>  -  array of pathnames of logo_files saved in the working directory
621
     * - <b>internal:CAs</b> - the value is an array produced by X509::processCertificate() with the following filds
622
     * - <b>internal:SSID</b> - an array indexed by SSID strings with values either TKIP or AES; if TKIP is set the both WPA/TKIP and WPA2/AES should be set if AES is set the this is a WPA2/AES only SSID; the consortium's defined SSIDs are always set as the first array elements.
623
     * - <b>internal:consortia</b> an array of consortion IO as declared in the config-confassistant
624
     * - <b>internal:profile_count</b> - the number of profiles for the associated IdP
625
     *
626
     *
627
     * these attributes are available and can be used, but the "internal" attributes are better suited for modules
628
     * -  eap:ca_file    -      certificate of the CA signing the RADIUS server key                                         
629
     * - <b>media:SSID</b>       -  additional SSID to configure, WPA2/AES only (device modules should use internal:SSID)
630
     * - <b>media:SSID_with_legacy</b> -  additional SSID to configure, WPA2/AES and WPA/TKIP (device modules should use internal:SSID)
631
     *
632
     * @see \core\common\X509::processCertificate()
633
     * @var array $attributes
0 ignored issues
show
Coding Style introduced by
The @var tag must be the first tag in a member variable comment
Loading history...
634
     */
635
    public $attributes;
636
637
    /**
638
     * stores the path to the module source location and is used 
639
     * by copyFile and translateFile
640
     * the only reason for it to be a public variable ies that it is set by the DeviceFactory class
641
     * module_path should not be used by module drivers.
642
     * @var string 
643
     */
644
    public $module_path;
645
646
    /**
647
     * * The optimal EAP type selected given profile and device
648
     * @var array
649
     */
650
    public $selectedEap;
651
    public $selectedEapObject;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
652
653
    /**
654
     * the path to the profile signing program
655
     * device modules which require signing should use this property to exec the signer
656
     * the signer program must accept two arguments - input and output file names
657
     * the signer program mus operate in the local directory and filenames are relative to this
658
     * directory
659
     *
660
     * @var string
661
     */
662
    public $sign;
663
    public $signer;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
664
665
    /**
666
     * The string identifier of the device (don't show this to users)
667
     * @var string
668
     */
669
    public $device_id;
670
671
    /**
672
     * See devices-template.php for a list of available options
673
     * @var array
674
     */
675
    public $options;
676
677
    /**
678
     * This string will be shown if no support email was configured by the admin
679
     * 
680
     * @var string 
681
     */
682
    public $support_email_substitute;
683
684
    /**
685
     * This string will be shown if no support URL was configured by the admin
686
     * 
687
     * @var string 
688
     */
689
    public $support_url_substitute;
690
691
    /**
692
     * This string should be used by all installer modules to set the 
693
     * installer file basename.
694
     *
695
     * @var string 
696
     */
697
    public $installerBasename;
698
699
    /**
700
     * stores the PKCS#12 DER representation of a client certificate for SilverBullet
701
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
702
    protected $clientCert;
703
704
    /**
705
     * stores identifier used by GEANTLink profiles
706
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
707
    public $deviceUUID;
708
709
}
710