From ca4e1df93cfd8469c8ee7dfeacd13dba31ff384b Mon Sep 17 00:00:00 2001 From: "relyea%netscape.com" Date: Tue, 25 Jun 2002 22:33:37 +0000 Subject: [PATCH] Add new function which returns the NSS 3.4 style nickname directly from a NSSCertificate structure. git-svn-id: svn://10.0.0.236/trunk@124032 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/pki/pki3hack.c | 44 ++++++++++++++++++++++++- mozilla/security/nss/lib/pki/pki3hack.h | 5 ++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/mozilla/security/nss/lib/pki/pki3hack.c b/mozilla/security/nss/lib/pki/pki3hack.c index d2d18068e84..e88dda9855a 100644 --- a/mozilla/security/nss/lib/pki/pki3hack.c +++ b/mozilla/security/nss/lib/pki/pki3hack.c @@ -32,7 +32,7 @@ */ #ifdef DEBUG -static const char CVS_ID[] = "@(#) $RCSfile: pki3hack.c,v $ $Revision: 1.56 $ $Date: 2002-06-24 22:36:59 $ $Name: not supported by cvs2svn $"; +static const char CVS_ID[] = "@(#) $RCSfile: pki3hack.c,v $ $Revision: 1.57 $ $Date: 2002-06-25 22:33:37 $ $Name: not supported by cvs2svn $"; #endif /* DEBUG */ /* @@ -547,6 +547,48 @@ get_cert_instance(NSSCertificate *c) return instance; } +char * +STAN_GetCERTCertificateName(NSSCertificate *c) +{ + nssCryptokiInstance *instance = get_cert_instance(c); + NSSCryptoContext *context = c->object.cryptoContext; + PRStatus nssrv; + int nicklen, tokenlen, len; + NSSUTF8 *tokenName = NULL; + NSSUTF8 *stanNick = NULL; + char *nickname = NULL; + char *nick; + + if (instance) { + stanNick = instance->label; + } else if (context) { + stanNick = c->object.tempName; + } + if (stanNick) { + /* fill other fields needed by NSS3 functions using CERTCertificate */ + if (instance && !PK11_IsInternal(instance->token->pk11slot)) { + tokenName = nssToken_GetName(instance->token); + tokenlen = nssUTF8_Size(tokenName, &nssrv); + } else { + /* don't use token name for internal slot; 3.3 didn't */ + tokenlen = 0; + } + nicklen = nssUTF8_Size(stanNick, &nssrv); + len = tokenlen + nicklen; + nickname = PORT_Alloc(len); + nick = nickname; + if (tokenName) { + memcpy(nick, tokenName, tokenlen-1); + nick += tokenlen-1; + *nick++ = ':'; + } + memcpy(nick, stanNick, nicklen-1); + nickname[len-1] = '\0'; + } + return nickname; +} + + static void fill_CERTCertificateFields(NSSCertificate *c, CERTCertificate *cc, PRBool forced) { diff --git a/mozilla/security/nss/lib/pki/pki3hack.h b/mozilla/security/nss/lib/pki/pki3hack.h index 73cdd164ba0..ad9acfaccab 100644 --- a/mozilla/security/nss/lib/pki/pki3hack.h +++ b/mozilla/security/nss/lib/pki/pki3hack.h @@ -35,7 +35,7 @@ #define PKINSS3HACK_H #ifdef DEBUG -static const char PKINSS3HACK_CVS_ID[] = "@(#) $RCSfile: pki3hack.h,v $ $Revision: 1.11 $ $Date: 2002-04-18 17:30:03 $ $Name: not supported by cvs2svn $"; +static const char PKINSS3HACK_CVS_ID[] = "@(#) $RCSfile: pki3hack.h,v $ $Revision: 1.12 $ $Date: 2002-06-25 22:33:37 $ $Name: not supported by cvs2svn $"; #endif /* DEBUG */ #ifndef NSSDEVT_H @@ -106,6 +106,9 @@ NSS_EXTERN PRStatus nssPKIX509_GetIssuerAndSerialFromDER(NSSDER *der, NSSArena *arena, NSSDER *issuer, NSSDER *serial); +NSS_EXTERN char * +STAN_GetCERTCertificateName(NSSCertificate *c); + /* exposing this */ NSS_EXTERN NSSCertificate * NSSCertificate_Create