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.

ksslx509v3.cc 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 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. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include "ksslx509v3.h"
  24. #include <kopenssl.h>
  25. #include <kdebug.h>
  26. KSSLX509V3::KSSLX509V3() {
  27. flags = 0;
  28. }
  29. KSSLX509V3::~KSSLX509V3() {
  30. }
  31. /* When reading this, please remember that
  32. * !A || B is logically equivalent to A => B
  33. */
  34. bool KSSLX509V3::certTypeCA() {
  35. #ifdef KSSL_HAVE_SSL
  36. // First try CA without X509_PURPOSE_ANY CA, then just try SSLCA
  37. return (flags & (65471L << 16)) ? true : certTypeSSLCA();
  38. #endif
  39. return false;
  40. }
  41. bool KSSLX509V3::certTypeSSLCA() {
  42. #ifdef KSSL_HAVE_SSL
  43. return (flags & ((1 << (16+X509_PURPOSE_NS_SSL_SERVER-1))|
  44. (1 << (16+X509_PURPOSE_SSL_SERVER-1))|
  45. (1 << (16+X509_PURPOSE_SSL_CLIENT-1)))) ? true :
  46. (false || ((1 << (16+X509_PURPOSE_ANY-1)) &&
  47. (certTypeSSLServer() ||
  48. certTypeSSLClient() ||
  49. certTypeNSSSLServer())));
  50. #endif
  51. return false;
  52. }
  53. bool KSSLX509V3::certTypeEmailCA() {
  54. #ifdef KSSL_HAVE_SSL
  55. return (flags & ((1 << (16+X509_PURPOSE_SMIME_ENCRYPT-1))|
  56. (1 << (16+X509_PURPOSE_SMIME_SIGN-1)))) ? true :
  57. (false || ((1 << (16+X509_PURPOSE_ANY-1)) &&
  58. certTypeSMIME()));
  59. #endif
  60. return false;
  61. }
  62. bool KSSLX509V3::certTypeCodeCA() {
  63. #ifdef KSSL_HAVE_SSL
  64. return (flags & (1 << (16+X509_PURPOSE_ANY-1))) ? true : false;
  65. #endif
  66. return false;
  67. }
  68. bool KSSLX509V3::certTypeSSLClient() {
  69. #ifdef KSSL_HAVE_SSL
  70. return (flags & (1 << (X509_PURPOSE_SSL_CLIENT-1))) ? true : false;
  71. #endif
  72. return false;
  73. }
  74. bool KSSLX509V3::certTypeSSLServer() {
  75. #ifdef KSSL_HAVE_SSL
  76. return (flags & (1 << (X509_PURPOSE_SSL_SERVER-1))) ? true : false;
  77. #endif
  78. return false;
  79. }
  80. bool KSSLX509V3::certTypeNSSSLServer() {
  81. #ifdef KSSL_HAVE_SSL
  82. return (flags & (1 << (X509_PURPOSE_NS_SSL_SERVER-1))) ? true : false;
  83. #endif
  84. return false;
  85. }
  86. bool KSSLX509V3::certTypeSMIME() {
  87. #ifdef KSSL_HAVE_SSL
  88. return certTypeSMIMEEncrypt()||certTypeSMIMESign();
  89. #endif
  90. return false;
  91. }
  92. bool KSSLX509V3::certTypeSMIMEEncrypt() {
  93. #ifdef KSSL_HAVE_SSL
  94. return (flags & (1 << (X509_PURPOSE_SMIME_ENCRYPT-1))) ? true : false;
  95. #endif
  96. return false;
  97. }
  98. bool KSSLX509V3::certTypeSMIMESign() {
  99. #ifdef KSSL_HAVE_SSL
  100. return (flags & (1 << (X509_PURPOSE_SMIME_SIGN-1))) ? true : false;
  101. #endif
  102. return false;
  103. }
  104. bool KSSLX509V3::certTypeCRLSign() {
  105. #ifdef KSSL_HAVE_SSL
  106. return (flags & (1 << (X509_PURPOSE_CRL_SIGN-1))) ? true : false;
  107. #endif
  108. return false;
  109. }