From: David Woodhouse <david.woodho...@intel.com>

The result must be freed by calling P11URI_FreeString()
---
 cmd/certutil/certutil.c |  3 +++
 lib/nss/nss.def         |  1 +
 lib/pk11wrap/pk11pub.h  |  2 ++
 lib/pk11wrap/pk11slot.c | 18 ++++++++++++++++++
 4 files changed, 24 insertions(+)

diff --git a/cmd/certutil/certutil.c b/cmd/certutil/certutil.c
index f4d4809..06bc45b 100644
--- a/cmd/certutil/certutil.c
+++ b/cmd/certutil/certutil.c
@@ -990,9 +990,12 @@ ListModules(void)
 
     /* look at each slot*/
     for (le = list->head; le; le = le->next) {
+        char *token_uri = PK11_GetTokenUri(le->slot, P11URI_FOR_TOKEN);
         printf("\n");
         printf("    slot: %s\n", PK11_GetSlotName(le->slot));
         printf("   token: %s\n", PK11_GetTokenName(le->slot));
+        printf("     uri: %s\n", token_uri);
+        P11URI_FreeString(token_uri);
     }
     PK11_FreeSlotList(list);
 
diff --git a/lib/nss/nss.def b/lib/nss/nss.def
index fa11944..ddf8f1e 100644
--- a/lib/nss/nss.def
+++ b/lib/nss/nss.def
@@ -104,6 +104,7 @@ PK11_GetInternalKeySlot;
 PK11_GetInternalSlot;
 PK11_GetSlotName;
 PK11_GetTokenName;
+PK11_GetTokenUri;
 PK11_HashBuf;
 PK11_IsFIPS;
 PK11_IsFriendly;
diff --git a/lib/pk11wrap/pk11pub.h b/lib/pk11wrap/pk11pub.h
index c130e1e..e496b91 100644
--- a/lib/pk11wrap/pk11pub.h
+++ b/lib/pk11wrap/pk11pub.h
@@ -14,6 +14,7 @@
 #include "seccomon.h"
 #include "pkcs7t.h"
 #include "cmsreclist.h"
+#include "p11uri.h"
 
 /*
  * Exported PK11 wrap functions.
@@ -78,6 +79,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, P11URIType type);
 char * PK11_GetSlotName(PK11SlotInfo *slot);
 PRBool PK11_NeedLogin(PK11SlotInfo *slot);
 PRBool PK11_IsFriendly(PK11SlotInfo *slot);
diff --git a/lib/pk11wrap/pk11slot.c b/lib/pk11wrap/pk11slot.c
index b6eef51..1b42bd5 100644
--- a/lib/pk11wrap/pk11slot.c
+++ b/lib/pk11wrap/pk11slot.c
@@ -18,6 +18,7 @@
 #include "dev3hack.h" 
 #include "pkim.h"
 #include "utilpars.h"
+#include "p11uri.h"
 
 
 /*************************************************************
@@ -1604,6 +1605,23 @@ PK11_GetTokenName(PK11SlotInfo *slot)
 }
 
 char *
+PK11_GetTokenUri(PK11SlotInfo *slot, P11URIType type)
+{
+    P11URI *uri;
+
+    uri = P11URI_New();
+    if (!uri)
+        return NULL;
+
+    if (PK11_GetTokenInfo(slot, P11URI_GetTokenInfo(uri)) != SECSuccess) {
+       P11URI_Free(uri);
+       return NULL;
+    }
+
+    return P11URI_Format(uri, type);
+}
+
+char *
 PK11_GetSlotName(PK11SlotInfo *slot)
 {
      return slot->slot_name;
-- 
2.7.4

-- 
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to