|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
| 15 | +#include <mbedtls/version.h> |
| 16 | +/* Keep forward-compatibility with Mbed TLS 3.x */ |
| 17 | +#if (MBEDTLS_VERSION_NUMBER < 0x03000000) |
| 18 | +#define MBEDTLS_2_X_COMPAT |
| 19 | +#else /* !(MBEDTLS_VERSION_NUMBER < 0x03000000) */ |
| 20 | +/* Macro wrapper for struct's private members */ |
| 21 | +#ifndef MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 22 | +#define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 23 | +#endif /* MBEDTLS_ALLOW_PRIVATE_ACCESS */ |
| 24 | +#endif /* !(MBEDTLS_VERSION_NUMBER < 0x03000000) */ |
15 | 25 |
|
16 |
| -#include "mbedtls/config.h" |
17 | 26 | #include "mbedtls/platform.h"
|
18 | 27 | #include "mbedtls/pk.h"
|
19 | 28 | #include "mbedtls/rsa.h"
|
|
45 | 54 | #include "esp_rmaker_client_data.h"
|
46 | 55 | #include "esp_rmaker_claim.h"
|
47 | 56 |
|
| 57 | + |
48 | 58 | static const char *TAG = "esp_claim";
|
49 | 59 |
|
50 | 60 | #define ESP_RMAKER_RANDOM_NUMBER_LEN 64
|
@@ -796,7 +806,12 @@ esp_err_t __esp_rmaker_claim_init(esp_rmaker_claim_data_t *claim_data)
|
796 | 806 | if (key) {
|
797 | 807 | mbedtls_pk_free(&claim_data->key);
|
798 | 808 | mbedtls_pk_init(&claim_data->key);
|
799 |
| - if (mbedtls_pk_parse_key(&claim_data->key, (uint8_t *)key, strlen(key) + 1, NULL, 0) == 0) { |
| 809 | +#ifdef MBEDTLS_2_X_COMPAT |
| 810 | + int ret = mbedtls_pk_parse_key(&claim_data->key, (uint8_t *)key, strlen(key) + 1, NULL, 0); |
| 811 | +#else |
| 812 | + int ret = mbedtls_pk_parse_key(&claim_data->key, (uint8_t *)key, strlen(key) + 1, NULL, 0, mbedtls_ctr_drbg_random, NULL); |
| 813 | +#endif |
| 814 | + if (ret == 0) { |
800 | 815 | ESP_LOGI(TAG, "Private key already exists. No need to re-initialise it.");
|
801 | 816 | claim_data->state = RMAKER_CLAIM_STATE_PK_GENERATED;
|
802 | 817 | }
|
|
0 commit comments