Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 639609 Details for
Bug 873858
PEM support should handle AES- and Camellia-encrypted private keys
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
test program, compile using: cc -Wall -Wextra -o testpem-once `pkg-config --cflags nss` testpem-once.c `pkg-config --libs nss`
testpem-once.c (text/plain), 4.48 KB, created by
Nalin Dahyabhai
on 2012-11-06 20:48:56 UTC
(
hide
)
Description:
test program, compile using: cc -Wall -Wextra -o testpem-once `pkg-config --cflags nss` testpem-once.c `pkg-config --libs nss`
Filename:
MIME Type:
Creator:
Nalin Dahyabhai
Created:
2012-11-06 20:48:56 UTC
Size:
4.48 KB
patch
obsolete
>#include <sys/types.h> >#include <getopt.h> >#include <limits.h> >#include <stdio.h> >#include <unistd.h> > >#include <nspr4/plstr.h> >#include <nspr4/prmem.h> >#include <nss3/nss.h> >#include <nss3/cert.h> >#include <nss3/certdb.h> >#include <nss3/keyhi.h> >#include <nss3/pk11pub.h> >#include <nss3/secmod.h> > >#define DEFAULT_CONFIGDIR "/etc/pki/nssdb" >#define PEM_MODULE "nsspem" > >static char * >pwcb(PK11SlotInfo *slot, PRBool retry, void *arg) >{ > char *tmp, prompt[LINE_MAX]; > const char *password; > static int failcount; > if (retry) { > if (failcount < 3) { > printf("(Again) "); > fflush(NULL); > failcount++; > } else { > return NULL; > } > } else { > failcount = 0; > } > snprintf(prompt, sizeof(prompt), "PIN for token \"%s\": ", > PK11_GetTokenName(slot)); > password = arg ? (const char *) arg : getpass(prompt); > tmp = NULL; > if (password != NULL) { > tmp = PR_Malloc(strlen(password) + 1); > if (tmp != NULL) { > memcpy(tmp, password, strlen(password)); > tmp[strlen(password)] = '\0'; > tmp[strcspn(tmp, "\r\n")] = '\0'; > } > } > return tmp; >} > >int >main(int argc, char **argv) >{ > NSSInitContext *ctx; > SECMODModule *module; > PK11SlotInfo *slot; > CERTCertificate *cert; > CERTCertList *certs; > CERTCertListNode *node; > SECKEYPrivateKey *key; > CK_ATTRIBUTE attrs[4]; > CK_BBOOL cktrue = CK_TRUE, cktrust = CK_FALSE; > CK_OBJECT_CLASS keyclass = CKO_PRIVATE_KEY, certclass = CKO_CERTIFICATE; > char spec[LINE_MAX], *modname, *password = NULL; > void *objs[argc]; > int c, n_objs = 0, retval; > > memset(&objs, 0, sizeof(objs)); > ctx = NSS_InitContext(DEFAULT_CONFIGDIR, > NULL, > NULL, > NULL, > NULL, > NSS_INIT_READONLY | > NSS_INIT_NOCERTDB | > NSS_INIT_NOMODDB | > NSS_INIT_FORCEOPEN | > NSS_INIT_NOROOTINIT | > NSS_INIT_PK11RELOAD); > if (ctx == NULL) { > printf(" FAIL: Error initializing NSS using \"%s\".\n", > DEFAULT_CONFIGDIR); > return 1; > } > > modname = PR_GetLibraryName(NULL, PEM_MODULE); > if (modname == NULL) { > printf(" FAIL: Error building library name from \"%s\".\n", > PEM_MODULE); > return 1; > } > snprintf(spec, sizeof(spec), "library=%s", modname); > > module = SECMOD_LoadUserModule(spec, NULL, PR_FALSE); > if (module == NULL) { > printf(" FAIL: Error loading \"%s\".\n", spec); > return 2; > } > if (module->slotCount == 0) { > printf(" FAIL: No slots in module!\n"); > return 3; > } > slot = module->slots[0]; > > while ((c = getopt(argc, argv, "p:c:k:")) != -1) { > switch (c) { > case 'p': > password = optarg; > continue; > break; > case 'c': > attrs[0].type = CKA_CLASS; > attrs[0].pValue = &certclass; > attrs[0].ulValueLen = sizeof(certclass); > attrs[1].type = CKA_TOKEN; > attrs[1].pValue = &cktrue; > attrs[1].ulValueLen = sizeof(cktrue); > attrs[2].type = CKA_LABEL; > attrs[2].pValue = optarg; > attrs[2].ulValueLen = strlen(optarg); > attrs[3].type = CKA_TRUST; > attrs[3].pValue = &cktrust; > attrs[3].ulValueLen = sizeof(cktrust); > objs[n_objs] = PK11_CreateGenericObject(slot, > attrs, 4, > CK_FALSE); > break; > case 'k': > attrs[0].type = CKA_CLASS; > attrs[0].pValue = &keyclass; > attrs[0].ulValueLen = sizeof(certclass); > attrs[1].type = CKA_TOKEN; > attrs[1].pValue = &cktrue; > attrs[1].ulValueLen = sizeof(cktrue); > attrs[2].type = CKA_LABEL; > attrs[2].pValue = optarg; > attrs[2].ulValueLen = strlen(optarg); > objs[n_objs] = PK11_CreateGenericObject(slot, > attrs, 3, > CK_FALSE); > if (PK11_TokenRefresh(slot) != SECSuccess) { > printf(" Error refreshing token.\n"); > } > if (!PK11_IsLoggedIn(slot, NULL) && > PK11_NeedLogin(slot)) { > PK11_SetPasswordFunc(pwcb); > printf(" Logging in to token.\n"); > PK11_Authenticate(slot, PR_FALSE, password); > } > break; > } > if (objs[n_objs] == NULL) { > printf(" FAIL: Error loading \"%s\".\n", optarg); > return 4; > } else { > n_objs++; > } > } > retval = 0; > certs = PK11_ListCertsInSlot(slot); > if (certs == NULL) { > printf(" No certificates in slot.\n"); > } else { > if (!CERT_LIST_EMPTY(certs)) { > for (node = CERT_LIST_HEAD(certs); > (node != NULL) && !CERT_LIST_END(node, certs); > node = CERT_LIST_NEXT(node)) { > cert = node->cert; > key = PK11_FindKeyByAnyCert(node->cert, NULL); > if (key != NULL) { > printf(" OK: Found key for \"%s\".\n", > cert->nickname); > SECKEY_DestroyPrivateKey(key); > } else { > printf(" FAIL: No key found for " > "\"%s\".\n", cert->nickname); > retval = 5; > } > } > } > CERT_DestroyCertList(certs); > } > > NSS_ShutdownContext(ctx); > return retval; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 873858
: 639609 |
639610