2001-10-11 20:33: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-01-30 00:10:50 +03:00
|
|
|
static const char CVS_ID[] = "@(#) $RCSfile: dev3hack.c,v $ $Revision: 1.3 $ $Date: 2002/01/29 21:10:50 $ $Name: $";
|
2001-10-11 20:33:38 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2001-11-08 03:15:51 +03:00
|
|
|
#ifndef NSS_3_4_CODE
|
|
|
|
#define NSS_3_4_CODE
|
|
|
|
#endif /* NSS_3_4_CODE */
|
|
|
|
|
2001-10-11 20:33:38 +04:00
|
|
|
#ifndef PKIT_H
|
|
|
|
#include "pkit.h"
|
|
|
|
#endif /* PKIT_H */
|
|
|
|
|
|
|
|
#ifndef DEVT_H
|
|
|
|
#include "devt.h"
|
|
|
|
#endif /* DEVT_H */
|
|
|
|
|
2001-11-08 03:15:51 +03:00
|
|
|
#include "dev3hack.h"
|
2001-10-11 20:33:38 +04:00
|
|
|
|
|
|
|
#ifndef BASE_H
|
|
|
|
#include "base.h"
|
|
|
|
#endif /* BASE_H */
|
|
|
|
|
|
|
|
#include "pk11func.h"
|
|
|
|
#include "secmodti.h"
|
|
|
|
|
|
|
|
NSS_IMPLEMENT nssSession *
|
|
|
|
nssSession_ImportNSS3Session(NSSArena *arenaOpt,
|
|
|
|
CK_SESSION_HANDLE session,
|
|
|
|
PZLock *lock, PRBool rw)
|
|
|
|
{
|
|
|
|
nssSession *rvSession;
|
|
|
|
rvSession = nss_ZNEW(arenaOpt, nssSession);
|
|
|
|
rvSession->handle = session;
|
|
|
|
rvSession->lock = lock;
|
|
|
|
rvSession->isRW = rw;
|
|
|
|
return rvSession;
|
|
|
|
}
|
|
|
|
|
2001-11-05 20:18:48 +03:00
|
|
|
NSS_IMPLEMENT nssSession *
|
|
|
|
nssSlot_CreateSession
|
|
|
|
(
|
|
|
|
NSSSlot *slot,
|
|
|
|
NSSArena *arenaOpt,
|
|
|
|
PRBool readWrite
|
|
|
|
)
|
|
|
|
{
|
|
|
|
nssSession *rvSession;
|
|
|
|
rvSession = nss_ZNEW(arenaOpt, nssSession);
|
|
|
|
if (!rvSession) {
|
|
|
|
return (nssSession *)NULL;
|
|
|
|
}
|
|
|
|
if (readWrite) {
|
|
|
|
rvSession->handle = PK11_GetRWSession(slot->pk11slot);
|
|
|
|
rvSession->isRW = PR_TRUE;
|
|
|
|
rvSession->slot = slot;
|
|
|
|
return rvSession;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT PRStatus
|
|
|
|
nssSession_Destroy
|
|
|
|
(
|
|
|
|
nssSession *s
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CK_RV ckrv = CKR_OK;
|
|
|
|
if (s) {
|
|
|
|
if (s->isRW) {
|
|
|
|
PK11_RestoreROSession(s->slot->pk11slot, s->handle);
|
|
|
|
}
|
|
|
|
nss_ZFreeIf(s);
|
|
|
|
}
|
|
|
|
return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-10-11 20:33:38 +04:00
|
|
|
static NSSSlot *
|
|
|
|
nssSlot_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
|
|
|
|
{
|
|
|
|
NSSSlot *rvSlot;
|
|
|
|
rvSlot = nss_ZNEW(td->arena, NSSSlot);
|
|
|
|
if (!rvSlot) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rvSlot->refCount = 1;
|
|
|
|
rvSlot->pk11slot = nss3slot;
|
|
|
|
rvSlot->epv = nss3slot->functionList;
|
|
|
|
rvSlot->slotID = nss3slot->slotID;
|
|
|
|
rvSlot->trustDomain = td;
|
|
|
|
/* Grab the slot name from the PKCS#11 fixed-length buffer */
|
2002-01-30 00:10:50 +03:00
|
|
|
rvSlot->name = nssUTF8_Duplicate(nss3slot->slot_name,td->arena);
|
2001-10-11 20:33:38 +04:00
|
|
|
return rvSlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_IMPLEMENT NSSToken *
|
|
|
|
nssToken_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
|
|
|
|
{
|
|
|
|
NSSToken *rvToken;
|
|
|
|
rvToken = nss_ZNEW(td->arena, NSSToken);
|
|
|
|
if (!rvToken) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rvToken->refCount = 1;
|
|
|
|
rvToken->pk11slot = nss3slot;
|
|
|
|
rvToken->epv = nss3slot->functionList;
|
|
|
|
rvToken->defaultSession = nssSession_ImportNSS3Session(td->arena,
|
|
|
|
nss3slot->session,
|
|
|
|
nss3slot->sessionLock,
|
|
|
|
nss3slot->defRWSession);
|
|
|
|
rvToken->trustDomain = td;
|
|
|
|
/* Grab the token name from the PKCS#11 fixed-length buffer */
|
2002-01-30 00:10:50 +03:00
|
|
|
rvToken->name = nssUTF8_Duplicate(nss3slot->token_name,td->arena);
|
2001-10-11 20:33:38 +04:00
|
|
|
rvToken->slot = nssSlot_CreateFromPK11SlotInfo(td, nss3slot);
|
|
|
|
rvToken->slot->token = rvToken;
|
2001-11-05 20:18:48 +03:00
|
|
|
rvToken->defaultSession->slot = rvToken->slot;
|
2001-10-11 20:33:38 +04:00
|
|
|
return rvToken;
|
|
|
|
}
|
|
|
|
|
2001-11-08 03:15:51 +03:00
|
|
|
|
|
|
|
NSSTrustDomain *
|
|
|
|
nssToken_GetTrustDomain(NSSToken *token)
|
|
|
|
{
|
|
|
|
return token->trustDomain;
|
|
|
|
}
|
|
|
|
|
2001-10-11 20:33:38 +04:00
|
|
|
typedef enum {
|
|
|
|
nssPK11Event_DefaultSessionRO = 0,
|
|
|
|
nssPK11Event_DefaultSessionRW = 1
|
|
|
|
} nssPK11Event;
|
|
|
|
|
|
|
|
NSS_IMPLEMENT PRStatus
|
|
|
|
nssToken_Nofify
|
|
|
|
(
|
|
|
|
NSSToken *tok,
|
|
|
|
nssPK11Event event
|
|
|
|
)
|
2001-12-07 04:36:25 +03:00
|
|
|
|
2001-10-11 20:33:38 +04:00
|
|
|
{
|
2001-12-07 04:36:25 +03:00
|
|
|
#ifdef notdef
|
2001-10-11 20:33:38 +04:00
|
|
|
switch (event) {
|
|
|
|
default:
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
2001-12-07 04:36:25 +03:00
|
|
|
#endif
|
2001-10-11 20:33:38 +04:00
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|