| Total Complexity | 64 |
| Total Lines | 456 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Device_Vista7 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.
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_Vista7, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class Device_Vista7 extends WindowsCommon { |
||
| 27 | |||
| 28 | final public function __construct() { |
||
| 29 | parent::__construct(); |
||
| 30 | $this->setSupportedEapMethods([\core\common\EAP::EAPTYPE_TLS, \core\common\EAP::EAPTYPE_PEAP_MSCHAP2, \core\common\EAP::EAPTYPE_PWD, \core\common\EAP::EAPTYPE_TTLS_PAP, \core\common\EAP::EAPTYPE_TTLS_MSCHAP2, \core\common\EAP::EAPTYPE_SILVERBULLET]); |
||
| 31 | $this->loggerInstance->debug(4, "This device supports the following EAP methods: "); |
||
| 32 | $this->loggerInstance->debug(4, $this->supportedEapMethods); |
||
| 33 | $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."); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function writeInstaller() { |
||
| 94 | } |
||
| 95 | |||
| 96 | private function prepareEapConfig($attr) { |
||
| 97 | $outerUser = ''; |
||
| 98 | $vistaExt = ''; |
||
| 99 | $w7Ext = ''; |
||
| 100 | $useAnon = $attr['internal:use_anon_outer'] [0]; |
||
| 101 | $realm = $attr['internal:realm'] [0]; |
||
| 102 | if ($useAnon) { |
||
| 103 | $outerUser = $attr['internal:anon_local_value'][0]; |
||
| 104 | } |
||
| 105 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
||
| 106 | $servers = implode(';', $attr['eap:server_name']); |
||
| 107 | $caArray = $attr['internal:CAs'][0]; |
||
| 108 | $authorId = "0"; |
||
| 109 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
| 110 | $authorId = "67532"; |
||
| 111 | $servers = implode('</ServerName><ServerName>', $attr['eap:server_name']); |
||
| 112 | } |
||
| 113 | |||
| 114 | $profileFileCont = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
| 115 | <EapMethod> |
||
| 116 | <Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' . |
||
| 117 | $this->selectedEap["OUTER"] . '</Type> |
||
| 118 | <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> |
||
| 119 | <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> |
||
| 120 | <AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">' . $authorId . '</AuthorId> |
||
| 121 | </EapMethod> |
||
| 122 | '; |
||
| 123 | |||
| 124 | |||
| 125 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP || $this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_MSCHAP2) { |
||
| 126 | $innerMethod = 'MSCHAPv2'; |
||
| 127 | if ($this->selectedEap == \core\common\EAP::EAPTYPE_TTLS_PAP) { |
||
| 128 | $innerMethod = 'PAP'; |
||
| 129 | } |
||
| 130 | $profileFileCont .= ' |
||
| 131 | <Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
| 132 | <EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata"> |
||
| 133 | <EAPIdentityProvider ID="' . $this->deviceUUID . '" namespace="urn:UUID"> |
||
| 134 | <ProviderInfo> |
||
| 135 | <DisplayName>' . $this->translateString($attr['general:instname'][0], $this->codePage) . '</DisplayName> |
||
| 136 | </ProviderInfo> |
||
| 137 | <AuthenticationMethods> |
||
| 138 | <AuthenticationMethod> |
||
| 139 | <EAPMethod>21</EAPMethod> |
||
| 140 | <ClientSideCredential> |
||
| 141 | <allow-save>true</allow-save> |
||
| 142 | '; |
||
| 143 | if ($useAnon == 1) { |
||
| 144 | if ($outerUser == '') { |
||
| 145 | $profileFileCont .= '<AnonymousIdentity>@</AnonymousIdentity>'; |
||
| 146 | } else { |
||
| 147 | $profileFileCont .= '<AnonymousIdentity>' . $outerUser . '@' . $realm . '</AnonymousIdentity>'; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | $profileFileCont .= '</ClientSideCredential> |
||
| 151 | <ServerSideCredential> |
||
| 152 | '; |
||
| 153 | |||
| 154 | foreach ($caArray as $ca) { |
||
| 155 | $profileFileCont .= '<CA><format>PEM</format><cert-data>'; |
||
| 156 | $profileFileCont .= base64_encode($ca['der']); |
||
| 157 | $profileFileCont .= '</cert-data></CA> |
||
| 158 | '; |
||
| 159 | } |
||
| 160 | $profileFileCont .= "<ServerName>$servers</ServerName>\n"; |
||
| 161 | |||
| 162 | $profileFileCont .= ' |
||
| 163 | </ServerSideCredential> |
||
| 164 | <InnerAuthenticationMethod> |
||
| 165 | <NonEAPAuthMethod>' .$innerMethod. '</NonEAPAuthMethod> |
||
| 166 | </InnerAuthenticationMethod> |
||
| 167 | <VendorSpecific> |
||
| 168 | <SessionResumption>false</SessionResumption> |
||
| 169 | </VendorSpecific> |
||
| 170 | </AuthenticationMethod> |
||
| 171 | </AuthenticationMethods> |
||
| 172 | </EAPIdentityProvider> |
||
| 173 | </EAPIdentityProviderList> |
||
| 174 | </Config> |
||
| 175 | '; |
||
| 176 | } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_TLS || $this->selectedEap == \core\common\EAP::EAPTYPE_SILVERBULLET) { |
||
| 177 | |||
| 178 | $profileFileCont .= ' |
||
| 179 | |||
| 180 | <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" |
||
| 181 | xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> |
||
| 182 | <baseEap:Eap> |
||
| 183 | <baseEap:Type>13</baseEap:Type> |
||
| 184 | <eapTls:EapType> |
||
| 185 | <eapTls:CredentialsSource> |
||
| 186 | <eapTls:CertificateStore /> |
||
| 187 | </eapTls:CredentialsSource> |
||
| 188 | <eapTls:ServerValidation> |
||
| 189 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
||
| 190 | <eapTls:ServerNames>' . $servers . '</eapTls:ServerNames>'; |
||
| 191 | if ($caArray) { |
||
| 192 | foreach ($caArray as $certAuthority) { |
||
| 193 | if ($certAuthority['root']) { |
||
| 194 | $profileFileCont .= "<eapTls:TrustedRootCA>" . $certAuthority['sha1'] . "</eapTls:TrustedRootCA>\n"; |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | $profileFileCont .= '</eapTls:ServerValidation> |
||
| 199 | '; |
||
| 200 | if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') { |
||
| 201 | $profileFileCont .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
||
| 202 | $this->tlsOtherUsername = 1; |
||
| 203 | } else { |
||
| 204 | $profileFileCont .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
||
| 205 | } |
||
| 206 | $profileFileCont .= ' |
||
| 207 | </eapTls:EapType> |
||
| 208 | </baseEap:Eap> |
||
| 209 | </Config> |
||
| 210 | '; |
||
| 211 | } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_PEAP_MSCHAP2) { |
||
| 212 | if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') { |
||
| 213 | $nea = 'true'; |
||
| 214 | } else { |
||
| 215 | $nea = 'false'; |
||
| 216 | } |
||
| 217 | $vistaExt = '<Config xmlns:eapUser="http://www.microsoft.com/provisioning/EapUserPropertiesV1" |
||
| 218 | xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" |
||
| 219 | xmlns:msPeap="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1" |
||
| 220 | xmlns:msChapV2="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"> |
||
| 221 | <baseEap:Eap> |
||
| 222 | <baseEap:Type>25</baseEap:Type> |
||
| 223 | <msPeap:EapType> |
||
| 224 | <msPeap:ServerValidation> |
||
| 225 | <msPeap:DisableUserPromptForServerValidation>true</msPeap:DisableUserPromptForServerValidation> |
||
| 226 | <msPeap:ServerNames>' . $servers . '</msPeap:ServerNames>'; |
||
| 227 | if ($caArray) { |
||
| 228 | foreach ($caArray as $certAuthority) { |
||
| 229 | if ($certAuthority['root']) { |
||
| 230 | $vistaExt .= "<msPeap:TrustedRootCA>" . $certAuthority['sha1'] . "</msPeap:TrustedRootCA>\n"; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | $vistaExt .= '</msPeap:ServerValidation> |
||
| 235 | <msPeap:FastReconnect>true</msPeap:FastReconnect> |
||
| 236 | <msPeap:InnerEapOptional>0</msPeap:InnerEapOptional> |
||
| 237 | <baseEap:Eap> |
||
| 238 | <baseEap:Type>26</baseEap:Type> |
||
| 239 | <msChapV2:EapType> |
||
| 240 | <msChapV2:UseWinLogonCredentials>false</msChapV2:UseWinLogonCredentials> |
||
| 241 | </msChapV2:EapType> |
||
| 242 | </baseEap:Eap> |
||
| 243 | <msPeap:EnableQuarantineChecks>' . $nea . '</msPeap:EnableQuarantineChecks> |
||
| 244 | <msPeap:RequireCryptoBinding>false</msPeap:RequireCryptoBinding> |
||
| 245 | </msPeap:EapType> |
||
| 246 | </baseEap:Eap> |
||
| 247 | </Config> |
||
| 248 | '; |
||
| 249 | $w7Ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
||
| 250 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
| 251 | <Type>25</Type> |
||
| 252 | <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> |
||
| 253 | <ServerValidation> |
||
| 254 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
||
| 255 | <ServerNames>' . $servers . '</ServerNames>'; |
||
| 256 | if ($caArray) { |
||
| 257 | foreach ($caArray as $certAuthority) { |
||
| 258 | if ($certAuthority['root']) { |
||
| 259 | $w7Ext .= "<TrustedRootCA>" . $certAuthority['sha1'] . "</TrustedRootCA>\n"; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } |
||
| 263 | $w7Ext .= '</ServerValidation> |
||
| 264 | <FastReconnect>true</FastReconnect> |
||
| 265 | <InnerEapOptional>false</InnerEapOptional> |
||
| 266 | <Eap xmlns="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"> |
||
| 267 | <Type>26</Type> |
||
| 268 | <EapType xmlns="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"> |
||
| 269 | <UseWinLogonCredentials>false</UseWinLogonCredentials> |
||
| 270 | </EapType> |
||
| 271 | </Eap> |
||
| 272 | <EnableQuarantineChecks>' . $nea . '</EnableQuarantineChecks> |
||
| 273 | <RequireCryptoBinding>false</RequireCryptoBinding> |
||
| 274 | '; |
||
| 275 | if ($useAnon == 1) { |
||
| 276 | $w7Ext .= '<PeapExtensions> |
||
| 277 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
||
| 278 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
||
| 279 | <AnonymousUserName>' . $outerUser . '</AnonymousUserName> |
||
| 280 | </IdentityPrivacy> |
||
| 281 | </PeapExtensions> |
||
| 282 | '; |
||
| 283 | } |
||
| 284 | $w7Ext .= '</EapType> |
||
| 285 | </Eap> |
||
| 286 | </Config> |
||
| 287 | '; |
||
| 288 | } elseif ($this->selectedEap == \core\common\EAP::EAPTYPE_PWD) { |
||
| 289 | $profileFileCont .= '<ConfigBlob></ConfigBlob>'; |
||
| 290 | } |
||
| 291 | |||
| 292 | |||
| 293 | |||
| 294 | $profileFileContEnd = '</EapHostConfig></EAPConfig> |
||
| 295 | '; |
||
| 296 | $returnArray = []; |
||
| 297 | $returnArray['vista'] = $profileFileCont . $vistaExt . $profileFileContEnd; |
||
| 298 | $returnArray['w7'] = $profileFileCont . $w7Ext . $profileFileContEnd; |
||
| 299 | return $returnArray; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * produce PEAP, TLS and TTLS configuration files for Vista and Windows 7 |
||
| 304 | * |
||
| 305 | * @param string $wlanProfileName |
||
| 306 | * @param string $ssid |
||
| 307 | * @param string $auth can be one of "WPA", "WPA2" |
||
| 308 | * @param string $encryption can be one of: "TKIP", "AES" |
||
| 309 | * @param array $eapConfig XML configuration block with EAP config data (two entries, one for Vista, one for 7) |
||
| 310 | * @param int $profileNumber counter, which profile number is this |
||
| 311 | * @return string |
||
| 312 | */ |
||
| 313 | private function writeWLANprofile($wlanProfileName, $ssid, $auth, $encryption, $eapConfig, $profileNumber) { |
||
| 366 | } |
||
| 367 | |||
| 368 | private function writeLANprofile($eapConfig) { |
||
| 394 | |||
| 395 | } |
||
| 396 | |||
| 397 | private function writeMainNSH($eap, $attr) { |
||
| 435 | } |
||
| 436 | |||
| 437 | private function writeProfilesNSH($wlanProfiles, $caArray) { |
||
| 438 | $this->loggerInstance->debug(4, "writeProfilesNSH"); |
||
| 439 | $this->loggerInstance->debug(4, $wlanProfiles); |
||
| 440 | $contentWlan = ''; |
||
| 441 | foreach ($wlanProfiles as $wlanProfile) { |
||
| 442 | $contentWlan .= "!insertmacro define_wlan_profile $wlanProfile\n"; |
||
| 443 | } |
||
| 444 | |||
| 445 | file_put_contents('profiles.nsh', $contentWlan); |
||
| 446 | |||
| 447 | $contentCerts = ''; |
||
| 448 | $fileHandleCerts = fopen('certs.nsh', 'w'); |
||
| 449 | if ($fileHandleCerts === FALSE) { |
||
| 450 | throw new Exception("Unable to open new file certs.nsh to write CAs!"); |
||
| 451 | } |
||
| 452 | foreach ($caArray as $certAuthority) { |
||
| 453 | $store = $certAuthority['root'] ? "root" : "ca"; |
||
| 454 | $contentCerts .= '!insertmacro install_ca_cert "' . $certAuthority['file'] . '" "' . $certAuthority['sha1'] . '" "' . $store . "\"\n"; |
||
| 455 | } |
||
| 456 | fwrite($fileHandleCerts, $contentCerts); |
||
| 457 | fclose($fileHandleCerts); |
||
| 458 | } |
||
| 459 | |||
| 460 | private function copyFiles($eap) { |
||
| 479 | } |
||
| 480 | |||
| 481 | private $tlsOtherUsername = 0; |
||
| 482 | |||
| 484 |