2001-07-20 00:41:38 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Netscape security libraries.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU General Public License Version 2 or later (the
|
|
|
|
* "GPL"), in which case the provisions of the GPL are applicable
|
|
|
|
* instead of those above. If you wish to allow use of your
|
|
|
|
* version of this file only under the terms of the GPL and not to
|
|
|
|
* allow others to use your version of this file under the MPL,
|
|
|
|
* indicate your decision by deleting the provisions above and
|
|
|
|
* replace them with the notice and other provisions required by
|
|
|
|
* the GPL. If you do not delete the provisions above, a recipient
|
|
|
|
* may use your version of this file under either the MPL or the
|
|
|
|
* GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-04-18 21:30:05 +04:00
|
|
|
static const char CVS_ID[] = "@(#) $RCSfile: trustdomain.c,v $ $Revision: 1.39 $ $Date: 2002-04-18 17:30:05 $ $Name: $";
|
2001-07-20 00:41:38 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
#ifndef DEV_H
|
|
|
|
#include "dev.h"
|
|
|
|
#endif /* DEV_H */
|
2001-10-11 20:34:49 +04:00
|
|
|
|
|
|
|
#ifndef PKIM_H
|
|
|
|
#include "pkim.h"
|
|
|
|
#endif /* PKIM_H */
|
2001-09-14 02:16:22 +04:00
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
#ifndef PKI1T_H
|
|
|
|
#include "pki1t.h"
|
|
|
|
#endif /* PKI1T_H */
|
2001-09-20 01:49:52 +04:00
|
|
|
|
2002-01-24 03:34:03 +03:00
|
|
|
#ifdef NSS_3_4_CODE
|
|
|
|
#include "cert.h"
|
2002-01-24 18:45:55 +03:00
|
|
|
#include "pki3hack.h"
|
2002-01-24 03:34:03 +03:00
|
|
|
#endif
|
|
|
|
|
2001-10-11 20:34:49 +04:00
|
|
|
#define NSSTRUSTDOMAIN_DEFAULT_CACHE_SIZE 32
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
#ifdef PURE_STAN_BUILD
|
|
|
|
struct NSSTrustDomainStr {
|
|
|
|
PRInt32 refCount;
|
|
|
|
NSSArena *arena;
|
|
|
|
NSSCallback *defaultCallback;
|
|
|
|
struct {
|
|
|
|
nssSlotList *forCerts;
|
|
|
|
nssSlotList *forCiphers;
|
|
|
|
nssSlotList *forTrust;
|
|
|
|
} slots;
|
|
|
|
nssCertificateCache *cache;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern const NSSError NSS_ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
typedef PRUint32 nssUpdateLevel;
|
2001-10-11 20:34:49 +04:00
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSTrustDomain *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_Create
|
|
|
|
(
|
|
|
|
NSSUTF8 *moduleOpt,
|
|
|
|
NSSUTF8 *uriOpt,
|
|
|
|
NSSUTF8 *opaqueOpt,
|
|
|
|
void *reserved
|
|
|
|
)
|
|
|
|
{
|
2001-09-14 02:16:22 +04:00
|
|
|
NSSArena *arena;
|
|
|
|
NSSTrustDomain *rvTD;
|
|
|
|
arena = NSSArena_Create();
|
|
|
|
if(!arena) {
|
|
|
|
return (NSSTrustDomain *)NULL;
|
|
|
|
}
|
|
|
|
rvTD = nss_ZNEW(arena, NSSTrustDomain);
|
|
|
|
if (!rvTD) {
|
2001-09-21 00:40:03 +04:00
|
|
|
goto loser;
|
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
nssTrustDomain_InitializeCache(rvTD, NSSTRUSTDOMAIN_DEFAULT_CACHE_SIZE);
|
2001-09-14 02:16:22 +04:00
|
|
|
rvTD->arena = arena;
|
2001-09-19 00:55:01 +04:00
|
|
|
rvTD->refCount = 1;
|
2002-01-10 03:45:27 +03:00
|
|
|
#ifdef NSS_3_4_CODE
|
|
|
|
rvTD->statusConfig = NULL;
|
|
|
|
#endif
|
2001-09-14 02:16:22 +04:00
|
|
|
return rvTD;
|
2001-09-21 00:40:03 +04:00
|
|
|
loser:
|
|
|
|
nssArena_Destroy(arena);
|
|
|
|
return (NSSTrustDomain *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-12 21:54:50 +04:00
|
|
|
token_destructor(void *t)
|
2001-09-21 00:40:03 +04:00
|
|
|
{
|
2001-10-12 21:54:50 +04:00
|
|
|
NSSToken *tok = (NSSToken *)t;
|
|
|
|
/* in 3.4, also destroy the slot (managed separately) */
|
|
|
|
(void)nssSlot_Destroy(tok->slot);
|
2002-04-18 21:30:05 +04:00
|
|
|
nssToken_Destroy(tok);
|
2001-09-21 00:40:03 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_Destroy
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td
|
|
|
|
)
|
|
|
|
{
|
2001-09-19 00:55:01 +04:00
|
|
|
if (--td->refCount == 0) {
|
2001-10-11 20:34:49 +04:00
|
|
|
/* Destroy each token in the list of tokens */
|
|
|
|
if (td->tokens) {
|
2002-01-08 18:37:42 +03:00
|
|
|
nssListIterator_Destroy(td->tokens);
|
2001-11-28 19:23:51 +03:00
|
|
|
nssList_Clear(td->tokenList, token_destructor);
|
|
|
|
nssList_Destroy(td->tokenList);
|
2001-09-21 00:40:03 +04:00
|
|
|
}
|
2001-11-29 22:34:08 +03:00
|
|
|
nssTrustDomain_DestroyCache(td);
|
2001-09-21 00:40:03 +04:00
|
|
|
/* Destroy the trust domain */
|
2001-09-19 00:55:01 +04:00
|
|
|
nssArena_Destroy(td->arena);
|
|
|
|
}
|
|
|
|
return PR_SUCCESS;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
/* XXX uses tokens until slot list is in place */
|
|
|
|
static NSSSlot **
|
|
|
|
nssTrustDomain_GetActiveSlots
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
nssUpdateLevel *updateLevel
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PRUint32 count;
|
|
|
|
NSSSlot **slots = NULL;
|
|
|
|
NSSToken **tp, **tokens;
|
|
|
|
*updateLevel = 1;
|
|
|
|
count = nssList_Count(td->tokenList);
|
|
|
|
tokens = nss_ZNEWARRAY(NULL, NSSToken *, count + 1);
|
|
|
|
if (!tokens) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
slots = nss_ZNEWARRAY(NULL, NSSSlot *, count + 1);
|
|
|
|
if (!slots) {
|
|
|
|
nss_ZFreeIf(tokens);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
nssList_GetArray(td->tokenList, (void **)tokens, count);
|
|
|
|
count = 0;
|
|
|
|
for (tp = tokens; *tp; tp++) {
|
|
|
|
slots[count++] = nssToken_GetSlot(*tp);
|
|
|
|
}
|
|
|
|
nss_ZFreeIf(tokens);
|
|
|
|
return slots;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
static nssSession *
|
|
|
|
nssTrustDomain_GetSessionForToken
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSToken *token
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssToken_GetDefaultSession(token);
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_SetDefaultCallback
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCallback *newCallback,
|
|
|
|
NSSCallback **oldCallbackOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
if (oldCallbackOpt) {
|
|
|
|
*oldCallbackOpt = td->defaultCallback;
|
|
|
|
}
|
|
|
|
td->defaultCallback = newCallback;
|
|
|
|
return PR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCallback *
|
|
|
|
nssTrustDomain_GetDefaultCallback
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
PRStatus *statusOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (statusOpt) {
|
|
|
|
*statusOpt = PR_SUCCESS;
|
|
|
|
}
|
|
|
|
return td->defaultCallback;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCallback *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_GetDefaultCallback
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
PRStatus *statusOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
return nssTrustDomain_GetDefaultCallback(td, statusOpt);
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_LoadModule
|
|
|
|
(
|
2001-09-14 02:16:22 +04:00
|
|
|
NSSTrustDomain *td,
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSUTF8 *moduleOpt,
|
|
|
|
NSSUTF8 *uriOpt,
|
|
|
|
NSSUTF8 *opaqueOpt,
|
|
|
|
void *reserved
|
|
|
|
)
|
|
|
|
{
|
2001-10-11 20:34:49 +04:00
|
|
|
return PR_FAILURE;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_DisableToken
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSToken *token,
|
|
|
|
NSSError why
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_EnableToken
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSToken *token
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_IsTokenEnabled
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSToken *token,
|
|
|
|
NSSError *whyOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSSlot *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindSlotByName
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *slotName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSToken *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindTokenByName
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *tokenName
|
|
|
|
)
|
|
|
|
{
|
2001-10-17 18:40:27 +04:00
|
|
|
PRStatus nssrv;
|
|
|
|
NSSUTF8 *myName;
|
|
|
|
NSSToken *tok = NULL;
|
|
|
|
for (tok = (NSSToken *)nssListIterator_Start(td->tokens);
|
|
|
|
tok != (NSSToken *)NULL;
|
|
|
|
tok = (NSSToken *)nssListIterator_Next(td->tokens))
|
|
|
|
{
|
|
|
|
myName = nssToken_GetName(tok);
|
|
|
|
if (nssUTF8_Equal(tokenName, myName, &nssrv)) break;
|
|
|
|
}
|
|
|
|
nssListIterator_Finish(td->tokens);
|
|
|
|
return tok;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSToken *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindTokenBySlotName
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *slotName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSToken *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindTokenForAlgorithm
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSOID *algorithm
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSToken *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindBestTokenForAlgorithms
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSOID *algorithms[], /* may be null-terminated */
|
|
|
|
PRUint32 nAlgorithmsOpt /* limits the array if nonzero */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_Login
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_Logout
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCertificate *c
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportPKIXCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
/* declared as a struct until these "data types" are defined */
|
|
|
|
struct NSSPKIXCertificateStr *pc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportEncodedCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportEncodedCertificateChain
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber,
|
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt, /* 0 for no max */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSPrivateKey *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportEncodedPrivateKey
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber,
|
|
|
|
NSSItem *passwordOpt, /* NULL will cause a callback */
|
|
|
|
NSSCallback *uhhOpt,
|
|
|
|
NSSToken *destination
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSPublicKey *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_ImportEncodedPublicKey
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
static NSSCertificate **
|
|
|
|
get_certs_from_list(nssList *list)
|
2002-01-03 23:09:30 +03:00
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
PRUint32 count = nssList_Count(list);
|
|
|
|
NSSCertificate **certs = NULL;
|
|
|
|
if (count > 0) {
|
|
|
|
certs = nss_ZNEWARRAY(NULL, NSSCertificate *, count + 1);
|
|
|
|
if (certs) {
|
|
|
|
nssList_GetArray(list, (void **)certs, count);
|
|
|
|
}
|
2001-10-11 20:34:49 +04:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
return certs;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
|
|
|
nssTrustDomain_FindCertificatesByNickname
|
2001-10-12 21:54:50 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *name,
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt, /* 0 for no max */
|
|
|
|
NSSArena *arenaOpt
|
2001-10-12 21:54:50 +04:00
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
PRStatus status;
|
|
|
|
PRUint32 numRemaining;
|
|
|
|
NSSToken *token = NULL;
|
|
|
|
NSSSlot **slots = NULL;
|
|
|
|
NSSSlot **slotp;
|
|
|
|
NSSCertificate **rvCerts = NULL;
|
|
|
|
nssPKIObjectCollection *collection = NULL;
|
|
|
|
nssUpdateLevel updateLevel;
|
2001-10-12 21:54:50 +04:00
|
|
|
nssList *nameList;
|
2002-04-15 19:22:11 +04:00
|
|
|
/* First, grab from the cache */
|
2001-10-12 21:54:50 +04:00
|
|
|
nameList = nssList_Create(NULL, PR_FALSE);
|
2002-04-15 19:22:11 +04:00
|
|
|
if (!nameList) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-12 21:54:50 +04:00
|
|
|
(void)nssTrustDomain_GetCertsForNicknameFromCache(td, name, nameList);
|
2002-04-15 19:22:11 +04:00
|
|
|
rvCerts = get_certs_from_list(nameList);
|
|
|
|
/* initialize the collection of token certificates with the set of
|
|
|
|
* cached certs (if any).
|
|
|
|
*/
|
|
|
|
collection = nssCertificateCollection_Create(td, rvCerts);
|
|
|
|
nssCertificateArray_Destroy(rvCerts);
|
|
|
|
nssList_Destroy(nameList);
|
|
|
|
if (!collection) {
|
|
|
|
return (NSSCertificate **)NULL;
|
|
|
|
}
|
|
|
|
/* obtain the current set of active slots in the trust domain */
|
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
/* iterate over the slots */
|
|
|
|
numRemaining = maximumOpt;
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
|
|
|
if (token) {
|
|
|
|
nssSession *session;
|
|
|
|
nssCryptokiObject **instances;
|
|
|
|
nssTokenSearchType tokenOnly = nssTokenSearchType_TokenOnly;
|
|
|
|
session = nssTrustDomain_GetSessionForToken(td, token);
|
|
|
|
if (!session) {
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
instances = nssToken_FindCertificatesByNickname(token,
|
|
|
|
session,
|
|
|
|
name,
|
|
|
|
tokenOnly,
|
|
|
|
numRemaining,
|
|
|
|
&status);
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
if (instances) {
|
|
|
|
status = nssPKIObjectCollection_AddInstances(collection,
|
|
|
|
instances, 0);
|
|
|
|
nss_ZFreeIf(instances);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
if (maximumOpt > 0) {
|
|
|
|
PRUint32 count;
|
|
|
|
count = nssPKIObjectCollection_Count(collection);
|
|
|
|
numRemaining = maximumOpt - count;
|
|
|
|
if (numRemaining == 0) break;
|
|
|
|
}
|
|
|
|
}
|
2002-02-28 01:41:56 +03:00
|
|
|
}
|
2001-10-12 21:54:50 +04:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
/* Grab the certs collected in the search. */
|
|
|
|
rvCerts = nssPKIObjectCollection_GetCertificates(collection,
|
|
|
|
rvOpt, maximumOpt,
|
|
|
|
arenaOpt);
|
|
|
|
/* clean up */
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
return rvCerts;
|
|
|
|
loser:
|
|
|
|
if (slots) {
|
|
|
|
nssSlotArray_Destroy(slots);
|
2001-11-28 19:23:51 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
if (collection) {
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
}
|
|
|
|
return (NSSCertificate **)NULL;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-10-17 18:40:27 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
|
|
|
NSSTrustDomain_FindCertificatesByNickname
|
2001-10-11 20:34:49 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
2001-10-17 18:40:27 +04:00
|
|
|
NSSUTF8 *name,
|
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt, /* 0 for no max */
|
|
|
|
NSSArena *arenaOpt
|
2001-10-11 20:34:49 +04:00
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
return nssTrustDomain_FindCertificatesByNickname(td,
|
|
|
|
name,
|
|
|
|
rvOpt,
|
|
|
|
maximumOpt,
|
|
|
|
arenaOpt);
|
2002-02-28 01:41:56 +03:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2002-04-15 19:22:11 +04:00
|
|
|
nssTrustDomain_FindBestCertificateByNickname
|
2001-07-20 00:41:38 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSUTF8 *name,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
2001-07-20 00:41:38 +04:00
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSCertificate **nicknameCerts;
|
2001-10-12 21:54:50 +04:00
|
|
|
NSSCertificate *rvCert = NULL;
|
2002-04-15 19:22:11 +04:00
|
|
|
nicknameCerts = nssTrustDomain_FindCertificatesByNickname(td, name,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (nicknameCerts) {
|
|
|
|
rvCert = nssCertificateArray_FindBestCertificate(nicknameCerts,
|
|
|
|
timeOpt,
|
|
|
|
usage,
|
|
|
|
policiesOpt);
|
|
|
|
nssCertificateArray_Destroy(nicknameCerts);
|
2001-10-12 21:54:50 +04:00
|
|
|
}
|
|
|
|
return rvCert;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSTrustDomain_FindBestCertificateByNickname
|
2001-07-20 00:41:38 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSUTF8 *name,
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
return nssTrustDomain_FindBestCertificateByNickname(td,
|
|
|
|
name,
|
|
|
|
timeOpt,
|
|
|
|
usage,
|
|
|
|
policiesOpt);
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2002-04-15 19:22:11 +04:00
|
|
|
nssTrustDomain_FindCertificatesBySubject
|
2001-07-20 00:41:38 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
2001-10-12 21:54:50 +04:00
|
|
|
NSSDER *subject,
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSCertificate *rvOpt[],
|
2002-04-15 19:22:11 +04:00
|
|
|
PRUint32 maximumOpt,
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
PRStatus status;
|
|
|
|
PRUint32 numRemaining;
|
|
|
|
NSSToken *token = NULL;
|
|
|
|
NSSSlot **slots = NULL;
|
|
|
|
NSSSlot **slotp;
|
2001-10-12 21:54:50 +04:00
|
|
|
NSSCertificate **rvCerts = NULL;
|
2002-04-15 19:22:11 +04:00
|
|
|
nssPKIObjectCollection *collection = NULL;
|
|
|
|
nssUpdateLevel updateLevel;
|
2001-10-12 21:54:50 +04:00
|
|
|
nssList *subjectList;
|
2002-04-15 19:22:11 +04:00
|
|
|
/* look in cache */
|
2001-10-12 21:54:50 +04:00
|
|
|
subjectList = nssList_Create(NULL, PR_FALSE);
|
2002-04-15 19:22:11 +04:00
|
|
|
if (!subjectList) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-12 21:54:50 +04:00
|
|
|
(void)nssTrustDomain_GetCertsForSubjectFromCache(td, subject, subjectList);
|
2002-04-15 19:22:11 +04:00
|
|
|
rvCerts = get_certs_from_list(subjectList);
|
|
|
|
collection = nssCertificateCollection_Create(td, rvCerts);
|
|
|
|
nssCertificateArray_Destroy(rvCerts);
|
|
|
|
nssList_Destroy(subjectList);
|
|
|
|
if (!collection) {
|
|
|
|
return (NSSCertificate **)NULL;
|
2001-11-28 19:23:51 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
numRemaining = maximumOpt;
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
|
|
|
if (token) {
|
|
|
|
nssSession *session;
|
|
|
|
nssCryptokiObject **instances;
|
|
|
|
nssTokenSearchType tokenOnly = nssTokenSearchType_TokenOnly;
|
|
|
|
session = nssTrustDomain_GetSessionForToken(td, token);
|
|
|
|
if (!session) {
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
instances = nssToken_FindCertificatesBySubject(token,
|
|
|
|
session,
|
|
|
|
subject,
|
|
|
|
tokenOnly,
|
|
|
|
numRemaining,
|
|
|
|
&status);
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
if (instances) {
|
|
|
|
status = nssPKIObjectCollection_AddInstances(collection,
|
|
|
|
instances, 0);
|
|
|
|
nss_ZFreeIf(instances);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
if (maximumOpt > 0) {
|
|
|
|
PRUint32 count;
|
|
|
|
count = nssPKIObjectCollection_Count(collection);
|
|
|
|
numRemaining = maximumOpt - count;
|
|
|
|
if (numRemaining == 0) break;
|
|
|
|
}
|
|
|
|
}
|
2001-11-28 19:23:51 +03:00
|
|
|
}
|
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
rvCerts = nssPKIObjectCollection_GetCertificates(collection,
|
|
|
|
rvOpt, maximumOpt,
|
|
|
|
arenaOpt);
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
nssSlotArray_Destroy(slots);
|
2001-10-12 21:54:50 +04:00
|
|
|
return rvCerts;
|
2002-04-15 19:22:11 +04:00
|
|
|
loser:
|
|
|
|
if (slots) {
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
}
|
|
|
|
if (collection) {
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
}
|
|
|
|
return (NSSCertificate **)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
|
|
|
NSSTrustDomain_FindCertificatesBySubject
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSDER *subject,
|
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt,
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssTrustDomain_FindCertificatesBySubject(td,
|
|
|
|
subject,
|
|
|
|
rvOpt,
|
|
|
|
maximumOpt,
|
|
|
|
arenaOpt);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
|
|
|
nssTrustDomain_FindBestCertificateBySubject
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSDER *subject,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
NSSCertificate **subjectCerts;
|
|
|
|
NSSCertificate *rvCert = NULL;
|
|
|
|
subjectCerts = nssTrustDomain_FindCertificatesBySubject(td, subject,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (subjectCerts) {
|
|
|
|
rvCert = nssCertificateArray_FindBestCertificate(subjectCerts,
|
|
|
|
timeOpt,
|
|
|
|
usage,
|
|
|
|
policiesOpt);
|
|
|
|
nssCertificateArray_Destroy(subjectCerts);
|
|
|
|
}
|
|
|
|
return rvCert;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
|
|
|
NSSTrustDomain_FindBestCertificateBySubject
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSDER *subject,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssTrustDomain_FindBestCertificateBySubject(td,
|
|
|
|
subject,
|
|
|
|
timeOpt,
|
|
|
|
usage,
|
|
|
|
policiesOpt);
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindBestCertificateByNameComponents
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *nameComponents,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindCertificatesByNameComponents
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *nameComponents,
|
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt, /* 0 for no max */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2002-04-15 19:22:11 +04:00
|
|
|
nssTrustDomain_FindCertificateByIssuerAndSerialNumber
|
2001-07-20 00:41:38 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSDER *issuer,
|
|
|
|
NSSDER *serial
|
2001-07-20 00:41:38 +04:00
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
PRStatus status;
|
|
|
|
NSSToken *token = NULL;
|
|
|
|
NSSSlot **slots = NULL;
|
|
|
|
NSSSlot **slotp;
|
2001-10-12 21:54:50 +04:00
|
|
|
NSSCertificate *rvCert = NULL;
|
2002-04-15 19:22:11 +04:00
|
|
|
nssPKIObjectCollection *collection = NULL;
|
|
|
|
nssUpdateLevel updateLevel;
|
|
|
|
/* see if this search is already cached */
|
|
|
|
rvCert = nssTrustDomain_GetCertForIssuerAndSNFromCache(td,
|
|
|
|
issuer,
|
|
|
|
serial);
|
2001-11-28 19:23:51 +03:00
|
|
|
if (rvCert) {
|
|
|
|
return rvCert;
|
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
|
|
|
if (token) {
|
|
|
|
nssSession *session;
|
|
|
|
nssCryptokiObject *instance;
|
|
|
|
nssTokenSearchType tokenOnly = nssTokenSearchType_TokenOnly;
|
|
|
|
session = nssTrustDomain_GetSessionForToken(td, token);
|
|
|
|
if (!session) {
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
instance = nssToken_FindCertificateByIssuerAndSerialNumber(
|
|
|
|
token,
|
|
|
|
session,
|
|
|
|
issuer,
|
|
|
|
serial,
|
|
|
|
tokenOnly,
|
|
|
|
&status);
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
if (instance) {
|
|
|
|
if (!collection) {
|
|
|
|
collection = nssCertificateCollection_Create(td, NULL);
|
|
|
|
if (!collection) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nssPKIObjectCollection_AddInstances(collection,
|
|
|
|
&instance, 1);
|
|
|
|
}
|
2002-02-01 20:25:15 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
}
|
|
|
|
if (collection) {
|
|
|
|
(void)nssPKIObjectCollection_GetCertificates(collection,
|
|
|
|
&rvCert, 1, NULL);
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
if (!rvCert) {
|
|
|
|
goto loser;
|
2001-10-12 21:54:50 +04:00
|
|
|
}
|
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
return rvCert;
|
|
|
|
loser:
|
|
|
|
if (collection) {
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
}
|
|
|
|
if (slots) {
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
}
|
|
|
|
return (NSSCertificate *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
|
|
|
NSSTrustDomain_FindCertificateByIssuerAndSerialNumber
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSDER *issuer,
|
|
|
|
NSSDER *serial
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssTrustDomain_FindCertificateByIssuerAndSerialNumber(td,
|
|
|
|
issuer,
|
|
|
|
serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
|
|
|
nssTrustDomain_FindCertificateByEncodedCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PRStatus status;
|
|
|
|
NSSCertificate *rvCert = NULL;
|
|
|
|
NSSDER issuer = { 0 };
|
|
|
|
NSSDER serial = { 0 };
|
|
|
|
NSSArena *arena = nssArena_Create();
|
|
|
|
if (!arena) {
|
|
|
|
return (NSSCertificate *)NULL;
|
|
|
|
}
|
|
|
|
/* XXX this is not generic... will any cert crack into issuer/serial? */
|
|
|
|
status = nssPKIX509_GetIssuerAndSerialFromDER(ber, arena, &issuer, &serial);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
rvCert = nssTrustDomain_FindCertificateByIssuerAndSerialNumber(td,
|
|
|
|
&issuer,
|
|
|
|
&serial);
|
|
|
|
finish:
|
|
|
|
nssArena_Destroy(arena);
|
2001-10-12 21:54:50 +04:00
|
|
|
return rvCert;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2002-04-15 19:22:11 +04:00
|
|
|
NSSTrustDomain_FindCertificateByEncodedCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSBER *ber
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssTrustDomain_FindCertificateByEncodedCertificate(td, ber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
|
|
|
NSSTrustDomain_FindBestCertificateByEmail
|
2001-07-20 00:41:38 +04:00
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSASCII7 *email,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
return 0;
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindCertificatesByEmail
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSASCII7 *email,
|
|
|
|
NSSCertificate *rvOpt[],
|
|
|
|
PRUint32 maximumOpt, /* 0 for no max */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindCertificateByOCSPHash
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSItem *hash
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindBestUserCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usage,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindUserCertificates
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSTime *timeOpt,
|
|
|
|
NSSUsage *usageOpt,
|
|
|
|
NSSPolicies *policiesOpt,
|
|
|
|
NSSCertificate **rvOpt,
|
|
|
|
PRUint32 rvLimit, /* zero for no limit */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindBestUserCertificateForSSLClientAuth
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *sslHostOpt,
|
|
|
|
NSSDER *rootCAsOpt[], /* null pointer for none */
|
|
|
|
PRUint32 rootCAsMaxOpt, /* zero means list is null-terminated */
|
|
|
|
NSSAlgorithmAndParameters *apOpt,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindUserCertificatesForSSLClientAuth
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSUTF8 *sslHostOpt,
|
|
|
|
NSSDER *rootCAsOpt[], /* null pointer for none */
|
|
|
|
PRUint32 rootCAsMaxOpt, /* zero means list is null-terminated */
|
|
|
|
NSSAlgorithmAndParameters *apOpt,
|
|
|
|
NSSPolicies *policiesOpt,
|
|
|
|
NSSCertificate **rvOpt,
|
|
|
|
PRUint32 rvLimit, /* zero for no limit */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindBestUserCertificateForEmailSigning
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSASCII7 *signerOpt,
|
|
|
|
NSSASCII7 *recipientOpt,
|
|
|
|
/* anything more here? */
|
|
|
|
NSSAlgorithmAndParameters *apOpt,
|
|
|
|
NSSPolicies *policiesOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCertificate **
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindUserCertificatesForEmailSigning
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSASCII7 *signerOpt,
|
|
|
|
NSSASCII7 *recipientOpt,
|
|
|
|
/* anything more here? */
|
|
|
|
NSSAlgorithmAndParameters *apOpt,
|
|
|
|
NSSPolicies *policiesOpt,
|
|
|
|
NSSCertificate **rvOpt,
|
|
|
|
PRUint32 rvLimit, /* zero for no limit */
|
|
|
|
NSSArena *arenaOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-01-23 23:35:18 +03:00
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus *
|
|
|
|
NSSTrustDomain_TraverseCertificates
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
PRStatus (*callback)(NSSCertificate *c, void *arg),
|
|
|
|
void *arg
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
PRStatus status;
|
|
|
|
NSSToken *token = NULL;
|
|
|
|
NSSSlot **slots = NULL;
|
|
|
|
NSSSlot **slotp;
|
|
|
|
nssPKIObjectCollection *collection = NULL;
|
|
|
|
nssPKIObjectCallback pkiCallback;
|
|
|
|
nssUpdateLevel updateLevel;
|
|
|
|
NSSCertificate **cached = NULL;
|
|
|
|
nssList *certList;
|
2001-11-30 01:05:32 +03:00
|
|
|
certList = nssList_Create(NULL, PR_FALSE);
|
2002-01-23 23:35:18 +03:00
|
|
|
if (!certList) return NULL;
|
2001-11-28 19:23:51 +03:00
|
|
|
(void *)nssTrustDomain_GetCertsFromCache(td, certList);
|
2002-04-15 19:22:11 +04:00
|
|
|
cached = get_certs_from_list(certList);
|
|
|
|
collection = nssCertificateCollection_Create(td, cached);
|
|
|
|
nssCertificateArray_Destroy(cached);
|
|
|
|
nssList_Destroy(certList);
|
|
|
|
if (!collection) {
|
|
|
|
return (PRStatus *)NULL;
|
2002-02-28 01:41:56 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
/* obtain the current set of active slots in the trust domain */
|
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
goto loser;
|
2002-02-08 18:13:13 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
/* iterate over the slots */
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
/* get the token for the slot, if present */
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
|
|
|
if (token) {
|
|
|
|
nssSession *session;
|
|
|
|
nssCryptokiObject **instances;
|
|
|
|
nssTokenSearchType tokenOnly = nssTokenSearchType_TokenOnly;
|
|
|
|
/* get a session for the token */
|
|
|
|
session = nssTrustDomain_GetSessionForToken(td, token);
|
|
|
|
if (!session) {
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
/* perform the traversal */
|
|
|
|
instances = nssToken_FindCertificates(token,
|
|
|
|
session,
|
|
|
|
tokenOnly,
|
|
|
|
0, &status);
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
/* add the found certificates to the collection */
|
|
|
|
status = nssPKIObjectCollection_AddInstances(collection,
|
|
|
|
instances, 0);
|
|
|
|
nss_ZFreeIf(instances);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
2002-02-28 01:41:56 +03:00
|
|
|
}
|
2001-11-20 21:28:49 +03:00
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
/* Traverse the collection */
|
|
|
|
pkiCallback.func.cert = callback;
|
|
|
|
pkiCallback.arg = arg;
|
|
|
|
status = nssPKIObjectCollection_Traverse(collection, &pkiCallback);
|
|
|
|
/* clean up */
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
nssSlotArray_Destroy(slots);
|
2001-11-28 19:23:51 +03:00
|
|
|
return NULL;
|
2002-04-15 19:22:11 +04:00
|
|
|
loser:
|
|
|
|
if (slots) {
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
}
|
|
|
|
if (collection) {
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSTrust *
|
|
|
|
nssTrustDomain_FindTrustForCertificate
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCertificate *c
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PRStatus status;
|
|
|
|
NSSSlot **slots;
|
|
|
|
NSSSlot **slotp;
|
|
|
|
NSSToken *token;
|
|
|
|
nssCryptokiObject *to = NULL;
|
|
|
|
nssPKIObject *pkio = NULL;
|
|
|
|
NSSTrust *rvt = NULL;
|
|
|
|
nssUpdateLevel updateLevel;
|
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
return (NSSTrust *)NULL;
|
|
|
|
}
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
2002-04-18 21:30:05 +04:00
|
|
|
if (token) {
|
|
|
|
to = nssToken_FindTrustForCertificate(token, NULL,
|
|
|
|
&c->encoding,
|
|
|
|
&c->issuer,
|
|
|
|
&c->serial,
|
2002-04-15 19:22:11 +04:00
|
|
|
nssTokenSearchType_TokenOnly);
|
2002-04-18 21:30:05 +04:00
|
|
|
if (to) {
|
2002-04-15 19:22:11 +04:00
|
|
|
if (!pkio) {
|
2002-04-18 21:30:05 +04:00
|
|
|
pkio = nssPKIObject_Create(NULL, to, td, NULL);
|
|
|
|
if (!pkio) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status = nssPKIObject_AddInstance(pkio, to);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
2002-04-15 19:22:11 +04:00
|
|
|
}
|
|
|
|
}
|
2002-04-18 21:30:05 +04:00
|
|
|
nssToken_Destroy(token);
|
2002-04-15 19:22:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkio) {
|
|
|
|
rvt = nssTrust_Create(pkio);
|
|
|
|
if (!rvt) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
return rvt;
|
|
|
|
loser:
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
if (to) {
|
|
|
|
nssCryptokiObject_Destroy(to);
|
|
|
|
}
|
|
|
|
if (pkio) {
|
|
|
|
nssPKIObject_Destroy(pkio);
|
|
|
|
}
|
|
|
|
return (NSSTrust *)NULL;
|
2001-09-14 02:16:22 +04:00
|
|
|
}
|
2001-07-20 00:41:38 +04:00
|
|
|
|
2002-04-18 21:30:05 +04:00
|
|
|
NSS_IMPLEMENT NSSCRL **
|
|
|
|
nssTrustDomain_FindCRLsBySubject
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSDER *subject
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PRStatus status;
|
|
|
|
NSSSlot **slots;
|
|
|
|
NSSSlot **slotp;
|
|
|
|
NSSToken *token;
|
|
|
|
nssUpdateLevel updateLevel;
|
|
|
|
nssPKIObjectCollection *collection;
|
|
|
|
NSSCRL **rvCRLs = NULL;
|
|
|
|
collection = nssCRLCollection_Create(td, NULL);
|
|
|
|
if (!collection) {
|
|
|
|
return (NSSCRL **)NULL;
|
|
|
|
}
|
|
|
|
slots = nssTrustDomain_GetActiveSlots(td, &updateLevel);
|
|
|
|
if (!slots) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
for (slotp = slots; *slotp; slotp++) {
|
|
|
|
token = nssSlot_GetToken(*slotp);
|
|
|
|
if (token) {
|
|
|
|
nssSession *session;
|
|
|
|
nssCryptokiObject **instances;
|
|
|
|
nssTokenSearchType tokenOnly = nssTokenSearchType_TokenOnly;
|
|
|
|
/* get a session for the token */
|
|
|
|
session = nssTrustDomain_GetSessionForToken(td, token);
|
|
|
|
if (!session) {
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
/* perform the traversal */
|
|
|
|
instances = nssToken_FindCRLsBySubject(token, session, subject,
|
|
|
|
tokenOnly, 0, &status);
|
|
|
|
nssToken_Destroy(token);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
/* add the found CRL's to the collection */
|
|
|
|
status = nssPKIObjectCollection_AddInstances(collection,
|
|
|
|
instances, 0);
|
|
|
|
nss_ZFreeIf(instances);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rvCRLs = nssPKIObjectCollection_GetCRLs(collection, NULL, 0, NULL);
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
return rvCRLs;
|
|
|
|
loser:
|
|
|
|
nssPKIObjectCollection_Destroy(collection);
|
|
|
|
nssSlotArray_Destroy(slots);
|
|
|
|
return (NSSCRL **)NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT PRStatus
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_GenerateKeyPair
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSAlgorithmAndParameters *ap,
|
|
|
|
NSSPrivateKey **pvkOpt,
|
|
|
|
NSSPublicKey **pbkOpt,
|
|
|
|
PRBool privateKeyIsSensitive,
|
|
|
|
NSSToken *destination,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSSymmetricKey *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_GenerateSymmetricKey
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSAlgorithmAndParameters *ap,
|
|
|
|
PRUint32 keysize,
|
|
|
|
NSSToken *destination,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSSymmetricKey *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_GenerateSymmetricKeyFromPassword
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSAlgorithmAndParameters *ap,
|
|
|
|
NSSUTF8 *passwordOpt, /* if null, prompt */
|
|
|
|
NSSToken *destinationOpt,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSSymmetricKey *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_FindSymmetricKeyByAlgorithmAndKeyID
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSOID *algorithm,
|
|
|
|
NSSItem *keyID,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-15 19:22:11 +04:00
|
|
|
NSS_IMPLEMENT NSSCryptoContext *
|
|
|
|
nssTrustDomain_CreateCryptoContext
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return nssCryptoContext_Create(td, uhhOpt);
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCryptoContext *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_CreateCryptoContext
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSCallback *uhhOpt
|
|
|
|
)
|
|
|
|
{
|
2002-04-15 19:22:11 +04:00
|
|
|
return nssTrustDomain_CreateCryptoContext(td, uhhOpt);
|
2001-07-20 00:41:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCryptoContext *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_CreateCryptoContextForAlgorithm
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSOID *algorithm
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-14 02:16:22 +04:00
|
|
|
NSS_IMPLEMENT NSSCryptoContext *
|
2001-07-20 00:41:38 +04:00
|
|
|
NSSTrustDomain_CreateCryptoContextForAlgorithmAndParameters
|
|
|
|
(
|
|
|
|
NSSTrustDomain *td,
|
|
|
|
NSSAlgorithmAndParameters *ap
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nss_SetError(NSS_ERROR_NOT_FOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|