Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor code issues #13

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 Arm Limited and/or its affiliates
# <[email protected]>
# SPDX-License-Identifier: MIT

name: Build

on:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 Arm Limited and/or its affiliates
# <[email protected]>
# SPDX-License-Identifier: MIT

name: CI Checks

on:
Expand Down
3 changes: 2 additions & 1 deletion Docs/Prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion Middleware/ARM/IoT_Socket-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ target_include_directories(iot-socket-api
INTERFACE
IoT_Socket/include
)

4 changes: 2 additions & 2 deletions Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -257,14 +257,14 @@ 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 )
{
status = TRANSPORT_STATUS_INVALID_PARAMETER;
}
else
{
int32_t socketStatus;
do
{
socketStatus = iotSocketClose( pNetworkContext->socket );
Expand Down
2 changes: 1 addition & 1 deletion Projects/aws-iot-example/event-helper/event_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/* Copyright 2023 Arm Limited and/or its affiliates
* <[email protected]>
* SPDX-License-Identifier: MIT
*/

/* dummy file for workaround missing ifdefs in AWS qual tests */
6 changes: 3 additions & 3 deletions Projects/aws-iot-example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 0 additions & 1 deletion Projects/aws-iot-example/provisioning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ target_elf_to_bin(provisioning_data provisioning_data)
add_custom_target(provisioning_data_bin ALL
SOURCES provisioning_data.bin
)

Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -17,35 +17,42 @@


#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'
formatted += '"' + lines[-1].strip() + '"'
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())
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ LR_DATA PROVISIONING_DATA_START {
*
}
}

6 changes: 3 additions & 3 deletions Projects/blinky/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
163 changes: 91 additions & 72 deletions Tools/scripts/generate_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
13 changes: 10 additions & 3 deletions Tools/tests/aws_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
Loading
Loading