summaryrefslogtreecommitdiff
path: root/common/rma_auth.c
Commit message (Collapse)AuthorAgeFilesLines
* rma: when processing 'RMA open' do not reboot the deviceVadim Bendebury2018-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Once RMA open is processed and CCD state is updated, the AP still might require to perform some operations, even if TPM is not available any more. With this patch enable_ccd_factory_mode() does not trigger device reset, if invoked by the RMA open handler. Another modification is that WP is disabled immediately when factory mode is enabled, there is no need to reset the H1 for WP status to change. BRANCH=cr50, cr50-mp BUG=b:115495431 TEST=verified that running 'gsctool -a -r <authcode>' sets to 'Y' all CCD properties, disables write protection, but does not reboot the device. Change-Id: I834a9e4b5ebbe4aaaf1caafad9c82424087d01f7 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1250037 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* cr50: refactor rma mode into factory modeMary Ruthven2018-05-301-75/+1
| | | | | | | | | | | | | | | | | | | | | | | | We're doing a bit of refactoring to break out factory mode into its own file. Now factory reset and rma reset will be two methods of entering factory mode. Factory mode can be disabled with the disable_factory vendor command. Factory mode means all ccd capabilities are set to Always and WP is permanently disabled. When factory mode is disabled, all capabilities are reset to Default and WP is reset to follow battery presence. This adds 56 bytes. BUG=none BRANCH=cr50 TEST=verify rma reset will enable factory mode. Change-Id: I21c6f7b4341e3a18e213e438bbd17c67739b85fa Signed-off-by: Mary Ruthven <mruthven@google.com> Reviewed-on: https://chromium-review.googlesource.com/1069789 Commit-Ready: Mary Ruthven <mruthven@chromium.org> Tested-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cr50: move RMA challenge-response to P256Vadim Bendebury2018-05-301-35/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the p256 curve is beneficial, because RMA feature is currently the only user of the x25519 curve in Cr50, whereas p256 support is required by other subsystems and its implementation is based on dcrypto. The p256 public key is 65 bytes in size, appropriate adjustments are being made for the structure storing the server public key and the key ID. The compact representation of the p256 public key requires 33 bytes, including the X coordinate and one extra byte used to communicate if the omitted Y coordinate is odd or even. The challenge structure communicated to the RMA server allows exactly 32 bytes for the public key. To comply, the generated ephemeral public key is used in compressed form (only the X coordinate is used). For the server to properly uncompress the public key one extra bit is required, to indicate if the original key's Y coordinate is odd or even. Since there is no room for the extra bit in the challenge structure, a convention is used where the generated ephemeral public key is guaranteed to have an odd Y coordinate. When generating the ephemeral key, the Y coordinate is checked, and if it is even, generation attempt is repeated. Some clean up is also included: even with debug enabled, generated challenge is displayed only once as a long string, convenient for copying and pasting. The new feature is not yet enabled, p256 support on the RMA server side is not yet available. Enabling p256 curve for RMA authentication saves 5336 bytes of the flash space. BRANCH=cr50, cr50-mp BUG=b:73296606 TEST=enabled CONFIG_RMA_AUTH_USE_P256 in board.h, generated challenge and verified matching auth code generated by the rma_reset utility. Change-Id: I857543c89a7c33c6fc2dc00e142fe9fa6fc642cf Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1074743 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* rma: mark key ID volatile so that it can be replaced post compilationVadim Bendebury2018-04-051-1/+1
| | | | | | | | | | | | | | | | | | | | | Swapping binary blobs in the image post compilation/linking is not working quite as expected, because some of the const data values seem to be inlined by the compiler, the values are not looked up at run time. This happens to the RMA public key ID field, which is just one byte in size. Marking the field 'volatile' seems to be fixing the issue. BRANCH=cr50, cr50-mp BUG=b:73296144 TEST=with the rest of the patches applied public key substitution between test and prod works as expected. Change-Id: I12d5d1243e7988ab59bf3bba8cdfa46f27116bd2 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/996513 Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org>
* cr50: use run time generated public RMA key definitionVadim Bendebury2018-04-041-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Use RMA public key definition generated based on the binary blob containing the key and key ID. Key generation is controlled by the make file in common/, but actual key blob comes from the board directory. The structure holding the key and key ID is being modified to allow initialization using a flat array. No more need in defining CONFIG_RMA_AUTH_SERVER_PUBLIC_KEY and CONFIG_RMA_AUTH_SERVER_KEY_ID. BRANCH=cr50, cr50-mp BUG=b:73296144, b:74100307 TEST='make buildall' still succeeds. test RMA server generated authentication codes are accepted when unlocking RMA. Change-Id: I8ade94de6eb69b3e49bc5b948dbac20e59962acf Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/990783 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cr50: bundle together RMA key and key IDVadim Bendebury2018-04-021-4/+11
| | | | | | | | | | | | | | | We want to be able to replace RMA public key and its key ID in the elf module before signing. Let's make sure they are packed together for ease of find and replace operation. BRANCH=cr50, cr50-mp BUG=b:73296144 TEST=built an image, verified that RMA unlock still works. Change-Id: I1a8e155391421f32b7422f11ab2a5f53d1ddd0ac Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/990781 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cr50: fix console command RMA authentication code checkVadim Bendebury2018-03-021-11/+30
| | | | | | | | | | | | | | | | | | When checking the RMA authentication code the code currently just verifies the value, but does not act on it. This patch directs the user input through the same vendor command path which is used when the RMA operation is controlled using gsctool. BRANCH=cr50, cr50-mp BUG=b:74080723 TEST=verified that issuing 'rma_auth <code>' on the Cr50 console now trigger CCD open and reboot. Change-Id: Ib3fab131b6a24b65618f0b1f2504638f8df11a4b Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/945311 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* rma: process proper auth codeVadim Bendebury2017-10-241-0/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When RMA process has been initialized and the user entered the expected authentication code value, the Cr50 needs to wipe out TPM memory, open and unlock CCD and reboot the device. This patch adds a function to accomplish that. User response is validated on the TPM task context, and TPM reset request also requires TPM task processing. To decouple response processing from the following reset, the response processing is handled by a hook task callback, delayed for 1s to make sure that user receives the response. After TPM has successfully reset the CCD is reinitialized with RMA 'opened' and the device is rebooted. Just in case something goes wrong with the unlock and the hook is not invoked, add a 10s deferred function to take the EC out of reset so that the device still can reboot. BRANCH=none BUG=b:67007905 TEST=on a Bob device: - on the Cr50 console enter 'ccd lock', verify that ccd is locked (by examining output of the 'ccd' command) - at the bash prompt enter gsctool -r -s -t, copy the authentication code from the Cr50 console and pass it to gsctool. - observe the device reset TPM wiping out its memory, enable CCD and reboot. Change-Id: I6fafb5e642cb2b6f2040507a7f1989607fd31316 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/729983 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* common: add rma_auth console commandVadim Bendebury2017-10-131-9/+81
| | | | | | | | | | | | | | | | | | | | The new console command uses the alternative TPM command execution path to generate the RMA challenge and also allows to verify the RMA authentication code. This patch also limits the rma challenge/auth code printouts to images supporting debug features (built with CR50_DEV=1), and limits the code included when building test images. BRANCH=cr50 BUG=b:67008109 TEST=while running TCG tpm test ran the new console command multiple times, observed all tests pass and the command always succeed. Change-Id: I9ca3e86040d8adbdbe70f33cf2b317075f823f36 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/699524 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* common: make rma_auth work with the serverVadim Bendebury2017-10-041-2/+0
| | | | | | | | | | | | | | | | | A couple of bugs have crept in with the latest series of patches: - the board ID value endianness does not have to be changed - the test RMA server public key value is wrong BRANCH=cr50 BUG=b:67007905 TEST=the generated challenge is now accepted by the server, and the generated auth code matches between the server and the Cr50. Change-Id: I18f413ab0bcc14d9cc50b115ac3784fdfcd5851c Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/700798 Reviewed-by: Michael Tang <ntang@chromium.org>
* common: add TPM vendor command to support RMA authenticationVadim Bendebury2017-10-021-0/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | The new vendor command operates in two modes: when received with a zero size payload, it triggers the Cr50 to generate a new RMA authentication challenge and the expected authentication code value. When receive with the payload, it compares the received payload with the pre-calculate authentication code, and returns to the host the comparison result (passed/not passed). A care is taken not to accept payload until at least there is a valid calculated auth code present (to avoid reporting a match on a payload of all zeros). Test config needed to be modified to allow compiling of the ccprintf wrapper. BRANCH=cr50 BUG=b:37952913 TEST=with the rest of the patches applied observed expected behavior of generating challenge/response and verifying the auth code. Change-Id: I30638b0ceef68830565f222dd1f4af17cfc8d7ef Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/690992
* commom: generalize rma_auth to and make it match server expectationsVadim Bendebury2017-10-021-3/+32
| | | | | | | | | | | | | | | | | | | | | | | Different devices could have different sized unique device IDs. Let's just use the IDs as is if they are no larger than the rma_challenge:device_id field, or the first 8 bytes of the HMAC_sha256 value of the unique device ID, where the unique device ID is used both as the key and the payload. The server expects the board ID field in big endian format, let's swap it before calculating the RMA auth challenge. The test's server side implementation needs to be also adjusted. BRANCH=cr50 BUG=b:37952913 TEST=make buildall -j passes. With the rest of the patches applied RMA authentication process generates sensible values. Change-Id: Ia1fbf9161e01de30a2da8214258008f6e5f7d915 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/690991 Reviewed-by: Michael Tang <ntang@chromium.org>
* common: allow rma_auth to work with both crypto and dcryptoVadim Bendebury2017-10-021-2/+21
| | | | | | | | | | | | | | | | | On Cr50 the crypto library has a slightly different API, as indicated by the presence of the CONFIG_DCRYPTO configuration option. This patch provides a wrapper which allows to calculate a SHA256 HMAC hash using either underlying crypto API. BRANCH=cr50 BUG=b:37952913 TEST=make buildall -j Change-Id: Ibb8c60e50139fd5506a4dd5f2ed19653c68af8cb Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/690440 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* common: Add RMA reset auth challenge-response cryptoRandall Spangler2017-06-301-0/+123
RMA auth uses X25519 to generate a relatively small challenge and response. Currently, nothing calls the rma_auth code. We'll need console and TPM vendor commands to do so. BUG=b:37952913 BRANCH=none TEST=make buildall Change-Id: Iec7f2d0e3dc8243f79b009ead16bb3ba9f1bef9d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/544184