QSSLDevice.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           Data Encryption Support                             *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2003 by Niall Douglas.   All Rights Reserved.            *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 #ifndef QSSLDEVICE_H
00023 #define QSSLDEVICE_H
00024 
00025 #include "QIODeviceS.h"
00026 #include "FXString.h"
00027 #include "FXSecure.h"
00028 
00029 namespace FX {
00030 
00035 class FXStream;
00036 class QSSLDevice;
00037 
00081 class FXSSLPKeyPrivate;
00082 class FXAPI FXSSLPKey
00083 {
00084     friend class QSSLDevice;
00085     FXSSLPKeyPrivate *p;
00086 public:
00088     enum KeyType
00089     {
00090         NoEncryption=0, 
00091         RSA,            
00092         DH              
00093     };
00096     explicit FXSSLPKey(FXuint bitsize=0, KeyType type=NoEncryption);
00097     ~FXSSLPKey();
00098     FXSSLPKey(const FXSSLPKey &other);
00099     FXSSLPKey &operator=(const FXSSLPKey &other);
00101     bool operator==(const FXSSLPKey &other) const;
00103     bool operator!=(const FXSSLPKey &other) const { return !(*this==other); }
00105     bool operator<(const FXSSLPKey &other) const;
00107     bool operator>(const FXSSLPKey &other) const { return !(*this<other); }
00109     KeyType type() const throw();
00111     void setType(KeyType type);
00113     FXString typeAsString() const;
00115     FXuint bytesLen() const throw();
00117     FXuint bitsLen() const throw();
00119     void setBitsLen(FXuint newsize);
00121     bool hasPublicKey() const throw();
00123     FXSSLPKey publicKey() const;
00125     FXString publicKeyAsString() const;
00127     Secure::TigerHashValue publicKeyAsHash() const;
00129     bool hasPrivateKey() const throw();
00131     FXSSLPKey privateKey() const;
00133     void generate();
00135     bool verify() const;
00137     void readFromPEM(QIODevice *dev);
00139     void writeAsPEM(QIODevice *dev) const;
00140 
00142     static FXSSLPKey publicKeyFromString(const FXString &s, KeyType type);
00143     friend FXAPI FXStream &operator<<(FXStream &s, const FXSSLPKey &i);
00144     friend FXAPI FXStream &operator>>(FXStream &s, FXSSLPKey &i);
00145 };
00147 FXAPI FXStream &operator<<(FXStream &s, const FXSSLPKey &i);
00149 FXAPI FXStream &operator>>(FXStream &s, FXSSLPKey &i);
00150 
00217 class FXSSLKeyPrivate;
00218 class FXAPI FXSSLKey
00219 {
00220     friend class QSSLDevice;
00221     FXSSLKeyPrivate *p;
00222 public:
00224     enum KeyType
00225     {
00226         NoEncryption=0, 
00227         Blowfish,       
00228         AES,            
00229         Encrypted=0xffff 
00230     };
00235     explicit FXSSLKey(FXuint bitsize=0, KeyType type=NoEncryption, const FXString &text=(const char *) 0);
00236     ~FXSSLKey();
00237     FXSSLKey(const FXSSLKey &other);
00238     FXSSLKey &operator=(const FXSSLKey &other);
00240     bool operator==(const FXSSLKey &other) const;
00242     bool operator!=(const FXSSLKey &other) const { return !(*this==other); }
00244     bool operator<(const FXSSLKey &other) const;
00246     bool operator>(const FXSSLKey &other) const { return !(*this<other); }
00248     KeyType type() const throw();
00250     void setType(KeyType type);
00252     FXString typeAsString() const;
00254     FXuint saltLen() const throw();
00256     void setSaltLen(FXuint salt);
00258     FXSSLPKey *asymmetricKey() const throw();
00260     FXSSLKey &setAsymmetricKey(const FXSSLPKey *pkey);
00262     FXuint bytesLen() const throw();
00264     FXuint bitsLen() const throw();
00266     void setBitsLen(FXuint newsize);
00268     void generate();
00272     void generateFromText(const FXString &text, int rounds=65536);
00274     Secure::TigerHashValue hash() const throw();
00275 
00276     friend FXAPI FXStream &operator<<(FXStream &s, const FXSSLKey &i);
00277     friend FXAPI FXStream &operator>>(FXStream &s, FXSSLKey &i);
00278 };
00280 FXAPI FXStream &operator<<(FXStream &s, const FXSSLKey &i);
00282 FXAPI FXStream &operator>>(FXStream &s, FXSSLKey &i);
00283 
00668 struct QSSLDevicePrivate;
00669 class FXAPIR QSSLDevice : public QIODeviceS
00670 {
00671     QSSLDevicePrivate *p;
00672     QSSLDevice(const QSSLDevice &);
00673     QSSLDevice &operator=(const QSSLDevice &);
00674     virtual FXDLLLOCAL void *int_getOSHandle() const;
00675     inline FXDLLLOCAL void int_genEBuffer() const;
00676     FXDLLLOCAL void int_xorInEBuffer(char *dest, const char *src, FXuval amount);
00677 public:
00681     QSSLDevice(QIODevice *encrypteddev=0, bool enablev2=false);
00682     ~QSSLDevice();
00683 
00685     QIODevice *encryptedDev() const throw();
00687     void setEncryptedDev(QIODevice *dev);
00689     const FXSSLKey &key() const;
00691     void setKey(const FXSSLKey &key);
00693     bool SSLv2Available() const throw();
00695     void setSSLv2Available(bool a);
00697     bool SSLv3Available() const throw();
00699     void setSSLv3Available(bool a);
00701     FXString ciphers() const;
00703     void setCiphers(const FXString &list);
00704 
00706     bool usingSSLv2() const;
00708     bool usingSSLv3() const;
00710     bool usingTLSv1() const;
00716     FXString peerHostNameByCertificate() const;
00718     FXString cipherName() const;
00720     FXuint cipherBits() const;
00722     FXString cipherDescription() const;
00727     void renegotiate();
00728 
00730     FXuint fileHeaderLen() const throw();
00731 
00732     virtual bool isSynchronous() const;
00733     virtual bool create(FXuint mode=IO_ReadWrite);
00734     virtual bool open(FXuint mode=IO_ReadWrite);
00735     virtual void close();
00736     virtual void flush();
00737     virtual FXfval size() const;
00739     virtual void truncate(FXfval size);
00740     virtual FXfval at() const;
00741     virtual bool at(FXfval newpos);
00742     virtual bool atEnd() const;
00743     virtual const FXACL &permissions() const;
00744     virtual void setPermissions(const FXACL &);
00745     virtual FXuval readBlock(char *data, FXuval maxlen);
00746     virtual FXuval writeBlock(const char *data, FXuval maxlen);
00747     virtual FXuval readBlockFrom(char *data, FXuval maxlen, FXfval pos);
00748     virtual FXuval writeBlockTo(FXfval pos, const char *data, FXuval maxlen);
00749     virtual int ungetch(int c);
00750 public:
00754     static void setCertificateFile(const FXString &path);
00761     static void setPrivateKeyFile(const FXString &path, const FXString &password);
00763     static const FXString &strongestAnonCipher();
00765     static const FXString &fastestAnonCipher();
00766 };
00767 
00768 } // namespace
00769 
00770 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:26 2009 for TnFOX by doxygen v1.4.7