Hostbased::authenticate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace LibSSH2\Authentication;
3
4
use LibSSH2\Configuration;
5
/**
6
 * Hostbased class.
7
 *
8
 * Public hostkey based authentication.
9
 *
10
 * @package LibSSH2\Authentication
11
 */
12
class Hostbased extends Configuration implements Authentication
13
{
14
    /**
15
     * Username.
16
     *
17
     * @var string
18
     */
19
    protected $username;
20
    
21
    /**
22
     * Hostname.
23
     *
24
     * @var string
25
     */
26
    protected $hostname;
27
    
28
    /**
29
     * Public key file.
30
     *
31
     * @var string
32
     */
33
    protected $pubkeyfile;
34
    
35
    /**
36
     * Private key file.
37
     *
38
     * @var string
39
     */
40
    protected $privkeyfile;
41
42
    /**
43
     * Passphrase.
44
     *
45
     * @var string
46
     */
47
    protected $passphrase;
48
    
49
    /**
50
     * Local username.
51
     *
52
     * @var string
53
     */
54
    protected $local_username;
55
56
    /**
57
     * Constructor.
58
     *
59
     * @param  object $configuration Configuration object
60
     * @return void
61
     */
62
    public function __construct(Configuration $configuration)
63
    {
64
        $this->username = $configuration->get_username();
65
        $this->hostname = $configuration->get_host();
66
        $this->pubkeyfile = $configuration->get_publickey();
67
        $this->privkeyfile = $configuration->get_privatekey();
68
        $this->passphrase = $configuration->get_passphrase();
69
        $this->local_username = $configuration->get_username();
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    final public function authenticate($resource)
76
    {
77
        if (@ssh2_auth_hostbased_file(
78
            $resource,
79
            $this->username,
80
            $this->hostname,
81
            $this->pubkeyfile,
82
            $this->privkeyfile,
83
            $this->passphrase,
84
            $this->local_username
85
        ) === false)
86
        {
87
            throw new \RuntimeException('Hostbased file authentication failed.');
88
        }
89
    }
90
}
91