diff --git a/README.md b/README.md index 6fb168a..ad2ffe5 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ -# ioConnect +# ioID-SDK An embedded SDK for connecting smart devices to Web3 ![SDK_Design_Overall](./doc/image/SDK_Design_Overall.png) -ioConnect SDK is based on the previously developed PSACrypto SDK and adds implementations of protocols such as DID, DIDDoc, JOSE, and DIDComm on top of ARM PSA functionality. It is implemented in C language and enhances the cross-platform compatibility of the SDK. +ioID-SDK is based on the previously developed PSACrypto SDK and adds implementations of protocols such as DID, DIDDoc, JOSE, and DIDComm on top of ARM PSA functionality. It is implemented in C language and enhances the cross-platform compatibility of the SDK. -The ioConnect SDK is primarily divided into two parts: the Core Layer and the Platform Adaptation Layer (PAL). The Core Layer provides functionality independent of the hardware platform, including implementations of PSA, DID, JOSE, and other protocols. The PAL layer optimizes the code according to the specific characteristics of different hardware platforms. For example, for the ESP platform, the SDK relies on its event messaging mechanism for code optimization, while for the Arduino platform, it implements communication functionality by inheriting the base class. - -![ioConnect_repo](./doc/image/ioConnect_repo.png) +The ioID-SDK is primarily divided into two parts: the Core Layer and the Platform Adaptation Layer (PAL). The Core Layer provides functionality independent of the hardware platform, including implementations of PSA, DID, JOSE, and other protocols. The PAL layer optimizes the code according to the specific characteristics of different hardware platforms. For example, for the ESP platform, the SDK relies on its event messaging mechanism for code optimization, while for the Arduino platform, it implements communication functionality by inheriting the base class. In the file structure of the Core Layer: @@ -18,11 +16,11 @@ The `dids` folder mainly implements the functionality of the DID, DIDComm, and V The `jose` folder mainly implements the JOSE protocol suite, including JWK, JWS, JWE, and others. -![ioConnect_repo_2](./doc/image/ioConnect_repo_2.png) +![ioID-SDK_repo_2](./doc/image/ioConnect_repo_2.png) In the file structure of the Platform Adaptation Layer (PAL), the SDK mainly implements methods for connecting to IoTeX decentralized network nodes. For example, the `DeviceRegister` component provides a method for terminal devices to register with the IoTeX Wallet, and the `Sprout` component allows easy communication with Sprout. -![ioConnect_repo_3](./doc/image/ioConnect_repo_3.png) +![ioID-SDK_repo_3](./doc/image/ioConnect_repo_3.png) @@ -45,32 +43,32 @@ In the file structure of the Platform Adaptation Layer (PAL), the SDK mainly imp ### How to Generate a DID for a device -Please view the documentation : **[How to Generate a DID for a device Using ioConnect SDK](./doc/How_to_Generate_a_DID_for_a_device_Using_ioConnectSDK.md)** +Please view the documentation : **[How to Generate a DID for a device Using ioID SDK](./doc/How_to_Generate_a_DID_for_a_device_Using_ioID-SDK.md)** ### How to Generate a DIDDoc -Please view the documentation : **[How to Generate a DID Document Using ioConnect SDK](./doc/How_to_Generate_a_DID_Document_Using_ioConnectSDK.md)** +Please view the documentation : **[How to Generate a DID Document Using ioID SDK](./doc/How_to_Generate_a_DID_Document_Using_ioID-SDK.md)** ### How to Generate a Verifiable Credentials -Please view the documentation : **[How to Generate a Verifiable Credentials Using ioConnect SDK](./doc/How_to_Generate_a_Verifiable_Credentials_Using_ioConnectSDK.md)** +Please view the documentation : **[How to Generate a Verifiable Credentials Using ioID SDK](./doc/How_to_Generate_a_Verifiable_Credentials_Using_ioID-SDK.md)** ### How to Generate a JWS -Please view the documentation : **[How_to generate_a_JWS](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWS_Serialization.md)** +Please view the documentation : **[How_to generate_a_JWS](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWS_Serialization.md)** ### How to Generate a JWE -Please view the documentation : **[How_to generate_a_JWE](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWE_Serialization.md)** +Please view the documentation : **[How_to generate_a_JWE](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWE_Serialization.md)** ### How to Generate a JWT -Please view the documentation : **[How_to generate_a_JWT](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWT_Serialization.md)** +Please view the documentation : **[How_to generate_a_JWT](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWT_Serialization.md)** ### How to Generate a DIDComm -Please view the documentation : **[How_to generate_a_DIDComm](./doc/How_to_use_the_ioConnectSDK_to_generate_a_DIDComm.md)** +Please view the documentation : **[How_to generate_a_DIDComm](./doc/How_to_use_the_ioID-SDK_to_generate_a_DIDComm.md)** diff --git a/core/src/psa/psa_crypto_ecp.c b/core/src/psa/psa_crypto_ecp.c index 0193036..363a051 100644 --- a/core/src/psa/psa_crypto_ecp.c +++ b/core/src/psa/psa_crypto_ecp.c @@ -510,7 +510,7 @@ psa_status_t iotex_psa_ecdsa_verify_hash( return( iotex_to_psa_error( ret ) ); #else - return iotex_ecdsa_verify( PSA_KEY_TYPE_ECC_GET_FAMILY(attributes->core.type), + return iotex_ecdsa_verify( attributes->core.type, key_buffer, key_buffer_size, hash, hash_length, (uint8_t *)signature, signature_length); #endif diff --git a/core/src/psa/psa_crypto_porting.c b/core/src/psa/psa_crypto_porting.c index b759bff..039207d 100644 --- a/core/src/psa/psa_crypto_porting.c +++ b/core/src/psa/psa_crypto_porting.c @@ -2570,7 +2570,10 @@ int iotex_ecdsa_verify( psa_key_type_t type, uint8_t public_key[2 * NUM_ECC_BYTES] = {0}; int ret; - switch( type ) + if ( (key_buffer_size != 64) && (key_buffer_size != 65)) + return PSA_ERROR_INVALID_ARGUMENT; + + switch( PSA_KEY_TYPE_ECC_GET_FAMILY(type) ) { case PSA_ECC_FAMILY_SECP_R1: @@ -2586,11 +2589,17 @@ int iotex_ecdsa_verify( psa_key_type_t type, return PSA_ERROR_GENERIC_ERROR; } - uECC_compute_public_key(key_buffer, public_key, curve); + int offset = key_buffer_size == 64 ? 0 : 1; + + if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)) { + memcpy(public_key, key_buffer + offset, 64); + } else { + uECC_compute_public_key(key_buffer, public_key, curve); + } ret = uECC_verify(public_key, hash, hash_length, signature, curve); if ( 0 == ret ) - return PSA_ERROR_GENERIC_ERROR; + return PSA_ERROR_INVALID_SIGNATURE; return PSA_SUCCESS; } diff --git a/doc/How_to_Generate_a_DID_Document_Using_ioConnectSDK.md b/doc/How_to_Generate_a_DID_Document_Using_ioID-SDK.md similarity index 99% rename from doc/How_to_Generate_a_DID_Document_Using_ioConnectSDK.md rename to doc/How_to_Generate_a_DID_Document_Using_ioID-SDK.md index 00f1504..9689785 100644 --- a/doc/How_to_Generate_a_DID_Document_Using_ioConnectSDK.md +++ b/doc/How_to_Generate_a_DID_Document_Using_ioID-SDK.md @@ -1,6 +1,6 @@ -# How to Generate a DID Document Using ioConnectSDK +# How to Generate a DID Document Using ioID-SDK ​ A DIDDoc is a set of data describing the [DID subject](https://www.w3.org/TR/did-core/#dfn-did-subjects), including mechanisms, such as cryptographic public keys, that the [DID subject](https://www.w3.org/TR/did-core/#dfn-did-subjects) or a [DID delegate](https://www.w3.org/TR/did-core/#dfn-did-delegate) can use to [authenticate](https://www.w3.org/TR/did-core/#dfn-authenticated) itself and prove its association with the [DID](https://www.w3.org/TR/did-core/#dfn-decentralized-identifiers). A DID document might have one or more different [representations](https://www.w3.org/TR/did-core/#dfn-representations) diff --git a/doc/How_to_Generate_a_DID_for_a_device_Using_ioConnectSDK.md b/doc/How_to_Generate_a_DID_for_a_device_Using_ioID-SDK.md similarity index 99% rename from doc/How_to_Generate_a_DID_for_a_device_Using_ioConnectSDK.md rename to doc/How_to_Generate_a_DID_for_a_device_Using_ioID-SDK.md index 85a8a22..28141e2 100644 --- a/doc/How_to_Generate_a_DID_for_a_device_Using_ioConnectSDK.md +++ b/doc/How_to_Generate_a_DID_for_a_device_Using_ioID-SDK.md @@ -1,6 +1,6 @@ -# How to Generate a DID for a device Using ioConnectSDK +# How to Generate a DID for a device Using ioID-SDK diff --git a/doc/How_to_Generate_a_Verifiable_Credentials_Using_ioConnectSDK.md b/doc/How_to_Generate_a_Verifiable_Credentials_Using_ioID-SDK.md similarity index 99% rename from doc/How_to_Generate_a_Verifiable_Credentials_Using_ioConnectSDK.md rename to doc/How_to_Generate_a_Verifiable_Credentials_Using_ioID-SDK.md index 4efc662..2be7b2a 100644 --- a/doc/How_to_Generate_a_Verifiable_Credentials_Using_ioConnectSDK.md +++ b/doc/How_to_Generate_a_Verifiable_Credentials_Using_ioID-SDK.md @@ -1,6 +1,6 @@ -# How to Generate a Verifiable Credentials Using ioConnectSDK +# How to Generate a Verifiable Credentials Using ioID-SDK diff --git a/pal/ESP32/DeviceRegister/deviceregister.c b/pal/ESP32/DeviceRegister/deviceregister.c index 31144fc..b12051a 100644 --- a/pal/ESP32/DeviceRegister/deviceregister.c +++ b/pal/ESP32/DeviceRegister/deviceregister.c @@ -52,7 +52,9 @@ static char signature_str[64 * 2 + 1] = {0}; static TaskHandle_t pxCreatedTask; static esp_log_level_t log_level = 0; +#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS) static httpd_handle_t server = NULL; +#endif #if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS) static esp_err_t did_get_handler(httpd_req_t *req) @@ -349,18 +351,18 @@ void iotex_pal_sprout_device_register_start(char *did, char *diddoc) printf("Failed to _pal_device_register_init() ret %d\n", ret); } - upload_did = iotex_utils_device_register_did_upload_prepare(did, 1, signature_str, true); + upload_did = iotex_utils_device_register_did_upload_prepare(did, 1, NULL, true); if (upload_did) printf("Upload DID : %s\n", upload_did); - upload_diddoc = iotex_utils_device_register_diddoc_upload_prepare(diddoc, 1, signature_str, true); + upload_diddoc = iotex_utils_device_register_diddoc_upload_prepare(diddoc, 1, NULL, true); if (upload_diddoc) printf("Upload DIDDoc : %s\n", upload_diddoc); #if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_SERIAL) - xTaskCreate(_sprout_device_register_serial_task, "device_register_task", 1024 * 5, NULL, 10, &pxCreatedTask); -#elif (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS) - _pal_sprout_webserver_secure_start(); + xTaskCreate(_sprout_device_register_serial_task, "device_register_task", 1024 * 5, NULL, 10, &pxCreatedTask); +#elif (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS) + _pal_sprout_webserver_secure_start(); #endif } @@ -379,9 +381,12 @@ void iotex_pal_sprout_device_register_stop(void) pxCreatedTask = NULL; mode_https: - +#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS) if (server) httpd_ssl_stop(server); +#endif + + return; }