Commit 5fd60048 authored by David Woodhouse's avatar David Woodhouse

Bug 1162897, Add PK11_GetTokenURI() and use it from certutil, r=rrelyea

parent 20079356
......@@ -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);
......
......@@ -1108,6 +1108,7 @@ PK11_HasAttributeSet;
;+ global:
CERT_GetCertIsPerm;
CERT_GetCertIsTemp;
PK11_GetTokenURI;
;+ local:
;+ *;
;+};
......@@ -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);
......
......@@ -18,6 +18,7 @@
#include "dev3hack.h"
#include "pkim.h"
#include "utilpars.h"
#include "pkcs11uri.h"
/*************************************************************
* local static and global data
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment