Skip to content
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
8 changes: 8 additions & 0 deletions include/os_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
// thrown). takes into account the currently loaded application
#define OS_REGISTRY_GET_TAG_OFFSET_COMPARE_WITH_BUFFER (0x80000000UL)
#define OS_REGISTRY_GET_TAG_OFFSET_GET_LENGTH (0x40000000UL)

// Copy the currently running application tag from its install parameters to the given user buffer.
// Only APPNAME/APPVERSION/DERIVEPATH/ICON tags are retrievable to avoid install parameters private
// information. Warning: this function returns tag content of the application lastly scheduled to
// run, not the tag content of the currently executed piece of code (libraries subcalls)
SYSCALL unsigned int os_registry_get_current_app_tag(unsigned int tag,
unsigned char *buffer PLENGTH(maxlen),
unsigned int maxlen);
1 change: 1 addition & 0 deletions include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
#define SYSCALL_os_setting_get_ID 0x03000070
#define SYSCALL_os_setting_set_ID 0x03000071
#define SYSCALL_RESERVED_5_ID 0x06000123
#define SYSCALL_os_registry_get_current_app_tag_ID 0x03000074
#define SYSCALL_RESERVED_6_ID 0x00000125
#define SYSCALL_RESERVED_34_ID 0x01000126
#define SYSCALL_os_sched_exit_ID 0x0100009a
Expand Down
78 changes: 33 additions & 45 deletions io/src/os_io_default_apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "os_seed.h"
#include "os_app.h"
#include "os_pki.h"
#include "os_registry.h"
#include "os_io_default_apdu.h"
#include "status_words.h"

Expand Down Expand Up @@ -61,60 +62,47 @@ static bolos_err_t pki_load_certificate(uint8_t *buffer, size_t buffer_len, uint
/* Private variables ---------------------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

#ifndef APPNAME
#define APPNAME "Unknown"
#endif

#ifndef APPVERSION
#define APPVERSION "Unknown"
#endif

static bolos_err_t get_version(uint8_t *buffer_out, size_t *buffer_out_length)
{
bolos_err_t err = SWO_CONDITIONS_NOT_SATISFIED;
size_t max_buffer_out_length = *buffer_out_length;
int str_length = 0;

*buffer_out_length = 0;

#if defined(HAVE_BOLOS)
const char *name = "BOLOS";
const char *version = VERSION;
#else
const char *name = APPNAME;
const char *version = APPVERSION;
#endif

size_t out_len = 0;
uint8_t name_len = (uint8_t) strlen(name);
uint8_t version_len = (uint8_t) strlen(version);

if (max_buffer_out_length >= (size_t) (name_len + version_len + 5)) {
buffer_out[out_len] = 1; // format ID
out_len += sizeof(uint8_t);

// Copy name: Length, value
buffer_out[out_len] = (uint8_t) name_len;
out_len += sizeof(uint8_t);
memcpy(&buffer_out[out_len], name, name_len);
out_len += name_len;

// Copy version: Length, value
buffer_out[out_len] = (uint8_t) version_len;
out_len += sizeof(uint8_t);
memcpy(&buffer_out[out_len], version, version_len);
out_len += version_len;

// Copy os flags: Length, value
buffer_out[out_len] = 1;
out_len += sizeof(uint8_t);
buffer_out[out_len] = (uint8_t) os_flags();
out_len += sizeof(uint8_t);

// Success
*buffer_out_length = out_len;
err = SWO_SUCCESS;
if (max_buffer_out_length >= (strlen("BOLOS") + strlen(VERSION) + 3 + 2)) {
buffer_out[(*buffer_out_length)++] = 1; // format ID
str_length = strlen("BOLOS");
buffer_out[(*buffer_out_length)++] = str_length;
strcpy((char *) (&buffer_out[*buffer_out_length]), "BOLOS");
*buffer_out_length += str_length;
str_length = strlen(VERSION);
buffer_out[(*buffer_out_length)++] = str_length;
strcpy((char *) (&buffer_out[*buffer_out_length]), VERSION);
*buffer_out_length += str_length;
err = SWO_SUCCESS;
}
#else // !HAVE_BOLOS
if (max_buffer_out_length >= 3) {
buffer_out[(*buffer_out_length)++] = 1; // format ID
str_length
= os_registry_get_current_app_tag(BOLOS_TAG_APPNAME,
&buffer_out[(*buffer_out_length) + 1],
max_buffer_out_length - *buffer_out_length - 3);
buffer_out[(*buffer_out_length)++] = str_length;
*buffer_out_length += str_length;
str_length
= os_registry_get_current_app_tag(BOLOS_TAG_APPVERSION,
&buffer_out[(*buffer_out_length) + 1],
max_buffer_out_length - *buffer_out_length - 3);
buffer_out[(*buffer_out_length)++] = str_length;
*buffer_out_length += str_length;
buffer_out[(*buffer_out_length)++] = 1;
buffer_out[(*buffer_out_length)++] = os_flags();
err = SWO_SUCCESS;
}
#endif // !HAVE_BOLOS

return err;
}
Expand Down
11 changes: 11 additions & 0 deletions src/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,17 @@ void os_setting_set(unsigned int setting_id, unsigned char *value, unsigned int
return;
}

unsigned int os_registry_get_current_app_tag(unsigned int tag,
unsigned char *buffer,
unsigned int maxlen)
{
unsigned int parameters[3];
parameters[0] = (unsigned int) tag;
parameters[1] = (unsigned int) buffer;
parameters[2] = (unsigned int) maxlen;
return (unsigned int) SVC_Call(SYSCALL_os_registry_get_current_app_tag_ID, parameters);
}

void __attribute__((noreturn)) os_sched_exit(bolos_task_status_t exit_code)
{
unsigned int parameters[2];
Expand Down