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

« back to all changes in this revision

Viewing changes to gtk/ssl-dlg.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
/* ssl_dlg.c
2
2
 *
3
 
 * $Id: ssl-dlg.c 18205 2006-05-22 07:29:40Z guy $
 
3
 * $Id: ssl-dlg.c 20408 2007-01-12 13:02:49Z kukosa $
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU General Public License
88
88
        GtkWidget       *carray_bt;
89
89
        GtkWidget       *raw_bt;
90
90
        GtkWidget       *follow_save_as_w;
 
91
#if GTK_MAJOR_VERSION >= 2
 
92
        GtkWidget       *find_dlg_w;
 
93
#endif
91
94
        gboolean        is_ipv6;
92
95
        char            *filter_out_filter;
93
96
        GtkWidget       *filter_te;
102
105
static void follow_charset_toggle_cb(GtkWidget * w, gpointer parent_w);
103
106
static void follow_load_text(follow_info_t *follow_info);
104
107
static void follow_filter_out_stream(GtkWidget * w, gpointer parent_w);
 
108
#if GTK_MAJOR_VERSION >= 2
 
109
static void follow_find_cb(GtkWidget * w, gpointer data);
 
110
static void follow_find_button_cb(GtkWidget * w _U_, gpointer parent_w);
 
111
static void follow_find_destroy_cb(GtkWidget * win _U_, gpointer data);
 
112
#endif
105
113
static void follow_save_as_cmd_cb(GtkWidget * w, gpointer data);
106
114
static void follow_save_as_ok_cb(GtkWidget * w, gpointer fs);
107
115
static void follow_save_as_destroy_cb(GtkWidget * win, gpointer user_data);
118
126
 
119
127
typedef struct {
120
128
    gboolean is_server;
121
 
    StringInfo* data;
 
129
    StringInfo data;
122
130
} SslDecryptedRecord;
123
131
 
124
132
/* Add a "follow_info_t" structure to the list. */
140
148
{
141
149
    follow_info_t* follow_info = tapdata;
142
150
    SslDecryptedRecord* rec;
 
151
    SslDataInfo* appl_data;
 
152
    gint total_len;
 
153
    guchar *p;
143
154
    int proto_ssl = (int) ssl;
144
155
    SslPacketInfo* pi = p_get_proto_data(pinfo->fd, proto_ssl);
145
156
 
146
157
    /* skip packet without decrypted data payload*/    
147
 
    if (!pi || !pi->app_data.data)
 
158
    if (!pi || !pi->appl_data)
148
159
        return 0;
 
160
 
 
161
    /* compute total length */
 
162
    total_len = 0;
 
163
    appl_data = pi->appl_data;
 
164
    do {
 
165
      total_len += appl_data->plain_data.data_len; 
 
166
      appl_data = appl_data->next;
 
167
    } while (appl_data);
149
168
    
150
169
    /* compute packet direction */
151
 
    rec = g_malloc(sizeof(SslDecryptedRecord));
 
170
    rec = g_malloc(sizeof(SslDecryptedRecord) + total_len);
152
171
 
153
172
    if (follow_info->client_port == 0) {
154
173
        follow_info->client_port = pinfo->srcport;
162
181
        rec->is_server = 1;
163
182
 
164
183
    /* update stream counter */
165
 
    follow_info->bytes_written[rec->is_server] += pi->app_data.data_len;
 
184
    follow_info->bytes_written[rec->is_server] += total_len;
166
185
    
167
186
    /* extract decrypted data and queue it locally */    
168
 
    rec->data = &pi->app_data;
 
187
    rec->data.data = (guchar*)(rec + 1);
 
188
    rec->data.data_len = total_len;
 
189
    appl_data = pi->appl_data;
 
190
    p = rec->data.data;
 
191
    do {
 
192
      memcpy(p, appl_data->plain_data.data, appl_data->plain_data.data_len);
 
193
      p += appl_data->plain_data.data_len; 
 
194
      appl_data = appl_data->next;
 
195
    } while (appl_data);
169
196
    follow_info->ssl_decrypted_data = g_list_append(
170
197
        follow_info->ssl_decrypted_data,rec);
171
198
 
317
344
    hbox = gtk_hbox_new(FALSE, 1);
318
345
    gtk_box_pack_start(GTK_BOX(stream_vb), hbox, FALSE, FALSE, 0);
319
346
 
 
347
#if GTK_MAJOR_VERSION >= 2
 
348
        /* Create Find Button */
 
349
        button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_FIND);
 
350
        SIGNAL_CONNECT(button, "clicked", follow_find_cb, follow_info);
 
351
        gtk_tooltips_set_tip (tooltips, button, "Find text in the displayed content", NULL);
 
352
        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
 
353
#endif
 
354
 
320
355
    /* Create Save As Button */
321
356
    button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_SAVE_AS);
322
357
    SIGNAL_CONNECT(button, "clicked", follow_save_as_cmd_cb, follow_info);
609
644
        }
610
645
 
611
646
        if (!skip) {
612
 
            size_t nchars = rec->data->data_len;
613
 
            char* buffer = (char*) rec->data->data;
 
647
            size_t nchars = rec->data.data_len;
 
648
            char* buffer = (char*) rec->data.data;
614
649
            
615
650
            switch (follow_info->show_type) {
616
651
    
728
763
    return FRS_PRINT_ERROR;
729
764
}
730
765
 
 
766
#if GTK_MAJOR_VERSION >= 2
 
767
static void
 
768
follow_find_cb(GtkWidget * w _U_, gpointer data)
 
769
{
 
770
    follow_info_t       *follow_info = data;
 
771
    GtkTooltips         *tooltips;
 
772
    GtkWidget           *find_dlg_w, *main_vb, *buttons_row, *find_lb;
 
773
    GtkWidget           *find_hb, *find_text_box, *find_bt, *cancel_bt;
 
774
 
 
775
    tooltips = gtk_tooltips_new();
 
776
 
 
777
    if (follow_info->find_dlg_w != NULL) {
 
778
            /* There's already a dialog box; reactivate it. */
 
779
            reactivate_window(follow_info->find_dlg_w);
 
780
            return;
 
781
    }
 
782
 
 
783
    /* Create the find box */
 
784
    find_dlg_w = dlg_window_new("Wireshark: Find text");
 
785
    gtk_window_set_transient_for(GTK_WINDOW(find_dlg_w),
 
786
                                 GTK_WINDOW(follow_info->streamwindow));
 
787
    gtk_window_set_destroy_with_parent(GTK_WINDOW(find_dlg_w), TRUE);
 
788
    follow_info->find_dlg_w = find_dlg_w;
 
789
 
 
790
    SIGNAL_CONNECT(find_dlg_w, "destroy", follow_find_destroy_cb, follow_info);
 
791
    SIGNAL_CONNECT(find_dlg_w, "delete_event", window_delete_event_cb, NULL);
 
792
 
 
793
    /* Main vertical box */
 
794
    main_vb = gtk_vbox_new(FALSE, 3);
 
795
    gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
 
796
    gtk_container_add(GTK_CONTAINER(find_dlg_w), main_vb);
 
797
 
 
798
    /* Horizontal box for find label, entry field and up/down radio buttons*/
 
799
    find_hb = gtk_hbox_new(FALSE, 3);
 
800
    gtk_container_add(GTK_CONTAINER(main_vb), find_hb);
 
801
    gtk_widget_show(find_hb);
 
802
 
 
803
    /* Find label */
 
804
    find_lb = gtk_label_new("Find text:");
 
805
    gtk_box_pack_start(GTK_BOX(find_hb), find_lb, FALSE, FALSE, 0);
 
806
    gtk_widget_show(find_lb);
 
807
 
 
808
    /* Find field */
 
809
    find_text_box = gtk_entry_new();
 
810
    gtk_box_pack_start(GTK_BOX(find_hb), find_text_box, FALSE, FALSE, 0);
 
811
    gtk_tooltips_set_tip(tooltips, find_text_box, "Text to search for (case sensitive)", NULL);
 
812
    gtk_widget_show(find_text_box);
 
813
 
 
814
    /* Buttons row */
 
815
    buttons_row = dlg_button_row_new(GTK_STOCK_FIND, GTK_STOCK_CANCEL, NULL);
 
816
    gtk_container_add(GTK_CONTAINER(main_vb), buttons_row);
 
817
    find_bt = OBJECT_GET_DATA(buttons_row, GTK_STOCK_FIND);
 
818
    cancel_bt = OBJECT_GET_DATA(buttons_row, GTK_STOCK_CANCEL);
 
819
 
 
820
    SIGNAL_CONNECT(find_bt, "clicked", follow_find_button_cb, follow_info);
 
821
    OBJECT_SET_DATA(find_bt, "find_string", find_text_box);
 
822
    window_set_cancel_button(find_dlg_w, cancel_bt, window_cancel_button_cb);
 
823
 
 
824
    /* Hitting return in the find field "clicks" the find button */
 
825
    dlg_set_activate(find_text_box, find_bt);
 
826
 
 
827
    /* Show the dialog */
 
828
    gtk_widget_show_all(find_dlg_w);
 
829
    window_present(find_dlg_w);
 
830
}
 
831
 
 
832
static void
 
833
follow_find_button_cb(GtkWidget * w, gpointer data)
 
834
{
 
835
    gboolean            found;
 
836
    const gchar         *find_string;
 
837
    follow_info_t       *follow_info = data;
 
838
    GtkTextBuffer       *buffer;
 
839
    GtkTextIter         iter, match_start, match_end;
 
840
    GtkTextMark         *last_pos_mark;
 
841
    GtkWidget           *find_string_w;
 
842
 
 
843
    /* Get the text the user typed into the find field */
 
844
    find_string_w = (GtkWidget *)OBJECT_GET_DATA(w, "find_string");
 
845
    find_string = gtk_entry_get_text(GTK_ENTRY(find_string_w));
 
846
 
 
847
    /* Get the buffer associated with the follow stream */
 
848
    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(follow_info->text));
 
849
    gtk_text_buffer_get_start_iter(buffer, &iter);
 
850
 
 
851
    /* Look for the search string in the buffer */
 
852
    last_pos_mark = gtk_text_buffer_get_mark(buffer, "last_position");
 
853
    if(last_pos_mark)
 
854
            gtk_text_buffer_get_iter_at_mark(buffer, &iter, last_pos_mark);
 
855
 
 
856
    found = gtk_text_iter_forward_search(&iter, find_string, 0, &match_start,
 
857
                                         &match_end,
 
858
                                         NULL);
 
859
 
 
860
    if(found) {
 
861
            gtk_text_buffer_select_range(buffer, &match_start, &match_end);
 
862
            last_pos_mark = gtk_text_buffer_create_mark (buffer, "last_position",
 
863
                                                         &match_end, FALSE);
 
864
            gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(follow_info->text), last_pos_mark);
 
865
    } else {
 
866
            /* We didn't find a match */
 
867
            simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
 
868
                          "%sFind text has reached the end of the followed "
 
869
                          "stream%s\n\nThe next search will start from the "
 
870
                          "beginning", simple_dialog_primary_start(),
 
871
                          simple_dialog_primary_end());
 
872
            if(last_pos_mark)
 
873
                    gtk_text_buffer_delete_mark(buffer, last_pos_mark);
 
874
    }
 
875
        
 
876
}
 
877
 
 
878
static void
 
879
follow_find_destroy_cb(GtkWidget * win _U_, gpointer data)
 
880
{
 
881
        follow_info_t   *follow_info = data;
 
882
 
 
883
        /* Note that we no longer have a dialog box. */
 
884
        follow_info->find_dlg_w = NULL;
 
885
}
 
886
#endif /* GTK_MAJOR_VERSION >= 2 */
 
887
 
 
888
 
731
889
/*
732
890
 * XXX - for text printing, we probably want to wrap lines at 80 characters;
733
891
 * (PostScript printing is doing this already), and perhaps put some kind of