Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
From a5701e863bddfde58380bf61d84719bb68cad3c9 Mon Sep 17 00:00:00 2001
Bug 1162897,  Add PK11_GetModuleURI() function, r=rrelyea
  • Loading branch information
varunnaganathan committed Aug 17, 2016
1 parent 5fd6004 commit 7d1c773
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nss/nss.def
Expand Up @@ -1108,6 +1108,7 @@ PK11_HasAttributeSet;
;+ global:
CERT_GetCertIsPerm;
CERT_GetCertIsTemp;
PK11_GetModuleURI;
PK11_GetTokenURI;
;+ local:
;+ *;
Expand Down
1 change: 1 addition & 0 deletions lib/pk11wrap/pk11pub.h
Expand Up @@ -136,6 +136,7 @@ PK11TokenStatus PK11_WaitForTokenEvent(PK11SlotInfo *slot, PK11TokenEvent event,
PRBool PK11_NeedPWInit(void);
PRBool PK11_TokenExists(CK_MECHANISM_TYPE);
SECStatus PK11_GetModInfo(SECMODModule *mod, CK_INFO *info);
char *PK11_GetModuleURI(SECMODModule *mod);
PRBool PK11_IsFIPS(void);
SECMODModule *PK11_GetModule(PK11SlotInfo *slot);

Expand Down
53 changes: 53 additions & 0 deletions lib/pk11wrap/pk11util.c
Expand Up @@ -14,6 +14,7 @@
#include "secerr.h"
#include "dev.h"
#include "utilpars.h"
#include "pkcs11uri.h"

/* these are for displaying error messages */

Expand Down Expand Up @@ -590,6 +591,58 @@ PK11_GetModInfo(SECMODModule *mod, CK_INFO *info)
return (crv == CKR_OK) ? SECSuccess : SECFailure;
}

char *
PK11_GetModuleURI(SECMODModule *mod)
{
CK_INFO info;
PK11URI *uri;
char *ret = NULL;
PK11URIAttribute attrs[3];
size_t nattrs = 0;
char libraryManufacturer[32 + 1], libraryDescription[32 + 1], libraryVersion[8];

if (PK11_GetModInfo(mod, &info) == SECFailure) {
return NULL;
}

PK11_MakeString(NULL, libraryManufacturer, (char *)info.manufacturerID,
sizeof(info.manufacturerID));
if (*libraryManufacturer != '\0') {
attrs[nattrs].name = PK11URI_PATTR_LIBRARY_MANUFACTURER;
attrs[nattrs].value = libraryManufacturer;
nattrs++;
}

PK11_MakeString(NULL, libraryDescription, (char *)info.libraryDescription,
sizeof(info.libraryDescription));
if (*libraryDescription != '\0') {
attrs[nattrs].name = PK11URI_PATTR_LIBRARY_DESCRIPTION;
attrs[nattrs].value = libraryDescription;
nattrs++;
}

PR_snprintf(libraryVersion, sizeof(libraryVersion), "%d.%d",
info.libraryVersion.major, info.libraryVersion.minor);
attrs[nattrs].name = PK11URI_PATTR_LIBRARY_VERSION;
attrs[nattrs].value = libraryVersion;
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 NULL;
}

return ret;
}

/* Determine if we have the FIP's module loaded as the default
* module to trigger other bogus FIPS requirements in PKCS #12 and
* SSL
Expand Down

0 comments on commit 7d1c773

Please sign in to comment.