Changeset 8823

Show
Ignore:
Timestamp:
05/03/11 10:54:48 (2 years ago)
Author:
sampson
Message:

Coding Windows certificates

Location:
branches/windows-client
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/windows-client/projects/OrangeFS/client-service/client-service.vcxproj

    r8819 r8823  
    2727  </ItemGroup> 
    2828  <ItemGroup> 
     29    <ClInclude Include="..\..\..\src\client\windows\client-service\cert.h" /> 
    2930    <ClInclude Include="..\..\..\src\client\windows\client-service\client-service.h" /> 
    3031    <ClInclude Include="..\..\..\src\client\windows\client-service\config.h" /> 
  • branches/windows-client/src/client/windows/client-service/cert.c

    r8822 r8823  
    33 
    44#include <Windows.h> 
     5#include <LM.h> 
    56#include <stdio.h> 
    67 
     
    1213#include <openssl/x509_vfy.h> 
    1314 
     15#include "pvfs2.h" 
     16 
     17extern char *convert_wstring(const wchar_t *); 
     18extern wchar_t *convert_mbstring(const char *); 
     19 
    1420/* initialize OpenSSL */ 
    1521static void openssl_init() 
    1622{ 
     23    SSL_library_init(); 
    1724    SSL_load_error_strings(); 
    1825    ERR_load_BIO_strings(); 
     
    2936 
    3037/* load certificate from file (PEM format) */ 
    31 static unsigned long load_cert_from_file(char *path, X509 **cert) 
     38static unsigned long load_cert_from_file(char *path,  
     39                                         X509 **cert) 
    3240{ 
    3341    FILE *f; 
     
    4856 
    4957/* verify certificate */ 
    50 static unsigned long verify_cert(X509 *cert, X509 *ca_cert) 
     58static unsigned long verify_cert(X509 *cert,  
     59                                 X509 *ca_cert) 
    5160{ 
    5261    X509_STORE *trust_store; 
     
    93102    return err; 
    94103} 
     104 
     105/* get user profile directory */ 
     106static unsigned int get_profile_dir(char *userid,  
     107                                    char *profile_dir) 
     108{ 
     109    USER_INFO_4 user_info; 
     110    LPCWSTR wuserid; 
     111    int ret; 
     112    char *mbstr; 
     113 
     114    /* convert to unicode */ 
     115    wuserid = convert_mbstring(userid); 
     116    if (wuserid == NULL) 
     117        return -1; 
     118 
     119    /* get user information */ 
     120    ret = NetUserGetInfo(NULL, wuserid, 4, &user_info); 
     121 
     122    if (ret == 0) 
     123    { 
     124        mbstr = convert_wstring(user_info.usri4_profile); 
     125        if (mbstr == NULL)  
     126        { 
     127            free(wuserid); 
     128            return -1; 
     129        } 
     130         
     131        strcpy(profile_dir, mbstr); 
     132 
     133        free(mbstr); 
     134    } 
     135 
     136    free(wuserid); 
     137 
     138    return ret; 
     139} 
     140 
     141/* retrieve OrangeFS credentials from cert */ 
     142static unsigned int get_cert_credentials(char *userid, 
     143                                         char *cert_dir_prefix, 
     144                                         char *ca_path, 
     145                                         PVFS_credentials *credentials) 
     146{ 
     147    char cert_path[MAX_PATH]; 
     148    char *temp; 
     149    X509 *cert, *ca_cert; 
     150    int ret; 
     151 
     152    if (userid == NULL || credentials == NULL || 
     153        ca_path) 
     154        return -1; 
     155 
     156    /* checked for cached credentials */ 
     157    ret = get_cached_credentials(userid, credentials); 
     158    if (ret == 0) 
     159    { 
     160        /* cache hit */ 
     161        return 0; 
     162    } 
     163    else if (ret != 1) 
     164    { 
     165        /* error */ 
     166        return ret; 
     167    } 
     168 
     169    /* credentials not in cache... */ 
     170 
     171    /* locate the certificate and CA */ 
     172    if (cert_dir_prefix != NULL) 
     173    { 
     174        if ((strlen(cert_dir_prefix) + strlen(userid) + 10) > MAX_PATH) 
     175        { 
     176            DbgPrint("User %s: path to cert too long\n", userid); 
     177            return -1; 
     178        } 
     179 
     180        /* cert file is cert.pem in directory of user name */ 
     181        strcpy(cert_path, cert_dir_prefix); 
     182        strcat(cert_path, userid); 
     183        strcat(cert_path, "\\cert.pem"); 
     184    } 
     185    else 
     186    { 
     187        /* get profile directory */ 
     188        ret = get_profile_dir(userid, cert_path); 
     189        if (ret != 0) 
     190        { 
     191            DbgPrint("User %s: could not locate profile dir: %d\n", userid, 
     192                ret); 
     193            return ret; 
     194        } 
     195         
     196        if (strlen(cert_path) + 9 >= MAX_PATH) 
     197        { 
     198            DbgPrint("User %s: profile dir too long\n", userid); 
     199            return -1; 
     200        } 
     201 
     202        strcat(cert_path, "\\cert.pem"); 
     203    } 
     204 
     205    /* verify the certificate */ 
     206    ret = load_cert_from_file(cert_path, &cert); 
     207    if (ret != 0) 
     208        return ret; 
     209 
     210    ret = load_cert_from_file(ca_path, &ca_cert); 
     211    if (ret != 0) 
     212    { 
     213        X509_free(cert); 
     214        return ret; 
     215    } 
     216     
     217    /* read and cache credentials from certificate */ 
     218 
     219} 
  • branches/windows-client/src/client/windows/client-service/client-service.h

    r8782 r8823  
    1010{ 
    1111    char mount_point[MAX_PATH]; 
     12    char cert_dir_prefix[MAX_PATH]; 
     13    char ca_path[MAX_PATH]; 
    1214    int threads; 
    1315    int debug; 
  • branches/windows-client/src/client/windows/client-service/config.c

    r8819 r8823  
    3232            file_name = (char *) malloc(MAX_PATH); 
    3333            malloc_flag = TRUE; 
    34             strcpy(file_name, exe_path); 
     34            strncpy(file_name, exe_path, MAX_PATH-14); 
    3535            strcat(file_name, "\\orangefs.cfg"); 
    3636 
     
    172172                continue; 
    173173 
    174             if (!stricmp(token, "-mount") || 
    175                 !stricmp(token, "mount")) 
     174            if (!stricmp(token, "mount")) 
    176175            { 
    177176                /* copy the remaining portion of the line  
     
    186185                strncpy(options->mount_point, token, MAX_PATH); 
    187186            } 
    188             else if (!stricmp(token, "-threads") || 
    189                      !stricmp(token, "threads")) 
     187            else if (!stricmp(token, "threads")) 
    190188            { 
    191189                /* 
     
    198196                options->threads = atoi(token); 
    199197            } 
    200             else if (!stricmp(token, "-user") || 
    201                      !stricmp(token, "user"))  
     198            else if (!stricmp(token, "user"))  
    202199            { 
    203200                if (parse_user() != 0) 
    204201                { 
    205                     fprintf(stderr, "-user option: parse error\n"); 
     202                    fprintf(stderr, "user option: parse error\n"); 
    206203                    close_config_file(config_file); 
    207204                    return 1; 
    208205                } 
    209206            } 
    210             else if (!stricmp(token, "-debug") || 
    211                      !stricmp(token, "debug")) 
     207            else if (!stricmp(token, "cert-dir-prefix")) 
     208            { 
     209                if (strlen(line) > 16) 
     210                { 
     211                    strncpy(options->cert_dir_prefix, line + 16, MAX_PATH-2); 
     212                    options->cert_dir_prefix[MAX_PATH-2] = '\0'; 
     213                    if (options->cert_dir_prefix[strlen(options->cert_dir_prefix)-1] != '\\') 
     214                        strcat(options->cert_dir_prefix, "\\"); 
     215                } 
     216                else 
     217                { 
     218                    fprintf(stderr, "cert-dir-prefix option: parse error\n"); 
     219                } 
     220            } 
     221            else if (!stricmp(token, "ca-path")) 
     222            { 
     223                if (strlen(line) > 8) 
     224                { 
     225                    strncpy(options->ca_path, line + 8, MAX_PATH-2); 
     226                    options->ca_path[MAX_PATH-2] = '\0'; 
     227                    if (options->ca_path[strlen(options->ca_path)-1] != '\\') 
     228                        strcat(options->ca_path, "\\"); 
     229                } 
     230                else 
     231                { 
     232                    fprintf(stderr, "ca-path option: parse error\n"); 
     233                } 
     234            } 
     235            else if (!stricmp(token, "debug")) 
    212236            { 
    213237                options->debug = TRUE; 
  • branches/windows-client/src/client/windows/client-service/dokan-interface.c

    r8819 r8823  
    413413        err = GetLastError(); 
    414414        DbgPrint("   LookupAccountSid failed: %u\n", err); 
     415        return err * -1; 
    415416    } 
    416417