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.

ksmimecrypto.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2003 Stefan Rompf <sux@loplof.de>
  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 __KSMIMECRYPTO_H
  21. #define __KSMIMECRYPTO_H
  22. #include <tqcstring.h>
  23. #include <tqptrlist.h>
  24. #include "ksslpkcs12.h"
  25. #include "ksslcertificate.h"
  26. class KOpenSSLProxy;
  27. class KSMIMECryptoPrivate;
  28. class TDEIO_EXPORT KSMIMECrypto {
  29. public:
  30. KSMIMECrypto();
  31. ~KSMIMECrypto();
  32. enum algo { KSC_C_DES3_CBC = 1,
  33. KSC_C_RC2_CBC_128,
  34. KSC_C_RC2_CBC_64,
  35. KSC_C_DES_CBC,
  36. KSC_C_RC2_CBC_40 };
  37. enum rc { KSC_R_OK, /* everything ok */
  38. KSC_R_OTHER, /* unspecified error */
  39. KSC_R_NO_SSL, /* No crypto lib / compiled without SSL */
  40. KSC_R_NOCIPHER, /* encryption cipher n/a */
  41. KSC_R_NOMEM, /* out of memory */
  42. KSC_R_FORMAT, /* wrong input data format */
  43. KSC_R_WRONGKEY, /* wrong decryption/signature key */
  44. KSC_R_VERIFY /* data does not match signature */
  45. };
  46. /**
  47. * Sign a message
  48. * @param clearText MIME representation of the message (part) to sign
  49. * @param cipherText signature to append or signature block
  50. * @param privKey private key/certificate to sign with
  51. * @param certs additional certificates (may be empty)
  52. * @param detached create detached or opaque signature
  53. * @return 0 on success
  54. */
  55. rc signMessage(const TQCString &clearText,
  56. TQByteArray &cipherText,
  57. const KSSLPKCS12 &privKey,
  58. const TQPtrList<KSSLCertificate> &certs,
  59. bool detached);
  60. /**
  61. * Check a detached message signature
  62. * Will check if messages matches signature and extract certificates
  63. * Does not check certificates for validity!
  64. * @param clearText MIME representation of signed message (without SIG)
  65. * @param signature signature
  66. * @param foundCerts certificates found in this message
  67. * @return 0 on success
  68. */
  69. rc checkDetachedSignature(const TQCString &clearText,
  70. const TQByteArray &signature,
  71. TQPtrList<KSSLCertificate> &foundCerts);
  72. /**
  73. * Check an opaque signed message
  74. * Will check if signature matches and extract message
  75. * Does not check certificates for validity!
  76. * @param signedText signed message block
  77. * @param clearText cleartext of signed message
  78. * @param foundCerts certificates found in this mesasge
  79. * @return 0 on success
  80. */
  81. rc checkOpaqueSignature(const TQByteArray &signedText,
  82. TQCString &clearText,
  83. TQPtrList<KSSLCertificate> &foundCerts);
  84. /**
  85. * Encrypt a message
  86. * encrypts a message for the given list of recipients and the
  87. * selected algorithm. Note that any algorithm <128 bytes is
  88. * insecure and should never be used, even if SMIME-2 requires
  89. * only RC2-40
  90. * @param clearText MIME representation of message to encrypt
  91. * @param cipherText returned encrypted message
  92. * @param algorithm encryption algorithm
  93. * @param recip recipient certificates
  94. * @return 0 on success
  95. */
  96. rc encryptMessage(const TQCString &clearText,
  97. TQByteArray &cipherText,
  98. algo algorithm,
  99. const TQPtrList<KSSLCertificate> &recip);
  100. /**
  101. * Decrypt a message
  102. * @param cipherText encrypted message block
  103. * @param clearText returns decrypted message
  104. * @param privKey private key to use
  105. * @return 0 on success
  106. */
  107. rc decryptMessage(const TQByteArray &cipherText,
  108. TQCString &clearText,
  109. const KSSLPKCS12 &privKey);
  110. private:
  111. KSMIMECryptoPrivate *priv;
  112. KOpenSSLProxy *kossl;
  113. };
  114. #endif