ksslutils.cc
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2000,2001 George Staikos <staikos@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 00022 #include "ksslutils.h" 00023 00024 #include <tqstring.h> 00025 #include <kglobal.h> 00026 #include <klocale.h> 00027 #include <tqdatetime.h> 00028 00029 #include "kopenssl.h" 00030 00031 #ifdef KSSL_HAVE_SSL 00032 // This code is mostly taken from OpenSSL v0.9.5a 00033 // by Eric Young 00034 TQDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) { 00035 TQDateTime qdt; 00036 char *v; 00037 int gmt=0; 00038 int gentime=0; 00039 int yoffset=0; 00040 int yearbase=1900; 00041 int i; 00042 int y=0,M=0,d=0,h=0,m=0,s=0; 00043 TQDate qdate; 00044 TQTime qtime; 00045 00046 i = tm->length; 00047 v = (char *)tm->data; 00048 if ((i == 15) || (i == 21)) { 00049 gentime=1; 00050 yoffset=2; 00051 yearbase=0; 00052 } 00053 if (i < 10) goto auq_err; 00054 if (v[i-1] == 'Z') gmt=1; 00055 for (i=0; i<10+yoffset; i++) 00056 if ((v[i] > '9') || (v[i] < '0')) goto auq_err; 00057 y = (v[0+yoffset]-'0')*10+(v[1+yoffset]-'0'); 00058 if (gentime) 00059 y += (v[0]-'0')*1000+(v[1]-'0')*100; 00060 if (y < 50) y+=100; 00061 M = (v[2+yoffset]-'0')*10+(v[3+yoffset]-'0'); 00062 if ((M > 12) || (M < 1)) goto auq_err; 00063 d = (v[4+yoffset]-'0')*10+(v[5+yoffset]-'0'); 00064 h = (v[6+yoffset]-'0')*10+(v[7+yoffset]-'0'); 00065 m = (v[8+yoffset]-'0')*10+(v[9+yoffset]-'0'); 00066 if ( (v[10+yoffset] >= '0') && (v[10+yoffset] <= '9') && 00067 (v[11+yoffset] >= '0') && (v[11+yoffset] <= '9')) 00068 s = (v[10+yoffset]-'0')*10+(v[11+yoffset]-'0'); 00069 00070 // localize the date and display it. 00071 qdate.setYMD(y+yearbase, M, d); 00072 qtime.setHMS(h,m,s); 00073 qdt.setDate(qdate); qdt.setTime(qtime); 00074 auq_err: 00075 if (isGmt) *isGmt = gmt; 00076 return qdt; 00077 } 00078 00079 00080 TQString ASN1_UTCTIME_QString(ASN1_UTCTIME *tm) { 00081 TQString qstr; 00082 int gmt; 00083 TQDateTime qdt = ASN1_UTCTIME_QDateTime(tm, &gmt); 00084 00085 qstr = KGlobal::locale()->formatDateTime(qdt, false, true); 00086 if (gmt) { 00087 qstr += " "; 00088 qstr += i18n("GMT"); 00089 } 00090 return qstr; 00091 } 00092 00093 00094 TQString ASN1_INTEGER_QString(ASN1_INTEGER *aint) { 00095 char *rep = KOSSL::self()->i2s_ASN1_INTEGER(NULL, aint); 00096 TQString yy = rep; 00097 KOSSL::self()->CRYPTO_free(rep); 00098 return yy; 00099 } 00100 00101 00102 #endif 00103