Ignore:
Timestamp:
Dec 18, 2014 4:40:35 AM (9 years ago)
Author:
riza
Message:

Re #1806: Implement SSL/TLS setting to set protocol operation.

File:
1 edited

Legend:

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

    r4901 r4968  
    503503    EC_KEY *ecdh; 
    504504#endif 
    505     SSL_METHOD *ssl_method; 
     505    SSL_METHOD *ssl_method = NULL; 
    506506    SSL_CTX *ctx; 
     507    pj_uint32_t ssl_opt = 0; 
    507508    pj_ssl_cert_t *cert; 
    508509    int mode, rc; 
     
    515516    /* Make sure OpenSSL library has been initialized */ 
    516517    init_openssl(); 
     518 
     519    if (ssock->param.proto == PJ_SSL_SOCK_PROTO_DEFAULT) 
     520        ssock->param.proto = PJ_SSL_SOCK_PROTO_SSL23; 
    517521 
    518522    /* Determine SSL method to use */ 
     
    529533        ssl_method = (SSL_METHOD*)SSLv3_method(); 
    530534        break; 
    531     case PJ_SSL_SOCK_PROTO_DEFAULT: 
    532     case PJ_SSL_SOCK_PROTO_SSL23: 
     535    } 
     536 
     537    if (!ssl_method) { 
    533538        ssl_method = (SSL_METHOD*)SSLv23_method(); 
    534         break; 
    535     //case PJ_SSL_SOCK_PROTO_DTLS1: 
    536         //ssl_method = (SSL_METHOD*)DTLSv1_method(); 
    537         //break; 
    538     default: 
    539         return PJ_EINVAL; 
     539 
     540#ifdef SSL_OP_NO_SSLv2 
     541        /** Check if SSLv2 is enabled */ 
     542        ssl_opt |= ((ssock->param.proto & PJ_SSL_SOCK_PROTO_SSL2)==0)? 
     543                    SSL_OP_NO_SSLv2:0; 
     544#endif 
     545 
     546#ifdef SSL_OP_NO_SSLv3 
     547        /** Check if SSLv3 is enabled */ 
     548        ssl_opt |= ((ssock->param.proto & PJ_SSL_SOCK_PROTO_SSL3)==0)? 
     549                    SSL_OP_NO_SSLv3:0; 
     550#endif 
     551 
     552#ifdef SSL_OP_NO_TLSv1 
     553        /** Check if TLSv1 is enabled */ 
     554        ssl_opt |= ((ssock->param.proto & PJ_SSL_SOCK_PROTO_TLS1)==0)? 
     555                    SSL_OP_NO_TLSv1:0; 
     556#endif 
     557 
     558#ifdef SSL_OP_NO_TLSv1_1 
     559        /** Check if TLSv1_1 is enabled */ 
     560        ssl_opt |= ((ssock->param.proto & PJ_SSL_SOCK_PROTO_TLS1_1)==0)? 
     561                    SSL_OP_NO_TLSv1_1:0; 
     562#endif 
     563 
     564#ifdef SSL_OP_NO_TLSv1_2 
     565        /** Check if TLSv1_2 is enabled */ 
     566        ssl_opt |= ((ssock->param.proto & PJ_SSL_SOCK_PROTO_TLS1_2)==0)? 
     567                    SSL_OP_NO_TLSv1_2:0; 
     568 
     569#endif 
     570 
    540571    } 
    541572 
     
    545576        return GET_SSL_STATUS(ssock); 
    546577    } 
     578    if (ssl_opt) 
     579        SSL_CTX_set_options(ctx, ssl_opt); 
    547580 
    548581    /* Apply credentials */ 
Note: See TracChangeset for help on using the changeset viewer.