Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1162897, Add PK11_GetTokenURI() and use it from certutil, r=rrelyea
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Aug 15, 2016
1 parent 2007935 commit 5fd6004
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/certutil/certutil.c
Expand Up @@ -1002,9 +1002,12 @@ ListModules(void)

/* look at each slot*/
for (le = list->head; le; le = le->next) {
char *token_uri = PK11_GetTokenURI(le->slot);
printf("\n");
printf(" slot: %s\n", PK11_GetSlotName(le->slot));
printf(" token: %s\n", PK11_GetTokenName(le->slot));
printf(" uri: %s\n", token_uri);
PORT_Free(token_uri);
}
PK11_FreeSlotList(list);

Expand Down
1 change: 1 addition & 0 deletions lib/nss/nss.def
Expand Up @@ -1108,6 +1108,7 @@ PK11_HasAttributeSet;
;+ global:
CERT_GetCertIsPerm;
CERT_GetCertIsTemp;
PK11_GetTokenURI;
;+ local:
;+ *;
;+};
1 change: 1 addition & 0 deletions lib/pk11wrap/pk11pub.h
Expand Up @@ -76,6 +76,7 @@ PRBool PK11_IsReadOnly(PK11SlotInfo *slot);
PRBool PK11_IsInternal(PK11SlotInfo *slot);
PRBool PK11_IsInternalKeySlot(PK11SlotInfo *slot);
char *PK11_GetTokenName(PK11SlotInfo *slot);
char *PK11_GetTokenURI(PK11SlotInfo *slot);
char *PK11_GetSlotName(PK11SlotInfo *slot);
PRBool PK11_NeedLogin(PK11SlotInfo *slot);
PRBool PK11_IsFriendly(PK11SlotInfo *slot);
Expand Down
58 changes: 58 additions & 0 deletions lib/pk11wrap/pk11slot.c
Expand Up @@ -18,6 +18,7 @@
#include "dev3hack.h"
#include "pkim.h"
#include "utilpars.h"
#include "pkcs11uri.h"

/*************************************************************
* local static and global data
Expand Down Expand Up @@ -1687,6 +1688,63 @@ PK11_GetTokenName(PK11SlotInfo *slot)
return slot->token_name;
}

char *
PK11_GetTokenURI(PK11SlotInfo *slot)
{
PK11URI *uri;
char *ret = NULL;
char label[32 + 1], manufacturer[32 + 1], serial[16 + 1], model[16 + 1];
PK11URIAttribute attrs[4];
size_t nattrs = 0;

PK11_MakeString(NULL, label, (char *)slot->tokenInfo.label,
sizeof(slot->tokenInfo.label));
if (*label != '\0') {
attrs[nattrs].name = PK11URI_PATTR_TOKEN;
attrs[nattrs].value = label;
nattrs++;
}

PK11_MakeString(NULL, manufacturer, (char *)slot->tokenInfo.manufacturerID,
sizeof(slot->tokenInfo.manufacturerID));
if (*manufacturer != '\0') {
attrs[nattrs].name = PK11URI_PATTR_MANUFACTURER;
attrs[nattrs].value = manufacturer;
nattrs++;
}

PK11_MakeString(NULL, serial, (char *)slot->tokenInfo.serialNumber,
sizeof(slot->tokenInfo.serialNumber));
if (*serial != '\0') {
attrs[nattrs].name = PK11URI_PATTR_SERIAL;
attrs[nattrs].value = serial;
nattrs++;
}

PK11_MakeString(NULL, model, (char *)slot->tokenInfo.model,
sizeof(slot->tokenInfo.model));
if (*model != '\0') {
attrs[nattrs].name = PK11URI_PATTR_MODEL;
attrs[nattrs].value = model;
nattrs++;
}

uri = PK11URI_CreateURI(attrs, nattrs, NULL, 0);
if (uri == NULL) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return NULL;
}

ret = PK11URI_FormatURI(NULL, uri);
PK11URI_DestroyURI(uri);

if (ret == NULL) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
}

return ret;
}

char *
PK11_GetSlotName(PK11SlotInfo *slot)
{
Expand Down

0 comments on commit 5fd6004

Please sign in to comment.