Ignore:
Timestamp:
Feb 24, 2010 5:43:34 AM (14 years ago)
Author:
nanang
Message:

Ticket #1032:

  • Initial version of server domain name verification:
    • Updated SSL certificate info, especially identities info
    • Updated verification mechanism as in the specifications in ticket desc.
    • Added server domain name info in pjsip_tx_data.
    • Added alternative API for acquiring transport and creating transport of transport factory to include pjsip_tx_data param.
    • Server identity match criteria:
      • full host name match
      • wild card not accepted
      • if identity is URI, it must be SIP/SIPS URI
  • Initial version of transport state notifications:
    • Added new API to set transport state callback in PJSIP and PJSUA.
    • Defined states: connected/disconnected, accepted/rejected, verification errors.
  • Minors:
    • Updated SSL socket test: dump verification result, test of requiring client cert, and few minors.
    • Updated test cert to include subjectAltName extensions.
    • Added SSL certificate dump function.
    • Updated max number of socket async operations in Symbian sample apps (RSocketServ::Connect()) to 32 (was default 8).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ssl_sock_symbian.cpp

    r2998 r3106  
    128128        return KErrNotFound; 
    129129    } 
     130    const CX509Certificate *GetPeerCert() { 
     131        if (securesock_) 
     132            return securesock_->ServerCert(); 
     133        return NULL; 
     134    } 
    130135 
    131136private: 
     
    410415struct pj_ssl_sock_t 
    411416{ 
     417    pj_pool_t           *pool; 
    412418    pj_ssl_sock_cb       cb; 
    413419    void                *user_data; 
     
    435441    pj_ssl_cipher       *ciphers; 
    436442    pj_str_t             servername; 
     443    pj_ssl_cert_info     remote_cert_info; 
    437444}; 
     445 
     446 
     447static pj_str_t get_cert_name(pj_pool_t *pool, 
     448                              const CX500DistinguishedName &name) 
     449{ 
     450    TInt i; 
     451    char buf[1024]; 
     452    TUint8 *p; 
     453    TInt l = sizeof(buf); 
     454     
     455    p = (TUint8*)buf; 
     456    for(i = 0; i < name.Count(); ++i) { 
     457        const CX520AttributeTypeAndValue &attr = name.Element(i); 
     458 
     459        /* Print element separator */ 
     460        *p++ = '/'; 
     461        if (0 == --l) break; 
     462 
     463        /* Print the type. */ 
     464        TPtr8 type(p, l); 
     465        type.Copy(attr.Type()); 
     466        p += type.Length(); 
     467        l -= type.Length(); 
     468        if (0 >= --l) break; 
     469 
     470        /* Print equal sign */ 
     471        *p++ = '='; 
     472        if (0 == --l) break; 
     473         
     474        /* Print the value. Let's just get the raw data here */ 
     475        TPtr8 value(p, l); 
     476        value.Copy(attr.EncodedValue().Mid(2)); 
     477        p += value.Length(); 
     478        l -= value.Length(); 
     479        if (0 >= --l) break; 
     480    } 
     481     
     482    pj_str_t src, res; 
     483    pj_strset(&src, buf, sizeof(buf) - l); 
     484    pj_strdup(pool, &res, &src); 
     485     
     486    return res; 
     487} 
     488                             
     489/* Get certificate info from CX509Certificate. 
     490 */ 
     491static void get_cert_info(pj_pool_t *pool, pj_ssl_cert_info *ci, 
     492                          const CX509Certificate *x) 
     493{ 
     494    unsigned len; 
     495     
     496    pj_assert(pool && ci && x); 
     497     
     498    pj_bzero(ci, sizeof(*ci)); 
     499     
     500    /* Version */ 
     501    ci->version = x->Version(); 
     502     
     503    /* Serial number */ 
     504    len = x->SerialNumber().Length(); 
     505    if (len > sizeof(ci->serial_no))  
     506        len = sizeof(ci->serial_no); 
     507    pj_memcpy(ci->serial_no + sizeof(ci->serial_no) - len,  
     508              x->SerialNumber().Ptr(), len); 
     509     
     510    /* Subject */ 
     511    { 
     512        HBufC *subject = NULL; 
     513        TRAPD(err, subject = x->SubjectL()); 
     514        if (err == KErrNone) { 
     515            TPtr16 ptr16(subject->Des()); 
     516            len = ptr16.Length(); 
     517            TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len); 
     518            ptr8.Copy(ptr16); 
     519            pj_strset(&ci->subject.cn, (char*)ptr8.Ptr(), ptr8.Length()); 
     520        } 
     521        ci->subject.info = get_cert_name(pool, x->SubjectName()); 
     522    } 
     523 
     524    /* Issuer */ 
     525    { 
     526        HBufC *issuer = NULL; 
     527        TRAPD(err, issuer = x->IssuerL()); 
     528        if (err == KErrNone) { 
     529            TPtr16 ptr16(issuer->Des()); 
     530            len = ptr16.Length(); 
     531            TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len); 
     532            ptr8.Copy(ptr16); 
     533            pj_strset(&ci->issuer.cn, (char*)ptr8.Ptr(), ptr8.Length()); 
     534        } 
     535        ci->issuer.info = get_cert_name(pool, x->IssuerName()); 
     536    } 
     537     
     538    /* Validity */ 
     539    const CValidityPeriod &valid_period = x->ValidityPeriod(); 
     540    TTime base_time(TDateTime(1970, EJanuary, 0, 0, 0, 0, 0)); 
     541    TTimeIntervalSeconds tmp_sec; 
     542    valid_period.Start().SecondsFrom(base_time, tmp_sec); 
     543    ci->validity.start.sec = tmp_sec.Int();  
     544    valid_period.Finish().SecondsFrom(base_time, tmp_sec); 
     545    ci->validity.end.sec = tmp_sec.Int(); 
     546} 
     547 
     548 
     549/* Update certificates info. This function should be called after handshake 
     550 * or renegotiation successfully completed. 
     551 */ 
     552static void update_certs_info(pj_ssl_sock_t *ssock) 
     553{ 
     554    const CX509Certificate *x; 
     555 
     556    pj_assert(ssock && ssock->sock && 
     557              ssock->sock->GetState() == CPjSSLSocket::SSL_STATE_ESTABLISHED); 
     558         
     559    /* Active remote certificate */ 
     560    x = ssock->sock->GetPeerCert(); 
     561    if (x) { 
     562        get_cert_info(ssock->pool, &ssock->remote_cert_info, x); 
     563    } else { 
     564        pj_bzero(&ssock->remote_cert_info, sizeof(pj_ssl_cert_info)); 
     565    } 
     566} 
    438567 
    439568 
     
    505634     
    506635    /* Init secure socket */ 
     636    ssock->pool = pool; 
    507637    ssock->sock_af = param->sock_af; 
    508638    ssock->sock_type = param->sock_type; 
     
    644774        /* Remote address */ 
    645775        pj_sockaddr_cp((pj_sockaddr_t*)&info->remote_addr,  
    646                    (pj_sockaddr_t*)&ssock->rem_addr); 
     776                       (pj_sockaddr_t*)&ssock->rem_addr); 
     777         
     778        /* Certificates info */ 
     779        info->remote_cert_info = &ssock->remote_cert_info; 
    647780    } 
    648781 
     
    729862        status = reader->Read(&read_cb, ssock, *ssock->read_state.read_buf,  
    730863                              ssock->read_state.flags); 
    731         if (status != PJ_EPENDING) { 
    732             /* Notify error */ 
    733             (*ssock->cb.on_data_read)(ssock, NULL, 0, status, NULL); 
    734         } 
    735     } 
    736      
     864    } 
     865     
     866    /* Connection closed or something goes wrong */ 
    737867    if (status != PJ_SUCCESS && status != PJ_EPENDING) { 
    738         /* Connection closed or something goes wrong */ 
     868        /* Notify error */ 
     869        if (ssock->cb.on_data_read) { 
     870            pj_bool_t ret = (*ssock->cb.on_data_read)(ssock, NULL, 0,  
     871                                                      status, NULL); 
     872            if (!ret) { 
     873                /* We've been destroyed */ 
     874                return; 
     875            } 
     876        } 
     877         
    739878        delete ssock->read_state.read_buf; 
    740879        delete ssock->read_state.orig_buf; 
     
    10021141    if (status == PJ_SUCCESS) { 
    10031142        ssock->established = PJ_TRUE; 
     1143        update_certs_info(ssock); 
    10041144    } else { 
    10051145        delete ssock->sock; 
Note: See TracChangeset for help on using the changeset viewer.