Commit 73411c1
committed
MB-61292: Add integrity check for stored keys
This commit adds an integrity check for stored keys. The check is
performed every time the stored keys are loaded from disk.
The check is done by comparing the stored key proof with the proof
that is calculated using token from the tokens file.
Proof for Key with KeyId is calculated the following way:
Proof := TokenUUID + ENCRYPT(SHA512(Token + KeyId) with Key)
Token file contains all the tokens that are considered trusted for
the integrity check. Tokens are stored in the following format:
TokenUUID1:Token1\n
TokenUUID2:Token2\n
...
Token file is encrypted with current config dek.
If configuration encryption is disabled, tokens are stored in plain,
so there basically no integrity protection for keys in this case.
When configuration encryption gets enabled, we generate new
configuration key first, then we generate new token, and then we
store that new token in the tokens file encrypted with the newly
generated congifuration key. By doing so we are making sure that
new token is never stored in plain text.
Old tokens (that were stored in plain text) are removed from the
tokens file once all the existing keys have their proofs recalculated
with the latest token.
Rotation of tokens is performed on any config key generation, or
config encryption enabling/disabling.
Change-Id: I3de47705964337f20b4eb035115210549979f5c5
Reviewed-on: https://review.couchbase.org/c/ns_server/+/220792
Tested-by: Timofey Barmin <[email protected]>
Tested-by: Build Bot <[email protected]>
Reviewed-by: Navdeep S Boparai <[email protected]>
Well-Formed: Build Bot <[email protected]>1 parent b662a1d commit 73411c1
File tree
9 files changed
+827
-122
lines changed- apps
- ns_babysitter/src
- ns_server/src
- deps/gocode
- gosecrets
9 files changed
+827
-122
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| |||
352 | 364 | | |
353 | 365 | | |
354 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
355 | 373 | | |
356 | 374 | | |
357 | 375 | | |
| |||
493 | 511 | | |
494 | 512 | | |
495 | 513 | | |
496 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
497 | 522 | | |
498 | 523 | | |
499 | 524 | | |
| |||
853 | 878 | | |
854 | 879 | | |
855 | 880 | | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
856 | 961 | | |
857 | 962 | | |
858 | 963 | | |
| |||
1216 | 1321 | | |
1217 | 1322 | | |
1218 | 1323 | | |
1219 | | - | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
1223 | 1329 | | |
1224 | 1330 | | |
1225 | 1331 | | |
1226 | | - | |
1227 | | - | |
| 1332 | + | |
1228 | 1333 | | |
1229 | 1334 | | |
1230 | 1335 | | |
| |||
1313 | 1418 | | |
1314 | 1419 | | |
1315 | 1420 | | |
| 1421 | + | |
| 1422 | + | |
1316 | 1423 | | |
1317 | 1424 | | |
1318 | 1425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1263 | 1263 | | |
1264 | 1264 | | |
1265 | 1265 | | |
| 1266 | + | |
1266 | 1267 | | |
1267 | 1268 | | |
1268 | 1269 | | |
| |||
1283 | 1284 | | |
1284 | 1285 | | |
1285 | 1286 | | |
| 1287 | + | |
1286 | 1288 | | |
1287 | 1289 | | |
1288 | 1290 | | |
| |||
1293 | 1295 | | |
1294 | 1296 | | |
1295 | 1297 | | |
| 1298 | + | |
1296 | 1299 | | |
1297 | 1300 | | |
1298 | 1301 | | |
| |||
1496 | 1499 | | |
1497 | 1500 | | |
1498 | 1501 | | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
1499 | 1509 | | |
1500 | 1510 | | |
1501 | 1511 | | |
| |||
1597 | 1607 | | |
1598 | 1608 | | |
1599 | 1609 | | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
1600 | 1623 | | |
1601 | 1624 | | |
1602 | 1625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
428 | 430 | | |
429 | 431 | | |
430 | 432 | | |
| |||
439 | 441 | | |
440 | 442 | | |
441 | 443 | | |
| 444 | + | |
442 | 445 | | |
443 | 446 | | |
444 | 447 | | |
445 | | - | |
| 448 | + | |
446 | 449 | | |
447 | 450 | | |
448 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
173 | 176 | | |
174 | 177 | | |
175 | 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 | + | |
| 203 | + | |
| 204 | + | |
176 | 205 | | |
177 | 206 | | |
178 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
0 commit comments