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.

ksslpkcs12.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #ifndef _KSSLPKCS12_H
  21. #define _KSSLPKCS12_H
  22. #ifdef Q_WS_WIN
  23. #include "ksslconfig_win.h"
  24. #else
  25. #include "ksslconfig.h"
  26. #endif
  27. #ifdef KSSL_HAVE_SSL
  28. #define crypt _openssl_crypt
  29. #include <openssl/pkcs12.h>
  30. #undef crypt
  31. #else
  32. class PKCS12;
  33. class EVP_PKEY;
  34. class X509;
  35. #endif
  36. #include <ksslcertificate.h>
  37. #include <ksslcertchain.h>
  38. #ifndef STACK_OF
  39. #define STACK_OF(x) void
  40. #endif
  41. class KSSL;
  42. class KSSLPKCS12Private;
  43. class KOpenSSLProxy;
  44. /**
  45. * KDE PKCS#12 Certificate
  46. *
  47. * As of yet, this class is being defined. if you use it, let it be known
  48. * that BC will break on you until this message is removed.
  49. *
  50. * @author George Staikos <staikos@kde.org>
  51. * @see KSSL, KSSLCertificate
  52. * @short KDE PKCS#12 Certificate
  53. */
  54. class TDEIO_EXPORT KSSLPKCS12 {
  55. friend class KSSL;
  56. public:
  57. /**
  58. * Destroy this PKCS#12 certificate
  59. */
  60. virtual ~KSSLPKCS12();
  61. /**
  62. * The name of this certificate. This can be used to refer to the
  63. * certificate instead of passing the object itself.
  64. * @return the name of the certificate
  65. */
  66. TQString name();
  67. /**
  68. * Create a KSSLPKCS12 object from a Base64 in a TQString.
  69. * @param base64 the base64 encoded certificate
  70. * @param password a password for the certificate if encrypted
  71. * @return the PKCS#12 object, or NULL on failure.
  72. */
  73. static KSSLPKCS12* fromString(TQString base64, TQString password = "");
  74. /**
  75. * Create a KSSLPKCS12 object by reading a PKCS#12 file.
  76. * @param filename the filename of the certificate
  77. * @param password a password for the certificate if encrypted
  78. * @return the PKCS#12 object, or NULL on failure.
  79. */
  80. static KSSLPKCS12* loadCertFile(TQString filename, TQString password = "");
  81. /**
  82. * Convert to a Base64 string.
  83. * @return the certificate in base64 form
  84. */
  85. TQString toString();
  86. /**
  87. * Raw set the PKCS12 object.
  88. * @param c the openssl PKCS12 object
  89. * @internal
  90. */
  91. void setCert(PKCS12 *c);
  92. /**
  93. * Change the password of the PKCS#12 in memory.
  94. * @param pold the old password
  95. * @param pnew the new password
  96. * @return true on success
  97. */
  98. bool changePassword(TQString pold, TQString pnew);
  99. /**
  100. * Get the private key.
  101. * @return the internal OpenSSL private key format
  102. * @internal
  103. */
  104. EVP_PKEY *getPrivateKey();
  105. /**
  106. * Get the X.509 certificate.
  107. * @return the X.509 certificate for the PKCS#12 object, or NULL
  108. */
  109. KSSLCertificate *getCertificate();
  110. /**
  111. * Write the PKCS#12 to a file in raw mode.
  112. * @param filename the file to write to
  113. * @return true on success
  114. */
  115. bool toFile(TQString filename);
  116. /**
  117. * Check the X.509 and private key to make sure they're valid.
  118. * @return the result of the validation
  119. * @see KSSLCertificate
  120. */
  121. KSSLCertificate::KSSLValidation validate();
  122. /**
  123. * Check the X.509 and private key to make sure they're valid.
  124. * @param p the purpose to validate for
  125. * @return the result of the validation
  126. * @see KSSLCertificate
  127. */
  128. KSSLCertificate::KSSLValidation validate(KSSLCertificate::KSSLPurpose p);
  129. /**
  130. * Check the X.509 and private key to make sure they're valid.
  131. * Ignore any cached validation result.
  132. * @return the result of the validation
  133. * @see KSSLCertificate
  134. */
  135. KSSLCertificate::KSSLValidation revalidate();
  136. /**
  137. * Check the X.509 and private key to make sure they're valid.
  138. * Ignore any cached validation result.
  139. * @param p the purpose to validate for
  140. * @return the result of the validation
  141. * @see KSSLCertificate
  142. */
  143. KSSLCertificate::KSSLValidation revalidate(KSSLCertificate::KSSLPurpose p);
  144. /**
  145. * Check if the X.509 and private key are valid.
  146. * @return true if valid
  147. */
  148. bool isValid();
  149. /**
  150. * Check if the X.509 and private key are valid.
  151. * @param p the purpose to validate for
  152. * @return true if valid
  153. */
  154. bool isValid(KSSLCertificate::KSSLPurpose p);
  155. protected:
  156. KSSLPKCS12();
  157. bool parse(TQString pass);
  158. private:
  159. KSSLPKCS12Private *d;
  160. PKCS12 *_pkcs;
  161. KOpenSSLProxy *kossl;
  162. EVP_PKEY *_pkey;
  163. KSSLCertificate *_cert;
  164. STACK_OF(X509) *_caStack;
  165. };
  166. #endif