├── .gitignore ├── LGPL_EXCEPTION.TXT ├── LICENSE.LGPL ├── README.md ├── examples ├── examples.pro └── ssh │ ├── errorhandling │ ├── errorhandling.pro │ └── main.cpp │ ├── remoteprocess │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── remoteprocess.pro │ ├── remoteprocesstest.cpp │ └── remoteprocesstest.h │ ├── sftp │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── parameters.h │ ├── sftp.pro │ ├── sftptest.cpp │ └── sftptest.h │ ├── sftpfsmodel │ ├── main.cpp │ ├── sftpfsmodel.pro │ ├── window.cpp │ ├── window.h │ └── window.ui │ ├── shell │ ├── main.cpp │ ├── shell.cpp │ ├── shell.h │ └── shell.pro │ ├── ssh.pri │ ├── ssh.pro │ └── tunnel │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── tunnel.cpp │ ├── tunnel.h │ └── tunnel.pro ├── examples_bin ├── SecureUploader ├── errorhandling ├── qtsshshell ├── remoteprocess ├── sftp ├── shell └── tunnel ├── include ├── QSsh └── ssh │ ├── .directory │ ├── sftpchannel.h │ ├── sftpdefs.h │ ├── sftpfilesystemmodel.h │ ├── ssh_global.h │ ├── sshconnection.h │ ├── sshconnectionmanager.h │ ├── sshdirecttcpiptunnel.h │ ├── ssherrors.h │ ├── sshhostkeydatabase.h │ ├── sshkeycreationdialog.h │ ├── sshkeygenerator.h │ ├── sshpseudoterminal.h │ ├── sshremoteprocess.h │ └── sshremoteprocessrunner.h ├── qssh.pro └── src ├── .directory ├── 3rdparty └── botan │ ├── botan.cpp │ ├── botan.h │ ├── botan.pri │ ├── configure.py │ ├── doc │ └── license.txt │ └── readme.txt ├── sftpchannel.cpp ├── sftpchannel.h ├── sftpchannel_p.h ├── sftpdefs.cpp ├── sftpdefs.h ├── sftpfilesystemmodel.cpp ├── sftpfilesystemmodel.h ├── sftpincomingpacket.cpp ├── sftpincomingpacket_p.h ├── sftpoperation.cpp ├── sftpoperation_p.h ├── sftpoutgoingpacket.cpp ├── sftpoutgoingpacket_p.h ├── sftppacket.cpp ├── sftppacket_p.h ├── src.pro ├── ssh.pri ├── ssh_global.h ├── sshbotanconversions_p.h ├── sshcapabilities.cpp ├── sshcapabilities_p.h ├── sshchannel.cpp ├── sshchannel_p.h ├── sshchannelmanager.cpp ├── sshchannelmanager_p.h ├── sshconnection.cpp ├── sshconnection.h ├── sshconnection_p.h ├── sshconnectionmanager.cpp ├── sshconnectionmanager.h ├── sshcryptofacility.cpp ├── sshcryptofacility_p.h ├── sshdirecttcpiptunnel.cpp ├── sshdirecttcpiptunnel.h ├── sshdirecttcpiptunnel_p.h ├── ssherrors.h ├── sshexception_p.h ├── sshhostkeydatabase.cpp ├── sshhostkeydatabase.h ├── sshincomingpacket.cpp ├── sshincomingpacket_p.h ├── sshinit.cpp ├── sshinit_p.h ├── sshkeycreationdialog.cpp ├── sshkeycreationdialog.h ├── sshkeycreationdialog.ui ├── sshkeyexchange.cpp ├── sshkeyexchange_p.h ├── sshkeygenerator.cpp ├── sshkeygenerator.h ├── sshkeypasswordretriever.cpp ├── sshkeypasswordretriever_p.h ├── sshlogging.cpp ├── sshlogging_p.h ├── sshoutgoingpacket.cpp ├── sshoutgoingpacket_p.h ├── sshpacket.cpp ├── sshpacket_p.h ├── sshpacketparser.cpp ├── sshpacketparser_p.h ├── sshpseudoterminal.h ├── sshremoteprocess.cpp ├── sshremoteprocess.h ├── sshremoteprocess_p.h ├── sshremoteprocessrunner.cpp ├── sshremoteprocessrunner.h ├── sshsendfacility.cpp └── sshsendfacility_p.h /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *_pch.h.cpp 15 | *_resource.rc 16 | *.qm 17 | .#* 18 | *.*# 19 | core 20 | !core/ 21 | tags 22 | .DS_Store 23 | *.debug 24 | Makefile* 25 | *.prl 26 | *.app 27 | moc_*.cpp 28 | ui_*.h 29 | qrc_*.cpp 30 | Thumbs.db 31 | 32 | # qtcreator generated files 33 | *.pro.user* 34 | *.qmlproject.user* 35 | *.pluginspec 36 | src/app/Info.plist 37 | app_version.h 38 | src/plugins/coreplugin/ide_version.h 39 | share/qtcreator/externaltools 40 | phony.c 41 | 42 | # xemacs temporary files 43 | *.flc 44 | 45 | # Vim temporary files 46 | .*.swp 47 | 48 | # Visual Studio generated files 49 | *.ib_pdb_index 50 | *.idb 51 | *.ilk 52 | *.pdb 53 | *.sln 54 | *.suo 55 | *.vcproj 56 | *vcproj.*.*.user 57 | *.ncb 58 | *.sdf 59 | *.opensdf 60 | *.vcxproj 61 | *vcxproj.* 62 | 63 | # MinGW generated files 64 | *.Debug 65 | *.Release 66 | 67 | # translation related: 68 | share/qtcreator/translations/*_tr.h 69 | share/qtcreator/translations/qtcreator_untranslated.ts 70 | 71 | # Directories to ignore 72 | # --------------------- 73 | 74 | build 75 | debug 76 | lib/* 77 | lib64/* 78 | release 79 | doc/html/* 80 | doc/html-dev/* 81 | doc/api/html/* 82 | doc/pluginhowto/html/* 83 | dist/gdb/python 84 | .rcc 85 | .pch 86 | dist/gdb/qtcreator-* 87 | dist/gdb/source 88 | dist/gdb/staging 89 | ipch 90 | tmp 91 | # ignore both a directory as well as a symlink 92 | share/qtcreator/Nokia/ 93 | share/qtcreator/Nokia 94 | 95 | # Binaries 96 | # -------- 97 | bin/*.dll 98 | bin/qtcreator 99 | bin/qtcreator_process_stub* 100 | bin/qtcreator_ctrlc_stub* 101 | bin/qtcreator.exe 102 | bin/qmlpuppet 103 | bin/qmlpuppet.exe 104 | bin/qml2puppet 105 | bin/qml2puppet.exe 106 | bin/qtpromaker 107 | bin/qtpromaker.exe 108 | share/doc/qtcreator/*.qch 109 | src/tools/gen-cpp-ast/generate-ast 110 | src/tools/mkvisitor/cplusplus0 111 | src/tools/qml/qmldump/qmldump 112 | src/tools/examplesscanner/examplesscanner 113 | src/tools/valgrindfake/valgrind-fake 114 | bin/*.exe 115 | 116 | # Tests 117 | #------ 118 | tests/manual/cplusplus-frontend/cplusplus0 119 | tests/manual/cplusplus-dump/cplusplus0 120 | tests/manual/qml-ast2dot/qml-ast2dot 121 | tests/manual/debugger/simple/libsimple_test_plugin.*dylib 122 | tests/manual/debugger/simple/simple_test_app 123 | tests/manual/plain-cplusplus/plain-c++ 124 | tests/manual/preprocessor/pp 125 | tests/auto/cplusplus/codegen/tst_codegen 126 | tests/auto/cplusplus/ast/tst_ast 127 | tests/auto/cplusplus/codeformatter/tst_codeformatter 128 | tests/auto/cplusplus/findusages/tst_findusages 129 | tests/auto/cplusplus/lookup/tst_lookup 130 | tests/auto/cplusplus/preprocessor/tst_preprocessor 131 | tests/auto/cplusplus/semantic/tst_semantic 132 | tests/auto/cplusplus/typeprettyprinter/tst_typeprettyprinter 133 | tests/auto/qml/qmldesigner/bauhaustests/tst_bauhaus 134 | tests/auto/qml/qmldesigner/coretests/tst_qmldesigner_core 135 | tests/auto/qml/qmldesigner/propertyeditortests/tst_propertyeditor 136 | tests/auto/profilewriter/tst_profilewriter 137 | tests/auto/externaltool/tst_externaltool 138 | tests/valgrind/memcheck/modeldemo 139 | tests/valgrind/memcheck/parsertests 140 | tests/valgrind/memcheck/testapps/free1/free1 141 | tests/valgrind/memcheck/testapps/free2/free2 142 | tests/valgrind/memcheck/testapps/invalidjump/invalidjump 143 | tests/valgrind/memcheck/testapps/leak1/leak1 144 | tests/valgrind/memcheck/testapps/leak2/leak2 145 | tests/valgrind/memcheck/testapps/leak3/leak3 146 | tests/valgrind/memcheck/testapps/leak4/leak4 147 | tests/valgrind/memcheck/testapps/overlap/overlap 148 | tests/valgrind/memcheck/testapps/syscall/syscall 149 | tests/valgrind/memcheck/testapps/uninit1/uninit1 150 | tests/valgrind/memcheck/testapps/uninit2/uninit2 151 | tests/valgrind/memcheck/testapps/uninit3/uninit3 152 | tests/valgrind/memcheck/testrunner 153 | tests/valgrind/callgrind/callgrindparsertests 154 | tests/valgrind/callgrind/modeltest 155 | -------------------------------------------------------------------------------- /LGPL_EXCEPTION.TXT: -------------------------------------------------------------------------------- 1 | Digia Qt LGPL Exception version 1.1 2 | 3 | As an additional permission to the GNU Lesser General Public License version 4 | 2.1, the object code form of a "work that uses the Library" may incorporate 5 | material from a header file that is part of the Library. You may distribute 6 | such object code under terms of your choice, provided that: 7 | (i) the header files of the Library have not been modified; and 8 | (ii) the incorporated material is limited to numerical parameters, data 9 | structure layouts, accessors, macros, inline functions and 10 | templates; and 11 | (iii) you comply with the terms of Section 6 of the GNU Lesser General 12 | Public License version 2.1. 13 | 14 | Moreover, you may apply this exception to a modified version of the Library, 15 | provided that such modification does not involve copying material from the 16 | Library into the modified Library's header files unless such material is 17 | limited to (i) numerical parameters; (ii) data structure layouts; 18 | (iii) accessors; and (iv) small macros, templates and inline functions of 19 | five lines or less in length. 20 | 21 | Furthermore, you are not required to apply this additional permission to a 22 | modified version of the Library. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | About QSsh(关于 QSsh) 3 | ========== 4 | 5 | QSsh provides SSH and SFTP support for Qt applications. The aim of this project 6 | is to provide a easy way to use these protocols in any Qt application. 7 | This project is based on Qt Creator's libQtcSsh.so. All the credits to 8 | Qt Creator's team! 9 | 10 | QSsh为qt提供SSH和SFTP支持,使你能方便快捷的使用SSH和SFTP。 11 | 这个项目是基于Qt Creator中的LibQtcSsh.so。十分感谢Qt Creator团队。 12 | 基于GPL和LGPL授权。 13 | ========== 14 | 15 | Prerequisites:(编译环境) 16 | ------------- 17 | Qt 5.x 18 | 19 | On Windows: MinGW 4.7 or later, Visual Studio 2010 or later 20 | 21 | On Mac: XCode 2.5 or later, compiling on 10.4 requires setting the environment variable QTC_TIGER_COMPAT before running qmake 22 | 23 | ========== 24 | 25 | Compiling QSsh(编译QSsh) 26 | ---------------------- 27 | mkdir $BUILD_DIRECTORY 28 | 29 | cd $BUILD_DIRECTORY 30 | 31 | qmake $SOURCE_DIRECTORY/qssh.pro 32 | 33 | make (or mingw32-make or nmake depending on your platform) 34 | 35 | 36 | ###Or 37 | 38 | You can open "qssh.pro" used "Qt Creator". 39 | 40 | 你也可以直接用Qt Creator打开qssh.pro。 41 | 42 | Examples 43 | =========== 44 | - Directory examples/ssh/ Qt-Creator下自带的例子。 45 | 46 | > 注:生成的库在 lib文件夹下就可以直接用的。 47 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | 4 | SUBDIRS = \ 5 | ssh 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/ssh/errorhandling/errorhandling.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | 3 | TARGET=errorhandling 4 | SOURCES=main.cpp 5 | -------------------------------------------------------------------------------- /examples/ssh/remoteprocess/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef ARGUMENTSCOLLECTOR_H 27 | #define ARGUMENTSCOLLECTOR_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | class ArgumentsCollector 34 | { 35 | public: 36 | ArgumentsCollector(const QStringList &args); 37 | QSsh::SshConnectionParameters collect(bool &success) const; 38 | private: 39 | struct ArgumentErrorException 40 | { 41 | ArgumentErrorException(const QString &error) : error(error) {} 42 | const QString error; 43 | }; 44 | 45 | void printUsage() const; 46 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 47 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 48 | const char *opt) const; 49 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; 50 | 51 | const QStringList m_arguments; 52 | }; 53 | 54 | #endif // ARGUMENTSCOLLECTOR_H 55 | -------------------------------------------------------------------------------- /examples/ssh/remoteprocess/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "argumentscollector.h" 27 | #include "remoteprocesstest.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | QCoreApplication app(argc, argv); 41 | bool parseSuccess; 42 | const QSsh::SshConnectionParameters ¶meters 43 | = ArgumentsCollector(app.arguments()).collect(parseSuccess); 44 | if (!parseSuccess) 45 | return EXIT_FAILURE; 46 | RemoteProcessTest remoteProcessTest(parameters); 47 | remoteProcessTest.run(); 48 | return app.exec(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/ssh/remoteprocess/remoteprocess.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | 3 | TARGET=remoteprocess 4 | SOURCES=main.cpp remoteprocesstest.cpp argumentscollector.cpp 5 | HEADERS=remoteprocesstest.h argumentscollector.h 6 | -------------------------------------------------------------------------------- /examples/ssh/remoteprocess/remoteprocesstest.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef REMOTEPROCESSTEST_H 27 | #define REMOTEPROCESSTEST_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | QT_FORWARD_DECLARE_CLASS(QTextStream) 34 | QT_FORWARD_DECLARE_CLASS(QTimer) 35 | 36 | class RemoteProcessTest : public QObject 37 | { 38 | Q_OBJECT 39 | public: 40 | RemoteProcessTest(const QSsh::SshConnectionParameters ¶ms); 41 | ~RemoteProcessTest(); 42 | void run(); 43 | 44 | private slots: 45 | void handleConnectionError(); 46 | void handleProcessStarted(); 47 | void handleProcessStdout(); 48 | void handleProcessStderr(); 49 | void handleProcessClosed(int exitStatus); 50 | void handleTimeout(); 51 | void handleReadyRead(); 52 | void handleReadyReadStdout(); 53 | void handleReadyReadStderr(); 54 | void handleConnected(); 55 | 56 | private: 57 | enum State { 58 | Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice, 59 | TestingProcessChannels 60 | }; 61 | 62 | QString testString() const; 63 | void handleSuccessfulCrashTest(); 64 | void handleSuccessfulIoTest(); 65 | 66 | const QSsh::SshConnectionParameters m_sshParams; 67 | QTimer * const m_timeoutTimer; 68 | QTextStream *m_textStream; 69 | QSsh::SshRemoteProcess::Ptr m_catProcess; 70 | QSsh::SshRemoteProcess::Ptr m_echoProcess; 71 | QSsh::SshConnection *m_sshConnection; 72 | QSsh::SshRemoteProcessRunner * const m_remoteRunner; 73 | QByteArray m_remoteStdout; 74 | QByteArray m_remoteStderr; 75 | QByteArray m_remoteData; 76 | State m_state; 77 | bool m_started; 78 | }; 79 | 80 | 81 | #endif // REMOTEPROCESSTEST_H 82 | -------------------------------------------------------------------------------- /examples/ssh/sftp/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef ARGUMENTSCOLLECTOR_H 27 | #define ARGUMENTSCOLLECTOR_H 28 | 29 | #include "parameters.h" 30 | 31 | #include 32 | 33 | class ArgumentsCollector 34 | { 35 | public: 36 | ArgumentsCollector(const QStringList &args); 37 | Parameters collect(bool &success) const; 38 | private: 39 | struct ArgumentErrorException 40 | { 41 | ArgumentErrorException(const QString &error) : error(error) {} 42 | const QString error; 43 | }; 44 | 45 | void printUsage() const; 46 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 47 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 48 | const char *opt) const; 49 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, 50 | bool &alreadyGiven) const; 51 | 52 | const QStringList m_arguments; 53 | }; 54 | 55 | #endif // ARGUMENTSCOLLECTOR_H 56 | -------------------------------------------------------------------------------- /examples/ssh/sftp/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "argumentscollector.h" 27 | #include "sftptest.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | QCoreApplication app(argc, argv); 42 | bool parseSuccess; 43 | const Parameters parameters = ArgumentsCollector(app.arguments()).collect(parseSuccess); 44 | if (!parseSuccess) 45 | return EXIT_FAILURE; 46 | SftpTest sftpTest(parameters); 47 | sftpTest.run(); 48 | return app.exec(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/ssh/sftp/parameters.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef PARAMETERS_H 27 | #define PARAMETERS_H 28 | 29 | #include 30 | 31 | struct Parameters { 32 | QSsh::SshConnectionParameters sshParams; 33 | int smallFileCount; 34 | int bigFileSize; 35 | }; 36 | 37 | #endif // PARAMETERS_H 38 | -------------------------------------------------------------------------------- /examples/ssh/sftp/sftp.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | 3 | TARGET = sftp 4 | SOURCES = main.cpp sftptest.cpp argumentscollector.cpp 5 | HEADERS = sftptest.h argumentscollector.h parameters.h 6 | 7 | -------------------------------------------------------------------------------- /examples/ssh/sftp/sftptest.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPTEST_H 27 | #define SFTPTEST_H 28 | 29 | #include "parameters.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | QT_FORWARD_DECLARE_CLASS(QFile); 41 | 42 | class SftpTest : public QObject 43 | { 44 | Q_OBJECT 45 | public: 46 | SftpTest(const Parameters ¶ms); 47 | ~SftpTest(); 48 | void run(); 49 | 50 | private slots: 51 | void handleConnected(); 52 | void handleError(); 53 | void handleDisconnected(); 54 | void handleChannelInitialized(); 55 | void handleChannelInitializationFailure(const QString &reason); 56 | void handleJobFinished(QSsh::SftpJobId job, const QString &error); 57 | void handleFileInfo(QSsh::SftpJobId job, const QList &fileInfoList); 58 | void handleChannelClosed(); 59 | 60 | private: 61 | typedef QHash JobMap; 62 | typedef QSharedPointer FilePtr; 63 | enum State { 64 | Inactive, Connecting, InitializingChannel, UploadingSmall, DownloadingSmall, 65 | RemovingSmall, UploadingBig, DownloadingBig, RemovingBig, CreatingDir, 66 | CheckingDirAttributes, CheckingDirContents, RemovingDir, ChannelClosing, Disconnecting 67 | }; 68 | 69 | void removeFile(const FilePtr &filePtr, bool remoteToo); 70 | void removeFiles(bool remoteToo); 71 | QString cmpFileName(const QString &localFileName) const; 72 | QString remoteFilePath(const QString &localFileName) const; 73 | void earlyDisconnectFromHost(); 74 | bool checkJobId(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, const char *activity); 75 | bool handleJobFinished(QSsh::SftpJobId job, JobMap &jobMap, 76 | const QString &error, const char *activity); 77 | bool handleJobFinished(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, const QString &error, 78 | const char *activity); 79 | bool handleBigJobFinished(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, 80 | const QString &error, const char *activity); 81 | bool compareFiles(QFile *orig, QFile *copy); 82 | 83 | const Parameters m_parameters; 84 | State m_state; 85 | bool m_error; 86 | QSsh::SshConnection *m_connection; 87 | QSsh::SftpChannel::Ptr m_channel; 88 | QList m_localSmallFiles; 89 | JobMap m_smallFilesUploadJobs; 90 | JobMap m_smallFilesDownloadJobs; 91 | JobMap m_smallFilesRemovalJobs; 92 | FilePtr m_localBigFile; 93 | QSsh::SftpJobId m_bigFileUploadJob; 94 | QSsh::SftpJobId m_bigFileDownloadJob; 95 | QSsh::SftpJobId m_bigFileRemovalJob; 96 | QSsh::SftpJobId m_mkdirJob; 97 | QSsh::SftpJobId m_statDirJob; 98 | QSsh::SftpJobId m_lsDirJob; 99 | QSsh::SftpJobId m_rmDirJob; 100 | QElapsedTimer m_bigJobTimer; 101 | QString m_remoteDirPath; 102 | QSsh::SftpFileInfo m_dirInfo; 103 | QList m_dirContents; 104 | }; 105 | 106 | 107 | #endif // SFTPTEST_H 108 | -------------------------------------------------------------------------------- /examples/ssh/sftpfsmodel/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "window.h" 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | QApplication app(argc, argv); 37 | SftpFsWindow w; 38 | w.show(); 39 | return app.exec(); 40 | } 41 | -------------------------------------------------------------------------------- /examples/ssh/sftpfsmodel/sftpfsmodel.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | include(../../../../src/shared/modeltest/modeltest.pri) 3 | 4 | QT += widgets 5 | 6 | TARGET=sftpfsmodel 7 | SOURCES+=main.cpp window.cpp 8 | HEADERS+=window.h 9 | FORMS=window.ui 10 | -------------------------------------------------------------------------------- /examples/ssh/sftpfsmodel/window.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "window.h" 27 | #include "ui_window.h" 28 | 29 | #include "modeltest.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using namespace QSsh; 43 | 44 | SftpFsWindow::SftpFsWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::Window) 45 | { 46 | m_ui->setupUi(this); 47 | connect(m_ui->connectButton, SIGNAL(clicked()), SLOT(connectToHost())); 48 | connect(m_ui->downloadButton, SIGNAL(clicked()), SLOT(downloadFile())); 49 | } 50 | 51 | SftpFsWindow::~SftpFsWindow() 52 | { 53 | delete m_ui; 54 | } 55 | 56 | void SftpFsWindow::connectToHost() 57 | { 58 | m_ui->connectButton->setEnabled(false); 59 | SshConnectionParameters sshParams; 60 | sshParams.host = m_ui->hostLineEdit->text(); 61 | sshParams.userName = m_ui->userLineEdit->text(); 62 | sshParams.authenticationType 63 | = SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods; 64 | sshParams.password = m_ui->passwordLineEdit->text(); 65 | sshParams.port = m_ui->portSpinBox->value(); 66 | sshParams.timeout = 10; 67 | m_fsModel = new SftpFileSystemModel(this); 68 | if (m_ui->useModelTesterCheckBox->isChecked()) 69 | new ModelTest(m_fsModel, this); 70 | connect(m_fsModel, SIGNAL(sftpOperationFailed(QString)), 71 | SLOT(handleSftpOperationFailed(QString))); 72 | connect(m_fsModel, SIGNAL(connectionError(QString)), SLOT(handleConnectionError(QString))); 73 | connect(m_fsModel, SIGNAL(sftpOperationFinished(QSsh::SftpJobId,QString)), 74 | SLOT(handleSftpOperationFinished(QSsh::SftpJobId,QString))); 75 | m_fsModel->setSshConnection(sshParams); 76 | m_ui->fsView->setModel(m_fsModel); 77 | } 78 | 79 | void SftpFsWindow::downloadFile() 80 | { 81 | const QModelIndexList selectedIndexes = m_ui->fsView->selectionModel()->selectedIndexes(); 82 | if (selectedIndexes.count() != 2) 83 | return; 84 | const QString targetFilePath = QFileDialog::getSaveFileName(this, tr("Choose target file"), 85 | QDir::tempPath()); 86 | if (targetFilePath.isEmpty()) 87 | return; 88 | const SftpJobId jobId = m_fsModel->downloadFile(selectedIndexes.at(1), targetFilePath); 89 | QString message; 90 | if (jobId == SftpInvalidJob) 91 | message = tr("Download failed."); 92 | else 93 | message = tr("Queuing download operation %1.").arg(jobId); 94 | m_ui->outputTextEdit->appendPlainText(message); 95 | } 96 | 97 | void SftpFsWindow::handleSftpOperationFailed(const QString &errorMessage) 98 | { 99 | m_ui->outputTextEdit->appendPlainText(errorMessage); 100 | } 101 | 102 | void SftpFsWindow::handleSftpOperationFinished(SftpJobId jobId, const QString &error) 103 | { 104 | QString message; 105 | if (error.isEmpty()) 106 | message = tr("Operation %1 finished successfully.").arg(jobId); 107 | else 108 | message = tr("Operation %1 failed: %2.").arg(jobId).arg(error); 109 | m_ui->outputTextEdit->appendPlainText(message); 110 | } 111 | 112 | void SftpFsWindow::handleConnectionError(const QString &errorMessage) 113 | { 114 | QMessageBox::warning(this, tr("Connection Error"), 115 | tr("Fatal SSH error: %1").arg(errorMessage)); 116 | qApp->quit(); 117 | } 118 | -------------------------------------------------------------------------------- /examples/ssh/sftpfsmodel/window.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include 27 | 28 | #include 29 | 30 | QT_BEGIN_NAMESPACE 31 | namespace Ui { class Window; } 32 | QT_END_NAMESPACE 33 | 34 | namespace QSsh { class SftpFileSystemModel; } 35 | 36 | class SftpFsWindow : public QDialog 37 | { 38 | Q_OBJECT 39 | public: 40 | SftpFsWindow(QWidget *parent = 0); 41 | ~SftpFsWindow(); 42 | 43 | private slots: 44 | void connectToHost(); 45 | void downloadFile(); 46 | void handleConnectionError(const QString &errorMessage); 47 | void handleSftpOperationFailed(const QString &errorMessage); 48 | void handleSftpOperationFinished(QSsh::SftpJobId jobId, const QString &error); 49 | 50 | private: 51 | QSsh::SftpFileSystemModel *m_fsModel; 52 | Ui::Window *m_ui; 53 | }; 54 | -------------------------------------------------------------------------------- /examples/ssh/shell/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "../remoteprocess/argumentscollector.h" 27 | #include "shell.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | QCoreApplication app(argc, argv); 41 | bool parseSuccess; 42 | const QSsh::SshConnectionParameters ¶meters 43 | = ArgumentsCollector(app.arguments()).collect(parseSuccess); 44 | if (!parseSuccess) 45 | return EXIT_FAILURE; 46 | Shell shell(parameters); 47 | shell.run(); 48 | return app.exec(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/ssh/shell/shell.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "shell.h" 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | using namespace QSsh; 39 | 40 | Shell::Shell(const SshConnectionParameters ¶meters, QObject *parent) 41 | : QObject(parent), 42 | m_connection(new SshConnection(parameters)), 43 | m_stdin(new QFile(this)) 44 | { 45 | connect(m_connection, SIGNAL(connected()), SLOT(handleConnected())); 46 | connect(m_connection, SIGNAL(dataAvailable(QString)), SLOT(handleShellMessage(QString))); 47 | connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError())); 48 | } 49 | 50 | Shell::~Shell() 51 | { 52 | delete m_connection; 53 | } 54 | 55 | void Shell::run() 56 | { 57 | if (!m_stdin->open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered)) { 58 | std::cerr << "Error: Cannot read from standard input." << std::endl; 59 | qApp->exit(EXIT_FAILURE); 60 | return; 61 | } 62 | 63 | m_connection->connectToHost(); 64 | } 65 | 66 | void Shell::handleConnectionError() 67 | { 68 | std::cerr << "SSH connection error: " << qPrintable(m_connection->errorString()) << std::endl; 69 | qApp->exit(EXIT_FAILURE); 70 | } 71 | 72 | void Shell::handleShellMessage(const QString &message) 73 | { 74 | std::cout << qPrintable(message); 75 | } 76 | 77 | void Shell::handleConnected() 78 | { 79 | m_shell = m_connection->createRemoteShell(); 80 | connect(m_shell.data(), SIGNAL(started()), SLOT(handleShellStarted())); 81 | connect(m_shell.data(), SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout())); 82 | connect(m_shell.data(), SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr())); 83 | connect(m_shell.data(), SIGNAL(closed(int)), SLOT(handleChannelClosed(int))); 84 | m_shell->start(); 85 | } 86 | 87 | void Shell::handleShellStarted() 88 | { 89 | QSocketNotifier * const notifier = new QSocketNotifier(0, QSocketNotifier::Read, this); 90 | connect(notifier, SIGNAL(activated(int)), SLOT(handleStdin())); 91 | } 92 | 93 | void Shell::handleRemoteStdout() 94 | { 95 | std::cout << m_shell->readAllStandardOutput().data() << std::flush; 96 | } 97 | 98 | void Shell::handleRemoteStderr() 99 | { 100 | std::cerr << m_shell->readAllStandardError().data() << std::flush; 101 | } 102 | 103 | void Shell::handleChannelClosed(int exitStatus) 104 | { 105 | std::cerr << "Shell closed. Exit status was " << exitStatus << ", exit code was " 106 | << m_shell->exitCode() << "." << std::endl; 107 | qApp->exit(exitStatus == SshRemoteProcess::NormalExit && m_shell->exitCode() == 0 108 | ? EXIT_SUCCESS : EXIT_FAILURE); 109 | } 110 | 111 | void Shell::handleStdin() 112 | { 113 | m_shell->write(m_stdin->readLine()); 114 | } 115 | -------------------------------------------------------------------------------- /examples/ssh/shell/shell.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SHELL_H 27 | #define SHELL_H 28 | 29 | #include 30 | #include 31 | 32 | namespace QSsh { 33 | class SshConnection; 34 | class SshConnectionParameters; 35 | class SshRemoteProcess; 36 | } 37 | 38 | QT_BEGIN_NAMESPACE 39 | class QByteArray; 40 | class QFile; 41 | class QString; 42 | QT_END_NAMESPACE 43 | 44 | class Shell : public QObject 45 | { 46 | Q_OBJECT 47 | public: 48 | Shell(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0); 49 | ~Shell(); 50 | 51 | void run(); 52 | 53 | private slots: 54 | void handleConnected(); 55 | void handleConnectionError(); 56 | void handleRemoteStdout(); 57 | void handleRemoteStderr(); 58 | void handleShellMessage(const QString &message); 59 | void handleChannelClosed(int exitStatus); 60 | void handleShellStarted(); 61 | void handleStdin(); 62 | 63 | private: 64 | QSsh::SshConnection *m_connection; 65 | QSharedPointer m_shell; 66 | QFile * const m_stdin; 67 | }; 68 | 69 | #endif // SHELL_H 70 | -------------------------------------------------------------------------------- /examples/ssh/shell/shell.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | QT += network 3 | 4 | TARGET=shell 5 | SOURCES=main.cpp shell.cpp ../remoteprocess/argumentscollector.cpp 6 | HEADERS=shell.h ../remoteprocess/argumentscollector.h 7 | -------------------------------------------------------------------------------- /examples/ssh/ssh.pri: -------------------------------------------------------------------------------- 1 | QT += core gui network 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | QSSH_ROOT = $${PWD}/../.. 6 | DESTDIR = $${QSSH_ROOT}/examples_bin 7 | 8 | INCLUDEPATH += $$PWD/../../include 9 | CONFIG += console 10 | CONFIG -= app_bundle 11 | TEMPLATE = app 12 | 13 | CONFIG += c++11 14 | 15 | unix:LIBS += -L$${QSSH_ROOT}/lib -lQSsh 16 | 17 | win32:CONFIG(release, debug|release): LIBS += -L$${QSSH_ROOT}/lib -lQSsh 18 | else:win32:CONFIG(debug, debug|release): LIBS += -L$${QSSH_ROOT}/lib -lQSshd 19 | -------------------------------------------------------------------------------- /examples/ssh/ssh.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2010-07-01T09:44:44 4 | # 5 | #------------------------------------------------- 6 | 7 | TEMPLATE = subdirs 8 | SUBDIRS = errorhandling sftp remoteprocess shell tunnel 9 | -------------------------------------------------------------------------------- /examples/ssh/tunnel/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef ARGUMENTSCOLLECTOR_H 27 | #define ARGUMENTSCOLLECTOR_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | class ArgumentsCollector 34 | { 35 | public: 36 | ArgumentsCollector(const QStringList &args); 37 | QSsh::SshConnectionParameters collect(bool &success) const; 38 | private: 39 | struct ArgumentErrorException 40 | { 41 | ArgumentErrorException(const QString &error) : error(error) {} 42 | const QString error; 43 | }; 44 | 45 | void printUsage() const; 46 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 47 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 48 | const char *opt) const; 49 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; 50 | 51 | const QStringList m_arguments; 52 | }; 53 | 54 | #endif // ARGUMENTSCOLLECTOR_H 55 | -------------------------------------------------------------------------------- /examples/ssh/tunnel/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "../remoteprocess/argumentscollector.h" 27 | #include "tunnel.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | QCoreApplication app(argc, argv); 41 | bool parseSuccess; 42 | QSsh::SshConnectionParameters parameters 43 | = ArgumentsCollector(app.arguments()).collect(parseSuccess); 44 | parameters.host = QLatin1String("127.0.0.1"); 45 | if (!parseSuccess) 46 | return EXIT_FAILURE; 47 | Tunnel tunnel(parameters); 48 | tunnel.run(); 49 | return app.exec(); 50 | } 51 | -------------------------------------------------------------------------------- /examples/ssh/tunnel/tunnel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef TUNNEL_H 27 | #define TUNNEL_H 28 | 29 | #include 30 | #include 31 | 32 | QT_BEGIN_NAMESPACE 33 | class QTcpServer; 34 | class QTcpSocket; 35 | QT_END_NAMESPACE 36 | 37 | namespace QSsh { 38 | class SshConnection; 39 | class SshConnectionParameters; 40 | class SshDirectTcpIpTunnel; 41 | } 42 | 43 | class Tunnel : public QObject 44 | { 45 | Q_OBJECT 46 | public: 47 | Tunnel(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0); 48 | ~Tunnel(); 49 | 50 | void run(); 51 | 52 | private slots: 53 | void handleConnected(); 54 | void handleConnectionError(); 55 | void handleServerData(); 56 | void handleInitialized(); 57 | void handleTunnelError(const QString &reason); 58 | void handleTunnelClosed(); 59 | void handleNewConnection(); 60 | void handleSocketError(); 61 | void handleClientData(); 62 | void handleTimeout(); 63 | 64 | private: 65 | QSsh::SshConnection * const m_connection; 66 | QSharedPointer m_tunnel; 67 | QTcpServer * const m_targetServer; 68 | QTcpSocket *m_targetSocket; 69 | quint16 m_targetPort; 70 | QByteArray m_dataReceivedFromServer; 71 | QByteArray m_dataReceivedFromClient; 72 | bool m_expectingChannelClose; 73 | }; 74 | 75 | #endif // TUNNEL_H 76 | -------------------------------------------------------------------------------- /examples/ssh/tunnel/tunnel.pro: -------------------------------------------------------------------------------- 1 | include(../ssh.pri) 2 | 3 | TARGET=tunnel 4 | SOURCES=main.cpp tunnel.cpp argumentscollector.cpp 5 | HEADERS=tunnel.h argumentscollector.h 6 | -------------------------------------------------------------------------------- /examples_bin/SecureUploader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/SecureUploader -------------------------------------------------------------------------------- /examples_bin/errorhandling: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/errorhandling -------------------------------------------------------------------------------- /examples_bin/qtsshshell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/qtsshshell -------------------------------------------------------------------------------- /examples_bin/remoteprocess: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/remoteprocess -------------------------------------------------------------------------------- /examples_bin/sftp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/sftp -------------------------------------------------------------------------------- /examples_bin/shell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/shell -------------------------------------------------------------------------------- /examples_bin/tunnel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dushibaiyu/QSsh/f2be2d9cb4298ea2bae3d131c2aee22b55285154/examples_bin/tunnel -------------------------------------------------------------------------------- /include/QSsh: -------------------------------------------------------------------------------- 1 | #include "ssh/ssh_global.h" 2 | #include "ssh/sftpchannel.h" 3 | #include "ssh/sftpdefs.h" 4 | #include "ssh/sftpfilesystemmodel.h" 5 | #include "ssh/sshconnection.h" 6 | #include "ssh/sshconnectionmanager.h" 7 | #include "ssh/ssherrors.h" 8 | #include "ssh/sshkeygenerator.h" 9 | #include "ssh/sshpseudoterminal.h" 10 | #include "ssh/sshremoteprocess.h" 11 | #include "ssh/sshremoteprocessrunner.h" 12 | #include "ssh/sshdirecttcpiptunnel.h" 13 | #include "ssh/sshkeycreationdialog.h" 14 | #include "ssh/sshhostkeydatabase.h" 15 | -------------------------------------------------------------------------------- /include/ssh/.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | Timestamp=2016,7,3,18,14,35 3 | Version=3 4 | ViewMode=1 5 | -------------------------------------------------------------------------------- /include/ssh/sftpchannel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPCHANNEL_H 27 | #define SFTPCHANNEL_H 28 | 29 | #include "sftpdefs.h" 30 | //#include "sftpincomingpacket_p.h" 31 | 32 | #include "ssh_global.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace QSsh { 40 | 41 | namespace Internal { 42 | class SftpChannelPrivate; 43 | class SshChannelManager; 44 | class SshSendFacility; 45 | } // namespace Internal 46 | 47 | class QSSH_EXPORT SftpChannel : public QObject 48 | { 49 | Q_OBJECT 50 | 51 | friend class Internal::SftpChannelPrivate; 52 | friend class Internal::SshChannelManager; 53 | public: 54 | typedef QSharedPointer Ptr; 55 | 56 | enum State { Uninitialized, Initializing, Initialized, Closing, Closed }; 57 | State state() const; 58 | 59 | void initialize(); 60 | void closeChannel(); 61 | 62 | SftpJobId statFile(const QString &path); 63 | SftpJobId listDirectory(const QString &dirPath); 64 | SftpJobId createDirectory(const QString &dirPath); 65 | SftpJobId removeDirectory(const QString &dirPath); 66 | SftpJobId removeFile(const QString &filePath); 67 | SftpJobId renameFileOrDirectory(const QString &oldPath, 68 | const QString &newPath); 69 | SftpJobId createFile(const QString &filePath, SftpOverwriteMode mode); 70 | SftpJobId createLink(const QString &filePath, const QString &target); 71 | SftpJobId uploadFile(const QString &localFilePath, 72 | const QString &remoteFilePath, SftpOverwriteMode mode); 73 | SftpJobId downloadFile(const QString &remoteFilePath, 74 | const QString &localFilePath, SftpOverwriteMode mode); 75 | SftpJobId uploadDir(const QString &localDirPath, 76 | const QString &remoteParentDirPath); 77 | 78 | ~SftpChannel(); 79 | 80 | signals: 81 | void initialized(); 82 | void channelError(const QString &reason); 83 | void closed(); 84 | 85 | // error.isEmpty <=> finished successfully 86 | void finished(QSsh::SftpJobId job, const QString &error = QString()); 87 | 88 | // TODO: Also emit for each file copied by uploadDir(). 89 | void dataAvailable(QSsh::SftpJobId job, const QString &data); 90 | 91 | /* 92 | * This signal is emitted as a result of: 93 | * - statFile() (with the list having exactly one element) 94 | * - listDirectory() (potentially more than once) 95 | */ 96 | void fileInfoAvailable(QSsh::SftpJobId job, const QList &fileInfoList); 97 | 98 | private: 99 | SftpChannel(quint32 channelId, Internal::SshSendFacility &sendFacility); 100 | 101 | Internal::SftpChannelPrivate *d; 102 | }; 103 | 104 | } // namespace QSsh 105 | 106 | #endif // SFTPCHANNEL_H 107 | -------------------------------------------------------------------------------- /include/ssh/sftpdefs.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPDEFS_H 27 | #define SFTPDEFS_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace QSsh { 35 | 36 | typedef quint32 SftpJobId; 37 | QSSH_EXPORT extern const SftpJobId SftpInvalidJob; 38 | 39 | enum SftpOverwriteMode { 40 | SftpOverwriteExisting, SftpAppendToExisting, SftpSkipExisting 41 | }; 42 | 43 | enum SftpFileType { FileTypeRegular, FileTypeDirectory, FileTypeOther, FileTypeUnknown }; 44 | 45 | class QSSH_EXPORT SftpFileInfo 46 | { 47 | public: 48 | SftpFileInfo() : type(FileTypeUnknown), sizeValid(false), permissionsValid(false) { } 49 | 50 | QString name; 51 | SftpFileType type; 52 | quint64 size; 53 | QFile::Permissions permissions; 54 | 55 | // The RFC allows an SFTP server not to support any file attributes beyond the name. 56 | bool sizeValid; 57 | bool permissionsValid; 58 | }; 59 | 60 | } // namespace QSsh 61 | 62 | #endif // SFTPDEFS_H 63 | -------------------------------------------------------------------------------- /include/ssh/sftpfilesystemmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPFILESYSTEMMODEL_H 27 | #define SFTPFILESYSTEMMODEL_H 28 | 29 | #include "sftpdefs.h" 30 | 31 | #include "ssh_global.h" 32 | 33 | #include 34 | 35 | namespace QSsh { 36 | class SshConnectionParameters; 37 | 38 | namespace Internal { class SftpFileSystemModelPrivate; } 39 | 40 | // Very simple read-only model. Symbolic links are not followed. 41 | class QSSH_EXPORT SftpFileSystemModel : public QAbstractItemModel 42 | { 43 | Q_OBJECT 44 | public: 45 | explicit SftpFileSystemModel(QObject *parent = 0); 46 | ~SftpFileSystemModel(); 47 | 48 | /* 49 | * Once this is called, an SFTP connection is established and the model is populated. 50 | * The effect of additional calls is undefined. 51 | */ 52 | void setSshConnection(const SshConnectionParameters &sshParams); 53 | 54 | void setRootDirectory(const QString &path); // Default is "/". 55 | QString rootDirectory() const; 56 | 57 | SftpJobId downloadFile(const QModelIndex &index, const QString &targetFilePath); 58 | 59 | // Use this to get the full path of a file or directory. 60 | static const int PathRole = Qt::UserRole; 61 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 62 | 63 | signals: 64 | /* 65 | * E.g. "Permission denied". Note that this can happen without direct user intervention, 66 | * due to e.g. the view calling rowCount() on a non-readable directory. This signal should 67 | * therefore not result in a message box or similar, since it might occur very often. 68 | */ 69 | void sftpOperationFailed(const QString &errorMessage); 70 | 71 | /* 72 | * This error is not recoverable. The model will not have any content after 73 | * the signal has been emitted. 74 | */ 75 | void connectionError(const QString &errorMessage); 76 | 77 | // Success <=> error.isEmpty(). 78 | void sftpOperationFinished(QSsh::SftpJobId, const QString &error); 79 | 80 | private slots: 81 | void handleSshConnectionEstablished(); 82 | void handleSshConnectionFailure(); 83 | void handleSftpChannelInitialized(); 84 | void handleSftpChannelError(const QString &reason); 85 | void handleFileInfo(QSsh::SftpJobId jobId, const QList &fileInfoList); 86 | void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage); 87 | 88 | private: 89 | int columnCount(const QModelIndex &parent = QModelIndex()) const; 90 | Qt::ItemFlags flags(const QModelIndex &index) const; 91 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 92 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 93 | QModelIndex parent(const QModelIndex &child) const; 94 | int rowCount(const QModelIndex &parent = QModelIndex()) const; 95 | 96 | void statRootDirectory(); 97 | void shutDown(); 98 | 99 | Internal::SftpFileSystemModelPrivate * const d; 100 | }; 101 | 102 | } // namespace QSsh; 103 | 104 | #endif // SFTPFILESYSTEMMODEL_H 105 | -------------------------------------------------------------------------------- /include/ssh/ssh_global.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSH_GLOBAL_H 27 | #define SSH_GLOBAL_H 28 | 29 | #include 30 | 31 | #if defined(QSSH_LIBRARY) 32 | # define QSSH_EXPORT Q_DECL_EXPORT 33 | #else 34 | # define QSSH_EXPORT Q_DECL_IMPORT 35 | #endif 36 | 37 | #define QSSH_PRINT_WARNING qWarning("Soft assert at %s:%d", __FILE__, __LINE__) 38 | #define QSSH_ASSERT(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; } } while (false) 39 | #define QSSH_ASSERT_AND_RETURN(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; return; } } while (false) 40 | #define QSSH_ASSERT_AND_RETURN_VALUE(cond, value) do { if (!(cond)) { QSSH_PRINT_WARNING; return value; } } while (false) 41 | 42 | #endif // SSH_GLOBAL_H 43 | -------------------------------------------------------------------------------- /include/ssh/sshconnection.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCONNECTION_H 27 | #define SSHCONNECTION_H 28 | 29 | #include "ssherrors.h" 30 | #include "sshhostkeydatabase.h" 31 | 32 | #include "ssh_global.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace QSsh { 42 | class SftpChannel; 43 | class SshDirectTcpIpTunnel; 44 | class SshRemoteProcess; 45 | 46 | namespace Internal { class SshConnectionPrivate; } 47 | 48 | enum SshConnectionOption { 49 | SshIgnoreDefaultProxy = 0x1, 50 | SshEnableStrictConformanceChecks = 0x2 51 | }; 52 | 53 | Q_DECLARE_FLAGS(SshConnectionOptions, SshConnectionOption) 54 | 55 | enum SshHostKeyCheckingMode { 56 | SshHostKeyCheckingNone, 57 | SshHostKeyCheckingStrict, 58 | SshHostKeyCheckingAllowNoMatch, 59 | SshHostKeyCheckingAllowMismatch 60 | }; 61 | 62 | class QSSH_EXPORT SshConnectionParameters 63 | { 64 | public: 65 | enum AuthenticationType { 66 | AuthenticationTypePassword, 67 | AuthenticationTypePublicKey, 68 | AuthenticationTypeKeyboardInteractive, 69 | 70 | // Some servers disable "password", others disable "keyboard-interactive". 71 | AuthenticationTypeTryAllPasswordBasedMethods 72 | }; 73 | 74 | SshConnectionParameters(); 75 | 76 | QString host; 77 | QString userName; 78 | QString password; 79 | QString privateKeyFile; 80 | int timeout; // In seconds. 81 | AuthenticationType authenticationType; 82 | quint16 port; 83 | SshConnectionOptions options; 84 | SshHostKeyCheckingMode hostKeyCheckingMode; 85 | SshHostKeyDatabasePtr hostKeyDatabase; 86 | }; 87 | 88 | QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2); 89 | QSSH_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2); 90 | 91 | class QSSH_EXPORT SshConnectionInfo 92 | { 93 | public: 94 | SshConnectionInfo() : localPort(0), peerPort(0) {} 95 | SshConnectionInfo(const QHostAddress &la, quint16 lp, const QHostAddress &pa, quint16 pp) 96 | : localAddress(la), localPort(lp), peerAddress(pa), peerPort(pp) {} 97 | 98 | QHostAddress localAddress; 99 | quint16 localPort; 100 | QHostAddress peerAddress; 101 | quint16 peerPort; 102 | }; 103 | 104 | class QSSH_EXPORT SshConnection : public QObject 105 | { 106 | Q_OBJECT 107 | 108 | public: 109 | enum State { Unconnected, Connecting, Connected }; 110 | 111 | explicit SshConnection(const SshConnectionParameters &serverInfo, QObject *parent = 0); 112 | 113 | void connectToHost(); 114 | void disconnectFromHost(); 115 | State state() const; 116 | SshError errorState() const; 117 | QString errorString() const; 118 | SshConnectionParameters connectionParameters() const; 119 | SshConnectionInfo connectionInfo() const; 120 | ~SshConnection(); 121 | 122 | QSharedPointer createRemoteProcess(const QByteArray &command); 123 | QSharedPointer createRemoteShell(); 124 | QSharedPointer createSftpChannel(); 125 | QSharedPointer createTunnel(const QString &originatingHost, 126 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort); 127 | 128 | // -1 if an error occurred, number of channels closed otherwise. 129 | int closeAllChannels(); 130 | 131 | int channelCount() const; 132 | 133 | signals: 134 | void connected(); 135 | void disconnected(); 136 | void dataAvailable(const QString &message); 137 | void error(QSsh::SshError); 138 | 139 | private: 140 | Internal::SshConnectionPrivate *d; 141 | }; 142 | 143 | } // namespace QSsh 144 | 145 | #endif // SSHCONNECTION_H 146 | -------------------------------------------------------------------------------- /include/ssh/sshconnectionmanager.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCONNECTIONMANAGER_H 27 | #define SSHCONNECTIONMANAGER_H 28 | 29 | #include "ssh_global.h" 30 | 31 | namespace QSsh { 32 | 33 | class SshConnection; 34 | class SshConnectionParameters; 35 | 36 | QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams); 37 | QSSH_EXPORT void releaseConnection(SshConnection *connection); 38 | 39 | // Make sure the next acquireConnection with the given parameters will return a new connection. 40 | QSSH_EXPORT void forceNewConnection(const SshConnectionParameters &sshParams); 41 | 42 | } // namespace QSsh 43 | 44 | #endif // SSHCONNECTIONMANAGER_H 45 | -------------------------------------------------------------------------------- /include/ssh/sshdirecttcpiptunnel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHDIRECTTCPIPTUNNEL_H 27 | #define SSHDIRECTTCPIPTUNNEL_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace QSsh { 35 | 36 | namespace Internal { 37 | class SshChannelManager; 38 | class SshDirectTcpIpTunnelPrivate; 39 | class SshSendFacility; 40 | } // namespace Internal 41 | 42 | class QSSH_EXPORT SshDirectTcpIpTunnel : public QIODevice 43 | { 44 | Q_OBJECT 45 | 46 | friend class Internal::SshChannelManager; 47 | 48 | public: 49 | typedef QSharedPointer Ptr; 50 | 51 | ~SshDirectTcpIpTunnel(); 52 | 53 | // QIODevice stuff 54 | bool atEnd() const; 55 | qint64 bytesAvailable() const; 56 | bool canReadLine() const; 57 | void close(); 58 | bool isSequential() const { return true; } 59 | 60 | void initialize(); 61 | 62 | signals: 63 | void initialized(); 64 | void error(const QString &reason); 65 | void tunnelClosed(); 66 | 67 | private: 68 | SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost, 69 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 70 | Internal::SshSendFacility &sendFacility); 71 | 72 | // QIODevice stuff 73 | qint64 readData(char *data, qint64 maxlen); 74 | qint64 writeData(const char *data, qint64 len); 75 | 76 | Q_SLOT void handleError(const QString &reason); 77 | 78 | Internal::SshDirectTcpIpTunnelPrivate * const d; 79 | }; 80 | 81 | } // namespace QSsh 82 | 83 | #endif // SSHDIRECTTCPIPTUNNEL_H 84 | -------------------------------------------------------------------------------- /include/ssh/ssherrors.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHERRORS_P_H 27 | #define SSHERRORS_P_H 28 | 29 | namespace QSsh { 30 | 31 | enum SshError { 32 | SshNoError, SshSocketError, SshTimeoutError, SshProtocolError, 33 | SshHostKeyError, SshKeyFileError, SshAuthenticationError, 34 | SshClosedByServerError, SshInternalError 35 | }; 36 | 37 | } // namespace QSsh 38 | 39 | #endif // SSHERRORS_P_H 40 | -------------------------------------------------------------------------------- /include/ssh/sshhostkeydatabase.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHHOSTKEYDATABASE_H 27 | #define SSHHOSTKEYDATABASE_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | class QByteArray; 35 | class QString; 36 | QT_END_NAMESPACE 37 | 38 | namespace QSsh { 39 | class SshHostKeyDatabase; 40 | typedef QSharedPointer SshHostKeyDatabasePtr; 41 | 42 | class QSSH_EXPORT SshHostKeyDatabase 43 | { 44 | friend class QSharedPointer; // To give create() access to our constructor. 45 | 46 | public: 47 | enum KeyLookupResult { 48 | KeyLookupMatch, 49 | KeyLookupNoMatch, 50 | KeyLookupMismatch 51 | }; 52 | 53 | ~SshHostKeyDatabase(); 54 | 55 | bool load(const QString &filePath, QString *error = 0); 56 | bool store(const QString &filePath, QString *error = 0) const; 57 | KeyLookupResult matchHostKey(const QString &hostName, const QByteArray &key) const; 58 | void insertHostKey(const QString &hostName, const QByteArray &key); 59 | 60 | private: 61 | SshHostKeyDatabase(); 62 | 63 | class SshHostKeyDatabasePrivate; 64 | SshHostKeyDatabasePrivate * const d; 65 | }; 66 | 67 | } // namespace QSsh 68 | 69 | #endif // Include guard. 70 | -------------------------------------------------------------------------------- /include/ssh/sshkeycreationdialog.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHKEYCREATIONDIALOG_H 27 | #define SSHKEYCREATIONDIALOG_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | 33 | namespace QSsh { 34 | class SshKeyGenerator; 35 | 36 | namespace Ui { class SshKeyCreationDialog; } 37 | 38 | class QSSH_EXPORT SshKeyCreationDialog : public QDialog 39 | { 40 | Q_OBJECT 41 | public: 42 | SshKeyCreationDialog(QWidget *parent = 0); 43 | ~SshKeyCreationDialog(); 44 | 45 | QString privateKeyFilePath() const; 46 | QString publicKeyFilePath() const; 47 | 48 | private slots: 49 | void keyTypeChanged(); 50 | void generateKeys(); 51 | void handleBrowseButtonClicked(); 52 | 53 | private: 54 | void setPrivateKeyFile(const QString &filePath); 55 | void saveKeys(); 56 | bool userForbidsOverwriting(); 57 | 58 | private: 59 | SshKeyGenerator *m_keyGenerator; 60 | Ui::SshKeyCreationDialog *m_ui; 61 | }; 62 | 63 | } // namespace QSsh 64 | 65 | #endif // SSHKEYCREATIONDIALOG_H 66 | -------------------------------------------------------------------------------- /include/ssh/sshkeygenerator.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and Digia. For licensing terms and 13 | ** conditions see http://www.qt.io/licensing. For further information 14 | ** use the contact form at http://www.qt.io/contact-us. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser 18 | ** General Public License version 2.1 or version 3 as published by the Free 19 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 20 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 21 | ** following information to ensure the GNU Lesser General Public License 22 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 23 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ****************************************************************************/ 30 | 31 | #ifndef SSHKEYGENERATOR_H 32 | #define SSHKEYGENERATOR_H 33 | 34 | #include "ssh_global.h" 35 | 36 | #include 37 | #include 38 | 39 | namespace Botan { 40 | class Private_Key; 41 | class RandomNumberGenerator; 42 | } 43 | 44 | namespace QSsh { 45 | 46 | class QSSH_EXPORT SshKeyGenerator 47 | { 48 | Q_DECLARE_TR_FUNCTIONS(SshKeyGenerator) 49 | public: 50 | enum KeyType { Rsa, Dsa }; 51 | enum PrivateKeyFormat { Pkcs8, OpenSsl, Mixed }; 52 | enum EncryptionMode { DoOfferEncryption, DoNotOfferEncryption }; // Only relevant for Pkcs8 format. 53 | 54 | SshKeyGenerator(); 55 | bool generateKeys(KeyType type, PrivateKeyFormat format, int keySize, 56 | EncryptionMode encryptionMode = DoOfferEncryption); 57 | 58 | QString error() const { return m_error; } 59 | QByteArray privateKey() const { return m_privateKey; } 60 | QByteArray publicKey() const { return m_publicKey; } 61 | KeyType type() const { return m_type; } 62 | 63 | private: 64 | typedef QSharedPointer KeyPtr; 65 | 66 | void generatePkcs8KeyStrings(const KeyPtr &key, Botan::RandomNumberGenerator &rng); 67 | void generatePkcs8KeyString(const KeyPtr &key, bool privateKey, 68 | Botan::RandomNumberGenerator &rng); 69 | void generateOpenSslKeyStrings(const KeyPtr &key); 70 | void generateOpenSslPrivateKeyString(const KeyPtr &key); 71 | void generateOpenSslPublicKeyString(const KeyPtr &key); 72 | QString getPassword() const; 73 | 74 | QString m_error; 75 | QByteArray m_publicKey; 76 | QByteArray m_privateKey; 77 | KeyType m_type; 78 | EncryptionMode m_encryptionMode; 79 | }; 80 | 81 | } // namespace QSsh 82 | 83 | #endif // SSHKEYGENERATOR_H 84 | -------------------------------------------------------------------------------- /include/ssh/sshremoteprocess.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and Digia. For licensing terms and 13 | ** conditions see http://www.qt.io/licensing. For further information 14 | ** use the contact form at http://www.qt.io/contact-us. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser 18 | ** General Public License version 2.1 or version 3 as published by the Free 19 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 20 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 21 | ** following information to ensure the GNU Lesser General Public License 22 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 23 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ****************************************************************************/ 30 | 31 | #ifndef SSHREMOTEPROCESS_H 32 | #define SSHREMOTEPROCESS_H 33 | 34 | #include "ssh_global.h" 35 | 36 | #include 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | class QByteArray; 41 | QT_END_NAMESPACE 42 | 43 | namespace QSsh { 44 | class SshPseudoTerminal; 45 | namespace Internal { 46 | class SshChannelManager; 47 | class SshRemoteProcessPrivate; 48 | class SshSendFacility; 49 | } // namespace Internal 50 | 51 | // TODO: ProcessChannel 52 | class QSSH_EXPORT SshRemoteProcess : public QIODevice 53 | { 54 | Q_OBJECT 55 | 56 | friend class Internal::SshChannelManager; 57 | friend class Internal::SshRemoteProcessPrivate; 58 | 59 | public: 60 | typedef QSharedPointer Ptr; 61 | enum ExitStatus { FailedToStart, CrashExit, NormalExit }; 62 | enum Signal { 63 | AbrtSignal, AlrmSignal, FpeSignal, HupSignal, IllSignal, IntSignal, KillSignal, PipeSignal, 64 | QuitSignal, SegvSignal, TermSignal, Usr1Signal, Usr2Signal, NoSignal 65 | }; 66 | 67 | ~SshRemoteProcess(); 68 | 69 | // QIODevice stuff 70 | bool atEnd() const; 71 | qint64 bytesAvailable() const; 72 | bool canReadLine() const; 73 | void close(); 74 | bool isSequential() const { return true; } 75 | 76 | QProcess::ProcessChannel readChannel() const; 77 | void setReadChannel(QProcess::ProcessChannel channel); 78 | 79 | /* 80 | * Note that this is of limited value in practice, because servers are 81 | * usually configured to ignore such requests for security reasons. 82 | */ 83 | void addToEnvironment(const QByteArray &var, const QByteArray &value); 84 | void clearEnvironment(); 85 | 86 | void requestTerminal(const SshPseudoTerminal &terminal); 87 | void start(); 88 | 89 | bool isRunning() const; 90 | int exitCode() const; 91 | Signal exitSignal() const; 92 | 93 | QByteArray readAllStandardOutput(); 94 | QByteArray readAllStandardError(); 95 | 96 | // Note: This is ignored by the OpenSSH server. 97 | void sendSignal(Signal signal); 98 | void kill() { sendSignal(KillSignal); } 99 | 100 | signals: 101 | void started(); 102 | 103 | void readyReadStandardOutput(); 104 | void readyReadStandardError(); 105 | 106 | /* 107 | * Parameter is of type ExitStatus, but we use int because of 108 | * signal/slot awkwardness (full namespace required). 109 | */ 110 | void closed(int exitStatus); 111 | 112 | private: 113 | SshRemoteProcess(const QByteArray &command, quint32 channelId, 114 | Internal::SshSendFacility &sendFacility); 115 | SshRemoteProcess(quint32 channelId, Internal::SshSendFacility &sendFacility); 116 | 117 | // QIODevice stuff 118 | qint64 readData(char *data, qint64 maxlen); 119 | qint64 writeData(const char *data, qint64 len); 120 | 121 | void init(); 122 | QByteArray readAllFromChannel(QProcess::ProcessChannel channel); 123 | 124 | Internal::SshRemoteProcessPrivate *d; 125 | }; 126 | 127 | } // namespace QSsh 128 | 129 | #endif // SSHREMOTEPROCESS_H 130 | -------------------------------------------------------------------------------- /include/ssh/sshremoteprocessrunner.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHREMOTEPROCESSRUNNER_H 27 | #define SSHREMOTEPROCESSRUNNER_H 28 | 29 | #include "sshconnection.h" 30 | #include "sshremoteprocess.h" 31 | 32 | namespace QSsh { 33 | namespace Internal { class SshRemoteProcessRunnerPrivate; } 34 | 35 | class QSSH_EXPORT SshRemoteProcessRunner : public QObject 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | SshRemoteProcessRunner(QObject *parent = 0); 41 | ~SshRemoteProcessRunner(); 42 | 43 | void run(const QByteArray &command, const SshConnectionParameters &sshParams); 44 | void runInTerminal(const QByteArray &command, const SshPseudoTerminal &terminal, 45 | const SshConnectionParameters &sshParams); 46 | QByteArray command() const; 47 | 48 | QSsh::SshError lastConnectionError() const; 49 | QString lastConnectionErrorString() const; 50 | 51 | bool isProcessRunning() const; 52 | void writeDataToProcess(const QByteArray &data); 53 | void sendSignalToProcess(SshRemoteProcess::Signal signal); // No effect with OpenSSH server. 54 | void cancel(); // Does not stop remote process, just frees SSH-related process resources. 55 | SshRemoteProcess::ExitStatus processExitStatus() const; 56 | SshRemoteProcess::Signal processExitSignal() const; 57 | int processExitCode() const; 58 | QString processErrorString() const; 59 | QByteArray readAllStandardOutput(); 60 | QByteArray readAllStandardError(); 61 | 62 | signals: 63 | void connectionError(); 64 | void processStarted(); 65 | void readyReadStandardOutput(); 66 | void readyReadStandardError(); 67 | void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus 68 | 69 | private slots: 70 | void handleConnected(); 71 | void handleConnectionError(QSsh::SshError error); 72 | void handleDisconnected(); 73 | void handleProcessStarted(); 74 | void handleProcessFinished(int exitStatus); 75 | void handleStdout(); 76 | void handleStderr(); 77 | 78 | private: 79 | void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams); 80 | void setState(int newState); 81 | 82 | Internal::SshRemoteProcessRunnerPrivate * const d; 83 | }; 84 | 85 | } // namespace QSsh 86 | 87 | #endif // SSHREMOTEPROCESSRUNNER_H 88 | -------------------------------------------------------------------------------- /qssh.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | 4 | SUBDIRS = \ 5 | src \ 6 | examples 7 | -------------------------------------------------------------------------------- /src/.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | SortRole=type 3 | Timestamp=2016,7,3,18,18,59 4 | Version=3 5 | ViewMode=1 6 | VisibleRoles=Details_text,Details_size,Details_date,Details_type,CustomizedDetails 7 | -------------------------------------------------------------------------------- /src/3rdparty/botan/botan.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH *= $$PWD/.. 2 | HEADERS += $$PWD/botan.h 3 | 4 | equals(USE_SYSTEM_BOTAN, 1) { 5 | DEFINES += USE_SYSTEM_BOTAN 6 | CONFIG += link_pkgconfig 7 | PKGCONFIG += botan-1.10 8 | } else { 9 | 10 | SOURCES += $$PWD/botan.cpp 11 | 12 | CONFIG += exceptions 13 | 14 | DEPENDPATH += . 15 | 16 | DEFINES += BOTAN_DLL= 17 | unix:DEFINES += BOTAN_TARGET_OS_HAS_GETTIMEOFDAY BOTAN_HAS_ALLOC_MMAP \ 18 | BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM BOTAN_HAS_ENTROPY_SRC_EGD BOTAN_HAS_ENTROPY_SRC_FTW \ 19 | BOTAN_HAS_ENTROPY_SRC_UNIX BOTAN_HAS_MUTEX_PTHREAD BOTAN_HAS_PIPE_UNIXFD_IO 20 | *linux*:DEFINES += BOTAN_TARGET_OS_IS_LINUX BOTAN_TARGET_OS_HAS_CLOCK_GETTIME \ 21 | BOTAN_TARGET_OS_HAS_DLOPEN BOTAN_TARGET_OS_HAS_GMTIME_R BOTAN_TARGET_OS_HAS_POSIX_MLOCK \ 22 | BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE BOTAN_HAS_DYNAMIC_LOADER 23 | macx:DEFINES += BOTAN_TARGET_OS_IS_DARWIN 24 | *g++*:DEFINES += BOTAN_BUILD_COMPILER_IS_GCC 25 | *clang*:DEFINES += BOTAN_BUILD_COMPILER_IS_CLANG 26 | *icc*:DEFINES += BOTAN_BUILD_COMPILER_IS_INTEL 27 | 28 | CONFIG(x86_64):DEFINES += BOTAN_TARGET_ARCH_IS_X86_64 29 | 30 | win32 { 31 | DEFINES += BOTAN_TARGET_OS_IS_WINDOWS \ 32 | BOTAN_TARGET_OS_HAS_LOADLIBRARY BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME \ 33 | BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE \ 34 | BOTAN_HAS_DYNAMIC_LOADER BOTAN_HAS_ENTROPY_SRC_CAPI BOTAN_HAS_ENTROPY_SRC_WIN32 \ 35 | BOTAN_HAS_MUTEX_WIN32 36 | 37 | msvc { 38 | QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs 39 | QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250 40 | DEFINES += BOTAN_BUILD_COMPILER_IS_MSVC BOTAN_TARGET_OS_HAS_GMTIME_S _SCL_SECURE_NO_WARNINGS 41 | } else { 42 | QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long 43 | QMAKE_CXXFLAGS += -fpermissive -finline-functions -Wno-long-long 44 | } 45 | LIBS += -ladvapi32 -luser32 46 | } 47 | 48 | unix:*-g++* { 49 | QMAKE_CFLAGS += -fPIC -fpermissive -finline-functions -Wno-long-long 50 | QMAKE_CXXFLAGS += -fPIC -fpermissive -finline-functions -Wno-long-long 51 | } 52 | 53 | linux*|freebsd* { 54 | LIBS += -lrt $$QMAKE_LIBS_DYNLOAD 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/3rdparty/botan/doc/license.txt: -------------------------------------------------------------------------------- 1 | 2 | .. _license: 3 | .. highlight:: none 4 | 5 | License 6 | ======================================== 7 | 8 | Botan (http://botan.randombit.net/) is distributed under these terms:: 9 | 10 | Copyright (C) 1999-2011 Jack Lloyd 11 | 2001 Peter J Jones 12 | 2004-2007 Justin Karneges 13 | 2004 Vaclav Ovsik 14 | 2005 Matthew Gregan 15 | 2005-2006 Matt Johnston 16 | 2006 Luca Piccarreta 17 | 2007 Yves Jerschow 18 | 2007-2008 FlexSecure GmbH 19 | 2007-2008 Technische Universitat Darmstadt 20 | 2007-2008 Falko Strenzke 21 | 2007-2008 Martin Doering 22 | 2007 Manuel Hartl 23 | 2007 Christoph Ludwig 24 | 2007 Patrick Sona 25 | 2010 Olivier de Gaalon 26 | All rights reserved. 27 | 28 | Redistribution and use in source and binary forms, with or without 29 | modification, are permitted provided that the following conditions are 30 | met: 31 | 32 | 1. Redistributions of source code must retain the above copyright 33 | notice, this list of conditions, and the following disclaimer. 34 | 35 | 2. Redistributions in binary form must reproduce the above copyright 36 | notice, this list of conditions, and the following disclaimer in the 37 | documentation and/or other materials provided with the distribution. 38 | 39 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR 40 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 41 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, 42 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE 43 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 44 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 46 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 48 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 49 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | -------------------------------------------------------------------------------- /src/3rdparty/botan/readme.txt: -------------------------------------------------------------------------------- 1 | Botan 1.10.2, 2012-06-17 2 | http://botan.randombit.net/ 3 | 4 | Botan is a C++ class library for performing a wide variety of 5 | cryptographic operations. It is released under the 2 clause BSD 6 | license; see doc/license.txt for the specifics. You can file bugs in 7 | Bugzilla (http://bugs.randombit.net/) or by sending a report to the 8 | botan-devel mailing list. More information about the mailing list is 9 | at http://lists.randombit.net/mailman/listinfo/botan-devel/ 10 | 11 | You can find documentation online at http://botan.randombit.net/ as 12 | well as in the doc directory in the distribution. Several examples can 13 | be found in doc/examples as well. 14 | 15 | Jack Lloyd (lloyd@randombit.net) 16 | -------------------------------------------------------------------------------- /src/sftpchannel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPCHANNEL_H 27 | #define SFTPCHANNEL_H 28 | 29 | #include "sftpdefs.h" 30 | #include "sftpincomingpacket_p.h" 31 | 32 | #include "ssh_global.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace QSsh { 40 | 41 | namespace Internal { 42 | class SftpChannelPrivate; 43 | class SshChannelManager; 44 | class SshSendFacility; 45 | } // namespace Internal 46 | 47 | class QSSH_EXPORT SftpChannel : public QObject 48 | { 49 | Q_OBJECT 50 | 51 | friend class Internal::SftpChannelPrivate; 52 | friend class Internal::SshChannelManager; 53 | public: 54 | typedef QSharedPointer Ptr; 55 | 56 | enum State { Uninitialized, Initializing, Initialized, Closing, Closed }; 57 | State state() const; 58 | 59 | void initialize(); 60 | void closeChannel(); 61 | 62 | SftpJobId statFile(const QString &path); 63 | SftpJobId listDirectory(const QString &dirPath); 64 | SftpJobId createDirectory(const QString &dirPath); 65 | SftpJobId removeDirectory(const QString &dirPath); 66 | SftpJobId removeFile(const QString &filePath); 67 | SftpJobId renameFileOrDirectory(const QString &oldPath, 68 | const QString &newPath); 69 | SftpJobId createFile(const QString &filePath, SftpOverwriteMode mode); 70 | SftpJobId createLink(const QString &filePath, const QString &target); 71 | SftpJobId uploadFile(const QString &localFilePath, 72 | const QString &remoteFilePath, SftpOverwriteMode mode); 73 | SftpJobId downloadFile(const QString &remoteFilePath, 74 | const QString &localFilePath, SftpOverwriteMode mode); 75 | SftpJobId uploadDir(const QString &localDirPath, 76 | const QString &remoteParentDirPath); 77 | 78 | ~SftpChannel(); 79 | 80 | signals: 81 | void initialized(); 82 | void channelError(const QString &reason); 83 | void closed(); 84 | 85 | // error.isEmpty <=> finished successfully 86 | void finished(QSsh::SftpJobId job, const QString &error = QString()); 87 | 88 | // TODO: Also emit for each file copied by uploadDir(). 89 | void dataAvailable(QSsh::SftpJobId job, const QString &data); 90 | 91 | /* 92 | * This signal is emitted as a result of: 93 | * - statFile() (with the list having exactly one element) 94 | * - listDirectory() (potentially more than once) 95 | */ 96 | void fileInfoAvailable(QSsh::SftpJobId job, const QList &fileInfoList); 97 | 98 | private: 99 | SftpChannel(quint32 channelId, Internal::SshSendFacility &sendFacility); 100 | 101 | Internal::SftpChannelPrivate *d; 102 | }; 103 | 104 | } // namespace QSsh 105 | 106 | #endif // SFTPCHANNEL_H 107 | -------------------------------------------------------------------------------- /src/sftpchannel_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPCHANNEL_P_H 27 | #define SFTPCHANNEL_P_H 28 | 29 | #include "sftpdefs.h" 30 | #include "sftpincomingpacket_p.h" 31 | #include "sftpoperation_p.h" 32 | #include "sftpoutgoingpacket_p.h" 33 | #include "sshchannel_p.h" 34 | 35 | #include 36 | #include 37 | 38 | namespace QSsh { 39 | class SftpChannel; 40 | namespace Internal { 41 | 42 | class SftpChannelPrivate : public AbstractSshChannel 43 | { 44 | Q_OBJECT 45 | friend class QSsh::SftpChannel; 46 | public: 47 | enum SftpState { Inactive, SubsystemRequested, InitSent, Initialized }; 48 | 49 | signals: 50 | void initialized(); 51 | void channelError(const QString &reason); 52 | void closed(); 53 | void finished(QSsh::SftpJobId job, const QString &error = QString()); 54 | void dataAvailable(QSsh::SftpJobId job, const QString &data); 55 | void fileInfoAvailable(QSsh::SftpJobId job, const QList &fileInfoList); 56 | 57 | private: 58 | typedef QMap JobMap; 59 | 60 | SftpChannelPrivate(quint32 channelId, SshSendFacility &sendFacility, 61 | SftpChannel *sftp); 62 | SftpJobId createJob(const AbstractSftpOperation::Ptr &job); 63 | 64 | virtual void handleChannelSuccess(); 65 | virtual void handleChannelFailure(); 66 | 67 | virtual void handleOpenSuccessInternal(); 68 | virtual void handleOpenFailureInternal(const QString &reason); 69 | virtual void handleChannelDataInternal(const QByteArray &data); 70 | virtual void handleChannelExtendedDataInternal(quint32 type, 71 | const QByteArray &data); 72 | virtual void handleExitStatus(const SshChannelExitStatus &exitStatus); 73 | virtual void handleExitSignal(const SshChannelExitSignal &signal); 74 | 75 | virtual void closeHook(); 76 | 77 | void handleCurrentPacket(); 78 | void handleServerVersion(); 79 | void handleHandle(); 80 | void handleStatus(); 81 | void handleName(); 82 | void handleReadData(); 83 | void handleAttrs(); 84 | 85 | void handleStatusGeneric(const JobMap::Iterator &it, 86 | const SftpStatusResponse &response); 87 | void handleMkdirStatus(const JobMap::Iterator &it, 88 | const SftpStatusResponse &response); 89 | void handleLsStatus(const JobMap::Iterator &it, 90 | const SftpStatusResponse &response); 91 | void handleGetStatus(const JobMap::Iterator &it, 92 | const SftpStatusResponse &response); 93 | void handlePutStatus(const JobMap::Iterator &it, 94 | const SftpStatusResponse &response); 95 | 96 | void handleLsHandle(const JobMap::Iterator &it); 97 | void handleCreateFileHandle(const JobMap::Iterator &it); 98 | void handleGetHandle(const JobMap::Iterator &it); 99 | void handlePutHandle(const JobMap::Iterator &it); 100 | 101 | void spawnReadRequests(const SftpDownload::Ptr &job); 102 | void spawnWriteRequests(const JobMap::Iterator &it); 103 | void sendReadRequest(const SftpDownload::Ptr &job, quint32 requestId); 104 | void sendWriteRequest(const JobMap::Iterator &it); 105 | void finishTransferRequest(const JobMap::Iterator &it); 106 | void removeTransferRequest(const JobMap::Iterator &it); 107 | void reportRequestError(const AbstractSftpOperationWithHandle::Ptr &job, 108 | const QString &error); 109 | void sendTransferCloseHandle(const AbstractSftpTransfer::Ptr &job, 110 | quint32 requestId); 111 | 112 | void attributesToFileInfo(const SftpFileAttributes &attributes, SftpFileInfo &fileInfo) const; 113 | 114 | JobMap::Iterator lookupJob(SftpJobId id); 115 | JobMap m_jobs; 116 | SftpOutgoingPacket m_outgoingPacket; 117 | SftpIncomingPacket m_incomingPacket; 118 | QByteArray m_incomingData; 119 | SftpJobId m_nextJobId; 120 | SftpState m_sftpState; 121 | SftpChannel *m_sftp; 122 | }; 123 | 124 | } // namespace Internal 125 | } // namespace QSsh 126 | 127 | #endif // SFTPCHANNEL_P_H 128 | -------------------------------------------------------------------------------- /src/sftpdefs.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sftpdefs.h" 27 | 28 | namespace QSsh { const SftpJobId SftpInvalidJob = 0; } 29 | -------------------------------------------------------------------------------- /src/sftpdefs.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPDEFS_H 27 | #define SFTPDEFS_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace QSsh { 35 | 36 | typedef quint32 SftpJobId; 37 | QSSH_EXPORT extern const SftpJobId SftpInvalidJob; 38 | 39 | enum SftpOverwriteMode { 40 | SftpOverwriteExisting, SftpAppendToExisting, SftpSkipExisting 41 | }; 42 | 43 | enum SftpFileType { FileTypeRegular, FileTypeDirectory, FileTypeOther, FileTypeUnknown }; 44 | 45 | class QSSH_EXPORT SftpFileInfo 46 | { 47 | public: 48 | SftpFileInfo() : type(FileTypeUnknown), sizeValid(false), permissionsValid(false) { } 49 | 50 | QString name; 51 | SftpFileType type; 52 | quint64 size; 53 | QFile::Permissions permissions; 54 | 55 | // The RFC allows an SFTP server not to support any file attributes beyond the name. 56 | bool sizeValid; 57 | bool permissionsValid; 58 | }; 59 | 60 | } // namespace QSsh 61 | 62 | #endif // SFTPDEFS_H 63 | -------------------------------------------------------------------------------- /src/sftpfilesystemmodel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPFILESYSTEMMODEL_H 27 | #define SFTPFILESYSTEMMODEL_H 28 | 29 | #include "sftpdefs.h" 30 | 31 | #include "ssh_global.h" 32 | 33 | #include 34 | 35 | namespace QSsh { 36 | class SshConnectionParameters; 37 | 38 | namespace Internal { class SftpFileSystemModelPrivate; } 39 | 40 | // Very simple read-only model. Symbolic links are not followed. 41 | class QSSH_EXPORT SftpFileSystemModel : public QAbstractItemModel 42 | { 43 | Q_OBJECT 44 | public: 45 | explicit SftpFileSystemModel(QObject *parent = 0); 46 | ~SftpFileSystemModel(); 47 | 48 | /* 49 | * Once this is called, an SFTP connection is established and the model is populated. 50 | * The effect of additional calls is undefined. 51 | */ 52 | void setSshConnection(const SshConnectionParameters &sshParams); 53 | 54 | void setRootDirectory(const QString &path); // Default is "/". 55 | QString rootDirectory() const; 56 | 57 | SftpJobId downloadFile(const QModelIndex &index, const QString &targetFilePath); 58 | 59 | // Use this to get the full path of a file or directory. 60 | static const int PathRole = Qt::UserRole; 61 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 62 | 63 | signals: 64 | /* 65 | * E.g. "Permission denied". Note that this can happen without direct user intervention, 66 | * due to e.g. the view calling rowCount() on a non-readable directory. This signal should 67 | * therefore not result in a message box or similar, since it might occur very often. 68 | */ 69 | void sftpOperationFailed(const QString &errorMessage); 70 | 71 | /* 72 | * This error is not recoverable. The model will not have any content after 73 | * the signal has been emitted. 74 | */ 75 | void connectionError(const QString &errorMessage); 76 | 77 | // Success <=> error.isEmpty(). 78 | void sftpOperationFinished(QSsh::SftpJobId, const QString &error); 79 | 80 | private slots: 81 | void handleSshConnectionEstablished(); 82 | void handleSshConnectionFailure(); 83 | void handleSftpChannelInitialized(); 84 | void handleSftpChannelError(const QString &reason); 85 | void handleFileInfo(QSsh::SftpJobId jobId, const QList &fileInfoList); 86 | void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage); 87 | 88 | private: 89 | int columnCount(const QModelIndex &parent = QModelIndex()) const; 90 | Qt::ItemFlags flags(const QModelIndex &index) const; 91 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 92 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 93 | QModelIndex parent(const QModelIndex &child) const; 94 | int rowCount(const QModelIndex &parent = QModelIndex()) const; 95 | 96 | void statRootDirectory(); 97 | void shutDown(); 98 | 99 | Internal::SftpFileSystemModelPrivate * const d; 100 | }; 101 | 102 | } // namespace QSsh; 103 | 104 | #endif // SFTPFILESYSTEMMODEL_H 105 | -------------------------------------------------------------------------------- /src/sftpincomingpacket_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPINCOMINGPACKET_P_H 27 | #define SFTPINCOMINGPACKET_P_H 28 | 29 | #include "sftppacket_p.h" 30 | 31 | namespace QSsh { 32 | namespace Internal { 33 | 34 | struct SftpHandleResponse { 35 | quint32 requestId; 36 | QByteArray handle; 37 | }; 38 | 39 | struct SftpStatusResponse { 40 | quint32 requestId; 41 | SftpStatusCode status; 42 | QString errorString; 43 | QByteArray language; 44 | }; 45 | 46 | struct SftpFileAttributes { 47 | bool sizePresent; 48 | bool timesPresent; 49 | bool uidAndGidPresent; 50 | bool permissionsPresent; 51 | quint64 size; 52 | quint32 uid; 53 | quint32 gid; 54 | quint32 permissions; 55 | quint32 atime; 56 | quint32 mtime; 57 | }; 58 | 59 | struct SftpFile { 60 | QString fileName; 61 | QString longName; // Not present in later RFCs, so we don't expose this to the user. 62 | SftpFileAttributes attributes; 63 | }; 64 | 65 | struct SftpNameResponse { 66 | quint32 requestId; 67 | QList files; 68 | }; 69 | 70 | struct SftpDataResponse { 71 | quint32 requestId; 72 | QByteArray data; 73 | }; 74 | 75 | struct SftpAttrsResponse { 76 | quint32 requestId; 77 | SftpFileAttributes attrs; 78 | }; 79 | 80 | class SftpIncomingPacket : public AbstractSftpPacket 81 | { 82 | public: 83 | SftpIncomingPacket(); 84 | 85 | void consumeData(QByteArray &data); 86 | void clear(); 87 | bool isComplete() const; 88 | quint32 extractServerVersion() const; 89 | SftpHandleResponse asHandleResponse() const; 90 | SftpStatusResponse asStatusResponse() const; 91 | SftpNameResponse asNameResponse() const; 92 | SftpDataResponse asDataResponse() const; 93 | SftpAttrsResponse asAttrsResponse() const; 94 | 95 | private: 96 | void moveFirstBytes(QByteArray &target, QByteArray &source, int n); 97 | 98 | SftpFileAttributes asFileAttributes(quint32 &offset) const; 99 | SftpFile asFile(quint32 &offset) const; 100 | 101 | quint32 m_length; 102 | }; 103 | 104 | } // namespace Internal 105 | } // namespace QSsh 106 | 107 | #endif // SFTPINCOMINGPACKET_P_H 108 | -------------------------------------------------------------------------------- /src/sftpoutgoingpacket_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPOUTGOINGPACKET_P_H 27 | #define SFTPOUTGOINGPACKET_P_H 28 | 29 | #include "sftppacket_p.h" 30 | #include "sftpdefs.h" 31 | 32 | namespace QSsh { 33 | namespace Internal { 34 | 35 | class SftpOutgoingPacket : public AbstractSftpPacket 36 | { 37 | public: 38 | SftpOutgoingPacket(); 39 | SftpOutgoingPacket &generateInit(quint32 version); 40 | SftpOutgoingPacket &generateStat(const QString &path, quint32 requestId); 41 | SftpOutgoingPacket &generateOpenDir(const QString &path, quint32 requestId); 42 | SftpOutgoingPacket &generateReadDir(const QByteArray &handle, 43 | quint32 requestId); 44 | SftpOutgoingPacket &generateCloseHandle(const QByteArray &handle, 45 | quint32 requestId); 46 | SftpOutgoingPacket &generateMkDir(const QString &path, quint32 requestId); 47 | SftpOutgoingPacket &generateRmDir(const QString &path, quint32 requestId); 48 | SftpOutgoingPacket &generateRm(const QString &path, quint32 requestId); 49 | SftpOutgoingPacket &generateRename(const QString &oldPath, 50 | const QString &newPath, quint32 requestId); 51 | SftpOutgoingPacket &generateOpenFileForWriting(const QString &path, 52 | SftpOverwriteMode mode, quint32 permissions, quint32 requestId); 53 | SftpOutgoingPacket &generateOpenFileForReading(const QString &path, 54 | quint32 requestId); 55 | SftpOutgoingPacket &generateReadFile(const QByteArray &handle, 56 | quint64 offset, quint32 length, quint32 requestId); 57 | SftpOutgoingPacket &generateFstat(const QByteArray &handle, 58 | quint32 requestId); 59 | SftpOutgoingPacket &generateWriteFile(const QByteArray &handle, 60 | quint64 offset, const QByteArray &data, quint32 requestId); 61 | 62 | // Note: OpenSSH's SFTP server has a bug that reverses the filePath and target 63 | // arguments, so this operation is not portable. 64 | SftpOutgoingPacket &generateCreateLink(const QString &filePath, const QString &target, 65 | quint32 requestId); 66 | 67 | static const quint32 DefaultPermissions; 68 | 69 | private: 70 | static QByteArray encodeString(const QString &string); 71 | 72 | enum OpenType { Read, Write }; 73 | SftpOutgoingPacket &generateOpenFile(const QString &path, OpenType openType, 74 | SftpOverwriteMode mode, const QList &attributes, quint32 requestId); 75 | 76 | SftpOutgoingPacket &init(SftpPacketType type, quint32 requestId); 77 | SftpOutgoingPacket &appendInt(quint32 value); 78 | SftpOutgoingPacket &appendInt64(quint64 value); 79 | SftpOutgoingPacket &appendString(const QString &string); 80 | SftpOutgoingPacket &appendString(const QByteArray &string); 81 | SftpOutgoingPacket &finalize(); 82 | }; 83 | 84 | } // namespace Internal 85 | } // namespace QSsh 86 | 87 | #endif // SFTPOUTGOINGPACKET_P_H 88 | -------------------------------------------------------------------------------- /src/sftppacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sftppacket_p.h" 27 | 28 | #include "sshpacketparser_p.h" 29 | 30 | namespace QSsh { 31 | namespace Internal { 32 | 33 | const quint32 AbstractSftpPacket::MaxDataSize = 32000; 34 | const quint32 AbstractSftpPacket::MaxPacketSize = 34000; 35 | const int AbstractSftpPacket::TypeOffset = 4; 36 | const int AbstractSftpPacket::RequestIdOffset = TypeOffset + 1; 37 | const int AbstractSftpPacket::PayloadOffset = RequestIdOffset + 4; 38 | 39 | AbstractSftpPacket::AbstractSftpPacket() 40 | { 41 | } 42 | 43 | quint32 AbstractSftpPacket::requestId() const 44 | { 45 | return SshPacketParser::asUint32(m_data, RequestIdOffset); 46 | } 47 | 48 | } // namespace Internal 49 | } // namespace QSsh 50 | -------------------------------------------------------------------------------- /src/sftppacket_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SFTPPACKET_P_H 27 | #define SFTPPACKET_P_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace QSsh { 34 | namespace Internal { 35 | 36 | enum SftpPacketType { 37 | SSH_FXP_INIT = 1, 38 | SSH_FXP_VERSION = 2, 39 | SSH_FXP_OPEN = 3, 40 | SSH_FXP_CLOSE = 4, 41 | SSH_FXP_READ = 5, 42 | SSH_FXP_WRITE = 6, 43 | SSH_FXP_LSTAT = 7, 44 | SSH_FXP_FSTAT = 8, 45 | SSH_FXP_SETSTAT = 9, 46 | SSH_FXP_FSETSTAT = 10, 47 | SSH_FXP_OPENDIR = 11, 48 | SSH_FXP_READDIR = 12, 49 | SSH_FXP_REMOVE = 13, 50 | SSH_FXP_MKDIR = 14, 51 | SSH_FXP_RMDIR = 15, 52 | SSH_FXP_REALPATH = 16, 53 | SSH_FXP_STAT = 17, 54 | SSH_FXP_RENAME = 18, 55 | SSH_FXP_READLINK = 19, 56 | SSH_FXP_SYMLINK = 20, // Removed from later protocol versions. Try not to use. 57 | 58 | SSH_FXP_STATUS = 101, 59 | SSH_FXP_HANDLE = 102, 60 | SSH_FXP_DATA = 103, 61 | SSH_FXP_NAME = 104, 62 | SSH_FXP_ATTRS = 105, 63 | 64 | SSH_FXP_EXTENDED = 200, 65 | SSH_FXP_EXTENDED_REPLY = 201 66 | }; 67 | 68 | enum SftpStatusCode { 69 | SSH_FX_OK = 0, 70 | SSH_FX_EOF = 1, 71 | SSH_FX_NO_SUCH_FILE = 2, 72 | SSH_FX_PERMISSION_DENIED = 3, 73 | SSH_FX_FAILURE = 4, 74 | SSH_FX_BAD_MESSAGE = 5, 75 | SSH_FX_NO_CONNECTION = 6, 76 | SSH_FX_CONNECTION_LOST = 7, 77 | SSH_FX_OP_UNSUPPORTED = 8 78 | }; 79 | 80 | enum SftpAttributeType { 81 | SSH_FILEXFER_ATTR_SIZE = 0x00000001, 82 | SSH_FILEXFER_ATTR_UIDGID = 0x00000002, 83 | SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004, 84 | SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008, 85 | SSH_FILEXFER_ATTR_EXTENDED = 0x80000000 86 | }; 87 | 88 | class AbstractSftpPacket 89 | { 90 | public: 91 | AbstractSftpPacket(); 92 | quint32 requestId() const; 93 | const QByteArray &rawData() const { return m_data; } 94 | SftpPacketType type() const { return static_cast(m_data.at(TypeOffset)); } 95 | 96 | static const quint32 MaxDataSize; // "Pure" data size per read/writepacket. 97 | static const quint32 MaxPacketSize; 98 | 99 | protected: 100 | quint32 dataSize() const { return static_cast(m_data.size()); } 101 | 102 | static const int TypeOffset; 103 | static const int RequestIdOffset; 104 | static const int PayloadOffset; 105 | 106 | QByteArray m_data; 107 | }; 108 | 109 | } // namespace Internal 110 | } // namespace QSsh 111 | 112 | #endif // SFTPPACKET_P_H 113 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | QT += core gui network 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | QSSH_ROOT = $${PWD}/.. 6 | DESTDIR = $${QSSH_ROOT}/lib 7 | 8 | TEMPLATE = lib 9 | DEFINES += QSSH_LIBRARY 10 | 11 | TARGET = $$qtLibraryTarget(QSsh) 12 | 13 | CONFIG += c++11 14 | 15 | include ($${PWD}/ssh.pri) 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/ssh.pri: -------------------------------------------------------------------------------- 1 | SOURCES = $$PWD/*.cpp 2 | # $$PWD/sshsendfacility.cpp \ 3 | # $$PWD/sshremoteprocess.cpp \ 4 | # $$PWD/sshpacketparser.cpp \ 5 | # $$PWD/sshpacket.cpp \ 6 | # $$PWD/sshoutgoingpacket.cpp \ 7 | # $$PWD/sshkeygenerator.cpp \ 8 | # $$PWD/sshkeyexchange.cpp \ 9 | # $$PWD/sshincomingpacket.cpp \ 10 | # $$PWD/sshcryptofacility.cpp \ 11 | # $$PWD/sshconnection.cpp \ 12 | # $$PWD/sshchannelmanager.cpp \ 13 | # $$PWD/sshchannel.cpp \ 14 | # $$PWD/sshcapabilities.cpp \ 15 | # $$PWD/sftppacket.cpp \ 16 | # $$PWD/sftpoutgoingpacket.cpp \ 17 | # $$PWD/sftpoperation.cpp \ 18 | # $$PWD/sftpincomingpacket.cpp \ 19 | # $$PWD/sftpdefs.cpp \ 20 | # $$PWD/sftpchannel.cpp \ 21 | # $$PWD/sshremoteprocessrunner.cpp \ 22 | # $$PWD/sshconnectionmanager.cpp \ 23 | # $$PWD/sshkeypasswordretriever.cpp \ 24 | # $$PWD/sftpfilesystemmodel.cpp \ 25 | # $$PWD/sshkeycreationdialog.cpp \ 26 | # $$PWD/sshinit.cpp \ 27 | # $$PWD/sshdirecttcpiptunnel.cpp 28 | 29 | HEADERS = $$PWD/*.h 30 | # $$PWD/sshsendfacility_p.h \ 31 | # $$PWD/sshremoteprocess.h \ 32 | # $$PWD/sshremoteprocess_p.h \ 33 | # $$PWD/sshpacketparser_p.h \ 34 | # $$PWD/sshpacket_p.h \ 35 | # $$PWD/sshoutgoingpacket_p.h \ 36 | # $$PWD/sshkeygenerator.h \ 37 | # $$PWD/sshkeyexchange_p.h \ 38 | # $$PWD/sshincomingpacket_p.h \ 39 | # $$PWD/sshexception_p.h \ 40 | # $$PWD/ssherrors.h \ 41 | # $$PWD/sshcryptofacility_p.h \ 42 | # $$PWD/sshconnection.h \ 43 | # $$PWD/sshconnection_p.h \ 44 | # $$PWD/sshchannelmanager_p.h \ 45 | # $$PWD/sshchannel_p.h \ 46 | # $$PWD/sshcapabilities_p.h \ 47 | # $$PWD/sshbotanconversions_p.h \ 48 | # $$PWD/sftppacket_p.h \ 49 | # $$PWD/sftpoutgoingpacket_p.h \ 50 | # $$PWD/sftpoperation_p.h \ 51 | # $$PWD/sftpincomingpacket_p.h \ 52 | # $$PWD/sftpdefs.h \ 53 | # $$PWD/sftpchannel.h \ 54 | # $$PWD/sftpchannel_p.h \ 55 | # $$PWD/sshremoteprocessrunner.h \ 56 | # $$PWD/sshconnectionmanager.h \ 57 | # $$PWD/sshpseudoterminal.h \ 58 | # $$PWD/sshkeypasswordretriever_p.h \ 59 | # $$PWD/sftpfilesystemmodel.h \ 60 | # $$PWD/sshkeycreationdialog.h \ 61 | # $$PWD/ssh_global.h \ 62 | # $$PWD/sshdirecttcpiptunnel_p.h \ 63 | # $$PWD/sshinit_p.h \ 64 | # $$PWD/sshdirecttcpiptunnel.h 65 | 66 | FORMS = $$PWD/sshkeycreationdialog.ui 67 | 68 | include($$PWD/3rdparty/botan/botan.pri) 69 | -------------------------------------------------------------------------------- /src/ssh_global.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSH_GLOBAL_H 27 | #define SSH_GLOBAL_H 28 | 29 | #include 30 | 31 | #if defined(QSSH_LIBRARY) 32 | # define QSSH_EXPORT Q_DECL_EXPORT 33 | #else 34 | # define QSSH_EXPORT Q_DECL_IMPORT 35 | #endif 36 | 37 | #define QSSH_PRINT_WARNING qWarning("Soft assert at %s:%d", __FILE__, __LINE__) 38 | #define QSSH_ASSERT(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; } } while (false) 39 | #define QSSH_ASSERT_AND_RETURN(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; return; } } while (false) 40 | #define QSSH_ASSERT_AND_RETURN_VALUE(cond, value) do { if (!(cond)) { QSSH_PRINT_WARNING; return value; } } while (false) 41 | 42 | #endif // SSH_GLOBAL_H 43 | -------------------------------------------------------------------------------- /src/sshcapabilities_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef CAPABILITIES_P_H 27 | #define CAPABILITIES_P_H 28 | 29 | #include 30 | #include 31 | 32 | namespace QSsh { 33 | namespace Internal { 34 | 35 | class SshCapabilities 36 | { 37 | public: 38 | static const QByteArray DiffieHellmanGroup1Sha1; 39 | static const QByteArray DiffieHellmanGroup14Sha1; 40 | static const QByteArray EcdhKexNamePrefix; 41 | static const QByteArray EcdhNistp256; 42 | static const QByteArray EcdhNistp384; 43 | static const QByteArray EcdhNistp521; // sic 44 | static const QList KeyExchangeMethods; 45 | 46 | static const QByteArray PubKeyDss; 47 | static const QByteArray PubKeyRsa; 48 | static const QByteArray PubKeyEcdsaPrefix; 49 | static const QByteArray PubKeyEcdsa256; 50 | static const QByteArray PubKeyEcdsa384; 51 | static const QByteArray PubKeyEcdsa521; 52 | static const QList PublicKeyAlgorithms; 53 | 54 | static const QByteArray CryptAlgo3DesCbc; 55 | static const QByteArray CryptAlgo3DesCtr; 56 | static const QByteArray CryptAlgoAes128Cbc; 57 | static const QByteArray CryptAlgoAes128Ctr; 58 | static const QByteArray CryptAlgoAes192Ctr; 59 | static const QByteArray CryptAlgoAes256Ctr; 60 | static const QList EncryptionAlgorithms; 61 | 62 | static const QByteArray HMacSha1; 63 | static const QByteArray HMacSha196; 64 | static const QByteArray HMacSha256; 65 | static const QByteArray HMacSha384; 66 | static const QByteArray HMacSha512; 67 | static const QList MacAlgorithms; 68 | 69 | static const QList CompressionAlgorithms; 70 | 71 | static const QByteArray SshConnectionService; 72 | 73 | static QList commonCapabilities(const QList &myCapabilities, 74 | const QList &serverCapabilities); 75 | static QByteArray findBestMatch(const QList &myCapabilities, 76 | const QList &serverCapabilities); 77 | 78 | static int ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo); 79 | static QByteArray ecdsaPubKeyAlgoForKeyWidth(int keyWidthInBytes); 80 | static const char *oid(const QByteArray &ecdsaAlgo); 81 | }; 82 | 83 | } // namespace Internal 84 | } // namespace QSsh 85 | 86 | #endif // CAPABILITIES_P_H 87 | -------------------------------------------------------------------------------- /src/sshchannel_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCHANNEL_P_H 27 | #define SSHCHANNEL_P_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace QSsh { 35 | namespace Internal { 36 | 37 | struct SshChannelExitSignal; 38 | struct SshChannelExitStatus; 39 | class SshIncomingPacket; 40 | class SshSendFacility; 41 | 42 | class AbstractSshChannel : public QObject 43 | { 44 | Q_OBJECT 45 | public: 46 | enum ChannelState { 47 | Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed 48 | }; 49 | 50 | quint32 localChannelId() const { return m_localChannel; } 51 | quint32 remoteChannel() const { return m_remoteChannel; } 52 | 53 | virtual void handleChannelSuccess() = 0; 54 | virtual void handleChannelFailure() = 0; 55 | 56 | void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize, 57 | quint32 remoteMaxPacketSize); 58 | void handleOpenFailure(const QString &reason); 59 | void handleWindowAdjust(quint32 bytesToAdd); 60 | void handleChannelEof(); 61 | void handleChannelClose(); 62 | void handleChannelData(const QByteArray &data); 63 | void handleChannelExtendedData(quint32 type, const QByteArray &data); 64 | void handleChannelRequest(const SshIncomingPacket &packet); 65 | 66 | void closeChannel(); 67 | 68 | virtual ~AbstractSshChannel(); 69 | 70 | static const int ReplyTimeout = 10000; // milli seconds 71 | ChannelState channelState() const { return m_state; } 72 | 73 | signals: 74 | void timeout(); 75 | void eof(); 76 | 77 | protected: 78 | AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility); 79 | 80 | void setChannelState(ChannelState state); 81 | 82 | void requestSessionStart(); 83 | void sendData(const QByteArray &data); 84 | 85 | static quint32 initialWindowSize(); 86 | static quint32 maxPacketSize(); 87 | 88 | quint32 maxDataSize() const; 89 | void checkChannelActive(); 90 | 91 | SshSendFacility &m_sendFacility; 92 | QTimer m_timeoutTimer; 93 | 94 | private: 95 | virtual void handleOpenSuccessInternal() = 0; 96 | virtual void handleOpenFailureInternal(const QString &reason) = 0; 97 | virtual void handleChannelDataInternal(const QByteArray &data) = 0; 98 | virtual void handleChannelExtendedDataInternal(quint32 type, 99 | const QByteArray &data) = 0; 100 | virtual void handleExitStatus(const SshChannelExitStatus &exitStatus) = 0; 101 | virtual void handleExitSignal(const SshChannelExitSignal &signal) = 0; 102 | 103 | virtual void closeHook() = 0; 104 | 105 | void flushSendBuffer(); 106 | int handleChannelOrExtendedChannelData(const QByteArray &data); 107 | 108 | const quint32 m_localChannel; 109 | quint32 m_remoteChannel; 110 | quint32 m_localWindowSize; 111 | quint32 m_remoteWindowSize; 112 | quint32 m_remoteMaxPacketSize; 113 | ChannelState m_state; 114 | QByteArray m_sendBuffer; 115 | }; 116 | 117 | } // namespace Internal 118 | } // namespace QSsh 119 | 120 | #endif // SSHCHANNEL_P_H 121 | -------------------------------------------------------------------------------- /src/sshchannelmanager_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCHANNELMANAGER_P_H 27 | #define SSHCHANNELMANAGER_P_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace QSsh { 34 | class SftpChannel; 35 | class SshDirectTcpIpTunnel; 36 | class SshRemoteProcess; 37 | 38 | namespace Internal { 39 | 40 | class AbstractSshChannel; 41 | class SshIncomingPacket; 42 | class SshSendFacility; 43 | 44 | class SshChannelManager : public QObject 45 | { 46 | Q_OBJECT 47 | public: 48 | SshChannelManager(SshSendFacility &sendFacility, QObject *parent); 49 | 50 | QSharedPointer createRemoteProcess(const QByteArray &command); 51 | QSharedPointer createRemoteShell(); 52 | QSharedPointer createSftpChannel(); 53 | QSharedPointer createTunnel(const QString &originatingHost, 54 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort); 55 | 56 | int channelCount() const; 57 | enum CloseAllMode { CloseAllRegular, CloseAllAndReset }; 58 | int closeAllChannels(CloseAllMode mode); 59 | 60 | void handleChannelRequest(const SshIncomingPacket &packet); 61 | void handleChannelOpen(const SshIncomingPacket &packet); 62 | void handleChannelOpenFailure(const SshIncomingPacket &packet); 63 | void handleChannelOpenConfirmation(const SshIncomingPacket &packet); 64 | void handleChannelSuccess(const SshIncomingPacket &packet); 65 | void handleChannelFailure(const SshIncomingPacket &packet); 66 | void handleChannelWindowAdjust(const SshIncomingPacket &packet); 67 | void handleChannelData(const SshIncomingPacket &packet); 68 | void handleChannelExtendedData(const SshIncomingPacket &packet); 69 | void handleChannelEof(const SshIncomingPacket &packet); 70 | void handleChannelClose(const SshIncomingPacket &packet); 71 | 72 | signals: 73 | void timeout(); 74 | 75 | private: 76 | typedef QHash::Iterator ChannelIterator; 77 | 78 | ChannelIterator lookupChannelAsIterator(quint32 channelId, 79 | bool allowNotFound = false); 80 | AbstractSshChannel *lookupChannel(quint32 channelId, 81 | bool allowNotFound = false); 82 | void removeChannel(ChannelIterator it); 83 | void insertChannel(AbstractSshChannel *priv, 84 | const QSharedPointer &pub); 85 | 86 | SshSendFacility &m_sendFacility; 87 | QHash m_channels; 88 | QHash > m_sessions; 89 | quint32 m_nextLocalChannelId; 90 | }; 91 | 92 | } // namespace Internal 93 | } // namespace QSsh 94 | 95 | #endif // SSHCHANNELMANAGER_P_H 96 | -------------------------------------------------------------------------------- /src/sshconnection.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCONNECTION_H 27 | #define SSHCONNECTION_H 28 | 29 | #include "ssherrors.h" 30 | #include "sshhostkeydatabase.h" 31 | 32 | #include "ssh_global.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace QSsh { 42 | class SftpChannel; 43 | class SshDirectTcpIpTunnel; 44 | class SshRemoteProcess; 45 | 46 | namespace Internal { class SshConnectionPrivate; } 47 | 48 | enum SshConnectionOption { 49 | SshIgnoreDefaultProxy = 0x1, 50 | SshEnableStrictConformanceChecks = 0x2 51 | }; 52 | 53 | Q_DECLARE_FLAGS(SshConnectionOptions, SshConnectionOption) 54 | 55 | enum SshHostKeyCheckingMode { 56 | SshHostKeyCheckingNone, 57 | SshHostKeyCheckingStrict, 58 | SshHostKeyCheckingAllowNoMatch, 59 | SshHostKeyCheckingAllowMismatch 60 | }; 61 | 62 | class QSSH_EXPORT SshConnectionParameters 63 | { 64 | public: 65 | enum AuthenticationType { 66 | AuthenticationTypePassword, 67 | AuthenticationTypePublicKey, 68 | AuthenticationTypeKeyboardInteractive, 69 | 70 | // Some servers disable "password", others disable "keyboard-interactive". 71 | AuthenticationTypeTryAllPasswordBasedMethods 72 | }; 73 | 74 | SshConnectionParameters(); 75 | 76 | QString host; 77 | QString userName; 78 | QString password; 79 | QString privateKeyFile; 80 | int timeout; // In seconds. 81 | AuthenticationType authenticationType; 82 | quint16 port; 83 | SshConnectionOptions options; 84 | SshHostKeyCheckingMode hostKeyCheckingMode; 85 | SshHostKeyDatabasePtr hostKeyDatabase; 86 | }; 87 | 88 | QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2); 89 | QSSH_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2); 90 | 91 | class QSSH_EXPORT SshConnectionInfo 92 | { 93 | public: 94 | SshConnectionInfo() : localPort(0), peerPort(0) {} 95 | SshConnectionInfo(const QHostAddress &la, quint16 lp, const QHostAddress &pa, quint16 pp) 96 | : localAddress(la), localPort(lp), peerAddress(pa), peerPort(pp) {} 97 | 98 | QHostAddress localAddress; 99 | quint16 localPort; 100 | QHostAddress peerAddress; 101 | quint16 peerPort; 102 | }; 103 | 104 | class QSSH_EXPORT SshConnection : public QObject 105 | { 106 | Q_OBJECT 107 | 108 | public: 109 | enum State { Unconnected, Connecting, Connected }; 110 | 111 | explicit SshConnection(const SshConnectionParameters &serverInfo, QObject *parent = 0); 112 | 113 | void connectToHost(); 114 | void disconnectFromHost(); 115 | State state() const; 116 | SshError errorState() const; 117 | QString errorString() const; 118 | SshConnectionParameters connectionParameters() const; 119 | SshConnectionInfo connectionInfo() const; 120 | ~SshConnection(); 121 | 122 | QSharedPointer createRemoteProcess(const QByteArray &command); 123 | QSharedPointer createRemoteShell(); 124 | QSharedPointer createSftpChannel(); 125 | QSharedPointer createTunnel(const QString &originatingHost, 126 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort); 127 | 128 | // -1 if an error occurred, number of channels closed otherwise. 129 | int closeAllChannels(); 130 | 131 | int channelCount() const; 132 | 133 | signals: 134 | void connected(); 135 | void disconnected(); 136 | void dataAvailable(const QString &message); 137 | void error(QSsh::SshError); 138 | 139 | private: 140 | Internal::SshConnectionPrivate *d; 141 | }; 142 | 143 | } // namespace QSsh 144 | 145 | #endif // SSHCONNECTION_H 146 | -------------------------------------------------------------------------------- /src/sshconnectionmanager.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHCONNECTIONMANAGER_H 27 | #define SSHCONNECTIONMANAGER_H 28 | 29 | #include "ssh_global.h" 30 | 31 | namespace QSsh { 32 | 33 | class SshConnection; 34 | class SshConnectionParameters; 35 | 36 | QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams); 37 | QSSH_EXPORT void releaseConnection(SshConnection *connection); 38 | 39 | // Make sure the next acquireConnection with the given parameters will return a new connection. 40 | QSSH_EXPORT void forceNewConnection(const SshConnectionParameters &sshParams); 41 | 42 | } // namespace QSsh 43 | 44 | #endif // SSHCONNECTIONMANAGER_H 45 | -------------------------------------------------------------------------------- /src/sshdirecttcpiptunnel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHDIRECTTCPIPTUNNEL_H 27 | #define SSHDIRECTTCPIPTUNNEL_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace QSsh { 35 | 36 | namespace Internal { 37 | class SshChannelManager; 38 | class SshDirectTcpIpTunnelPrivate; 39 | class SshSendFacility; 40 | } // namespace Internal 41 | 42 | class QSSH_EXPORT SshDirectTcpIpTunnel : public QIODevice 43 | { 44 | Q_OBJECT 45 | 46 | friend class Internal::SshChannelManager; 47 | 48 | public: 49 | typedef QSharedPointer Ptr; 50 | 51 | ~SshDirectTcpIpTunnel(); 52 | 53 | // QIODevice stuff 54 | bool atEnd() const; 55 | qint64 bytesAvailable() const; 56 | bool canReadLine() const; 57 | void close(); 58 | bool isSequential() const { return true; } 59 | 60 | void initialize(); 61 | 62 | signals: 63 | void initialized(); 64 | void error(const QString &reason); 65 | void tunnelClosed(); 66 | 67 | private: 68 | SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost, 69 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 70 | Internal::SshSendFacility &sendFacility); 71 | 72 | // QIODevice stuff 73 | qint64 readData(char *data, qint64 maxlen); 74 | qint64 writeData(const char *data, qint64 len); 75 | 76 | Q_SLOT void handleError(const QString &reason); 77 | 78 | Internal::SshDirectTcpIpTunnelPrivate * const d; 79 | }; 80 | 81 | } // namespace QSsh 82 | 83 | #endif // SSHDIRECTTCPIPTUNNEL_H 84 | -------------------------------------------------------------------------------- /src/sshdirecttcpiptunnel_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHDIRECTTCPIPTUNNEL_P_H 27 | #define SSHDIRECTTCPIPTUNNEL_P_H 28 | 29 | #include "sshchannel_p.h" 30 | 31 | namespace QSsh { 32 | class SshDirectTcpIpTunnel; 33 | 34 | namespace Internal { 35 | 36 | class SshDirectTcpIpTunnelPrivate : public AbstractSshChannel 37 | { 38 | Q_OBJECT 39 | 40 | friend class QSsh::SshDirectTcpIpTunnel; 41 | 42 | public: 43 | explicit SshDirectTcpIpTunnelPrivate(quint32 channelId, const QString &originatingHost, 44 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 45 | SshSendFacility &sendFacility); 46 | 47 | signals: 48 | void initialized(); 49 | void readyRead(); 50 | void error(const QString &reason); 51 | void closed(); 52 | 53 | private slots: 54 | void handleEof(); 55 | 56 | private: 57 | void handleChannelSuccess(); 58 | void handleChannelFailure(); 59 | 60 | void handleOpenSuccessInternal(); 61 | void handleOpenFailureInternal(const QString &reason); 62 | void handleChannelDataInternal(const QByteArray &data); 63 | void handleChannelExtendedDataInternal(quint32 type, const QByteArray &data); 64 | void handleExitStatus(const SshChannelExitStatus &exitStatus); 65 | void handleExitSignal(const SshChannelExitSignal &signal); 66 | 67 | void closeHook(); 68 | 69 | const QString m_originatingHost; 70 | const quint16 m_originatingPort; 71 | const QString m_remoteHost; 72 | const quint16 m_remotePort; 73 | QByteArray m_data; 74 | }; 75 | 76 | } // namespace Internal 77 | } // namespace QSsh 78 | 79 | #endif // SSHDIRECTTCPIPTUNNEL_P_H 80 | -------------------------------------------------------------------------------- /src/ssherrors.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHERRORS_P_H 27 | #define SSHERRORS_P_H 28 | 29 | namespace QSsh { 30 | 31 | enum SshError { 32 | SshNoError, SshSocketError, SshTimeoutError, SshProtocolError, 33 | SshHostKeyError, SshKeyFileError, SshAuthenticationError, 34 | SshClosedByServerError, SshInternalError 35 | }; 36 | 37 | } // namespace QSsh 38 | 39 | #endif // SSHERRORS_P_H 40 | -------------------------------------------------------------------------------- /src/sshexception_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHEXCEPTION_P_H 27 | #define SSHEXCEPTION_P_H 28 | 29 | #include "ssherrors.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace QSsh { 36 | namespace Internal { 37 | 38 | enum SshErrorCode { 39 | SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1, 40 | SSH_DISCONNECT_PROTOCOL_ERROR = 2, 41 | SSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3, 42 | SSH_DISCONNECT_RESERVED = 4, 43 | SSH_DISCONNECT_MAC_ERROR = 5, 44 | SSH_DISCONNECT_COMPRESSION_ERROR = 6, 45 | SSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7, 46 | SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8, 47 | SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9, 48 | SSH_DISCONNECT_CONNECTION_LOST = 10, 49 | SSH_DISCONNECT_BY_APPLICATION = 11, 50 | SSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12, 51 | SSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13, 52 | SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14, 53 | SSH_DISCONNECT_ILLEGAL_USER_NAME = 15 54 | }; 55 | 56 | #define SSH_TR(string) QCoreApplication::translate("SshConnection", string) 57 | 58 | #define SSH_SERVER_EXCEPTION(error, errorString) \ 59 | SshServerException((error), (errorString), SSH_TR(errorString)) 60 | 61 | struct SshServerException 62 | { 63 | SshServerException(SshErrorCode error, const QByteArray &errorStringServer, 64 | const QString &errorStringUser) 65 | : error(error), errorStringServer(errorStringServer), 66 | errorStringUser(errorStringUser) {} 67 | 68 | const SshErrorCode error; 69 | const QByteArray errorStringServer; 70 | const QString errorStringUser; 71 | }; 72 | 73 | struct SshClientException 74 | { 75 | SshClientException(SshError error, const QString &errorString) 76 | : error(error), errorString(errorString) {} 77 | 78 | const SshError error; 79 | const QString errorString; 80 | }; 81 | 82 | } // namespace Internal 83 | } // namespace QSsh 84 | 85 | #endif // SSHEXCEPTION_P_H 86 | -------------------------------------------------------------------------------- /src/sshhostkeydatabase.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sshhostkeydatabase.h" 27 | 28 | #include "sshlogging_p.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace QSsh { 38 | 39 | class SshHostKeyDatabase::SshHostKeyDatabasePrivate 40 | { 41 | public: 42 | QHash hostKeys; 43 | }; 44 | 45 | SshHostKeyDatabase::SshHostKeyDatabase() : d(new SshHostKeyDatabasePrivate) 46 | { 47 | } 48 | 49 | SshHostKeyDatabase::~SshHostKeyDatabase() 50 | { 51 | delete d; 52 | } 53 | 54 | bool SshHostKeyDatabase::load(const QString &filePath, QString *error) 55 | { 56 | QFile file(filePath); 57 | if (!file.open(QIODevice::ReadOnly)) { 58 | if (error) { 59 | *error = QCoreApplication::translate("QSsh::Ssh", 60 | "Failed to open key file \"%1\" for reading: %2") 61 | .arg(QDir::toNativeSeparators(filePath), file.errorString()); 62 | } 63 | return false; 64 | } 65 | 66 | d->hostKeys.clear(); 67 | const QByteArray content = file.readAll().trimmed(); 68 | if (content.isEmpty()) 69 | return true; 70 | foreach (const QByteArray &line, content.split('\n')) { 71 | const QList &lineData = line.trimmed().split(' '); 72 | if (lineData.count() != 2) { 73 | qCDebug(Internal::sshLog, "Unexpected line \"%s\" in file \"%s\".", line.constData(), 74 | qPrintable(filePath)); 75 | continue; 76 | } 77 | d->hostKeys.insert(QString::fromUtf8(lineData.first()), 78 | QByteArray::fromHex(lineData.last())); 79 | } 80 | 81 | return true; 82 | } 83 | 84 | bool SshHostKeyDatabase::store(const QString &filePath, QString *error) const 85 | { 86 | QFile file(filePath); 87 | if (!file.open(QIODevice::WriteOnly)) { 88 | if (error) { 89 | *error = QCoreApplication::translate("QSsh::Ssh", 90 | "Failed to open key file \"%1\" for writing: %2") 91 | .arg(QDir::toNativeSeparators(filePath), file.errorString()); 92 | } 93 | return false; 94 | } 95 | 96 | file.resize(0); 97 | for (auto it = d->hostKeys.constBegin(); it != d->hostKeys.constEnd(); ++it) 98 | file.write(it.key().toUtf8() + ' ' + it.value().toHex() + '\n'); 99 | return true; 100 | } 101 | 102 | SshHostKeyDatabase::KeyLookupResult SshHostKeyDatabase::matchHostKey(const QString &hostName, 103 | const QByteArray &key) const 104 | { 105 | auto it = d->hostKeys.constFind(hostName); 106 | if (it == d->hostKeys.constEnd()) 107 | return KeyLookupNoMatch; 108 | if (it.value() == key) 109 | return KeyLookupMatch; 110 | return KeyLookupMismatch; 111 | } 112 | 113 | void SshHostKeyDatabase::insertHostKey(const QString &hostName, const QByteArray &key) 114 | { 115 | d->hostKeys.insert(hostName, key); 116 | } 117 | 118 | } // namespace QSsh 119 | -------------------------------------------------------------------------------- /src/sshhostkeydatabase.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHHOSTKEYDATABASE_H 27 | #define SSHHOSTKEYDATABASE_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | class QByteArray; 35 | class QString; 36 | QT_END_NAMESPACE 37 | 38 | namespace QSsh { 39 | class SshHostKeyDatabase; 40 | typedef QSharedPointer SshHostKeyDatabasePtr; 41 | 42 | class QSSH_EXPORT SshHostKeyDatabase 43 | { 44 | friend class QSharedPointer; // To give create() access to our constructor. 45 | 46 | public: 47 | enum KeyLookupResult { 48 | KeyLookupMatch, 49 | KeyLookupNoMatch, 50 | KeyLookupMismatch 51 | }; 52 | 53 | ~SshHostKeyDatabase(); 54 | 55 | bool load(const QString &filePath, QString *error = 0); 56 | bool store(const QString &filePath, QString *error = 0) const; 57 | KeyLookupResult matchHostKey(const QString &hostName, const QByteArray &key) const; 58 | void insertHostKey(const QString &hostName, const QByteArray &key); 59 | 60 | private: 61 | SshHostKeyDatabase(); 62 | 63 | class SshHostKeyDatabasePrivate; 64 | SshHostKeyDatabasePrivate * const d; 65 | }; 66 | 67 | } // namespace QSsh 68 | 69 | #endif // Include guard. 70 | -------------------------------------------------------------------------------- /src/sshinit.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sshinit_p.h" 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace QSsh { 34 | namespace Internal { 35 | 36 | static bool initialized = false; 37 | static QMutex initMutex; 38 | 39 | void initSsh() 40 | { 41 | QMutexLocker locker(&initMutex); 42 | if (!initialized) { 43 | Botan::LibraryInitializer::initialize("thread_safe=true"); 44 | initialized = true; 45 | } 46 | } 47 | 48 | } // namespace Internal 49 | } // namespace QSsh 50 | -------------------------------------------------------------------------------- /src/sshinit_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | namespace QSsh { 27 | namespace Internal { 28 | 29 | void initSsh(); 30 | 31 | } // namespace Internal 32 | } // namespace QSsh 33 | -------------------------------------------------------------------------------- /src/sshkeycreationdialog.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHKEYCREATIONDIALOG_H 27 | #define SSHKEYCREATIONDIALOG_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | 33 | namespace QSsh { 34 | class SshKeyGenerator; 35 | 36 | namespace Ui { class SshKeyCreationDialog; } 37 | 38 | class QSSH_EXPORT SshKeyCreationDialog : public QDialog 39 | { 40 | Q_OBJECT 41 | public: 42 | SshKeyCreationDialog(QWidget *parent = 0); 43 | ~SshKeyCreationDialog(); 44 | 45 | QString privateKeyFilePath() const; 46 | QString publicKeyFilePath() const; 47 | 48 | private slots: 49 | void keyTypeChanged(); 50 | void generateKeys(); 51 | void handleBrowseButtonClicked(); 52 | 53 | private: 54 | void setPrivateKeyFile(const QString &filePath); 55 | void saveKeys(); 56 | bool userForbidsOverwriting(); 57 | 58 | private: 59 | SshKeyGenerator *m_keyGenerator; 60 | Ui::SshKeyCreationDialog *m_ui; 61 | }; 62 | 63 | } // namespace QSsh 64 | 65 | #endif // SSHKEYCREATIONDIALOG_H 66 | -------------------------------------------------------------------------------- /src/sshkeyexchange_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHKEYEXCHANGE_P_H 27 | #define SSHKEYEXCHANGE_P_H 28 | 29 | #include "sshconnection.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace Botan { 35 | class DH_PrivateKey; 36 | class ECDH_PrivateKey; 37 | class HashFunction; 38 | } 39 | 40 | namespace QSsh { 41 | namespace Internal { 42 | 43 | struct SshKeyExchangeInit; 44 | class SshSendFacility; 45 | class SshIncomingPacket; 46 | 47 | class SshKeyExchange 48 | { 49 | public: 50 | SshKeyExchange(const SshConnectionParameters &connParams, SshSendFacility &sendFacility); 51 | ~SshKeyExchange(); 52 | 53 | void sendKexInitPacket(const QByteArray &serverId); 54 | 55 | // Returns true <=> the server sends a guessed package. 56 | bool sendDhInitPacket(const SshIncomingPacket &serverKexInit); 57 | 58 | void sendNewKeysPacket(const SshIncomingPacket &dhReply, 59 | const QByteArray &clientId); 60 | 61 | QByteArray k() const { return m_k; } 62 | QByteArray h() const { return m_h; } 63 | Botan::HashFunction *hash() const { return m_hash.data(); } 64 | QByteArray encryptionAlgo() const { return m_encryptionAlgo; } 65 | QByteArray decryptionAlgo() const { return m_decryptionAlgo; } 66 | QByteArray hMacAlgoClientToServer() const { return m_c2sHMacAlgo; } 67 | QByteArray hMacAlgoServerToClient() const { return m_s2cHMacAlgo; } 68 | 69 | private: 70 | QByteArray hashAlgoForKexAlgo() const; 71 | void determineHashingAlgorithm(const SshKeyExchangeInit &kexInit, bool serverToClient); 72 | void checkHostKey(const QByteArray &hostKey); 73 | Q_NORETURN void throwHostKeyException(); 74 | 75 | QByteArray m_serverId; 76 | QByteArray m_clientKexInitPayload; 77 | QByteArray m_serverKexInitPayload; 78 | QScopedPointer m_dhKey; 79 | QScopedPointer m_ecdhKey; 80 | QByteArray m_kexAlgoName; 81 | QByteArray m_k; 82 | QByteArray m_h; 83 | QByteArray m_serverHostKeyAlgo; 84 | QByteArray m_encryptionAlgo; 85 | QByteArray m_decryptionAlgo; 86 | QByteArray m_c2sHMacAlgo; 87 | QByteArray m_s2cHMacAlgo; 88 | QScopedPointer m_hash; 89 | const SshConnectionParameters m_connParams; 90 | SshSendFacility &m_sendFacility; 91 | }; 92 | 93 | } // namespace Internal 94 | } // namespace QSsh 95 | 96 | #endif // SSHKEYEXCHANGE_P_H 97 | -------------------------------------------------------------------------------- /src/sshkeygenerator.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHKEYGENERATOR_H 27 | #define SSHKEYGENERATOR_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace Botan { 35 | class Private_Key; 36 | class RandomNumberGenerator; 37 | } 38 | 39 | namespace QSsh { 40 | 41 | class QSSH_EXPORT SshKeyGenerator 42 | { 43 | Q_DECLARE_TR_FUNCTIONS(SshKeyGenerator) 44 | public: 45 | enum KeyType { Rsa, Dsa, Ecdsa }; 46 | enum PrivateKeyFormat { Pkcs8, OpenSsl, Mixed }; 47 | enum EncryptionMode { DoOfferEncryption, DoNotOfferEncryption }; // Only relevant for Pkcs8 format. 48 | 49 | SshKeyGenerator(); 50 | bool generateKeys(KeyType type, PrivateKeyFormat format, int keySize, 51 | EncryptionMode encryptionMode = DoOfferEncryption); 52 | 53 | QString error() const { return m_error; } 54 | QByteArray privateKey() const { return m_privateKey; } 55 | QByteArray publicKey() const { return m_publicKey; } 56 | KeyType type() const { return m_type; } 57 | 58 | private: 59 | typedef QSharedPointer KeyPtr; 60 | 61 | void generatePkcs8KeyStrings(const KeyPtr &key, Botan::RandomNumberGenerator &rng); 62 | void generatePkcs8KeyString(const KeyPtr &key, bool privateKey, 63 | Botan::RandomNumberGenerator &rng); 64 | void generateOpenSslKeyStrings(const KeyPtr &key); 65 | void generateOpenSslPrivateKeyString(const KeyPtr &key); 66 | void generateOpenSslPublicKeyString(const KeyPtr &key); 67 | QString getPassword() const; 68 | 69 | QString m_error; 70 | QByteArray m_publicKey; 71 | QByteArray m_privateKey; 72 | KeyType m_type; 73 | EncryptionMode m_encryptionMode; 74 | }; 75 | 76 | } // namespace QSsh 77 | 78 | #endif // SSHKEYGENERATOR_H 79 | -------------------------------------------------------------------------------- /src/sshkeypasswordretriever.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sshkeypasswordretriever_p.h" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | namespace QSsh { 35 | namespace Internal { 36 | 37 | std::string SshKeyPasswordRetriever::get_passphrase(const std::string &, const std::string &, 38 | UI_Result &result) const 39 | { 40 | const bool hasGui = dynamic_cast(QApplication::instance()); 41 | if (hasGui) { 42 | bool ok; 43 | const QString &password = QInputDialog::getText(0, 44 | QCoreApplication::translate("QSsh::Ssh", "Password Required"), 45 | QCoreApplication::translate("QSsh::Ssh", "Please enter the password for your private key."), 46 | QLineEdit::Password, QString(), &ok); 47 | result = ok ? OK : CANCEL_ACTION; 48 | return std::string(password.toLocal8Bit().data()); 49 | } else { 50 | result = OK; 51 | std::string password; 52 | std::cout << "Please enter the password for your private key (set echo off beforehand!): " << std::flush; 53 | std::cin >> password; 54 | return password; 55 | } 56 | } 57 | 58 | } // namespace Internal 59 | } // namespace QSsh 60 | -------------------------------------------------------------------------------- /src/sshkeypasswordretriever_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef KEYPASSWORDRETRIEVER_H 27 | #define KEYPASSWORDRETRIEVER_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace QSsh { 34 | namespace Internal { 35 | 36 | class SshKeyPasswordRetriever : public Botan::User_Interface 37 | { 38 | public: 39 | std::string get_passphrase(const std::string &what, const std::string &source, 40 | UI_Result &result) const; 41 | }; 42 | 43 | } // namespace Internal 44 | } // namespace QSsh 45 | 46 | #endif // KEYPASSWORDRETRIEVER_H 47 | -------------------------------------------------------------------------------- /src/sshlogging.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sshlogging_p.h" 27 | 28 | namespace QSsh { 29 | namespace Internal { 30 | Q_LOGGING_CATEGORY(sshLog, "qtc.ssh") 31 | } // namespace Internal 32 | } // namespace QSsh 33 | -------------------------------------------------------------------------------- /src/sshlogging_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHLOGGING_P_H 27 | #define SSHLOGGING_P_H 28 | 29 | #include 30 | 31 | namespace QSsh { 32 | namespace Internal { 33 | Q_DECLARE_LOGGING_CATEGORY(sshLog) 34 | } // namespace Internal 35 | } // namespace QSsh 36 | 37 | #endif // Include guard 38 | -------------------------------------------------------------------------------- /src/sshoutgoingpacket_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHOUTGOINGPACKET_P_H 27 | #define SSHOUTGOINGPACKET_P_H 28 | 29 | #include "sshpacket_p.h" 30 | 31 | #include "sshpseudoterminal.h" 32 | 33 | #include 34 | 35 | namespace QSsh { 36 | namespace Internal { 37 | 38 | class SshEncryptionFacility; 39 | 40 | class SshOutgoingPacket : public AbstractSshPacket 41 | { 42 | public: 43 | SshOutgoingPacket(const SshEncryptionFacility &encrypter, 44 | const quint32 &seqNr); 45 | 46 | QByteArray generateKeyExchangeInitPacket(); // Returns payload. 47 | void generateKeyDhInitPacket(const Botan::BigInt &e); 48 | void generateKeyEcdhInitPacket(const QByteArray &clientQ); 49 | void generateNewKeysPacket(); 50 | void generateDisconnectPacket(SshErrorCode reason, 51 | const QByteArray &reasonString); 52 | void generateMsgUnimplementedPacket(quint32 serverSeqNr); 53 | void generateUserAuthServiceRequestPacket(); 54 | void generateUserAuthByPasswordRequestPacket(const QByteArray &user, 55 | const QByteArray &service, const QByteArray &pwd); 56 | void generateUserAuthByPublicKeyRequestPacket(const QByteArray &user, 57 | const QByteArray &service); 58 | void generateUserAuthByKeyboardInteractiveRequestPacket(const QByteArray &user, 59 | const QByteArray &service); 60 | void generateUserAuthInfoResponsePacket(const QStringList &responses); 61 | void generateRequestFailurePacket(); 62 | void generateIgnorePacket(); 63 | void generateInvalidMessagePacket(); 64 | void generateSessionPacket(quint32 channelId, quint32 windowSize, 65 | quint32 maxPacketSize); 66 | void generateDirectTcpIpPacket(quint32 channelId, quint32 windowSize, 67 | quint32 maxPacketSize, const QByteArray &remoteHost, quint32 remotePort, 68 | const QByteArray &localIpAddress, quint32 localPort); 69 | void generateEnvPacket(quint32 remoteChannel, const QByteArray &var, 70 | const QByteArray &value); 71 | void generatePtyRequestPacket(quint32 remoteChannel, 72 | const SshPseudoTerminal &terminal); 73 | void generateExecPacket(quint32 remoteChannel, const QByteArray &command); 74 | void generateShellPacket(quint32 remoteChannel); 75 | void generateSftpPacket(quint32 remoteChannel); 76 | void generateWindowAdjustPacket(quint32 remoteChannel, quint32 bytesToAdd); 77 | void generateChannelDataPacket(quint32 remoteChannel, 78 | const QByteArray &data); 79 | void generateChannelSignalPacket(quint32 remoteChannel, 80 | const QByteArray &signalName); 81 | void generateChannelEofPacket(quint32 remoteChannel); 82 | void generateChannelClosePacket(quint32 remoteChannel); 83 | 84 | private: 85 | virtual quint32 cipherBlockSize() const; 86 | virtual quint32 macLength() const; 87 | 88 | static QByteArray encodeNameList(const QList &list); 89 | 90 | void generateServiceRequest(const QByteArray &service); 91 | 92 | SshOutgoingPacket &init(SshPacketType type); 93 | SshOutgoingPacket &setPadding(); 94 | SshOutgoingPacket &encrypt(); 95 | void finalize(); 96 | 97 | SshOutgoingPacket &appendInt(quint32 val); 98 | SshOutgoingPacket &appendString(const QByteArray &string); 99 | SshOutgoingPacket &appendMpInt(const Botan::BigInt &number); 100 | SshOutgoingPacket &appendBool(bool b); 101 | int sizeDivisor() const; 102 | 103 | const SshEncryptionFacility &m_encrypter; 104 | const quint32 &m_seqNr; 105 | }; 106 | 107 | } // namespace Internal 108 | } // namespace QSsh 109 | 110 | #endif // SSHOUTGOINGPACKET_P_H 111 | -------------------------------------------------------------------------------- /src/sshpacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #include "sshpacket_p.h" 27 | 28 | #include "sshcapabilities_p.h" 29 | #include "sshcryptofacility_p.h" 30 | #include "sshexception_p.h" 31 | #include "sshlogging_p.h" 32 | #include "sshpacketparser_p.h" 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace QSsh { 39 | namespace Internal { 40 | 41 | const quint32 AbstractSshPacket::PaddingLengthOffset = 4; 42 | const quint32 AbstractSshPacket::PayloadOffset = PaddingLengthOffset + 1; 43 | const quint32 AbstractSshPacket::TypeOffset = PayloadOffset; 44 | const quint32 AbstractSshPacket::MinPaddingLength = 4; 45 | 46 | static void printByteArray(const QByteArray &data) 47 | { 48 | qCDebug(sshLog, "%s", data.toHex().constData()); 49 | } 50 | 51 | 52 | AbstractSshPacket::AbstractSshPacket() : m_length(0) { } 53 | AbstractSshPacket::~AbstractSshPacket() {} 54 | 55 | bool AbstractSshPacket::isComplete() const 56 | { 57 | if (currentDataSize() < minPacketSize()) 58 | return false; 59 | return 4 + length() + macLength() == currentDataSize(); 60 | } 61 | 62 | void AbstractSshPacket::clear() 63 | { 64 | m_data.clear(); 65 | m_length = 0; 66 | } 67 | 68 | SshPacketType AbstractSshPacket::type() const 69 | { 70 | Q_ASSERT(isComplete()); 71 | return static_cast(m_data.at(TypeOffset)); 72 | } 73 | 74 | QByteArray AbstractSshPacket::payLoad() const 75 | { 76 | return QByteArray(m_data.constData() + PayloadOffset, 77 | length() - paddingLength() - 1); 78 | } 79 | 80 | void AbstractSshPacket::printRawBytes() const 81 | { 82 | printByteArray(m_data); 83 | } 84 | 85 | QByteArray AbstractSshPacket::encodeString(const QByteArray &string) 86 | { 87 | QByteArray data; 88 | data.resize(4); 89 | data += string; 90 | setLengthField(data); 91 | return data; 92 | } 93 | 94 | QByteArray AbstractSshPacket::encodeMpInt(const Botan::BigInt &number) 95 | { 96 | if (number.is_zero()) 97 | return QByteArray(4, 0); 98 | 99 | int stringLength = number.bytes(); 100 | const bool positiveAndMsbSet = number.sign() == Botan::BigInt::Positive 101 | && (number.byte_at(stringLength - 1) & 0x80); 102 | if (positiveAndMsbSet) 103 | ++stringLength; 104 | QByteArray data; 105 | data.resize(4 + stringLength); 106 | int pos = 4; 107 | if (positiveAndMsbSet) 108 | data[pos++] = '\0'; 109 | number.binary_encode(reinterpret_cast(data.data()) + pos); 110 | setLengthField(data); 111 | return data; 112 | } 113 | 114 | int AbstractSshPacket::paddingLength() const 115 | { 116 | return m_data[PaddingLengthOffset]; 117 | } 118 | 119 | quint32 AbstractSshPacket::length() const 120 | { 121 | //Q_ASSERT(currentDataSize() >= minPacketSize()); 122 | if (m_length == 0) 123 | calculateLength(); 124 | return m_length; 125 | } 126 | 127 | void AbstractSshPacket::calculateLength() const 128 | { 129 | m_length = SshPacketParser::asUint32(m_data, static_cast(0)); 130 | } 131 | 132 | QByteArray AbstractSshPacket::generateMac(const SshAbstractCryptoFacility &crypt, 133 | quint32 seqNr) const 134 | { 135 | const quint32 seqNrBe = qToBigEndian(seqNr); 136 | QByteArray data(reinterpret_cast(&seqNrBe), sizeof seqNrBe); 137 | data += QByteArray(m_data.constData(), length() + 4); 138 | return crypt.generateMac(data, data.size()); 139 | } 140 | 141 | quint32 AbstractSshPacket::minPacketSize() const 142 | { 143 | return qMax(cipherBlockSize(), 16) + macLength(); 144 | } 145 | 146 | void AbstractSshPacket::setLengthField(QByteArray &data) 147 | { 148 | const quint32 length = qToBigEndian(data.size() - 4); 149 | data.replace(0, 4, reinterpret_cast(&length), 4); 150 | } 151 | 152 | } // namespace Internal 153 | } // namespace QSsh 154 | -------------------------------------------------------------------------------- /src/sshpacket_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHPACKET_P_H 27 | #define SSHPACKET_P_H 28 | 29 | #include "sshexception_p.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace Botan { class BigInt; } 36 | 37 | namespace QSsh { 38 | namespace Internal { 39 | 40 | enum SshPacketType { 41 | SSH_MSG_DISCONNECT = 1, 42 | SSH_MSG_IGNORE = 2, 43 | SSH_MSG_UNIMPLEMENTED = 3, 44 | SSH_MSG_DEBUG = 4, 45 | SSH_MSG_SERVICE_REQUEST = 5, 46 | SSH_MSG_SERVICE_ACCEPT = 6, 47 | 48 | SSH_MSG_KEXINIT = 20, 49 | SSH_MSG_NEWKEYS = 21, 50 | SSH_MSG_KEXDH_INIT = 30, 51 | SSH_MSG_KEX_ECDH_INIT = 30, 52 | SSH_MSG_KEXDH_REPLY = 31, 53 | SSH_MSG_KEX_ECDH_REPLY = 31, 54 | 55 | SSH_MSG_USERAUTH_REQUEST = 50, 56 | SSH_MSG_USERAUTH_FAILURE = 51, 57 | SSH_MSG_USERAUTH_SUCCESS = 52, 58 | SSH_MSG_USERAUTH_BANNER = 53, 59 | SSH_MSG_USERAUTH_PK_OK = 60, 60 | SSH_MSG_USERAUTH_PASSWD_CHANGEREQ = 60, 61 | SSH_MSG_USERAUTH_INFO_REQUEST = 60, 62 | SSH_MSG_USERAUTH_INFO_RESPONSE = 61, 63 | 64 | SSH_MSG_GLOBAL_REQUEST = 80, 65 | SSH_MSG_REQUEST_SUCCESS = 81, 66 | SSH_MSG_REQUEST_FAILURE = 82, 67 | 68 | // TODO: We currently take no precautions against sending these messages 69 | // during a key re-exchange, which is not allowed. 70 | SSH_MSG_CHANNEL_OPEN = 90, 71 | SSH_MSG_CHANNEL_OPEN_CONFIRMATION = 91, 72 | SSH_MSG_CHANNEL_OPEN_FAILURE = 92, 73 | SSH_MSG_CHANNEL_WINDOW_ADJUST = 93, 74 | SSH_MSG_CHANNEL_DATA = 94, 75 | SSH_MSG_CHANNEL_EXTENDED_DATA = 95, 76 | SSH_MSG_CHANNEL_EOF = 96, 77 | SSH_MSG_CHANNEL_CLOSE = 97, 78 | SSH_MSG_CHANNEL_REQUEST = 98, 79 | SSH_MSG_CHANNEL_SUCCESS = 99, 80 | SSH_MSG_CHANNEL_FAILURE = 100, 81 | 82 | // Not completely safe, since the server may actually understand this 83 | // message type as an extension. Switch to a different value in that case 84 | // (between 128 and 191). 85 | SSH_MSG_INVALID = 128 86 | }; 87 | 88 | enum SshExtendedDataType { SSH_EXTENDED_DATA_STDERR = 1 }; 89 | 90 | class SshAbstractCryptoFacility; 91 | 92 | class AbstractSshPacket 93 | { 94 | public: 95 | virtual ~AbstractSshPacket(); 96 | 97 | void clear(); 98 | bool isComplete() const; 99 | SshPacketType type() const; 100 | 101 | static QByteArray encodeString(const QByteArray &string); 102 | static QByteArray encodeMpInt(const Botan::BigInt &number); 103 | template static QByteArray encodeInt(T value) 104 | { 105 | const T valMsb = qToBigEndian(value); 106 | return QByteArray(reinterpret_cast(&valMsb), sizeof valMsb); 107 | } 108 | 109 | static void setLengthField(QByteArray &data); 110 | 111 | void printRawBytes() const; // For Debugging. 112 | 113 | const QByteArray &rawData() const { return m_data; } 114 | 115 | QByteArray payLoad() const; 116 | 117 | protected: 118 | AbstractSshPacket(); 119 | 120 | virtual quint32 cipherBlockSize() const = 0; 121 | virtual quint32 macLength() const = 0; 122 | virtual void calculateLength() const; 123 | 124 | quint32 length() const; 125 | int paddingLength() const; 126 | quint32 minPacketSize() const; 127 | quint32 currentDataSize() const { return m_data.size(); } 128 | QByteArray generateMac(const SshAbstractCryptoFacility &crypt, 129 | quint32 seqNr) const; 130 | 131 | static const quint32 PaddingLengthOffset; 132 | static const quint32 PayloadOffset; 133 | static const quint32 TypeOffset; 134 | static const quint32 MinPaddingLength; 135 | 136 | mutable QByteArray m_data; 137 | mutable quint32 m_length; 138 | }; 139 | 140 | } // namespace Internal 141 | } // namespace QSsh 142 | 143 | #endif // SSHPACKET_P_H 144 | -------------------------------------------------------------------------------- /src/sshpacketparser_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHPACKETPARSER_P_H 27 | #define SSHPACKETPARSER_P_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace QSsh { 36 | namespace Internal { 37 | 38 | struct SshNameList 39 | { 40 | SshNameList() : originalLength(0) {} 41 | SshNameList(quint32 originalLength) : originalLength(originalLength) {} 42 | quint32 originalLength; 43 | QList names; 44 | }; 45 | 46 | class SshPacketParseException { }; 47 | 48 | // This class's functions try to read a byte array at a certain offset 49 | // as the respective chunk of data as specified in the SSH RFCs. 50 | // If they succeed, they update the offset, so they can easily 51 | // be called in succession by client code. 52 | // For convenience, some have also versions that don't update the offset, 53 | // so they can be called with rvalues if the new value is not needed. 54 | // If they fail, they throw an SshPacketParseException. 55 | class SshPacketParser 56 | { 57 | public: 58 | static bool asBool(const QByteArray &data, quint32 offset); 59 | static bool asBool(const QByteArray &data, quint32 *offset); 60 | static quint16 asUint16(const QByteArray &data, quint32 offset); 61 | static quint16 asUint16(const QByteArray &data, quint32 *offset); 62 | static quint64 asUint64(const QByteArray &data, quint32 offset); 63 | static quint64 asUint64(const QByteArray &data, quint32 *offset); 64 | static quint32 asUint32(const QByteArray &data, quint32 offset); 65 | static quint32 asUint32(const QByteArray &data, quint32 *offset); 66 | static QByteArray asString(const QByteArray &data, quint32 *offset); 67 | static QString asUserString(const QByteArray &data, quint32 *offset); 68 | static SshNameList asNameList(const QByteArray &data, quint32 *offset); 69 | static Botan::BigInt asBigInt(const QByteArray &data, quint32 *offset); 70 | 71 | static QString asUserString(const QByteArray &rawString); 72 | }; 73 | 74 | } // namespace Internal 75 | } // namespace QSsh 76 | 77 | #endif // SSHPACKETPARSER_P_H 78 | -------------------------------------------------------------------------------- /src/sshremoteprocess.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHREMOTEPROCESS_H 27 | #define SSHREMOTEPROCESS_H 28 | 29 | #include "ssh_global.h" 30 | 31 | #include 32 | #include 33 | 34 | QT_BEGIN_NAMESPACE 35 | class QByteArray; 36 | QT_END_NAMESPACE 37 | 38 | namespace QSsh { 39 | class SshPseudoTerminal; 40 | namespace Internal { 41 | class SshChannelManager; 42 | class SshRemoteProcessPrivate; 43 | class SshSendFacility; 44 | } // namespace Internal 45 | 46 | // TODO: ProcessChannel 47 | class QSSH_EXPORT SshRemoteProcess : public QIODevice 48 | { 49 | Q_OBJECT 50 | 51 | friend class Internal::SshChannelManager; 52 | friend class Internal::SshRemoteProcessPrivate; 53 | 54 | public: 55 | typedef QSharedPointer Ptr; 56 | enum ExitStatus { FailedToStart, CrashExit, NormalExit }; 57 | enum Signal { 58 | AbrtSignal, AlrmSignal, FpeSignal, HupSignal, IllSignal, IntSignal, KillSignal, PipeSignal, 59 | QuitSignal, SegvSignal, TermSignal, Usr1Signal, Usr2Signal, NoSignal 60 | }; 61 | 62 | ~SshRemoteProcess(); 63 | 64 | // QIODevice stuff 65 | bool atEnd() const; 66 | qint64 bytesAvailable() const; 67 | bool canReadLine() const; 68 | void close(); 69 | bool isSequential() const { return true; } 70 | 71 | QProcess::ProcessChannel readChannel() const; 72 | void setReadChannel(QProcess::ProcessChannel channel); 73 | 74 | /* 75 | * Note that this is of limited value in practice, because servers are 76 | * usually configured to ignore such requests for security reasons. 77 | */ 78 | void addToEnvironment(const QByteArray &var, const QByteArray &value); 79 | void clearEnvironment(); 80 | 81 | void requestTerminal(const SshPseudoTerminal &terminal); 82 | void start(); 83 | 84 | bool isRunning() const; 85 | int exitCode() const; 86 | Signal exitSignal() const; 87 | 88 | QByteArray readAllStandardOutput(); 89 | QByteArray readAllStandardError(); 90 | 91 | // Note: This is ignored by the OpenSSH server. 92 | void sendSignal(Signal signal); 93 | void kill() { sendSignal(KillSignal); } 94 | 95 | signals: 96 | void started(); 97 | 98 | void readyReadStandardOutput(); 99 | void readyReadStandardError(); 100 | 101 | /* 102 | * Parameter is of type ExitStatus, but we use int because of 103 | * signal/slot awkwardness (full namespace required). 104 | */ 105 | void closed(int exitStatus); 106 | 107 | private: 108 | SshRemoteProcess(const QByteArray &command, quint32 channelId, 109 | Internal::SshSendFacility &sendFacility); 110 | SshRemoteProcess(quint32 channelId, Internal::SshSendFacility &sendFacility); 111 | 112 | // QIODevice stuff 113 | qint64 readData(char *data, qint64 maxlen); 114 | qint64 writeData(const char *data, qint64 len); 115 | 116 | void init(); 117 | QByteArray readAllFromChannel(QProcess::ProcessChannel channel); 118 | 119 | Internal::SshRemoteProcessPrivate *d; 120 | }; 121 | 122 | } // namespace QSsh 123 | 124 | #endif // SSHREMOTEPROCESS_H 125 | -------------------------------------------------------------------------------- /src/sshremoteprocess_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHREMOTEPROCESS_P_H 27 | #define SSHREMOTEPROCESS_P_H 28 | 29 | #include "sshpseudoterminal.h" 30 | 31 | #include "sshchannel_p.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace QSsh { 38 | class SshRemoteProcess; 39 | 40 | namespace Internal { 41 | class SshSendFacility; 42 | 43 | class SshRemoteProcessPrivate : public AbstractSshChannel 44 | { 45 | Q_OBJECT 46 | friend class QSsh::SshRemoteProcess; 47 | public: 48 | enum ProcessState { 49 | NotYetStarted, ExecRequested, StartFailed, Running, Exited 50 | }; 51 | 52 | signals: 53 | void started(); 54 | void readyRead(); 55 | void readyReadStandardOutput(); 56 | void readyReadStandardError(); 57 | void closed(int exitStatus); 58 | 59 | private: 60 | SshRemoteProcessPrivate(const QByteArray &command, quint32 channelId, 61 | SshSendFacility &sendFacility, SshRemoteProcess *proc); 62 | SshRemoteProcessPrivate(quint32 channelId, SshSendFacility &sendFacility, 63 | SshRemoteProcess *proc); 64 | 65 | virtual void handleChannelSuccess(); 66 | virtual void handleChannelFailure(); 67 | 68 | virtual void handleOpenSuccessInternal(); 69 | virtual void handleOpenFailureInternal(const QString &reason); 70 | virtual void handleChannelDataInternal(const QByteArray &data); 71 | virtual void handleChannelExtendedDataInternal(quint32 type, 72 | const QByteArray &data); 73 | virtual void handleExitStatus(const SshChannelExitStatus &exitStatus); 74 | virtual void handleExitSignal(const SshChannelExitSignal &signal); 75 | 76 | virtual void closeHook(); 77 | 78 | void init(); 79 | void setProcState(ProcessState newState); 80 | QByteArray &data(); 81 | 82 | QProcess::ProcessChannel m_readChannel; 83 | 84 | ProcessState m_procState; 85 | bool m_wasRunning; 86 | int m_signal; 87 | int m_exitCode; 88 | 89 | const QByteArray m_command; 90 | const bool m_isShell; 91 | 92 | typedef QPair EnvVar; 93 | QList m_env; 94 | bool m_useTerminal; 95 | SshPseudoTerminal m_terminal; 96 | 97 | QByteArray m_stdout; 98 | QByteArray m_stderr; 99 | 100 | SshRemoteProcess *m_proc; 101 | }; 102 | 103 | } // namespace Internal 104 | } // namespace QSsh 105 | 106 | #endif // SSHREMOTEPROCESS_P_H 107 | -------------------------------------------------------------------------------- /src/sshremoteprocessrunner.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHREMOTEPROCESSRUNNER_H 27 | #define SSHREMOTEPROCESSRUNNER_H 28 | 29 | #include "sshconnection.h" 30 | #include "sshremoteprocess.h" 31 | 32 | namespace QSsh { 33 | namespace Internal { class SshRemoteProcessRunnerPrivate; } 34 | 35 | class QSSH_EXPORT SshRemoteProcessRunner : public QObject 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | SshRemoteProcessRunner(QObject *parent = 0); 41 | ~SshRemoteProcessRunner(); 42 | 43 | void run(const QByteArray &command, const SshConnectionParameters &sshParams); 44 | void runInTerminal(const QByteArray &command, const SshPseudoTerminal &terminal, 45 | const SshConnectionParameters &sshParams); 46 | QByteArray command() const; 47 | 48 | QSsh::SshError lastConnectionError() const; 49 | QString lastConnectionErrorString() const; 50 | 51 | bool isProcessRunning() const; 52 | void writeDataToProcess(const QByteArray &data); 53 | void sendSignalToProcess(SshRemoteProcess::Signal signal); // No effect with OpenSSH server. 54 | void cancel(); // Does not stop remote process, just frees SSH-related process resources. 55 | SshRemoteProcess::ExitStatus processExitStatus() const; 56 | SshRemoteProcess::Signal processExitSignal() const; 57 | int processExitCode() const; 58 | QString processErrorString() const; 59 | QByteArray readAllStandardOutput(); 60 | QByteArray readAllStandardError(); 61 | 62 | signals: 63 | void connectionError(); 64 | void processStarted(); 65 | void readyReadStandardOutput(); 66 | void readyReadStandardError(); 67 | void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus 68 | 69 | private slots: 70 | void handleConnected(); 71 | void handleConnectionError(QSsh::SshError error); 72 | void handleDisconnected(); 73 | void handleProcessStarted(); 74 | void handleProcessFinished(int exitStatus); 75 | void handleStdout(); 76 | void handleStderr(); 77 | 78 | private: 79 | void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams); 80 | void setState(int newState); 81 | 82 | Internal::SshRemoteProcessRunnerPrivate * const d; 83 | }; 84 | 85 | } // namespace QSsh 86 | 87 | #endif // SSHREMOTEPROCESSRUNNER_H 88 | -------------------------------------------------------------------------------- /src/sshsendfacility_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of Qt Creator. 7 | ** 8 | ** Commercial License Usage 9 | ** Licensees holding valid commercial Qt licenses may use this file in 10 | ** accordance with the commercial license agreement provided with the 11 | ** Software or, alternatively, in accordance with the terms contained in 12 | ** a written agreement between you and The Qt Company. For licensing terms 13 | ** and conditions see https://www.qt.io/terms-conditions. For further 14 | ** information use the contact form at https://www.qt.io/contact-us. 15 | ** 16 | ** GNU General Public License Usage 17 | ** Alternatively, this file may be used under the terms of the GNU 18 | ** General Public License version 3 as published by the Free Software 19 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 | ** included in the packaging of this file. Please review the following 21 | ** information to ensure the GNU General Public License requirements will 22 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef SSHSENDFACILITY_P_H 27 | #define SSHSENDFACILITY_P_H 28 | 29 | #include "sshcryptofacility_p.h" 30 | #include "sshoutgoingpacket_p.h" 31 | 32 | #include 33 | 34 | QT_BEGIN_NAMESPACE 35 | class QTcpSocket; 36 | QT_END_NAMESPACE 37 | 38 | 39 | namespace QSsh { 40 | class SshPseudoTerminal; 41 | 42 | namespace Internal { 43 | class SshKeyExchange; 44 | 45 | class SshSendFacility 46 | { 47 | public: 48 | SshSendFacility(QTcpSocket *socket); 49 | void reset(); 50 | void recreateKeys(const SshKeyExchange &keyExchange); 51 | void createAuthenticationKey(const QByteArray &privKeyFileContents); 52 | 53 | QByteArray sendKeyExchangeInitPacket(); 54 | void sendKeyDhInitPacket(const Botan::BigInt &e); 55 | void sendKeyEcdhInitPacket(const QByteArray &clientQ); 56 | void sendNewKeysPacket(); 57 | void sendDisconnectPacket(SshErrorCode reason, 58 | const QByteArray &reasonString); 59 | void sendMsgUnimplementedPacket(quint32 serverSeqNr); 60 | void sendUserAuthServiceRequestPacket(); 61 | void sendUserAuthByPasswordRequestPacket(const QByteArray &user, 62 | const QByteArray &service, const QByteArray &pwd); 63 | void sendUserAuthByPublicKeyRequestPacket(const QByteArray &user, 64 | const QByteArray &service); 65 | void sendUserAuthByKeyboardInteractiveRequestPacket(const QByteArray &user, 66 | const QByteArray &service); 67 | void sendUserAuthInfoResponsePacket(const QStringList &responses); 68 | void sendRequestFailurePacket(); 69 | void sendIgnorePacket(); 70 | void sendInvalidPacket(); 71 | void sendSessionPacket(quint32 channelId, quint32 windowSize, 72 | quint32 maxPacketSize); 73 | void sendDirectTcpIpPacket(quint32 channelId, quint32 windowSize, quint32 maxPacketSize, 74 | const QByteArray &remoteHost, quint32 remotePort, const QByteArray &localIpAddress, 75 | quint32 localPort); 76 | void sendPtyRequestPacket(quint32 remoteChannel, 77 | const SshPseudoTerminal &terminal); 78 | void sendEnvPacket(quint32 remoteChannel, const QByteArray &var, 79 | const QByteArray &value); 80 | void sendExecPacket(quint32 remoteChannel, const QByteArray &command); 81 | void sendShellPacket(quint32 remoteChannel); 82 | void sendSftpPacket(quint32 remoteChannel); 83 | void sendWindowAdjustPacket(quint32 remoteChannel, quint32 bytesToAdd); 84 | void sendChannelDataPacket(quint32 remoteChannel, const QByteArray &data); 85 | void sendChannelSignalPacket(quint32 remoteChannel, 86 | const QByteArray &signalName); 87 | void sendChannelEofPacket(quint32 remoteChannel); 88 | void sendChannelClosePacket(quint32 remoteChannel); 89 | quint32 nextClientSeqNr() const { return m_clientSeqNr; } 90 | 91 | private: 92 | void sendPacket(); 93 | 94 | quint32 m_clientSeqNr; 95 | SshEncryptionFacility m_encrypter; 96 | QTcpSocket *m_socket; 97 | SshOutgoingPacket m_outgoingPacket; 98 | }; 99 | 100 | } // namespace Internal 101 | } // namespace QSsh 102 | 103 | #endif // SSHSENDFACILITY_P_H 104 | --------------------------------------------------------------------------------