- This page is part of the SSL Reference that we are migrating into the format described in the MDN Style Guide. If you are inclined to help with this migration, your help would be very much appreciated.
- Upgraded documentation may be found in the Current NSS Reference
PKCS #11 Functions
Chapter 7
PKCS #11 Functions
PK11_FindCertFromNickname
PK11_FindKeyByAnyCert
PK11_GetSlotName
PK11_GetTokenName
PK11_IsHW
PK11_IsPresent
PK11_IsReadOnly
PK11_SetPasswordFunc
PK11_FindCertFromNickname
Finds a certificate from its nickname.
Syntax
#include <pk11func.h> #include <certt.h>
CERTCertificate *PK11_FindCertFromNickname( char *nickname, void *wincx);
Parameters
This function has the following parameters:
nickname |
A pointer to the nickname in the certificate database or to the nickname in the token. |
wincx |
A pointer to application data for the password callback function. This pointer is set with |
Returns
The function returns one of these values:
Description
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.
PK11_FindKeyByAnyCert
Finds the private key associated with a specified certificate in any available slot.
Syntax
#include <pk11func.h> #include <certt.h> #include <keyt.h>
SECKEYPrivateKey *PK11_FindKeyByAnyCert( CERTCertificate *cert, void *wincx);
Parameters
This function has the following parameters:
cert |
A pointer to a certificate structure in the certificate database. |
wincx |
A pointer to application data for the password callback function. This pointer is set with |
Returns
The function returns one of these values:
Description
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.
PK11_GetSlotName
Syntax
#include <pk11func.h>
char *PK11_GetSlotName(PK11SlotInfo *slot);
Parameters
This function has the following parameter:
slot |
Returns
The function returns one of these values:
Description
PK11_GetTokenName
Syntax
#include <pk11func.h>
char *PK11_GetTokenName(PK11SlotInfo *slot);
Parameters
This function has the following parameter:
slot |
Returns
The function returns one of these values:
Description
PK11_IsHW
Finds out whether a slot is implemented in hardware or software.
Syntax
#include <pk11func.h> #include <prtypes.h>
PRBool PK11_IsHW(PK11SlotInfo *slot);
Parameters
This function has the following parameter:
slot |
Returns
The function returns one of these values:
PK11_IsPresent
Finds out whether the token for a slot is available.
Syntax
#include <pk11func.h> #include <prtypes.h>
PRBool PK11_IsPresent(PK11SlotInfo *slot);
Parameters
This function has the following parameter:
slot |
Returns
The function returns one of these values:
PK11_IsReadOnly
Finds out whether a slot is read-only.
Syntax
#include <pk11func.h> #include <prtypes.h>
PRBool PK11_IsReadOnly(PK11SlotInfo *slot);
Parameters
This function has the following parameter:
slot |
Returns
The function returns one of these values:
PK11_SetPasswordFunc
Syntax
#include <pk11func.h> #include <prtypes.h>
void PK11_SetPasswordFunc(PK11PasswordFunc func);
Parameter
This function has the following parameter:
func |
Description
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:
slot |
|
retry |
|
arg |
A pointer supplied by the application that can be used to pass state information. Can be |
This callback function returns one of these values:
- If successful, a pointer to the password. This memory must have been allocated with
PR_Malloc
orPL_strdup
. - If unsuccessful, returns
NULL
.
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
.
See Also
For examples of password callback functions, see the samples in the Samples directory.