~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to ssl/ssl_cert.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
 
118
118
#if defined(WIN32)
119
119
#include <windows.h>
 
120
#include <tchar.h>
120
121
#endif
121
122
 
122
123
#ifdef NeXT
129
130
#include <openssl/pem.h>
130
131
#include <openssl/x509v3.h>
131
132
#include "ssl_locl.h"
 
133
#include <openssl/fips.h>
132
134
 
133
135
int SSL_get_ex_data_X509_STORE_CTX_idx(void)
134
136
        {
491
493
        else
492
494
                {
493
495
#ifndef OPENSSL_NO_X509_VERIFY
 
496
# ifdef OPENSSL_FIPS
 
497
                if(s->version == TLS1_VERSION)
 
498
                        FIPS_allow_md5(1);
 
499
# endif
494
500
                i=X509_verify_cert(&ctx);
 
501
# ifdef OPENSSL_FIPS
 
502
                if(s->version == TLS1_VERSION)
 
503
                        FIPS_allow_md5(0);
 
504
# endif
495
505
#else
496
506
                i=0;
497
507
                ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
783
793
 
784
794
#else /* OPENSSL_SYS_WIN32 */
785
795
 
 
796
#if defined(_WIN32_WCE)
 
797
# ifndef UNICODE
 
798
#  error "WinCE comes in UNICODE flavor only..."
 
799
# endif
 
800
# if _WIN32_WCE<101 && !defined(OPENSSL_NO_MULTIBYTE)
 
801
#  define OPENSSL_NO_MULTIBYTE
 
802
# endif
 
803
# ifndef  FindFirstFile
 
804
#  define FindFirstFile FindFirstFileW
 
805
# endif
 
806
# ifndef  FindNextFile
 
807
#  define FindNextFile FindNextFileW
 
808
# endif
 
809
#endif
 
810
 
786
811
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
787
812
                                       const char *dir)
788
813
        {
789
814
        WIN32_FIND_DATA FindFileData;
790
815
        HANDLE hFind;
791
 
        int ret = 0;
792
 
#ifdef OPENSSL_SYS_WINCE
793
 
        WCHAR* wdir = NULL;
794
 
#endif
 
816
        int    ret = 0;
 
817
        TCHAR *wdir = NULL;
 
818
        size_t i,len_0 = strlen(dir)+1; /* len_0 accounts for trailing 0 */
 
819
        char   buf[1024],*slash;
 
820
 
 
821
        if (len_0 > (sizeof(buf)-14))   /* 14 is just some value... */
 
822
                {
 
823
                SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
 
824
                return ret;
 
825
                }
795
826
 
796
827
        CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
797
 
        
798
 
#ifdef OPENSSL_SYS_WINCE
799
 
        /* convert strings to UNICODE */
800
 
        {
801
 
                BOOL result = FALSE;
802
 
                int i;
803
 
                wdir = malloc((strlen(dir)+1)*2);
 
828
 
 
829
        if (sizeof(TCHAR) != sizeof(char))
 
830
                {
 
831
                wdir = (TCHAR *)malloc(len_0*sizeof(TCHAR));
804
832
                if (wdir == NULL)
805
833
                        goto err_noclose;
806
 
                for (i=0; i<(int)strlen(dir)+1; i++)
807
 
                        wdir[i] = (short)dir[i];
808
 
        }
809
 
#endif
810
 
 
811
 
#ifdef OPENSSL_SYS_WINCE
812
 
        hFind = FindFirstFile(wdir, &FindFileData);
813
 
#else
814
 
        hFind = FindFirstFile(dir, &FindFileData);
815
 
#endif
 
834
#ifndef OPENSSL_NO_MULTIBYTE
 
835
                if (!MultiByteToWideChar(CP_ACP,0,dir,len_0,
 
836
                                        (WCHAR *)wdir,len_0))
 
837
#endif
 
838
                        for (i=0;i<len_0;i++) wdir[i]=(TCHAR)dir[i];
 
839
 
 
840
                hFind = FindFirstFile(wdir, &FindFileData);
 
841
                }
 
842
        else    hFind = FindFirstFile((const TCHAR *)dir, &FindFileData);
 
843
 
816
844
        /* Note that a side effect is that the CAs will be sorted by name */
817
845
        if(hFind == INVALID_HANDLE_VALUE)
818
846
                {
821
849
                SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
822
850
                goto err_noclose;
823
851
                }
824
 
        
825
 
        do 
826
 
                {
827
 
                char buf[1024];
828
 
                int r;
829
 
                
830
 
#ifdef OPENSSL_SYS_WINCE
831
 
                if(strlen(dir)+_tcslen(FindFileData.cFileName)+2 > sizeof buf)
832
 
#else
833
 
                if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf)
 
852
 
 
853
        strncpy(buf,dir,sizeof(buf));   /* strcpy is safe too... */
 
854
        buf[len_0-1]='/';               /* no trailing zero!     */
 
855
        slash=buf+len_0;
 
856
 
 
857
        do      {
 
858
                const TCHAR *fnam=FindFileData.cFileName;
 
859
                size_t flen_0=_tcslen(fnam)+1;
 
860
 
 
861
                if (flen_0 > (sizeof(buf)-len_0))
 
862
                        {
 
863
                        SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
 
864
                        goto err;
 
865
                        }
 
866
                /* else strcpy would be safe too... */
 
867
 
 
868
                if (sizeof(TCHAR) != sizeof(char))
 
869
                        {
 
870
#ifndef OPENSSL_NO_MULTIBYTE
 
871
                        if (!WideCharToMultiByte(CP_ACP,0,
 
872
                                                (WCHAR *)fnam,flen_0,
 
873
                                                slash,sizeof(buf)-len_0,
 
874
                                                NULL,0))
834
875
#endif
835
 
                        {
836
 
                        SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
837
 
                        goto err;
 
876
                                for (i=0;i<flen_0;i++) slash[i]=(char)fnam[i];
838
877
                        }
839
 
                
840
 
                r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,FindFileData.cFileName);
841
 
                if (r <= 0 || r >= sizeof buf)
842
 
                        goto err;
 
878
                else    strncpy(slash,(const char *)fnam,sizeof(buf)-len_0);
 
879
 
843
880
                if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
844
881
                        goto err;
845
882
                }
849
886
err:    
850
887
        FindClose(hFind);
851
888
err_noclose:
852
 
#ifdef OPENSSL_SYS_WINCE
853
889
        if (wdir != NULL)
854
890
                free(wdir);
855
 
#endif
 
891
 
856
892
        CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
857
893
        return ret;
858
894
        }