NetSurf
verify_ssl.c
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Ole Loots <ole@monochrom.net>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <unistd.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include <windom.h>
25 
26 #include "utils/errors.h"
27 #include "utils/utils.h"
28 #include "utils/log.h"
29 #include "utils/messages.h"
30 
31 #include "atari/res/netsurf.rsh"
32 #include "atari/verify_ssl.h"
33 
34 /*
35  todo: this file need to use the treeview api - complete rework,
36  current implementation is not used in any way.
37 */
38 
39 extern void * h_gem_rsrc;
40 extern short atari_plot_vdi_handle;
41 
42 
43 #define CERT_INF_LINES 8
44 
45 static struct ssl_info_draw_param
46 {
48  unsigned long num_certs;
49  int current;
50  int scrollx;
51  int cols;
52  int scrolly;
53  int rows; /* assumed to be 8 */
54  OBJECT * tree;
55 } dp;
56 
57 
59 {
60  int l1, l2;
61  int add = 16; /* strlen("Issuer: "); */
62 
63  l1 = strlen(cert_info->issuer) + add;
64  l2 = strlen(cert_info->subject) + add;
65  return( MAX(l1, l2) );
66 }
67 
68 
69 static void __CDECL cert_info_draw( WINDOW * win, short buf[8], void * data)
70 {
71  struct ssl_info_draw_param * dp = (struct ssl_info_draw_param *)data;
72  GRECT work;
73  short pxy[4];
74  int maxchars;
75  short d, cbh, cbw;
76  int i = 0;
77  short x,y,w,h;
78  int px_ypos;
79  char * line = malloc(512);
80  if( line == NULL )
81  return;
82 
83  NSLOG(netsurf, INFO,
84  "Cert info draw, win: %p, data: %p, scrollx: %d", win, data,
85  dp->scrollx);
86 
87  WindGet( win, WF_WORKXYWH, &x, &y, &w, &h );
88  /*using static values here, as RsrcUserDraw has mem leaks & a very small stack */
89  pxy[0] = work.g_x = x + 8;
90  pxy[1] = work.g_y = y + 80;
91  pxy[2] = x + 8 + 272;
92  pxy[3] = y + 80 + 176;
93  work.g_w = 272;
94  work.g_h = 176;
95 
96  maxchars = (work.g_w / 8)+1;
97  vs_clip( atari_plot_vdi_handle, 1,(short*) &pxy );
98  vswr_mode( atari_plot_vdi_handle, MD_REPLACE );
99  vsf_interior( atari_plot_vdi_handle, 1 );
100  vsf_color( atari_plot_vdi_handle, LWHITE );
101  v_bar( atari_plot_vdi_handle, (short*)&pxy );
102  vst_height( atari_plot_vdi_handle, 16, &d, &d, &cbw, &cbh );
103  vst_alignment(atari_plot_vdi_handle, 0, 5, &d, &d );
104  vst_color( atari_plot_vdi_handle, BLACK );
105  vst_effects( atari_plot_vdi_handle, 0 );
106  px_ypos = 0;
107  for(i=0; i<CERT_INF_LINES; i++ ) {
108  switch( i ) {
109  case 0:
110  sprintf(line, "Cert Version: %d", dp->cert_infos_n[dp->current].version );
111  break;
112 
113  case 1:
114  sprintf(line, "Invalid before: %s", &dp->cert_infos_n[dp->current].not_before );
115  break;
116 
117  case 2:
118  sprintf(line, "Invalid after: %s", &dp->cert_infos_n[dp->current].not_after );
119  break;
120 
121  case 3:
122  sprintf(line, "Signature type: %d", dp->cert_infos_n[dp->current].sig_type );
123  break;
124 
125  case 4:
126  sprintf(line, "Serial: %d", dp->cert_infos_n[dp->current].serial );
127  break;
128 
129  case 5:
130  sprintf(line, "Issuer: %s", &dp->cert_infos_n[dp->current].issuer );
131  break;
132 
133  case 6:
134  sprintf(line, "Subject: %s", &dp->cert_infos_n[dp->current].subject );
135  break;
136 
137  case 7:
138  sprintf(line, "Cert type: %d", dp->cert_infos_n[dp->current].cert_type );
139  break;
140 
141  default:
142  break;
143  }
144  if( (int)strlen(line) > dp->scrollx ) {
145  if( dp->scrollx + maxchars < 511 && ( (signed int)strlen(line) - dp->scrollx) > maxchars )
146  line[dp->scrollx + maxchars] = 0;
147  v_gtext(atari_plot_vdi_handle, work.g_x + 1, work.g_y + px_ypos, &line[dp->scrollx]);
148  }
149  px_ypos += cbh;
150  }
151  vst_alignment(atari_plot_vdi_handle, 0, 0, &d, &d );
152  vs_clip( atari_plot_vdi_handle, 0, (short*)&pxy );
153  free( line );
154 }
155 
156 
157 static void do_popup( WINDOW *win, int index, int mode, void *data)
158 {
159  struct ssl_info_draw_param * dp = (struct ssl_info_draw_param *)data;
160  char * items[dp->num_certs];
161  short x, y;
162  unsigned int i;
163  NSLOG(netsurf, INFO, "do_popup: num certs: %d", dp->num_certs);
164  for( i = 0; i<dp->num_certs; i++) {
165  items[i] = malloc( 48 );
166  strncpy(items[i], (char*)&dp->cert_infos_n[i].issuer, 46 );
167  }
168  objc_offset( FORM(win), index, &x, &y );
169  dp->current = MenuPopUp( items, x, y,
170  dp->num_certs, MIN( 3, dp->num_certs), 0,
171  P_LIST + P_WNDW + P_CHCK );
172  ObjcChange( OC_FORM, win, index, NORMAL, TRUE );
173  dp->cols = cert_display_width( &dp->cert_infos_n[dp->current] );
174  dp->rows = 8;
175  dp->scrollx = 0;
176  dp->scrolly = 0;
177 
178  /* Send (!) redraw ( OC_MSG ) */
179  ObjcDrawParent( OC_FORM, FORM(win), VERIFY_BOX_DETAILS, 1, 7 | OC_MSG );
180  for( i = 0; i<dp->num_certs; i++) {
181  free( items[i] );
182  }
183 }
184 
185 
186 
187 bool
188 verify_ssl_form_do(const char * url,
189  const struct ssl_cert_info * cert_infos_n,
190  unsigned long num_certs)
191 {
192  OBJECT *tree;
193  WINDOW * form;
194 
195  bool bres = false;
196  bool cont = true;
197  int res = 0;
198 
199  RsrcGaddr (h_gem_rsrc , R_TREE, VERIFY, &tree);
200  ObjcString( tree, VERIFY_LBL_HOST, (char*)url );
201  ObjcChange( OC_OBJC, tree, VERIFY_BT_ACCEPT, 0, 0 );
202  ObjcChange( OC_OBJC, tree, VERIFY_BT_REJECT, 0, 0 );
203  form = FormWindBegin( tree, (char*)"SSL Verify failed" );
204 
205  dp.cert_infos_n = (struct ssl_cert_info *)cert_infos_n;
207  dp.scrollx = 0;
208  dp.scrolly = 0;
209  dp.current = 0;
211  dp.rows = 8;
212  dp.tree = tree;
213  EvntDataAdd( form, WM_REDRAW, cert_info_draw, (void*)&dp, EV_BOT );
214  /* this results in some extended objects which can not be freed: :( */
215  /* RsrcUserDraw( OC_FORM, tree, VERIFY_BOX_DETAILS, cert_info_draw,(void*)&dp ) ; */
216  ObjcAttachFormFunc( form, VERIFY_BT_NEXT_CERT, do_popup, &dp );
217  /*
218  ObjcAttachFormFunc( form, VERIFY_BT_NEXT_CERT, do_popup, &dp );
219  ObjcAttachFormFunc( form, VERIFY_BT_NEXT_CERT, do_popup, &dp );
220  */
221  while( cont ) {
222  res = FormWindDo( MU_MESAG );
223  cont = false;
224  switch( res ){
225  case VERIFY_BT_ACCEPT:
226  bres = true;
227  break;
228 
229  case VERIFY_BT_NEXT_CERT:
230  /* select box clicked or dragged... */
231  cont = true;
232  break;
233 
234  case VERIFY_BT_REJECT:
235  bres = false;
236  break;
237 
238  case VERIFY_BT_SCROLL_D:
239  cont = true;
240  dp.scrolly += 1;
241  ObjcDrawParent( OC_FORM, form, VERIFY_BOX_DETAILS, 1, 7 | OC_MSG );
242  break;
243 
244  case VERIFY_BT_SCROLL_U:
245  cont = true;
246  dp.scrolly -= 1;
247  ObjcDrawParent( OC_FORM, form, VERIFY_BOX_DETAILS, 1, 7 | OC_MSG );
248  break;
249 
250  case VERIFY_BT_SCROLL_R:
251  NSLOG(netsurf, INFO, "scroll r!");
252  cont = true;
253  dp.scrollx += 1;
254  if( dp.scrollx > (dp.cols - (272 / 8 )) )
255  dp.scrollx -= 1;
256  ObjcDrawParent( OC_FORM, form, VERIFY_BOX_DETAILS, 1, 7 | OC_MSG);
257  break;
258 
259  case VERIFY_BT_SCROLL_L:
260  cont = true;
261  dp.scrollx -= 1;
262  if( dp.scrollx < 0 )
263  dp.scrollx = 0;
264  ObjcDrawParent( OC_FORM, form, VERIFY_BOX_DETAILS, 1, 7 | OC_MSG );
265  break;
266 
267  default:
268  break;
269  }
270  }
271  FormWindEnd( );
272  return( bres );
273 }
Error codes.
static void do_popup(WINDOW *win, int index, int mode, void *data)
Definition: verify_ssl.c:157
struct ssl_cert_info * cert_infos_n
Definition: verify_ssl.c:47
Interface to utility string handling.
Localised message support (interface).
long version
Certificate version.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: plot.c:579
#define CERT_INF_LINES
Definition: verify_ssl.c:43
#define MIN(a, b)
Definition: os3support.h:51
unsigned long num_certs
Definition: verify_ssl.c:48
static struct ssl_info_draw_param dp
HTML form.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:115
char not_after[32]
Valid to date.
int sig_type
Signature type.
char subject[256]
Subject details.
int cert_type
Certificate type.
char not_before[32]
Valid from date.
ssl certificate information for certificate error message
static os_mode mode
The current sprite mode.
Definition: buffer.c:72
static html_css_fetcher_item * items
Definition: css_fetcher.c:65
Interface to a number of general purpose functionality.
char issuer[256]
Issuer details.
short atari_plot_vdi_handle
Definition: plot.c:208
static int cert_display_width(struct ssl_cert_info *cert_info)
Definition: verify_ssl.c:58
void * h_gem_rsrc
Definition: gui.c:75
SSL certificate info.
Definition: curl.c:214
bool verify_ssl_form_do(const char *url, const struct ssl_cert_info *cert_infos_n, unsigned long num_certs)
Definition: verify_ssl.c:188
static void __CDECL cert_info_draw(WINDOW *win, short buf[8], void *data)
Definition: verify_ssl.c:69