Ignore:
Timestamp:
Jan 15, 2015 6:55:02 AM (9 years ago)
Author:
nanang
Message:

Close #1810: Adding CA path support into SSL socket.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c

    r4972 r4973  
    190190{ 
    191191    pj_str_t CA_file; 
     192    pj_str_t CA_path; 
    192193    pj_str_t cert_file; 
    193194    pj_str_t privkey_file; 
     
    582583    if (cert) { 
    583584        /* Load CA list if one is specified. */ 
    584         if (cert->CA_file.slen) { 
    585  
    586             rc = SSL_CTX_load_verify_locations(ctx, cert->CA_file.ptr, NULL); 
     585        if (cert->CA_file.slen || cert->CA_path.slen) { 
     586 
     587            rc = SSL_CTX_load_verify_locations( 
     588                        ctx, 
     589                        cert->CA_file.slen == 0 ? NULL : cert->CA_file.ptr, 
     590                        cert->CA_path.slen == 0 ? NULL : cert->CA_path.ptr); 
    587591 
    588592            if (rc != 1) { 
    589593                status = GET_SSL_STATUS(ssock); 
    590                 PJ_LOG(1,(ssock->pool->obj_name, "Error loading CA list file " 
    591                           "'%s'", cert->CA_file.ptr)); 
     594                if (cert->CA_file.slen) { 
     595                    PJ_LOG(1,(ssock->pool->obj_name, 
     596                              "Error loading CA list file '%s'", 
     597                              cert->CA_file.ptr)); 
     598                } 
     599                if (cert->CA_path.slen) { 
     600                    PJ_LOG(1,(ssock->pool->obj_name, 
     601                              "Error loading CA path '%s'", 
     602                              cert->CA_path.ptr)); 
     603                } 
    592604                SSL_CTX_free(ctx); 
    593605                return status; 
     
    19291941                                                 pj_ssl_cert_t **p_cert) 
    19301942{ 
     1943    return pj_ssl_cert_load_from_files2(pool, CA_file, NULL, cert_file, 
     1944                                        privkey_file, privkey_pass, p_cert); 
     1945} 
     1946 
     1947PJ_DEF(pj_status_t) pj_ssl_cert_load_from_files2(pj_pool_t *pool, 
     1948                                                 const pj_str_t *CA_file, 
     1949                                                 const pj_str_t *CA_path, 
     1950                                                 const pj_str_t *cert_file, 
     1951                                                 const pj_str_t *privkey_file, 
     1952                                                 const pj_str_t *privkey_pass, 
     1953                                                 pj_ssl_cert_t **p_cert) 
     1954{ 
    19311955    pj_ssl_cert_t *cert; 
    19321956 
    1933     PJ_ASSERT_RETURN(pool && CA_file && cert_file && privkey_file, PJ_EINVAL); 
     1957    PJ_ASSERT_RETURN(pool && (CA_file || CA_path) && cert_file && 
     1958                     privkey_file, 
     1959                     PJ_EINVAL); 
    19341960 
    19351961    cert = PJ_POOL_ZALLOC_T(pool, pj_ssl_cert_t); 
    1936     pj_strdup_with_null(pool, &cert->CA_file, CA_file); 
     1962    if (CA_file) { 
     1963        pj_strdup_with_null(pool, &cert->CA_file, CA_file); 
     1964    } 
     1965    if (CA_path) { 
     1966        pj_strdup_with_null(pool, &cert->CA_path, CA_path); 
     1967    } 
    19371968    pj_strdup_with_null(pool, &cert->cert_file, cert_file); 
    19381969    pj_strdup_with_null(pool, &cert->privkey_file, privkey_file); 
     
    19581989    pj_memcpy(cert_, cert, sizeof(cert)); 
    19591990    pj_strdup_with_null(pool, &cert_->CA_file, &cert->CA_file); 
     1991    pj_strdup_with_null(pool, &cert_->CA_path, &cert->CA_path); 
    19601992    pj_strdup_with_null(pool, &cert_->cert_file, &cert->cert_file); 
    19611993    pj_strdup_with_null(pool, &cert_->privkey_file, &cert->privkey_file); 
Note: See TracChangeset for help on using the changeset viewer.