diff options
author | stoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68> | 2000-04-15 19:05:13 +0000 |
---|---|---|
committer | stoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68> | 2000-04-15 19:05:13 +0000 |
commit | 9ea0e9b011116be21e4ea36ce82a691600dff565 (patch) | |
tree | aa857dcfce9827d6e56b7178bd820d7b9ff0696a /misc | |
parent | eb4488faaf9b56f2f3c40800b80c5a128dec9ff7 (diff) | |
download | libapr-9ea0e9b011116be21e4ea36ce82a691600dff565.tar.gz |
Here's my first stab at getting mod_auth_digest working under 2.0
quick change summary:
- moved the random byte generation into APR
This patch adds ap_generate_random_bytes()
- now uses ap_time_t
- compiles and runs on linux
- tested with amaya
still to do:
- test win32 (This will have to be someone with a windows box :-)
I think I did everything correctly. APR_HAS_RANDOM should be defined
on windows and there is a lib/apr/misc/win32/rand.c which is basically
a copy of what mod_auth_digest used to use.
- error handling cleanup
Since there is not currently a usable ap_strerror it is commented out.
win32 error handling is virtually non-existant. I just don't know enough
about win32 to touch this stuff.
Brian
Submitted by: Brian Martin
Reviewed by: Bill Stoddard (very quick review, moving in right direction)
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59866 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/unix/Makefile.in | 2 | ||||
-rw-r--r-- | misc/unix/rand.c | 99 | ||||
-rw-r--r-- | misc/win32/rand.c | 76 |
3 files changed, 176 insertions, 1 deletions
diff --git a/misc/unix/Makefile.in b/misc/unix/Makefile.in index 90308359c..49f69f125 100644 --- a/misc/unix/Makefile.in +++ b/misc/unix/Makefile.in @@ -15,7 +15,7 @@ INCLUDES=-I$(INCDIR1) -I$(INCDIR2) -I. #LIB=libmisc.a -OBJS=start.o getopt.o otherchild.o error.o +OBJS=start.o getopt.o otherchild.o error.o rand.o .c.o: $(CC) $(CFLAGS) -c $(INCLUDES) $< diff --git a/misc/unix/rand.c b/misc/unix/rand.c new file mode 100644 index 000000000..548b7c778 --- /dev/null +++ b/misc/unix/rand.c @@ -0,0 +1,99 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +#include "misc.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#if APR_HAS_RANDOM + +#define XSTR(x) #x +#define STR(x) XSTR(x) + +ap_status_t ap_generate_random_bytes(unsigned char * buf, int length) +{ +#ifdef DEV_RANDOM + + int rnd; + size_t got, tot; + + if ((rnd = open(STR(DEV_RANDOM), O_RDONLY)) == -1) + return errno; + + for (tot=0; tot<length; tot += got) + if ((got = read(rnd, buf+tot, length-tot)) < 0) + return errno; + + close(rnd); + +#else /* use truerand */ + + extern int randbyte(void); /* from the truerand library */ + unsigned int idx; + + /* this will increase the startup time of the server, unfortunately... + * (generating 20 bytes takes about 8 seconds) + */ + for (idx=0; idx<length; idx++) + buf[idx] = (unsigned char) randbyte(); + +#endif /* DEV_RANDOM */ + + return APR_SUCCESS; +} + +#undef STR +#undef XSTR +#endif /* APR_HAS_RANDOM */ diff --git a/misc/win32/rand.c b/misc/win32/rand.c new file mode 100644 index 000000000..99598213d --- /dev/null +++ b/misc/win32/rand.c @@ -0,0 +1,76 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +#include <wincrypt.h> + +ap_status_t ap_generate_random_bytes(unsigned char * buf, int length) +{ + HCRYPTPROV hProv; + + if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,0)) { + /* ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, + "Digest: Error acquiring context. Errno = %d", + GetLastError()); + exit(EXIT_FAILURE);*/ + return 1; + } + if (!CryptGenRandom(hProv,length,buf)) { + /* ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, + "Digest: Error generating secret. Errno = %d", + GetLastError()); + exit(EXIT_FAILURE);*/ + return 1; + } + return APR_SUCCESS; +} |