OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / ssh / sshcapabilities.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "sshcapabilities_p.h"
34
35 #include "sshexception_p.h"
36
37 #include <QtCore/QCoreApplication>
38 #include <QtCore/QString>
39
40 namespace Utils {
41 namespace Internal {
42
43 namespace {
44     QByteArray listAsByteArray(const QList<QByteArray> &list)
45     {
46         QByteArray array;
47         foreach(const QByteArray &elem, list)
48             array += elem + ',';
49         if (!array.isEmpty())
50             array.remove(array.count() - 1, 1);
51         return array;
52     }
53 } // anonymous namspace
54
55 const QByteArray SshCapabilities::DiffieHellmanGroup1Sha1("diffie-hellman-group1-sha1");
56 const QByteArray SshCapabilities::DiffieHellmanGroup14Sha1("diffie-hellman-group14-sha1");
57 const QList<QByteArray> SshCapabilities::KeyExchangeMethods
58     = QList<QByteArray>() << SshCapabilities::DiffieHellmanGroup1Sha1
59           << SshCapabilities::DiffieHellmanGroup14Sha1;
60
61 const QByteArray SshCapabilities::PubKeyDss("ssh-dss");
62 const QByteArray SshCapabilities::PubKeyRsa("ssh-rsa");
63 const QList<QByteArray> SshCapabilities::PublicKeyAlgorithms
64     = QList<QByteArray>() << SshCapabilities::PubKeyRsa
65           << SshCapabilities::PubKeyDss;
66
67 const QByteArray SshCapabilities::CryptAlgo3Des("3des-cbc");
68 const QByteArray SshCapabilities::CryptAlgoAes128("aes128-cbc");
69 const QList<QByteArray> SshCapabilities::EncryptionAlgorithms
70     = QList<QByteArray>() << SshCapabilities::CryptAlgoAes128
71           << SshCapabilities::CryptAlgo3Des;
72
73 const QByteArray SshCapabilities::HMacSha1("hmac-sha1");
74 const QByteArray SshCapabilities::HMacSha196("hmac-sha1-96");
75 const QList<QByteArray> SshCapabilities::MacAlgorithms
76     = QList<QByteArray>() /* << SshCapabilities::HMacSha196 */
77         << SshCapabilities::HMacSha1;
78
79 const QList<QByteArray> SshCapabilities::CompressionAlgorithms
80     = QList<QByteArray>() << "none";
81
82 const QByteArray SshCapabilities::SshConnectionService("ssh-connection");
83
84 const QByteArray SshCapabilities::PublicKeyAuthMethod("publickey");
85 const QByteArray SshCapabilities::PasswordAuthMethod("password");
86
87
88 QByteArray SshCapabilities::findBestMatch(const QList<QByteArray> &myCapabilities,
89     const QList<QByteArray> &serverCapabilities)
90 {
91     foreach (const QByteArray &myCapability, myCapabilities) {
92         if (serverCapabilities.contains(myCapability))
93             return myCapability;
94     }
95
96     throw SshServerException(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
97         "Server and client capabilities do not match.",
98         QCoreApplication::translate("SshConnection",
99             "Server and client capabilities don't match. "
100             "Client list was: %1.\nServer list was %2.")
101             .arg(listAsByteArray(myCapabilities).data())
102             .arg(listAsByteArray(serverCapabilities).data()));
103 }
104
105 } // namespace Internal
106 } // namespace Utils