1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
** Sample client side test program that uses SSL and NSS
16
#include "ctype.h" /* for isalpha() */
36
fprintf(stderr,"usage: %s [-d profiledir] -t tokenName [-r]\n", progName);
40
int main(int argc, char **argv)
42
char * certDir = NULL;
44
PLOptStatus optstatus;
46
char * tokenName = NULL;
48
PK11TokenEvent event = PK11TokenPresentEvent;
49
PK11TokenStatus status;
53
progName = strrchr(argv[0], '/');
55
progName = strrchr(argv[0], '\\');
56
progName = progName ? progName+1 : argv[0];
58
optstate = PL_CreateOptState(argc, argv, "rd:t:");
59
while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
60
switch (optstate->option) {
63
certDir = strdup(optstate->value);
64
certDir = SECU_ConfigDirectory(certDir);
67
tokenName = strdup(optstate->value);
70
event = PK11TokenRemovedOrChangedEvent;
74
if (optstatus == PL_OPT_BAD)
77
if (tokenName == NULL) {
82
certDir = SECU_DefaultSSLDir(); /* Look in $SSL_DIR */
83
certDir = SECU_ConfigDirectory(certDir); /* call even if it's NULL */
86
PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
88
PK11_SetPasswordFunc(SECU_GetModulePassword);
90
/* open the cert DB, the key DB, and the secmod DB. */
91
rv = NSS_Init(certDir);
92
if (rv != SECSuccess) {
93
SECU_PrintError(progName, "unable to open cert database");
97
printf("Looking up tokenNamed: <%s>\n",tokenName);
98
slot = PK11_FindSlotByName(tokenName);
100
SECU_PrintError(progName, "unable to find token");
106
PK11_WaitForTokenEvent(slot,event,PR_INTERVAL_NO_TIMEOUT, 0, 0);
109
case PK11TokenNotRemovable:
111
printf("%s Token Not Removable\n",tokenName);
113
case PK11TokenChanged:
114
event = PK11TokenRemovedOrChangedEvent;
115
printf("%s Token Changed\n", tokenName);
117
case PK11TokenRemoved:
118
event = PK11TokenPresentEvent;
119
printf("%s Token Removed\n", tokenName);
121
case PK11TokenPresent:
122
event = PK11TokenRemovedOrChangedEvent;
123
printf("%s Token Present\n", tokenName);
130
if (NSS_Shutdown() != SECSuccess) {