Passed
Branch master (1136d4)
by Stefan
05:08
created

Device_W8_10   C

Complexity

Total Complexity 75

Size/Duplication

Total Lines 533
Duplicated Lines 14.45 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 77
loc 533
rs 5.5056
c 0
b 0
f 0
wmc 75
lcom 1
cbo 4

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
D writeInstaller() 0 54 11
A setAuthorId() 0 12 3
A eapConfigHeader() 0 14 1
A tlsServerValidation() 15 15 3
A msTtlsServerValidation() 15 15 3
A glTtlsServerValidation() 0 18 2
A peapServerValidation() 0 14 3
B tlsConfig() 0 25 2
B msTtlsConfig() 9 34 4
B glTtlsConfig() 7 40 3
B peapConfig() 7 42 4
A pwdConfig() 0 3 1
D prepareEapConfig() 0 34 9
A writeWLANprofile() 0 49 3
B writeLANprofile() 0 25 2
B writeProfilesNSH() 24 24 6
C writeMainNSH() 0 38 7
A copyStandardNsi() 0 5 2
B copyFiles() 0 20 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Device_W8_10 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Device_W8_10, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * ******************************************************************************
5
 * Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1
6
 * and GN4-2 consortia
7
 *
8
 * License: see the web/copyright.php file in the file structure
9
 * ******************************************************************************
10
 */
11
12
/**
13
 * This file creates MS Windows 8 installers
14
 * It supports EAP-TLS, TTLS, PEAP and EAP-pwd
15
 * @author Tomasz Wolniewicz <[email protected]>
16
 *
17
 * @package ModuleWriting
18
 */
19
20
namespace devices\ms;
21
use \Exception;
22
23
/**
24
 *
25
 * @author Tomasz Wolniewicz <[email protected]>
26
 * @package ModuleWriting
27
 */
28
 class Device_W8_10 extends WindowsCommon {
29
    final public function __construct() {
30
        parent::__construct();
31
        $this->setSupportedEapMethods(
32
                [
33
                    \core\common\EAP::EAPTYPE_TLS,
34
                    \core\common\EAP::EAPTYPE_PEAP_MSCHAP2,
35
                    \core\common\EAP::EAPTYPE_TTLS_PAP,
36
                    \core\common\EAP::EAPTYPE_TTLS_MSCHAP2,
37
                    \core\common\EAP::EAPTYPE_PWD,
38
                    \core\common\EAP::EAPTYPE_SILVERBULLET
39
                ]);
40
        $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.");
41
    }
42
    public function writeInstaller() {
43
        $dom = textdomain(NULL);
44
        textdomain("devices");
45
        // create certificate files and save their names in $caFiles arrary
46
        $caFiles = $this->saveCertificateFiles('der');
47
        $this->caArray = $this->attributes['internal:CAs'][0];
48
        $this->useAnon = $this->attributes['internal:use_anon_outer'] [0] === NULL ? FALSE : TRUE;
49
        $this->servers = implode(';', $this->attributes['eap:server_name']);
50
        $allSSID = $this->attributes['internal:SSID'];
51
        $delSSIDs = $this->attributes['internal:remove_SSID'];
52
        $this->prepareInstallerLang();
53
        $setWired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
54
//   create a list of profiles to be deleted after installation
55
        $delProfiles = [];
56
        foreach ($delSSIDs as $ssid => $cipher) {
57
            if ($cipher == 'DEL') {
58
                $delProfiles[] = $ssid;
59
            }
60
            if ($cipher == 'TKIP') {
61
                $delProfiles[] = $ssid . ' (TKIP)';
62
            }
63
        }
64
        $windowsProfile = [];
65
        $eapConfig = $this->prepareEapConfig();
66
        $iterator = 0;
67
        foreach ($allSSID as $ssid => $cipher) {
68
            if ($cipher == 'TKIP') {
69
                $windowsProfile[$iterator] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eapConfig, $iterator);
70
                $iterator++;
71
            }
72
            $windowsProfile[$iterator] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eapConfig, $iterator);
73
            $iterator++;
74
        }
75
        if ($setWired) {
76
            $this->writeLANprofile($eapConfig);
77
        }
78
        $this->loggerInstance->debug(4, "windowsProfile");
79
        $this->loggerInstance->debug(4, print_r($windowsProfile, true));
80
81
        $this->writeProfilesNSH($windowsProfile, $caFiles);
82
        $this->writeAdditionalDeletes($delProfiles);
83
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
84
            $this->writeClientP12File();
85
        }
86
        $this->copyFiles($this->selectedEap);
87
        $fedLogo = $this->attributes['fed:logo_file'] ?? NULL;
88
        $idpLogo = $this->attributes['internal:logo_file'] ?? NULL;
89
        $this->combineLogo($idpLogo, $fedLogo);
90
        $this->writeMainNSH($this->selectedEap, $this->attributes);
91
        $this->compileNSIS();
92
        $installerPath = $this->signInstaller();
93
        textdomain($dom);
94
        return($installerPath);
95
    }
96
97
    private function setAuthorId() {
98
        if ($this->selectedEap['OUTER'] === \core\common\EAP::TTLS) {
99
            if ($this->useGeantLink) {
100
                $authorId = "67532";
101
            } else {
102
                $authorId = "311";
103
            }
104
        } else {
105
            $authorId = 0;
106
        }
107
        return($authorId);
108
    }
109
110
    private function eapConfigHeader() {
111
        $authorId = $this->setAuthorId();
112
        $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
113
<EapMethod>
114
';
115
        $profileFileCont .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' .
116
                $this->selectedEap["OUTER"] . '</Type>
117
<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
118
<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
119
<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId>
120
</EapMethod>
121
';
122
        return($profileFileCont);
123
    }
124
125 View Code Duplication
    private function tlsServerValidation() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
        $profileFileCont = '
127
<eapTls:ServerValidation>
128
<eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation>
129
';
130
        $profileFileCont .= '<eapTls:ServerNames>' . $this->servers . '</eapTls:ServerNames>';
131
        foreach ($this->caArray as $certAuthority) {
132
            if ($certAuthority['root']) {
133
                $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n";
134
            }
135
        }
136
        $profileFileCont .= '</eapTls:ServerValidation>
137
';
138
        return($profileFileCont);
139
    }
140
    
141 View Code Duplication
    private function msTtlsServerValidation() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
        $profileFileCont = '
143
        <ServerValidation>
144
';
145
        $profileFileCont .= '<ServerNames>' . $this->servers . '</ServerNames> ';
146
        foreach ($this->caArray as $certAuthority) {
147
            if ($certAuthority['root']) {
148
                $profileFileCont .= "<TrustedRootCAHash>" . chunk_split($certAuthority['sha1'], 2, ' ') . "</TrustedRootCAHash>\n";
149
            }
150
        }
151
        $profileFileCont .= '<DisablePrompt>true</DisablePrompt>
152
</ServerValidation>
153
';
154
        return($profileFileCont);
155
    }
156
    
157
    private function glTtlsServerValidation() {
158
        $servers = implode('</ServerName><ServerName>', $this->attributes['eap:server_name']);
159
        $profileFileCont = '
160
<ServerSideCredential>
161
';
162
        foreach ($this->caArray as $ca) {
163
            $profileFileCont .= '<CA><format>PEM</format><cert-data>';
164
            $profileFileCont .= base64_encode($ca['der']);
165
            $profileFileCont .= '</cert-data></CA>
166
';
167
        }
168
        $profileFileCont .= "<ServerName>$servers</ServerName>\n";
169
170
        $profileFileCont .= '
171
</ServerSideCredential>
172
';
173
        return($profileFileCont);
174
    }
175
    
176
    private function peapServerValidation() {
177
        $profileFileCont = '
178
        <ServerValidation>
179
<DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation>
180
<ServerNames>' . $this->servers . '</ServerNames>';
181
        foreach ($this->caArray as $certAuthority) {
182
            if ($certAuthority['root']) {
183
                $profileFileCont .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n";
184
            }
185
        }
186
        $profileFileCont .= '</ServerValidation>
187
';
188
        return($profileFileCont);
189
    }
190
    
191
    private function tlsConfig() {
192
        $profileFileCont = '
193
<Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"
194
  xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
195
<baseEap:Eap>
196
<baseEap:Type>13</baseEap:Type>
197
<eapTls:EapType>
198
<eapTls:CredentialsSource>
199
<eapTls:CertificateStore />
200
</eapTls:CredentialsSource>
201
';    
202
        $profileFileCont .= $this->tlsServerValidation();
203
        if (\core\common\Entity::getAttributeValue($this->attributes, 'eap-specific:tls_use_other_id', 0) === 'on') {
204
            $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
205
            $this->tlsOtherUsername = 1;
206
        } else {
207
            $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
208
        }
209
        $profileFileCont .= '
210
</eapTls:EapType>
211
</baseEap:Eap>
212
</Config>
213
';
214
        return($profileFileCont);
215
    }
216
217
    private function msTtlsConfig() {        
218
        $profileFileCont = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
219
<EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1">
220
';
221
        $profileFileCont .= $this->msTtlsServerValidation();
222
        $profileFileCont .= '<Phase2Authentication>
223
';
224
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP) {
225
            $profileFileCont .= '<PAPAuthentication /> ';
226
        }
227
        if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) {
228
            $profileFileCont .= '<MSCHAPv2Authentication>
229
<UseWinlogonCredentials>false</UseWinlogonCredentials>
230
</MSCHAPv2Authentication>
231
';
232
        }
233
        $profileFileCont .= '</Phase2Authentication>
234
<Phase1Identity>
235
';
236 View Code Duplication
        if ($this->useAnon) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
            $profileFileCont .= '<IdentityPrivacy>true</IdentityPrivacy>
238
';
239
            $profileFileCont .= '<AnonymousIdentity>' . $this->outerId . '</AnonymousIdentity>
240
                ';
241
        } else {
242
            $profileFileCont .= '<IdentityPrivacy>false</IdentityPrivacy>
243
';
244
        }
245
        $profileFileCont .= '</Phase1Identity>
246
</EapTtls>
247
</Config>
248
';
249
        return($profileFileCont);
250
    }
251
    
252
    private function glTtlsConfig() {        
253
        $profileFileCont = '
254
<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
255
<EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata">
256
<EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID">
257
258
<ProviderInfo>
259
<DisplayName>' . $this->translateString($this->attributes['general:instname'][0], $this->codePage) . '</DisplayName>
260
</ProviderInfo>
261
<AuthenticationMethods>
262
<AuthenticationMethod>
263
<EAPMethod>21</EAPMethod>
264
<ClientSideCredential>
265
<allow-save>true</allow-save>
266
';
267 View Code Duplication
        if ($this->useAnon) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
            if ($this->outerUser == '') {
269
                $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>';
270
            } else {
271
                $profileFileCont .= '<AnonymousIdentity>' . $this->outerId . '</AnonymousIdentity>';
272
            }
273
        }
274
        $profileFileCont .= '</ClientSideCredential>
275
';
276
        $profileFileCont .= $this->glTtlsServerValidation();
277
        $profileFileCont .= '
278
<InnerAuthenticationMethod>
279
<NonEAPAuthMethod>' . \core\common\EAP::eapDisplayName($this->selectedEap)['INNER'] . '</NonEAPAuthMethod>
280
</InnerAuthenticationMethod>
281
<VendorSpecific>
282
<SessionResumption>false</SessionResumption>
283
</VendorSpecific>
284
</AuthenticationMethod>
285
</AuthenticationMethods>
286
</EAPIdentityProvider>
287
</EAPIdentityProviderList>
288
</Config>
289
';
290
        return($profileFileCont);
291
    }
292
293
    private function peapConfig() {
294
        $nea = (\core\common\Entity::getAttributeValue($this->attributes, 'media:wired', 0) == 'on') ? 'true' : 'false';
295
        $profileFileCont = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
296
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
297
<Type>25</Type>
298
<EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1">
299
';
300
        $profileFileCont .= $this->peapServerValidation();
301
        $profileFileCont .= '
302
<FastReconnect>true</FastReconnect>
303
<InnerEapOptional>false</InnerEapOptional>
304
<Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1">
305
<Type>26</Type>
306
<EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
307
<UseWinLogonCredentials>false</UseWinLogonCredentials>
308
</EapType>
309
</Eap>
310
<EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks>
311
<RequireCryptoBinding>false</RequireCryptoBinding>
312
';
313
        if ($this->useAnon) {
314
            $profileFileCont .= '<PeapExtensions>
315
<IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2">
316
<EnableIdentityPrivacy>true</EnableIdentityPrivacy>
317
';
318 View Code Duplication
            if ($this->outerUser == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
319
                $profileFileCont .= '<AnonymousUserName/>
320
';
321
            } else {
322
                $profileFileCont .= '<AnonymousUserName>' . $this->outerUser . '</AnonymousUserName>
323
                ';
324
            }
325
            $profileFileCont .= '</IdentityPrivacy>
326
</PeapExtensions>
327
';
328
        }
329
        $profileFileCont .= '</EapType>
330
</Eap>
331
</Config>
332
';
333
        return($profileFileCont);
334
    }
335
    
336
    private function pwdConfig() {
337
        return('<ConfigBlob></ConfigBlob>');
338
    }
339
340
    private function prepareEapConfig() {
341
        if ($this->useAnon) {
342
            $this->outerUser = $this->attributes['internal:anon_local_value'][0];
343
            $this->outerId = $this->outerUser . '@' . $this->attributes['internal:realm'][0];
344
        }
345
        if (isset($this->options['args']) && $this->options['args'] == 'gl') {
346
            $this->useGeantLink = TRUE;
347
        } else {
348
            $this->useGeantLink = FALSE;
349
        }
350
        $profileFileCont = $this->eapConfigHeader();
351
352
        switch ($this->selectedEap['OUTER']) {
353
            case \core\common\EAP::TLS:
354
                $profileFileCont .= $this->tlsConfig();
355
                break;
356
            case \core\common\EAP::PEAP:
357
                $profileFileCont .= $this->peapConfig();
358
                break;
359
            case \core\common\EAP::TTLS:
360
                if ($this->useGeantLink) {
361
                    $profileFileCont .= $this->glTtlsConfig();
362
                } else {
363
                    $profileFileCont .= $this->msTtlsConfig();
364
                }
365
                break;
366
            case \core\common\EAP::PWD:
367
                $profileFileCont .= $this->pwdConfig();
368
                break;
369
            default:
370
                break;
371
        }
372
        return(['win' => $profileFileCont . '</EapHostConfig></EAPConfig>']);
373
    }
374
375
    /**
376
     * produce PEAP, TLS and TTLS configuration files for Windows 8
377
     *
378
     * @param string $wlanProfileName
379
     * @param string $ssid
380
     * @param string $auth can be one of "WPA", "WPA2"
381
     * @param string $encryption can be one of: "TKIP", "AES"
382
     * @param array $eapConfig XML configuration block with EAP config data
383
     * @param int $profileNumber counter, which profile number is this
384
     * @return string
385
     */
386
    private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) {
387
        $profileFileCont = '<?xml version="1.0"?>
388
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
389
<name>' . $wlanProfileName . '</name>
390
<SSIDConfig>
391
<SSID>
392
<name>' . $ssid . '</name>
393
</SSID>
394
<nonBroadcast>true</nonBroadcast>
395
</SSIDConfig>
396
<connectionType>ESS</connectionType>
397
<connectionMode>auto</connectionMode>
398
<autoSwitch>false</autoSwitch>
399
<MSM>
400
<security>
401
<authEncryption>
402
<authentication>' . $auth . '</authentication>
403
<encryption>' . $encryption . '</encryption>
404
<useOneX>true</useOneX>
405
</authEncryption>
406
';
407
        if ($auth == 'WPA2') {
408
            $profileFileCont .= '<PMKCacheMode>enabled</PMKCacheMode>
409
<PMKCacheTTL>720</PMKCacheTTL>
410
<PMKCacheSize>128</PMKCacheSize>
411
<preAuthMode>disabled</preAuthMode>
412
        ';
413
        }
414
        $profileFileCont .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
415
<cacheUserData>true</cacheUserData>
416
<authMode>user</authMode>
417
';
418
419
        $closing = '
420
</OneX>
421
</security>
422
</MSM>
423
</WLANProfile>
424
';
425
426
        if (!is_dir('w8')) {
427
            mkdir('w8');
428
        }
429
        $xmlFname = "w8/wlan_prof-$profileNumber.xml";
430
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
431
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
432
        $this->loggerInstance->debug(4, "WWWWLAN_Profile:$wlanProfileName:$encryption\n");
433
        return("\"$wlanProfileName\" \"$encryption\"");
434
    }
435
436
    private function writeLANprofile($eapConfig) {
437
        $profileFileCont = '<?xml version="1.0"?>
438
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
439
<MSM>
440
<security>
441
<OneXEnforced>false</OneXEnforced>
442
<OneXEnabled>true</OneXEnabled>
443
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
444
<cacheUserData>true</cacheUserData>
445
<authMode>user</authMode>
446
';
447
        $closing = '
448
</OneX>
449
</security>
450
</MSM>
451
</LANProfile>
452
';
453
454
        if (!is_dir('w8')) {
455
            mkdir('w8');
456
        }
457
        $xmlFname = "w8/lan_prof.xml";
458
        file_put_contents($xmlFname, $profileFileCont . $eapConfig['win'] . $closing);
459
        $this->loggerInstance->debug(2, "Installer has been written into directory $this->FPATH\n");
460
    }
461
462 View Code Duplication
    private function writeProfilesNSH($wlanProfiles, $caArray) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
463
        $this->loggerInstance->debug(4, "writeProfilesNSH");
464
        $this->loggerInstance->debug(4, $wlanProfiles);
465
        $fcontentsProfile = '';
466
        foreach ($wlanProfiles as $wlanProfile) {
467
            $fcontentsProfile .= "!insertmacro define_wlan_profile $wlanProfile\n";
468
        }
469
470
        file_put_contents('profiles.nsh', $fcontentsProfile);
471
472
        $fcontentsCerts = '';
473
        $fileHandleCerts = fopen('certs.nsh', 'w');
474
        if ($fileHandleCerts === FALSE) {
475
            throw new Exception("Unable to open new certs.nsh file for writing CAs.");
476
        }
477
        if ($caArray) {
478
            foreach ($caArray as $certAuthority) {
479
                $store = $certAuthority['root'] ? "root" : "ca";
480
                $fcontentsCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n";
481
            }
482
            fwrite($fileHandleCerts, $fcontentsCerts);
483
        }
484
        fclose($fileHandleCerts);
485
    }
486
487
    private function writeMainNSH($eap, $attr) {
488
        $this->loggerInstance->debug(4, "writeMainNSH");
489
        $this->loggerInstance->debug(4, $attr);
490
        $this->loggerInstance->debug(4, "Device_id = " . $this->device_id . "\n");
491
        $fcontents = "!define W8\n";
492
        if ($this->device_id == 'w10') {
493
            $fcontents .= "!define W10\n";
494
        }
495
        if (CONFIG_CONFASSISTANT['NSIS_VERSION'] >= 3) {
496
            $fcontents .= "Unicode true\n";
497
        }
498
        $eapOptions = [
499
            \core\common\EAP::PEAP => ['str' => 'PEAP', 'exec' => 'user'],
500
            \core\common\EAP::TLS => ['str' => 'TLS', 'exec' => 'user'],
501
            \core\common\EAP::TTLS => ['str' => 'TTLS', 'exec' => 'user'],
502
            \core\common\EAP::PWD => ['str' => 'PWD', 'exec' => 'user'],
503
        ];
504
        if (isset($this->options['args']) && $this->options['args'] == 'gl') {
505
            $eapOptions[\core\common\EAP::TTLS]['str'] = 'GEANTLink';
506
        }
507
508
// Uncomment the line below if you want this module to run under XP (only displaying a warning)
509
// $fcontents .= "!define ALLOW_XP\n";
510
// Uncomment the line below if you want this module to produce debugging messages on the client
511
// $fcontents .= "!define DEBUG_CAT\n";
512
        if ($this->tlsOtherUsername == 1) {
513
            $fcontents .= "!define PFX_USERNAME\n";
514
        }
515
        $execLevel = $eapOptions[$eap["OUTER"]]['exec'];
516
        $eapStr = $eapOptions[$eap["OUTER"]]['str'];
517
        if ($eap == \core\common\EAP::EAPTYPE_SILVERBULLET) {
518
            $fcontents .= "!define SILVERBULLET\n";
519
        }
520
        $fcontents .= '!define ' . $eapStr;
521
        $fcontents .= "\n" . '!define EXECLEVEL "' . $execLevel . '"';
522
        $fcontents .= $this->writeNsisDefines($attr);
523
        file_put_contents('main.nsh', $fcontents);
524
    }
525
526
    private function copyStandardNsi() {
527
        if (!$this->translateFile('eap_w8.inc', 'cat.NSI', $this->codePage)) {
528
            throw new Exception("Translating needed file eap_w8.inc failed!");
529
        }
530
    }
531
532
    private function copyFiles($eap) {
533
        $this->loggerInstance->debug(4, "copyFiles start\n");
534
        $this->copyBasicFiles();
535
        switch ($eap["OUTER"]) {
536
            case \core\common\EAP::TTLS:
537
                if (isset($this->options['args']) && $this->options['args'] == 'gl') {
538
                    $this->copyGeantLinkFiles();
539
                } else {
540
                    $this->copyStandardNsi();
541
                }
542
                break;
543
            case \core\common\EAP::PWD:
544
                $this->copyPwdFiles();
545
                break;
546
            default:
547
                $this->copyStandardNsi();
548
        }
549
        $this->loggerInstance->debug(4, "copyFiles end\n");
550
        return TRUE;
551
    }
552
553
    private $tlsOtherUsername = 0;
554
    private $caArray;
555
    private $useAnon;
556
    private $servers;
557
    private $outerUser;
558
    private $outerId;
559
560
}
561
562