-
Notifications
You must be signed in to change notification settings - Fork 27
/
kdbx_format.html
202 lines (188 loc) · 4.49 KB
/
kdbx_format.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<html>
<head>
<title>Reverse Engineered KeePass (KDBX) File Format</title>
</head>
<body>
<h1>Reverse Engineered KeePass (KDBX) File Format</h1>
<hr />
<p>Integers are stored in little endian format.</p>
<p></p>
<p></p>
<h2>*Magic bytes</h2>
<p>8 bytes:</p>
<p>0x03, 0xd9, 0xa2, 0x9a, 0x67, 0xfb, 0x4b, 0xb5</p>
<p></p>
<p>
The magic bytes are used as a first check to determine if a file could be
a KDBX file.
</p>
<p></p>
<p></p>
<h2>*Format version</h2>
<p>
This field is uint32, where the upper 16 bits represent the major version,
and the lower 16 bits represent the minor version.
</p>
<p></p>
<p>Version 2.20.1: 0x003001</p>
<p></p>
<p></p>
<h2>*Header</h2>
<p>
The header consists of a number of header fields. The order of the fields
is not important. Header fields are read until the end of header field is
encountered. A header field starts with a header with the following
structure:
</p>
<p></p>
<p>uint8 id</p>
<p>uint16 size of field data</p>
<p></p>
<p>followed by the field data.</p>
<p></p>
<p>Header fields</p>
<p></p>
<p>end of header</p>
<p></p>
<hr />
<ul>
<li>
id 0
<p>size 4</p>
<p>data 0x0d, 0x0a, 0x0d, 0x0a</p>
<p></p>
<p></p>
</li>
<li>
comment
<p></p>
<p>id 1</p>
<p></p>
<p>The comment field seems to be ignored in KeePass.</p>
<p></p>
<p></p>
</li>
<li>
cipher id
<p></p>
<p>id 2</p>
<p></p>
<p>
The cipher id is 16 bytes. For AES-CBC with PKCS7 padding, which is
the default cipher, the id is
</p>
<p>
0x31,0xc1,0xf2,0xe6,0xbf,0x71,0x43,0x50,0xbe,0x58,0x05,0x21,0x6a,0xfc,0x5a,0xff
</p>
<p></p>
<p></p>
</li>
<li>
compression
<p></p>
<p>id 3</p>
<p>size 4</p>
<p>data 0x00,0x00,0x00,0x00 (no compression)</p>
<p></p>
<p></p>
</li>
<li>
master seed
<p></p>
<p>id 4</p>
<p>size 32</p>
<p></p>
<p>
The master seed is a 32 byte salt value for the key transformation.
</p>
<p></p>
<p></p>
</li>
<li>
transform seed
<p></p>
<p>id 5</p>
<p>
size KeePass writes 32 bytes of transform seed, but accepts a seed of
any length when reading a file.
</p>
<p></p>
<p>
The transform seed is another salt value for the key transformation.
</p>
<p></p>
<p></p>
</li>
<li>
number of transform rounds
<p></p>
<p>id 6</p>
<p>size 8</p>
<p></p>
<p>The number of key transformation rounds, expressed as an uint64.</p>
<p></p>
<p></p>
</li>
<li>
iv
<p></p>
<p>id 7</p>
<p>
size KeePass always writes 16 bytes of IV, but the length is not
checked when reading the file.
</p>
<p>
Having the wrong IV length would cause an exception in the encryption
engine, though.
</p>
<p></p>
<p>The IV of the cipher.</p>
<p></p>
<p></p>
</li>
<li>
protected stream key
<p></p>
<p>id 8</p>
<p>
size KeePass always writes 32 bytes, but length is not checked when
reading the file.
</p>
<p></p>
<p>
the protected stream key seems to be a way to obfuscate some fields of
the decrypted file.
</p>
<p></p>
<p></p>
</li>
<li>
stream start bytes
<p></p>
<p>id 9</p>
<p>size 32</p>
<p></p>
<p>
the initial 32 bytes of the decrypted stream, used to verify that the
decryption key is
</p>
<p>probably correct before decrypting the entire stream</p>
<p></p>
<p></p>
</li>
<li>
inner random stream id
<p></p>
<p>id 10</p>
<p>size 4</p>
<p></p>
<p>
an uint32 giving the algorithm used to produce the random stream used
with the protected stream key for obfuscation
</p>
<p></p>
<p></p>
</li>
</ul>
</body>
</html>