1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef SSHABSTRACTCRYPTOFACILITY_P_H
35 #define SSHABSTRACTCRYPTOFACILITY_P_H
37 #include <botan/auto_rng.h>
38 #include <botan/symkey.h>
40 #include <QtCore/QByteArray>
41 #include <QtCore/QScopedPointer>
46 class BlockCipherMode;
47 class BlockCipherModePaddingMethod;
59 class SshAbstractCryptoFacility
62 virtual ~SshAbstractCryptoFacility();
65 void recreateKeys(const SshKeyExchange &kex);
66 QByteArray generateMac(const QByteArray &data, quint32 dataSize) const;
67 quint32 cipherBlockSize() const { return m_cipherBlockSize; }
68 quint32 macLength() const { return m_macLength; }
71 SshAbstractCryptoFacility();
72 void convert(QByteArray &data, quint32 offset, quint32 dataSize) const;
73 QByteArray sessionId() const { return m_sessionId; }
76 SshAbstractCryptoFacility(const SshAbstractCryptoFacility &);
77 SshAbstractCryptoFacility &operator=(const SshAbstractCryptoFacility &);
79 virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const=0;
80 virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const=0;
81 virtual Botan::BlockCipherMode *makeCipherMode(Botan::BlockCipher *cipher,
82 Botan::BlockCipherModePaddingMethod *paddingMethod,
83 const Botan::InitializationVector &iv,
84 const Botan::SymmetricKey &key)=0;
85 virtual char ivChar() const=0;
86 virtual char keyChar() const=0;
87 virtual char macChar() const=0;
89 QByteArray generateHash(const SshKeyExchange &kex, char c, quint32 length);
90 void checkInvariant() const;
92 QByteArray m_sessionId;
93 QScopedPointer<Botan::Pipe> m_pipe;
94 QScopedPointer<Botan::HMAC> m_hMac;
95 quint32 m_cipherBlockSize;
99 class SshEncryptionFacility : public SshAbstractCryptoFacility
102 void encrypt(QByteArray &data) const;
104 void createAuthenticationKey(const QByteArray &privKeyFileContents);
105 QByteArray authenticationAlgorithmName() const;
106 QByteArray authenticationPublicKey() const { return m_authPubKeyBlob; }
107 QByteArray authenticationKeySignature(const QByteArray &data) const;
108 QByteArray getRandomNumbers(int count) const;
110 ~SshEncryptionFacility();
113 virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const;
114 virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const;
115 virtual Botan::BlockCipherMode *makeCipherMode(Botan::BlockCipher *cipher,
116 Botan::BlockCipherModePaddingMethod *paddingMethod,
117 const Botan::InitializationVector &iv, const Botan::SymmetricKey &key);
118 virtual char ivChar() const { return 'A'; }
119 virtual char keyChar() const { return 'C'; }
120 virtual char macChar() const { return 'E'; }
122 void createAuthenticationKeyFromPKCS8(const QByteArray &privKeyFileContents,
123 QList<Botan::BigInt> &pubKeyParams, QList<Botan::BigInt> &allKeyParams);
124 void createAuthenticationKeyFromOpenSSL(const QByteArray &privKeyFileContents,
125 QList<Botan::BigInt> &pubKeyParams, QList<Botan::BigInt> &allKeyParams);
127 static const QByteArray PrivKeyFileStartLineRsa;
128 static const QByteArray PrivKeyFileStartLineDsa;
129 static const QByteArray PrivKeyFileEndLineRsa;
130 static const QByteArray PrivKeyFileEndLineDsa;
132 QByteArray m_authKeyAlgoName;
133 QByteArray m_authPubKeyBlob;
134 QByteArray m_cachedPrivKeyContents;
135 QScopedPointer<Botan::PK_Signing_Key> m_authKey;
136 mutable Botan::AutoSeeded_RNG m_rng;
139 class SshDecryptionFacility : public SshAbstractCryptoFacility
142 void decrypt(QByteArray &data, quint32 offset, quint32 dataSize) const;
145 virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const;
146 virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const;
147 virtual Botan::BlockCipherMode *makeCipherMode(Botan::BlockCipher *cipher,
148 Botan::BlockCipherModePaddingMethod *paddingMethod,
149 const Botan::InitializationVector &iv, const Botan::SymmetricKey &key);
150 virtual char ivChar() const { return 'B'; }
151 virtual char keyChar() const { return 'D'; }
152 virtual char macChar() const { return 'F'; }
155 } // namespace Internal
158 #endif // SSHABSTRACTCRYPTOFACILITY_P_H