1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AESKW\Tests; |
13
|
|
|
|
14
|
|
|
use AESKW\A128KW; |
15
|
|
|
use AESKW\A192KW; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* These tests come from the RFC3394. |
20
|
|
|
* |
21
|
|
|
* @see https://www.ietf.org/rfc/rfc3394.txt#4 |
22
|
|
|
*/ |
23
|
|
|
final class ExceptionTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @expectedException \InvalidArgumentException |
27
|
|
|
* @expectedExceptionMessage Integrity check failed |
28
|
|
|
*/ |
29
|
|
|
public function testIntegrityCheckFailed() |
30
|
|
|
{ |
31
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F'); |
32
|
|
|
$data = hex2bin('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE4'); |
33
|
|
|
|
34
|
|
|
A128KW::unwrap($kek, $data); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
* @expectedExceptionMessage Bad key size |
40
|
|
|
*/ |
41
|
|
|
public function testA128KWBadKeySize() |
42
|
|
|
{ |
43
|
|
|
$kek = hex2bin('00010203040506070809101112131415'); |
44
|
|
|
$data = hex2bin('0011223344'); |
45
|
|
|
|
46
|
|
|
A128KW::wrap($kek, $data); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @expectedException \InvalidArgumentException |
51
|
|
|
* @expectedExceptionMessage Bad key size |
52
|
|
|
*/ |
53
|
|
|
public function testA128KWEmptyKey() |
54
|
|
|
{ |
55
|
|
|
$kek = hex2bin('00010203040506070809101112131415'); |
56
|
|
|
$data = hex2bin(''); |
57
|
|
|
|
58
|
|
|
A128KW::wrap($kek, $data, true); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @expectedException \InvalidArgumentException |
63
|
|
|
* @expectedExceptionMessage Integrity check failed |
64
|
|
|
*/ |
65
|
|
|
public function testA128KWIntegrityNotVerified() |
66
|
|
|
{ |
67
|
|
|
$kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8'); |
68
|
|
|
$data = hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6b'); |
69
|
|
|
|
70
|
|
|
A192KW::unwrap($kek, $data, true); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @expectedException \InvalidArgumentException |
75
|
|
|
* @expectedExceptionMessage Bad data |
76
|
|
|
*/ |
77
|
|
|
public function testWrap64BitsKeyDataWith128BitKEK() |
78
|
|
|
{ |
79
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F'); |
80
|
|
|
$data = hex2bin('F4740052E82A2251'); |
81
|
|
|
|
82
|
|
|
A128KW::unwrap($kek, $data); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @expectedException \InvalidArgumentException |
87
|
|
|
* @expectedExceptionMessage Integrity check failed |
88
|
|
|
*/ |
89
|
|
|
public function testBadData() |
90
|
|
|
{ |
91
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F'); |
92
|
|
|
$data = hex2bin('F4740052E82A225174CE86FBD7B805E6'); |
93
|
|
|
|
94
|
|
|
A128KW::unwrap($kek, $data); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|