Test Failed
Push — master ( f87563...d76ff0 )
by Tomasz
10:13
created

DeviceXML::scaleLogo()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 23
c 2
b 0
f 1
dl 0
loc 38
rs 9.2408
cc 5
nc 6
nop 2
1
<?php
2
3
/*
4
 * *****************************************************************************
5
 * Contributions to this work were made on behalf of the GÉANT project, a 
6
 * project that has received funding from the European Union’s Framework 
7
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
8
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
9
 * 691567 (GN4-1) and No. 731122 (GN4-2).
10
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
11
 * of the copyright in all material which was developed by a member of the GÉANT
12
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
13
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
14
 * UK as a branch of GÉANT Vereniging.
15
 * 
16
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
17
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
18
 *
19
 * License: see the web/copyright.inc.php file in the file structure or
20
 *          <base_url>/copyright.php after deploying the software
21
 */
22
23
/**
24
 * This file defines an abstract class used for generic XML
25
 * devices
26
 * actual modules only define available EAP types.
27
 *
28
 * @author Maja Gorecka-Wolniewicz <[email protected]>
29
 * @author Tomasz Wolniewicz <[email protected]>
30
 *
31
 * @package ModuleWriting
32
 */
33
34
namespace devices\eap_config;
35
36
use Exception;
37
38
/**
39
 * This class implements full functionality of the generic XML device
40
 * the only function of the extensions of this class is to specify
41
 * supported EAP methods.
42
 * Instead of specifying supported EAPS an extension can set $all_eaps to true
43
 * this will cause the installer to configure all EAP methods supported by 
44
 * the current profile and declared by the given device.
45
 */
46
abstract class DeviceXML extends \core\DeviceConfig
47
{
48
    
49
    /**
50
     *  @var array $AuthMethodElements is used to limit
51
     *  XML elements present within ServerSideCredentials and
52
     *  ClientSideCredentials to ones which are relevant
53
     *  for a given EAP method.
54
     *  @var array of XLM element names which are allowed
55
     *  EAP method names are defined in core/EAP.php
56
     */
57
    private $authMethodElements = [
58
        'server' => [
59
            \core\common\EAP::TLS => ['CA', 'ServerID'],
60
            \core\common\EAP::FAST => ['CA', 'ServerID'],
61
            \core\common\EAP::PEAP => ['CA', 'ServerID'],
62
            \core\common\EAP::TTLS => ['CA', 'ServerID'],
63
            \core\common\EAP::PWD => ['ServerID'],
64
        ],
65
        'client' => [
66
            \core\common\EAP::TLS => ['UserName', 'Password', 'ClientCertificate'],
67
            \core\common\EAP::NE_MSCHAP2 => ['UserName', 'Password', 'OuterIdentity', 'InnerIdentitySuffix', 'InnerIdentityHint'],
68
            \core\common\EAP::MSCHAP2 => ['UserName', 'Password', 'OuterIdentity', 'InnerIdentitySuffix', 'InnerIdentityHint'],
69
            \core\common\EAP::GTC => ['UserName', 'OneTimeToken'],
70
            \core\common\EAP::NE_PAP => ['UserName', 'Password', 'OuterIdentity', 'InnerIdentitySuffix', 'InnerIdentityHint'],
71
            \core\common\EAP::NE_SILVERBULLET => ['UserName', 'ClientCertificate', 'OuterIdentity'],
72
            \core\common\EAP::NONE => [],
73
        ]
74
    ];
75
76
    /**
77
     * construct the device
78
     */
79
    public function __construct()
80
    {
81
        parent::__construct();
82
    }
83
84
    /**
85
     * $langScope can be 'global' when all lang and all lang-specific information
86
     * is dumped or 'single' when only the selected lang (and defaults) are passed
87
     * 
88
     * @var string
89
     */
90
    public $langScope;
91
92
    /**
93
     * whether all EAP types should be included in the file or only the 
94
     * preferred one
95
     * 
96
     * @var boolean
97
     */
98
    public $allEaps = false;
99
100
    /**
101
     * vendor-specific additional information, this is nit yest fully
102
     * implemented due to lack of use cases.
103
     * 
104
     * @var array
105
     */
106
    public $VendorSpecific;
107
    
108
    /**
109
     * A flag to preserve backwards compatibility for eduroamCAT application
110
     */
111
    public $eduroamCATcompatibility = false; 
112
    public $singleEAPProvider = false;
113
114
    private $eapId;
115
    private $namespace;
116
    private $providerInfo;
117
    private $authMethodsList;
118
    
119
    /**
120
     * create HTML code explaining the installer
121
     * 
122
     * @return string
123
     */
124
    public function writeDeviceInfo()
125
    {
126
        \core\common\Entity::intoThePotatoes();
127
        $out = "<p>";
128
        $out .= sprintf(_("This is a generic configuration file in the IETF <a href='%s'>EAP Metadata -00</a> XML format."), "https://tools.ietf.org/html/draft-winter-opsawg-eap-metadata-00");
129
        \core\common\Entity::outOfThePotatoes();
130
        return $out;
131
    }
132
133
    /**
134
     * create the actual XML file
135
     * 
136
     * @return string filename of the generated installer
137
     * @throws Exception
138
     *
139
     */
140
    public function writeInstaller()
141
    {
142
        \core\common\Entity::intoThePotatoes();
143
        $rootname = 'EAPIdentityProviderList';
144
        $dom = new \DOMDocument('1.0', 'utf-8');
145
        $root = $dom->createElement($rootname);
146
        $dom->appendChild($root);
147
        $ns = $dom->createAttributeNS( 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation' );
148
        $ns->value = "eap-metadata.xsd";
149
        $root->appendChild($ns);
150
        $this->openRoamingToU = sprintf(_("I have read and agree to OpenRoaming Terms of Use at %s."), "https://wballiance.com/openroaming/toc-2020/");
151
        foreach ($this->languageInstance->getAllTranslations("I have read and agree to OpenRoaming Terms of Use at %s", "device") as $lang => $message) {
152
            $this->openRoamingToUArray[$lang] = sprintf($message, "https://wballiance.com/openroaming/toc-2020/");
153
        }
154
        
155
        if (empty($this->attributes['internal:realm'][0])) {
156
            $this->eapId = 'undefined';
157
            $this->namespace = 'urn:undefined';
158
        } else {
159
            $this->eapId = $this->attributes['internal:realm'][0];
160
            $this->namespace = 'urn:RFC4282:realm';
161
        }
162
        
163
        $this->authMethodsList = $this->getAuthMethodsList();
164
        $this->loggerInstance->debug(5, $this->attributes['internal:networks'], "NETWORKS:", "\n");
165
        /*
166
         * This approach is forced by geteduroam compatibility. We pack all networks into a single Provider
167
         * with the exception of the openroaming one which we pack separately.
168
         */
169
        
170
        if ($this->singleEAPProvider === true) {
171
            /*
172
             * if "condition" is set to openroaming, OpenRoaming terms of use must be mentioned
173
             * unless the preagreed is set for openroaming
174
             * if "ask" is set then we generate a separate OR profile which needs to contain the OR ToU
175
             * the ToU is not needed in the eduroam-only profile
176
             */
177
            $ssids = [];
178
            $ois = [];
179
            $orNetwork = [];
180
            foreach ($this->attributes['internal:networks'] as $netName => $netDefinition) {
181
                if ($netDefinition['condition'] === 'internal:openroaming' &&
182
                        $this->attributes['internal:openroaming']) {
183
                    $this->setORtou();
184
                    if (preg_match("/^ask/",$this->attributes['media:openroaming'][0])) {
185
                        $orNetwork = $netDefinition;
186
                        continue;                        
187
                    }
188
                }
189
                foreach ($netDefinition['ssid'] as $ssid) {
190
                    $ssids[] = $ssid;
191
                }
192
                foreach ($netDefinition['oi'] as $oi) {
193
                    $ois[] = $oi;
194
                }
195
            }
196
197
            if (!empty($orNetwork)) {
198
                $this->addORtou = false;
199
            }
200
            $this->providerInfo = $this->getProviderInfo();
201
            
202
            if (!empty($ssids) || !empty($ois)) {
203
                \core\DeviceXMLmain::marshalObject($dom, $root, 'EAPIdentityProvider', $this->eapIdp($ssids, $ois));
204
            }
205
            
206
            if (!empty($orNetwork)) {
207
                // here we need to add the Tou unless preagreed is set
208
                $this->setORtou();
209
                $this->providerInfo = $this->getProviderInfo();
210
                \core\DeviceXMLmain::marshalObject($dom, $root, 'EAPIdentityProvider', $this->eapIdp($orNetwork['ssid'], $orNetwork['oi']));
211
            }
212
        } else {
213
214
            foreach ($this->attributes['internal:networks'] as $netName => $netDefinition) {
215
                if ($netDefinition['condition'] === 'internal:openroaming' &&
216
                        $this->attributes['internal:openroaming']) {
217
                    $this->setORtou();
218
                } else {
219
                    $this->addORtou = false;
220
                }
221
                $this->providerInfo = $this->getProviderInfo();
222
                $ssids = $netDefinition['ssid'];
223
                $ois = $netDefinition['oi'];
224
                if (!empty($ssids) || !empty($ois)) {
225
                    \core\DeviceXMLmain::marshalObject($dom, $root, 'EAPIdentityProvider', $this->eapIdp($ssids, $ois));
226
                }
227
            }
228
        }
229
        
230
        if ($dom->schemaValidate(ROOT.'/devices/eap_config/eap-metadata.xsd') === FALSE) {
231
            throw new Exception("Schema validation failed for eap-metadata");
232
        }
233
234
        $dom->formatOutput = true;
235
        file_put_contents($this->installerBasename.'.eap-config', $dom->saveXML($dom));
236
        \core\common\Entity::outOfThePotatoes();
237
        return($this->installerBasename.'.eap-config');
238
    }
239
    
240
    private function setORtou() {
241
        if (preg_match("/preagreed/",$this->attributes['media:openroaming'][0])) {
242
            $this->addORtou = false;
243
        } else {
244
            $this->addORtou = true;
245
        }
246
    }
247
    
248
    /**
249
     * determines the inner authentication. Is it EAP, and which mechanism is used to convey actual auth data
250
     * @param array $eap the EAP type for which we want to get the inner auth
251
     * @return array
252
     */    
253
    private function eapIdp($ssids, $oids)
254
    {
255
        $eapIdp = new \core\DeviceXMLmain();
256
        $eapIdp->setAttribute('version', '1');
257
        if ($this->langScope === 'single') {
258
            $eapIdp->setAttribute('lang', $this->languageInstance->getLang());
259
        }
260
        $eapIdp->setAttribute('ID', $this->eapId);
261
        $eapIdp->setAttribute('namespace', $this->namespace);
262
        $authMethods = new \core\DeviceXMLmain();
263
        $authMethods->setChild('AuthenticationMethod', $this->authMethodsList);
264
        $eapIdp->setChild('AuthenticationMethods', $authMethods);
265
        $eapIdp->setChild('CredentialApplicability', $this->getCredentialApplicability($ssids,$oids));
266
// TODO   $eap_idp->setChild('ValidUntil',$this->getValidUntil());
267
        $eapIdp->setChild('ProviderInfo', $this->providerInfo);
268
// TODO   $eap_idp->setChild('VendorSpecific',$this->getVendorSpecific());
269
        return($eapIdp);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $eapIdp returns the type core\DeviceXMLmain which is incompatible with the documented return type array.
Loading history...
270
    }
271
272
    /**
273
     * determines the inner authentication. Is it EAP, and which mechanism is used to convey actual auth data
274
     * @param array $eap the EAP type for which we want to get the inner auth
275
     * @return array
276
     */  
277
    private function innerAuth($eap)
278
    {
279
        $out = [];
280
        $out['EAP'] = 0;
281
        switch ($eap["INNER"]) {
282
            case \core\common\EAP::NE_MSCHAP2:
283
                if ($this->eduroamCATcompatibility === TRUE) {
284
                    $out['METHOD'] = \core\common\EAP::MSCHAP2;
285
                    $out['EAP'] = 1;
286
                } else {
287
                    $out['METHOD'] = $eap["INNER"];
288
                }
289
                break;
290
            case \core\common\EAP::NE_SILVERBULLET:
291
                $out['METHOD'] = \core\common\EAP::NONE;
292
                break;
293
            default:
294
                $out['METHOD'] = $eap["INNER"];
295
                break;
296
        }
297
        // override if there is an inner EAP
298
        if ($eap["INNER"] > 0) { // there is an inner EAP method
299
            $out['EAP'] = 1;
300
        }
301
        return $out;
302
    }
303
    
304
    /**
305
     * 
306
     * @param string $attrName the attribute name
307
     * @return array of values for this attribute
308
     */
309
    private function getSimpleMLAttribute($attrName)
310
    {
311
        if (empty($this->attributes[$attrName][0])) {
312
            return([]);
313
        }
314
        $attributeList = $this->attributes[$attrName];
315
        $objs = [];
316
        if ($this->langScope === 'global') {
317
            foreach ($attributeList['langs'] as $language => $value) {
318
                $language = ($language === 'C' ? 'any' : $language);
319
                $obj = new \core\DeviceXMLmain();
320
                $obj->setValue($value);
321
                $obj->setAttributes(['lang' => $language]);
322
                $objs[] = $obj;
323
            }
324
        } else {
325
            $objs[] = $attributeList[0];
326
        }
327
        return($objs);
328
    }
329
    
330
    /**
331
     * constructs the name of the institution and puts it into the XML.
332
     * consists of the best-language-match inst name, and if the inst has more 
333
     * than one profile also the best-language-match profile name
334
     * 
335
     * @return \core\DeviceXMLmain[]
336
     */
337
    private function getDisplayName()
338
    {
339
        $attr = $this->attributes;
340
        $objs = [];
341
        if ($this->langScope === 'global') {
342
            $instNameLangs = $attr['general:instname']['langs'];
343
            if ($attr['internal:profile_count'][0] > 1) {
344
                $profileNameLangs = $attr['profile:name']['langs'];
345
            }
346
            foreach ($instNameLangs as $language => $value) {
347
                $language = ($language === 'C' ? 'any' : $language);
348
                $displayname = new \core\DeviceXMLmain();
349
                if (isset($profileNameLangs)) {
350
                    $langOrC = isset($profileNameLangs[$language]) ? $profileNameLangs[$language] : $profileNameLangs['C'];
351
                    $value .= ' - '.$langOrC;
352
                }
353
                $displayname->setValue($value);
354
                $displayname->setAttributes(['lang' => $language]);
355
                $objs[] = $displayname;
356
            }
357
        } else {
358
            $displayname = new \core\DeviceXMLmain();
359
            $value = $attr['general:instname'][0];
360
            if ($attr['internal:profile_count'][0] > 1) {
361
                $value .= ' - '.$attr['profile:name'][0];
362
            }
363
            $displayname->setValue($value);
364
            $objs[] = $displayname;
365
        }
366
        return $objs;
367
    }
368
369
    /**
370
     * retrieves the provider logo and puts it into the XML structure
371
     * 
372
     * @return \core\DeviceXMLmain
373
     */
374
    private function getProviderLogo()
375
    {
376
        $attr = $this->attributes;
377
        if (isset($attr['general:logo_file'][0])) {
378
            $rawLogoBlob = $attr['general:logo_file'][0];
379
            $logoMime= $attr['internal:logo_file'][0]['mime'];
380
            [$scaledBlob, $scaledMime] = $this->scaleLogo($rawLogoBlob, $logoMime);
381
            $logoString = base64_encode($scaledBlob);
382
            $providerlogo = new \core\DeviceXMLmain();
383
            $providerlogo->setAttributes(['mime' => 'image/'.$scaledMime, 'encoding' => 'base64']);
384
            $providerlogo->setValue($logoString);
385
            return $providerlogo;
386
        }
387
        return NULL;
388
    }
389
    
390
    /**
391
     * Scales a logo to the desired byte imag size if necessary.
392
     * If the image size is below tha alowed maximum, nothing is done;
393
     * if the image is larger than we run a series of scaling iterations to sizes
394
     * specified in $maxPixelSize and the moment we manage to end up below the $maxByte
395
     * we returm the scaled blob - we always use png as the output format since it seems
396
     * to behave best in scaling.
397
     * 
398
     * @param string $blob the image data
399
     * @param string $mime the mime type of the original image
400
     * @return array the scaled blob, the resulting mime type
401
     */
402
    private function scaleLogo($blob, $mime)
403
    {
404
        $maxByte = 1024*50;
405
        $maxPixelSize = [400,300,200,100];
406
        // start with the actual file size
407
        $logoSize = strlen($blob);
408
        \core\common\Logging::debug_s(4, $logoSize, "Logo file size: ", "\n");
409
        if ($logoSize <= $maxByte) {
410
            return [$blob, $mime];
411
        }
412
        // resize logo if necessary
413
        /* Gmagic implementation would require method naming changes
414
        if (class_exists('\\Gmagick')) { 
415
            $imageObject = new \Gmagick(); 
416
        } else {
417
         * 
418
         */
419
            $imageObject = new \Imagick();
420
//        }
421
        $imageObject->readImageBlob($blob);       
422
        $imageSize = $imageObject->getImageGeometry();
423
        \core\common\Logging::debug_s(4, $imageSize, "Input logo pixel size: ","\n");        
424
        foreach ($maxPixelSize as $size) {
425
            $tmpImage = $imageObject;
426
            $tmpImage->setImageFormat('PNG');
427
            \core\common\Logging::debug_s(4, $size, "Reducing size to: ", "\n");
428
            if ($imageSize['width'] > $imageSize['height']) {
429
                $tmpImage->thumbnailImage($size, 0);
430
            } else {
431
                $tmpImage->thumbnailImage(0, $size);
432
            }
433
            $outBlob = $tmpImage->getImageBlob();
434
            if (strlen($outBlob) <= $maxByte) {
435
                break;
436
            }
437
        }
438
        \core\common\Logging::debug_s(4, strlen($outBlob), "Scaled size: ", "\n");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $outBlob seems to be defined by a foreach iteration on line 424. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
439
        return [$outBlob, 'png'];
440
    }
441
442
    /**
443
     * retrieves provider information and puts it into the XML structure.
444
     * contains the profile description and the ToU file, if any
445
     * 
446
     * @return \core\DeviceXMLmain
447
     */
448
    private function getProviderInfo()
449
    {
450
        $providerinfo = new \core\DeviceXMLmain();
451
        $providerinfo->setChild('DisplayName', $this->getDisplayName());
452
        $providerinfo->setChild('Description', $this->getSimpleMLAttribute('profile:description'));
453
        $providerinfo->setChild('ProviderLocation', $this->getProviderLocation());
454
        $providerinfo->setChild('ProviderLogo', $this->getProviderLogo());
455
        $providerinfo->setChild('TermsOfUse', $this->getProviderTou(), null, 'cdata');
456
        $providerinfo->setChild('Helpdesk', $this->getHelpdesk());
457
        return $providerinfo; 
458
    }
459
    
460
    private function getProviderTou() {
461
        $standardTou = $this->getSimpleMLAttribute('support:info_file');
462
        if ($this->addORtou === false) {
463
            return $standardTou;
464
        }
465
        $out = [];
466
        if ($this->langScope === 'global') {
467
            foreach ($standardTou as $touObj) {
468
                $tou = $touObj->getValue();
469
                $lngAttr = $touObj->getAttributes();
470
                $lng = $lngAttr['lang'] === 'any' ? \config\Master::APPEARANCE['defaultlocale'] : $lngAttr['lang'];
471
                $tou .= "\n".$this->openRoamingToUArray[$lng];
472
                $touObj->setValue($tou);
473
                $out[] =  $touObj;
474
            } 
475
        } else {
476
            $tou = $standardTou[0];
477
            $tou .= "\n".$this->openRoamingToU;
478
            $out = [$tou];
479
        }
480
        return $out;
481
    }
482
483
    /**
484
     * retrieves the location information and puts it into the XML structure
485
     * 
486
     * @return \core\DeviceXMLmain[]
487
     */
488
    private function getProviderLocation()
489
    {
490
        $attr = $this->attributes;
491
        if (isset($attr['general:geo_coordinates'])) {
492
            $attrCoordinates = $attr['general:geo_coordinates'];
493
            $location = [];
494
            foreach ($attrCoordinates as $a) {
495
                $providerlocation = new \core\DeviceXMLmain();
496
                $b = json_decode($a, true);
497
                $providerlocation->setChild('Longitude', $b['lon']);
498
                $providerlocation->setChild('Latitude', $b['lat']);
499
                $location[] = $providerlocation;
500
            }           
501
            return $location;
502
        }
503
        return NULL;
504
    }
505
506
    /**
507
     * retrieves helpdesk contact information and puts it into the XML structure
508
     * 
509
     * @return \core\DeviceXMLmain
510
     */
511
    private function getHelpdesk()
512
    {
513
        $helpdesk = new \core\DeviceXMLmain();
514
        $helpdesk->setChild('EmailAddress', $this->getSimpleMLAttribute('support:email'));
515
        $helpdesk->setChild('WebAddress', $this->getSimpleMLAttribute('support:url'));
516
        $helpdesk->setChild('Phone', $this->getSimpleMLAttribute('support:phone'));
517
        return $helpdesk;
518
    }
519
520
    /**
521
     * determine where this credential should be applicable
522
     * 
523
     * @return \core\DeviceXMLmain
524
     */
525
    private function getCredentialApplicability($ssids, $oids)
526
    {
527
        $setWired = isset($this->attributes['media:wired'][0]) && 
528
                $this->attributes['media:wired'][0] == 'on' ? 1 : 0;        
529
        $credentialapplicability = new \core\DeviceXMLmain();
530
        $ieee80211s = [];
531
        foreach ($ssids as $ssid) {
532
            $ieee80211 = new \core\DeviceXMLmain();
533
            $ieee80211->setChild('SSID', $ssid);
534
            $ieee80211->setChild('MinRSNProto', 'CCMP');
535
            $ieee80211s[] = $ieee80211;
536
        }
537
        foreach ($oids as $oid) {
538
            $ieee80211 = new \core\DeviceXMLmain();
539
            $ieee80211->setChild('ConsortiumOID', $oid);
540
            $ieee80211s[] = $ieee80211;
541
        }
542
        $credentialapplicability->setChild('IEEE80211', $ieee80211s);
543
        if ($setWired) {
544
            $credentialapplicability->setChild('IEEE8023', '');
545
        }
546
        return $credentialapplicability;
547
    }
548
549
    /**
550
     * retrieves the parameters needed for the given EAP method and creates
551
     * appropriate nodes in the XML structure for them
552
     * 
553
     * @param array $eap the EAP type in question
554
     * @return array a recap of the findings
555
     */
556
    private function getAuthenticationMethodParams($eap)
557
    {
558
        $inner = $this->innerAuth($eap);
559
        $outerMethod = $eap["OUTER"];
560
561
        if (isset($inner["METHOD"]) && $inner["METHOD"]) {
562
            $innerauthmethod = new \core\DeviceXMLmain();
563
            $typeOfInner = ($inner["EAP"] ? 'EAPMethod' : 'NonEAPAuthMethod');
564
            $eapmethod = new \core\DeviceXMLmain();
565
            $eapmethod->setChild('Type', abs($inner['METHOD']));
566
            $innerauthmethod->setChild($typeOfInner, $eapmethod);
567
            return ['inner_method' => $innerauthmethod, 'methodID' => $outerMethod, 'inner_methodID' => $inner['METHOD']];
568
        } else {
569
            return ['inner_method' => 0, 'methodID' => $outerMethod, 'inner_methodID' => 0];
570
        }
571
    }
572
573
    /**
574
     * sets the server-side credentials for a given EAP type
575
     * 
576
     * @param \devices\XML\Type $eaptype the EAP type
0 ignored issues
show
Bug introduced by
The type devices\XML\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
577
     * @return \core\DeviceXMLmain
578
     */
579
    private function getServerSideCredentials($eap)
580
    {
581
        $attr = $this->attributes;
582
        $children = $this->authMethodElements['server'][$eap];
583
        $serversidecredential = new \core\DeviceXMLmain();
584
// Certificates and server names
585
        $cAlist = [];
586
        $attrCaList = $attr['internal:CAs'][0];
587
        foreach ($attrCaList as $ca) {
588
            /* possibly we will want to stop sending server certificates in the future
589
            if ($ca['full_details']['type'] == 'server') {
590
                continue;
591
            }
592
             * 
593
             */
594
            $caObject = new \core\DeviceXMLmain();
595
            $caObject->setValue(base64_encode($ca['der']));
596
            $caObject->setAttributes(['format' => 'X.509', 'encoding' => 'base64']);
597
            $cAlist[] = $caObject;
598
        }
599
        $serverids = [];
600
        $servers = $attr['eap:server_name'];
601
        foreach ($servers as $server) {
602
            $serverid = new \core\DeviceXMLmain();
603
            $serverid->setValue($server);
604
            $serverids[] = $serverid;
605
        }
606
        if (in_array('CA', $children)) {
607
            $serversidecredential->setChild('CA', $cAlist);
608
        }
609
        if (in_array('ServerID', $children)) {
610
            $serversidecredential->setChild('ServerID', $serverids);
611
        }
612
        return $serversidecredential;
613
    }
614
615
    /**
616
     * sets the realm information for the client-side credential
617
     * 
618
     * @param \core\DeviceXMLmain $clientsidecredential the ClientSideCredential to which the realm info is to be added
619
     * @return void
620
     */
621
    private function setClientSideRealm($clientsidecredential)
622
    {
623
        $attr = $this->attributes;
624
        $realm = \core\common\Entity::getAttributeValue($attr, 'internal:realm', 0);
625
        if ($realm === NULL) {
626
            return;
627
        }
628
        if (\core\common\Entity::getAttributeValue($attr, 'internal:verify_userinput_suffix', 0) !== 1) {
629
            return;
630
        }
631
        $clientsidecredential->setChild('InnerIdentitySuffix', $realm);
632
        if (\core\common\Entity::getAttributeValue($attr, 'internal:hint_userinput_suffix', 0) === 1) {
633
            $clientsidecredential->setChild('InnerIdentityHint', 'true');
634
        }
635
    }
636
637
    /**
638
     * sets the client certificate
639
     * 
640
     * @return \core\DeviceXMLmain
641
     */
642
    private function getClientCertificate()
643
    {
644
        $clientCertificateObject = new \core\DeviceXMLmain();
645
        $clientCertificateObject->setValue(base64_encode($this->clientCert["certdata"]));
646
        $clientCertificateObject->setAttributes(['format' => 'PKCS12', 'encoding' => 'base64']);
647
        return $clientCertificateObject;
648
    }
649
650
    /**
651
     * sets the client-side credentials for the given EAP type
652
     * 
653
     * @param array $eapParams the EAP parameters
654
     * @return \core\DeviceXMLmain
655
     */
656
    private function getClientSideCredentials($eap)
657
    {
658
        $children = $this->authMethodElements['client'][$eap];
659
        $clientsidecredential = new \core\DeviceXMLmain();
660
        $outerId = $this->determineOuterIdString();
661
        $this->loggerInstance->debug(5, $eap, "XMLOI:", "\n");
662
        if (in_array('OuterIdentity', $children)) {
663
            if ($outerId !== NULL) {
664
                $clientsidecredential->setChild('OuterIdentity', $outerId);
665
            }
666
        }
667
        $this->setClientSideRealm($clientsidecredential);
668
//        $clientsidecredential->setChild('EAPType', $eapParams['inner_methodID'] ? $eapParams['inner_methodID'] : $eapParams['methodID']);
669
670
        // Client Certificate
671
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
672
            $attr = $this->attributes;
673
            $outerId = \core\common\Entity::getAttributeValue($attr, 'internal:username', 0);
674
            $clientsidecredential->setChild('OuterIdentity', $outerId);
675
            $clientsidecredential->setChild('ClientCertificate', $this->getClientCertificate());
676
        }
677
        return $clientsidecredential;
678
    }
679
680
    /**
681
     * sets the EAP method
682
     * 
683
     * @param \devices\XML\Type $eaptype the EAP type XMLObject
684
     * @return \core\DeviceXMLmain
685
     */
686
    private function getEapMethod($eaptype)
687
    {
688
        $eapmethod = new \core\DeviceXMLmain();
689
        $eapmethod->setChild('Type', $eaptype);
690
        if (isset($this->VendorSpecific)) {
691
            $vendorspecifics = [];
692
            foreach ($this->VendorSpecific as $vs) {
693
                $vendorspecific = new \core\DeviceXMLmain();
694
                $vs['value']->addAttribute('xsi:noNamespaceSchemaLocation', "xxx.xsd");
695
                $vendorspecific->setValue($vs['value']);
696
                $vendorspecific->setAttributes(['vendor' => $vs['vendor']]);
697
                $vendorspecifics[] = $vendorspecific;
698
            }
699
            $eapmethod->setChild('VendorSpecific', $vendorspecifics);
700
        }
701
        return($eapmethod);
702
    }
703
704
    /**
705
     * determines the authentication method to use
706
     * 
707
     * @param array $eap the EAP methods, in array representation
708
     * @return \core\DeviceXMLmain
709
     */
710
    private function getAuthMethod($eap)
711
    {
712
        $authmethod = new \core\DeviceXMLmain();
713
        $eapParams = $this->getAuthenticationMethodParams($eap);
714
        $eaptype = new \core\DeviceXMLmain();
715
        $eaptype->setValue($eapParams['methodID']);
716
// Type
717
        $authmethod->setChild('EAPMethod', $this->getEapMethod($eaptype));
718
719
// ServerSideCredentials
720
        $authmethod->setChild('ServerSideCredential', $this->getServerSideCredentials($eap['OUTER']));
721
722
// ClientSideCredentials
723
        $authmethod->setChild('ClientSideCredential', $this->getClientSideCredentials($eap['INNER']));
724
725
        if ($eapParams['inner_method']) {
726
            $authmethod->setChild('InnerAuthenticationMethod', $eapParams['inner_method']);
727
        }
728
        return $authmethod;
729
    }
730
    
731
    private function getAuthMethodsList() {
732
        $methodList = [];
733
        if ($this->allEaps) {
734
            $eapmethods = [];
735
            foreach ($this->attributes['all_eaps'] as $eap) {
736
                $eapRep = $eap->getArrayRep();
737
                if (in_array($eapRep, $this->supportedEapMethods)) {
738
                    $eapmethods[] = $eapRep;
739
                }
740
            }
741
        } else {
742
            $eapmethods = [$this->selectedEap];
743
        }
744
        foreach ($eapmethods as $eap) {
745
            $methodList[] = $this->getAuthMethod($eap);
746
        }
747
        return $methodList;
748
    }
749
    
750
    private $openRoamingToUArray;
751
    private $openRoamingToU;
752
    private $addORtou = false;
753
754
}
755