libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit eee154c8b0da6fa536e93b08747e26ccf686d722
parent 713de1b671da566857d58a13126f46222e46dbeb
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  9 Jul 2012 11:43:14 +0000

-LRN: use cryptoapi for PRNG on W32

Diffstat:
Msrc/testcurl/daemontest_digestauth.c | 25+++++++++++++++++++++++++
Msrc/testcurl/daemontest_digestauth_with_arguments.c | 25+++++++++++++++++++++++++
2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/src/testcurl/daemontest_digestauth.c b/src/testcurl/daemontest_digestauth.c @@ -35,6 +35,8 @@ #ifndef WINDOWS #include <sys/socket.h> #include <unistd.h> +#else +#include <wincrypt.h> #endif #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" @@ -135,6 +137,7 @@ testDigestAuth () cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; +#if !WINDOWS fd = open("/dev/urandom", O_RDONLY); if (-1 == fd) { @@ -157,6 +160,28 @@ testDigestAuth () off += len; } (void) close(fd); +#else + { + HCRYPTPROV cc; + BOOL b; + b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + if (b == 0) + { + fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", + GetLastError ()); + return 1; + } + b = CryptGenRandom (cc, 8, rnd); + if (b == 0) + { + fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", + GetLastError ()); + } + CryptReleaseContext (cc, 0); + if (b == 0) + return 1; + } +#endif d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1337, NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, diff --git a/src/testcurl/daemontest_digestauth_with_arguments.c b/src/testcurl/daemontest_digestauth_with_arguments.c @@ -35,6 +35,8 @@ #ifndef WINDOWS #include <sys/socket.h> #include <unistd.h> +#else +#include <wincrypt.h> #endif #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" @@ -135,6 +137,7 @@ testDigestAuth () cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; +#if !WINDOWS fd = open("/dev/urandom", O_RDONLY); if (-1 == fd) { @@ -157,6 +160,28 @@ testDigestAuth () off += len; } (void) close(fd); +#else + { + HCRYPTPROV cc; + BOOL b; + b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + if (b == 0) + { + fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", + GetLastError ()); + return 1; + } + b = CryptGenRandom (cc, 8, rnd); + if (b == 0) + { + fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", + GetLastError ()); + } + CryptReleaseContext (cc, 0); + if (b == 0) + return 1; + } +#endif d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1337, NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,