TLS plugin for the TQt Cryptographic Architecture
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.
 
 
 

201 lines
6.0 KiB

  1. /*
  2. * qcaprovider.h - TQCA Plugin API
  3. * Copyright (C) 2003 Justin Karneges
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 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. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #ifndef TQCAPROVIDER_H
  21. #define TQCAPROVIDER_H
  22. #include<tqglobal.h>
  23. #include<tqstring.h>
  24. #include<tqdatetime.h>
  25. #include<tqobject.h>
  26. #include<tqhostaddress.h>
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #ifdef HAVE_TQCA
  31. #include <tqca.h>
  32. #else
  33. #include "qca.h"
  34. #endif
  35. #define TQCA_PLUGIN_VERSION 1
  36. class TQCAProvider
  37. {
  38. public:
  39. TQCAProvider() {}
  40. virtual ~TQCAProvider() {}
  41. virtual void init()=0;
  42. virtual int qcaVersion() const=0;
  43. virtual int capabilities() const=0;
  44. virtual void *context(int cap)=0;
  45. };
  46. class TQCA_HashContext
  47. {
  48. public:
  49. virtual ~TQCA_HashContext() {}
  50. virtual TQCA_HashContext *clone()=0;
  51. virtual void reset()=0;
  52. virtual void update(const char *in, unsigned int len)=0;
  53. virtual void final(TQByteArray *out)=0;
  54. };
  55. class TQCA_CipherContext
  56. {
  57. public:
  58. virtual ~TQCA_CipherContext() {}
  59. virtual TQCA_CipherContext *clone()=0;
  60. virtual int keySize()=0;
  61. virtual int blockSize()=0;
  62. virtual bool generateKey(char *out, int keysize=-1)=0;
  63. virtual bool generateIV(char *out)=0;
  64. virtual bool setup(int dir, int mode, const char *key, int keysize, const char *iv, bool pad)=0;
  65. virtual bool update(const char *in, unsigned int len)=0;
  66. virtual bool final(TQByteArray *out)=0;
  67. };
  68. class TQCA_RSAKeyContext
  69. {
  70. public:
  71. virtual ~TQCA_RSAKeyContext() {}
  72. virtual TQCA_RSAKeyContext *clone() const=0;
  73. virtual bool isNull() const=0;
  74. virtual bool havePublic() const=0;
  75. virtual bool havePrivate() const=0;
  76. virtual bool createFromDER(const char *in, unsigned int len)=0;
  77. virtual bool createFromPEM(const char *in, unsigned int len)=0;
  78. virtual bool createFromNative(void *in)=0;
  79. virtual bool generate(unsigned int bits)=0;
  80. virtual bool toDER(TQByteArray *out, bool publicOnly)=0;
  81. virtual bool toPEM(TQByteArray *out, bool publicOnly)=0;
  82. virtual bool encrypt(const TQByteArray &in, TQByteArray *out, bool oaep)=0;
  83. virtual bool decrypt(const TQByteArray &in, TQByteArray *out, bool oaep)=0;
  84. };
  85. struct TQCA_CertProperty
  86. {
  87. TQString var;
  88. TQString val;
  89. };
  90. class TQCA_CertContext
  91. {
  92. public:
  93. virtual ~TQCA_CertContext() {}
  94. virtual TQCA_CertContext *clone() const=0;
  95. virtual bool isNull() const=0;
  96. virtual bool createFromDER(const char *in, unsigned int len)=0;
  97. virtual bool createFromPEM(const char *in, unsigned int len)=0;
  98. virtual bool toDER(TQByteArray *out)=0;
  99. virtual bool toPEM(TQByteArray *out)=0;
  100. virtual TQString serialNumber() const=0;
  101. virtual TQString subjectString() const=0;
  102. virtual TQString issuerString() const=0;
  103. virtual TQValueList<TQCA_CertProperty> subject() const=0;
  104. virtual TQValueList<TQCA_CertProperty> issuer() const=0;
  105. virtual TQDateTime notBefore() const=0;
  106. virtual TQDateTime notAfter() const=0;
  107. virtual bool matchesAddress(const TQString &realHost) const=0;
  108. };
  109. class TQCA_TLSContext
  110. {
  111. public:
  112. enum Result { Success, Error, Continue };
  113. virtual ~TQCA_TLSContext() {}
  114. virtual void reset()=0;
  115. virtual bool startClient(const TQPtrList<TQCA_CertContext> &store, const TQCA_CertContext &cert, const TQCA_RSAKeyContext &key)=0;
  116. virtual bool startServer(const TQPtrList<TQCA_CertContext> &store, const TQCA_CertContext &cert, const TQCA_RSAKeyContext &key)=0;
  117. virtual int handshake(const TQByteArray &in, TQByteArray *out)=0;
  118. virtual int shutdown(const TQByteArray &in, TQByteArray *out)=0;
  119. virtual bool encode(const TQByteArray &plain, TQByteArray *to_net, int *encoded)=0;
  120. virtual bool decode(const TQByteArray &from_net, TQByteArray *plain, TQByteArray *to_net)=0;
  121. virtual bool eof() const=0;
  122. virtual TQByteArray unprocessed()=0;
  123. virtual TQCA_CertContext *peerCertificate() const=0;
  124. virtual int validityResult() const=0;
  125. };
  126. struct TQCA_SASLHostPort
  127. {
  128. TQHostAddress addr;
  129. TQ_UINT16 port;
  130. };
  131. struct TQCA_SASLNeedParams
  132. {
  133. bool user, authzid, pass, realm;
  134. };
  135. class TQCA_SASLContext
  136. {
  137. public:
  138. enum Result { Success, Error, NeedParams, AuthCheck, Continue };
  139. virtual ~TQCA_SASLContext() {}
  140. // common
  141. virtual void reset()=0;
  142. virtual void setCoreProps(const TQString &service, const TQString &host, TQCA_SASLHostPort *local, TQCA_SASLHostPort *remote)=0;
  143. virtual void setSecurityProps(bool noPlain, bool noActive, bool noDict, bool noAnon, bool reqForward, bool reqCreds, bool reqMutual, int ssfMin, int ssfMax, const TQString &_ext_authid, int _ext_ssf)=0;
  144. virtual int security() const=0;
  145. virtual int errorCond() const=0;
  146. // init / first step
  147. virtual bool clientStart(const TQStringList &mechlist)=0;
  148. virtual int clientFirstStep(bool allowClientSendFirst)=0;
  149. virtual bool serverStart(const TQString &realm, TQStringList *mechlist, const TQString &name)=0;
  150. virtual int serverFirstStep(const TQString &mech, const TQByteArray *in)=0;
  151. // get / set params
  152. virtual TQCA_SASLNeedParams clientParamsNeeded() const=0;
  153. virtual void setClientParams(const TQString *user, const TQString *authzid, const TQString *pass, const TQString *realm)=0;
  154. virtual TQString username() const=0;
  155. virtual TQString authzid() const=0;
  156. // continue steps
  157. virtual int nextStep(const TQByteArray &in)=0;
  158. virtual int tryAgain()=0;
  159. // results
  160. virtual TQString mech() const=0;
  161. virtual const TQByteArray *clientInit() const=0;
  162. virtual TQByteArray result() const=0;
  163. // security layer
  164. virtual bool encode(const TQByteArray &in, TQByteArray *out)=0;
  165. virtual bool decode(const TQByteArray &in, TQByteArray *out)=0;
  166. };
  167. #endif