divide qca.h, move the includes

svn path=/trunk/kdesupport/qca/; revision=374565
This commit is contained in:
Justin Karneges 2005-01-01 02:44:28 +00:00
parent 1005b0de76
commit 47d42a6d6d
24 changed files with 3572 additions and 3303 deletions

1
TODO
View File

@ -17,6 +17,7 @@
cert: turn Info into an enum
cert/pkey: fingerprints (is there a standard for this?)
cert: subjectAltName
qcaprovider.h -> qca_provider ?
* finish code for APIs:
cipher - needs to handling padding

View File

@ -0,0 +1 @@
#include "qca.h"

131
include/QtCrypto/qca.h Normal file
View File

@ -0,0 +1,131 @@
/*
* qca.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_H
#define QCA_H
#include "qca_core.h"
#include "qca_textfilter.h"
#include "qca_basic.h"
#include "qca_publickey.h"
#include "qca_cert.h"
#include "qca_securelayer.h"
/**
\mainpage %Qt Cryptographic Architecture
Taking a hint from the similarly-named
<a href="http://java.sun.com/j2se/1.4/docs/guide/security/CryptoSpec.html">Java
Cryptography Architecture</a>, %QCA aims to provide a
straightforward and cross-platform cryptographic API, using Qt
datatypes and conventions. %QCA separates the API from the
implementation, using plugins known as Providers. The advantage
of this model is to allow applications to avoid linking to or
explicitly depending on any particular cryptographic library.
This allows one to easily change or upgrade Provider
implementations without even needing to recompile the
application!
%QCA should work everywhere %Qt does, including Windows/Unix/MacOSX.
\section features Features
This library provides an easy API for the following features:
- Secure byte arrays (QSecureArray)
- Arbitrary precision integers (QBigInteger)
- Random number generation (QCA::Random)
- SSL/TLS (ToDo)
- X509 certificate (Cert) (ToDo)
- Simple Authentication and Security Layer (SASL) (ToDo)
- RSA (ToDo)
- Hashing (QCA::Hash)
- QCA::SHA0
- QCA::SHA1
- QCA::MD2
- QCA::MD4
- QCA::MD5
- QCA::RIPEMD160
- QCA::SHA256
- QCA::SHA384
- QCA::SHA512
- Ciphers (QCA::Cipher)
- BlowFish (QCA::BlowFish)
- Triple %DES (QCA::TripleDES)
- %DES (QCA::DES)
- AES (QCA::AES128, QCA::AES192, QCA::AES256)
- Keyed Hash Message Authentication Code (QCA::HMAC), using
- SHA1
- MD5
- RIPEMD160
Functionality is supplied via plugins. This is useful for avoiding
dependence on a particular crypto library and makes upgrading easier,
as there is no need to recompile your application when adding or
upgrading a crypto plugin. Also, by pushing crypto functionality into
plugins, your application is free of legal issues, such as export
regulation.
And of course, you get a very simple crypto API for Qt, where you can
do things like:
\code
QString hash = QCA::SHA1().hashToString(blockOfData);
\endcode
\section using Using QCA
The application simply includes %qca.h and links to libqca,
which provides the 'wrapper API' and plugin loader. Crypto
functionality is determined during runtime, and plugins are
loaded from the 'crypto' subfolder of the %Qt library paths. There
are <a href="examples.html">additional examples available</a>.
\section availability Availability
\subsection qca2code Current development
The latest version of the code is available from the KDE CVS
server (there is no formal release of the current version at this time). See
<a href="http://developer.kde.org/source/anoncvs.html">
http://developer.kde.org/source/anoncvs.html
</a> for general instructions. You do <i>not</i> need kdelibs or
arts modules for %QCA - just pull down kdesupport/qca. The plugins
are in the same tree. Naturally you will need %Qt properly set up
and configured in order to build and use %QCA.
The CVS code can also be browsed
<a href="http://webcvs.kde.org/cgi-bin/cvsweb.cgi/kdesupport/qca/">
via the web</a>
\subsection qca1code Previous versions
A previous version of %QCA (sometimes referred to as QCA1) is still available.
You will need to get the main library
(<a href="src/qca1/qca-1.0.tar.bz2">qca-1.0.tar.bz2</a>) and one or
more providers
(<a href="src/qca1/qca-tls-1.0.tar.bz2">qca-tls-1.0.tar.bz2</a> for
the OpenSSL based provider, or
<a href="src/qca1/qca-sasl-1.0.tar.bz2">qca-sasl-1.0.tar.bz2</a> for
the SASL based provider). Note that development of QCA1 has basically
stopped.
*/
#endif

1208
include/QtCrypto/qca_basic.h Normal file

File diff suppressed because it is too large Load Diff

107
include/QtCrypto/qca_cert.h Normal file
View File

@ -0,0 +1,107 @@
/*
* qca_cert.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_CERT_H
#define QCA_CERT_H
#include <qmap.h>
#include "qca_core.h"
class QDateTime;
namespace QCA
{
class PublicKey;
class QCA_EXPORT Certificate : public Algorithm
{
public:
typedef QMap<QString, QString> Info;
Certificate();
bool isNull() const;
QDateTime notValidBefore() const;
QDateTime notValidAfter() const;
Info subjectInfo() const;
Info issuerInfo() const;
QString commonName() const;
QBigInteger serialNumber() const;
PublicKey subjectPublicKey() const;
SignAlgo signatureAlgorithm() const;
bool isCA() const;
bool isSelfSigned() const;
// import / export
QSecureArray toDER() const;
QString toPEM() const;
static Certificate fromDER(const QSecureArray &a, const QString &provider = QString() );
static Certificate fromPEM(const QString &s, const QString &provider = QString() );
bool matchesHostname(const QString &host) const;
bool operator==(const Certificate &a) const;
bool operator!=(const Certificate &a) const;
private:
friend class Store;
friend class TLS;
};
class QCA_EXPORT CRL : public Algorithm
{
public:
CRL();
bool isNull() const;
int number() const;
QDateTime thisUpdate() const;
QDateTime nextUpdate() const;
// import / export
QSecureArray toDER() const;
QString toPEM() const;
static CRL fromDER(const QSecureArray &a, const QString &provider = QString() );
static CRL fromPEM(const QString &s, const QString &provider = QString() );
private:
friend class Store;
};
class QCA_EXPORT Store : public Algorithm
{
public:
Store(const QString &provider = QString() );
void addCertificate(const Certificate &cert, bool trusted = false);
void addCRL(const CRL &crl);
CertValidity validate(const Certificate &cert, CertUsage u = Any) const;
private:
friend class TLS;
};
}
#endif

833
include/QtCrypto/qca_core.h Normal file
View File

@ -0,0 +1,833 @@
/*
* qca_core.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_CORE_H
#define QCA_CORE_H
#define QCA_VERSION 0x020000
#include <qptrlist.h>
#include <qstringlist.h>
#include "qca_export.h"
#include "qca_tools.h"
// Direct secure memory access. For interfacing with C libraries if needed.
QCA_EXPORT void *qca_secure_alloc(int bytes);
QCA_EXPORT void qca_secure_free(void *p);
/**
* QCA - the Qt Cryptographic Architecture
*/
namespace QCA
{
class Provider;
class Random;
class Store;
/**
* Convenience representation for the plugin providers
*
* You can get a list of providers using the providers()
* function
*
* \sa ProviderListIterator
* \sa providers()
*/
typedef QPtrList<Provider> ProviderList;
/**
* Convenience representation for iterator for the plugin providers
*
* You would use this something like the following:
* \code
* QCA::ProviderList qcaProviders = QCA::providers();
* QCA::ProviderListIterator it( qcaProviders );
* QCA::Provider *provider;
* while ( 0 != (provider = it.current() ) ) {
* ++it;
* cout << provider->name();
* }
* \endcode
*
* \sa ProviderList
* \sa providers()
*/
typedef QPtrListIterator<Provider> ProviderListIterator;
/**
* Mode settings for memory allocation
*
* QCA can use secure memory, however most operating systems
* restrict the amount of memory that can be pinned by user
* applications, to prevent a denial-of-service attack.
*
* QCA supports two approaches to getting memory - the mlock
* method, which generally requires root (administrator) level
* privileges, and the mmap method which is not as secure, but
* which should be able to be used by any process.
*
* \sa Initializer
*/
enum MemoryMode
{
Practical, ///< mlock and drop root if available, else mmap
Locking, ///< mlock and drop root
LockingKeepPrivileges ///< mlock, retaining root privileges
};
/**
* Direction settings for symmetric algorithms
*
* For some algorithms, it makes sense to have a "direction", such
* as Cipher algorithms which can be used to encrypt or decrypt.
*/
enum Direction
{
Encode, ///< Operate in the "forward" direction; for example, encrypting
Decode ///< Operate in the "reverse" direction; for example, decrypting
};
enum DL_Group
{
DSA_512,
DSA_768,
DSA_1024,
IETF_768,
IETF_1024,
IETF_1536,
IETF_2048,
IETF_3072,
IETF_4096
};
enum EncAlgo
{
EME_PKCS1v15,
EME_PKCS1_OAEP
};
enum SignAlgo
{
SignUnknown,
EMSA1_SHA1, // usual dsa
EMSA3_SHA1,
EMSA3_MD5, // usual rsa
EMSA3_MD2,
EMSA3_RIPEMD160
};
enum CertValidity
{
Valid,
Rejected,
Untrusted,
SignatureFailed,
InvalidCA,
InvalidPurpose,
SelfSigned,
Revoked,
PathLengthExceeded,
Expired,
Unknown
};
enum CertUsage
{
Any = 0x00,
TLSServer = 0x01,
TLSClient = 0x02,
CodeSigning = 0x04,
EmailProtection = 0x08,
TimeStamping = 0x10,
CRLSigning = 0x20
};
/**
* Specify the lower-bound for acceptable TLS/SASL security layers
*/
enum SecurityLevel
{
SL_None, ///< indicates that no security is ok
SL_Integrity, ///< must at least get integrity protection
SL_Export, ///< must be export level bits or more
SL_Baseline, ///< must be 128 bit or more
SL_High, ///< must be more than 128 bit
SL_Highest ///< SL_High or max possible, whichever is greater
};
/**
* Initialise %QCA.
* This call is not normally required, because it is cleaner
* to use an Initializer.
*/
QCA_EXPORT void init();
/**
* \overload
*
* \param m the MemoryMode to use
* \param prealloc the amount of memory in kilobytes to allocate
* for secure storage
*/
QCA_EXPORT void init(MemoryMode m, int prealloc);
/**
* Clean up routine
*
* This routine cleans up %QCA, including memory allocations
* This call is not normally required, because it is cleaner
* to use an Initializer
*/
QCA_EXPORT void deinit();
/**
* Test if secure storage memory is available
*
* \return true if secure storage memory is available
*/
QCA_EXPORT bool haveSecureMemory();
/**
* Test if a capability (algorithm) is available.
*
* Since capabilities are made available at runtime, you
* should always check before using a capability the first
* time, as shown below.
* \code
* QCA::init();
* if(!QCA::isSupported("sha1"))
* printf("SHA1 not supported!\n");
* else {
* QString result = QCA::SHA1::hashToString(myString);
* printf("sha1(\"%s\") = [%s]\n", myString.data(), result.latin1());
* }
* \endcode
*
* \param features the name of the capability to test for
*
* \return true if the capability is available, otherwise false
*
* Note that you can test for a combination of capabilities,
* using a comma delimited list:
* \code
* QCA::isSupported("sha1,md5"):
* \endcode
* which will return true if all of the capabilities listed
* are present.
*
*/
QCA_EXPORT bool isSupported(const char *features);
/**
* \overload
*
* \param features a list of features to test for
*/
QCA_EXPORT bool isSupported(const QStringList &features);
/**
* Generate a list of all the supported features in plugins,
* and in built in capabilities
*
* \return a list containing the names of the features
*
* The following code writes a list of features to standard out
* \code
* QStringList capabilities;
* capabilities = QCA::supportedFeatures();
* std::cout << "Supported:" << capabilities.join(",") << std::endl;
* \endcode
*
* \sa isSupported(const char *features)
* \sa isSupported(const QStringList &features)
* \sa defaultFeatures()
*/
QCA_EXPORT QStringList supportedFeatures();
/**
* Generate a list of the built in features. This differs from
* supportedFeatures() in that it does not include features provided
* by plugins.
*
* \return a list containing the names of the features
*
* The following code writes a list of features to standard out
* \code
* QStringList capabilities;
* capabilities = QCA::defaultFeatures();
* std::cout << "Default:" << capabilities.join(",") << std::endl;
* \endcode
*
* \sa isSupported(const char *features)
* \sa isSupported(const QStringList &features)
* \sa supportedFeatures()
*/
QCA_EXPORT QStringList defaultFeatures();
/**
* Add a provider to the current list of providers
*
* This function allows you to add a provider to the
* current plugin providers at a specified priority. If
* a provider with the name already exists, this call fails.
*
* \param p a pointer to a Provider object, which must be
* set up.
* \param priority the priority level to set the provider to
*
* \return true if the provider is added, and false if the
* provider is not added (failure)
*
* \sa setProviderPriority for a description of the provider priority system
*/
QCA_EXPORT bool insertProvider(Provider *p, int priority = 0);
/**
* Change the priority of a specified provider
*
* QCA supports a number of providers, and if a number of providers
* support the same algorithm, it needs to choose between them. You
* can do this at object instantiation time (by specifying the name
* of the provider that should be used). Alternatively, you can provide a
* relative priority level at an application level, using this call.
*
* Priority is used at object instantiation time. The provider is selected
* according to the following logic:
* - if a particular provider is nominated, and that provider supports
* the required algorithm, then the nominated provider is used
* - if no provider is nominated, or it doesn't support the required
* algorithm, then the provider with the lowest priority number will be used,
* if that provider supports the algorithm.
* - if the provider with the lowest priority number doesn't support
* the required algorithm, the provider with the next lowest priority number
* will be tried,and so on through to the provider with the largest priority number
* - if none of the plugin providers support the required algorithm, then
* the default (built-in) provider will be tried.
*
* \param name the name of the provider
* \param priority the new priority of the provider. As a special case, if
* you pass in -1, then this provider gets the same priority as the
* the last provider that was added or had its priority set using this
* call.
*
* \sa providerPriority
*/
QCA_EXPORT void setProviderPriority(const QString &name, int priority);
/**
* Return the priority of a specified provider
*
* The name of the provider (eg "qca-openssl") is used to look up the
* current priority associated with that provider. If the provider
* is not found (or something else went wrong), -1 is returned.
*
* \param name the name of the provider
*
* \return the current priority level
*
* \sa setProviderPriority for a description of the provider priority system
*/
QCA_EXPORT int providerPriority(const QString &name);
/**
* Return a list of the current providers
*
* The current plugin providers are provided as a list, which you
* can iterate over using ProviderListIterator.
*
* \sa ProviderList
* \sa ProviderListIterator
*/
QCA_EXPORT const ProviderList & providers();
/**
* Unload the current plugins
*
*/
QCA_EXPORT void unloadAllPlugins();
/**
* Return the Random provider that is currently set to be the
* global random number generator.
*
* For example, to get the name of the provider that is currently
* providing the Random capability, you could use:
* \code
* QCA::Random rng = QCA::globalRNG();
* std::cout << "Provider name: " << rng.provider()->name() << std::endl;
* \endcode
*/
QCA_EXPORT Random & globalRNG();
/**
* Change the global random generation provider
*
* The Random capabilities of %QCA are provided as part of the
* built in capabilities, however the generator can be changed
* if required.
*/
QCA_EXPORT void setGlobalRNG(const QString &provider);
QCA_EXPORT bool haveSystemStore();
QCA_EXPORT Store systemStore(const QString &provider = QString() );
/**
* Get the application name that will be used by SASL server mode
*
* The application name is used by SASL in server mode, as some systems might
* have different security policies depending on the app.
* The default application name is 'qca'
*/
QCA_EXPORT QString appName();
/**
* Set the application name that will be used by SASL server mode
*
* The application name is used by SASL in server mode, as some systems might
* have different security policies depending on the app. This should be set
* before using SASL objects, and it cannot be changed later.
*
* \param name the name string to use for SASL server mode
*/
QCA_EXPORT void setAppName(const QString &name);
/**
* Convert a byte array to printable hexadecimal
* representation.
*
* This is a convenience function to convert an arbitrary
* QSecureArray to a printable representation.
*
* \code
* QSecureArray test(10);
* test.fill('a');
* // 0x61 is 'a' in ASCII
* if (QString("61616161616161616161") == QCA::arrayToHex(test) ) {
* printf ("arrayToHex passed\n");
* }
* \endcode
*
* \param array the array to be converted
* \return a printable representation
*/
QCA_EXPORT QString arrayToHex(const QSecureArray &array);
/**
* Convert a QString containing a hexadecimal representation
* of a byte array into a QByteArray
*
* This is a convenience function to convert a printable
* representation into a QByteArray - effectively the inverse
* of QCA::arrayToHex.
*
* \code
* QCA::init();
* QByteArray test(10);
*
* test.fill('b'); // 0x62 in hexadecimal
* test[7] = 0x00; // can handle strings with nulls
*
* if (QCA::hexToArray(QString("62626262626262006262") ) == test ) {
* printf ("hexToArray passed\n");
* }
* \endcode
*
* \param hexString the string containing a printable
* representation to be converted
* \return the equivalent QByteArray
*
*/
QCA_EXPORT QByteArray hexToArray(const QString &hexString);
/**
* Convenience method for initialising and cleaning up %QCA
*
* To ensure that QCA is properly initialised and cleaned up,
* it is convenient to create an Initializer object, and let it
* go out of scope at the end of %QCA usage.
*/
class QCA_EXPORT Initializer
{
public:
/**
* Standard constructor
*
* \param m the MemoryMode to use for secure memory
* \param prealloc the amount of secure memory to pre-allocate,
* in units of 1024 bytes (1K).
*/
Initializer(MemoryMode m = Practical, int prealloc = 64);
~Initializer();
};
/**
* Simple container for acceptable key lengths
*
* The KeyLength specifies the minimum and maximum byte sizes
* allowed for a key, as well as a "multiple" which the key
* size must evenly divide into.
*
* As an example, if the key can be 4, 8 or 12 bytes, you can
* express this as
* \code
* KeyLength keyLen( 4, 12, 4 );
* \endcode
*
* If you want to express a KeyLength that takes any number
* of bytes (including zero), you may want to use
* \code
* #include<limits>
* KeyLength( 0, std::numeric_limits<int>::max(), 1 );
* \endcode
*/
class QCA_EXPORT KeyLength
{
public:
/**
* Construct a %KeyLength object
*
* \param min the minimum length of the key, in bytes
* \param max the maximum length of the key, in bytes
* \param multiple the number of bytes that the key must be a
* multiple of.
*/
KeyLength(int min, int max, int multiple)
: _min( min ), _max(max), _multiple( multiple )
{ }
/**
* Obtain the minimum length for the key, in bytes
*/
int minimum() const { return _min; }
/**
* Obtain the maximum length for the key, in bytes
*/
int maximum() const { return _max; }
/**
* Return the number of bytes that the key must be a multiple of
*
* If this is one, then anything between minumum and maximum (inclusive)
* is acceptable.
*/
int multiple() const { return _multiple; }
private:
int const _min, _max, _multiple;
};
/**
* Algorithm provider
*
* %Provider represents a plugin provider (or as a special case, the
* built-in provider). This is the class you need to inherit
* from to create your own plugin. You don't normally need to
* worry about this class if you are just using existing
* QCA capabilities and plugins, however there is nothing stopping
* you from using it to obtain information about specific plugins,
* as shown in the example below.
*/
class QCA_EXPORT Provider
{
public:
virtual ~Provider();
class Context
{
public:
Context(Provider *parent, const QString &type);
virtual ~Context();
Provider *provider() const;
QString type() const;
virtual Context *clone() const = 0;
bool sameProvider(Context *c);
int refs;
private:
Provider *_provider;
QString _type;
};
/**
* Initialisation routine.
*
* This routine will be called when your plugin
* is loaded, so this is a good place to do any
* one-off initialisation tasks. If you don't need
* any initialisation, just implement it as an empty
* routine.
*/
virtual void init();
/**
* The name of the provider.
*
* Typically you just return a string containing a
* convenient name.
*
* \code
* QString name() const
* {
* return "qca-myplugin";
* }
* \endcode
*
* \note The name is used to tell if a provider is
* already loaded, so you need to make sure it is
* unique amongst the various plugins.
*/
virtual QString name() const = 0;
/**
* The capabilities (algorithms) of the provider.
*
* Typically you just return a fixed QStringList:
* \code
* QStringList features() const
* {
* QStringList list;
* list += "sha1";
* list += "sha256";
* list += "hmac(md5)";
* return list;
* }
* \endcode
*/
virtual QStringList features() const = 0;
/**
* Routine to create a plugin context
*
* You need to return a pointer to an algorithm
* Context that corresponds with the algorithm
* name specified.
*
* \param type the name of the algorithm required
*
* \code
* Context *createContext(const QString &type)
* {
* if ( type == "sha1" )
* return new SHA1Context( this );
* else if ( type == "sha256" )
* return new SHA0256Context( this );
* else if ( type == "hmac(sha1)" )
* return new HMACSHA1Context( this );
* else
* return 0;
* }
* \endcode
*
* Naturally you also need to implement
* the specified Context subclasses as well.
*/
virtual Context *createContext(const QString &type) = 0;
};
/**
General superclass for buffered computation algorithms
A buffered computation is characterised by having the
algorithm take data in an incremental way, then having
the results delivered at the end. Conceptually, the
algorithm has some internal state that is modified
when you call update() and returned when you call
final().
*/
class QCA_EXPORT BufferedComputation
{
public:
virtual ~BufferedComputation();
/**
Reset the internal state
*/
virtual void clear() = 0;
/**
Update the internal state with a byte array
\param a the byte array of data that is to
be used to update the internal state.
*/
virtual void update(const QSecureArray &a) = 0;
/**
Complete the algorithm and return the internal state
*/
virtual QSecureArray final() = 0;
/**
Perform an "all in one" update, returning
the result. This is appropriate if you
have all the data in one array - just
call process on that array, and you will
get back the results of the computation.
\note This will invalidate any previous
computation using this object.
*/
QSecureArray process(const QSecureArray &a);
};
/**
General superclass for filtering transformation algorithms
A filtering computation is characterised by having the
algorithm take input data in an incremental way, with results
delivered for each input, or block of input. Some internal
state may be managed, with the transformation completed
when final() is called.
*/
class QCA_EXPORT Filter
{
public:
virtual ~Filter();
virtual void clear() = 0;
virtual QSecureArray update(const QSecureArray &a) = 0;
virtual QSecureArray final() = 0;
virtual bool ok() const = 0;
QSecureArray process(const QSecureArray &a);
};
/**
General superclass for an algorithm
*/
class QCA_EXPORT Algorithm
{
public:
Algorithm(const Algorithm &from);
virtual ~Algorithm();
/**
Assignment operator
\param from the Algorithm to copy state from
*/
Algorithm & operator=(const Algorithm &from);
/**
The type of algorithm
*/
QString type() const;
/**
The name of the provider
Each algorithm is implemented by a provider. This
allows you to figure out which provider is associated
*/
Provider *provider() const;
protected:
Algorithm();
Algorithm(const QString &type, const QString &provider);
Provider::Context *context() const;
void change(Provider::Context *c);
void change(const QString &type, const QString &provider);
void detach();
private:
class Private;
Private *d;
};
/**
* Container for keys for symmetric encryption algorithms.
*/
class QCA_EXPORT SymmetricKey : public QSecureArray
{
public:
/**
* Construct an empty (zero length) key
*/
SymmetricKey();
/**
* Construct an key of specified size, with random contents
*
* This is intended to be used as a random session key.
*
* \param size the number of bytes for the key
*
*/
SymmetricKey(int size);
/**
* Construct a key from a provided byte array
*
* \param a the byte array to copy
*/
SymmetricKey(const QSecureArray &a);
/**
* Construct a key from a provided string
*
* \param cs the QCString to copy
*/
SymmetricKey(const QCString &cs);
/**
* Test for weak DES keys
*
* \return true if the key is a weak key for DES
*/
bool isWeakDESKey();
};
/**
* Container for initialisation vectors and nonces
*/
class QCA_EXPORT InitializationVector : public QSecureArray
{
public:
/**
* Construct an empty (zero length) initisation vector
*/
InitializationVector();
/**
* Construct an initialisation vector of the specified size
*
* \param size the length of the initialisation vector, in bytes
*/
InitializationVector(int size);
/**
* Construct an initialisation vector from a provided byte array
*
* \param a the byte array to copy
*/
InitializationVector(const QSecureArray &a);
/**
* Construct an initialisaton vector from a provided string
*
* \param cs the QCString to copy
*/
InitializationVector(const QCString &cs);
};
}
#endif

View File

@ -0,0 +1,50 @@
/*
* qca_export.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_EXPORT_H
#define QCA_EXPORT_H
#include <qglobal.h>
#ifdef Q_OS_WIN32
# ifndef QCA_STATIC
# ifdef QCA_MAKEDLL
# define QCA_EXPORT __declspec(dllexport)
# else
# define QCA_EXPORT __declspec(dllimport)
# endif
# endif
#endif
#ifndef QCA_EXPORT
# define QCA_EXPORT
#endif
#ifdef Q_OS_WIN32
# ifdef QCA_PLUGIN_DLL
# define QCA_PLUGIN_EXPORT extern "C" __declspec(dllexport)
# else
# define QCA_PLUGIN_EXPORT extern "C" __declspec(dllimport)
# endif
#endif
#ifndef QCA_PLUGIN_EXPORT
# define QCA_PLUGIN_EXPORT extern "C"
#endif
#endif

View File

@ -0,0 +1,247 @@
/*
* qca_publickey.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_PUBLICKEY_H
#define QCA_PUBLICKEY_H
#include <qobject.h>
#include "qca_core.h"
namespace QCA
{
class PublicKey;
class PrivateKey;
class KeyGenerator;
class RSAPublicKey;
class RSAPrivateKey;
class DSAPublicKey;
class DSAPrivateKey;
class DHPublicKey;
class DHPrivateKey;
class QCA_EXPORT PKey : public Algorithm
{
public:
enum Type { RSA, DSA, DH };
PKey();
PKey(const PKey &from);
~PKey();
PKey & operator=(const PKey &from);
bool isNull() const;
Type type() const;
bool isRSA() const;
bool isDSA() const;
bool isDH() const;
bool isPublic() const;
bool isPrivate() const;
bool canKeyAgree() const;
PublicKey toPublicKey() const;
PrivateKey toPrivateKey() const;
friend class KeyGenerator;
protected:
PKey(const QString &type, const QString &provider);
void set(const PKey &k);
RSAPublicKey toRSAPublicKey() const;
RSAPrivateKey toRSAPrivateKey() const;
DSAPublicKey toDSAPublicKey() const;
DSAPrivateKey toDSAPrivateKey() const;
DHPublicKey toDHPublicKey() const;
DHPrivateKey toDHPrivateKey() const;
private:
class Private;
Private *d;
};
class QCA_EXPORT PublicKey : public PKey
{
public:
PublicKey();
PublicKey(const PrivateKey &k);
RSAPublicKey toRSA() const;
DSAPublicKey toDSA() const;
DHPublicKey toDH() const;
bool canEncrypt() const;
bool canVerify() const;
// encrypt / verify
int maximumEncryptSize(EncAlgo alg) const;
QSecureArray encrypt(EncAlgo alg, const QSecureArray &a);
void startVerify(SignAlgo alg);
void update(const QSecureArray &a);
bool validSignature(const QSecureArray &sig);
bool verifyMessage(SignAlgo alg, const QSecureArray &a, const QSecureArray &sig);
// import / export
QSecureArray toDER() const;
QString toPEM() const;
static PublicKey fromDER(const QSecureArray &a, const QString &provider = QString() );
static PublicKey fromPEM(const QString &s, const QString &provider = QString() );
protected:
PublicKey(const QString &type, const QString &provider);
private:
friend class PrivateKey;
friend class Certificate;
};
class QCA_EXPORT PrivateKey : public PKey
{
public:
PrivateKey();
RSAPrivateKey toRSA() const;
DSAPrivateKey toDSA() const;
DHPrivateKey toDH() const;
bool canDecrypt() const;
bool canSign() const;
// decrypt / sign / key agreement
bool decrypt(EncAlgo alg, const QSecureArray &in, QSecureArray *out);
void startSign(SignAlgo alg);
void update(const QSecureArray &);
QSecureArray signature();
QSecureArray signMessage(SignAlgo alg, const QSecureArray &a);
SymmetricKey deriveKey(const PublicKey &theirs);
// import / export
QSecureArray toDER(const QString &passphrase = QString() ) const;
QString toPEM(const QString &passphrase = QString() ) const;
static PrivateKey fromDER(const QSecureArray &a, const QString &passphrase = QString(), const QString &provider = QString() );
static PrivateKey fromPEM(const QString &s, const QString &passphrase = QString(), const QString &provider = QString() );
protected:
PrivateKey(const QString &type, const QString &provider);
private:
friend class TLS;
};
class QCA_EXPORT KeyGenerator : public QObject
{
Q_OBJECT
public:
KeyGenerator(QObject *parent = 0, const char *name = 0);
~KeyGenerator();
bool blocking() const;
void setBlocking(bool b);
bool isBusy() const;
void generateRSA(int bits, int exp = 65537, const QString &provider = QString() );
void generateDSA(DL_Group group, const QString &provider = QString() );
void generateDH(DL_Group group, const QString &provider = QString() );
PrivateKey result() const;
signals:
void finished();
private:
void done();
class Private;
Private *d;
};
class QCA_EXPORT RSAPublicKey : public PublicKey
{
public:
RSAPublicKey();
RSAPublicKey(const QBigInteger &n, const QBigInteger &e, const QString &provider = QString() );
RSAPublicKey(const RSAPrivateKey &k);
QBigInteger n() const;
QBigInteger e() const;
};
class QCA_EXPORT RSAPrivateKey : public PrivateKey
{
public:
RSAPrivateKey();
RSAPrivateKey(const QBigInteger &p, const QBigInteger &q, const QBigInteger &d, const QBigInteger &n, const QBigInteger &e, const QString &provider = QString() );
QBigInteger p() const;
QBigInteger q() const;
QBigInteger d() const;
QBigInteger n() const;
QBigInteger e() const;
};
class QCA_EXPORT DSAPublicKey : public PublicKey
{
public:
DSAPublicKey();
DSAPublicKey(DL_Group group, const QBigInteger &y, const QString &provider = QString() );
DSAPublicKey(const DSAPrivateKey &k);
DL_Group domain() const;
QBigInteger y() const;
};
class QCA_EXPORT DSAPrivateKey : public PrivateKey
{
public:
DSAPrivateKey();
DSAPrivateKey(DL_Group group, const QBigInteger &x, const QBigInteger &y, const QString &provider = QString() );
DL_Group domain() const;
QBigInteger x() const;
QBigInteger y() const;
};
class QCA_EXPORT DHPublicKey : public PublicKey
{
public:
DHPublicKey();
DHPublicKey(DL_Group group, const QBigInteger &y, const QString &provider = QString() );
DHPublicKey(const DHPrivateKey &k);
DL_Group domain() const;
QBigInteger y() const;
};
class QCA_EXPORT DHPrivateKey : public PrivateKey
{
public:
DHPrivateKey();
DHPrivateKey(DL_Group group, const QBigInteger &x, const QBigInteger &y, const QString &provider = QString() );
DL_Group domain() const;
QBigInteger x() const;
QBigInteger y() const;
};
}
#endif

View File

@ -0,0 +1,246 @@
/*
* qca_securelayer.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_SECURELAYER_H
#define QCA_SECURELAYER_H
#include <qobject.h>
#include "qca_core.h"
class QHostAddress;
namespace QCA
{
class PrivateKey;
class Certificate;
class Store;
// securefilter basic rule: after calling a function that might
// affect something, call others to get the results.
//
// write: call readOutgoing
// writeIncoming: call haveClosed/haveError, read, and readOutgoing
// close: call haveClosed/haveError and readOutgoing
// haveClosed: if Closed, call readUnprocessed
class QCA_EXPORT SecureFilter
{
public:
virtual ~SecureFilter();
virtual bool isClosable() const;
virtual bool haveClosed() const;
virtual bool haveError() const = 0;
virtual int bytesAvailable() const = 0;
virtual int bytesOutgoingAvailable() const = 0;
virtual void close();
// plain (application side)
virtual void write(const QSecureArray &a) = 0;
virtual QSecureArray read() = 0;
// encoded (network side)
virtual void writeIncoming(const QByteArray &a) = 0;
virtual QByteArray readOutgoing(int *plainBytes = 0) = 0;
virtual QSecureArray readUnprocessed();
};
// securelayer - "nicer" interface, using signals. subclass
// should call layerUpdateBegin/End before and after write,
// writeIncoming, or close.
class QCA_EXPORT SecureLayer : public QObject, public SecureFilter
{
Q_OBJECT
public:
SecureLayer(QObject *parent = 0, const char *name = 0);
void setStatefulOnly(bool b);
protected:
void layerUpdateBegin();
void layerUpdateEnd();
signals:
void readyRead();
void readyReadOutgoing();
void closed();
void error();
private:
bool _signals;
int _read, _readout;
bool _closed, _error;
};
class QCA_EXPORT TLS : public SecureLayer, public Algorithm
{
Q_OBJECT
public:
enum Error
{
ErrHandshake, ///< problem during the negotiation
ErrCrypt ///< problem at anytime after
};
enum IdentityResult
{
Valid, ///< identity is verified
HostMismatch, ///< valid cert provided, but wrong owner
BadCert, ///< invalid cert
NoCert ///< identity unknown
};
TLS(QObject *parent = 0, const char *name = 0, const QString &provider = QString() );
~TLS();
void reset();
void setCertificate(const Certificate &cert, const PrivateKey &key);
void setStore(const Store &store);
void setConstraints(SecurityLevel s);
void setConstraints(int minSSF, int maxSSF);
bool canCompress() const;
void setCompressionEnabled(bool b);
bool startClient(const QString &host = QString() );
bool startServer();
bool isHandshaken() const;
QString cipherName() const;
int cipherBits() const;
Error errorCode() const;
IdentityResult peerIdentityResult() const;
CertValidity peerCertificateValidity() const;
Certificate localCertificate() const;
Certificate peerCertificate() const;
// reimplemented
virtual bool isClosable() const;
virtual bool haveClosed() const;
virtual bool haveError() const;
virtual int bytesAvailable() const;
virtual int bytesOutgoingAvailable() const;
virtual void close();
virtual void write(const QSecureArray &a);
virtual QSecureArray read();
virtual void writeIncoming(const QByteArray &a);
virtual QByteArray readOutgoing(int *plainBytes = 0);
virtual QSecureArray readUnprocessed();
signals:
void handshaken();
public:
class Private;
private:
friend class Private;
Private *d;
};
class QCA_EXPORT SASL : public SecureLayer, public Algorithm
{
Q_OBJECT
public:
enum Error
{
ErrAuth, ///< problem during the authentication process
ErrCrypt ///< problem at anytime after
};
enum AuthCondition
{
NoMech,
BadProto,
BadServ,
BadAuth,
NoAuthzid,
TooWeak,
NeedEncrypt,
Expired,
Disabled,
NoUser,
RemoteUnavail
};
enum AuthFlags
{
AllowPlain = 0x01,
AllowAnonymous = 0x02,
RequireForwardSecrecy = 0x04,
RequirePassCredentials = 0x08,
RequireMutualAuth = 0x10,
RequireAuthzidSupport = 0x20 // server-only
};
SASL(QObject *parent = 0, const char *name = 0, const QString &provider = QString() );
~SASL();
void reset();
// configuration
void setConstraints(AuthFlags f, SecurityLevel s = SL_None);
void setConstraints(AuthFlags f, int minSSF, int maxSSF);
void setLocalAddr(const QHostAddress &addr, Q_UINT16 port);
void setRemoteAddr(const QHostAddress &addr, Q_UINT16 port);
void setExternalAuthId(const QString &authid);
void setExternalSSF(int);
// main
bool startClient(const QString &service, const QString &host, const QStringList &mechlist, bool allowClientSendFirst = true);
bool startServer(const QString &service, const QString &host, const QString &realm, QStringList *mechlist, bool allowServerSendLast = false);
void putStep(const QByteArray &stepData);
void putServerFirstStep(const QString &mech);
void putServerFirstStep(const QString &mech, const QByteArray &clientInit);
int ssf() const;
Error errorCode() const;
AuthCondition authCondition() const;
// authentication
void setUsername(const QString &user);
void setAuthzid(const QString &auth);
void setPassword(const QSecureArray &pass);
void setRealm(const QString &realm);
void continueAfterParams();
void continueAfterAuthCheck();
// reimplemented
virtual bool haveError() const;
virtual int bytesAvailable() const;
virtual int bytesOutgoingAvailable() const;
virtual void close();
virtual void write(const QSecureArray &a);
virtual QSecureArray read();
virtual void writeIncoming(const QByteArray &a);
virtual QByteArray readOutgoing(int *plainBytes = 0);
signals:
void clientFirstStep(const QString &mech, const QByteArray *clientInit);
void nextStep(const QByteArray &stepData);
void needParams(bool user, bool authzid, bool pass, bool realm);
void authCheck(const QString &user, const QString &authzid);
void authenticated();
public:
class Private;
private:
friend class Private;
Private *d;
};
}
#endif

View File

@ -0,0 +1,78 @@
/*
* qca_textfilter.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_TEXTFILTER_H
#define QCA_TEXTFILTER_H
#include "qca_core.h"
namespace QCA
{
class QCA_EXPORT TextFilter : public Filter
{
public:
TextFilter(Direction dir);
void setup(Direction dir);
QSecureArray encode(const QSecureArray &a);
QSecureArray decode(const QSecureArray &a);
QString arrayToString(const QSecureArray &a);
QSecureArray stringToArray(const QString &s);
QString encodeString(const QString &s);
QString decodeString(const QString &s);
protected:
Direction _dir;
};
class QCA_EXPORT Hex : public TextFilter
{
public:
Hex(Direction dir = Encode);
virtual void clear();
virtual QSecureArray update(const QSecureArray &a);
virtual QSecureArray final();
virtual bool ok() const;
private:
uchar val;
bool partial;
bool _ok;
};
class QCA_EXPORT Base64 : public TextFilter
{
public:
Base64(Direction dir = Encode);
virtual void clear();
virtual QSecureArray update(const QSecureArray &a);
virtual QSecureArray final();
virtual bool ok() const;
private:
QSecureArray partial;
bool _ok;
};
}
#endif

View File

@ -0,0 +1,526 @@
/*
* qca_tools.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef QCA_TOOLS_H
#define QCA_TOOLS_H
#include "qca_export.h"
#include <qcstring.h>
#include <qstring.h>
/**
* Secure array of bytes
*
* The %QSecureArray provides an array of memory from a pool that is,
* at least partly, secure. In this sense, secure means that the contents
* of the memory should not be made available to other applications. By
* comparison, a QMemArray (or subclass such as QCString or QByteArray) may
* be held in pages that might be swapped to disk or free'd without being
* cleared first.
*
* Note that this class is implicitly shared (that is, copy on write).
**/
class QCA_EXPORT QSecureArray
{
public:
/**
* Construct a secure byte array, zero length
*/
QSecureArray();
/**
* Construct a secure byte array of the specified length
*
* \param size the number of bytes in the array
*/
QSecureArray(int size);
/**
* Construct a secure byte array from a QByteArray
*
* Note that this copies, rather than references the source array
*
* \sa operator=()
*/
QSecureArray(const QByteArray &a);
/**
* Construct a secure byte array from a string
*
* Note that this copies, rather than references the source array
*
* \sa operator=()
*/
QSecureArray(const QCString &cs);
/**
* Construct a (shallow) copy of another secure byte array
*
* \param from the source of the data and length.
*/
QSecureArray(const QSecureArray &from);
~QSecureArray();
/**
* Creates a reference, rather than a deep copy.
* if you want a deep copy then you should use copy()
* instead, or use operator=(), then call detach() when required.
*/
QSecureArray & operator=(const QSecureArray &from);
/**
* Creates a copy, rather than references
*
* \param a the array to copy from
*/
QSecureArray & operator=(const QByteArray &a);
/**
* Creates a copy, rather than references
*
* \param cs the string to copy from
*/
QSecureArray & operator=(const QCString &cs);
/**
* Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain
*/
char & operator[](int index);
/**
* Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain
*/
const char & operator[](int index) const;
/**
* Pointer to the data in the secure array
*
* You can use this for memcpy and similar functions. If you are trying
* to obtain data at a particular offset, you might be better off using
* at() or operator[]
*
*/
const char *data() const;
/**
* Pointer to the data in the secure array
*
* You can use this for memcpy and similar functions. If you are trying
* to obtain data at a particular offset, you might be better off using
* at() or operator[]
*
*/
char *data();
/**
* Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain
*/
const char & at(uint index) const;
/**
* Returns a reference to the byte at the index position
*
* \param index the zero-based offset to obtain
*/
char & at(uint index);
/**
* Returns the number of bytes in the array
*/
uint size() const;
/**
* Test if the array contains any bytes.
*
* This is equivalent to testing (size() != 0). Note that if
* the array is allocated, isEmpty() is false (even if no data
* has been added)
*
* \return true if the array has zero length, otherwise false
*/
bool isEmpty() const;
/**
* Change the length of this array
* If the new length is less than the old length, the extra information
* is (safely) discarded. If the new length is equal to or greater than
* the old length, the existing data is copied into the array.
*
* \param size the new length
*/
bool resize(uint size);
/**
* Fill the data array with a specified character
*
* \param fillChar the character to use as the fill
* \param fillToPosition the number of characters to fill
* to. If not specified (or -1), fills array to
* current length.
*
* \note This function does not extend the array - if
* you ask for fill beyond the current length, only
* the current length will be used.
* \note The number of characters is 1 based, so if
* you ask for fill('x', 10), it will fill from
*
*/
void fill(char fillChar, int fillToPosition = -1);
/**
* creates a deep copy, rather than a reference
* if you want a reference then you should use operator=()
*/
QSecureArray copy() const;
/**
* If the current array is shared, this conducts a deep copy,
* otherwise it has no effect.
*
* \code
* QSecureArray myArray = anotherArray; // currently the same
* myArray.detach(); // no longer the same data, but a copy
* // anything here that affects anotherArray does not affect
* // myArray; and vice versa.
* \endcode
*/
void detach();
/**
* Copy the contents of the secure array out to a
* standard QByteArray. Note that this performs a deep copy
* of the data.
*/
QByteArray toByteArray() const;
/**
* Append a secure byte array to the end of this array
*/
QSecureArray & append(const QSecureArray &a);
protected:
/**
* Assign the contents of a provided byte array to this
* object.
*
* \param from the byte array to copy
*/
void set(const QSecureArray &from);
/**
* Assign the contents of a provided string to this
* object.
*
* \param cs the QCString to copy
*/
void set(const QCString &cs);
private:
class Private;
Private *d;
void reset();
};
/**
* Equality operator. Returns true if the two QSecureArray
* arguments have the same data (and the same length, of course).
*
* \relates QSecureArray
**/
QCA_EXPORT bool operator==(const QSecureArray &a, const QSecureArray &b);
/**
* Inequality operator. Returns true if the two QSecureArray
* arguments have different length, or the same length but
* different data
*
* \relates QSecureArray
**/
QCA_EXPORT bool operator!=(const QSecureArray &a, const QSecureArray &b);
/**
* Arbitrary precision integer
*
* %QBigInteger provides arbitrary precision integers.
* \code
* if ( QBigInteger("3499543804349") ==
* QBigInteger("38493290803248") + QBigInteger( 343 ) )
* {
* // do something
* }
* \endcode
*
**/
class QCA_EXPORT QBigInteger
{
public:
/**
* Constructor. Creates a new QBigInteger, initialised to zero.
*/
QBigInteger();
/**
* \overload
*
* \param n an alternative integer initialisation value.
*/
QBigInteger(int n);
/**
* \overload
*
* \param s an alternative initialisation value, encoded as a string
*
* \code
* QBigInteger b ( "9890343" );
* \endcode
*/
QBigInteger(const QString &s);
/**
* \overload
*
* \param a an alternative initialisation value, encoded as QSecureArray
*/
QBigInteger(const QSecureArray &a);
/**
* \overload
*
* \param from an alternative initialisation value, encoded as a %QBigInteger
*/
QBigInteger(const QBigInteger &from);
~QBigInteger();
/**
* Assignment operator
*
* \param from the QBigInteger to copy from
*
* \code
* QBigInteger a; // a is zero
* QBigInteger b( 500 );
* a = b; // a is now 500
* \endcode
*/
QBigInteger & operator=(const QBigInteger &from);
/**
* \overload
*
* \param s the QString containing an integer representation
*
* \sa bool fromString(const QString &s)
*
* \note it is the application's responsibility to make sure
* that the QString represents a valid integer (ie it only
* contains numbers and an optional minus sign at the start)
*
**/
QBigInteger & operator=(const QString &s);
/**
* Increment in place operator
*
* \param b the amount to increment by
*
* \code
* QBigInteger a; // a is zero
* QBigInteger b( 500 );
* a += b; // a is now 500
* a += b; // a is now 1000
* \endcode
**/
QBigInteger & operator+=(const QBigInteger &b);
/**
* Decrement in place operator
*
* \param b the amount to decrement by
*
* \code
* QBigInteger a; // a is zero
* QBigInteger b( 500 );
* a -= b; // a is now -500
* a -= b; // a is now -1000
* \endcode
**/
QBigInteger & operator-=(const QBigInteger &b);
/**
* Output %QBigInteger as a byte array, useful for storage or
* transmission. The format is a binary integer in sign-extended
* network-byte-order.
*
* \sa void fromArray(const QSecureArray &a);
*/
QSecureArray toArray() const;
/**
* Assign from an array. The input is expected to be a binary integer
* in sign-extended network-byte-order.
*
* \param a a QSecureArray that represents an integer
*
* \sa QBigInteger(const QSecureArray &a);
* \sa QSecureArray toArray() const;
*/
void fromArray(const QSecureArray &a);
/**
* Convert %QBigInteger to a QString
*
* \code
* QString aString;
* QBigInteger aBiggishInteger( 5878990 );
* aString = aBiggishInteger.toString(); // aString is now "5878990"
* \endcode
*/
QString toString() const;
/**
* Assign from a QString
*
* \param s a QString that represents an integer
*
* \note it is the application's responsibility to make sure
* that the QString represents a valid integer (ie it only
* contains numbers and an optional minus sign at the start)
*
* \sa QBigInteger(const QString &s)
* \sa QBigInteger & operator=(const QString &s)
*/
bool fromString(const QString &s);
/**
* Compare this value with another %QBigInteger
*
* Normally it is more readable to use one of the operator overloads,
* so you don't need to use this method directly.
*
* \param n the QBigInteger to compare with
*
* \return zero if the values are the same, negative if the argument
* is less than the value of this QBigInteger, and positive if the argument
* value is greater than this QBigInteger
*
* \code
* QBigInteger a( "400" );
* QBigInteger b( "-400" );
* QBigInteger c( " 200 " );
* int result;
* result = a.compare( b ); // return positive 400 > -400
* result = a.compare( c ); // return positive, 400 > 200
* result = b.compare( c ); // return negative, -400 < 200
* \endcode
**/
int compare(const QBigInteger &n) const;
private:
class Private;
Private *d;
};
/**
* Equality operator. Returns true if the two QBigInteger values
* are the same, including having the same sign.
*
* \relates QBigInteger
**/
inline bool operator==(const QBigInteger &a, const QBigInteger &b)
{
return (0 == a.compare( b ) );
}
/**
* Inequality operator. Returns true if the two QBigInteger values
* are different in magnitude, sign or both
*
* \relates QBigInteger
**/
inline bool operator!=(const QBigInteger &a, const QBigInteger &b)
{
return (0 != a.compare( b ) );
}
/**
* Less than or equal operator. Returns true if the QBigInteger value
* on the left hand side is equal to or less than the QBigInteger value
* on the right hand side.
*
* \relates QBigInteger
**/
inline bool operator<=(const QBigInteger &a, const QBigInteger &b)
{
return (a.compare( b ) <= 0 );
}
/**
* Greater than or equal operator. Returns true if the QBigInteger value
* on the left hand side is equal to or greater than the QBigInteger value
* on the right hand side.
*
* \relates QBigInteger
**/
inline bool operator>=(const QBigInteger &a, const QBigInteger &b)
{
return (a.compare( b ) >= 0 );
}
/**
* Less than operator. Returns true if the QBigInteger value
* on the left hand side is less than the QBigInteger value
* on the right hand side.
*
* \relates QBigInteger
**/
inline bool operator<(const QBigInteger &a, const QBigInteger &b)
{
return (a.compare( b ) < 0 );
}
/**
* Greater than operator. Returns true if the QBigInteger value
* on the left hand side is greater than the QBigInteger value
* on the right hand side.
*
* \relates QBigInteger
**/
inline bool operator>(const QBigInteger &a, const QBigInteger &b)
{
return (a.compare( b ) > 0 );
}
/**
* Stream operator.
*
* \relates QBigInteger
**/
QCA_EXPORT QTextStream &operator<<(QTextStream &stream, const QBigInteger &b);
#endif

View File

@ -1,6 +1,7 @@
/*
* qcaprovider.h - QCA Plugin API
* Copyright (C) 2003,2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -25,7 +26,8 @@
#include <qdatetime.h>
#include <qobject.h>
#include <qhostaddress.h>
#include "qca.h"
#include "qca_core.h"
#include "qca_basic.h"
#include <limits>

37
qca.pro
View File

@ -17,34 +17,51 @@ win32:{
DEFINES += QCA_MAKEDLL
}
QCA_INC = include/QtCrypto
QCA_CPP = src
INCLUDEPATH += $$QCA_CPP
INCLUDEPATH += $$QCA_INC $$QCA_CPP
# botantools
include(src/botantools/botantools.pri)
HEADERS += \
$$QCA_CPP/qca.h \
$$QCA_CPP/qcaprovider.h \
$$QCA_INC/qca_export.h \
$$QCA_INC/qca_tools.h \
$$QCA_INC/qca_core.h \
$$QCA_INC/qca_textfilter.h \
$$QCA_CPP/qca_plugin.h \
$$QCA_INC/qca_basic.h \
$$QCA_INC/qca_publickey.h \
$$QCA_INC/qca_cert.h \
$$QCA_INC/qca_securelayer.h \
$$QCA_INC/qcaprovider.h \
$$QCA_CPP/qca_systemstore.h
SOURCES += \
$$QCA_CPP/qca.cpp \
$$QCA_CPP/qca_plugin.cpp \
$$QCA_CPP/qca_tools.cpp \
$$QCA_CPP/qca_basic.cpp \
$$QCA_CPP/qca_core.cpp \
$$QCA_CPP/qca_textfilter.cpp \
$$QCA_CPP/qca_plugin.cpp \
$$QCA_CPP/qca_basic.cpp \
$$QCA_CPP/qca_publickey.cpp \
$$QCA_CPP/qca_cert.cpp \
$$QCA_CPP/qca_securelayer.cpp \
$$QCA_CPP/qca_default.cpp
#DEFINES += QCA_NO_SYSTEMSTORE
DEFINES += QCA_NO_SYSTEMSTORE
# debian cert store
DEFINES += QCA_SYSTEMSTORE_PATH='"/etc/ssl/certs/ca-certificates.crt"'
SOURCES += $$QCA_CPP/qca_systemstore_flatfile.cpp
unix:!mac: {
# debian cert store
DEFINES += QCA_SYSTEMSTORE_PATH='"/etc/ssl/certs/ca-certificates.crt"'
SOURCES += $$QCA_CPP/qca_systemstore_flatfile.cpp
}
win: {
SOURCES += $$QCA_CPP/qca_systemstore_win.cpp
}
mac: {
SOURCES += $$QCA_CPP/qca_systemstore_mac.cpp
QMAKE_LFLAGS += -framework Carbon
}
include(conf.pri)
include(extra.pri)

3191
src/qca.h

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
/*
* qca_basic.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,7 +19,7 @@
*
*/
#include "qca.h"
#include "qca_basic.h"
#include "qcaprovider.h"

View File

@ -1,6 +1,7 @@
/*
* qca_cert.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,10 +19,11 @@
*
*/
#include "qca.h"
#include "qca_cert.h"
#include <qdatetime.h>
#include <qregexp.h>
#include "qca_publickey.h"
#include "qcaprovider.h"
namespace QCA {

View File

@ -1,6 +1,7 @@
/*
* qca.cpp - Qt Cryptographic Architecture
* Copyright (C) 2003,2004 Justin Karneges
* qca_core.cpp - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,18 +19,18 @@
*
*/
#include"qca.h"
#include "qca_core.h"
#include <qptrlist.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <qhostaddress.h>
#include <qguardedptr.h>
#include <qptrdict.h>
#include <stdlib.h>
#include "qcaprovider.h"
#include "qca_tools.h"
#include "qca_plugin.h"
#include "qca_systemstore.h"
#include "qca_textfilter.h"
#include "qca_cert.h"
#include "qcaprovider.h"
#ifndef QCA_NO_SYSTEMSTORE
# include "qca_systemstore.h"
#endif
namespace QCA {
@ -585,87 +586,87 @@ SymmetricKey::SymmetricKey(const QCString &cs)
}
/* from libgcrypt-1.2.0 */
static unsigned char desWeakKeyTable[64][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /*w*/
{ 0x00, 0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e },
{ 0x00, 0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0 },
{ 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe },
{ 0x00, 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e }, /*sw*/
{ 0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e, 0x00 },
{ 0x00, 0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0, 0xfe },
{ 0x00, 0x1e, 0xfe, 0xe0, 0x00, 0x0e, 0xfe, 0xf0 },
{ 0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0 }, /*sw*/
{ 0x00, 0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e, 0xfe },
{ 0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0, 0x00 },
{ 0x00, 0xe0, 0xfe, 0x1e, 0x00, 0xf0, 0xfe, 0x0e },
{ 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe }, /*sw*/
{ 0x00, 0xfe, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0 },
{ 0x00, 0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e },
{ 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00 },
{ 0x1e, 0x00, 0x00, 0x1e, 0x0e, 0x00, 0x00, 0x0e },
{ 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e, 0x00 }, /*sw*/
{ 0x1e, 0x00, 0xe0, 0xfe, 0x0e, 0x00, 0x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e, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0, 0x00 },
{ 0xfe, 0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e }, /*sw*/
{ 0xfe, 0xe0, 0x00, 0x1e, 0xfe, 0xf0, 0x00, 0x0e },
{ 0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e, 0x00 },
{ 0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0, 0xfe },
{ 0xfe, 0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0 }, /*sw*/
{ 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00 },
{ 0xfe, 0xfe, 0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e },
{ 0xfe, 0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0 },
{ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe } /*w*/
};
bool SymmetricKey::isWeakDESKey()
{
if ( 8 != size() )
if(size() != 8)
return false; // dubious
QSecureArray workingCopy(8);
// clear parity bits
for (unsigned int i = 0; i < 8; i++) {
for(uint i = 0; i < 8; i++)
workingCopy[i] = (data()[i]) & 0xfe;
}
for (int n = 0; n < 64; n++) {
if ( 0 == memcmp( workingCopy.data(), desWeakKeyTable[n], 8) ) {
for(int n = 0; n < 64; n++)
{
if(memcmp(workingCopy.data(), desWeakKeyTable[n], 8) == 0)
return true;
}
}
return false;
}

View File

@ -1,6 +1,7 @@
/*
* qca_default.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,9 +19,8 @@
*
*/
#include "qca.h"
#include "qca_core.h"
#include <qconfig.h>
#include <qdatetime.h>
#include <qstringlist.h>
#include <stdlib.h>

View File

@ -1,6 +1,7 @@
/*
* qca_plugin.h - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -25,7 +26,9 @@
#include <qptrlist.h>
#include <qstringlist.h>
#include "qca.h"
#include "qca_core.h"
class QCAProvider;
namespace QCA
{

View File

@ -1,6 +1,7 @@
/*
* qca_publickey.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,7 +19,7 @@
*
*/
#include "qca.h"
#include "qca_publickey.h"
#include <qptrdict.h>
#include "qcaprovider.h"

View File

@ -1,6 +1,7 @@
/*
* qca_securelayer.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,11 +19,13 @@
*
*/
#include "qca.h"
#include "qca_securelayer.h"
#include <qtimer.h>
#include <qhostaddress.h>
#include <qguardedptr.h>
#include "qca_publickey.h"
#include "qca_cert.h"
#include "qcaprovider.h"
namespace QCA {

View File

@ -23,7 +23,7 @@
// NOTE: this API is private to QCA
#include "qca.h"
#include "qca_cert.h"
namespace QCA
{

View File

@ -1,6 +1,7 @@
/*
* qca_textfilter.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,7 +19,7 @@
*
*/
#include "qca.h"
#include "qca_textfilter.h"
namespace QCA {

View File

@ -1,6 +1,7 @@
/*
* qca_tools.cpp - Qt Cryptographic Architecture
* Copyright (C) 2004 Justin Karneges
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,7 +19,7 @@
*
*/
#include "qca.h"
#include "qca_tools.h"
#ifdef Q_OS_UNIX
# include <stdlib.h>