~ubuntu-branches/ubuntu/gutsy/wireshark/gutsy-security

« back to all changes in this revision

Viewing changes to epan/dissectors/packet-ssl-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2007-04-01 08:58:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070401085840-or3qhrpv8alt1bwg
Tags: 0.99.5-1
* New upstream release.
* debian/patches/09_idl2wrs.dpatch: updated to patch idl2wrs.sh.in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* packet-ssl-utils.c
2
2
 *
3
 
 * $Id: packet-ssl-utils.c 19072 2006-08-29 08:33:52Z kukosa $
 
3
 * $Id: packet-ssl-utils.c 20405 2007-01-12 10:25:03Z kukosa $
4
4
 *
5
5
 * ssl manipulation functions
6
6
 * By Paolo Abeni <paolo.abeni@email.com>
31
31
 
32
32
#include <epan/emem.h>
33
33
 
 
34
static gint ver_major, ver_minor, ver_patch;
 
35
 
34
36
void 
35
 
ssl_data_set(StringInfo* str, guchar* data, guint len)
 
37
ssl_data_set(StringInfo* str, const guchar* data, guint len)
36
38
{
37
39
    memcpy(str->data, data, len);
38
40
    str->data_len = len;
147
149
    gcry_md_close(*(md));
148
150
}
149
151
 
150
 
static gint
151
 
ssl_cipher_setiv(gcry_cipher_hd_t *cipher,guchar* iv, gint iv_len)
 
152
gint
 
153
ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
152
154
{
153
155
  /* guchar * ivp; */
154
156
  gint ret;
646
648
    dec->mac_key.data = dec->_mac_key;
647
649
    ssl_data_set(&dec->mac_key, mk, cipher_suite->dig_len);
648
650
    dec->seq = 0;
 
651
    dec->byte_seq = 0;
649
652
    
650
653
    if (dec->evp)
651
654
        ssl_cipher_cleanup(&dec->evp);
1095
1098
        pad=out[inl-1];
1096
1099
        worklen-=(pad+1);
1097
1100
        ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n", 
1098
 
            pad, *outl);
 
1101
            pad, worklen);
1099
1102
    }
1100
1103
 
1101
1104
    /* And the MAC */
1143
1146
    return(0);
1144
1147
}
1145
1148
 
1146
 
/* old relase of gnutls does not define the appropriate macros, so get 
1147
 
 * them from the string*/
1148
1149
static void 
1149
1150
ssl_get_version(gint* major, gint* minor, gint* patch)
1150
1151
{
1151
 
    const gchar* str = gnutls_check_version(NULL);
1152
 
    
1153
 
    ssl_debug_printf("ssl_get_version: %s\n", str);
1154
 
    sscanf(str, "%d.%d.%d", major, minor, patch);
 
1152
  *major = ver_major;
 
1153
  *minor = ver_minor;
 
1154
  *patch = ver_patch;
1155
1155
}
1156
1156
 
1157
1157
 
1294
1294
void 
1295
1295
ssl_lib_init(void)
1296
1296
{
 
1297
    const gchar* str = gnutls_check_version(NULL);
 
1298
 
 
1299
    /* get library version */
 
1300
    /* old relase of gnutls does not define the appropriate macros, so get 
 
1301
     * them from the string*/
 
1302
    ssl_debug_printf("gnutls version: %s\n", str);
 
1303
    sscanf(str, "%d.%d.%d", &ver_major, &ver_minor, &ver_patch);
1297
1304
}
1298
1305
 
1299
1306
#else /* HAVE_LIBGNUTLS */
1349
1356
    return 0;
1350
1357
}
1351
1358
 
 
1359
gint
 
1360
ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
 
1361
{
 
1362
    ssl_debug_printf("ssl_cipher_setiv: impossible without glutls.\n");
 
1363
    return 0; 
 
1364
}
 
1365
 
1352
1366
#endif /* HAVE_LIBGNUTLS */
1353
1367
 
1354
1368
/* get ssl data for this session. if no ssl data is found allocate a new one*/
1363
1377
    ssl_session->client_random.data = ssl_session->_client_random;
1364
1378
    ssl_session->server_random.data = ssl_session->_server_random;
1365
1379
    ssl_session->master_secret.data_len = 48;
 
1380
    ssl_session->server_data_for_iv.data = 0;
 
1381
    ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
 
1382
    ssl_session->client_data_for_iv.data = 0;
 
1383
    ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
1366
1384
    ssl_session->app_data_segment.data=NULL;
1367
1385
    ssl_session->app_data_segment.data_len=0;
1368
1386
}
1459
1477
                   (assoc->tcp)?"TCP":"UDP", port, protocol, assoc->handle);
1460
1478
 
1461
1479
  
 
1480
  if (!assoc->handle) {
 
1481
    ssl_debug_printf("association_add could not find handle for protocol '%s', try to find 'data' dissector\n", protocol);
 
1482
    assoc->handle = find_dissector("data"); 
 
1483
  }
 
1484
 
1462
1485
  if(!assoc->handle){
1463
1486
    fprintf(stderr, "association_add() could not find handle for protocol:%s\n",protocol);
1464
1487
  } else {
1567
1590
  return NULL;
1568
1591
}
1569
1592
 
 
1593
void
 
1594
ssl_add_data_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint key, guint32 seq)
 
1595
{
 
1596
  SslDataInfo *rec, **prec;
 
1597
  SslPacketInfo *pi;
 
1598
 
 
1599
  pi = p_get_proto_data(pinfo->fd, proto);
 
1600
  if (!pi)
 
1601
    {
 
1602
      pi = se_alloc0(sizeof(SslPacketInfo));
 
1603
      p_add_proto_data(pinfo->fd, proto,pi);
 
1604
    }
 
1605
    
 
1606
  rec = se_alloc(sizeof(SslDataInfo)+data_len);
 
1607
  rec->key = key;
 
1608
  rec->plain_data.data = (guchar*)(rec + 1);
 
1609
  memcpy(rec->plain_data.data, data, data_len);
 
1610
  rec->plain_data.data_len = data_len;
 
1611
  rec->seq = seq;
 
1612
  rec->nxtseq = seq + data_len;
 
1613
  rec->next = NULL;
 
1614
 
 
1615
  /* insertion */
 
1616
  prec = &pi->appl_data;
 
1617
  while (*prec) prec = &(*prec)->next;
 
1618
  *prec = rec;
 
1619
 
 
1620
  ssl_debug_printf("ssl_add_data_info: new data inserted data_len = %d, seq = %u, nxtseq = %u\n", 
 
1621
                   rec->plain_data.data_len, rec->seq, rec->nxtseq);
 
1622
}
 
1623
 
 
1624
SslDataInfo* 
 
1625
ssl_get_data_info(int proto, packet_info *pinfo, gint key)
 
1626
{
 
1627
  SslDataInfo* rec;
 
1628
  SslPacketInfo* pi;
 
1629
  pi = p_get_proto_data(pinfo->fd, proto);
 
1630
 
 
1631
  if (!pi) return NULL;
 
1632
 
 
1633
  rec = pi->appl_data;
 
1634
  while (rec) {
 
1635
    if (rec->key == key) return rec;
 
1636
    rec = rec->next;
 
1637
  }
 
1638
 
 
1639
  return NULL;
 
1640
}
 
1641
 
1570
1642
/* initialize/reset per capture state data (ssl sessions cache) */
1571
1643
void 
1572
1644
ssl_common_init(GHashTable **session_hash , StringInfo * decrypted_data)
1594
1666
 
1595
1667
  start = strdup(keys_list);
1596
1668
  tmp = start;   
1597
 
  ssl_debug_printf("ssl_init keys string %s\n", start);
 
1669
  ssl_debug_printf("ssl_init keys string:\n%s\n", start);
1598
1670
  do {
1599
1671
    gchar* addr, *port, *protocol, *filename;            
1600
1672
            
1601
1673
    addr = start;
1602
1674
    /* split ip/file couple with ';' separator*/
1603
 
    end = strchr(start, ';');
 
1675
    end = strpbrk(start, ";\n\r");
1604
1676
    if (end) {
1605
1677
      *end = 0;
1606
1678
      start = end+1;
1607
1679
    }
1608
1680
  
 
1681
    /* skip comments (in file) */
 
1682
    if (addr[0] == '#') continue;
 
1683
 
1609
1684
    /* for each entry split ip, port, protocol, filename with ',' separator */
1610
1685
    ssl_debug_printf("ssl_init found host entry %s\n", addr);
1611
1686
    port = strchr(addr, ',');
1612
1687
    if (!port)
1613
1688
      {
1614
 
        ssl_debug_printf("ssl_init entry malformed can't find port in %s\n", addr);
1615
 
        break;
 
1689
        ssl_debug_printf("ssl_init entry malformed can't find port in '%s'\n", addr);
 
1690
        continue;
1616
1691
      }
1617
1692
    *port = 0;
1618
1693
    port++;
1621
1696
    if (!protocol)
1622
1697
      {
1623
1698
        ssl_debug_printf("ssl_init entry malformed can't find protocol in %s\n", port);
1624
 
        break;
 
1699
        continue;
1625
1700
      }
1626
1701
    *protocol=0;
1627
1702
    protocol++;
1630
1705
    if (!filename)
1631
1706
      {
1632
1707
        ssl_debug_printf("ssl_init entry malformed can't find filename in %s\n", port);
1633
 
        break;
 
1708
        continue;
1634
1709
      }
1635
1710
    *filename=0;
1636
1711
    filename++;
1649
1724
    fp = fopen(filename, "rb");
1650
1725
    if (!fp) {
1651
1726
      fprintf(stderr, "can't open file %s \n",filename);
1652
 
      break;
 
1727
      continue;
1653
1728
    }        
1654
1729
            
1655
1730
    private_key = ssl_load_key(fp);
1656
1731
    if (!private_key) {
1657
1732
      fprintf(stderr,"can't load private key from %s\n",
1658
1733
              filename);
1659
 
      break;
 
1734
      continue;
1660
1735
    }
1661
1736
    fclose(fp);
1662
1737