| Conditions | 6 |
| Paths | 9 |
| Total Lines | 26 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function analyze(JWK $jwk, array &$messages) |
||
| 26 | { |
||
| 27 | if ('oct' !== $jwk->get('kty')) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | $k = Base64Url::decode($jwk->get('k')); |
||
| 31 | $kLength = 8 * mb_strlen($k, '8bit'); |
||
| 32 | if ($kLength < 128) { |
||
| 33 | $messages[] = 'The key length is less than 128 bits.'; |
||
| 34 | } |
||
| 35 | |||
| 36 | if (class_exists(Zxcvbn::class)) { |
||
| 37 | $zxcvbn = new Zxcvbn(); |
||
| 38 | $strength = $zxcvbn->passwordStrength($k); |
||
| 39 | switch (true) { |
||
| 40 | case $strength['score'] < 3: |
||
| 41 | $messages[] = 'The octet string is weak and easily guessable. Please change your key as soon as possible.'; |
||
| 42 | break; |
||
| 43 | case $strength['score'] === 3: |
||
| 44 | $messages[] = 'The octet string is safe, but a longer key is preferable.'; |
||
| 45 | break; |
||
| 46 | default: |
||
| 47 | break; |
||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 |