Skip to content

Commit

Permalink
Include uri in pkcs11-tool -L option
Browse files Browse the repository at this point in the history
Resolves: OpenSC#3123

Signed-off-by: Sergio Arroutbi <sarroutb@redhat.com>
  • Loading branch information
sarroutbi committed Apr 19, 2024
1 parent 26b9067 commit 363f331
Showing 1 changed file with 156 additions and 0 deletions.
156 changes: 156 additions & 0 deletions src/tools/pkcs11-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ static void p11_warn(const char *, CK_RV);
static const char * p11_slot_info_flags(CK_FLAGS);
static const char * p11_token_info_flags(CK_FLAGS);
static const char * p11_utf8_to_local(CK_UTF8CHAR *, size_t);
static const char * p11_utf8_to_local_percent_format(CK_UTF8CHAR *, size_t);
static const char * p11_flag_names(struct flag_info *, CK_FLAGS);
static const char * p11_mechanism_to_name(CK_MECHANISM_TYPE);
static CK_MECHANISM_TYPE p11_name_to_mechanism(const char *);
Expand Down Expand Up @@ -1681,6 +1682,15 @@ static void show_token(CK_SLOT_ID slot)
printf(" serial num : %s\n", p11_utf8_to_local(info.serialNumber,
sizeof(info.serialNumber)));
printf(" pin min/max : %lu/%lu\n", info.ulMinPinLen, info.ulMaxPinLen);
printf(" uri : pkcs11:model=");
printf(p11_utf8_to_local_percent_format(info.model, sizeof(info.model)));
printf(";manufacturer=");
printf(p11_utf8_to_local(info.manufacturerID, sizeof(info.manufacturerID)));
printf(";serial=");
printf(p11_utf8_to_local(info.serialNumber, sizeof(info.serialNumber)));
printf(";token=");
printf(p11_utf8_to_local(info.label, sizeof(info.label)));
printf("\n");
}

static void list_mechs(CK_SLOT_ID slot)
Expand Down Expand Up @@ -8293,6 +8303,152 @@ static const char *p11_utf8_to_local(CK_UTF8CHAR *string, size_t len)
return buffer;
}

static const char *p11_utf8_to_local_percent_format(CK_UTF8CHAR *string, size_t len)
{
static char buffer[1024];
size_t output_index, input_index;

for (output_index = input_index = 0; output_index < sizeof(buffer) - 1;
output_index++) {
if (input_index >= len) {
break;
}
if (string[input_index] == ' ') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '0';
}
else if (string[input_index] == '!') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '1';
}
else if (string[input_index] == '"') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '2';
}
else if (string[input_index] == '#') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '3';
}
else if (string[input_index] == '$') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '4';
}
else if (string[input_index] == '%') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '5';
}
else if (string[input_index] == '&') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '6';
}
else if (string[input_index] == '\'') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '7';
}
else if (string[input_index] == '(') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '8';
}
else if (string[input_index] == ')') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = '9';
}
else if (string[input_index] == '*') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = 'A';
}
else if (string[input_index] == '+') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = 'B';
}
else if (string[input_index] == ',') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = 'C';
}
else if (string[input_index] == '/') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '2';
buffer[output_index] = 'F';
}
else if (string[input_index] == ':') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '3';
buffer[output_index] = 'A';
}
else if (string[input_index] == ';') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '3';
buffer[output_index] = 'B';
}
else if (string[input_index] == '=') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '3';
buffer[output_index] = 'D';
}
else if (string[input_index] == '?') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '3';
buffer[output_index] = 'F';
}
else if (string[input_index] == '@') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '4';
buffer[output_index] = '0';
}
else if (string[input_index] == '[') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '5';
buffer[output_index] = 'B';
}
else if (string[input_index] == ']') {
buffer[output_index++] = '%';
buffer[output_index++] = '%';
buffer[output_index++] = '5';
buffer[output_index] = 'D';
}
else {
buffer[output_index] = string[input_index];
}
input_index++;
}
buffer[output_index] = '\0';
return buffer;
}


static void p11_fatal(const char *func, CK_RV rv)
{
if (p11)
Expand Down

0 comments on commit 363f331

Please sign in to comment.