WifiConfigStore: Store integrity data in same file

Store the computed integrity data back in the same config store file.
The previous approach of storing the integrity data in a separate file
made config store updates non-atomic (look at associated bug for
details).

New approach:
a) Store the integrity data at the start of each config store XML file
(version + integrity == metadata for each file).
b) Uprev the config store version to 2 to support the new format.
c) Since we need to an-in place integrity check, when we write the file
For writes:
i) We fill up the integrity fields with the zeroes for the expected
number of bytes in the store file contents.
ii) Compute the integrity for the entire file contents.
iii) Rewrite the document metadata (version & integrity data) with the
newly computed integrity data in store file contents.
iv) Write the file contents to disk.
For reads:
i) Parse out the version & integrity contents from the file contents.
ii) Rewrite the document metadata (version & integrity data) with zeroed
integrity data in store file contents.
iii) Compute the integrity data for the modified file contents created
from (ii) and validate the result with the parsed value from (i).
iv) If the integrity check passes, continue with the parsing of the
document, else abort.
d) Since we need fixed size fields in the integrity fields, remove
storage of keystore alias string from |EncryptedData|. This can anyway
be trivially computed from the config store file name.

Bug: 138482990
Test: Verified that the device does not lose any stored networks on
reboot when the config store file is not modified.
Test:  Verified that the device discards all stored networks on reboot
when the config store file is modified.
Test: atest com.android.server.wifi
Test: Will send for full regression test.

Change-Id: I528d3402cb047cca3793be5f1386c4bb60c39a10
6 files changed