TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ksslutils.cc 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library 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 GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "ksslutils.h"
  21. #include <tqstring.h>
  22. #include <tdeglobal.h>
  23. #include <tdelocale.h>
  24. #include <tqdatetime.h>
  25. #include "kopenssl.h"
  26. #ifdef KSSL_HAVE_SSL
  27. // This code is mostly taken from OpenSSL v0.9.5a
  28. // by Eric Young
  29. TQDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) {
  30. TQDateTime qdt;
  31. char *v;
  32. int gmt=0;
  33. int gentime=0;
  34. int yoffset=0;
  35. int yearbase=1900;
  36. int i;
  37. int y=0,M=0,d=0,h=0,m=0,s=0;
  38. TQDate qdate;
  39. TQTime qtime;
  40. i = tm->length;
  41. v = (char *)tm->data;
  42. if ((i == 15) || (i == 21)) {
  43. gentime=1;
  44. yoffset=2;
  45. yearbase=0;
  46. }
  47. if (i < 10) goto auq_err;
  48. if (v[i-1] == 'Z') gmt=1;
  49. for (i=0; i<10+yoffset; i++)
  50. if ((v[i] > '9') || (v[i] < '0')) goto auq_err;
  51. y = (v[0+yoffset]-'0')*10+(v[1+yoffset]-'0');
  52. if (gentime)
  53. y += (v[0]-'0')*1000+(v[1]-'0')*100;
  54. if (y < 50) y+=100;
  55. M = (v[2+yoffset]-'0')*10+(v[3+yoffset]-'0');
  56. if ((M > 12) || (M < 1)) goto auq_err;
  57. d = (v[4+yoffset]-'0')*10+(v[5+yoffset]-'0');
  58. h = (v[6+yoffset]-'0')*10+(v[7+yoffset]-'0');
  59. m = (v[8+yoffset]-'0')*10+(v[9+yoffset]-'0');
  60. if ( (v[10+yoffset] >= '0') && (v[10+yoffset] <= '9') &&
  61. (v[11+yoffset] >= '0') && (v[11+yoffset] <= '9'))
  62. s = (v[10+yoffset]-'0')*10+(v[11+yoffset]-'0');
  63. // localize the date and display it.
  64. qdate.setYMD(y+yearbase, M, d);
  65. qtime.setHMS(h,m,s);
  66. qdt.setDate(qdate); qdt.setTime(qtime);
  67. auq_err:
  68. if (isGmt) *isGmt = gmt;
  69. return qdt;
  70. }
  71. TQString ASN1_UTCTIME_QString(ASN1_UTCTIME *tm) {
  72. TQString qstr;
  73. int gmt;
  74. TQDateTime qdt = ASN1_UTCTIME_QDateTime(tm, &gmt);
  75. qstr = TDEGlobal::locale()->formatDateTime(qdt, false, true);
  76. if (gmt) {
  77. qstr += " ";
  78. qstr += i18n("GMT");
  79. }
  80. return qstr;
  81. }
  82. TQString ASN1_INTEGER_QString(ASN1_INTEGER *aint) {
  83. char *rep = KOSSL::self()->i2s_ASN1_INTEGER(NULL, aint);
  84. TQString yy = rep;
  85. KOSSL::self()->CRYPTO_free(rep);
  86. return yy;
  87. }
  88. #endif