/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * Allow freebl and softoken to be loaded without util or NSPR. * * These symbols are overridden once real NSPR, and libutil are attached.
*/ #define _GNU_SOURCE 1 #include <stdlib.h> #include <stdio.h> #include <stdarg.h> #include <fcntl.h> #include <time.h> #include <unistd.h> #include <sys/time.h> #include <dlfcn.h> #include <prio.h> #include <prlink.h> #include <prlog.h> #include <prthread.h> #include <plstr.h> #include <prinit.h> #include <prlock.h> #include <prmem.h> #include <prerror.h> #include <prmon.h> #include <pratom.h> #include <prsystem.h> #include <prinrval.h> #include <prtime.h> #include <prcvar.h> #include <secasn1.h> #include <secdig.h> #include <secport.h> #include <secitem.h> #include <blapi.h> #include <assert.h> #include <private/pprio.h>
/* * This uses function pointers. * * CONS: A separate function is needed to * fill in the function pointers. * * PROS: it works on all platforms. * it allows for dynamically finding nspr and libutil, even once * softoken is loaded and running. (NOTE: this may be a problem if * we switch between the stubs and real NSPR on the fly. NSPR will * do bad things if passed an _FakeArena to free or allocate from).
*/ #define STUB_DECLARE(ret, fn, args) \ typedef ret(*type_##fn) args; \ static type_##fn ptr_##fn = NULL
#else /* * this uses the loader weak attribute. it works automatically, but once * freebl is loaded, the symbols are 'fixed' (later loading of NSPR or * libutil will not resolve these symbols).
*/
#define STUB_DECLARE(ret, fn, args) \
WEAK extern ret fn args
/* * NOTE: in order to support hashing only the memory allocation stubs, * the get library name stubs, and the file io stubs are needed (the latter * two are for the library verification). The remaining stubs are simply to * compile. Attempts to use the library for other operations without NSPR * will most likely fail.
*/
/* aligned_alloc is C11. This is an alternative to get aligned memory. */ externvoid *
PORT_ZAllocAligned_stub(size_t bytes, size_t alignment, void **mem)
{
STUB_SAFE_CALL3(PORT_ZAllocAligned_Util, bytes, alignment, mem);
/* This only works if alignement is a power of 2. */ if ((alignment == 0) || (alignment & (alignment - 1))) { return NULL;
}
size_t x = alignment - 1;
size_t len = (bytes ? bytes : 1) + x;
if (!mem) { return NULL;
}
/* Always allocate a non-zero amount of bytes */
*mem = malloc(len); if (!*mem) { return NULL;
}
memset(*mem, 0, len);
/* We're pretty sure this is non-zero, but let's assure scan-build too. */ void *ret = (void *)(((uintptr_t)*mem + x) & ~(uintptr_t)x);
assert(ret);
/* we have defensive returns after abort(), which is marked noreturn on some
* platforms, making the compiler legitimately complain. */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code-return" #endif
externvoid
PORT_SafeZero(void *p, size_t n)
{
STUB_SAFE_CALL2(PORT_SafeZero, p, n); /* just use a generic call in the case where we are running
* standalone freebl */ if (p != NULL) { volatileunsignedchar *__vl = (unsignedchar *)p;
size_t __nl = n; while (__nl--)
*__vl++ = 0;
}
}
extern PRBool
SECITEM_ItemsAreEqual_stub(const SECItem *a, const SECItem *b)
{
STUB_SAFE_CALL2(SECITEM_ItemsAreEqual_Util, a, b); /* two nulls are equal */ if (!a && !b) { return PR_TRUE;
} /* only one NULL is not equal */ if (!a || !b) { return PR_FALSE;
} /* we know both secitems have been set, now make sure the lengths
* are equal */ if (a->len != b->len) { return PR_FALSE;
} /* lengths are equal, safe to verify the data */ if (PORT_Memcmp(a->data, b->data, b->len) != 0) { return PR_FALSE;
} return PR_TRUE;
}
/* The environment variable is active for all platforms */
env = PR_GetEnvSecure_stub("NSS_FIPS"); /* we generally accept y, Y, 1, FIPS, TRUE, and ON as turning on FIPS
* mode. Anything else is considered 'off' */ if (env && (*env == 'y' || *env == '1' || *env == 'Y' ||
(strcasecmp(env, "fips") == 0) ||
(strcasecmp(env, "true") == 0) ||
(strcasecmp(env, "on") == 0))) { return PR_TRUE;
}
/* currently only Linux has a system FIPS indicator. Add others here
* as they become available/known */ #ifdef LINUX
{
FILE *f; char d;
size_t size;
f = fopen("/proc/sys/crypto/fips_enabled", "r"); if (!f) return PR_FALSE;
/* * fetch the library if it's loaded. For NSS it should already be loaded
*/ #define freebl_getLibrary(libName) \
dlopen(libName, RTLD_LAZY | RTLD_NOLOAD)
#define freebl_releaseLibrary(lib) \ if (lib) \
dlclose(lib)
/* * load the symbols from the real libraries if available. * * if force is set, explicitly load the libraries if they are not already * loaded. If we could not use the real libraries, return failure.
*/ extern SECStatus
FREEBL_InitStubs()
{
SECStatus rv = SECSuccess; #ifdef FREEBL_NO_WEAK void *nspr = NULL; void *nssutil = NULL;
/* NSPR should be first */ if (!FREEBLnsprGlobalLib) {
nspr = freebl_getLibrary(nsprLibName); if (!nspr) { return SECFailure;
}
rv = freebl_InitNSPR(nspr); if (rv != SECSuccess) {
freebl_releaseLibrary(nspr); return rv;
}
FREEBLnsprGlobalLib = nspr; /* adopt */
} /* now load NSSUTIL */ if (!FREEBLnssutilGlobalLib) {
nssutil = freebl_getLibrary(nssutilLibName); if (!nssutil) { return SECFailure;
}
rv = freebl_InitNSSUtil(nssutil); if (rv != SECSuccess) {
freebl_releaseLibrary(nssutil); return rv;
}
FREEBLnssutilGlobalLib = nssutil; /* adopt */
} #endif
return rv;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.