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.

qcaprovider.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #include"qca.h"
  28. #define TQCA_PLUGIN_VERSION 1
  29. class TQCAProvider
  30. {
  31. public:
  32. TQCAProvider() {}
  33. virtual ~TQCAProvider() {}
  34. virtual void init()=0;
  35. virtual int qcaVersion() const=0;
  36. virtual int capabilities() const=0;
  37. virtual void *context(int cap)=0;
  38. };
  39. class TQCA_HashContext
  40. {
  41. public:
  42. virtual ~TQCA_HashContext() {}
  43. virtual TQCA_HashContext *clone()=0;
  44. virtual void reset()=0;
  45. virtual void update(const char *in, unsigned int len)=0;
  46. virtual void final(TQByteArray *out)=0;
  47. };
  48. class TQCA_CipherContext
  49. {
  50. public:
  51. virtual ~TQCA_CipherContext() {}
  52. virtual TQCA_CipherContext *clone()=0;
  53. virtual int keySize()=0;
  54. virtual int blockSize()=0;
  55. virtual bool generateKey(char *out, int keysize=-1)=0;
  56. virtual bool generateIV(char *out)=0;
  57. virtual bool setup(int dir, int mode, const char *key, int keysize, const char *iv, bool pad)=0;
  58. virtual bool update(const char *in, unsigned int len)=0;
  59. virtual bool final(TQByteArray *out)=0;
  60. };
  61. class TQCA_RSAKeyContext
  62. {
  63. public:
  64. virtual ~TQCA_RSAKeyContext() {}
  65. virtual TQCA_RSAKeyContext *clone() const=0;
  66. virtual bool isNull() const=0;
  67. virtual bool havePublic() const=0;
  68. virtual bool havePrivate() const=0;
  69. virtual bool createFromDER(const char *in, unsigned int len)=0;
  70. virtual bool createFromPEM(const char *in, unsigned int len)=0;
  71. virtual bool createFromNative(void *in)=0;
  72. virtual bool generate(unsigned int bits)=0;
  73. virtual bool toDER(TQByteArray *out, bool publicOnly)=0;
  74. virtual bool toPEM(TQByteArray *out, bool publicOnly)=0;
  75. virtual bool encrypt(const TQByteArray &in, TQByteArray *out, bool oaep)=0;
  76. virtual bool decrypt(const TQByteArray &in, TQByteArray *out, bool oaep)=0;
  77. };
  78. struct TQCA_CertProperty
  79. {
  80. TQString var;
  81. TQString val;
  82. };
  83. class TQCA_CertContext
  84. {
  85. public:
  86. virtual ~TQCA_CertContext() {}
  87. virtual TQCA_CertContext *clone() const=0;
  88. virtual bool isNull() const=0;
  89. virtual bool createFromDER(const char *in, unsigned int len)=0;
  90. virtual bool createFromPEM(const char *in, unsigned int len)=0;
  91. virtual bool toDER(TQByteArray *out)=0;
  92. virtual bool toPEM(TQByteArray *out)=0;
  93. virtual TQString serialNumber() const=0;
  94. virtual TQString subjectString() const=0;
  95. virtual TQString issuerString() const=0;
  96. virtual TQValueList<TQCA_CertProperty> subject() const=0;
  97. virtual TQValueList<TQCA_CertProperty> issuer() const=0;
  98. virtual TQDateTime notBefore() const=0;
  99. virtual TQDateTime notAfter() const=0;
  100. virtual bool matchesAddress(const TQString &realHost) const=0;
  101. };
  102. class TQCA_TLSContext
  103. {
  104. public:
  105. enum Result { Success, Error, Continue };
  106. virtual ~TQCA_TLSContext() {}
  107. virtual void reset()=0;
  108. virtual bool startClient(const TQPtrList<TQCA_CertContext> &store, const TQCA_CertContext &cert, const TQCA_RSAKeyContext &key)=0;
  109. virtual bool startServer(const TQPtrList<TQCA_CertContext> &store, const TQCA_CertContext &cert, const TQCA_RSAKeyContext &key)=0;
  110. virtual int handshake(const TQByteArray &in, TQByteArray *out)=0;
  111. virtual int shutdown(const TQByteArray &in, TQByteArray *out)=0;
  112. virtual bool encode(const TQByteArray &plain, TQByteArray *to_net, int *encoded)=0;
  113. virtual bool decode(const TQByteArray &from_net, TQByteArray *plain, TQByteArray *to_net)=0;
  114. virtual bool eof() const=0;
  115. virtual TQByteArray unprocessed()=0;
  116. virtual TQCA_CertContext *peerCertificate() const=0;
  117. virtual int validityResult() const=0;
  118. };
  119. struct TQCA_SASLHostPort
  120. {
  121. TQHostAddress addr;
  122. TQ_UINT16 port;
  123. };
  124. struct TQCA_SASLNeedParams
  125. {
  126. bool user, authzid, pass, realm;
  127. };
  128. class TQCA_SASLContext
  129. {
  130. public:
  131. enum Result { Success, Error, NeedParams, AuthCheck, Continue };
  132. virtual ~TQCA_SASLContext() {}
  133. // common
  134. virtual void reset()=0;
  135. virtual void setCoreProps(const TQString &service, const TQString &host, TQCA_SASLHostPort *local, TQCA_SASLHostPort *remote)=0;
  136. 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;
  137. virtual int security() const=0;
  138. virtual int errorCond() const=0;
  139. // init / first step
  140. virtual bool clientStart(const TQStringList &mechlist)=0;
  141. virtual int clientFirstStep(bool allowClientSendFirst)=0;
  142. virtual bool serverStart(const TQString &realm, TQStringList *mechlist, const TQString &name)=0;
  143. virtual int serverFirstStep(const TQString &mech, const TQByteArray *in)=0;
  144. // get / set params
  145. virtual TQCA_SASLNeedParams clientParamsNeeded() const=0;
  146. virtual void setClientParams(const TQString *user, const TQString *authzid, const TQString *pass, const TQString *realm)=0;
  147. virtual TQString username() const=0;
  148. virtual TQString authzid() const=0;
  149. // continue steps
  150. virtual int nextStep(const TQByteArray &in)=0;
  151. virtual int tryAgain()=0;
  152. // results
  153. virtual TQString mech() const=0;
  154. virtual const TQByteArray *clientInit() const=0;
  155. virtual TQByteArray result() const=0;
  156. // security layer
  157. virtual bool encode(const TQByteArray &in, TQByteArray *out)=0;
  158. virtual bool decode(const TQByteArray &in, TQByteArray *out)=0;
  159. };
  160. #endif