1 | <?php |
||
9 | class OpenSSLCrypto implements CryptoHandler |
||
10 | { |
||
11 | protected $key; |
||
12 | |||
13 | protected $salt; |
||
14 | |||
15 | protected $saltedKey; |
||
16 | |||
17 | /** |
||
18 | * @return string |
||
19 | */ |
||
20 | public function getKey() |
||
24 | |||
25 | /** |
||
26 | * @return string |
||
27 | */ |
||
28 | public function getSalt() |
||
32 | |||
33 | /** |
||
34 | * @param string $key a per-site secret string which is used as the base encryption key. |
||
35 | * @param string $salt a per-session random string which is used as a salt to generate a per-session key |
||
36 | * |
||
37 | * The base encryption key needs to stay secret. If an attacker ever gets it, they can read their session, |
||
38 | * and even modify & re-sign it. |
||
39 | * |
||
40 | * The salt is a random per-session string that is used with the base encryption key to create a per-session key. |
||
41 | * This (amongst other things) makes sure an attacker can't use a known-plaintext attack to guess the key. |
||
42 | * |
||
43 | * Normally we could create a salt on encryption, send it to the client as part of the session (it doesn't |
||
44 | * need to remain secret), then use the returned salt to decrypt. But we already have the Session ID which makes |
||
45 | * a great salt, so no need to generate & handle another one. |
||
46 | */ |
||
47 | public function __construct($key, $salt) |
||
53 | |||
54 | /** |
||
55 | * Encrypt and then sign some cleartext |
||
56 | * |
||
57 | * @param string $cleartext - The cleartext to encrypt and sign |
||
58 | * @return string - The encrypted-and-signed message as base64 ASCII. |
||
59 | */ |
||
60 | public function encrypt($cleartext) |
||
71 | |||
72 | /** |
||
73 | * Check the signature on an encrypted-and-signed message, and if valid |
||
74 | * decrypt the content |
||
75 | * |
||
76 | * @param string $data - The encrypted-and-signed message as base64 ASCII |
||
77 | * |
||
78 | * @return bool|string - The decrypted cleartext or false if signature failed |
||
79 | */ |
||
80 | public function decrypt($data) |
||
97 | } |
||
98 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.