gui.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  $RCSfile$
00003  -------------------
00004  cvs         : $Id: bio_buffer.c 1102 2006-12-30 19:39:37Z martin $
00005  begin       : Fri Feb 07 2003
00006  copyright   : (C) 2003 by Martin Preuss
00007  email       : martin@libchipcard.de
00008 
00009  ***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 
00029 #ifdef HAVE_CONFIG_H
00030 # include <config.h>
00031 #endif
00032 
00033 
00034 #include "gui_p.h"
00035 #include "i18n_l.h"
00036 
00037 #include <gwenhywfar/debug.h>
00038 
00039 
00040 
00041 static GWEN_GUI *gwenhywfar_gui=NULL;
00042 
00043 
00044 GWEN_INHERIT_FUNCTIONS(GWEN_GUI)
00045 
00046 
00047 
00048 GWEN_GUI *GWEN_Gui_new() {
00049   GWEN_GUI *gui;
00050 
00051   GWEN_NEW_OBJECT(GWEN_GUI, gui);
00052   GWEN_INHERIT_INIT(GWEN_GUI, gui);
00053   gui->refCount=1;
00054 
00055   gui->checkCertFn=GWEN_Gui_CheckCertBuiltIn;
00056 
00057   return gui;
00058 }
00059 
00060 
00061 
00062 void GWEN_Gui_free(GWEN_GUI *gui) {
00063   if (gui) {
00064     assert(gui->refCount);
00065     if ((--gui->refCount)==0) {
00066       GWEN_INHERIT_FINI(GWEN_GUI, gui);
00067       GWEN_FREE_OBJECT(gui);
00068     }
00069   }
00070 }
00071 
00072 
00073 
00074 void GWEN_Gui_Attach(GWEN_GUI *gui) {
00075   assert(gui);
00076   assert(gui->refCount);
00077   gui->refCount++;
00078 }
00079 
00080 
00081 
00082 void GWEN_Gui_SetGui(GWEN_GUI *gui) {
00083   if (gui)
00084     GWEN_Gui_Attach(gui);
00085   if (gwenhywfar_gui)
00086     GWEN_Gui_free(gwenhywfar_gui);
00087   gwenhywfar_gui=gui;
00088 }
00089 
00090 
00091 
00092 GWEN_GUI *GWEN_Gui_GetGui() {
00093   return gwenhywfar_gui;
00094 }
00095 
00096 
00097 
00098 GWEN_GUI_MESSAGEBOX_FN GWEN_Gui_SetMessageBoxFn(GWEN_GUI *gui,
00099                                                 GWEN_GUI_MESSAGEBOX_FN f){
00100   GWEN_GUI_MESSAGEBOX_FN of;
00101 
00102   assert(gui);
00103   of=gui->messageBoxFn;
00104   gui->messageBoxFn=f;
00105   return of;
00106 }
00107 
00108 
00109 
00110 GWEN_GUI_INPUTBOX_FN GWEN_Gui_SetInputBoxFn(GWEN_GUI *gui,
00111                                             GWEN_GUI_INPUTBOX_FN f){
00112   GWEN_GUI_INPUTBOX_FN of;
00113 
00114   assert(gui);
00115   of=gui->inputBoxFn;
00116   gui->inputBoxFn=f;
00117   return of;
00118 }
00119 
00120 
00121 
00122 GWEN_GUI_SHOWBOX_FN GWEN_Gui_SetShowBoxFn(GWEN_GUI *gui,
00123                                           GWEN_GUI_SHOWBOX_FN f){
00124   GWEN_GUI_SHOWBOX_FN of;
00125 
00126   assert(gui);
00127   of=gui->showBoxFn;
00128   gui->showBoxFn=f;
00129   return of;
00130 }
00131 
00132 
00133 
00134 GWEN_GUI_HIDEBOX_FN GWEN_Gui_SetHideBoxFn(GWEN_GUI *gui,
00135                                           GWEN_GUI_HIDEBOX_FN f){
00136   GWEN_GUI_HIDEBOX_FN of;
00137 
00138   assert(gui);
00139   of=gui->hideBoxFn;
00140   gui->hideBoxFn=f;
00141   return of;
00142 }
00143 
00144 
00145 
00146 GWEN_GUI_PROGRESS_START_FN
00147 GWEN_Gui_SetProgressStartFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_START_FN f){
00148   GWEN_GUI_PROGRESS_START_FN of;
00149 
00150   assert(gui);
00151   of=gui->progressStartFn;
00152   gui->progressStartFn=f;
00153   return of;
00154 }
00155 
00156 
00157 
00158 GWEN_GUI_PROGRESS_ADVANCE_FN
00159 GWEN_Gui_SetProgressAdvanceFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_ADVANCE_FN f){
00160   GWEN_GUI_PROGRESS_ADVANCE_FN of;
00161 
00162   assert(gui);
00163   of=gui->progressAdvanceFn;
00164   gui->progressAdvanceFn=f;
00165   return of;
00166 }
00167 
00168 
00169 
00170 GWEN_GUI_PROGRESS_LOG_FN
00171 GWEN_Gui_SetProgressLogFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_LOG_FN f){
00172   GWEN_GUI_PROGRESS_LOG_FN of;
00173 
00174   assert(gui);
00175   of=gui->progressLogFn;
00176   gui->progressLogFn=f;
00177   return of;
00178 }
00179 
00180 
00181 
00182 GWEN_GUI_PROGRESS_END_FN
00183 GWEN_Gui_SetProgressEndFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_END_FN f){
00184   GWEN_GUI_PROGRESS_END_FN of;
00185 
00186   assert(gui);
00187   of=gui->progressEndFn;
00188   gui->progressEndFn=f;
00189   return of;
00190 }
00191 
00192 
00193 
00194 GWEN_GUI_PRINT_FN GWEN_Gui_SetPrintFn(GWEN_GUI *gui,
00195                                       GWEN_GUI_PRINT_FN f){
00196   GWEN_GUI_PRINT_FN of;
00197 
00198   assert(gui);
00199   of=gui->printFn;
00200   gui->printFn=f;
00201   return of;
00202 }
00203 
00204 
00205 
00206 GWEN_GUI_GETPASSWORD_FN GWEN_Gui_SetGetPasswordFn(GWEN_GUI *gui,
00207                                                   GWEN_GUI_GETPASSWORD_FN f) {
00208   GWEN_GUI_GETPASSWORD_FN of;
00209 
00210   assert(gui);
00211   of=gui->getPasswordFn;
00212   gui->getPasswordFn=f;
00213   return of;
00214 }
00215 
00216 
00217 
00218 GWEN_GUI_SETPASSWORDSTATUS_FN
00219 GWEN_Gui_SetSetPasswordStatusFn(GWEN_GUI *gui,
00220                                 GWEN_GUI_SETPASSWORDSTATUS_FN f) {
00221   GWEN_GUI_SETPASSWORDSTATUS_FN of;
00222 
00223   assert(gui);
00224   of=gui->setPasswordStatusFn;
00225   gui->setPasswordStatusFn=f;
00226   return of;
00227 }
00228 
00229 
00230 
00231 GWEN_GUI_LOG_HOOK_FN GWEN_Gui_SetLogHookFn(GWEN_GUI *gui,
00232                                            GWEN_GUI_LOG_HOOK_FN f) {
00233   GWEN_GUI_LOG_HOOK_FN of;
00234 
00235   assert(gui);
00236   of=gui->logHookFn;
00237   gui->logHookFn=f;
00238 
00239   return of;
00240 }
00241 
00242 
00243 
00244 GWEN_GUI_WAITFORSOCKETS_FN GWEN_Gui_SetWaitForSocketsFn(GWEN_GUI *gui,
00245                                                         GWEN_GUI_WAITFORSOCKETS_FN f) {
00246   GWEN_GUI_WAITFORSOCKETS_FN of;
00247 
00248   assert(gui);
00249   of=gui->waitForSocketsFn;
00250   gui->waitForSocketsFn=f;
00251 
00252   return of;
00253 }
00254 
00255 
00256 
00257 GWEN_GUI_CHECKCERT_FN GWEN_Gui_SetCheckCertFn(GWEN_GUI *gui, GWEN_GUI_CHECKCERT_FN f) {
00258   GWEN_GUI_CHECKCERT_FN of;
00259 
00260   assert(gui);
00261   of=gui->checkCertFn;
00262   gui->checkCertFn=f;
00263 
00264   return of;
00265 }
00266 
00267 
00268 
00269 GWEN_GUI_KEYDATAFROMTEXT_OPENSSL_FN
00270 GWEN_Gui_SetKeyDataFromTextOpenSslFn(GWEN_GUI *gui,
00271                                      GWEN_GUI_KEYDATAFROMTEXT_OPENSSL_FN f) {
00272   GWEN_GUI_KEYDATAFROMTEXT_OPENSSL_FN of;
00273 
00274   assert(gui);
00275   of=gui->keyDataFromTextOpenSslFn;
00276   gui->keyDataFromTextOpenSslFn=f;
00277 
00278   return of;
00279 
00280 }
00281 
00282 
00283 
00284 uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui) {
00285   assert(gui);
00286   return gui->flags;
00287 }
00288 
00289 
00290 
00291 void GWEN_Gui_SetFlags(GWEN_GUI *gui, uint32_t fl) {
00292   assert(gui);
00293   gui->flags=fl;
00294 }
00295 
00296 
00297 
00298 void GWEN_Gui_AddFlags(GWEN_GUI *gui, uint32_t fl) {
00299   assert(gui);
00300   gui->flags|=fl;
00301 }
00302 
00303 
00304 
00305 void GWEN_Gui_SubFlags(GWEN_GUI *gui, uint32_t fl) {
00306   assert(gui);
00307   gui->flags&=~fl;
00308 }
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 int GWEN_Gui_MessageBox(uint32_t flags,
00320                         const char *title,
00321                         const char *text,
00322                         const char *b1,
00323                         const char *b2,
00324                         const char *b3,
00325                         uint32_t guiid) {
00326   if (gwenhywfar_gui && gwenhywfar_gui->messageBoxFn)
00327     return gwenhywfar_gui->messageBoxFn(gwenhywfar_gui,
00328                                         flags,
00329                                         title,
00330                                         text,
00331                                         b1, b2, b3, guiid);
00332   return GWEN_ERROR_NOT_IMPLEMENTED;
00333 }
00334 
00335 
00336 
00337 int GWEN_Gui_InputBox(uint32_t flags,
00338                       const char *title,
00339                       const char *text,
00340                       char *buffer,
00341                       int minLen,
00342                       int maxLen,
00343                       uint32_t guiid) {
00344   if (gwenhywfar_gui && gwenhywfar_gui->inputBoxFn)
00345     return gwenhywfar_gui->inputBoxFn(gwenhywfar_gui,
00346                                       flags,
00347                                       title,
00348                                       text,
00349                                       buffer,
00350                                       minLen, maxLen, guiid);
00351   return GWEN_ERROR_NOT_IMPLEMENTED;
00352 }
00353 
00354 
00355 
00356 uint32_t GWEN_Gui_ShowBox(uint32_t flags,
00357                           const char *title,
00358                           const char *text,
00359                           uint32_t guiid) {
00360   if (gwenhywfar_gui && gwenhywfar_gui->showBoxFn)
00361     return gwenhywfar_gui->showBoxFn(gwenhywfar_gui,
00362                                      flags,
00363                                      title,
00364                                      text,
00365                                      guiid);
00366   return 0;
00367 }
00368 
00369 
00370 
00371 void GWEN_Gui_HideBox(uint32_t id) {
00372   if (gwenhywfar_gui && gwenhywfar_gui->hideBoxFn)
00373     return gwenhywfar_gui->hideBoxFn(gwenhywfar_gui, id);
00374 }
00375 
00376 
00377 
00378 uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags,
00379                                 const char *title,
00380                                 const char *text,
00381                                 uint64_t total,
00382                                 uint32_t guiid) {
00383   if (gwenhywfar_gui && gwenhywfar_gui->progressStartFn)
00384     return gwenhywfar_gui->progressStartFn(gwenhywfar_gui,
00385                                            progressFlags,
00386                                            title,
00387                                            text,
00388                                            total,
00389                                            guiid);
00390   return 0;
00391 }
00392 
00393 
00394 
00395 int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress) {
00396   if (gwenhywfar_gui && gwenhywfar_gui->progressAdvanceFn)
00397     return gwenhywfar_gui->progressAdvanceFn(gwenhywfar_gui,
00398                                              id,
00399                                              progress);
00400   return 0;
00401 }
00402 
00403 
00404 
00405 int GWEN_Gui_ProgressLog(uint32_t id,
00406                          GWEN_LOGGER_LEVEL level,
00407                          const char *text) {
00408   if (gwenhywfar_gui && gwenhywfar_gui->progressLogFn)
00409     return gwenhywfar_gui->progressLogFn(gwenhywfar_gui,
00410                                          id, level, text);
00411   return 0;
00412 }
00413 
00414 
00415 
00416 int GWEN_Gui_ProgressEnd(uint32_t id) {
00417   if (gwenhywfar_gui && gwenhywfar_gui->progressEndFn)
00418     return gwenhywfar_gui->progressEndFn(gwenhywfar_gui, id);
00419   return GWEN_ERROR_NOT_IMPLEMENTED;
00420 }
00421 
00422 
00423 
00424 int GWEN_Gui_Print(const char *docTitle,
00425                    const char *docType,
00426                    const char *descr,
00427                    const char *text,
00428                    uint32_t guiid) {
00429   if (gwenhywfar_gui && gwenhywfar_gui->printFn)
00430     return gwenhywfar_gui->printFn(gwenhywfar_gui,
00431                                    docTitle,
00432                                    docType,
00433                                    descr,
00434                                    text,
00435                                    guiid);
00436   return GWEN_ERROR_NOT_IMPLEMENTED;
00437 }
00438 
00439 
00440 
00441 int GWEN_Gui_GetPassword(uint32_t flags,
00442                          const char *token,
00443                          const char *title,
00444                          const char *text,
00445                          char *buffer,
00446                          int minLen,
00447                          int maxLen,
00448                          uint32_t guiid) {
00449   if (gwenhywfar_gui) {
00450     if (gwenhywfar_gui->getPasswordFn)
00451       return gwenhywfar_gui->getPasswordFn(gwenhywfar_gui,
00452                                            flags,
00453                                            token,
00454                                            title,
00455                                            text,
00456                                            buffer,
00457                                            minLen,
00458                                            maxLen,
00459                                            guiid);
00460     else
00461       if (gwenhywfar_gui->inputBoxFn)
00462         return gwenhywfar_gui->inputBoxFn(gwenhywfar_gui,
00463                                         flags,
00464                                         title,
00465                                         text,
00466                                         buffer,
00467                                         minLen,
00468                                         maxLen,
00469                                         guiid);
00470   }
00471   return GWEN_ERROR_NOT_IMPLEMENTED;
00472 }
00473 
00474 
00475 
00476 int GWEN_Gui_SetPasswordStatus(const char *token,
00477                                const char *pin,
00478                                GWEN_GUI_PASSWORD_STATUS status,
00479                                uint32_t guiid) {
00480   if (gwenhywfar_gui && gwenhywfar_gui->setPasswordStatusFn)
00481     return gwenhywfar_gui->setPasswordStatusFn(gwenhywfar_gui,
00482                                                token, pin, status, guiid);
00483   return GWEN_ERROR_NOT_IMPLEMENTED;
00484 }
00485 
00486 
00487 
00488 int GWEN_Gui_LogHook(const char *logDomain,
00489                      GWEN_LOGGER_LEVEL priority, const char *s) {
00490   if (gwenhywfar_gui && gwenhywfar_gui->logHookFn) {
00491     if (priority>=GWEN_LoggerLevel_Debug &&
00492         logDomain &&
00493         strcasecmp(logDomain, "gwenhywfar")==0)
00494       /* don't send possibly sensitive data to the log function because
00495        * some application tend to store the messages indiscriminately.
00496        * In some cases sensitive information can be send to this function
00497        * which we don't want the application to store */
00498       return 0;
00499     else
00500       /* otherwise the log message seems to be uncritical, convey it */
00501       return gwenhywfar_gui->logHookFn(gwenhywfar_gui, logDomain, priority, s);
00502   }
00503   else
00504     /* handle as usual */
00505     return 0;
00506 }
00507 
00508 
00509 
00510 int GWEN_Gui_WaitForSockets(GWEN_SOCKET_LIST2 *readSockets,
00511                             GWEN_SOCKET_LIST2 *writeSockets,
00512                             uint32_t guiid,
00513                             int msecs) {
00514   if (gwenhywfar_gui && gwenhywfar_gui->waitForSocketsFn)
00515     return gwenhywfar_gui->waitForSocketsFn(gwenhywfar_gui, readSockets, writeSockets, guiid, msecs);
00516   else {
00517     GWEN_SOCKETSET *rset;
00518     GWEN_SOCKETSET *wset;
00519     GWEN_SOCKET_LIST2_ITERATOR *sit;
00520 
00521     rset=GWEN_SocketSet_new();
00522     wset=GWEN_SocketSet_new();
00523 
00524     /* fill read socket set */
00525     sit=GWEN_Socket_List2_First(readSockets);
00526     if (sit) {
00527       GWEN_SOCKET *s;
00528 
00529       s=GWEN_Socket_List2Iterator_Data(sit);
00530       assert(s);
00531 
00532       while(s) {
00533         GWEN_SocketSet_AddSocket(rset, s);
00534         s=GWEN_Socket_List2Iterator_Next(sit);
00535       }
00536       GWEN_Socket_List2Iterator_free(sit);
00537     }
00538 
00539     /* fill write socket set */
00540     sit=GWEN_Socket_List2_First(writeSockets);
00541     if (sit) {
00542       GWEN_SOCKET *s;
00543 
00544       s=GWEN_Socket_List2Iterator_Data(sit);
00545       assert(s);
00546 
00547       while(s) {
00548         GWEN_SocketSet_AddSocket(wset, s);
00549         s=GWEN_Socket_List2Iterator_Next(sit);
00550       }
00551       GWEN_Socket_List2Iterator_free(sit);
00552     }
00553 
00554     if (GWEN_SocketSet_GetSocketCount(rset)==0 &&
00555         GWEN_SocketSet_GetSocketCount(wset)==0) {
00556       /* no sockets to wait for, sleep for a few ms to keep cpu load down */
00557       GWEN_SocketSet_free(wset);
00558       GWEN_SocketSet_free(rset);
00559 
00560       if (msecs) {
00561         /* only sleep if a timeout was given */
00562         DBG_DEBUG(GWEN_LOGDOMAIN, "Sleeping (no socket)");
00563         GWEN_Socket_Select(NULL, NULL, NULL, GWEN_GUI_CPU_TIMEOUT);
00564       }
00565       return GWEN_ERROR_TIMEOUT;
00566     }
00567     else {
00568       int rv;
00569 
00570       rv=GWEN_Socket_Select(rset, wset, NULL, msecs);
00571       GWEN_SocketSet_free(wset);
00572       GWEN_SocketSet_free(rset);
00573 
00574       return rv;
00575     }
00576   }
00577 }
00578 
00579 
00580 
00581 int GWEN_Gui_CheckCert(const GWEN_SSLCERTDESCR *cd, GWEN_IO_LAYER *io, uint32_t guiid) {
00582   if (gwenhywfar_gui && gwenhywfar_gui->checkCertFn)
00583     return gwenhywfar_gui->checkCertFn(gwenhywfar_gui, cd, io, guiid);
00584   else
00585     return GWEN_ERROR_NOT_IMPLEMENTED;
00586 }
00587 
00588 
00589 
00590 int GWEN_Gui_CheckCertBuiltIn(GWEN_UNUSED GWEN_GUI *gui,
00591                               const GWEN_SSLCERTDESCR *cd,
00592                               GWEN_UNUSED GWEN_IO_LAYER *io, uint32_t guiid) {
00593   int rv;
00594   int isError;
00595   const char *hash;
00596   const char *status;
00597   const char *ipAddr;
00598   const char *statusOn;
00599   const char *statusOff;
00600   char varName[128];
00601   char dbuffer1[32];
00602   char dbuffer2[32];
00603   char buffer[8192];
00604   const GWEN_TIME *ti;
00605   const char *unknown;
00606   const char *commonName;
00607   const char *organizationName;
00608   const char *organizationalUnitName;
00609   const char *countryName;
00610   const char *localityName;
00611   const char *stateOrProvinceName;
00612 
00613   char *msg=I18S(
00614     "The following certificate has been received:\n"
00615     "Name        : %s\n"
00616     "Organisation: %s\n"
00617     "Department  : %s\n"
00618     "Country     : %s\n"
00619     "City        : %s\n"
00620     "State       : %s\n"
00621     "Valid after : %s\n"
00622     "Valid until : %s\n"
00623     "Hash        : %s\n"
00624     "Status      : %s\n"
00625     "Do you wish to accept this certificate?"
00626 
00627     "<html>"
00628     " <p>"
00629     "  The following certificate has been received:"
00630     " </p>"
00631     " <table>"
00632     "  <tr><td>Name</td><td>%s</td></tr>"
00633     "  <tr><td>Organisation</td><td>%s</td></tr>"
00634     "  <tr><td>Department</td><td>%s</td></tr>"
00635     "  <tr><td>Country</td><td>%s</td></tr>"
00636     "  <tr><td>City</td><td>%s</td></tr>"
00637     "  <tr><td>State</td><td>%s</td></tr>"
00638     "  <tr><td>Valid after</td><td>%s</td></tr>"
00639     "  <tr><td>Valid until</td><td>%s</td></tr>"
00640     "  <tr><td>Hash</td><td>%s</td></tr>"
00641     "  <tr><td>Status</td><td>%s%s%s</td></tr>"
00642     " </table>"
00643     " <p>"
00644     "  Do you wish to accept this certificate?"
00645     " </p>"
00646     "</html>"
00647     );
00648 
00649   memset(dbuffer1, 0, sizeof(dbuffer1));
00650   memset(dbuffer2, 0, sizeof(dbuffer2));
00651   memset(varName, 0, sizeof(varName));
00652 
00653   isError=GWEN_SslCertDescr_GetIsError(cd);
00654 
00655   hash=GWEN_SslCertDescr_GetFingerPrint(cd);
00656   status=GWEN_SslCertDescr_GetStatusText(cd);
00657   ipAddr=GWEN_SslCertDescr_GetIpAddress(cd);
00658 
00659   ti=GWEN_SslCertDescr_GetNotBefore(cd);
00660   if (ti) {
00661     GWEN_BUFFER *tbuf;
00662 
00663     tbuf=GWEN_Buffer_new(0, 32, 0, 1);
00664     /* TRANSLATORS: This string is used as a template string to
00665        convert a given time into your local translated timeformat. The
00666        following characters are accepted in the template string: Y -
00667        digit of the year, M - digit of the month, D - digit of the day
00668        of month, h - digit of the hour, m - digit of the minute, s-
00669        digit of the second. All other characters are left unchanged. */
00670     if (GWEN_Time_toString(ti, I18N("YYYY/MM/DD hh:mm:ss"), tbuf)) {
00671       DBG_ERROR(GWEN_LOGDOMAIN,
00672                 "Could not convert beforeDate to string");
00673       abort();
00674     }
00675     strncpy(dbuffer1, GWEN_Buffer_GetStart(tbuf), sizeof(dbuffer1)-1);
00676     GWEN_Buffer_free(tbuf);
00677   }
00678 
00679   ti=GWEN_SslCertDescr_GetNotAfter(cd);
00680   if (ti) {
00681     GWEN_BUFFER *tbuf;
00682 
00683     tbuf=GWEN_Buffer_new(0, 32, 0, 1);
00684     if (GWEN_Time_toString(ti, I18N("YYYY/MM/DD hh:mm:ss"), tbuf)) {
00685       DBG_ERROR(GWEN_LOGDOMAIN,
00686                 "Could not convert untilDate to string");
00687       abort();
00688     }
00689     strncpy(dbuffer2, GWEN_Buffer_GetStart(tbuf), sizeof(dbuffer2)-1);
00690     GWEN_Buffer_free(tbuf);
00691   }
00692 
00693   if (isError) {
00694     statusOn="<font color=red>";
00695     statusOff="</font>";
00696   }
00697   else {
00698     statusOn="<font color=green>";
00699     statusOff="</font>";
00700   }
00701 
00702   unknown=I18N("unknown");
00703   commonName=GWEN_SslCertDescr_GetCommonName(cd);
00704   if (!commonName)
00705     commonName=unknown;
00706   organizationName=GWEN_SslCertDescr_GetOrganizationName(cd);
00707   if (!organizationName)
00708     organizationName=unknown;
00709   organizationalUnitName=GWEN_SslCertDescr_GetOrganizationalUnitName(cd);
00710   if (!organizationalUnitName)
00711     organizationalUnitName=unknown;
00712   countryName=GWEN_SslCertDescr_GetCountryName(cd);
00713   if (!countryName)
00714     countryName=unknown;
00715   localityName=GWEN_SslCertDescr_GetLocalityName(cd);
00716   if (!localityName)
00717     localityName=unknown;
00718   stateOrProvinceName=GWEN_SslCertDescr_GetStateOrProvinceName(cd);
00719   if (!stateOrProvinceName)
00720     stateOrProvinceName=unknown;
00721   if (!status)
00722     status=unknown;
00723 
00724   snprintf(buffer, sizeof(buffer)-1,
00725            I18N(msg),
00726            commonName,
00727            organizationName,
00728            organizationalUnitName,
00729            countryName,
00730            localityName,
00731            stateOrProvinceName,
00732            dbuffer1, dbuffer2,
00733            hash,
00734            status,
00735            /* the same again for HTML */
00736            commonName,
00737            organizationName,
00738            organizationalUnitName,
00739            countryName,
00740            localityName,
00741            stateOrProvinceName,
00742            dbuffer1, dbuffer2,
00743            hash,
00744            statusOn,
00745            status,
00746            statusOff
00747           );
00748 
00749   rv=GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_TYPE_WARN |
00750                          GWEN_GUI_MSG_FLAGS_CONFIRM_B1 |
00751                          GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS,
00752                          I18N("Certificate Received"),
00753                          buffer,
00754                          I18N("Yes"), I18N("No"), 0, guiid);
00755   if (rv==1) {
00756     return 0;
00757   }
00758   else {
00759     DBG_NOTICE(GWEN_LOGDOMAIN, "User rejected certificate");
00760 
00761     return GWEN_ERROR_SSL_SECURITY;
00762   }
00763 }
00764 
00765 
00766 
00767 int GWEN_Gui_KeyDataFromText_OpenSSL(const char *text,
00768                                      unsigned char *buffer,
00769                                      unsigned int bufLength) {
00770   if (gwenhywfar_gui && gwenhywfar_gui->keyDataFromTextOpenSslFn)
00771     return gwenhywfar_gui->keyDataFromTextOpenSslFn(gwenhywfar_gui,
00772                                                     text,
00773                                                     buffer,
00774                                                     bufLength);
00775   return GWEN_ERROR_NOT_IMPLEMENTED;
00776 }
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
00789 
00790 
00791 
00792 

Generated by  doxygen 1.6.2