Changeset 6014


Ignore:
Timestamp:
May 29, 2019 3:49:23 AM (5 years ago)
Author:
ming
Message:

Fixed #2204: Add OpenSSL remote certificate chain info

File:
1 edited

Legend:

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

    r6006 r6014  
    15671567} 
    15681568 
     1569/* Update remote certificates chain info. This function should be 
     1570 * called after handshake or renegotiation successfully completed. 
     1571 */ 
     1572static void ssl_update_remote_cert_chain_info(pj_pool_t *pool, 
     1573                                              pj_ssl_cert_info *ci, 
     1574                                              STACK_OF(X509) *chain, 
     1575                                              pj_bool_t get_pem) 
     1576{ 
     1577    int i; 
     1578 
     1579    ci->raw_chain.cert_raw = (pj_str_t *)pj_pool_calloc(pool, 
     1580                                                        sk_X509_num(chain), 
     1581                                                        sizeof(pj_str_t)); 
     1582    ci->raw_chain.cnt = sk_X509_num(chain); 
     1583 
     1584    for (i = 0; i < sk_X509_num(chain); i++) { 
     1585        BIO *bio; 
     1586        BUF_MEM *ptr; 
     1587        X509 *x = sk_X509_value(chain, i); 
     1588 
     1589        bio = BIO_new(BIO_s_mem()); 
     1590         
     1591        if (!PEM_write_bio_X509(bio, x)) { 
     1592            PJ_LOG(3, (THIS_FILE, "Error retrieving raw certificate info")); 
     1593            ci->raw_chain.cert_raw[i].ptr  = NULL; 
     1594            ci->raw_chain.cert_raw[i].slen = 0; 
     1595        } else { 
     1596            BIO_write(bio, "\0", 1); 
     1597            BIO_get_mem_ptr(bio, &ptr); 
     1598            pj_strdup2(pool, &ci->raw_chain.cert_raw[i], ptr->data ); 
     1599        } 
     1600         
     1601        BIO_free(bio); 
     1602    } 
     1603} 
    15691604 
    15701605/* Update local & remote certificates info. This function should be 
     
    15751610    ossl_sock_t *ossock = (ossl_sock_t *)ssock; 
    15761611    X509 *x; 
     1612    STACK_OF(X509) *chain; 
    15771613 
    15781614    pj_assert(ssock->ssl_state == SSL_STATE_ESTABLISHED); 
     
    15951631    } else { 
    15961632        pj_bzero(&ssock->remote_cert_info, sizeof(pj_ssl_cert_info)); 
     1633    } 
     1634 
     1635    chain = SSL_get_peer_cert_chain(ossock->ossl_ssl); 
     1636    if (chain) { 
     1637       ssl_update_remote_cert_chain_info(ssock->pool, 
     1638                                         &ssock->remote_cert_info, 
     1639                                         chain, PJ_TRUE); 
     1640    } else { 
     1641       ssock->remote_cert_info.raw_chain.cnt = 0; 
    15971642    } 
    15981643} 
Note: See TracChangeset for help on using the changeset viewer.