1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plasma Driver MySQL component |
4
|
|
|
* Copyright 2018 PlasmaPHP, All Rights Reserved |
5
|
|
|
* |
6
|
|
|
* Website: https://github.com/PlasmaPHP |
7
|
|
|
* License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Plasma\Drivers\MySQL\AuthPlugins; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Defines the interface for auth plugins. |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class AuthSecureConnection implements AuthPluginInterface { |
17
|
|
|
/** |
18
|
|
|
* @var \Plasma\Drivers\MySQL\ProtocolParser |
19
|
|
|
*/ |
20
|
|
|
protected $parser; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Plasma\Drivers\MySQL\Messages\HandshakeMessage |
24
|
|
|
*/ |
25
|
|
|
protected $handshake; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. Receives the protocol parser and the handshake message. |
29
|
|
|
* @param \Plasma\Drivers\MySQL\ProtocolParser $parser |
30
|
|
|
* @param \Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake |
31
|
|
|
*/ |
32
|
15 |
|
function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser, \Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake) { |
33
|
15 |
|
$this->parser = $parser; |
34
|
15 |
|
$this->handshake = $handshake; |
35
|
15 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Computes the auth response, including the length, for the handshake response. |
39
|
|
|
* @param string $password |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
14 |
|
function getHandshakeAuth(string $password): string { |
43
|
14 |
|
if($password !== '') { |
44
|
2 |
|
$hash = \sha1($password, true); |
45
|
2 |
|
$str = $hash ^ \sha1($this->handshake->scramble.\sha1($hash, true), true); |
46
|
|
|
|
47
|
2 |
|
return \Plasma\BinaryBuffer::writeStringLength($str); |
48
|
|
|
} |
49
|
|
|
|
50
|
12 |
|
return "\x00"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* We received more auth data, so we send it into the auth plugin. |
55
|
|
|
* @param \Plasma\Drivers\MySQL\Messages\AuthMoreDataMessage $message |
56
|
|
|
* @return \Plasma\Drivers\MySQL\Commands\CommandInterface |
57
|
|
|
* @throws \Plasma\Exception |
58
|
|
|
*/ |
59
|
1 |
|
function receiveMoreData(\Plasma\Drivers\MySQL\Messages\AuthMoreDataMessage $message): \Plasma\Drivers\MySQL\Commands\CommandInterface { |
60
|
1 |
|
throw new \Plasma\Exception('Auth plugin does not support auth more data'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|