| 1 | /*
|
|---|
| 2 | * qcaprovider.h - QCA 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 |
|
|---|
| 21 | #ifndef QCAPROVIDER_H
|
|---|
| 22 | #define QCAPROVIDER_H
|
|---|
| 23 |
|
|---|
| 24 | #include<qglobal.h>
|
|---|
| 25 | #include<qstring.h>
|
|---|
| 26 | #include<qdatetime.h>
|
|---|
| 27 | #include<qobject.h>
|
|---|
| 28 | #include<qhostaddress.h>
|
|---|
| 29 | #include"qca.h"
|
|---|
| 30 |
|
|---|
| 31 | #define QCA_PLUGIN_VERSION 1
|
|---|
| 32 |
|
|---|
| 33 | class QCAProvider
|
|---|
| 34 | {
|
|---|
| 35 | public:
|
|---|
| 36 | QCAProvider() {}
|
|---|
| 37 | virtual ~QCAProvider() {}
|
|---|
| 38 |
|
|---|
| 39 | virtual void init()=0;
|
|---|
| 40 | virtual int qcaVersion() const=0;
|
|---|
| 41 | virtual int capabilities() const=0;
|
|---|
| 42 | virtual void *context(int cap)=0;
|
|---|
| 43 | };
|
|---|
| 44 |
|
|---|
| 45 | class QCA_HashContext
|
|---|
| 46 | {
|
|---|
| 47 | public:
|
|---|
| 48 | virtual ~QCA_HashContext() {}
|
|---|
| 49 |
|
|---|
| 50 | virtual QCA_HashContext *clone()=0;
|
|---|
| 51 | virtual void reset()=0;
|
|---|
| 52 | virtual void update(const char *in, unsigned int len)=0;
|
|---|
| 53 | virtual void final(QByteArray *out)=0;
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | class QCA_CipherContext
|
|---|
| 57 | {
|
|---|
| 58 | public:
|
|---|
| 59 | virtual ~QCA_CipherContext() {}
|
|---|
| 60 |
|
|---|
| 61 | virtual QCA_CipherContext *clone()=0;
|
|---|
| 62 | virtual int keySize()=0;
|
|---|
| 63 | virtual int blockSize()=0;
|
|---|
| 64 | virtual bool generateKey(char *out, int keysize=-1)=0;
|
|---|
| 65 | virtual bool generateIV(char *out)=0;
|
|---|
| 66 |
|
|---|
| 67 | virtual bool setup(int dir, int mode, const char *key, int keysize, const char *iv, bool pad)=0;
|
|---|
| 68 | virtual bool update(const char *in, unsigned int len)=0;
|
|---|
| 69 | virtual bool final(QByteArray *out)=0;
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | class QCA_RSAKeyContext
|
|---|
| 73 | {
|
|---|
| 74 | public:
|
|---|
| 75 | virtual ~QCA_RSAKeyContext() {}
|
|---|
| 76 |
|
|---|
| 77 | virtual QCA_RSAKeyContext *clone() const=0;
|
|---|
| 78 | virtual bool isNull() const=0;
|
|---|
| 79 | virtual bool havePublic() const=0;
|
|---|
| 80 | virtual bool havePrivate() const=0;
|
|---|
| 81 | virtual bool createFromDER(const char *in, unsigned int len)=0;
|
|---|
| 82 | virtual bool createFromPEM(const char *in, unsigned int len)=0;
|
|---|
| 83 | virtual bool createFromNative(void *in)=0;
|
|---|
| 84 | virtual bool generate(unsigned int bits)=0;
|
|---|
| 85 | virtual bool toDER(QByteArray *out, bool publicOnly)=0;
|
|---|
| 86 | virtual bool toPEM(QByteArray *out, bool publicOnly)=0;
|
|---|
| 87 |
|
|---|
| 88 | virtual bool encrypt(const QByteArray &in, QByteArray *out, bool oaep)=0;
|
|---|
| 89 | virtual bool decrypt(const QByteArray &in, QByteArray *out, bool oaep)=0;
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | struct QCA_CertProperty
|
|---|
| 93 | {
|
|---|
| 94 | QString var;
|
|---|
| 95 | QString val;
|
|---|
| 96 | };
|
|---|
| 97 |
|
|---|
| 98 | class QCA_CertContext
|
|---|
| 99 | {
|
|---|
| 100 | public:
|
|---|
| 101 | virtual ~QCA_CertContext() {}
|
|---|
| 102 |
|
|---|
| 103 | virtual QCA_CertContext *clone() const=0;
|
|---|
| 104 | virtual bool isNull() const=0;
|
|---|
| 105 | virtual bool createFromDER(const char *in, unsigned int len)=0;
|
|---|
| 106 | virtual bool createFromPEM(const char *in, unsigned int len)=0;
|
|---|
| 107 | virtual bool toDER(QByteArray *out)=0;
|
|---|
| 108 | virtual bool toPEM(QByteArray *out)=0;
|
|---|
| 109 |
|
|---|
| 110 | virtual QString serialNumber() const=0;
|
|---|
| 111 | virtual QString subjectString() const=0;
|
|---|
| 112 | virtual QString issuerString() const=0;
|
|---|
| 113 | virtual QValueList<QCA_CertProperty> subject() const=0;
|
|---|
| 114 | virtual QValueList<QCA_CertProperty> issuer() const=0;
|
|---|
| 115 | virtual QDateTime notBefore() const=0;
|
|---|
| 116 | virtual QDateTime notAfter() const=0;
|
|---|
| 117 | virtual bool matchesAddress(const QString &realHost) const=0;
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 | class QCA_TLSContext
|
|---|
| 121 | {
|
|---|
| 122 | public:
|
|---|
| 123 | enum Result { Success, Error, Continue };
|
|---|
| 124 | virtual ~QCA_TLSContext() {}
|
|---|
| 125 |
|
|---|
| 126 | virtual void reset()=0;
|
|---|
| 127 | virtual bool startClient(const QPtrList<QCA_CertContext> &store, const QCA_CertContext &cert, const QCA_RSAKeyContext &key)=0;
|
|---|
| 128 | virtual bool startServer(const QPtrList<QCA_CertContext> &store, const QCA_CertContext &cert, const QCA_RSAKeyContext &key)=0;
|
|---|
| 129 |
|
|---|
| 130 | virtual int handshake(const QByteArray &in, QByteArray *out)=0;
|
|---|
| 131 | virtual int shutdown(const QByteArray &in, QByteArray *out)=0;
|
|---|
| 132 | virtual bool encode(const QByteArray &plain, QByteArray *to_net, int *encoded)=0;
|
|---|
| 133 | virtual bool decode(const QByteArray &from_net, QByteArray *plain, QByteArray *to_net)=0;
|
|---|
| 134 | virtual bool eof() const=0;
|
|---|
| 135 | virtual QByteArray unprocessed()=0;
|
|---|
| 136 |
|
|---|
| 137 | virtual QCA_CertContext *peerCertificate() const=0;
|
|---|
| 138 | virtual int validityResult() const=0;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 | struct QCA_SASLHostPort
|
|---|
| 142 | {
|
|---|
| 143 | QHostAddress addr;
|
|---|
| 144 | Q_UINT16 port;
|
|---|
| 145 | };
|
|---|
| 146 |
|
|---|
| 147 | struct QCA_SASLNeedParams
|
|---|
| 148 | {
|
|---|
| 149 | bool user, authzid, pass, realm;
|
|---|
| 150 | };
|
|---|
| 151 |
|
|---|
| 152 | class QCA_SASLContext
|
|---|
| 153 | {
|
|---|
| 154 | public:
|
|---|
| 155 | enum Result { Success, Error, NeedParams, AuthCheck, Continue };
|
|---|
| 156 | virtual ~QCA_SASLContext() {}
|
|---|
| 157 |
|
|---|
| 158 | // common
|
|---|
| 159 | virtual void reset()=0;
|
|---|
| 160 | virtual void setCoreProps(const QString &service, const QString &host, QCA_SASLHostPort *local, QCA_SASLHostPort *remote)=0;
|
|---|
| 161 | virtual void setSecurityProps(bool noPlain, bool noActive, bool noDict, bool noAnon, bool reqForward, bool reqCreds, bool reqMutual, int ssfMin, int ssfMax, const QString &_ext_authid, int _ext_ssf)=0;
|
|---|
| 162 | virtual int security() const=0;
|
|---|
| 163 | virtual int errorCond() const=0;
|
|---|
| 164 |
|
|---|
| 165 | // init / first step
|
|---|
| 166 | virtual bool clientStart(const QStringList &mechlist)=0;
|
|---|
| 167 | virtual int clientFirstStep(bool allowClientSendFirst)=0;
|
|---|
| 168 | virtual bool serverStart(const QString &realm, QStringList *mechlist, const QString &name)=0;
|
|---|
| 169 | virtual int serverFirstStep(const QString &mech, const QByteArray *in)=0;
|
|---|
| 170 |
|
|---|
| 171 | // get / set params
|
|---|
| 172 | virtual QCA_SASLNeedParams clientParamsNeeded() const=0;
|
|---|
| 173 | virtual void setClientParams(const QString *user, const QString *authzid, const QString *pass, const QString *realm)=0;
|
|---|
| 174 | virtual QString username() const=0;
|
|---|
| 175 | virtual QString authzid() const=0;
|
|---|
| 176 |
|
|---|
| 177 | // continue steps
|
|---|
| 178 | virtual int nextStep(const QByteArray &in)=0;
|
|---|
| 179 | virtual int tryAgain()=0;
|
|---|
| 180 |
|
|---|
| 181 | // results
|
|---|
| 182 | virtual QString mech() const=0;
|
|---|
| 183 | virtual const QByteArray *clientInit() const=0;
|
|---|
| 184 | virtual QByteArray result() const=0;
|
|---|
| 185 |
|
|---|
| 186 | // security layer
|
|---|
| 187 | virtual bool encode(const QByteArray &in, QByteArray *out)=0;
|
|---|
| 188 | virtual bool decode(const QByteArray &in, QByteArray *out)=0;
|
|---|
| 189 | };
|
|---|
| 190 |
|
|---|
| 191 | #endif
|
|---|