diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ea170466..5d9bcc61 100755 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,3 +1,7 @@ +# Copyright (c) 2023 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: MIT + name: Build on: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9379e345..b1c7cba8 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,7 @@ +# Copyright (c) 2023 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: MIT + name: CI Checks on: diff --git a/Docs/Prerequisites.md b/Docs/Prerequisites.md index 92b197b4..bbd5e569 100644 --- a/Docs/Prerequisites.md +++ b/Docs/Prerequisites.md @@ -37,7 +37,8 @@ console (either AWS-Web-Console or Local-Console) to an Arm Virtual Hardware Instance. From now on, any command-line commands described in this document must be run on the console connected to the Arm Virtual Hardware Instance. -**Note** +**Note** + The run example script `Tools/scripts/run.sh` assumes ecosystem FVP by default. If you are using Arm virtual hardware using Amazon machine images then an additional argument `--fvp_type vht` must be passed to the run example script. diff --git a/Middleware/ARM/IoT_Socket-lib/CMakeLists.txt b/Middleware/ARM/IoT_Socket-lib/CMakeLists.txt index 3ada0d6a..cf1e7961 100644 --- a/Middleware/ARM/IoT_Socket-lib/CMakeLists.txt +++ b/Middleware/ARM/IoT_Socket-lib/CMakeLists.txt @@ -8,4 +8,3 @@ target_include_directories(iot-socket-api INTERFACE IoT_Socket/include ) - diff --git a/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c b/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c index bb962727..90fcc915 100644 --- a/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c +++ b/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c @@ -37,7 +37,7 @@ TransportStatus_t Transport_Connect( NetworkContext_t * pNetworkContext, uint32_t recvTimeoutMs ) { TransportStatus_t status = TRANSPORT_STATUS_SUCCESS; - int32_t socketStatus = 0; + int32_t socketStatus; uint8_t ipAddr[ 4 ]; uint32_t ipAddrLen; TLSHelperParams_t tlsHelperParams = { 0 }; @@ -257,7 +257,6 @@ static int Send_Cb( void * pvCallerContext, TransportStatus_t Transport_Disconnect( NetworkContext_t * pNetworkContext ) { TransportStatus_t status = TRANSPORT_STATUS_SUCCESS; - int32_t socketStatus; if( pNetworkContext == NULL ) { @@ -265,6 +264,7 @@ TransportStatus_t Transport_Disconnect( NetworkContext_t * pNetworkContext ) } else { + int32_t socketStatus; do { socketStatus = iotSocketClose( pNetworkContext->socket ); diff --git a/Projects/aws-iot-example/event-helper/event_helper.c b/Projects/aws-iot-example/event-helper/event_helper.c index a2ff97dc..4286b825 100644 --- a/Projects/aws-iot-example/event-helper/event_helper.c +++ b/Projects/aws-iot-example/event-helper/event_helper.c @@ -58,5 +58,5 @@ bool xIsMqttAgentConnected( void ) { EventBits_t uxEvents = xEventGroupGetBits( xSystemEvents ); - return( ( bool ) ( uxEvents & EVENT_MASK_MQTT_CONNECTED ) ); + return( ( uxEvents & EVENT_MASK_MQTT_CONNECTED ) == 0 ? false : true ); } diff --git a/Projects/aws-iot-example/freertos-integration-tests/include/unistd.h b/Projects/aws-iot-example/freertos-integration-tests/include/unistd.h index 3d2de1a1..f7c85b86 100644 --- a/Projects/aws-iot-example/freertos-integration-tests/include/unistd.h +++ b/Projects/aws-iot-example/freertos-integration-tests/include/unistd.h @@ -1 +1,6 @@ +/* Copyright 2023 Arm Limited and/or its affiliates + * + * SPDX-License-Identifier: MIT + */ + /* dummy file for workaround missing ifdefs in AWS qual tests */ diff --git a/Projects/aws-iot-example/main.c b/Projects/aws-iot-example/main.c index 24c34585..9dfa214f 100644 --- a/Projects/aws-iot-example/main.c +++ b/Projects/aws-iot-example/main.c @@ -64,12 +64,12 @@ extern uint32_t tfm_ns_interface_init( void ); void vAssertCalled( const char * pcFile, unsigned long ulLine ) { - volatile unsigned long looping = 0; - - printf( "ASSERT failed! file %s:%ld, \n", pcFile, ulLine ); + printf( "ASSERT failed! file %s:%lu, \n", pcFile, ulLine ); taskENTER_CRITICAL(); { + volatile unsigned long looping = 0; + /* Use the debugger to set ul to a non-zero value in order to step out * of this function to determine why it was called. */ while( looping == 0LU ) diff --git a/Projects/aws-iot-example/provisioning/CMakeLists.txt b/Projects/aws-iot-example/provisioning/CMakeLists.txt index 00c1c8eb..ac3ae0f1 100644 --- a/Projects/aws-iot-example/provisioning/CMakeLists.txt +++ b/Projects/aws-iot-example/provisioning/CMakeLists.txt @@ -57,4 +57,3 @@ target_elf_to_bin(provisioning_data provisioning_data) add_custom_target(provisioning_data_bin ALL SOURCES provisioning_data.bin ) - diff --git a/Projects/aws-iot-example/provisioning/generate_credentials_header.py b/Projects/aws-iot-example/provisioning/generate_credentials_header.py index e5ff9812..b95e35eb 100644 --- a/Projects/aws-iot-example/provisioning/generate_credentials_header.py +++ b/Projects/aws-iot-example/provisioning/generate_credentials_header.py @@ -6,7 +6,7 @@ import argparse -CREDENTIALS_TEMPLATE = '''#ifndef AWS_CLIENT_CREDENTIAL_KEYS_H +CREDENTIALS_TEMPLATE = """#ifndef AWS_CLIENT_CREDENTIAL_KEYS_H #define AWS_CLIENT_CREDENTIAL_KEYS_H #define keyCLIENT_CERTIFICATE_PEM {client_certificate_pem} @@ -17,22 +17,25 @@ #endif /* AWS_CLIENT_CREDENTIAL_KEYS_H */ -''' +""" def main(args): client_private_key_pem = format_pem_to_c(args.client_private_key_pem) client_certificate_pem = format_pem_to_c(args.client_certificate_pem) with open("aws_clientcredential_keys.h", "w") as out_file: - out_file.write(CREDENTIALS_TEMPLATE. - format(client_certificate_pem=client_certificate_pem, - client_private_key_pem=client_private_key_pem, - jitr_dev_cert_auth_pem='''""''')) + out_file.write( + CREDENTIALS_TEMPLATE.format( + client_certificate_pem=client_certificate_pem, + client_private_key_pem=client_private_key_pem, + jitr_dev_cert_auth_pem='''""''', + ) + ) def format_pem_to_c(file): - formatted = '' - with open(file, 'r') as f: + formatted = "" + with open(file, "r") as f: lines = f.readlines() for line in lines[0:-1]: formatted += '"' + line.strip() + '\\n"\\\n' @@ -40,12 +43,16 @@ def format_pem_to_c(file): return formatted -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--client_certificate_pem", - help="the path of client certificate with pem extension", - required=True) - parser.add_argument("--client_private_key_pem", - help="the path of client private key with pem extension", - required=True) + parser.add_argument( + "--client_certificate_pem", + help="the path of client certificate with pem extension", + required=True, + ) + parser.add_argument( + "--client_private_key_pem", + help="the path of client private key with pem extension", + required=True, + ) main(parser.parse_args()) diff --git a/Projects/aws-iot-example/provisioning/provisioning_data.sct b/Projects/aws-iot-example/provisioning/provisioning_data.sct index 541be329..9a91af9f 100644 --- a/Projects/aws-iot-example/provisioning/provisioning_data.sct +++ b/Projects/aws-iot-example/provisioning/provisioning_data.sct @@ -10,4 +10,3 @@ LR_DATA PROVISIONING_DATA_START { * } } - diff --git a/Projects/blinky/main.c b/Projects/blinky/main.c index 0bbbfa0d..248925e9 100644 --- a/Projects/blinky/main.c +++ b/Projects/blinky/main.c @@ -18,12 +18,12 @@ extern uint32_t tfm_ns_interface_init( void ); void vAssertCalled( const char * pcFile, unsigned long ulLine ) { - volatile unsigned long looping = 0; - - printf( "ASSERT failed! file %s:%ld, \r\n", pcFile, ulLine ); + printf( "ASSERT failed! file %s:%lu, \r\n", pcFile, ulLine ); taskENTER_CRITICAL(); { + volatile unsigned long looping = 0; + /* Use the debugger to set ul to a non-zero value in order to step out * of this function to determine why it was called. */ while( looping == 0LU ) diff --git a/Tools/scripts/generate_credentials.py b/Tools/scripts/generate_credentials.py index a0e20eec..439f2330 100644 --- a/Tools/scripts/generate_credentials.py +++ b/Tools/scripts/generate_credentials.py @@ -16,83 +16,102 @@ def main(args): key = rsa.generate_private_key( - public_exponent=65537, - key_size=2048, + public_exponent=65537, + key_size=2048, + ) + with open(os.path.join(args.private_key_out_path, "private_key.pem"), "wb") as f: + f.write( + key.private_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PrivateFormat.TraditionalOpenSSL, + encryption_algorithm=serialization.NoEncryption(), + ) ) - with open(os.path.join(args.private_key_out_path, "private_key.pem"), - "wb") as f: - f.write(key.private_bytes( - encoding=serialization.Encoding.PEM, - format=serialization.PrivateFormat.TraditionalOpenSSL, - encryption_algorithm=serialization.NoEncryption(), - )) - subject = issuer = x509.Name([ - x509.NameAttribute(NameOID.COUNTRY_NAME, - args.certificate_country_name), - x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, - args.certificate_state_province_name), - x509.NameAttribute(NameOID.LOCALITY_NAME, - args.certificate_locality_name), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, - args.certificate_org_name), - x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, - args.certificate_org_unit_name), - x509.NameAttribute(NameOID.EMAIL_ADDRESS, - args.certificate_email_address_name), - ]) - cert = x509.CertificateBuilder().subject_name( - subject - ).issuer_name( - issuer - ).public_key( - key.public_key() - ).serial_number( - x509.random_serial_number() - ).not_valid_before( - datetime.datetime.now(datetime.timezone.utc) - ).not_valid_after( - datetime.datetime.now(datetime.timezone.utc) + - datetime.timedelta(days=int(args.certificate_valid_time)) - ).sign(key, hashes.SHA256()) + subject = issuer = x509.Name( + [ + x509.NameAttribute(NameOID.COUNTRY_NAME, args.certificate_country_name), + x509.NameAttribute( + NameOID.STATE_OR_PROVINCE_NAME, args.certificate_state_province_name + ), + x509.NameAttribute(NameOID.LOCALITY_NAME, args.certificate_locality_name), + x509.NameAttribute(NameOID.ORGANIZATION_NAME, args.certificate_org_name), + x509.NameAttribute( + NameOID.ORGANIZATIONAL_UNIT_NAME, args.certificate_org_unit_name + ), + x509.NameAttribute( + NameOID.EMAIL_ADDRESS, args.certificate_email_address_name + ), + ] + ) + cert = ( + x509.CertificateBuilder() + .subject_name(subject) + .issuer_name(issuer) + .public_key(key.public_key()) + .serial_number(x509.random_serial_number()) + .not_valid_before(datetime.datetime.now(datetime.timezone.utc)) + .not_valid_after( + datetime.datetime.now(datetime.timezone.utc) + + datetime.timedelta(days=int(args.certificate_valid_time)) + ) + .sign(key, hashes.SHA256()) + ) - with open(os.path.join(args.certificate_out_path, "certificate.pem"), - "wb") as f: + with open(os.path.join(args.certificate_out_path, "certificate.pem"), "wb") as f: f.write(cert.public_bytes(serialization.Encoding.PEM)) -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--certificate_valid_time", - help="the days until the certificate's expiration", - default="365", - required=False) - parser.add_argument("--certificate_country_name", - help="used for the certificate's meta data", - required=True) - parser.add_argument("--certificate_state_province_name", - help="used for the certificate's meta data", - required=True) - parser.add_argument("--certificate_locality_name", - help="used for the certificate's meta data", - required=True) - parser.add_argument("--certificate_org_name", - help="used for the certificate's meta data", - required=True) - parser.add_argument("--certificate_org_unit_name", - help="used for the certificate's meta data", - default="", - required=False) - parser.add_argument("--certificate_email_address_name", - help="used for the certificate's meta data", - default="", - required=False) - parser.add_argument("--certificate_out_path", - help="the path where certificate.pem will be generated", - default=".", - required=False) - parser.add_argument("--private_key_out_path", - help="the path where private_key.pem will be generated", - default=".", - required=False) + parser.add_argument( + "--certificate_valid_time", + help="the days until the certificate's expiration", + default="365", + required=False, + ) + parser.add_argument( + "--certificate_country_name", + help="used for the certificate's meta data", + required=True, + ) + parser.add_argument( + "--certificate_state_province_name", + help="used for the certificate's meta data", + required=True, + ) + parser.add_argument( + "--certificate_locality_name", + help="used for the certificate's meta data", + required=True, + ) + parser.add_argument( + "--certificate_org_name", + help="used for the certificate's meta data", + required=True, + ) + parser.add_argument( + "--certificate_org_unit_name", + help="used for the certificate's meta data", + default="", + required=False, + ) + parser.add_argument( + "--certificate_email_address_name", + help="used for the certificate's meta data", + default="", + required=False, + ) + parser.add_argument( + "--certificate_out_path", + help="the path where certificate.pem will be generated", + default=".", + required=False, + ) + parser.add_argument( + "--private_key_out_path", + help="the path where private_key.pem will be generated", + default=".", + required=False, + ) main(parser.parse_args()) diff --git a/Tools/tests/aws_test_util.py b/Tools/tests/aws_test_util.py index 95012b10..4ff03a3c 100755 --- a/Tools/tests/aws_test_util.py +++ b/Tools/tests/aws_test_util.py @@ -96,7 +96,8 @@ def wait_for_status(id, action): res = None try: res = iot.get_ota_update(otaUpdateId=id) - except: + except Exception as e: + print(e) break else: status = res["otaUpdateInfo"]["otaUpdateStatus"] @@ -137,9 +138,12 @@ def create_aws_resources(flags: Flags): # Create test thing with policy attached. flags.thing = iot.create_thing(thingName=flags.OTA_THING_NAME)["thingArn"] + ota_principal = ( + f"arn:aws:iot:{AWS_REGION}:{flags.AWS_ACCOUNT}:cert/{OTA_CERT_ID}" + ) iot.attach_thing_principal( thingName=flags.OTA_THING_NAME, - principal=f"arn:aws:iot:{AWS_REGION}:{flags.AWS_ACCOUNT}:cert/{OTA_CERT_ID}", + principal=ota_principal, ) print("Created OTA thing", flags.OTA_THING_NAME) @@ -174,10 +178,13 @@ def cleanup_aws_resources(flags: Flags): print("Deleted update", flags.update, file=sys.stderr) flags.update = None if flags.thing: + ota_principal = ( + f"arn:aws:iot:{AWS_REGION}:{flags.AWS_ACCOUNT}:cert/{OTA_CERT_ID}" + ) try: iot.detach_thing_principal( thingName=flags.OTA_THING_NAME, - principal=f"arn:aws:iot:{AWS_REGION}:{flags.AWS_ACCOUNT}:cert/{OTA_CERT_ID}", + principal=ota_principal, ) iot.delete_thing(thingName=flags.OTA_THING_NAME) except Exception as ex: diff --git a/Tools/tests/test_integration.py b/Tools/tests/test_integration.py index 2f65df20..d7c59f38 100755 --- a/Tools/tests/test_integration.py +++ b/Tools/tests/test_integration.py @@ -6,7 +6,10 @@ from aws_test_util import Flags, create_aws_resources, cleanup_aws_resources import re -ignore_tests = { "Full_OTA_PAL, otaPal_CloseFile_ValidSignature": "Test cannot succeed as the filename is hardcoded in test" } +Cases = "Full_OTA_PAL, otaPal_CloseFile_ValidSignature" +Output = "Test cannot succeed as the filename is hardcoded in test" +ignore_tests = {Cases: Output} + @fixture(scope="function") def aws_resources(build_path, credentials_path): @@ -22,13 +25,12 @@ def aws_resources(build_path, credentials_path): def test_integration(aws_resources, fvp): end_string = "RunQualificationTest returned" - index = 0 start = timer() current_time = timer() - regex = re.compile("(\d+) Tests (\d+) Failures (\d+) Ignored") - regex_test_name = re.compile("TEST\((.*)\)") - regex_fail = re.compile(":FAIL:") + regex = re.compile(r"(\d+) Tests (\d+) Failures (\d+) Ignored") + regex_test_name = re.compile(r"TEST\((.*)\)") + regex_fail = re.compile(r":FAIL:") current_test = "" tests = 0 @@ -59,7 +61,7 @@ def test_integration(aws_resources, fvp): if result: failed_tests.append(current_test) if end_string in line: - break; + break current_time = timer() print("-------------------- SUMMARY --------------------") diff --git a/Tools/uncrustify.cfg b/Tools/uncrustify.cfg index 3f4c40ca..916df630 100644 --- a/Tools/uncrustify.cfg +++ b/Tools/uncrustify.cfg @@ -1,3 +1,6 @@ +# Copyright (c) 2023 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: MIT # Uncrustify-0.69.0 newlines = auto # lf/crlf/cr/auto diff --git a/ci/aws_cleanup.py b/ci/aws_cleanup.py index 1d08e32e..ae0e8a68 100644 --- a/ci/aws_cleanup.py +++ b/ci/aws_cleanup.py @@ -123,9 +123,12 @@ def process_things(nextToken: str) -> str: thing_name: str = thing["thingName"] if thing_name.startswith(THING_NAME_PREFIX): try: + ota_principal = ( + f"arn:aws:iot:{AWS_REGION}:{AWS_ACCOUNT}:cert/{OTA_CERT_ID}" + ) iot.detach_thing_principal( thingName=thing_name, - principal=f"arn:aws:iot:{AWS_REGION}:{AWS_ACCOUNT}:cert/{OTA_CERT_ID}", + principal=ota_principal, ) iot.delete_thing(thingName=thing_name) except Exception as ex: diff --git a/conftest.py b/conftest.py index 0df99ac1..cc5da7ca 100644 --- a/conftest.py +++ b/conftest.py @@ -10,7 +10,9 @@ def pytest_addoption(parser): parser.addoption("--build-path", action="store", default="build") parser.addoption("--credentials-path", action="store", default="credentials") - parser.addoption("--avh", action="store", default="/opt/VHT/VHT_Corstone_SSE-300_Ethos-U55") + parser.addoption( + "--avh", action="store", default="/opt/VHT/VHT_Corstone_SSE-300_Ethos-U55" + ) parser.addoption("--avh-options", action="store", default="") @@ -61,18 +63,30 @@ def fvp(fvp_path, build_path, vsi_script_path, fvp_options): # Note: It can take few seconds to terminate the FVP cmdline = [ fvp_path, - "-a", f"{build_path}/Projects/aws-iot-example/aws-iot-example_merged.elf", - "-C", "core_clk.mul=200000000", - "-C", "mps3_board.visualisation.disable-visualisation=1", - "-C", "mps3_board.telnetterminal0.start_telnet=0", - "-C", "mps3_board.uart0.out_file=-", - "-C", "mps3_board.uart0.unbuffered_output=1", - "-C", "mps3_board.uart0.shutdown_on_eot=1", - "-C", "cpu0.semihosting-enable=1", - "-C", "mps3_board.smsc_91c111.enabled=1", - "-C", "mps3_board.hostbridge.userNetworking=1", - "-C", "mps3_board.DISABLE_GATING=1", - "-V", f"{vsi_script_path}", + "-a", + f"{build_path}/Projects/aws-iot-example/aws-iot-example_merged.elf", + "-C", + "core_clk.mul=200000000", + "-C", + "mps3_board.visualisation.disable-visualisation=1", + "-C", + "mps3_board.telnetterminal0.start_telnet=0", + "-C", + "mps3_board.uart0.out_file=-", + "-C", + "mps3_board.uart0.unbuffered_output=1", + "-C", + "mps3_board.uart0.shutdown_on_eot=1", + "-C", + "cpu0.semihosting-enable=1", + "-C", + "mps3_board.smsc_91c111.enabled=1", + "-C", + "mps3_board.hostbridge.userNetworking=1", + "-C", + "mps3_board.DISABLE_GATING=1", + "-V", + f"{vsi_script_path}", ] cmdline.extend(fvp_options) diff --git a/cspell.config.yaml b/cspell.config.yaml index e77f54e2..911ce1d8 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -28,4 +28,4 @@ ignorePaths: - 'dependency' - 'docs' - 'ThirdParty' - - 'History.txt' \ No newline at end of file + - 'History.txt'