gwenhywfar  5.10.1
gui_cert.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Fri Feb 07 2003
3  copyright : (C) 2021 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 /* included from gui.c */
26 
27 
28 
29 
30 int GWEN_Gui_CheckCert(const GWEN_SSLCERTDESCR *cd, GWEN_SYNCIO *sio, uint32_t guiid)
31 {
32  GWEN_GUI *gui;
33 
34  gui=GWEN_Gui_GetGui();
35  if (gui && gui->checkCertFn)
36  return gui->checkCertFn(gui, cd, sio, guiid);
37  else
39 }
40 
41 
42 
44  const GWEN_SSLCERTDESCR *cd,
45  GWEN_UNUSED GWEN_SYNCIO *sio, uint32_t guiid)
46 {
47  int rv;
48  int isError;
49  const char *hashMd5;
50  const char *hashSha1;
51  const char *hashSha512;
52  const char *status;
53  //const char *ipAddr;
54  const char *statusOn;
55  const char *statusOff;
56  char varName[128];
57  char dbuffer1[32];
58  char dbuffer2[32];
59  char buffer[8192];
60  const GWEN_TIME *ti;
61  const char *unknown;
62  const char *commonName;
63  const char *organizationName;
64  const char *organizationalUnitName;
65  const char *countryName;
66  const char *localityName;
67  const char *stateOrProvinceName;
68 
69  const char *msg=I18S(
70  "The following certificate has been received:\n"
71  "Name : %s\n"
72  "Organisation : %s\n"
73  "Department : %s\n"
74  "Country : %s\n"
75  "City : %s\n"
76  "State : %s\n"
77  "Valid after : %s\n"
78  "Valid until : %s\n"
79  "Hash (MD5) : %s\n"
80  "Hash (SHA1) : %s\n"
81  "Hash (SHA512): %s\n"
82  "Status : %s\n"
83  "Do you wish to accept this certificate?"
84 
85  "<html>"
86  " <p>"
87  " The following certificate has been received:"
88  " </p>"
89  " <table>"
90  " <tr><td>Name</td><td>%s</td></tr>"
91  " <tr><td>Organisation</td><td>%s</td></tr>"
92  " <tr><td>Department</td><td>%s</td></tr>"
93  " <tr><td>Country</td><td>%s</td></tr>"
94  " <tr><td>City</td><td>%s</td></tr>"
95  " <tr><td>State</td><td>%s</td></tr>"
96  " <tr><td>Valid after</td><td>%s</td></tr>"
97  " <tr><td>Valid until</td><td>%s</td></tr>"
98  " <tr><td>Hash (MD5)</td><td>%s</td></tr>"
99  " <tr><td>Hash (SHA1)</td><td>%s</td></tr>"
100  " <tr><td>Hash (SHA512)</td><td>%s</td></tr>"
101  " <tr><td>Status</td><td>%s%s%s</td></tr>"
102  " </table>"
103  " <p>"
104  " Do you wish to accept this certificate?"
105  " </p>"
106  "</html>"
107  );
108 
109  memset(dbuffer1, 0, sizeof(dbuffer1));
110  memset(dbuffer2, 0, sizeof(dbuffer2));
111  memset(varName, 0, sizeof(varName));
112 
113  isError=GWEN_SslCertDescr_GetIsError(cd);
114 
119  //ipAddr=GWEN_SslCertDescr_GetIpAddress(cd);
120 
122  if (ti) {
123  GWEN_BUFFER *tbuf;
124 
125  tbuf=GWEN_Buffer_new(0, 32, 0, 1);
126  /* TRANSLATORS: This string is used as a template string to
127  convert a given time into your local translated timeformat. The
128  following characters are accepted in the template string: Y -
129  digit of the year, M - digit of the month, D - digit of the day
130  of month, h - digit of the hour, m - digit of the minute, s-
131  digit of the second. All other characters are left unchanged. */
132  if (GWEN_Time_toString(ti, I18N("YYYY/MM/DD hh:mm:ss"), tbuf)) {
134  "Could not convert beforeDate to string");
135  abort();
136  }
137  strncpy(dbuffer1, GWEN_Buffer_GetStart(tbuf), sizeof(dbuffer1)-1);
138  GWEN_Buffer_free(tbuf);
139  }
140 
142  if (ti) {
143  GWEN_BUFFER *tbuf;
144 
145  tbuf=GWEN_Buffer_new(0, 32, 0, 1);
146  if (GWEN_Time_toString(ti, I18N("YYYY/MM/DD hh:mm:ss"), tbuf)) {
148  "Could not convert untilDate to string");
149  abort();
150  }
151  strncpy(dbuffer2, GWEN_Buffer_GetStart(tbuf), sizeof(dbuffer2)-1);
152  GWEN_Buffer_free(tbuf);
153  }
154 
155  if (isError) {
156  statusOn="<font color=red>";
157  statusOff="</font>";
158  }
159  else {
160  statusOn="<font color=green>";
161  statusOff="</font>";
162  }
163 
164  unknown=I18N("unknown");
165  commonName=GWEN_SslCertDescr_GetCommonName(cd);
166  if (!commonName)
167  commonName=unknown;
168  organizationName=GWEN_SslCertDescr_GetOrganizationName(cd);
169  if (!organizationName)
170  organizationName=unknown;
171  organizationalUnitName=GWEN_SslCertDescr_GetOrganizationalUnitName(cd);
172  if (!organizationalUnitName)
173  organizationalUnitName=unknown;
174  countryName=GWEN_SslCertDescr_GetCountryName(cd);
175  if (!countryName)
176  countryName=unknown;
177  localityName=GWEN_SslCertDescr_GetLocalityName(cd);
178  if (!localityName)
179  localityName=unknown;
180  stateOrProvinceName=GWEN_SslCertDescr_GetStateOrProvinceName(cd);
181  if (!stateOrProvinceName)
182  stateOrProvinceName=unknown;
183  if (!status)
184  status=unknown;
185 
186  snprintf(buffer, sizeof(buffer)-1,
187  I18N(msg),
188  commonName,
189  organizationName,
190  organizationalUnitName,
191  countryName,
192  localityName,
193  stateOrProvinceName,
194  dbuffer1, dbuffer2,
195  hashMd5,
196  hashSha1,
197  hashSha512,
198  status,
199  /* the same again for HTML */
200  commonName,
201  organizationName,
202  organizationalUnitName,
203  countryName,
204  localityName,
205  stateOrProvinceName,
206  dbuffer1, dbuffer2,
207  hashMd5,
208  hashSha1,
209  hashSha512,
210  statusOn,
211  status,
212  statusOff
213  );
214 
218  I18N("Certificate Received"),
219  buffer,
220  I18N("Yes"), I18N("No"), 0, guiid);
221  if (rv==1) {
222  return 0;
223  }
224  else {
225  DBG_NOTICE(GWEN_LOGDOMAIN, "User rejected certificate");
226 
228  }
229 }
230 
231 
232 
#define I18S(m)
Definition: error.c:43
const char * GWEN_SslCertDescr_GetFingerPrintSha1(const GWEN_SSLCERTDESCR *st)
struct GWEN_TIME GWEN_TIME
Definition: gwentime.h:43
struct GWEN_SSLCERTDESCR GWEN_SSLCERTDESCR
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define I18N(m)
Definition: error.c:42
int GWENHYWFAR_CB GWEN_Gui_CheckCertBuiltIn(GWEN_UNUSED GWEN_GUI *gui, const GWEN_SSLCERTDESCR *cd, GWEN_UNUSED GWEN_SYNCIO *sio, uint32_t guiid)
Definition: gui_cert.c:43
#define DBG_NOTICE(dbg_logger, format, args...)
Definition: debug.h:152
const char * GWEN_SslCertDescr_GetOrganizationName(const GWEN_SSLCERTDESCR *st)
const char * GWEN_SslCertDescr_GetFingerPrint(const GWEN_SSLCERTDESCR *st)
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWENHYWFAR_API int GWEN_Gui_MessageBox(uint32_t flags, const char *title, const char *text, const char *b1, const char *b2, const char *b3, uint32_t guiid)
Definition: gui_virtual.c:342
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
const GWEN_TIME * GWEN_SslCertDescr_GetNotBefore(const GWEN_SSLCERTDESCR *st)
const char * GWEN_SslCertDescr_GetStatusText(const GWEN_SSLCERTDESCR *st)
const char * GWEN_SslCertDescr_GetOrganizationalUnitName(const GWEN_SSLCERTDESCR *st)
struct GWEN_SYNCIO GWEN_SYNCIO
Definition: syncio.h:40
GWENHYWFAR_API int GWEN_Time_toString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
Definition: gwentime_all.c:830
#define GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS
Definition: gui.h:337
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
#define GWEN_ERROR_SSL_SECURITY
Definition: error.h:129
GWEN_GUI * GWEN_Gui_GetGui(void)
Definition: gui.c:160
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
const char * GWEN_SslCertDescr_GetCountryName(const GWEN_SSLCERTDESCR *st)
int GWEN_SslCertDescr_GetIsError(const GWEN_SSLCERTDESCR *st)
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
const char * GWEN_SslCertDescr_GetCommonName(const GWEN_SSLCERTDESCR *st)
#define GWEN_GUI_MSG_FLAGS_CONFIRM_B1
Definition: gui.h:299
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
const char * GWEN_SslCertDescr_GetFingerPrintSha512(const GWEN_SSLCERTDESCR *st)
const GWEN_TIME * GWEN_SslCertDescr_GetNotAfter(const GWEN_SSLCERTDESCR *st)
int GWEN_Gui_CheckCert(const GWEN_SSLCERTDESCR *cd, GWEN_SYNCIO *sio, uint32_t guiid)
Definition: gui_cert.c:30
const char * GWEN_SslCertDescr_GetLocalityName(const GWEN_SSLCERTDESCR *st)
#define GWEN_UNUSED
const char * GWEN_SslCertDescr_GetStateOrProvinceName(const GWEN_SSLCERTDESCR *st)
#define GWEN_GUI_MSG_FLAGS_TYPE_WARN
Definition: gui.h:287
#define GWEN_ERROR_NOT_IMPLEMENTED
Definition: error.h:108