Test Setup Failed
Push — master ( de37f4...b19653 )
by Tomasz
05:59
created

MsTtlsProfile   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 41
c 1
b 0
f 0
dl 0
loc 79
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhase1Identity() 0 10 2
A getTtlsTustedRoot() 0 5 1
A getTtlsServerValidation() 0 7 1
A __construct() 0 4 1
A getTrustedRootCAHash() 0 8 2
A getConfig() 0 5 1
A getWinlogonCred() 0 4 1
A getPhase2Auth() 0 9 3
A getEapTtls() 0 7 1
1
<?php
2
3
/* 
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace devices\ms;
10
11
class MsTtlsProfile extends MsEapProfile
12
{
13
    const MS_TTLS_NS = 'http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1';
14
15
    public function __construct()
16
    {
17
        $this->type = \core\common\EAP::TTLS;
18
        $this->authorId = 311;
19
    }
20
    
21
    public function getConfig()
22
    {
23
        $element = new \core\DeviceXMLmain();
24
        $element->setChild('EapTtls', $this->getEapTtls(), self::MS_TTLS_NS);
25
        return($element);
26
    }
27
    
28
    private function getEapTtls()
29
    {
30
        $element = new \core\DeviceXMLmain();
31
        $element->setChild('ServerValidation', $this->getTtlsServerValidation());
32
        $element->setChild('Phase2Authentication', $this->getPhase2Auth());
33
        $element->setChild('Phase1Identity', $this->getPhase1Identity());
34
        return($element);
35
    }
36
    
37
    private function getTtlsServerValidation()
38
    {
39
        $element = new \core\DeviceXMLmain();
40
        $element->setChild('ServerNames', $this->serverNames);
41
        $element->setChild('TrustedRootCAHash', $this->getTrustedRootCAHash());
42
        $element->setChild('DisablePrompt', 'true');
43
        return($element);
44
    }
45
    
46
    private function getTrustedRootCAHash()
47
    {
48
        $retArray = [];
49
        foreach ($this->caList as $ca) {
50
            $hash = $ca['sha1'];
51
            $retArray[] = chunk_split($hash, 2, ' ');
52
        }
53
        return($retArray);
54
    }
55
    
56
    private function getPhase2Auth() {
57
        $element = new \core\DeviceXMLmain();
58
        if ($this->innerType == \core\common\EAP::MSCHAP2) {
59
            $element->setChild('MSCHAPv2Authentication', $this->getWinlogonCred());
60
        }
61
        if ($this->innerType == \core\common\EAP::NONE) {
62
            $element->setChild('PAPAuthentication', '');
63
        }
64
        return($element);
65
    }
66
    
67
    private function getWinlogonCred() {
68
        $element = new \core\DeviceXMLmain();
69
        $element->setChild('UseWinlogonCredentials', 'false');
70
        return($element);
71
    }
72
73
    private function getPhase1Identity()
74
    {
75
        $element = new \core\DeviceXMLmain();
76
        if ($this->outerId == NULL) {
77
            $element->setChild('IdentityPrivacy', 'false');
78
        } else {
79
            $element->setChild('IdentityPrivacy', 'true');
80
            $element->setChild('AnonymousIdentity', $this->outerId);
81
        }
82
        return($element);
83
    }
84
    
85
    private function getTtlsTustedRoot($hash)
0 ignored issues
show
Unused Code introduced by
The method getTtlsTustedRoot() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
86
    {
87
        $element = new \core\DeviceXMLmain();
88
        $element->setChild('TrustedRootCAHash', chunk_split($hash, 2, ' '));
89
        return($element);
90
    }    
91
}
92