This is not related to linking, but this seems to be a bug of 3.14.1, maybe
related to Bug 811928 ?
to reproduce on Windows Visual C++ 2010, with cert8.db, key3.db, secmod.db in
the path (no pkcs11.txt), checked also renaming secmod.db (different error code)
====BEGIN CODE
#include <stdio.h>
#include <string.h>
#include <nspr.h>
#include <nss.h>
#include <ssl.h>
#include <pk11pub.h>
namespace {
void get_cert(const char *nickname)
{
CERTCertificate *cert = PK11_FindCertFromNickname(nickname, NULL);
if (!cert) {
printf("Cannot find '%s' certificate, error %d.\n", nickname,
PR_GetError());
} else {
printf("Certificate '%s', SN: %s\n", nickname,
cert->subjectName);
}
}
NSSInitContext *init_context(char *dbdir, char *desc)
{
NSSInitParameters initParams;
memset((void*) &initParams, '\0', sizeof(initParams));
initParams.length = sizeof(initParams);
NSSInitContext *ctx = NSS_InitContext(dbdir, "", "", SECMOD_DB,
&initParams, NSS_INIT_READONLY);
return ctx;
}
int tests_simple_2(char *path)
{
NSSInitParameters initParams;
memset((void*) &initParams, '\0', sizeof(initParams));
initParams.length = sizeof(initParams);
NSSInitContext *ctx = NSS_InitContext("", "", "", SECMOD_DB,
&initParams,
NSS_INIT_READONLY|NSS_INIT_NOCERTDB|NSS_INIT_NOMODDB);
if (!ctx) {
printf("NSS_InitContext error %d\n", PR_GetError());
return 1;
}
char conf[256];
sprintf(conf, "configDir='%s' tokenDescription='db1' flags=readOnly",
path);
PK11SlotInfo *slot_1 = SECMOD_OpenUserDB(conf);
if (!slot_1)
printf("SECMOD_OpenUserDB %d\n", PR_GetError());
if (slot_1)
SECMOD_CloseUserDB(slot_1);
NSS_ShutdownContext(ctx);
printf("tests_simple_2 OK\n");
return 0;
}
int tests_simple_1(char *path, char *key)
{
NSSInitContext *ctx1 = init_context(path, "db1");
if (!ctx1) {
printf("init context error %d\n", PR_GetError());
return 1;
}
get_cert(key);
NSS_ShutdownContext(ctx1);
printf("tests_simple_1 OK\n");
return 0;
}
} // namespace
int main(int argc, char* argv[])
{
char *path = "some_path";
char *key = "some_key_in_the_db";
tests_simple_2(path);
tests_simple_1(path, key);
tests_simple_2(path);
return 0;
}
====END CODE
this will output:
tests_simple_2 OK
init context error -8015
NSS_InitContext error -8018
Changing the order in the main gives the same error !
I am going to check that on 3.14.2
--
dev-tech-crypto mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-crypto