diff options
author | marha <marha@users.sourceforge.net> | 2009-06-28 22:07:26 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2009-06-28 22:07:26 +0000 |
commit | 3562e78743202e43aec8727005182a2558117eca (patch) | |
tree | 8f9113a77d12470c5c851a2a8e4cb02e89df7d43 /openssl/fips/fips_premain.c | |
download | vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.gz vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.bz2 vcxsrv-3562e78743202e43aec8727005182a2558117eca.zip |
Checked in the following released items:
xkeyboard-config-1.4.tar.gz
ttf-bitstream-vera-1.10.tar.gz
font-alias-1.0.1.tar.gz
font-sun-misc-1.0.0.tar.gz
font-sun-misc-1.0.0.tar.gz
font-sony-misc-1.0.0.tar.gz
font-schumacher-misc-1.0.0.tar.gz
font-mutt-misc-1.0.0.tar.gz
font-misc-misc-1.0.0.tar.gz
font-misc-meltho-1.0.0.tar.gz
font-micro-misc-1.0.0.tar.gz
font-jis-misc-1.0.0.tar.gz
font-isas-misc-1.0.0.tar.gz
font-dec-misc-1.0.0.tar.gz
font-daewoo-misc-1.0.0.tar.gz
font-cursor-misc-1.0.0.tar.gz
font-arabic-misc-1.0.0.tar.gz
font-winitzki-cyrillic-1.0.0.tar.gz
font-misc-cyrillic-1.0.0.tar.gz
font-cronyx-cyrillic-1.0.0.tar.gz
font-screen-cyrillic-1.0.1.tar.gz
font-xfree86-type1-1.0.1.tar.gz
font-adobe-utopia-type1-1.0.1.tar.gz
font-ibm-type1-1.0.0.tar.gz
font-bitstream-type1-1.0.0.tar.gz
font-bitstream-speedo-1.0.0.tar.gz
font-bh-ttf-1.0.0.tar.gz
font-bh-type1-1.0.0.tar.gz
font-bitstream-100dpi-1.0.0.tar.gz
font-bh-lucidatypewriter-100dpi-1.0.0.tar.gz
font-bh-100dpi-1.0.0.tar.gz
font-adobe-utopia-100dpi-1.0.1.tar.gz
font-adobe-100dpi-1.0.0.tar.gz
font-util-1.0.1.tar.gz
font-bitstream-75dpi-1.0.0.tar.gz
font-bh-lucidatypewriter-75dpi-1.0.0.tar.gz
font-adobe-utopia-75dpi-1.0.1.tar.gz
font-bh-75dpi-1.0.0.tar.gz
bdftopcf-1.0.1.tar.gz
font-adobe-75dpi-1.0.0.tar.gz
mkfontscale-1.0.6.tar.gz
openssl-0.9.8k.tar.gz
bigreqsproto-1.0.2.tar.gz
xtrans-1.2.2.tar.gz
resourceproto-1.0.2.tar.gz
inputproto-1.4.4.tar.gz
compositeproto-0.4.tar.gz
damageproto-1.1.0.tar.gz
zlib-1.2.3.tar.gz
xkbcomp-1.0.5.tar.gz
freetype-2.3.9.tar.gz
pthreads-w32-2-8-0-release.tar.gz
pixman-0.12.0.tar.gz
kbproto-1.0.3.tar.gz
evieext-1.0.2.tar.gz
fixesproto-4.0.tar.gz
recordproto-1.13.2.tar.gz
randrproto-1.2.2.tar.gz
scrnsaverproto-1.1.0.tar.gz
renderproto-0.9.3.tar.gz
xcmiscproto-1.1.2.tar.gz
fontsproto-2.0.2.tar.gz
xextproto-7.0.3.tar.gz
xproto-7.0.14.tar.gz
libXdmcp-1.0.2.tar.gz
libxkbfile-1.0.5.tar.gz
libfontenc-1.0.4.tar.gz
libXfont-1.3.4.tar.gz
libX11-1.1.5.tar.gz
libXau-1.0.4.tar.gz
libxcb-1.1.tar.gz
xorg-server-1.5.3.tar.gz
Diffstat (limited to 'openssl/fips/fips_premain.c')
-rw-r--r-- | openssl/fips/fips_premain.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/openssl/fips/fips_premain.c b/openssl/fips/fips_premain.c new file mode 100644 index 000000000..165d2c5dc --- /dev/null +++ b/openssl/fips/fips_premain.c @@ -0,0 +1,176 @@ +/* ==================================================================== + * Copyright (c) 2005 The OpenSSL Project. Rights for redistribution + * and usage in source and binary forms are granted according to the + * OpenSSL license. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#if defined(__unix) || defined(__unix__) +#include <unistd.h> +#endif + +#ifndef FINGERPRINT_PREMAIN_DSO_LOAD + +#if defined(__GNUC__) && __GNUC__>=2 + void FINGERPRINT_premain(void) __attribute__((constructor)); + /* Most commonly this results in pointer to premain to be dropped + * to .ctors segment, which is traversed by GCC crtbegin.o upon + * program startup. Except on a.out OpenBSD where it results in + * _GLOBAL_$I$premain() {premain();} being auto-generated by + * compiler... But one way or another this is believed to cover + * *all* GCC targets. */ +#elif defined(_MSC_VER) +# ifdef _WINDLL + __declspec(dllexport) /* this is essentially cosmetics... */ +# endif + void FINGERPRINT_premain(void); + static int premain_wrapper(void) { FINGERPRINT_premain(); return 0; } +# ifdef _WIN64 +# pragma section(".CRT$XCU",read) + __declspec(allocate(".CRT$XCU")) +# else +# pragma data_seg(".CRT$XCU") +# endif + static int (*p)(void) = premain_wrapper; + /* This results in pointer to premain to appear in .CRT segment, + * which is traversed by Visual C run-time initialization code. + * This applies to both Win32 and [all flavors of] Win64. */ +# pragma data_seg() +#elif defined(__SUNPRO_C) + void FINGERPRINT_premain(void); +# pragma init(FINGERPRINT_premain) + /* This results in a call to premain to appear in .init segment. */ +#elif defined(__DECC) && (defined(__VMS) || defined(VMS)) + void FINGERPRINT_premain(void); +# pragma __nostandard + globaldef { "LIB$INITIALIZ" } readonly _align (LONGWORD) + int spare[8] = {0}; + globaldef { "LIB$INITIALIZE" } readonly _align (LONGWORD) + void (*x_FINGERPRINT_premain)(void) = FINGERPRINT_premain; + /* Refer to LIB$INITIALIZE to ensure it exists in the image. */ + int lib$initialize(); + globaldef int (*lib_init_ref)() = lib$initialize; +# pragma __standard +#elif 0 + The rest has to be taken care of through command line: + + -Wl,-init,FINGERPRINT_premain on OSF1 and IRIX + -Wl,+init,FINGERPRINT_premain on HP-UX + -Wl,-binitfini:FINGERPRINT_premain on AIX + + On ELF platforms this results in a call to premain to appear in + .init segment... +#endif + +#ifndef HMAC_SHA1_SIG +#define HMAC_SHA1_SIG "?have to make sure this string is unique" +#endif + +static const unsigned char FINGERPRINT_ascii_value[40] = HMAC_SHA1_SIG; + +#define atox(c) ((c)>='a'?((c)-'a'+10):((c)>='A'?(c)-'A'+10:(c)-'0')) + +extern const void *FIPS_text_start(), *FIPS_text_end(); +extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[]; +extern unsigned char FIPS_signature[20]; +extern unsigned int FIPS_incore_fingerprint(unsigned char *,unsigned int); + +/* + * As name suggests this code is executed prior main(). We use this + * opportunity to fingerprint sequestered code in virtual address + * space of target application. + */ +void FINGERPRINT_premain(void) +{ unsigned char sig[sizeof(FIPS_signature)]; + const unsigned char * volatile p=FINGERPRINT_ascii_value; + unsigned int len=sizeof(sig),i; + + /* "volatilization" is done to disengage unwanted optimization... */ + if (*((volatile unsigned char *)p)=='?') + { if (FIPS_text_start()==NULL) + { fprintf(stderr,"FIPS_text_start() returns NULL\n"); + _exit(1); + } +#if defined(DEBUG_FINGERPRINT_PREMAIN) + fprintf(stderr,".text:%p+%d=%p\n",FIPS_text_start(), + (int)((size_t)FIPS_text_end()-(size_t)FIPS_text_start()), + FIPS_text_end()); + fprintf(stderr,".rodata:%p+%d=%p\n",FIPS_rodata_start, + (int)((size_t)FIPS_rodata_end-(size_t)FIPS_rodata_start), + FIPS_rodata_end); +#endif + + len=FIPS_incore_fingerprint(sig,sizeof(sig)); + + if (len!=sizeof(sig)) + { fprintf(stderr,"fingerprint length mismatch: %u\n",len); + _exit(1); + } + + for (i=0;i<len;i++) printf("%02x",sig[i]); + printf("\n"); + fflush(stdout); + _exit(0); + } + else if (FIPS_signature[0]=='\0') do + { for (i=0;i<sizeof(FIPS_signature);i++,p+=2) + FIPS_signature[i] = (atox(p[0])<<4)|atox(p[1]); + +#if defined(DEBUG_FINGERPRINT_PREMAIN) + if (getenv("OPENSSL_FIPS")==NULL) break; + + len=FIPS_incore_fingerprint(sig,sizeof(sig)); + + if (memcmp(FIPS_signature,sig,sizeof(FIPS_signature))) + { fprintf(stderr,"FINGERPRINT_premain: FIPS_signature mismatch\n"); + _exit(1); + } +#endif + } while(0); +} + +#else + +#include <openssl/bio.h> +#include <openssl/dso.h> +#include <openssl/err.h> + +int main(int argc,char *argv[]) +{ DSO *dso; + DSO_FUNC_TYPE func; + BIO *bio_err; + + if (argc < 2) + { fprintf (stderr,"usage: %s libcrypto.dso\n",argv[0]); + return 1; + } + + if ((bio_err=BIO_new(BIO_s_file())) == NULL) + { fprintf (stderr,"unable to allocate BIO\n"); + return 1; + } + BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + ERR_load_crypto_strings(); + + dso = DSO_load(NULL,argv[1],NULL,DSO_FLAG_NO_NAME_TRANSLATION); + if (dso == NULL) + { ERR_print_errors(bio_err); + return 1; + } + + /* This is not normally reached, because FINGERPRINT_premain should + * have executed and terminated application already upon DSO_load... */ + func = DSO_bind_func(dso,"FINGERPRINT_premain"); + if (func == NULL) + { ERR_print_errors(bio_err); + return 1; + } + + (*func)(); + + return 0; +} + +#endif |