Table of Contents | Previous
| Next
| Index
This chapter describes the core PKCS #11 functions that an application needs for communicating with cryptographic modules. In particular, these functions are used for obtaining certificates, keys, and passwords.
PK11_FindCertFromNickname
PK11_FindKeyByAnyCert
PK11_GetSlotName
PK11_GetTokenName
PK11_IsHW
PK11_IsPresent
PK11_IsReadOnly
PK11_SetPasswordFunc
Finds a certificate from its nickname.
#include <pk11func.h>
#include <certt.h>
CERTCertificate *PK11_FindCertFromNickname(
char *nickname,
void *wincx);
This function has the following parameters:
The function returns one of these values:
A nickname is an alias for a certificate subject. There may be multiple certificates with the same subject, and hence the same nickname. This function will return the newest certificate that matches the subject, based on the NotBefore / NotAfter fields of the certificate. When you are finished with the certificate structure returned by PK11_FindCertFromNickname
, you must free it by calling CERT_DestroyCertificate
.
The PK11_FindCertFromNickname
function calls the password callback function set with PK11_SetPasswordFunc
and passes it the pointer specified by the
wincx
parameter.
Finds the private key associated with a specified certificate in any available slot.
#include <pk11func.h>
#include <certt.h>
#include <keyt.h>
SECKEYPrivateKey *PK11_FindKeyByAnyCert(
CERTCertificate *cert,
void *wincx);
This function has the following parameters:
The function returns one of these values:
When you are finished with the private key structure returned by PK11_FindKeyByAnyCert
, you must free it by calling SECKEY_DestroyPrivateKey
.
The PK11_FindKeyByAnyCert
function calls the password callback function set with PK11_SetPasswordFunc
and passes it the pointer specified by the
wincx
parameter.
Gets the name of a slot.
#include <pk11func.h>
char *PK11_GetSlotName(PK11SlotInfo *slot);
This function has the following parameter:
The function returns one of these values:
If the slot is freed, the string with the slot name may also be freed. If you want to
preserve it, copy the string before freeing the slot. Do not try to free the string yourself.
Gets the name of the token.
#include <pk11func.h>
char *PK11_GetTokenName(PK11SlotInfo *slot);
This function has the following parameter:
The function returns one of these values:
If the slot is freed, the string with the token name may also be freed. If you
want to preserve it, copy the string before freeing the slot. Do not try to free the
string yourself.
Finds out whether a slot is implemented in hardware or software.
#include <pk11func.h>
#include <prtypes.h>
PRBool PK11_IsHW(PK11SlotInfo *slot);
This function has the following parameter:
The function returns one of these values:
Finds out whether the token for a slot is available.
#include <pk11func.h>
#include <prtypes.h>
PRBool PK11_IsPresent(PK11SlotInfo *slot);
This function has the following parameter:
The function returns one of these values:
Finds out whether a slot is read-only.
#include <pk11func.h>
#include <prtypes.h>
PRBool PK11_IsReadOnly(PK11SlotInfo *slot);
This function has the following parameter:
The function returns one of these values:
Defines a callback function used by the NSS libraries whenever information protected by a password needs to be retrieved from the key or certificate databases.
#include <pk11func.h>
#include <prtypes.h>
void PK11_SetPasswordFunc(PK11PasswordFunc func);
This function has the following parameter:
During the course of an SSL operation, it may be necessary for the user to log in to a PKCS #11 token (either a smart card or soft token) to access protected information, such as a private key. Such information is protected with a password that can be retrieved by calling an application-supplied callback function. The callback function is identified in a call to PK11_SetPasswordFunc
that takes place during NSS initialization.
The callback function set up by PK11_SetPasswordFunc
has the following prototype:
typedef char *(*PK11PasswordFunc)(
PK11SlotInfo *slot,
PRBool retry,
void *arg);
This callback function has the following parameters:
This callback function returns one of these values:
Many tokens keep track of the number of attempts to enter a password and do not allow further attempts after a certain point. Therefore, if the retry
argument is PR_TRUE
, indicating that the password was tried and is wrong, the callback function should return NULL
to indicate that it is unsuccessful, rather than attempting to return the same password again. Failing to terminate when the retry
argument is PR_TRUE
can result in an endless loop.
Several functions in the NSS libraries use the password callback function to obtain the password before performing operations that involve the protected information. The third parameter to the password callback function is application-defined and can be used for any purpose. For example, Communicator uses the parameter to pass information about which window is associated with the modal dialog box requesting the password from the user. When NSS libraries call the password callback function, the value they pass in the third parameter is determined by SSL_SetPKCS11PinArg
.
For examples of password callback functions, see the samples in the Samples directory.
Table of Contents | Previous
| Next
| Index
Last Updated: 10/18/00 09:17:48