Test Setup Failed
Push — master ( 5548b8...63dc2d )
by Stefan
16:44
created

DeviceVista7::prepareEapConfig()   F

Complexity

Conditions 31
Paths 672

Size

Total Lines 205
Code Lines 83

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 83
dl 0
loc 205
rs 0.4555
c 0
b 0
f 0
cc 31
nc 672
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 creates MS Windows Vista and MS Windows 7 installers
24
 * It supports EAP-TLS, PEAP and EAP-pwd (with external software)
25
 * @author Tomasz Wolniewicz <[email protected]>
26
 *
27
 * @package ModuleWriting
28
 */
29
/**
30
 * necessary includes
31
 */
32
33
namespace devices\ms;
34
use \Exception;
35
36
class DeviceVista7 extends WindowsCommon {
37
38
    /**
39
     * constructor; tells the world about supported EAP types and device anomalies
40
     */
41
    final public function __construct() {
42
        parent::__construct();
43
        \core\common\Entity::intoThePotatoes();
44
        $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_TLS, \core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_SILVERBULLET]);
45
        $this->loggerInstance->debug(4, "This device supports the following EAP methods: ");
46
        $this->loggerInstance->debug(4, $this->supportedEapMethods);
47
        $this->specialities['internal:use_anon_outer'][serialize(\core\common\EAP::EAPTYPE_PEAP_MSCHAP2)] = _("Anonymous identities do not use the realm as specified in the profile - it is derived from the suffix of the user's username input instead.");
48
        \core\common\Entity::outOfThePotatoes();
49
    }
50
51
    /**
52
     * create the actual installer executable
53
     * 
54
     * @return string filename of the generated installer
55
     *
56
     */
57
    public function writeInstaller() {
58
        $dom = textdomain(NULL);
59
        textdomain("devices");
60
        // create certificate files and save their names in $caFiles arrary
61
        $caFiles = $this->saveCertificateFiles('der');
62
63
        $allSSID = $this->attributes['internal:SSID'];
64
        $delSSIDs = $this->attributes['internal:remove_SSID'];
65
        $this->prepareInstallerLang();
66
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
67
//   create a list of profiles to be deleted after installation
68
        $delProfiles = [];
69
        foreach ($delSSIDs as $ssid => $cipher) {
70
            if ($cipher == 'DEL') {
71
                $delProfiles[] = $ssid;
72
            }
73
            if ($cipher == 'TKIP') {
74
                $delProfiles[] = $ssid . ' (TKIP)';
75
            }
76
        }
77
78
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS || $this->selectedEap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_PWD || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2 || $this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
79
            $windowsProfile = [];
80
            $eapConfig = $this->prepareEapConfig($this->attributes);
81
            $iterator = 0;
82
            foreach ($allSSID as $ssid => $cipher) {
83
                if ($cipher == 'TKIP') {
84
                    $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
85
                    $iterator++;
86
                }
87
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
88
                $iterator++;
89
            }
90
            if ($setWired) {
91
                $this->writeLANprofile($eapConfig);
92
            }
93
        } else {
94
            print("  this EAP type is not handled yet.\n");
95
            return;
96
        }
97
        $this->loggerInstance->debug(4, "windowsProfile");
98
        $this->loggerInstance->debug(4, $windowsProfile);
99
100
        $this->writeProfilesNSH($windowsProfile, $caFiles);
101
        $this->writeAdditionalDeletes($delProfiles);
102
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
103
            $this->writeClientP12File();
104
        }
105
        $this->copyFiles($this->selectedEap);
106
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
107
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
108
        $this->combineLogo($idpLogo, $fedLogo);
109
        $this->writeMainNSH($this->selectedEap, $this->attributes);
110
        $this->compileNSIS();
111
        $installerPath = $this->signInstaller();
112
113
        textdomain($dom);
114
        return($installerPath);
115
    }
116
117
    /**
118
     * creates the XML snippet that describes the EAP configuration
119
     * 
120
     * @param array $attr the attributes for the profile
121
     * @return array two XML snippets describing the EAP configuration, for Vista and 7 respectively
122
     */
123
    private function prepareEapConfig($attr) {
124
        $outerUser = '';
125
        $vistaExt = '';
126
        $w7Ext = '';
127
        $useAnon = isset($attr['internal:use_anon_outer']) && $attr['internal:use_anon_outer'][0] == "1" && isset($attr['internal:realm']) ? TRUE : FALSE;
0 ignored issues
show
Unused Code introduced by
The assignment to $useAnon is dead and can be removed.
Loading history...
128
        $useAnon = $attr['internal:use_anon_outer'] [0];
129
        $realm = $attr['internal:realm'] [0];
130
        if ($useAnon) {
131
            $outerUser = $attr['internal:anon_local_value'][0];
132
        }
133
//   $servers = preg_quote(implode(';',$attr['eap:server_name']));
134
        $servers = implode(';', $attr['eap:server_name']);
135
        $caArray = $attr['internal:CAs'][0];
136
        $authorId = "0";
137
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
138
            $authorId = "67532";
139
            $servers = implode('</ServerName><ServerName>', $attr['eap:server_name']);
140
        }
141
142
        $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
143
<EapMethod>
144
<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' .
145
                $this->selectedEap["OUTER"] . '</Type>
146
<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
147
<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
148
<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId>
149
</EapMethod>
150
';
151
152
153
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
154
            $innerMethod = 'MSCHAPv2';
155
            if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
156
                $innerMethod = 'PAP';
157
            }
158
            $profileFileCont .= '
159
<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
160
<EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata">
161
<EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID">
162
<ProviderInfo>
163
<DisplayName>' . $this->translateString($attr['general:instname'][0], $this->codePage) . '</DisplayName>
164
</ProviderInfo>
165
<AuthenticationMethods>
166
<AuthenticationMethod>
167
<EAPMethod>21</EAPMethod>
168
<ClientSideCredential>
169
<allow-save>true</allow-save>
170
';
171
            if ($useAnon) {
172
                if ($outerUser == '') {
173
                    $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>';
174
                } else {
175
                    $profileFileCont .= '<AnonymousIdentity>' . $outerUser . '@' . $realm . '</AnonymousIdentity>';
176
                }
177
            }
178
            $profileFileCont .= '</ClientSideCredential>
179
<ServerSideCredential>
180
';
181
182
            foreach ($caArray as $ca) {
183
                $profileFileCont .= '<CA><format>PEM</format><cert-data>';
184
                $profileFileCont .= base64_encode($ca['der']);
185
                $profileFileCont .= '</cert-data></CA>
186
';
187
            }
188
            $profileFileCont .= "<ServerName>$servers</ServerName>\n";
189
190
            $profileFileCont .= '
191
</ServerSideCredential>
192
<InnerAuthenticationMethod>
193
<NonEAPAuthMethod>' .$innerMethod. '</NonEAPAuthMethod>
194
</InnerAuthenticationMethod>
195
<VendorSpecific>
196
<SessionResumption>false</SessionResumption>
197
</VendorSpecific>
198
</AuthenticationMethod>
199
</AuthenticationMethods>
200
</EAPIdentityProvider>
201
</EAPIdentityProviderList>
202
</Config>
203
';
204
        } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS || $this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
205
206
            $profileFileCont .= '
207
208
<Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
209
  xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
210
<baseEap:Eap>
211
<baseEap:Type>13</baseEap:Type> 
212
<eapTls:EapType>
213
<eapTls:CredentialsSource>
214
<eapTls:CertificateStore />
215
</eapTls:CredentialsSource>
216
<eapTls:ServerValidation>
217
<eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation>
218
<eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>';
219
            if ($caArray) {
220
                foreach ($caArray as $certAuthority) {
221
                    if ($certAuthority['root']) {
222
                        $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n";
223
                    }
224
                }
225
            }
226
            $profileFileCont .= '</eapTls:ServerValidation>
227
';
228
            if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') {
229
                $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
230
                $this->tlsOtherUsername = 1;
231
            } else {
232
                $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
233
            }
234
            $profileFileCont .= '
235
</eapTls:EapType>
236
</baseEap:Eap>
237
</Config>
238
';
239
        } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) {
240
            if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') {
241
                $nea = 'true';
242
            } else {
243
                $nea = 'false';
244
            }
245
            $vistaExt = '<Config xmlns:eapUser="http://www.microsoft.com/provisioning/EapUserPropertiesV1" 
246
xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
247
  xmlns:msPeap="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1" 
248
  xmlns:msChapV2="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
249
<baseEap:Eap>
250
<baseEap:Type>25</baseEap:Type> 
251
<msPeap:EapType>
252
<msPeap:ServerValidation>
253
<msPeap:DisableUserPromptForServerValidation>true</msPeap:DisableUserPromptForServerValidation> 
254
<msPeap:ServerNames>' . $servers . '</msPeap:ServerNames>';
255
            if ($caArray) {
256
                foreach ($caArray as $certAuthority) {
257
                    if ($certAuthority['root']) {
258
                        $vistaExt .= "<msPeap:TrustedRootCA>" . $certAuthority['sha1'] . "</msPeap:TrustedRootCA>\n";
259
                    }
260
                }
261
            }
262
            $vistaExt .= '</msPeap:ServerValidation>
263
<msPeap:FastReconnect>true</msPeap:FastReconnect> 
264
<msPeap:InnerEapOptional>0</msPeap:InnerEapOptional> 
265
<baseEap:Eap>
266
<baseEap:Type>26</baseEap:Type>
267
<msChapV2:EapType>
268
<msChapV2:UseWinLogonCredentials>false</msChapV2:UseWinLogonCredentials> 
269
</msChapV2:EapType>
270
</baseEap:Eap>
271
<msPeap:EnableQuarantineChecks>' . $nea . '</msPeap:EnableQuarantineChecks>
272
<msPeap:RequireCryptoBinding>false</msPeap:RequireCryptoBinding>
273
</msPeap:EapType>
274
</baseEap:Eap>
275
</Config>
276
';
277
            $w7Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
278
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
279
<Type>25</Type>
280
<EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1">
281
<ServerValidation>
282
<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
283
<ServerNames>' . $servers . '</ServerNames>';
284
            if ($caArray) {
285
                foreach ($caArray as $certAuthority) {
286
                    if ($certAuthority['root']) {
287
                        $w7Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
288
                    }
289
                }
290
            }
291
            $w7Ext .= '</ServerValidation>
292
<FastReconnect>true</FastReconnect> 
293
<InnerEapOptional>false</InnerEapOptional> 
294
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
295
<Type>26</Type>
296
<EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
297
<UseWinLogonCredentials>false</UseWinLogonCredentials> 
298
</EapType>
299
</Eap>
300
<EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks>
301
<RequireCryptoBinding>false</RequireCryptoBinding>
302
';
303
            if ($useAnon) {
304
                $w7Ext .= '<PeapExtensions>
305
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
306
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
307
<AnonymousUserName>' . $outerUser . '</AnonymousUserName>
308
</IdentityPrivacy>
309
</PeapExtensions>
310
            ';
311
            }
312
            $w7Ext .= '</EapType>
313
</Eap>
314
</Config>
315
';
316
        } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_PWD) {
317
            $profileFileCont .= '<ConfigBlob></ConfigBlob>';
318
        }
319
320
321
322
        $profileFileContEnd = '</EapHostConfig></EAPConfig>
323
';
324
        $returnArray = [];
325
        $returnArray['vista'] = $profileFileCont . $vistaExt . $profileFileContEnd;
326
        $returnArray['w7'] = $profileFileCont . $w7Ext . $profileFileContEnd;
327
        return $returnArray;
328
    }
329
330
    /**
331
     * produce PEAP, TLS and TTLS configuration files for Vista and Windows 7.
332
     * Writes XML snippet into file and returns some meta information
333
     * 
334
     * @param string $wlanProfileName name of the WLAN profile
335
     * @param string $ssid            SSID that is being configured
336
     * @param string $auth            can be one of "WPA", "WPA2"
337
     * @param string $encryption      can be one of: "TKIP", "AES"
338
     * @param array  $eapConfig       XML configuration block with EAP config data (two entries, one for Vista, one for 7)
339
     * @param int    $profileNumber   counter, which profile number is this
340
     * @return string meta info about generated XML snippet
341
     */
342
    private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) {
343
        $profileFileCont = '<?xml version="1.0"?>
344
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
345
<name>' . $wlanProfileName . '</name>
346
<SSIDConfig>
347
<SSID>
348
<name>' . $ssid . '</name>
349
</SSID>
350
<nonBroadcast>true</nonBroadcast>
351
</SSIDConfig>
352
<connectionType>ESS</connectionType>
353
<connectionMode>auto</connectionMode>
354
<autoSwitch>false</autoSwitch>
355
<MSM>
356
<security>
357
<authEncryption>
358
<authentication>' . $auth . '</authentication>
359
<encryption>' . $encryption . '</encryption>
360
<useOneX>true</useOneX>
361
</authEncryption>
362
';
363
        if ($auth == 'WPA2') {
364
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode>
365
<PMKCacheTTL>720</PMKCacheTTL>
366
<PMKCacheSize>128</PMKCacheSize>
367
<preAuthMode>disabled</preAuthMode>
368
';
369
        }
370
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
371
<cacheUserData>true</cacheUserData>
372
<authMode>user</authMode>
373
';
374
375
        $closing = '
376
</OneX>
377
</security>
378
</MSM>
379
</WLANProfile>
380
';
381
382
        if (!is_dir('w7')) {
383
            mkdir('w7');
384
        }
385
        if (!is_dir('vista')) {
386
            mkdir('vista');
387
        }
388
        $vistaFileName = "vista/wlan_prof-$profileNumber.xml";
389
        file_put_contents($vistaFileName, $profileFileCont . $eapConfig['vista'] . $closing);
390
        $sevenFileName = "w7/wlan_prof-$profileNumber.xml";
391
        file_put_contents($sevenFileName, $profileFileCont . $eapConfig['w7'] . $closing);
392
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
393
        $this->loggerInstance->debug(4, "WLAN_Profile:$wlanProfileName:$encryption\n");
394
        return("\"$wlanProfileName\" \"$encryption\"");
395
    }
396
397
    /**
398
     * writes LAN configuration profile into file
399
     * 
400
     * @param array $eapConfig contains XML snippets for Vista and 7 with the EAP configuration
401
     * @return void
402
     */
403
    private function writeLANprofile($eapConfig) {
404
        $profileFileCont = '<?xml version="1.0"?>
405
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
406
<MSM>
407
<security>
408
<OneXEnforced>false</OneXEnforced>
409
<OneXEnabled>true</OneXEnabled>
410
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
411
<cacheUserData>true</cacheUserData>
412
<authMode>user</authMode>
413
';
414
        $closing = '
415
</OneX>
416
</security>
417
</MSM>
418
</LANProfile>
419
';
420
        if (!is_dir('w7')) {
421
            mkdir('w7');
422
        }
423
        if (!is_dir('vista')) {
424
            mkdir('vista');
425
        }
426
        
427
        file_put_contents("vista/lan_prof.xml", $profileFileCont . $eapConfig['vista'] . $closing);
428
        file_put_contents("w7/lan_prof.xml", $profileFileCont . $eapConfig['w7'] . $closing);
429
        
430
    }
431
432
    /**
433
     * writes the main NSH file
434
     * 
435
     * @param array $eap  EAP type that is being configured in array representation
436
     * @param array $attr list of attributes
437
     * @return void
438
     */
439
    private function writeMainNSH($eap, $attr) {
440
        $this->loggerInstance->debug(4, "writeMainNSH");
441
        $this->loggerInstance->debug(4, $attr);
442
        $this->loggerInstance->debug(4, "MYLANG=" . $this->lang . "\n");
443
444
        $eapOptions = [
445
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
446
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
447
// TODO for TW: the following line doesn't work - that constant is an array, which can't be a key for another array
448
// generated a PHP Warning but doesn't seem to have any catastrophic effect?
449
//           \core\common\EAP::EAPTYPE_SILVERBULLET => ['str' => 'TLS', 'exec' => 'user'],
450
            \core\common\EAP::TTLS => ['str' => 'GEANTLink', 'exec' => 'user'],
451
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
452
        ];
453
        $fcontents = '';
454
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
455
            $fcontents .= "Unicode true\n";
456
        }
457
458
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
459
// $fcontents .= "!define ALLOW_XP\n";
460
// Uncomment the line below if you want this module to produce debugging messages on the client
461
// $fcontents .= "!define DEBUG_CAT\n";
462
        if ($this->tlsOtherUsername == 1) {
463
            $fcontents .= "!define PFX_USERNAME\n";
464
        }
465
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
466
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
467
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
468
            $fcontents .= "!define SILVERBULLET\n";
469
        }
470
        $this->loggerInstance->debug(4, "EAP_STR=$eapStr\n");
471
        $this->loggerInstance->debug(4, $eap);
472
473
        $fcontents .= '!define ' . $eapStr;
474
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
475
        $fcontents .= $this->writeNsisDefines($attr);
476
        file_put_contents('main.nsh', $fcontents);
477
    }
478
479
    /**
480
     * writes references to the individual WLAN profile files into master file
481
     * @param array $wlanProfiles list of WLAN profiles
482
     * @param array $caArray      list of CA certificates
483
     * @return void
484
     * @throws Exception
485
     */
486
    private function writeProfilesNSH($wlanProfiles, $caArray) {
487
        $this->loggerInstance->debug(4, "writeProfilesNSH");
488
        $this->loggerInstance->debug(4, $wlanProfiles);
489
        $contentWlan = '';
490
        foreach ($wlanProfiles as $wlanProfile) {
491
            $contentWlan .= "!insertmacro define_wlan_profile $wlanProfile\n";
492
        }
493
494
        file_put_contents('profiles.nsh', $contentWlan);
495
        
496
        $contentCerts = '';
497
        $fileHandleCerts = fopen('certs.nsh', 'w');
498
        if ($fileHandleCerts === FALSE) {
499
            throw new Exception("Unable to open new file certs.nsh to write CAs!");
500
        }
501
        foreach ($caArray as $certAuthority) {
502
            $store = $certAuthority['root'] ? "root" : "ca";
503
            $contentCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
504
        }
505
        fwrite($fileHandleCerts, $contentCerts);
506
        fclose($fileHandleCerts);
507
    }
508
509
    /**
510
     * copies various files into temp dir for inclusion into installer
511
     * 
512
     * @param array $eap EAP type being configured, in array notation
513
     * @return boolean TRUE if things worked (and throws an Exception if not)
514
     * @throws Exception
515
     */
516
    private function copyFiles($eap) {
517
        $this->loggerInstance->debug(4, "copyFiles start\n");
518
        $this->loggerInstance->debug(4, "code_page=" . $this->codePage . "\n");
519
        $this->copyBasicFiles();
520
521
        switch ($eap["OUTER"]) {
522
            case \core\common\EAP::TTLS:
523
                $this->copyGeantLinkFiles();
524
                break;
525
            case \core\common\EAP::PWD:
526
                $this->copyPwdFiles();
527
                break;
528
            default:
529
                if (!$this->translateFile('peap_tls.inc', 'cat.NSI', $this->codePage)) {
530
                    throw new Exception("Translating needed file peap_tls.inc failed!");
531
                }
532
        }
533
        $this->loggerInstance->debug(4, "copyFiles end\n");
534
        return TRUE;
535
    }
536
537
    private $tlsOtherUsername = 0;
538
539
}
540