Jim Carver
/
mbed-cloud-workshop-connect
Fork for workshops
simple-mbed-cloud-client/pal_plat_rot_insecure.cpp@0:6b753f761943, 2018-10-12 (annotated)
- Committer:
- JimCarver
- Date:
- Fri Oct 12 21:22:49 2018 +0000
- Revision:
- 0:6b753f761943
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimCarver | 0:6b753f761943 | 1 | // ---------------------------------------------------------------------------- |
JimCarver | 0:6b753f761943 | 2 | // Copyright 2016-2018 ARM Ltd. |
JimCarver | 0:6b753f761943 | 3 | // |
JimCarver | 0:6b753f761943 | 4 | // SPDX-License-Identifier: Apache-2.0 |
JimCarver | 0:6b753f761943 | 5 | // |
JimCarver | 0:6b753f761943 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
JimCarver | 0:6b753f761943 | 7 | // you may not use this file except in compliance with the License. |
JimCarver | 0:6b753f761943 | 8 | // You may obtain a copy of the License at |
JimCarver | 0:6b753f761943 | 9 | // |
JimCarver | 0:6b753f761943 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
JimCarver | 0:6b753f761943 | 11 | // |
JimCarver | 0:6b753f761943 | 12 | // Unless required by applicable law or agreed to in writing, software |
JimCarver | 0:6b753f761943 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
JimCarver | 0:6b753f761943 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JimCarver | 0:6b753f761943 | 15 | // See the License for the specific language governing permissions and |
JimCarver | 0:6b753f761943 | 16 | // limitations under the License. |
JimCarver | 0:6b753f761943 | 17 | // ---------------------------------------------------------------------------- |
JimCarver | 0:6b753f761943 | 18 | |
JimCarver | 0:6b753f761943 | 19 | #include "pal_plat_rtos.h" |
JimCarver | 0:6b753f761943 | 20 | |
JimCarver | 0:6b753f761943 | 21 | #define PAL_DEVICE_KEY_SIZE_IN_BYTES 16 |
JimCarver | 0:6b753f761943 | 22 | |
JimCarver | 0:6b753f761943 | 23 | //THIS CODE IS FOR TESTING PURPOSES ONLY. DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE |
JimCarver | 0:6b753f761943 | 24 | palStatus_t __attribute__((weak)) pal_plat_osGetRoT128Bit(uint8_t *keyBuf, size_t keyLenBytes) |
JimCarver | 0:6b753f761943 | 25 | { |
JimCarver | 0:6b753f761943 | 26 | #if defined (__CC_ARM) /* ARM compiler. */ |
JimCarver | 0:6b753f761943 | 27 | #warning("PAL_INSECURE- You are using insecure Root Of Trust implementation, DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE") |
JimCarver | 0:6b753f761943 | 28 | #else |
JimCarver | 0:6b753f761943 | 29 | #pragma message ("You are using insecure Root Of Trust implementation, DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE") |
JimCarver | 0:6b753f761943 | 30 | #endif |
JimCarver | 0:6b753f761943 | 31 | static bool runOnce = true; |
JimCarver | 0:6b753f761943 | 32 | if (runOnce) { |
JimCarver | 0:6b753f761943 | 33 | |
JimCarver | 0:6b753f761943 | 34 | PAL_LOG(WARN, "You are using insecure Root Of Trust implementation"); |
JimCarver | 0:6b753f761943 | 35 | runOnce = false; |
JimCarver | 0:6b753f761943 | 36 | } |
JimCarver | 0:6b753f761943 | 37 | |
JimCarver | 0:6b753f761943 | 38 | if (keyLenBytes < PAL_DEVICE_KEY_SIZE_IN_BYTES) { |
JimCarver | 0:6b753f761943 | 39 | return PAL_ERR_BUFFER_TOO_SMALL; |
JimCarver | 0:6b753f761943 | 40 | } |
JimCarver | 0:6b753f761943 | 41 | |
JimCarver | 0:6b753f761943 | 42 | if (NULL == keyBuf) { |
JimCarver | 0:6b753f761943 | 43 | return PAL_ERR_NULL_POINTER; |
JimCarver | 0:6b753f761943 | 44 | } |
JimCarver | 0:6b753f761943 | 45 | |
JimCarver | 0:6b753f761943 | 46 | for (int i=0; i < PAL_DEVICE_KEY_SIZE_IN_BYTES; i++) { |
JimCarver | 0:6b753f761943 | 47 | keyBuf[i] = i; |
JimCarver | 0:6b753f761943 | 48 | } |
JimCarver | 0:6b753f761943 | 49 | |
JimCarver | 0:6b753f761943 | 50 | return PAL_SUCCESS; |
JimCarver | 0:6b753f761943 | 51 | } |
JimCarver | 0:6b753f761943 | 52 |