├── .gitignore ├── CMakeLists.txt ├── LGPL_EXCEPTION.TXT ├── LICENSE.LGPL ├── README.md ├── cmakeFindModules └── QSshConfig.cmake ├── examples ├── CMakeLists.txt ├── SecureUploader │ ├── CMakeLists.txt │ ├── SecureUploader.pro │ ├── main.cpp │ ├── securefileuploader.cpp │ └── securefileuploader.h ├── errorhandling │ ├── CMakeLists.txt │ ├── errorhandling.pro │ └── main.cpp ├── examples.pro ├── remoteprocess │ ├── CMakeLists.txt │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── remoteprocess.pro │ ├── remoteprocesstest.cpp │ └── remoteprocesstest.h ├── sftp │ ├── CMakeLists.txt │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── parameters.h │ ├── sftp.pro │ ├── sftptest.cpp │ └── sftptest.h ├── ssh-shell │ ├── CMakeLists.txt │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── main.cpp │ ├── shell.cpp │ ├── shell.h │ └── ssh-shell.pro └── tunnel │ ├── CMakeLists.txt │ ├── argumentscollector.cpp │ ├── argumentscollector.h │ ├── directtunnel.cpp │ ├── directtunnel.h │ ├── forwardtunnel.cpp │ ├── forwardtunnel.h │ ├── main.cpp │ └── tunnel.pro ├── qssh.pri ├── qssh.pro ├── src ├── CMakeLists.txt ├── libs │ ├── CMakeLists.txt │ ├── libs.pro │ └── qssh │ │ ├── CMakeLists.txt │ │ ├── images │ │ ├── dir.png │ │ ├── help.png │ │ └── unknownfile.png │ │ ├── opensshkeyfilereader.cpp │ │ ├── opensshkeyfilereader_p.h │ │ ├── qssh.pri │ │ ├── qssh.pro │ │ ├── qssh.qbs │ │ ├── qssh.qrc │ │ ├── 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 │ │ ├── ssh_global.h │ │ ├── sshagent.cpp │ │ ├── sshagent_p.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 │ │ ├── sshforwardedtcpiptunnel.cpp │ │ ├── sshforwardedtcpiptunnel.h │ │ ├── sshforwardedtcpiptunnel_p.h │ │ ├── sshhostkeydatabase.cpp │ │ ├── sshhostkeydatabase.h │ │ ├── sshincomingpacket.cpp │ │ ├── sshincomingpacket_p.h │ │ ├── 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 │ │ ├── sshtcpipforwardserver.cpp │ │ ├── sshtcpipforwardserver.h │ │ ├── sshtcpipforwardserver_p.h │ │ ├── sshtcpiptunnel.cpp │ │ ├── sshtcpiptunnel_p.h │ │ ├── sshx11channel.cpp │ │ ├── sshx11channel_p.h │ │ ├── sshx11displayinfo_p.h │ │ ├── sshx11inforetriever.cpp │ │ └── sshx11inforetriever_p.h ├── qtcreatorlibrary.pri ├── rpath.pri └── src.pro └── tests ├── auto ├── auto.pro ├── qttest.pri ├── qttestrpath.pri └── ssh │ ├── README.md │ ├── ssh.pro │ └── tst_ssh.cpp ├── manual ├── manual.pro └── ssh │ ├── qssh.pri │ ├── sftpfsmodel │ ├── main.cpp │ ├── sftpfsmodel.pro │ ├── window.cpp │ ├── window.h │ └── window.ui │ └── ssh.pro └── tests.pro /.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 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | # set the project name and version 4 | project(QSsh VERSION 1.0 LANGUAGES CXX) 5 | 6 | # specify the C++ standard 7 | set(CMAKE_CXX_STANDARD 14) 8 | set(CMAKE_CXX_STANDARD_REQUIRED True) 9 | 10 | if(MSVC) 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4005") 12 | set(BOTAN_LIB ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/botan.lib) 13 | else(MSVC) 14 | find_package(PkgConfig REQUIRED) 15 | pkg_search_module(Botan REQUIRED IMPORTED_TARGET GLOBAL botan-2) 16 | 17 | set_property(GLOBAL PROPERTY BOTAN_LIB PkgConfig::Botan) 18 | endif(MSVC) 19 | 20 | find_package(QT NAMES Qt5 Qt6 COMPONENTS Core Quick REQUIRED) 21 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Network REQUIRED) 22 | 23 | message(STATUS "Found Qt version ${QT_VERSION_MAJOR}") 24 | 25 | # qt 26 | set(CMAKE_AUTOMOC ON) 27 | set(CMAKE_AUTORCC ON) 28 | set(CMAKE_AUTOUIC ON) 29 | 30 | if(CMAKE_VERSION VERSION_LESS "3.7.0") 31 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 32 | endif() 33 | 34 | add_subdirectory(src) 35 | add_subdirectory(examples) 36 | 37 | # INSTALL RULES 38 | install(EXPORT QSsh-targets DESTINATION lib) 39 | install(EXPORT QSsh-targets 40 | FILE QSshTargets.cmake 41 | NAMESPACE QSsh:: 42 | DESTINATION share/QSsh/cmake 43 | ) 44 | 45 | 46 | install(FILES "${CMAKE_SOURCE_DIR}/cmakeFindModules/QSshConfig.cmake" 47 | DESTINATION share/QSsh/cmake) 48 | -------------------------------------------------------------------------------- /LGPL_EXCEPTION.TXT: -------------------------------------------------------------------------------- 1 | Nokia 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 | About QSsh 2 | ========== 3 | 4 | QSsh provides SSH and SFTP support for Qt applications without depending on 5 | openssh or similar. The aim of this project is to provide an easy way to use 6 | these protocols in any Qt application. 7 | 8 | This project is based on Qt Creator's previous SSH plugin. All credits to 9 | Qt Creator's team! 10 | 11 | Unfortunately Qt Creator has decided to start using openssh instead (with some 12 | hacks invoking it etc.), so this is now the most up to date maintained version. 13 | 14 | 15 | Compiling QSsh 16 | -------------- 17 | 18 | Prerequisites: 19 | * [Qt](https://www.qt.io/) 20 | * [Botan](https://botan.randombit.net/) 21 | 22 | Steps: 23 | ```bash 24 | git clone https://github.com/sandsmark/QSsh.git 25 | cd QSsh 26 | mkdir build 27 | cd build 28 | qmake ../qssh.pro 29 | make (or mingw32-make or nmake depending on your platform) 30 | ``` 31 | 32 | Examples 33 | -------- 34 | 35 | ### Complete applications 36 | 37 | * [ssh shell](examples/ssh-shell/), similar to a normal command line `ssh` client. 38 | * [Graphical SFTP browser](tests/manual/ssh/sftpfsmodel/), how to use the SFTP file system model with a QTreeView. 39 | * [Secure Uploader](examples/SecureUploader/), how to upload a file. 40 | 41 | 42 | ### Various usage examples 43 | * [Tunneling and forwarding](examples/tunnel/) 44 | * [SFTP](examples/sftp/) 45 | * [Remote process handling](examples/remoteprocess/) 46 | 47 | 48 | ### Other 49 | 50 | * [Error handling](examples/errorhandling/) 51 | * [Auto tests](tests/auto/ssh/) 52 | -------------------------------------------------------------------------------- /cmakeFindModules/QSshConfig.cmake: -------------------------------------------------------------------------------- 1 | # Called if we failed to find OpenMVG or any of it's required dependencies, 2 | # unsets all public (designed to be used externally) variables and reports 3 | # error message at priority depending upon [REQUIRED/QUIET/] argument. 4 | macro(QSSH_REPORT_NOT_FOUND REASON_MSG) 5 | # FindPackage() only references QSSH_FOUND, and requires it to be 6 | # explicitly set FALSE to denote not found (not merely undefined). 7 | set(QSSH_FOUND FALSE) 8 | 9 | # Reset the CMake module path to its state when this script was called. 10 | set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH}) 11 | 12 | # Note _FIND_[REQUIRED/QUIETLY] variables defined by 13 | # FindPackage() use the camelcase library name, not uppercase. 14 | if (QSSH_FIND_QUIETLY) 15 | message(STATUS "Failed to find OPENMVG - " ${REASON_MSG} ${ARGN}) 16 | elseif (QSSH_FIND_REQUIRED) 17 | message(FATAL_ERROR "Failed to find OPENMVG - " ${REASON_MSG} ${ARGN}) 18 | else() 19 | # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error 20 | # that prevents generation, but continues configuration. 21 | message(SEND_ERROR "Failed to find QSSH - " ${REASON_MSG} ${ARGN}) 22 | endif () 23 | return() 24 | endmacro(QSSH_REPORT_NOT_FOUND) 25 | 26 | # Get the (current, i.e. installed) directory containing this file. 27 | get_filename_component(CURRENT_CONFIG_INSTALL_DIR 28 | "${CMAKE_CURRENT_LIST_FILE}" PATH) 29 | 30 | # Record the state of the CMake module path when this script was 31 | # called so that we can ensure that we leave it in the same state on 32 | # exit as it was on entry, but modify it locally. 33 | set(CALLERS_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) 34 | # Reset CMake module path to the installation directory of this 35 | # script. 36 | set(CMAKE_MODULE_PATH ${CURRENT_CONFIG_INSTALL_DIR}) 37 | 38 | # Build the absolute root install directory as a relative path 39 | get_filename_component(CURRENT_ROOT_INSTALL_DIR 40 | ${CMAKE_MODULE_PATH}/../../../ ABSOLUTE) 41 | if (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR}) 42 | QSSH_REPORT_NOT_FOUND( 43 | "QSSH install root: ${CURRENT_ROOT_INSTALL_DIR}, " 44 | "determined from relative path from QSShConfig.cmake install location: " 45 | "${CMAKE_MODULE_PATH}, does not exist.") 46 | endif (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR}) 47 | 48 | # Check if QSSH header is installed 49 | if (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR}/include/qssh/sshconnection.h) 50 | OPENMVG_REPORT_NOT_FOUND( 51 | "QSSH install root: ${CMAKE_MODULE_PATH}. " 52 | "Cannot find QSSH include files.") 53 | endif (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR}/include/qssh/sshconnection.h) 54 | 55 | 56 | # Import exported QSSH targets 57 | include(${CURRENT_CONFIG_INSTALL_DIR}/QSshTargets.cmake) 58 | 59 | # As we use QSSH_REPORT_NOT_FOUND() to abort, if we reach this point we have 60 | # found QSSH and all required dependencies. 61 | message(STATUS "----") 62 | message(STATUS "QSSH Find_Package") 63 | message(STATUS "----") 64 | message(STATUS "Found QSSH ") 65 | message(STATUS "Installed in: ${CURRENT_ROOT_INSTALL_DIR}") 66 | message(STATUS "----") 67 | 68 | set(QSSH_FOUND TRUE) 69 | 70 | # Reset the CMake module path to its state when this script was called. 71 | set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH}) -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(SecureUploader) 2 | add_subdirectory(remoteprocess) 3 | add_subdirectory(sftp) 4 | add_subdirectory(tunnel) 5 | add_subdirectory(errorhandling) 6 | add_subdirectory(ssh-shell) 7 | -------------------------------------------------------------------------------- /examples/SecureUploader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(SecureUploader 2 | main.cpp 3 | securefileuploader.cpp) 4 | 5 | target_link_libraries(SecureUploader PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 6 | 7 | -------------------------------------------------------------------------------- /examples/SecureUploader/SecureUploader.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2012-11-22T15:56:43 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core network 8 | 9 | TARGET = SecureUploader 10 | TEMPLATE = app 11 | 12 | INCLUDEPATH = $$PWD/../../src/libs/ssh/ 13 | 14 | SOURCES += \ 15 | main.cpp \ 16 | securefileuploader.cpp 17 | 18 | HEADERS += \ 19 | securefileuploader.h 20 | 21 | include(../../qssh.pri) ## Required for IDE_LIBRARY_PATH and qtLibraryName 22 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 23 | -------------------------------------------------------------------------------- /examples/SecureUploader/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of QSsh 4 | ** 5 | ** Copyright (c) 2012 LVK 6 | ** 7 | ** Contact: andres.pagliano@lvklabs.com 8 | ** 9 | ** GNU Lesser General Public License Usage 10 | ** 11 | ** This file may be used under the terms of the GNU Lesser General Public 12 | ** License version 2.1 as published by the Free Software Foundation and 13 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 14 | ** Please review the following information to ensure the GNU Lesser General 15 | ** Public License version 2.1 requirements will be met: 16 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | **************************************************************************/ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "securefileuploader.h" 24 | 25 | void showSyntax(); 26 | QString getPassword(); 27 | void upload(const QString &orig, const QString &dest, const QString &passwd); 28 | 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | QCoreApplication a(argc, argv); 33 | 34 | if (argc != 3) { 35 | showSyntax(); 36 | } 37 | 38 | QString orig = QString::fromLocal8Bit(argv[1]); 39 | QString dest = QString::fromLocal8Bit(argv[2]); 40 | QString passwd = getPassword(); 41 | 42 | upload(orig, dest, passwd); 43 | 44 | return a.exec(); 45 | } 46 | 47 | 48 | void showSyntax() 49 | { 50 | std::cerr << "Syntax: " << std::endl; 51 | std::cerr << " SecureUploader local_file username@host:/destination_path" << std::endl; 52 | exit(1); 53 | } 54 | 55 | 56 | QString getPassword() 57 | { 58 | std::cout << "Password (Warning password will be echoed): "; 59 | std::string passwd; 60 | std::cin >> passwd; 61 | 62 | return QString::fromStdString(passwd).trimmed(); 63 | } 64 | 65 | 66 | void upload(const QString &orig, const QString &dest, const QString &passwd) 67 | { 68 | // Parse destination with format "username@host:/destination" 69 | 70 | QStringList l1 = dest.split(QLatin1Char('@')); 71 | 72 | if (l1.size() == 2) { 73 | QStringList l2 = l1[1].split(QLatin1Char(':')); 74 | 75 | if (l2.size() == 2) { 76 | static SecureFileUploader uploader; 77 | uploader.upload(orig, l2[1], l2[0], l1[0], passwd); 78 | } else { 79 | std::cerr << "SecureUploader: Error invalid parameter " << dest.toStdString() << std::endl; 80 | showSyntax(); 81 | } 82 | } else { 83 | std::cerr << "SecureUploader: Error invalid parameter " << dest.toStdString() << std::endl; 84 | showSyntax(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /examples/SecureUploader/securefileuploader.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of QSsh 4 | ** 5 | ** Copyright (c) 2012 LVK 6 | ** 7 | ** Contact: andres.pagliano@lvklabs.com 8 | ** 9 | ** GNU Lesser General Public License Usage 10 | ** 11 | ** This file may be used under the terms of the GNU Lesser General Public 12 | ** License version 2.1 as published by the Free Software Foundation and 13 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 14 | ** Please review the following information to ensure the GNU Lesser General 15 | ** Public License version 2.1 requirements will be met: 16 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | **************************************************************************/ 19 | 20 | #include "securefileuploader.h" 21 | 22 | #include 23 | #include 24 | 25 | SecureFileUploader::SecureFileUploader(QObject *parent) : 26 | QObject(parent), m_connection(0) 27 | { 28 | } 29 | 30 | void SecureFileUploader::upload(const QString &localFile, const QString &dest, const QString &host, 31 | const QString &username, const QString &passwd) 32 | { 33 | QFileInfo info(localFile); 34 | 35 | m_localFilename = info.canonicalFilePath(); 36 | m_remoteFilename = dest + QLatin1Char('/') + info.fileName(); 37 | 38 | QSsh::SshConnectionParameters params; 39 | params.setHost(host); 40 | params.setUserName(username); 41 | params.setPassword(passwd); 42 | params.authenticationType = QSsh::SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods; 43 | params.timeout = 30; 44 | params.setPort(22); 45 | 46 | m_connection = new QSsh::SshConnection(params, this); 47 | 48 | connect(m_connection, SIGNAL(connected()), SLOT(onConnected())); 49 | connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(onConnectionError(QSsh::SshError))); 50 | 51 | qDebug() << "SecureUploader: Connecting to host" << host; 52 | 53 | m_connection->connectToHost(); 54 | } 55 | 56 | void SecureFileUploader::onConnected() 57 | { 58 | qDebug() << "SecureUploader: Connected"; 59 | qDebug() << "SecureUploader: Creating SFTP channel..."; 60 | 61 | m_channel = m_connection->createSftpChannel(); 62 | 63 | if (m_channel) { 64 | connect(m_channel.data(), SIGNAL(initialized()), 65 | SLOT(onChannelInitialized())); 66 | connect(m_channel.data(), SIGNAL(initializationFailed(QString)), 67 | SLOT(onChannelError(QString))); 68 | connect(m_channel.data(), SIGNAL(finished(QSsh::SftpJobId, QString)), 69 | SLOT(onOpfinished(QSsh::SftpJobId, QString))); 70 | 71 | m_channel->initialize(); 72 | 73 | } else { 74 | qDebug() << "SecureUploader: Error null channel"; 75 | } 76 | } 77 | 78 | void SecureFileUploader::onConnectionError(QSsh::SshError err) 79 | { 80 | qDebug() << "SecureUploader: Connection error" << err; 81 | } 82 | 83 | void SecureFileUploader::onChannelInitialized() 84 | { 85 | qDebug() << "SecureUploader: Channel Initialized"; 86 | 87 | // TODO Choose the overwrite mode: SftpOverwriteExisting, SftpAppendToExisting, SftpSkipExisting 88 | QSsh::SftpJobId job = m_channel->uploadFile(m_localFilename, m_remoteFilename, 89 | QSsh::SftpOverwriteExisting); 90 | 91 | if (job != QSsh::SftpInvalidJob) { 92 | qDebug() << "SecureUploader: Starting job #" << job; 93 | } else { 94 | qDebug() << "SecureUploader: Invalid Job"; 95 | } 96 | } 97 | 98 | void SecureFileUploader::onChannelError(const QString &err) 99 | { 100 | qDebug() << "SecureUploader: Error: " << err; 101 | } 102 | 103 | void SecureFileUploader::onOpfinished(QSsh::SftpJobId job, const QString &err) 104 | { 105 | qDebug() << "SecureUploader: Finished job #" << job << ":" << (err.isEmpty() ? QStringLiteral("OK") : err); 106 | } 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /examples/SecureUploader/securefileuploader.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of QSsh 4 | ** 5 | ** Copyright (c) 2012 LVK 6 | ** 7 | ** Contact: andres.pagliano@lvklabs.com 8 | ** 9 | ** GNU Lesser General Public License Usage 10 | ** 11 | ** This file may be used under the terms of the GNU Lesser General Public 12 | ** License version 2.1 as published by the Free Software Foundation and 13 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 14 | ** Please review the following information to ensure the GNU Lesser General 15 | ** Public License version 2.1 requirements will be met: 16 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | **************************************************************************/ 19 | 20 | #ifndef SECUREFILEUPLOADER_H 21 | #define SECUREFILEUPLOADER_H 22 | 23 | #include 24 | 25 | #include "qssh/sftpchannel.h" 26 | #include "qssh/sshconnection.h" 27 | 28 | /// Very simple example to upload a file using FTPS 29 | class SecureFileUploader : public QObject 30 | { 31 | Q_OBJECT 32 | public: 33 | 34 | explicit SecureFileUploader(QObject *parent = 0); 35 | 36 | /// Uploads \a localFile to \a username@host:/dest using password \a passwd 37 | void upload(const QString &localFile, const QString &dest, const QString &host, 38 | const QString &username, const QString &passwd); 39 | 40 | signals: 41 | 42 | private slots: 43 | void onConnected(); 44 | void onConnectionError(QSsh::SshError); 45 | void onChannelInitialized(); 46 | void onChannelError(const QString &err); 47 | void onOpfinished(QSsh::SftpJobId job, const QString & error = QString()); 48 | 49 | private: 50 | QString m_localFilename; 51 | QString m_remoteFilename; 52 | QSsh::SftpChannel::Ptr m_channel; 53 | QSsh::SshConnection *m_connection; 54 | 55 | void parseDestination(const QString &dest); 56 | }; 57 | 58 | #endif // SECUREFILEUPLOADER_H 59 | -------------------------------------------------------------------------------- /examples/errorhandling/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(errorhandling 2 | main.cpp ) 3 | 4 | target_link_libraries(errorhandling PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 5 | 6 | -------------------------------------------------------------------------------- /examples/errorhandling/errorhandling.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | TARGET=errorhandling 3 | SOURCES=main.cpp 4 | 5 | include(../../qssh.pri) ## Required for IDE_LIBRARY_PATH and qtLibraryName 6 | 7 | # Don't clutter the example 8 | DEFINES -= QT_NO_CAST_FROM_ASCII 9 | DEFINES -= QT_NO_CAST_TO_ASCII 10 | 11 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 12 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | 4 | SUBDIRS = \ 5 | SecureUploader \ 6 | errorhandling \ 7 | remoteprocess \ 8 | ssh-shell \ 9 | sftp \ 10 | tunnel 11 | 12 | -------------------------------------------------------------------------------- /examples/remoteprocess/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(remoteprocess 2 | main.cpp remoteprocesstest.cpp argumentscollector.cpp) 3 | 4 | target_link_libraries(remoteprocess PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 5 | 6 | -------------------------------------------------------------------------------- /examples/remoteprocess/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef ARGUMENTSCOLLECTOR_H 32 | #define ARGUMENTSCOLLECTOR_H 33 | 34 | #include 35 | 36 | #include 37 | 38 | class ArgumentsCollector 39 | { 40 | public: 41 | ArgumentsCollector(const QStringList &args); 42 | QSsh::SshConnectionParameters collect(bool &success) const; 43 | private: 44 | struct ArgumentErrorException 45 | { 46 | ArgumentErrorException(const QString &error) : error(error) {} 47 | const QString error; 48 | }; 49 | 50 | void printUsage() const; 51 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 52 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 53 | const char *opt) const; 54 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; 55 | 56 | const QStringList m_arguments; 57 | }; 58 | 59 | #endif // ARGUMENTSCOLLECTOR_H 60 | -------------------------------------------------------------------------------- /examples/remoteprocess/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #include "argumentscollector.h" 32 | #include "remoteprocesstest.h" 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | QCoreApplication app(argc, argv); 46 | bool parseSuccess; 47 | const QSsh::SshConnectionParameters ¶meters 48 | = ArgumentsCollector(app.arguments()).collect(parseSuccess); 49 | if (!parseSuccess) 50 | return EXIT_FAILURE; 51 | RemoteProcessTest remoteProcessTest(parameters); 52 | remoteProcessTest.run(); 53 | return app.exec(); 54 | } 55 | -------------------------------------------------------------------------------- /examples/remoteprocess/remoteprocess.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | TARGET=remoteprocess 3 | SOURCES=main.cpp remoteprocesstest.cpp argumentscollector.cpp 4 | HEADERS=remoteprocesstest.h argumentscollector.h 5 | 6 | 7 | include(../../qssh.pri) ## Required for IDE_LIBRARY_PATH and qtLibraryName 8 | 9 | # Don't clutter the example 10 | DEFINES -= QT_NO_CAST_FROM_ASCII 11 | DEFINES -= QT_NO_CAST_TO_ASCII 12 | 13 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 14 | -------------------------------------------------------------------------------- /examples/remoteprocess/remoteprocesstest.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef REMOTEPROCESSTEST_H 32 | #define REMOTEPROCESSTEST_H 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | QT_FORWARD_DECLARE_CLASS(QTextStream) 40 | QT_FORWARD_DECLARE_CLASS(QTimer) 41 | 42 | class RemoteProcessTest : public QObject 43 | { 44 | Q_OBJECT 45 | public: 46 | RemoteProcessTest(const QSsh::SshConnectionParameters ¶ms); 47 | ~RemoteProcessTest(); 48 | void run(); 49 | 50 | private slots: 51 | void handleConnectionError(); 52 | void handleProcessStarted(); 53 | void handleProcessStdout(); 54 | void handleProcessStderr(); 55 | void handleProcessClosed(int exitStatus); 56 | void handleTimeout(); 57 | void handleReadyRead(); 58 | void handleReadyReadStdout(); 59 | void handleReadyReadStderr(); 60 | void handleConnected(); 61 | 62 | private: 63 | enum State { 64 | Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice, 65 | TestingProcessChannels 66 | }; 67 | 68 | QString testString() const; 69 | void handleSuccessfulCrashTest(); 70 | void handleSuccessfulIoTest(); 71 | 72 | const QSsh::SshConnectionParameters m_sshParams; 73 | QTimer * const m_timeoutTimer; 74 | QScopedPointer m_textStream; 75 | QSsh::SshConnection *m_sshConnection; 76 | QSsh::SshRemoteProcessRunner * const m_remoteRunner; 77 | QSsh::SshRemoteProcess::Ptr m_catProcess; 78 | QSsh::SshRemoteProcess::Ptr m_echoProcess; 79 | QByteArray m_remoteStdout; 80 | QByteArray m_remoteStderr; 81 | QByteArray m_remoteData; 82 | State m_state; 83 | bool m_started; 84 | }; 85 | 86 | 87 | #endif // REMOTEPROCESSTEST_H 88 | -------------------------------------------------------------------------------- /examples/sftp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sftp 2 | main.cpp sftptest.cpp argumentscollector.cpp) 3 | 4 | target_link_libraries(sftp PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 5 | 6 | -------------------------------------------------------------------------------- /examples/sftp/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef ARGUMENTSCOLLECTOR_H 32 | #define ARGUMENTSCOLLECTOR_H 33 | 34 | #include "parameters.h" 35 | 36 | #include 37 | 38 | class ArgumentsCollector 39 | { 40 | public: 41 | ArgumentsCollector(const QStringList &args); 42 | Parameters collect(bool &success) const; 43 | private: 44 | struct ArgumentErrorException 45 | { 46 | ArgumentErrorException(const QString &error) : error(error) {} 47 | const QString error; 48 | }; 49 | 50 | void printUsage() const; 51 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 52 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 53 | const char *opt) const; 54 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, 55 | bool &alreadyGiven) const; 56 | 57 | const QStringList m_arguments; 58 | }; 59 | 60 | #endif // ARGUMENTSCOLLECTOR_H 61 | -------------------------------------------------------------------------------- /examples/sftp/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #include "argumentscollector.h" 32 | #include "sftptest.h" 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | QCoreApplication app(argc, argv); 47 | bool parseSuccess; 48 | const Parameters parameters = ArgumentsCollector(app.arguments()).collect(parseSuccess); 49 | if (!parseSuccess) 50 | return EXIT_FAILURE; 51 | SftpTest sftpTest(parameters); 52 | sftpTest.run(); 53 | return app.exec(); 54 | } 55 | -------------------------------------------------------------------------------- /examples/sftp/parameters.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef PARAMETERS_H 32 | #define PARAMETERS_H 33 | 34 | #include 35 | 36 | struct Parameters { 37 | QSsh::SshConnectionParameters sshParams; 38 | int smallFileCount; 39 | int bigFileSize; 40 | QString remotePath; 41 | }; 42 | 43 | #endif // PARAMETERS_H 44 | -------------------------------------------------------------------------------- /examples/sftp/sftp.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | 3 | TARGET=sftp 4 | SOURCES=main.cpp sftptest.cpp argumentscollector.cpp 5 | HEADERS=sftptest.h argumentscollector.h parameters.h 6 | 7 | include(../../qssh.pri) ## Required for IDE_LIBRARY_PATH and qtLibraryName 8 | 9 | # Don't clutter the example 10 | DEFINES -= QT_NO_CAST_FROM_ASCII 11 | DEFINES -= QT_NO_CAST_TO_ASCII 12 | 13 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 14 | -------------------------------------------------------------------------------- /examples/sftp/sftptest.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SFTPTEST_H 32 | #define SFTPTEST_H 33 | 34 | #include "parameters.h" 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | QT_FORWARD_DECLARE_CLASS(QFile); 46 | 47 | class SftpTest : public QObject 48 | { 49 | Q_OBJECT 50 | public: 51 | SftpTest(const Parameters ¶ms); 52 | ~SftpTest(); 53 | void run(); 54 | 55 | private slots: 56 | void handleConnected(); 57 | void handleError(); 58 | void handleDisconnected(); 59 | void handleChannelInitialized(); 60 | void handleChannelInitializationFailure(const QString &reason); 61 | void handleSftpJobFinished(QSsh::SftpJobId job, const QSsh::SftpError errorType, const QString &error); 62 | void handleFileInfo(QSsh::SftpJobId job, const QList &fileInfoList); 63 | void handleChannelClosed(); 64 | 65 | private: 66 | typedef QHash JobMap; 67 | typedef QSharedPointer FilePtr; 68 | enum State { 69 | Inactive, Connecting, InitializingChannel, UploadingSmall, DownloadingSmall, 70 | RemovingSmall, UploadingBig, DownloadingBig, RemovingBig, CreatingDir, 71 | CheckingDirAttributes, CheckingDirContents, RemovingDir, ChannelClosing, Disconnecting 72 | }; 73 | 74 | void removeFile(const FilePtr &filePtr, bool remoteToo); 75 | void removeFiles(bool remoteToo); 76 | QString cmpFileName(const QString &localFileName) const; 77 | QString remoteFilePath(const QString &localFileName) const; 78 | void earlyDisconnectFromHost(); 79 | bool checkJobId(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, const char *activity); 80 | bool handleJobFinished(QSsh::SftpJobId job, JobMap &jobMap, 81 | const QString &error, const char *activity); 82 | bool handleJobFinished(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, const QString &error, 83 | const char *activity); 84 | bool handleBigJobFinished(QSsh::SftpJobId job, QSsh::SftpJobId expectedJob, 85 | const QString &error, const char *activity); 86 | bool compareFiles(QFile *orig, QFile *copy); 87 | 88 | const Parameters m_parameters; 89 | State m_state; 90 | bool m_error; 91 | QSsh::SshConnection *m_connection; 92 | QSsh::SftpChannel::Ptr m_channel; 93 | QList m_localSmallFiles; 94 | JobMap m_smallFilesUploadJobs; 95 | JobMap m_smallFilesDownloadJobs; 96 | JobMap m_smallFilesRemovalJobs; 97 | FilePtr m_localBigFile; 98 | QSsh::SftpJobId m_bigFileUploadJob; 99 | QSsh::SftpJobId m_bigFileDownloadJob; 100 | QSsh::SftpJobId m_bigFileRemovalJob; 101 | QSsh::SftpJobId m_mkdirJob; 102 | QSsh::SftpJobId m_statDirJob; 103 | QSsh::SftpJobId m_lsDirJob; 104 | QSsh::SftpJobId m_rmDirJob; 105 | QElapsedTimer m_bigJobTimer; 106 | QString m_remoteDirPath; 107 | QSsh::SftpFileInfo m_dirInfo; 108 | QList m_dirContents; 109 | }; 110 | 111 | 112 | #endif // SFTPTEST_H 113 | -------------------------------------------------------------------------------- /examples/ssh-shell/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ssh-hell 2 | argumentscollector.cpp main.cpp shell.cpp) 3 | 4 | target_link_libraries(ssh-shell PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 5 | 6 | -------------------------------------------------------------------------------- /examples/ssh-shell/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 | #pragma once 27 | 28 | #include 29 | 30 | #include 31 | 32 | class ArgumentsCollector 33 | { 34 | public: 35 | ArgumentsCollector(const QStringList &args); 36 | QSsh::SshConnectionParameters collect(bool &success) const; 37 | private: 38 | struct ArgumentErrorException 39 | { 40 | ArgumentErrorException(const QString &error) : error(error) {} 41 | const QString error; 42 | }; 43 | 44 | void printUsage() const; 45 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 46 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 47 | const char *opt) const; 48 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; 49 | 50 | const QStringList m_arguments; 51 | }; 52 | -------------------------------------------------------------------------------- /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 "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, &SshConnection::connected, this, &Shell::handleConnected); 46 | connect(m_connection, &SshConnection::dataAvailable, this, &Shell::handleShellMessage); 47 | connect(m_connection, &SshConnection::error, this, &Shell::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 | QCoreApplication::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 | QCoreApplication::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(), &SshRemoteProcess::started, this, &Shell::handleShellStarted); 81 | connect(m_shell.data(), &SshRemoteProcess::readyReadStandardOutput, 82 | this, &Shell::handleRemoteStdout); 83 | connect(m_shell.data(), &SshRemoteProcess::readyReadStandardError, 84 | this, &Shell::handleRemoteStderr); 85 | connect(m_shell.data(), &SshRemoteProcess::closed, this, &Shell::handleChannelClosed); 86 | m_shell->start(); 87 | } 88 | 89 | void Shell::handleShellStarted() 90 | { 91 | QSocketNotifier * const notifier = new QSocketNotifier(0, QSocketNotifier::Read, this); 92 | connect(notifier, &QSocketNotifier::activated, this, &Shell::handleStdin); 93 | } 94 | 95 | void Shell::handleRemoteStdout() 96 | { 97 | std::cout << m_shell->readAllStandardOutput().data() << std::flush; 98 | } 99 | 100 | void Shell::handleRemoteStderr() 101 | { 102 | std::cerr << m_shell->readAllStandardError().data() << std::flush; 103 | } 104 | 105 | void Shell::handleChannelClosed(int exitStatus) 106 | { 107 | std::cerr << "Shell closed. Exit status was " << exitStatus << ", exit code was " 108 | << m_shell->exitCode() << "." << std::endl; 109 | QCoreApplication::exit(exitStatus == SshRemoteProcess::NormalExit && m_shell->exitCode() == 0 110 | ? EXIT_SUCCESS : EXIT_FAILURE); 111 | } 112 | 113 | void Shell::handleStdin() 114 | { 115 | m_shell->write(m_stdin->readLine()); 116 | } 117 | -------------------------------------------------------------------------------- /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 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | namespace QSsh { 32 | class SshConnection; 33 | class SshConnectionParameters; 34 | class SshRemoteProcess; 35 | } 36 | 37 | QT_BEGIN_NAMESPACE 38 | class QByteArray; 39 | class QFile; 40 | class QString; 41 | QT_END_NAMESPACE 42 | 43 | class Shell : public QObject 44 | { 45 | Q_OBJECT 46 | public: 47 | Shell(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0); 48 | ~Shell(); 49 | 50 | void run(); 51 | 52 | private: 53 | void handleConnected(); 54 | void handleConnectionError(); 55 | void handleRemoteStdout(); 56 | void handleRemoteStderr(); 57 | void handleShellMessage(const QString &message); 58 | void handleChannelClosed(int exitStatus); 59 | void handleShellStarted(); 60 | void handleStdin(); 61 | 62 | QSsh::SshConnection *m_connection; 63 | QSharedPointer m_shell; 64 | QFile * const m_stdin; 65 | }; 66 | -------------------------------------------------------------------------------- /examples/ssh-shell/ssh-shell.pro: -------------------------------------------------------------------------------- 1 | include(../../qssh.pri) 2 | QT += network 3 | 4 | TARGET=shell 5 | SOURCES=main.cpp shell.cpp argumentscollector.cpp 6 | HEADERS=shell.h argumentscollector.h 7 | 8 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 9 | -------------------------------------------------------------------------------- /examples/tunnel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tunnel 2 | main.cpp 3 | argumentscollector.cpp 4 | directtunnel.cpp 5 | forwardtunnel.cpp) 6 | 7 | target_link_libraries(tunnel PRIVATE QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${BOTAN_LIB}) 8 | 9 | -------------------------------------------------------------------------------- /examples/tunnel/argumentscollector.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | 33 | #ifndef ARGUMENTSCOLLECTOR_H 34 | #define ARGUMENTSCOLLECTOR_H 35 | 36 | #include 37 | 38 | #include 39 | 40 | class ArgumentsCollector 41 | { 42 | public: 43 | ArgumentsCollector(const QStringList &args); 44 | QSsh::SshConnectionParameters collect(bool &success) const; 45 | private: 46 | struct ArgumentErrorException 47 | { 48 | ArgumentErrorException(const QString &error) : error(error) {} 49 | const QString error; 50 | }; 51 | 52 | void printUsage() const; 53 | bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; 54 | bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, 55 | const char *opt) const; 56 | bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; 57 | 58 | const QStringList m_arguments; 59 | }; 60 | 61 | #endif // ARGUMENTSCOLLECTOR_H 62 | -------------------------------------------------------------------------------- /examples/tunnel/directtunnel.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | #ifndef TUNNEL_H 33 | #define TUNNEL_H 34 | 35 | #include 36 | #include 37 | 38 | QT_BEGIN_NAMESPACE 39 | class QTcpServer; 40 | class QTcpSocket; 41 | QT_END_NAMESPACE 42 | 43 | namespace QSsh { 44 | class SshConnection; 45 | class SshConnectionParameters; 46 | class SshDirectTcpIpTunnel; 47 | } 48 | 49 | class DirectTunnel : public QObject 50 | { 51 | Q_OBJECT 52 | public: 53 | DirectTunnel(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0); 54 | ~DirectTunnel(); 55 | 56 | void run(); 57 | 58 | signals: 59 | void finished(int errorCode); 60 | 61 | private slots: 62 | void handleConnected(); 63 | void handleConnectionError(); 64 | void handleServerData(); 65 | void handleInitialized(); 66 | void handleTunnelError(const QString &reason); 67 | void handleTunnelClosed(); 68 | void handleNewConnection(); 69 | void handleSocketError(); 70 | void handleClientData(); 71 | void handleTimeout(); 72 | 73 | private: 74 | QSsh::SshConnection * const m_connection; 75 | QSharedPointer m_tunnel; 76 | QTcpServer * const m_targetServer; 77 | QTcpSocket *m_targetSocket; 78 | quint16 m_targetPort; 79 | QByteArray m_dataReceivedFromServer; 80 | QByteArray m_dataReceivedFromClient; 81 | bool m_expectingChannelClose; 82 | }; 83 | 84 | #endif // TUNNEL_H 85 | -------------------------------------------------------------------------------- /examples/tunnel/forwardtunnel.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 | #pragma once 27 | 28 | #include "qssh/ssherrors.h" 29 | 30 | #include 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | class QTcpSocket; 35 | QT_END_NAMESPACE 36 | 37 | namespace QSsh { 38 | class SshConnection; 39 | class SshConnectionParameters; 40 | class SshTcpIpForwardServer; 41 | } 42 | 43 | class ForwardTunnel : public QObject 44 | { 45 | Q_OBJECT 46 | public: 47 | ForwardTunnel(const QSsh::SshConnectionParameters ¶meters, 48 | QObject *parent = 0); 49 | void run(); 50 | 51 | signals: 52 | void finished(int exitCode); 53 | 54 | private slots: 55 | void handleConnected(); 56 | void handleConnectionError(QSsh::SshError error); 57 | void handleInitialized(); 58 | void handleServerError(const QString &reason); 59 | void handleServerClosed(); 60 | void handleNewConnection(); 61 | void handleSocketError(); 62 | 63 | private: 64 | QSsh::SshConnection * const m_connection; 65 | QSharedPointer m_server; 66 | QTcpSocket *m_targetSocket; 67 | quint16 m_targetPort; 68 | 69 | QByteArray m_dataReceivedFromServer; 70 | QByteArray m_dataReceivedFromClient; 71 | }; 72 | -------------------------------------------------------------------------------- /examples/tunnel/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | #include "../remoteprocess/argumentscollector.h" 33 | #include "directtunnel.h" 34 | #include "forwardtunnel.h" 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | QCoreApplication app(argc, argv); 48 | bool parseSuccess; 49 | QSsh::SshConnectionParameters parameters 50 | = ArgumentsCollector(app.arguments()).collect(parseSuccess); 51 | 52 | parameters.setHost("127.0.0.1"); 53 | if (!parseSuccess) 54 | return EXIT_FAILURE; 55 | 56 | DirectTunnel direct(parameters); 57 | 58 | parameters.setHost("127.0.0.2"); 59 | ForwardTunnel forward(parameters); 60 | forward.run(); 61 | 62 | QObject::connect(&forward, &ForwardTunnel::finished, &direct, &DirectTunnel::run); 63 | QObject::connect(&direct, &DirectTunnel::finished, &app, &QCoreApplication::exit); 64 | 65 | return app.exec(); 66 | } 67 | -------------------------------------------------------------------------------- /examples/tunnel/tunnel.pro: -------------------------------------------------------------------------------- 1 | QT += core network 2 | TARGET =tunnel 3 | SOURCES = \ 4 | main.cpp \ 5 | argumentscollector.cpp \ 6 | directtunnel.cpp \ 7 | forwardtunnel.cpp 8 | HEADERS = \ 9 | argumentscollector.h \ 10 | directtunnel.h \ 11 | forwardtunnel.h 12 | 13 | include(../../qssh.pri) ## Required for IDE_LIBRARY_PATH and qtLibraryName 14 | 15 | # Don't clutter the example 16 | DEFINES -= QT_NO_CAST_FROM_ASCII 17 | DEFINES -= QT_NO_CAST_TO_ASCII 18 | 19 | LIBS += -L$$IDE_LIBRARY_PATH -l$$qtLibraryName(botan-2) -l$$qtLibraryName(QSsh) 20 | -------------------------------------------------------------------------------- /qssh.pri: -------------------------------------------------------------------------------- 1 | !isEmpty(QSSH_PRI_INCLUDED):error("qssh.pri already included") 2 | QSSH_PRI_INCLUDED = 1 3 | 4 | isEmpty(QSSH_PREFIX) { 5 | unix:!macx: QSSH_PREFIX = $$[QT_INSTALL_PREFIX] 6 | } 7 | 8 | defineReplace(cleanPath) { 9 | return($$clean_path($$1)) 10 | } 11 | 12 | defineReplace(qtLibraryName) { 13 | unset(LIBRARY_NAME) 14 | LIBRARY_NAME = $$1 15 | CONFIG(debug, debug|release) { 16 | !debug_and_release|build_pass { 17 | mac:RET = $$member(LIBRARY_NAME, 0)_debug 18 | else:win32:RET = $$member(LIBRARY_NAME, 0)d 19 | } 20 | } 21 | isEmpty(RET):RET = $$LIBRARY_NAME 22 | return($$RET) 23 | } 24 | 25 | isEmpty(IDE_LIBRARY_BASENAME) { 26 | IDE_LIBRARY_BASENAME = lib 27 | } 28 | 29 | isEmpty(IDE_BUILD_TREE) { 30 | sub_dir = $$_PRO_FILE_PWD_ 31 | sub_dir ~= s,^$$re_escape($$PWD),, 32 | IDE_BUILD_TREE = $$cleanPath($$OUT_PWD) 33 | IDE_BUILD_TREE ~= s,$$re_escape($$sub_dir)$,, 34 | } 35 | IDE_APP_PATH = $$IDE_BUILD_TREE/bin 36 | macx { 37 | IDE_APP_TARGET = "Qt Creator" 38 | IDE_LIBRARY_PATH = $$IDE_APP_PATH/$${IDE_APP_TARGET}.app/Contents/PlugIns 39 | IDE_LIBEXEC_PATH = $$IDE_APP_PATH/$${IDE_APP_TARGET}.app/Contents/Resources 40 | IDE_BIN_PATH = $$IDE_APP_PATH/$${IDE_APP_TARGET}.app/Contents/MacOS 41 | copydata = 1 42 | isEmpty(TIGER_COMPAT_MODE):TIGER_COMPAT_MODE=$$(QSSH_TIGER_COMPAT) 43 | isEmpty(TIGER_COMPAT_MODE) { 44 | QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5 45 | QMAKE_LFLAGS *= -mmacosx-version-min=10.5 46 | } 47 | } else { 48 | contains(TEMPLATE, vc.*):vcproj = 1 49 | IDE_APP_TARGET = qtcreator 50 | IDE_LIBRARY_PATH = $$IDE_BUILD_TREE/$$IDE_LIBRARY_BASENAME 51 | IDE_LIBEXEC_PATH = $$IDE_APP_PATH # FIXME 52 | IDE_BIN_PATH = $$IDE_APP_PATH 53 | } 54 | 55 | clang { 56 | QMAKE_CXXFLAGS += -Wno-gnu-zero-variadic-macro-arguments 57 | } 58 | 59 | QT += widgets 60 | 61 | CONFIG += warn_on 62 | 63 | # Find botan2 64 | CONFIG += link_pkgconfig 65 | PKGCONFIG += botan-2 66 | 67 | CONFIG += depend_includepath 68 | 69 | LIBS += -L$$IDE_LIBRARY_PATH 70 | LIBS += -l$$qtLibraryName(botan-2) 71 | INCLUDEPATH += $${PWD}/src/libs/ 72 | 73 | DEFINES += QT_NO_CAST_FROM_ASCII 74 | DEFINES += QT_NO_CAST_TO_ASCII 75 | DEFINES += QT_USE_QSTRINGBUILDER 76 | 77 | win32-msvc* { 78 | #Don't warn about sprintf, fopen etc being 'unsafe' 79 | DEFINES += _CRT_SECURE_NO_WARNINGS 80 | } 81 | -------------------------------------------------------------------------------- /qssh.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00 4 | 5 | 6 | SUBDIRS = \ 7 | src \ 8 | examples \ 9 | tests 10 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(libs) -------------------------------------------------------------------------------- /src/libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(qssh) 2 | -------------------------------------------------------------------------------- /src/libs/libs.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | 4 | SUBDIRS = \ 5 | qssh 6 | -------------------------------------------------------------------------------- /src/libs/qssh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(QSsh 2 | sshsendfacility.cpp 3 | sshremoteprocess.cpp 4 | sshpacketparser.cpp 5 | sshpacket.cpp 6 | sshoutgoingpacket.cpp 7 | sshkeygenerator.cpp 8 | sshkeyexchange.cpp 9 | sshincomingpacket.cpp 10 | sshcryptofacility.cpp 11 | sshconnection.cpp 12 | sshchannelmanager.cpp 13 | sshchannel.cpp 14 | sshcapabilities.cpp 15 | sftppacket.cpp 16 | sftpoutgoingpacket.cpp 17 | sftpoperation.cpp 18 | sftpincomingpacket.cpp 19 | sftpdefs.cpp 20 | sftpchannel.cpp 21 | sshremoteprocessrunner.cpp 22 | sshconnectionmanager.cpp 23 | sshkeypasswordretriever.cpp 24 | sftpfilesystemmodel.cpp 25 | sshdirecttcpiptunnel.cpp 26 | sshhostkeydatabase.cpp 27 | sshlogging.cpp 28 | sshtcpipforwardserver.cpp 29 | sshtcpiptunnel.cpp 30 | sshforwardedtcpiptunnel.cpp 31 | sshagent.cpp 32 | sshx11channel.cpp 33 | sshx11inforetriever.cpp 34 | opensshkeyfilereader.cpp 35 | qssh.qrc) 36 | 37 | get_property(BOTAN_LIB GLOBAL PROPERTY BOTAN_LIB) 38 | target_link_libraries( QSsh Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets ${BOTAN_LIB}) 39 | 40 | # state that anybody linking to us needs to include the current source dir 41 | target_include_directories(QSsh 42 | INTERFACE 43 | $ 44 | $ 45 | $ 46 | $ 47 | ) 48 | 49 | #INSTALL RULES 50 | install( 51 | DIRECTORY . 52 | DESTINATION include 53 | COMPONENT headers 54 | FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h" 55 | ) 56 | install(TARGETS QSsh DESTINATION lib EXPORT QSsh-targets) 57 | -------------------------------------------------------------------------------- /src/libs/qssh/images/dir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandsmark/QSsh/3942e51b529165a2ca7c7f5bd09b298fee8b41a4/src/libs/qssh/images/dir.png -------------------------------------------------------------------------------- /src/libs/qssh/images/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandsmark/QSsh/3942e51b529165a2ca7c7f5bd09b298fee8b41a4/src/libs/qssh/images/help.png -------------------------------------------------------------------------------- /src/libs/qssh/images/unknownfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandsmark/QSsh/3942e51b529165a2ca7c7f5bd09b298fee8b41a4/src/libs/qssh/images/unknownfile.png -------------------------------------------------------------------------------- /src/libs/qssh/opensshkeyfilereader_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 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 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | 35 | namespace Botan { 36 | class Private_Key; 37 | class RandomNumberGenerator; 38 | } 39 | 40 | namespace QSsh { 41 | namespace Internal { 42 | 43 | class OpenSshKeyFileReader 44 | { 45 | public: 46 | OpenSshKeyFileReader(Botan::RandomNumberGenerator &rng) : m_rng(rng) {} 47 | 48 | bool parseKey(const QByteArray &privKeyFileContents); 49 | QByteArray keyType() const { return m_keyType; } 50 | std::unique_ptr privateKey() const; 51 | QList allParameters() const { return m_parameters; } 52 | QList publicParameters() const; 53 | 54 | private: 55 | void doParse(const QByteArray &payload); 56 | void parseKdfOptions(const QByteArray &kdfOptions); 57 | void decryptPrivateKeyList(); 58 | void parsePrivateKeyList(); 59 | [[noreturn]] void throwException(const QString &reason); 60 | 61 | Botan::RandomNumberGenerator &m_rng; 62 | QByteArray m_keyType; 63 | QList m_parameters; 64 | QByteArray m_cipherName; 65 | QByteArray m_kdf; 66 | QByteArray m_salt; 67 | quint32 m_rounds; 68 | QByteArray m_privateKeyList; 69 | }; 70 | 71 | } // namespace Internal 72 | } // namespace QSsh 73 | 74 | -------------------------------------------------------------------------------- /src/libs/qssh/qssh.pri: -------------------------------------------------------------------------------- 1 | LIBS *= -l$$qtLibraryName(QSsh) 2 | -------------------------------------------------------------------------------- /src/libs/qssh/qssh.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = QSsh 3 | QT += network 4 | DEFINES += QTCSSH_LIBRARY 5 | 6 | #Enable debug log 7 | #DEFINES += CREATOR_SSH_DEBUG 8 | 9 | INCLUDEPATH += $$QSSH_PREFIX/include/botan-2/ 10 | DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00 11 | 12 | include(../../../qssh.pri) 13 | 14 | win32 { 15 | DLLDESTDIR = $$[QT_INSTALL_LIBS] 16 | } 17 | 18 | !win32-msvc* { 19 | QMAKE_CXXFLAGS += -Wextra -pedantic 20 | } 21 | 22 | DESTDIR = $$IDE_LIBRARY_PATH 23 | 24 | TARGET = $$qtLibraryName($$TARGET) 25 | 26 | CONFIG += shared dll warn_on 27 | 28 | DEFINES += QT_DEPRECATED_WARNINGS 29 | 30 | contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols 31 | 32 | SOURCES = $$PWD/sshsendfacility.cpp \ 33 | $$PWD/sshremoteprocess.cpp \ 34 | $$PWD/sshpacketparser.cpp \ 35 | $$PWD/sshpacket.cpp \ 36 | $$PWD/sshoutgoingpacket.cpp \ 37 | $$PWD/sshkeygenerator.cpp \ 38 | $$PWD/sshkeyexchange.cpp \ 39 | $$PWD/sshincomingpacket.cpp \ 40 | $$PWD/sshcryptofacility.cpp \ 41 | $$PWD/sshconnection.cpp \ 42 | $$PWD/sshchannelmanager.cpp \ 43 | $$PWD/sshchannel.cpp \ 44 | $$PWD/sshcapabilities.cpp \ 45 | $$PWD/sftppacket.cpp \ 46 | $$PWD/sftpoutgoingpacket.cpp \ 47 | $$PWD/sftpoperation.cpp \ 48 | $$PWD/sftpincomingpacket.cpp \ 49 | $$PWD/sftpdefs.cpp \ 50 | $$PWD/sftpchannel.cpp \ 51 | $$PWD/sshremoteprocessrunner.cpp \ 52 | $$PWD/sshconnectionmanager.cpp \ 53 | $$PWD/sshkeypasswordretriever.cpp \ 54 | $$PWD/sftpfilesystemmodel.cpp \ 55 | $$PWD/sshdirecttcpiptunnel.cpp \ 56 | $$PWD/sshhostkeydatabase.cpp \ 57 | $$PWD/sshlogging.cpp \ 58 | $$PWD/sshtcpipforwardserver.cpp \ 59 | $$PWD/sshtcpiptunnel.cpp \ 60 | $$PWD/sshforwardedtcpiptunnel.cpp \ 61 | $$PWD/sshagent.cpp \ 62 | $$PWD/sshx11channel.cpp \ 63 | $$PWD/sshx11inforetriever.cpp \ 64 | $$PWD/opensshkeyfilereader.cpp \ 65 | 66 | PUBLIC_HEADERS = \ 67 | $$PWD/sftpdefs.h \ 68 | $$PWD/ssherrors.h \ 69 | $$PWD/sshremoteprocess.h \ 70 | $$PWD/sftpchannel.h \ 71 | $$PWD/sshkeygenerator.h \ 72 | $$PWD/sshremoteprocessrunner.h \ 73 | $$PWD/sshconnectionmanager.h \ 74 | $$PWD/sshpseudoterminal.h \ 75 | $$PWD/sftpfilesystemmodel.h \ 76 | $$PWD/sshdirecttcpiptunnel.h \ 77 | $$PWD/sshtcpipforwardserver.h \ 78 | $$PWD/sshhostkeydatabase.h \ 79 | $$PWD/sshforwardedtcpiptunnel.h \ 80 | $$PWD/ssh_global.h \ 81 | $$PWD/sshconnection.h \ 82 | 83 | HEADERS = $$PUBLIC_HEADERS \ 84 | $$PWD/sshsendfacility_p.h \ 85 | $$PWD/sshremoteprocess_p.h \ 86 | $$PWD/sshpacketparser_p.h \ 87 | $$PWD/sshpacket_p.h \ 88 | $$PWD/sshoutgoingpacket_p.h \ 89 | $$PWD/sshkeyexchange_p.h \ 90 | $$PWD/sshincomingpacket_p.h \ 91 | $$PWD/sshexception_p.h \ 92 | $$PWD/sshcryptofacility_p.h \ 93 | $$PWD/sshconnection_p.h \ 94 | $$PWD/sshchannelmanager_p.h \ 95 | $$PWD/sshchannel_p.h \ 96 | $$PWD/sshcapabilities_p.h \ 97 | $$PWD/sshbotanconversions_p.h \ 98 | $$PWD/sftppacket_p.h \ 99 | $$PWD/sftpoutgoingpacket_p.h \ 100 | $$PWD/sftpoperation_p.h \ 101 | $$PWD/sftpincomingpacket_p.h \ 102 | $$PWD/sftpchannel_p.h \ 103 | $$PWD/sshkeypasswordretriever_p.h \ 104 | $$PWD/sshdirecttcpiptunnel_p.h \ 105 | $$PWD/sshlogging_p.h \ 106 | $$PWD/sshtcpipforwardserver_p.h \ 107 | $$PWD/sshtcpiptunnel_p.h \ 108 | $$PWD/sshforwardedtcpiptunnel_p.h \ 109 | $$PWD/sshagent_p.h \ 110 | $$PWD/sshx11channel_p.h \ 111 | $$PWD/sshx11displayinfo_p.h \ 112 | $$PWD/sshx11inforetriever_p.h \ 113 | $$PWD/opensshkeyfilereader_p.h \ 114 | 115 | RESOURCES += $$PWD/qssh.qrc 116 | 117 | 118 | headers.files = $$PUBLIC_HEADERS 119 | headers.path = $$[QT_INSTALL_PREFIX]/include/QSsh 120 | 121 | target.path = $$[QT_INSTALL_LIBS] 122 | 123 | INSTALLS += target headers 124 | -------------------------------------------------------------------------------- /src/libs/qssh/qssh.qbs: -------------------------------------------------------------------------------- 1 | import qbs.base 1.0 2 | import "../QtcLibrary.qbs" as QtcLibrary 3 | 4 | QtcLibrary { 5 | name: "QtcSsh" 6 | 7 | cpp.defines: base.concat(["QSSH_LIBRARY"]) 8 | cpp.includePaths: [ 9 | ".", 10 | "..", 11 | "../..", 12 | buildDirectory 13 | ] 14 | 15 | Depends { name: "cpp" } 16 | Depends { name: "Qt"; submodules: ["widgets", "network" ] } 17 | Depends { name: "Botan" } 18 | 19 | files: [ 20 | "sftpchannel.h", "sftpchannel_p.h", "sftpchannel.cpp", 21 | "sftpdefs.cpp", "sftpdefs.h", 22 | "sftpincomingpacket.cpp", "sftpincomingpacket_p.h", 23 | "sftpoperation.cpp", "sftpoperation_p.h", 24 | "sftpoutgoingpacket.cpp", "sftpoutgoingpacket_p.h", 25 | "sftppacket.cpp", "sftppacket_p.h", 26 | "sshcapabilities_p.h", "sshcapabilities.cpp", 27 | "sshchannel.cpp", "sshchannel_p.h", 28 | "sshchannelmanager.cpp", "sshchannelmanager_p.h", 29 | "sshconnection.h", "sshconnection_p.h", "sshconnection.cpp", 30 | "sshconnectionmanager.cpp", "sshconnectionmanager.h", 31 | "sshcryptofacility.cpp", "sshcryptofacility_p.h", 32 | "sshkeyexchange.cpp", "sshkeyexchange_p.h", 33 | "sshkeypasswordretriever_p.h", 34 | "sshoutgoingpacket.cpp", "sshoutgoingpacket_p.h", 35 | "sshpacket.cpp", "sshpacket_p.h", 36 | "sshpacketparser.cpp", "sshpacketparser_p.h", 37 | "sshremoteprocess.cpp", "sshremoteprocess.h", "sshremoteprocess_p.h", 38 | "sshdirecttcpiptunnel.h", "sshdirecttcpiptunnel_p.h", "sshdirecttcpiptunnel.cpp", 39 | "sshremoteprocessrunner.cpp", "sshremoteprocessrunner.h", 40 | "sshsendfacility.cpp", "sshsendfacility_p.h", 41 | "sshkeypasswordretriever.cpp", 42 | "sshkeygenerator.cpp", "sshkeygenerator.h", 43 | "sshkeycreationdialog.cpp", "sshkeycreationdialog.h", "sshkeycreationdialog.ui", 44 | "sftpfilesystemmodel.cpp", "sftpfilesystemmodel.h", 45 | "sshincomingpacket_p.h", "sshincomingpacket.cpp", 46 | "ssherrors.h", 47 | "sshexception_p.h", 48 | "sshpseudoterminal.h", 49 | "sshbotanconversions_p.h" 50 | ] 51 | 52 | ProductModule { 53 | Depends { name: "cpp" } 54 | Depends { name: "Qt"; submodules: ["widgets", "network"] } 55 | cpp.includePaths: [".."] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/libs/qssh/qssh.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/dir.png 4 | images/help.png 5 | images/unknownfile.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/libs/qssh/sftpdefs.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #include "sftpdefs.h" 32 | 33 | namespace QSsh { const SftpJobId SftpInvalidJob = 0; } 34 | -------------------------------------------------------------------------------- /src/libs/qssh/sftpdefs.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SFTPDEFS_H 32 | #define SFTPDEFS_H 33 | 34 | #include "ssh_global.h" 35 | 36 | #include 37 | #include 38 | 39 | /*! 40 | * \namespace QSsh 41 | * \brief The namespace used for the entire library 42 | */ 43 | namespace QSsh { 44 | 45 | 46 | /*! 47 | *\brief Unique ID used for tracking individual jobs. 48 | */ 49 | typedef quint32 SftpJobId; 50 | 51 | /*! 52 | Special ID representing an invalid job, e. g. if a requested job could not be started. 53 | */ 54 | QSSH_EXPORT extern const SftpJobId SftpInvalidJob; 55 | 56 | 57 | /*! 58 | * \brief The behavior when uploading a file and the remote path already exists 59 | */ 60 | enum SftpOverwriteMode { 61 | /*! Overwrite any existing files */ 62 | SftpOverwriteExisting, 63 | 64 | /*! Append new content if the file already exists */ 65 | SftpAppendToExisting, 66 | 67 | /*! If the file or directory already exists skip it */ 68 | SftpSkipExisting 69 | }; 70 | 71 | /*! 72 | * \brief The type of a remote file. 73 | */ 74 | enum SftpFileType { FileTypeRegular, FileTypeDirectory, FileTypeOther, FileTypeUnknown }; 75 | 76 | /*! 77 | * \brief Possible errors. 78 | */ 79 | enum SftpError { NoError, EndOfFile, FileNotFound, PermissionDenied, GenericFailure, BadMessage, NoConnection, ConnectionLost, UnsupportedOperation }; 80 | 81 | /*! 82 | \brief Contains information about a remote file. 83 | */ 84 | class QSSH_EXPORT SftpFileInfo 85 | { 86 | public: 87 | SftpFileInfo() : type(FileTypeUnknown), sizeValid(false), permissionsValid(false) { } 88 | 89 | /// The remote file name, only file attribute required by the RFC to be present so this is always set 90 | QString name; 91 | 92 | /// The type of file 93 | SftpFileType type = FileTypeUnknown; 94 | 95 | /// The remote file size in bytes. 96 | quint64 size = 0; 97 | 98 | /// The permissions set on the file, might be empty as the RFC allows an SFTP server not to support any file attributes beyond the name. 99 | QFileDevice::Permissions permissions{}; 100 | 101 | /// Last time file was accessed. 102 | quint32 atime = 0; 103 | 104 | /// Last time file was modified. 105 | quint32 mtime = 0; 106 | 107 | /// If the timestamps (\ref atime and \ref mtime) are valid, the RFC allows an SFTP server not to support any file attributes beyond the name. 108 | bool timestampsValid = false; 109 | 110 | /// The RFC allows an SFTP server not to support any file attributes beyond the name. 111 | bool sizeValid = false; 112 | 113 | /// The RFC allows an SFTP server not to support any file attributes beyond the name. 114 | bool permissionsValid = false; 115 | }; 116 | 117 | } // namespace QSsh 118 | 119 | #endif // SFTPDEFS_H 120 | -------------------------------------------------------------------------------- /src/libs/qssh/sftpfilesystemmodel.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | #ifndef SFTPFILESYSTEMMODEL_H 31 | #define SFTPFILESYSTEMMODEL_H 32 | 33 | #include "sftpdefs.h" 34 | 35 | #include "ssh_global.h" 36 | 37 | #include 38 | 39 | namespace QSsh { 40 | class SshConnectionParameters; 41 | 42 | namespace Internal { class SftpFileSystemModelPrivate; } 43 | 44 | // Very simple read-only model. Symbolic links are not followed. 45 | class QSSH_EXPORT SftpFileSystemModel : public QAbstractItemModel 46 | { 47 | Q_OBJECT 48 | public: 49 | explicit SftpFileSystemModel(QObject *parent = nullptr); 50 | ~SftpFileSystemModel(); 51 | 52 | /* 53 | * Once this is called, an SFTP connection is established and the model is populated. 54 | * The effect of additional calls is undefined. 55 | */ 56 | void setSshConnection(const SshConnectionParameters &sshParams); 57 | 58 | void setRootDirectory(const QString &path); // Default is "/". 59 | QString rootDirectory() const; 60 | 61 | SftpJobId downloadFile(const QModelIndex &index, const QString &targetFilePath); 62 | 63 | // Use this to get the full path of a file or directory. 64 | static const int PathRole = Qt::UserRole; 65 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 66 | 67 | signals: 68 | /* 69 | * E.g. "Permission denied". Note that this can happen without direct user intervention, 70 | * due to e.g. the view calling rowCount() on a non-readable directory. This signal should 71 | * therefore not result in a message box or similar, since it might occur very often. 72 | */ 73 | void sftpOperationFailed(const QString &errorMessage); 74 | 75 | /* 76 | * This error is not recoverable. The model will not have any content after 77 | * the signal has been emitted. 78 | */ 79 | void connectionError(const QString &errorMessage); 80 | 81 | // Success <=> error.isEmpty(). 82 | void sftpOperationFinished(QSsh::SftpJobId, const QString &error); 83 | 84 | private: 85 | void handleSshConnectionEstablished(); 86 | void handleSshConnectionFailure(); 87 | void handleSftpChannelInitialized(); 88 | void handleSftpChannelError(const QString &reason); 89 | void handleFileInfo(QSsh::SftpJobId jobId, const QList &fileInfoList); 90 | void handleSftpJobFinished(QSsh::SftpJobId jobId, const SftpError error, const QString &errorMessage); 91 | 92 | int columnCount(const QModelIndex &parent = QModelIndex()) const; 93 | Qt::ItemFlags flags(const QModelIndex &index) const; 94 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 95 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 96 | QModelIndex parent(const QModelIndex &child) const; 97 | int rowCount(const QModelIndex &parent = QModelIndex()) const; 98 | 99 | void statRootDirectory(); 100 | void shutDown(); 101 | 102 | Internal::SftpFileSystemModelPrivate * const d; 103 | }; 104 | 105 | } // namespace QSsh; 106 | 107 | #endif // SFTPFILESYSTEMMODEL_H 108 | -------------------------------------------------------------------------------- /src/libs/qssh/sftpincomingpacket_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SFTPINCOMINGPACKET_P_H 32 | #define SFTPINCOMINGPACKET_P_H 33 | 34 | #include "sftppacket_p.h" 35 | 36 | namespace QSsh { 37 | namespace Internal { 38 | 39 | struct SftpHandleResponse { 40 | quint32 requestId; 41 | QByteArray handle; 42 | }; 43 | 44 | struct SftpStatusResponse { 45 | quint32 requestId; 46 | SftpStatusCode status; 47 | QString errorString; 48 | QByteArray language; 49 | }; 50 | 51 | struct SftpFileAttributes { 52 | bool sizePresent; 53 | bool timesPresent; 54 | bool uidAndGidPresent; 55 | bool permissionsPresent; 56 | quint64 size; 57 | quint32 uid; 58 | quint32 gid; 59 | quint32 permissions; 60 | quint32 atime; 61 | quint32 mtime; 62 | }; 63 | 64 | struct SftpFile { 65 | QString fileName; 66 | QString longName; // Not present in later RFCs, so we don't expose this to the user. 67 | SftpFileAttributes attributes; 68 | }; 69 | 70 | struct SftpNameResponse { 71 | quint32 requestId; 72 | QList files; 73 | }; 74 | 75 | struct SftpDataResponse { 76 | quint32 requestId; 77 | QByteArray data; 78 | }; 79 | 80 | struct SftpAttrsResponse { 81 | quint32 requestId; 82 | SftpFileAttributes attrs; 83 | }; 84 | 85 | class SftpIncomingPacket : public AbstractSftpPacket 86 | { 87 | public: 88 | SftpIncomingPacket(); 89 | 90 | void consumeData(QByteArray &data); 91 | void clear(); 92 | bool isComplete() const; 93 | quint32 extractServerVersion() const; 94 | SftpHandleResponse asHandleResponse() const; 95 | SftpStatusResponse asStatusResponse() const; 96 | SftpNameResponse asNameResponse() const; 97 | SftpDataResponse asDataResponse() const; 98 | SftpAttrsResponse asAttrsResponse() const; 99 | 100 | private: 101 | void moveFirstBytes(QByteArray &target, QByteArray &source, int n); 102 | 103 | SftpFileAttributes asFileAttributes(quint32 &offset) const; 104 | SftpFile asFile(quint32 &offset) const; 105 | 106 | quint32 m_length; 107 | }; 108 | 109 | } // namespace Internal 110 | } // namespace QSsh 111 | 112 | #endif // SFTPINCOMINGPACKET_P_H 113 | -------------------------------------------------------------------------------- /src/libs/qssh/sftpoutgoingpacket_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SFTPOUTGOINGPACKET_P_H 32 | #define SFTPOUTGOINGPACKET_P_H 33 | 34 | #include "sftppacket_p.h" 35 | #include "sftpdefs.h" 36 | 37 | namespace QSsh { 38 | namespace Internal { 39 | 40 | class SftpOutgoingPacket : public AbstractSftpPacket 41 | { 42 | public: 43 | SftpOutgoingPacket(); 44 | SftpOutgoingPacket &generateInit(quint32 version); 45 | SftpOutgoingPacket &generateStat(const QString &path, quint32 requestId); 46 | SftpOutgoingPacket &generateOpenDir(const QString &path, quint32 requestId); 47 | SftpOutgoingPacket &generateReadDir(const QByteArray &handle, 48 | quint32 requestId); 49 | SftpOutgoingPacket &generateCloseHandle(const QByteArray &handle, 50 | quint32 requestId); 51 | SftpOutgoingPacket &generateMkDir(const QString &path, quint32 requestId); 52 | SftpOutgoingPacket &generateRmDir(const QString &path, quint32 requestId); 53 | SftpOutgoingPacket &generateRm(const QString &path, quint32 requestId); 54 | SftpOutgoingPacket &generateRename(const QString &oldPath, 55 | const QString &newPath, quint32 requestId); 56 | SftpOutgoingPacket &generateOpenFileForWriting(const QString &path, 57 | SftpOverwriteMode mode, quint32 permissions, quint32 requestId); 58 | SftpOutgoingPacket &generateOpenFileForReading(const QString &path, 59 | quint32 requestId); 60 | SftpOutgoingPacket &generateReadFile(const QByteArray &handle, 61 | quint64 offset, quint32 length, quint32 requestId); 62 | SftpOutgoingPacket &generateFstat(const QByteArray &handle, 63 | quint32 requestId); 64 | SftpOutgoingPacket &generateWriteFile(const QByteArray &handle, 65 | quint64 offset, const QByteArray &data, quint32 requestId); 66 | 67 | // Note: OpenSSH's SFTP server has a bug that reverses the filePath and target 68 | // arguments, so this operation is not portable. 69 | SftpOutgoingPacket &generateCreateLink(const QString &filePath, const QString &target, 70 | quint32 requestId); 71 | 72 | static const quint32 DefaultPermissions; 73 | 74 | private: 75 | static QByteArray encodeString(const QString &string); 76 | 77 | enum OpenType { Read, Write }; 78 | SftpOutgoingPacket &generateOpenFile(const QString &path, OpenType openType, 79 | SftpOverwriteMode mode, const QList &attributes, quint32 requestId); 80 | 81 | SftpOutgoingPacket &init(SftpPacketType type, quint32 requestId); 82 | SftpOutgoingPacket &appendInt(quint32 value); 83 | SftpOutgoingPacket &appendInt64(quint64 value); 84 | SftpOutgoingPacket &appendString(const QString &string); 85 | SftpOutgoingPacket &appendString(const QByteArray &string); 86 | SftpOutgoingPacket &finalize(); 87 | }; 88 | 89 | } // namespace Internal 90 | } // namespace QSsh 91 | 92 | #endif // SFTPOUTGOINGPACKET_P_H 93 | -------------------------------------------------------------------------------- /src/libs/qssh/sftppacket.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #include "sftppacket_p.h" 32 | 33 | #include "sshpacketparser_p.h" 34 | 35 | namespace QSsh { 36 | namespace Internal { 37 | 38 | // There's no "standard" or negotiation between server and client for this, so 39 | // just use the same as openssh's sftp implementation 40 | const quint32 AbstractSftpPacket::MaxDataSize = 32768; 41 | const quint32 AbstractSftpPacket::MaxPacketSize = 256 * 1024; 42 | 43 | const int AbstractSftpPacket::TypeOffset = 4; 44 | const int AbstractSftpPacket::RequestIdOffset = TypeOffset + 1; 45 | const int AbstractSftpPacket::PayloadOffset = RequestIdOffset + 4; 46 | 47 | AbstractSftpPacket::AbstractSftpPacket() 48 | { 49 | } 50 | 51 | quint32 AbstractSftpPacket::requestId() const 52 | { 53 | return SshPacketParser::asUint32(m_data, RequestIdOffset); 54 | } 55 | 56 | } // namespace Internal 57 | } // namespace QSsh 58 | -------------------------------------------------------------------------------- /src/libs/qssh/sftppacket_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SFTPPACKET_P_H 32 | #define SFTPPACKET_P_H 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace QSsh { 39 | namespace Internal { 40 | 41 | enum SftpPacketType { 42 | SSH_FXP_INIT = 1, 43 | SSH_FXP_VERSION = 2, 44 | SSH_FXP_OPEN = 3, 45 | SSH_FXP_CLOSE = 4, 46 | SSH_FXP_READ = 5, 47 | SSH_FXP_WRITE = 6, 48 | SSH_FXP_LSTAT = 7, 49 | SSH_FXP_FSTAT = 8, 50 | SSH_FXP_SETSTAT = 9, 51 | SSH_FXP_FSETSTAT = 10, 52 | SSH_FXP_OPENDIR = 11, 53 | SSH_FXP_READDIR = 12, 54 | SSH_FXP_REMOVE = 13, 55 | SSH_FXP_MKDIR = 14, 56 | SSH_FXP_RMDIR = 15, 57 | SSH_FXP_REALPATH = 16, 58 | SSH_FXP_STAT = 17, 59 | SSH_FXP_RENAME = 18, 60 | SSH_FXP_READLINK = 19, 61 | SSH_FXP_SYMLINK = 20, // Removed from later protocol versions. Try not to use. 62 | 63 | SSH_FXP_STATUS = 101, 64 | SSH_FXP_HANDLE = 102, 65 | SSH_FXP_DATA = 103, 66 | SSH_FXP_NAME = 104, 67 | SSH_FXP_ATTRS = 105, 68 | 69 | SSH_FXP_EXTENDED = 200, 70 | SSH_FXP_EXTENDED_REPLY = 201 71 | }; 72 | 73 | enum SftpStatusCode { 74 | SSH_FX_OK = 0, 75 | SSH_FX_EOF = 1, 76 | SSH_FX_NO_SUCH_FILE = 2, 77 | SSH_FX_PERMISSION_DENIED = 3, 78 | SSH_FX_FAILURE = 4, 79 | SSH_FX_BAD_MESSAGE = 5, 80 | SSH_FX_NO_CONNECTION = 6, 81 | SSH_FX_CONNECTION_LOST = 7, 82 | SSH_FX_OP_UNSUPPORTED = 8 83 | }; 84 | 85 | enum SftpAttributeType { 86 | SSH_FILEXFER_ATTR_SIZE = 0x00000001, 87 | SSH_FILEXFER_ATTR_UIDGID = 0x00000002, 88 | SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004, 89 | SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008, 90 | SSH_FILEXFER_ATTR_EXTENDED = 0x80000000 91 | }; 92 | 93 | class AbstractSftpPacket 94 | { 95 | public: 96 | AbstractSftpPacket(); 97 | quint32 requestId() const; 98 | const QByteArray &rawData() const { return m_data; } 99 | SftpPacketType type() const { return static_cast(m_data.at(TypeOffset)); } 100 | 101 | static const quint32 MaxDataSize; // "Pure" data size per read/writepacket. 102 | static const quint32 MaxPacketSize; 103 | 104 | protected: 105 | quint32 dataSize() const { return static_cast(m_data.size()); } 106 | 107 | static const int TypeOffset; 108 | static const int RequestIdOffset; 109 | static const int PayloadOffset; 110 | 111 | QByteArray m_data; 112 | }; 113 | 114 | } // namespace Internal 115 | } // namespace QSsh 116 | 117 | #endif // SFTPPACKET_P_H 118 | -------------------------------------------------------------------------------- /src/libs/qssh/ssh_global.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSH_GLOBAL_H 32 | #define SSH_GLOBAL_H 33 | 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | // For static cmake building removing dll export/import 38 | # define QSSH_EXPORT 39 | #else 40 | 41 | #if defined(QTCSSH_LIBRARY) 42 | # define QSSH_EXPORT Q_DECL_EXPORT 43 | #else 44 | # define QSSH_EXPORT Q_DECL_IMPORT 45 | #endif 46 | 47 | #endif 48 | 49 | #define QSSH_PRINT_WARNING qWarning("Soft assert at %s:%d", __FILE__, __LINE__) 50 | #define QSSH_ASSERT(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; } } while (false) 51 | #define QSSH_ASSERT_AND_RETURN(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; return; } } while (false) 52 | #define QSSH_ASSERT_AND_RETURN_VALUE(cond, value) do { if (!(cond)) { QSSH_PRINT_WARNING; return value; } } while (false) 53 | 54 | #endif // SSH_GLOBAL_H 55 | -------------------------------------------------------------------------------- /src/libs/qssh/sshagent_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 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace QSsh { 38 | namespace Internal { 39 | 40 | class SshAgent : public QObject 41 | { 42 | Q_OBJECT 43 | public: 44 | enum State { Unconnected, Connecting, Connected, }; 45 | 46 | ~SshAgent(); 47 | static State state() { return instance().m_state; } 48 | static bool hasError() { return !instance().m_error.isEmpty(); } 49 | static QString errorString() { return instance().m_error; } 50 | static QList publicKeys() { return instance().m_keys; } 51 | 52 | static void refreshKeys() { instance().refreshKeysImpl(); } 53 | static void storeDataToSign(const QByteArray &key, const QByteArray &data, uint token); 54 | static void removeDataToSign(const QByteArray &key, uint token); 55 | static void requestSignature(const QByteArray &key, uint token) { 56 | instance().requestSignatureImpl(key, token); 57 | } 58 | 59 | static SshAgent &instance(); 60 | 61 | signals: 62 | void errorOccurred(); 63 | void keysUpdated(); 64 | 65 | // Empty signature means signing failure. 66 | void signatureAvailable(const QByteArray &key, const QByteArray &signature, uint token); 67 | 68 | private: 69 | struct Request { 70 | Request() { } 71 | Request(const QByteArray &k, const QByteArray &d, uint t) 72 | : key(k), dataToSign(d), token(t) { } 73 | 74 | bool isKeysRequest() const { return !isSignatureRequest(); } 75 | bool isSignatureRequest() const { return !key.isEmpty(); } 76 | 77 | QByteArray key; 78 | QByteArray dataToSign; 79 | uint token = 0; 80 | }; 81 | 82 | struct Packet { 83 | bool isComplete() const { return size != 0 && int(size) == data.count(); } 84 | void invalidate() { size = 0; data.clear(); } 85 | 86 | quint32 size = 0; 87 | QByteArray data; 88 | }; 89 | 90 | SshAgent(); 91 | void connectToServer(); 92 | void refreshKeysImpl(); 93 | void requestSignatureImpl(const QByteArray &key, uint token); 94 | 95 | void sendNextRequest(); 96 | Packet generateKeysPacket(); 97 | Packet generateSigPacket(const Request &request); 98 | 99 | void handleConnected(); 100 | void handleDisconnected(); 101 | void handleSocketError(); 102 | void handleIncomingData(); 103 | void handleIncomingPacket(); 104 | void handleIdentitiesPacket(); 105 | void handleSignaturePacket(); 106 | 107 | void handleProtocolError(); 108 | void setDisconnected(); 109 | 110 | void sendPacket(); 111 | 112 | State m_state = Unconnected; 113 | QString m_error; 114 | QList m_keys; 115 | QHash, QByteArray> m_dataToSign; 116 | QLocalSocket m_agentSocket; 117 | QByteArray m_incomingData; 118 | Packet m_incomingPacket; 119 | Packet m_outgoingPacket; 120 | 121 | QQueue m_pendingRequests; 122 | }; 123 | 124 | } // namespace Internal 125 | } // namespace QSsh 126 | -------------------------------------------------------------------------------- /src/libs/qssh/sshcapabilities_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef CAPABILITIES_P_H 32 | #define CAPABILITIES_P_H 33 | 34 | #include 35 | #include 36 | 37 | namespace QSsh { 38 | namespace Internal { 39 | 40 | class SshCapabilities 41 | { 42 | public: 43 | static const QByteArray DiffieHellmanGroup1Sha1; 44 | static const QByteArray DiffieHellmanGroup14Sha1; 45 | static const QByteArray EcdhKexNamePrefix; 46 | static const QByteArray EcdhNistp256; 47 | static const QByteArray EcdhNistp384; 48 | static const QByteArray EcdhNistp521; // sic 49 | static const QList KeyExchangeMethods; 50 | 51 | static const QByteArray PubKeyDss; 52 | static const QByteArray PubKeyRsa; 53 | static const QByteArray PubKeyEcdsaPrefix; 54 | static const QByteArray PubKeyEcdsa256; 55 | static const QByteArray PubKeyEcdsa384; 56 | static const QByteArray PubKeyEcdsa521; 57 | static const QList PublicKeyAlgorithms; 58 | 59 | static const QByteArray CryptAlgo3DesCbc; 60 | static const QByteArray CryptAlgo3DesCtr; 61 | static const QByteArray CryptAlgoAes128Cbc; 62 | static const QByteArray CryptAlgoAes128Ctr; 63 | static const QByteArray CryptAlgoAes192Ctr; 64 | static const QByteArray CryptAlgoAes256Ctr; 65 | static const QList EncryptionAlgorithms; 66 | 67 | static const QByteArray HMacSha1; 68 | static const QByteArray HMacSha196; 69 | static const QByteArray HMacSha256; 70 | static const QByteArray HMacSha384; 71 | static const QByteArray HMacSha512; 72 | static const QList MacAlgorithms; 73 | 74 | static const QList CompressionAlgorithms; 75 | 76 | static const QByteArray SshConnectionService; 77 | 78 | static QList commonCapabilities(const QList &myCapabilities, 79 | const QList &serverCapabilities, const QByteArray &group); 80 | static QByteArray findBestMatch(const QList &myCapabilities, 81 | const QList &serverCapabilities, const QByteArray &group); 82 | 83 | static int ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo); 84 | static QByteArray ecdsaPubKeyAlgoForKeyWidth(int keyWidthInBytes); 85 | static const char *oid(const QByteArray &ecdsaAlgo); 86 | }; 87 | 88 | } // namespace Internal 89 | } // namespace QSsh 90 | 91 | #endif // CAPABILITIES_P_H 92 | -------------------------------------------------------------------------------- /src/libs/qssh/sshchannel_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHCHANNEL_P_H 32 | #define SSHCHANNEL_P_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace QSsh { 40 | namespace Internal { 41 | 42 | struct SshChannelExitSignal; 43 | struct SshChannelExitStatus; 44 | class SshIncomingPacket; 45 | class SshSendFacility; 46 | 47 | class AbstractSshChannel : public QObject 48 | { 49 | Q_OBJECT 50 | public: 51 | enum ChannelState { 52 | Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed 53 | }; 54 | 55 | quint32 localChannelId() const { return m_localChannel; } 56 | quint32 remoteChannel() const { return m_remoteChannel; } 57 | 58 | virtual void handleChannelSuccess() = 0; 59 | virtual void handleChannelFailure() = 0; 60 | 61 | void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize, 62 | quint32 remoteMaxPacketSize); 63 | void handleOpenFailure(const QString &reason); 64 | void handleWindowAdjust(quint64 bytesToAdd); 65 | void handleChannelEof(); 66 | void handleChannelClose(); 67 | void handleChannelData(const QByteArray &data); 68 | void handleChannelExtendedData(quint32 type, const QByteArray &data); 69 | void handleChannelRequest(const SshIncomingPacket &packet); 70 | 71 | void closeChannel(); 72 | 73 | virtual ~AbstractSshChannel(); 74 | 75 | static const int ReplyTimeout = 10000; // milli seconds 76 | ChannelState channelState() const { return m_state; } 77 | 78 | signals: 79 | void timeout(); 80 | void eof(); 81 | 82 | protected: 83 | AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility); 84 | 85 | void setChannelState(ChannelState state); 86 | 87 | void requestSessionStart(); 88 | void sendData(const QByteArray &data); 89 | 90 | static quint32 initialWindowSize(); 91 | static quint32 maxPacketSize(); 92 | 93 | quint32 maxDataSize() const; 94 | void checkChannelActive() const; 95 | 96 | SshSendFacility &m_sendFacility; 97 | QTimer m_timeoutTimer; 98 | 99 | private: 100 | virtual void handleOpenSuccessInternal() = 0; 101 | virtual void handleOpenFailureInternal(const QString &reason) = 0; 102 | virtual void handleChannelDataInternal(const QByteArray &data) = 0; 103 | virtual void handleChannelExtendedDataInternal(quint32 type, 104 | const QByteArray &data) = 0; 105 | virtual void handleExitStatus(const SshChannelExitStatus &exitStatus) = 0; 106 | virtual void handleExitSignal(const SshChannelExitSignal &signal) = 0; 107 | 108 | virtual void closeHook() = 0; 109 | 110 | void flushSendBuffer(); 111 | int handleChannelOrExtendedChannelData(const QByteArray &data); 112 | 113 | const quint32 m_localChannel; 114 | quint32 m_remoteChannel; 115 | quint32 m_localWindowSize; 116 | quint32 m_remoteWindowSize; 117 | quint32 m_remoteMaxPacketSize; 118 | ChannelState m_state; 119 | QByteArray m_sendBuffer; 120 | }; 121 | 122 | } // namespace Internal 123 | } // namespace QSsh 124 | 125 | #endif // SSHCHANNEL_P_H 126 | -------------------------------------------------------------------------------- /src/libs/qssh/sshchannelmanager_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHCHANNELLAYER_P_H 32 | #define SSHCHANNELLAYER_P_H 33 | 34 | #include "sshx11displayinfo_p.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace QSsh { 41 | class SftpChannel; 42 | class SshDirectTcpIpTunnel; 43 | class SshRemoteProcess; 44 | class SshTcpIpForwardServer; 45 | 46 | namespace Internal { 47 | 48 | class AbstractSshChannel; 49 | struct SshChannelOpenGeneric; 50 | class SshIncomingPacket; 51 | class SshSendFacility; 52 | class SshRemoteProcessPrivate; 53 | 54 | class SshChannelManager : public QObject 55 | { 56 | Q_OBJECT 57 | public: 58 | SshChannelManager(SshSendFacility &sendFacility, QObject *parent); 59 | 60 | QSharedPointer createRemoteProcess(const QByteArray &command); 61 | QSharedPointer createRemoteShell(); 62 | QSharedPointer createSftpChannel(); 63 | QSharedPointer createDirectTunnel(const QString &originatingHost, 64 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort); 65 | QSharedPointer createForwardServer(const QString &remoteHost, 66 | quint16 remotePort); 67 | 68 | int channelCount() const; 69 | enum CloseAllMode { CloseAllRegular, CloseAllAndReset }; 70 | int closeAllChannels(CloseAllMode mode); 71 | QString x11DisplayName() const { return m_x11DisplayInfo.displayName; } 72 | 73 | void handleChannelRequest(const SshIncomingPacket &packet); 74 | void handleChannelOpen(const SshIncomingPacket &packet); 75 | void handleChannelOpenFailure(const SshIncomingPacket &packet); 76 | void handleChannelOpenConfirmation(const SshIncomingPacket &packet); 77 | void handleChannelSuccess(const SshIncomingPacket &packet); 78 | void handleChannelFailure(const SshIncomingPacket &packet); 79 | void handleChannelWindowAdjust(const SshIncomingPacket &packet); 80 | void handleChannelData(const SshIncomingPacket &packet); 81 | void handleChannelExtendedData(const SshIncomingPacket &packet); 82 | void handleChannelEof(const SshIncomingPacket &packet); 83 | void handleChannelClose(const SshIncomingPacket &packet); 84 | void handleRequestSuccess(const SshIncomingPacket &packet); 85 | void handleRequestFailure(const SshIncomingPacket &packet); 86 | 87 | signals: 88 | void timeout(); 89 | 90 | private: 91 | typedef QHash::Iterator ChannelIterator; 92 | 93 | ChannelIterator lookupChannelAsIterator(quint32 channelId, 94 | bool allowNotFound = false); 95 | AbstractSshChannel *lookupChannel(quint32 channelId, 96 | bool allowNotFound = false); 97 | void removeChannel(ChannelIterator it); 98 | void insertChannel(AbstractSshChannel *priv, 99 | const QSharedPointer &pub); 100 | 101 | void handleChannelOpenForwardedTcpIp(const SshChannelOpenGeneric &channelOpenGeneric); 102 | void handleChannelOpenX11(const SshChannelOpenGeneric &channelOpenGeneric); 103 | 104 | SshSendFacility &m_sendFacility; 105 | QHash m_channels; 106 | QHash > m_sessions; 107 | quint32 m_nextLocalChannelId; 108 | QList> m_waitingForwardServers; 109 | QList> m_listeningForwardServers; 110 | QList m_x11ForwardingRequests; 111 | X11DisplayInfo m_x11DisplayInfo; 112 | }; 113 | 114 | } // namespace Internal 115 | } // namespace QSsh 116 | 117 | #endif // SSHCHANNELLAYER_P_H 118 | -------------------------------------------------------------------------------- /src/libs/qssh/sshconnectionmanager.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHCONNECTIONMANAGER_H 32 | #define SSHCONNECTIONMANAGER_H 33 | 34 | #include "ssh_global.h" 35 | 36 | namespace QSsh { 37 | 38 | class SshConnection; 39 | class SshConnectionParameters; 40 | 41 | /*! 42 | * \brief Creates a new connection or returns an existing one if there already is one with identical sshParams 43 | * \param sshParams Parameters used during connection 44 | * \return A connection 45 | */ 46 | QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams); 47 | 48 | /*! 49 | * \brief Call this when you are done with a connection, might be disconnected and destroyed if there are no others who have called acquireConnection() 50 | * \param connection The connection to be released 51 | */ 52 | QSSH_EXPORT void releaseConnection(SshConnection *connection); 53 | 54 | /*! 55 | * \brief Creates a new connection, unlike acquireConnection() it will not reuse an existing one. 56 | * \param sshParams Parameters used during connection 57 | * Make sure the next acquireConnection with the given parameters will return a new connection. 58 | */ 59 | QSSH_EXPORT void forceNewConnection(const SshConnectionParameters &sshParams); 60 | 61 | } // namespace QSsh 62 | 63 | #endif // SSHCONNECTIONMANAGER_H 64 | -------------------------------------------------------------------------------- /src/libs/qssh/sshdirecttcpiptunnel.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | #include "sshdirecttcpiptunnel.h" 33 | #include "sshdirecttcpiptunnel_p.h" 34 | 35 | #include "sshincomingpacket_p.h" 36 | #include "sshlogging_p.h" 37 | #include "sshsendfacility_p.h" 38 | 39 | #include 40 | 41 | namespace QSsh { 42 | namespace Internal { 43 | 44 | SshDirectTcpIpTunnelPrivate::SshDirectTcpIpTunnelPrivate(quint32 channelId, 45 | const QString &originatingHost, quint16 originatingPort, const QString &remoteHost, 46 | quint16 remotePort, SshSendFacility &sendFacility) 47 | : SshTcpIpTunnelPrivate(channelId, sendFacility), 48 | m_originatingHost(originatingHost), 49 | m_originatingPort(originatingPort), 50 | m_remoteHost(remoteHost), 51 | m_remotePort(remotePort) 52 | { 53 | } 54 | 55 | void SshDirectTcpIpTunnelPrivate::handleOpenSuccessInternal() 56 | { 57 | emit initialized(); 58 | } 59 | 60 | } // namespace Internal 61 | 62 | using namespace Internal; 63 | 64 | SshDirectTcpIpTunnel::SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost, 65 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 66 | SshSendFacility &sendFacility) 67 | : d(new SshDirectTcpIpTunnelPrivate(channelId, originatingHost, originatingPort, remoteHost, 68 | remotePort, sendFacility)) 69 | { 70 | d->init(this); 71 | connect(d, &SshDirectTcpIpTunnelPrivate::initialized, 72 | this, &SshDirectTcpIpTunnel::initialized, Qt::QueuedConnection); 73 | } 74 | 75 | SshDirectTcpIpTunnel::~SshDirectTcpIpTunnel() 76 | { 77 | delete d; 78 | } 79 | 80 | bool SshDirectTcpIpTunnel::atEnd() const 81 | { 82 | return QIODevice::atEnd() && d->m_data.isEmpty(); 83 | } 84 | 85 | qint64 SshDirectTcpIpTunnel::bytesAvailable() const 86 | { 87 | return QIODevice::bytesAvailable() + d->m_data.count(); 88 | } 89 | 90 | bool SshDirectTcpIpTunnel::canReadLine() const 91 | { 92 | return QIODevice::canReadLine() || d->m_data.contains('\n'); 93 | } 94 | 95 | void SshDirectTcpIpTunnel::close() 96 | { 97 | d->closeChannel(); 98 | QIODevice::close(); 99 | } 100 | 101 | void SshDirectTcpIpTunnel::initialize() 102 | { 103 | QSSH_ASSERT_AND_RETURN(d->channelState() == AbstractSshChannel::Inactive); 104 | 105 | try { 106 | QIODevice::open(QIODevice::ReadWrite); 107 | d->m_sendFacility.sendDirectTcpIpPacket(d->localChannelId(), SshDirectTcpIpTunnelPrivate::initialWindowSize(), 108 | SshDirectTcpIpTunnelPrivate::maxPacketSize(), d->m_remoteHost.toUtf8(), d->m_remotePort, 109 | d->m_originatingHost.toUtf8(), d->m_originatingPort); 110 | d->setChannelState(AbstractSshChannel::SessionRequested); 111 | d->m_timeoutTimer.setTimerType(Qt::VeryCoarseTimer); 112 | d->m_timeoutTimer.start(SshDirectTcpIpTunnelPrivate::ReplyTimeout); 113 | } catch (const std::exception &e) { // Won't happen, but let's play it safe. 114 | qCWarning(sshLog, "Botan error: %s", e.what()); 115 | d->closeChannel(); 116 | } 117 | } 118 | 119 | qint64 SshDirectTcpIpTunnel::readData(char *data, qint64 maxlen) 120 | { 121 | return d->readData(data, maxlen); 122 | } 123 | 124 | qint64 SshDirectTcpIpTunnel::writeData(const char *data, qint64 len) 125 | { 126 | return d->writeData(data, len); 127 | } 128 | 129 | } // namespace QSsh 130 | -------------------------------------------------------------------------------- /src/libs/qssh/sshdirecttcpiptunnel.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | 33 | #ifndef SSHDIRECTTCPIPTUNNEL_H 34 | #define SSHDIRECTTCPIPTUNNEL_H 35 | 36 | #include "ssh_global.h" 37 | 38 | #include 39 | #include 40 | 41 | namespace QSsh { 42 | 43 | namespace Internal { 44 | class SshChannelManager; 45 | class SshDirectTcpIpTunnelPrivate; 46 | class SshSendFacility; 47 | class SshTcpIpTunnelPrivate; 48 | } // namespace Internal 49 | 50 | class QSSH_EXPORT SshDirectTcpIpTunnel : public QIODevice 51 | { 52 | Q_OBJECT 53 | 54 | friend class Internal::SshChannelManager; 55 | friend class Internal::SshTcpIpTunnelPrivate; 56 | 57 | public: 58 | typedef QSharedPointer Ptr; 59 | 60 | ~SshDirectTcpIpTunnel(); 61 | 62 | // QIODevice stuff 63 | bool atEnd() const; 64 | qint64 bytesAvailable() const; 65 | bool canReadLine() const; 66 | void close(); 67 | bool isSequential() const { return true; } 68 | 69 | void initialize(); 70 | 71 | signals: 72 | void initialized(); 73 | void error(const QString &reason); 74 | 75 | private: 76 | SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost, 77 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 78 | Internal::SshSendFacility &sendFacility); 79 | 80 | // QIODevice stuff 81 | qint64 readData(char *data, qint64 maxlen); 82 | qint64 writeData(const char *data, qint64 len); 83 | 84 | Internal::SshDirectTcpIpTunnelPrivate * const d; 85 | }; 86 | 87 | } // namespace QSsh 88 | 89 | #endif // SSHDIRECTTCPIPTUNNEL_H 90 | -------------------------------------------------------------------------------- /src/libs/qssh/sshdirecttcpiptunnel_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Nokia Corporation (qt-info@nokia.com) 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** If you have questions regarding the use of this file, please contact 29 | ** Nokia at qt-info@nokia.com. 30 | ** 31 | **************************************************************************/ 32 | #ifndef DIRECTTCPIPCHANNEL_P_H 33 | #define DIRECTTCPIPCHANNEL_P_H 34 | 35 | #include "sshtcpiptunnel_p.h" 36 | 37 | namespace QSsh { 38 | class SshDirectTcpIpTunnel; 39 | 40 | namespace Internal { 41 | 42 | class SshDirectTcpIpTunnelPrivate : public SshTcpIpTunnelPrivate 43 | { 44 | Q_OBJECT 45 | 46 | friend class QSsh::SshDirectTcpIpTunnel; 47 | 48 | public: 49 | explicit SshDirectTcpIpTunnelPrivate(quint32 channelId, const QString &originatingHost, 50 | quint16 originatingPort, const QString &remoteHost, quint16 remotePort, 51 | SshSendFacility &sendFacility); 52 | 53 | signals: 54 | void initialized(); 55 | 56 | private: 57 | void handleOpenSuccessInternal(); 58 | 59 | const QString m_originatingHost; 60 | const quint16 m_originatingPort; 61 | const QString m_remoteHost; 62 | const quint16 m_remotePort; 63 | }; 64 | 65 | } // namespace Internal 66 | } // namespace QSsh 67 | 68 | #endif // DIRECTTCPIPCHANNEL_P_H 69 | -------------------------------------------------------------------------------- /src/libs/qssh/ssherrors.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHERRORS_P_H 32 | #define SSHERRORS_P_H 33 | 34 | #include 35 | 36 | namespace QSsh { 37 | 38 | /*! 39 | * \brief SSH specific errors 40 | */ 41 | enum SshError { 42 | /// No error has occured 43 | SshNoError, 44 | 45 | /// There was a network socket error 46 | SshSocketError, 47 | 48 | /// The connection timed out 49 | SshTimeoutError, 50 | 51 | /// There was an error communicating with the server 52 | SshProtocolError, 53 | 54 | /// There was a problem with the remote host key 55 | SshHostKeyError, 56 | 57 | /// We failed to read or parse the key file used for authentication 58 | SshKeyFileError, 59 | 60 | /// We failed to authenticate 61 | SshAuthenticationError, 62 | 63 | /// The server closed our connection 64 | SshClosedByServerError, 65 | 66 | /// The ssh-agent used for authenticating failed somehow 67 | SshAgentError, 68 | 69 | /// Something bad happened on the server 70 | SshInternalError 71 | }; 72 | 73 | } // namespace QSsh 74 | 75 | Q_DECLARE_METATYPE(QSsh::SshError) 76 | 77 | #endif // SSHERRORS_P_H 78 | -------------------------------------------------------------------------------- /src/libs/qssh/sshexception_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHEXCEPTION_P_H 32 | #define SSHEXCEPTION_P_H 33 | 34 | #include "ssherrors.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | namespace QSsh { 43 | namespace Internal { 44 | 45 | enum SshErrorCode { 46 | SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1, 47 | SSH_DISCONNECT_PROTOCOL_ERROR = 2, 48 | SSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3, 49 | SSH_DISCONNECT_RESERVED = 4, 50 | SSH_DISCONNECT_MAC_ERROR = 5, 51 | SSH_DISCONNECT_COMPRESSION_ERROR = 6, 52 | SSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7, 53 | SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8, 54 | SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9, 55 | SSH_DISCONNECT_CONNECTION_LOST = 10, 56 | SSH_DISCONNECT_BY_APPLICATION = 11, 57 | SSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12, 58 | SSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13, 59 | SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14, 60 | SSH_DISCONNECT_ILLEGAL_USER_NAME = 15 61 | }; 62 | 63 | #define SSH_TR(string) QCoreApplication::translate("SshConnection", string) 64 | 65 | #define SSH_SERVER_EXCEPTION(error, errorString) \ 66 | SshServerException((error), (errorString), SSH_TR(errorString)) 67 | 68 | struct SshServerException : public std::exception 69 | { 70 | SshServerException(SshErrorCode error, const QByteArray &errorStringServer, 71 | const QString &errorStringUser) 72 | : error(error), errorStringServer(errorStringServer), 73 | errorStringUser(errorStringUser) {} 74 | const char *what() const noexcept override { return errorStringServer.constData(); } 75 | 76 | const SshErrorCode error; 77 | const QByteArray errorStringServer; 78 | const QString errorStringUser; 79 | }; 80 | 81 | struct SshClientException : public std::exception 82 | { 83 | SshClientException(SshError error, const QString &errorString) 84 | : error(error), errorString(errorString), errorStringPrintable(errorString.toLocal8Bit()) {} 85 | const char *what() const noexcept override { return errorStringPrintable.constData(); } 86 | 87 | const SshError error; 88 | const QString errorString; 89 | const QByteArray errorStringPrintable; 90 | }; 91 | 92 | } // namespace Internal 93 | } // namespace QSsh 94 | 95 | #endif // SSHEXCEPTION_P_H 96 | -------------------------------------------------------------------------------- /src/libs/qssh/sshforwardedtcpiptunnel.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 "sshforwardedtcpiptunnel.h" 27 | #include "sshforwardedtcpiptunnel_p.h" 28 | #include "sshlogging_p.h" 29 | #include "sshsendfacility_p.h" 30 | 31 | namespace QSsh { 32 | 33 | namespace Internal { 34 | SshForwardedTcpIpTunnelPrivate::SshForwardedTcpIpTunnelPrivate(quint32 channelId, 35 | SshSendFacility &sendFacility) : 36 | SshTcpIpTunnelPrivate(channelId, sendFacility) 37 | { 38 | setChannelState(SessionRequested); 39 | } 40 | 41 | void SshForwardedTcpIpTunnelPrivate::handleOpenSuccessInternal() 42 | { 43 | QSSH_ASSERT_AND_RETURN(channelState() == AbstractSshChannel::SessionEstablished); 44 | 45 | try { 46 | m_sendFacility.sendChannelOpenConfirmationPacket(remoteChannel(), localChannelId(), 47 | initialWindowSize(), maxPacketSize()); 48 | } catch (const std::exception &e) { // Won't happen, but let's play it safe. 49 | qCWarning(sshLog, "Botan error: %s", e.what()); 50 | closeChannel(); 51 | } 52 | } 53 | 54 | } // namespace Internal 55 | 56 | using namespace Internal; 57 | 58 | SshForwardedTcpIpTunnel::SshForwardedTcpIpTunnel(quint32 channelId, SshSendFacility &sendFacility) : 59 | d(new SshForwardedTcpIpTunnelPrivate(channelId, sendFacility)) 60 | { 61 | d->init(this); 62 | } 63 | 64 | SshForwardedTcpIpTunnel::~SshForwardedTcpIpTunnel() 65 | { 66 | delete d; 67 | } 68 | 69 | bool SshForwardedTcpIpTunnel::atEnd() const 70 | { 71 | return QIODevice::atEnd() && d->m_data.isEmpty(); 72 | } 73 | 74 | qint64 SshForwardedTcpIpTunnel::bytesAvailable() const 75 | { 76 | return QIODevice::bytesAvailable() + d->m_data.count(); 77 | } 78 | 79 | bool SshForwardedTcpIpTunnel::canReadLine() const 80 | { 81 | return QIODevice::canReadLine() || d->m_data.contains('\n'); 82 | } 83 | 84 | void SshForwardedTcpIpTunnel::close() 85 | { 86 | d->closeChannel(); 87 | QIODevice::close(); 88 | } 89 | 90 | qint64 SshForwardedTcpIpTunnel::readData(char *data, qint64 maxlen) 91 | { 92 | return d->readData(data, maxlen); 93 | } 94 | 95 | qint64 SshForwardedTcpIpTunnel::writeData(const char *data, qint64 len) 96 | { 97 | return d->writeData(data, len); 98 | } 99 | 100 | } // namespace QSsh 101 | -------------------------------------------------------------------------------- /src/libs/qssh/sshforwardedtcpiptunnel.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 | #pragma once 26 | 27 | #include "ssh_global.h" 28 | #include 29 | #include 30 | 31 | namespace QSsh { 32 | 33 | namespace Internal { 34 | class SshChannelManager; 35 | class SshForwardedTcpIpTunnelPrivate; 36 | class SshSendFacility; 37 | class SshTcpIpTunnelPrivate; 38 | } // namespace Internal 39 | 40 | class QSSH_EXPORT SshForwardedTcpIpTunnel : public QIODevice 41 | { 42 | Q_OBJECT 43 | friend class Internal::SshChannelManager; 44 | friend class Internal::SshTcpIpTunnelPrivate; 45 | 46 | public: 47 | typedef QSharedPointer Ptr; 48 | ~SshForwardedTcpIpTunnel() override; 49 | 50 | // QIODevice stuff 51 | bool atEnd() const override; 52 | qint64 bytesAvailable() const override; 53 | bool canReadLine() const override; 54 | void close() override; 55 | bool isSequential() const override { return true; } 56 | 57 | signals: 58 | void error(const QString &reason); 59 | 60 | private: 61 | SshForwardedTcpIpTunnel(quint32 channelId, Internal::SshSendFacility &sendFacility); 62 | 63 | // QIODevice stuff 64 | qint64 readData(char *data, qint64 maxlen) override; 65 | qint64 writeData(const char *data, qint64 len) override; 66 | 67 | Internal::SshForwardedTcpIpTunnelPrivate * const d; 68 | }; 69 | 70 | } // namespace QSsh 71 | -------------------------------------------------------------------------------- /src/libs/qssh/sshforwardedtcpiptunnel_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 | #pragma once 27 | 28 | #include "sshforwardedtcpiptunnel.h" 29 | #include "sshtcpiptunnel_p.h" 30 | 31 | namespace QSsh { 32 | namespace Internal { 33 | 34 | class SshForwardedTcpIpTunnelPrivate : public SshTcpIpTunnelPrivate 35 | { 36 | Q_OBJECT 37 | friend class QSsh::SshForwardedTcpIpTunnel; 38 | public: 39 | SshForwardedTcpIpTunnelPrivate(quint32 channelId, SshSendFacility &sendFacility); 40 | void handleOpenSuccessInternal() override; 41 | }; 42 | 43 | } // namespace Internal 44 | } // namespace QSsh 45 | -------------------------------------------------------------------------------- /src/libs/qssh/sshhostkeydatabase.cpp: -------------------------------------------------------------------------------- 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 | #include "sshhostkeydatabase.h" 31 | 32 | #include "sshlogging_p.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace QSsh { 42 | 43 | class SshHostKeyDatabase::SshHostKeyDatabasePrivate 44 | { 45 | public: 46 | QHash hostKeys; 47 | }; 48 | 49 | SshHostKeyDatabase::SshHostKeyDatabase() : d(new SshHostKeyDatabasePrivate) 50 | { 51 | } 52 | 53 | SshHostKeyDatabase::~SshHostKeyDatabase() 54 | { 55 | delete d; 56 | } 57 | 58 | bool SshHostKeyDatabase::load(const QString &filePath, QString *error) 59 | { 60 | QFile file(filePath); 61 | if (!file.open(QIODevice::ReadOnly)) { 62 | if (error) { 63 | *error = QCoreApplication::translate("QSsh::Ssh", 64 | "Failed to open key file \"%1\" for reading: %2") 65 | .arg(QDir::toNativeSeparators(filePath), file.errorString()); 66 | } 67 | return false; 68 | } 69 | 70 | d->hostKeys.clear(); 71 | const QByteArray content = file.readAll().trimmed(); 72 | if (content.isEmpty()) 73 | return true; 74 | for (const QByteArray &line : content.split('\n')) { 75 | const QList &lineData = line.trimmed().split(' '); 76 | if (lineData.count() != 2) { 77 | qCDebug(Internal::sshLog, "Unexpected line \"%s\" in file \"%s\".", line.constData(), 78 | qPrintable(filePath)); 79 | continue; 80 | } 81 | d->hostKeys.insert(QString::fromUtf8(lineData.first()), 82 | QByteArray::fromHex(lineData.last())); 83 | } 84 | 85 | return true; 86 | } 87 | 88 | bool SshHostKeyDatabase::store(const QString &filePath, QString *error) const 89 | { 90 | QFile file(filePath); 91 | if (!file.open(QIODevice::WriteOnly)) { 92 | if (error) { 93 | *error = QCoreApplication::translate("QSsh::Ssh", 94 | "Failed to open key file \"%1\" for writing: %2") 95 | .arg(QDir::toNativeSeparators(filePath), file.errorString()); 96 | } 97 | return false; 98 | } 99 | 100 | file.resize(0); 101 | for (auto it = d->hostKeys.constBegin(); it != d->hostKeys.constEnd(); ++it) 102 | file.write(it.key().toUtf8() + ' ' + it.value().toHex() + '\n'); 103 | return true; 104 | } 105 | 106 | SshHostKeyDatabase::KeyLookupResult SshHostKeyDatabase::matchHostKey(const QString &hostName, 107 | const QByteArray &key) const 108 | { 109 | auto it = d->hostKeys.constFind(hostName); 110 | if (it == d->hostKeys.constEnd()) 111 | return KeyLookupNoMatch; 112 | if (it.value() == key) 113 | return KeyLookupMatch; 114 | return KeyLookupMismatch; 115 | } 116 | 117 | void SshHostKeyDatabase::insertHostKey(const QString &hostName, const QByteArray &key) 118 | { 119 | d->hostKeys.insert(hostName, key); 120 | } 121 | 122 | QByteArray SshHostKeyDatabase::retrieveHostKey(const QString &hostName) 123 | { 124 | return d->hostKeys.value(hostName); 125 | } 126 | 127 | } // namespace QSsh 128 | -------------------------------------------------------------------------------- /src/libs/qssh/sshhostkeydatabase.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 | #ifndef SSHHOSTKEYDATABASE_H 31 | #define SSHHOSTKEYDATABASE_H 32 | 33 | #include "ssh_global.h" 34 | 35 | #include 36 | 37 | QT_BEGIN_NAMESPACE 38 | class QByteArray; 39 | class QString; 40 | QT_END_NAMESPACE 41 | 42 | namespace QSsh { 43 | class SshHostKeyDatabase; 44 | 45 | /// Convenience typedef 46 | typedef QSharedPointer SshHostKeyDatabasePtr; 47 | 48 | class QSSH_EXPORT SshHostKeyDatabase 49 | { 50 | friend class QSharedPointer; // To give create() access to our constructor. 51 | 52 | public: 53 | enum KeyLookupResult { 54 | KeyLookupMatch, 55 | KeyLookupNoMatch, 56 | KeyLookupMismatch 57 | }; 58 | 59 | SshHostKeyDatabase(); 60 | ~SshHostKeyDatabase(); 61 | 62 | bool load(const QString &filePath, QString *error = nullptr); 63 | bool store(const QString &filePath, QString *error = nullptr) const; 64 | KeyLookupResult matchHostKey(const QString &hostName, const QByteArray &key) const; 65 | void insertHostKey(const QString &hostName, const QByteArray &key); 66 | QByteArray retrieveHostKey(const QString &hostName); 67 | 68 | private: 69 | class SshHostKeyDatabasePrivate; 70 | SshHostKeyDatabasePrivate * const d; 71 | }; 72 | 73 | } // namespace QSsh 74 | 75 | #endif // Include guard. 76 | -------------------------------------------------------------------------------- /src/libs/qssh/sshkeyexchange_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHKEYEXCHANGE_P_H 32 | #define SSHKEYEXCHANGE_P_H 33 | 34 | #include "sshconnection.h" 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace Botan { 42 | class DH_PrivateKey; 43 | class ECDH_PrivateKey; 44 | class HashFunction; 45 | } 46 | 47 | namespace QSsh { 48 | namespace Internal { 49 | 50 | struct SshKeyExchangeInit; 51 | class SshSendFacility; 52 | class SshIncomingPacket; 53 | 54 | class SshKeyExchange 55 | { 56 | public: 57 | SshKeyExchange(const SshConnectionParameters &connParams, SshSendFacility &sendFacility); 58 | ~SshKeyExchange(); 59 | 60 | const QByteArray &hostKeyFingerprint() { return m_hostFingerprint; } 61 | void sendKexInitPacket(const QByteArray &serverId); 62 | 63 | // Returns true <=> the server sends a guessed package. 64 | bool sendDhInitPacket(const SshIncomingPacket &serverKexInit); 65 | 66 | void sendNewKeysPacket(const SshIncomingPacket &dhReply, 67 | const QByteArray &clientId); 68 | 69 | QByteArray k() const { return m_k; } 70 | QByteArray h() const { return m_h; } 71 | Botan::HashFunction *hash() const { return m_hash.get(); } 72 | QByteArray encryptionAlgo() const { return m_encryptionAlgo; } 73 | QByteArray decryptionAlgo() const { return m_decryptionAlgo; } 74 | QByteArray hMacAlgoClientToServer() const { return m_c2sHMacAlgo; } 75 | QByteArray hMacAlgoServerToClient() const { return m_s2cHMacAlgo; } 76 | 77 | private: 78 | QByteArray hashAlgoForKexAlgo() const; 79 | void determineHashingAlgorithm(const SshKeyExchangeInit &kexInit, bool serverToClient); 80 | void checkHostKey(const QByteArray &hostKey); 81 | Q_NORETURN void throwHostKeyException(); 82 | 83 | QByteArray m_serverId; 84 | QByteArray m_clientKexInitPayload; 85 | QByteArray m_serverKexInitPayload; 86 | QScopedPointer m_dhKey; 87 | QScopedPointer m_ecdhKey; 88 | QByteArray m_kexAlgoName; 89 | QByteArray m_k; 90 | QByteArray m_h; 91 | QByteArray m_serverHostKeyAlgo; 92 | QByteArray m_encryptionAlgo; 93 | QByteArray m_decryptionAlgo; 94 | QByteArray m_c2sHMacAlgo; 95 | QByteArray m_s2cHMacAlgo; 96 | std::unique_ptr m_hash; 97 | const SshConnectionParameters m_connParams; 98 | SshSendFacility &m_sendFacility; 99 | QByteArray m_hostFingerprint; 100 | }; 101 | 102 | } // namespace Internal 103 | } // namespace QSsh 104 | 105 | #endif // SSHKEYEXCHANGE_P_H 106 | -------------------------------------------------------------------------------- /src/libs/qssh/sshkeygenerator.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 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, Ecdsa }; 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 | -------------------------------------------------------------------------------- /src/libs/qssh/sshkeypasswordretriever.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | #include "sshkeypasswordretriever_p.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | namespace QSsh { 39 | namespace Internal { 40 | 41 | std::string SshKeyPasswordRetriever::get_passphrase() 42 | { 43 | const bool hasGui = dynamic_cast(QApplication::instance()); 44 | if (hasGui) { 45 | bool ok; 46 | const QString &password = QInputDialog::getText(nullptr, 47 | QCoreApplication::translate("QSsh::Ssh", "Password Required"), 48 | QCoreApplication::translate("QSsh::Ssh", "Please enter the password for your private key."), 49 | QLineEdit::Password, QString(), &ok); 50 | return std::string(password.toLocal8Bit().data()); 51 | } else { 52 | std::string password; 53 | std::cout << "Please enter the password for your private key (set echo off beforehand!): " << std::flush; 54 | std::cin >> password; 55 | return password; 56 | } 57 | } 58 | 59 | } // namespace Internal 60 | } // namespace QSsh 61 | -------------------------------------------------------------------------------- /src/libs/qssh/sshkeypasswordretriever_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | #ifndef KEYPASSWORDRETRIEVER_H 31 | #define KEYPASSWORDRETRIEVER_H 32 | 33 | #include 34 | 35 | namespace QSsh { 36 | namespace Internal { 37 | 38 | class SshKeyPasswordRetriever 39 | { 40 | public: 41 | static std::string get_passphrase(); 42 | }; 43 | 44 | } // namespace Internal 45 | } // namespace QSsh 46 | 47 | #endif // KEYPASSWORDRETRIEVER_H 48 | -------------------------------------------------------------------------------- /src/libs/qssh/sshlogging.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: http://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 and 13 | ** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional 26 | ** rights. These rights are described in The Qt Company LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ****************************************************************************/ 30 | 31 | #include "sshlogging_p.h" 32 | 33 | namespace QSsh { 34 | namespace Internal { 35 | Q_LOGGING_CATEGORY(sshLog, "qtc.ssh", QtWarningMsg) 36 | } // namespace Internal 37 | } // namespace QSsh 38 | -------------------------------------------------------------------------------- /src/libs/qssh/sshlogging_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: http://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 and 13 | ** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional 26 | ** rights. These rights are described in The Qt Company LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ****************************************************************************/ 30 | 31 | #ifndef SSHLOGGING_P_H 32 | #define SSHLOGGING_P_H 33 | 34 | #include 35 | 36 | namespace QSsh { 37 | namespace Internal { 38 | Q_DECLARE_LOGGING_CATEGORY(sshLog) 39 | } // namespace Internal 40 | } // namespace QSsh 41 | 42 | #endif // Include guard 43 | -------------------------------------------------------------------------------- /src/libs/qssh/sshpacketparser_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHPACKETPARSER_P_H 32 | #define SSHPACKETPARSER_P_H 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace QSsh { 41 | namespace Internal { 42 | 43 | struct SshNameList 44 | { 45 | SshNameList() : originalLength(0) {} 46 | SshNameList(quint32 originalLength) : originalLength(originalLength) {} 47 | quint32 originalLength; 48 | QList names; 49 | }; 50 | 51 | class SshPacketParseException { }; 52 | 53 | // This class's functions try to read a byte array at a certain offset 54 | // as the respective chunk of data as specified in the SSH RFCs. 55 | // If they succeed, they update the offset, so they can easily 56 | // be called in succession by client code. 57 | // For convenience, some have also versions that don't update the offset, 58 | // so they can be called with rvalues if the new value is not needed. 59 | // If they fail, they throw an SshPacketParseException. 60 | class SshPacketParser 61 | { 62 | public: 63 | static bool asBool(const QByteArray &data, quint32 offset); 64 | static bool asBool(const QByteArray &data, quint32 *offset); 65 | static quint16 asUint16(const QByteArray &data, quint32 offset); 66 | static quint16 asUint16(const QByteArray &data, quint32 *offset); 67 | static quint64 asUint64(const QByteArray &data, quint32 offset); 68 | static quint64 asUint64(const QByteArray &data, quint32 *offset); 69 | static quint32 asUint32(const QByteArray &data, quint32 offset); 70 | static quint32 asUint32(const QByteArray &data, quint32 *offset); 71 | static QByteArray asString(const QByteArray &data, quint32 offset); 72 | static QByteArray asString(const QByteArray &data, quint32 *offset); 73 | static QString asUserString(const QByteArray &data, quint32 *offset); 74 | static SshNameList asNameList(const QByteArray &data, quint32 *offset); 75 | static Botan::BigInt asBigInt(const QByteArray &data, quint32 *offset); 76 | 77 | static QString asUserString(const QByteArray &rawString); 78 | }; 79 | 80 | } // namespace Internal 81 | } // namespace QSsh 82 | 83 | #endif // SSHPACKETPARSER_P_H 84 | -------------------------------------------------------------------------------- /src/libs/qssh/sshremoteprocess.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHREMOTECOMMAND_H 32 | #define SSHREMOTECOMMAND_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 | /*! 52 | \class QSsh::SshRemoteProcess 53 | 54 | \brief This class implements an SSH channel for running a remote process. 55 | 56 | Objects are created via SshConnection::createRemoteProcess. 57 | The process is started via the start() member function. 58 | If the process needs a pseudo terminal, you can request one 59 | via requestTerminal() before calling start(). 60 | Note that this class does not support QIODevice's waitFor*() functions, i.e. it has 61 | no synchronous mode. 62 | */ 63 | 64 | // TODO: ProcessChannel 65 | class QSSH_EXPORT SshRemoteProcess : public QIODevice 66 | { 67 | Q_OBJECT 68 | 69 | friend class Internal::SshChannelManager; 70 | friend class Internal::SshRemoteProcessPrivate; 71 | 72 | public: 73 | typedef QSharedPointer Ptr; 74 | enum ExitStatus { FailedToStart, CrashExit, NormalExit }; 75 | enum Signal { 76 | AbrtSignal, AlrmSignal, FpeSignal, HupSignal, IllSignal, IntSignal, KillSignal, PipeSignal, 77 | QuitSignal, SegvSignal, TermSignal, Usr1Signal, Usr2Signal, NoSignal 78 | }; 79 | 80 | ~SshRemoteProcess(); 81 | 82 | // QIODevice stuff 83 | bool atEnd() const; 84 | qint64 bytesAvailable() const; 85 | bool canReadLine() const; 86 | void close(); 87 | bool isSequential() const { return true; } 88 | 89 | QProcess::ProcessChannel readChannel() const; 90 | void setReadChannel(QProcess::ProcessChannel channel); 91 | 92 | /* 93 | * Note that this is of limited value in practice, because servers are 94 | * usually configured to ignore such requests for security reasons. 95 | */ 96 | void addToEnvironment(const QByteArray &var, const QByteArray &value); 97 | void clearEnvironment(); 98 | 99 | void requestTerminal(const SshPseudoTerminal &terminal); 100 | void requestX11Forwarding(const QString &displayName); 101 | void start(); 102 | 103 | bool isRunning() const; 104 | int exitCode() const; 105 | Signal exitSignal() const; 106 | 107 | QByteArray readAllStandardOutput(); 108 | QByteArray readAllStandardError(); 109 | 110 | // Note: This is ignored by the OpenSSH server. 111 | void sendSignal(Signal signal); 112 | void kill() { sendSignal(KillSignal); } 113 | 114 | signals: 115 | void started(); 116 | 117 | void readyReadStandardOutput(); 118 | void readyReadStandardError(); 119 | 120 | /* 121 | * Parameter is of type ExitStatus, but we use int because of 122 | * signal/slot awkwardness (full namespace required). 123 | */ 124 | void closed(int exitStatus); 125 | 126 | private: 127 | SshRemoteProcess(const QByteArray &command, quint32 channelId, 128 | Internal::SshSendFacility &sendFacility); 129 | SshRemoteProcess(quint32 channelId, Internal::SshSendFacility &sendFacility); 130 | 131 | // QIODevice stuff 132 | qint64 readData(char *data, qint64 maxlen); 133 | qint64 writeData(const char *data, qint64 len); 134 | 135 | void init(); 136 | QByteArray readAllFromChannel(QProcess::ProcessChannel channel); 137 | 138 | Internal::SshRemoteProcessPrivate *d; 139 | }; 140 | 141 | } // namespace QSsh 142 | 143 | #endif // SSHREMOTECOMMAND_H 144 | -------------------------------------------------------------------------------- /src/libs/qssh/sshremoteprocess_p.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHREMOTEPROCESS_P_H 32 | #define SSHREMOTEPROCESS_P_H 33 | 34 | #include "sshpseudoterminal.h" 35 | 36 | #include "sshchannel_p.h" 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace QSsh { 43 | class SshRemoteProcess; 44 | 45 | namespace Internal { 46 | class SshSendFacility; 47 | class X11DisplayInfo; 48 | 49 | class SshRemoteProcessPrivate : public AbstractSshChannel 50 | { 51 | Q_OBJECT 52 | friend class QSsh::SshRemoteProcess; 53 | public: 54 | enum ProcessState { 55 | NotYetStarted, ExecRequested, StartFailed, Running, Exited 56 | }; 57 | 58 | void failToStart(const QString &reason); 59 | void startProcess(const X11DisplayInfo &displayInfo); 60 | 61 | signals: 62 | void started(); 63 | void readyRead(); 64 | void readyReadStandardOutput(); 65 | void readyReadStandardError(); 66 | void closed(int exitStatus); 67 | void x11ForwardingRequested(const QString &display); 68 | 69 | private: 70 | SshRemoteProcessPrivate(const QByteArray &command, quint32 channelId, 71 | SshSendFacility &sendFacility, SshRemoteProcess *proc); 72 | SshRemoteProcessPrivate(quint32 channelId, SshSendFacility &sendFacility, 73 | SshRemoteProcess *proc); 74 | 75 | virtual void handleChannelSuccess(); 76 | virtual void handleChannelFailure(); 77 | 78 | virtual void handleOpenSuccessInternal(); 79 | virtual void handleOpenFailureInternal(const QString &reason); 80 | virtual void handleChannelDataInternal(const QByteArray &data); 81 | virtual void handleChannelExtendedDataInternal(quint32 type, 82 | const QByteArray &data); 83 | virtual void handleExitStatus(const SshChannelExitStatus &exitStatus); 84 | virtual void handleExitSignal(const SshChannelExitSignal &signal); 85 | 86 | virtual void closeHook(); 87 | 88 | void init(); 89 | void setProcState(ProcessState newState); 90 | QByteArray &data(); 91 | 92 | QProcess::ProcessChannel m_readChannel; 93 | 94 | ProcessState m_procState; 95 | bool m_wasRunning; 96 | int m_signal; 97 | int m_exitCode; 98 | 99 | const QByteArray m_command; 100 | const bool m_isShell; 101 | 102 | typedef QPair EnvVar; 103 | QList m_env; 104 | bool m_useTerminal; 105 | SshPseudoTerminal m_terminal; 106 | 107 | QString m_x11DisplayName; 108 | 109 | QByteArray m_stdout; 110 | QByteArray m_stderr; 111 | 112 | SshRemoteProcess *m_proc; 113 | }; 114 | 115 | } // namespace Internal 116 | } // namespace QSsh 117 | 118 | #endif // SSHREMOTEPROCESS_P_H 119 | -------------------------------------------------------------------------------- /src/libs/qssh/sshremoteprocessrunner.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: http://www.qt-project.org/ 8 | ** 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** 12 | ** This file may be used under the terms of the GNU Lesser General Public 13 | ** License version 2.1 as published by the Free Software Foundation and 14 | ** appearing in the file LICENSE.LGPL included in the packaging of this file. 15 | ** Please review the following information to ensure the GNU Lesser General 16 | ** Public License version 2.1 requirements will be met: 17 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 18 | ** 19 | ** In addition, as a special exception, Nokia gives you certain additional 20 | ** rights. These rights are described in the Nokia Qt LGPL Exception 21 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 22 | ** 23 | ** Other Usage 24 | ** 25 | ** Alternatively, this file may be used in accordance with the terms and 26 | ** conditions contained in a signed written agreement between you and Nokia. 27 | ** 28 | ** 29 | **************************************************************************/ 30 | 31 | #ifndef SSHREMOTEPROCESSRUNNER_H 32 | #define SSHREMOTEPROCESSRUNNER_H 33 | 34 | #include "sshconnection.h" 35 | #include "sshremoteprocess.h" 36 | 37 | namespace QSsh { 38 | namespace Internal { 39 | class SshRemoteProcessRunnerPrivate; 40 | } // namespace Internal 41 | 42 | /*! 43 | \class QSsh::SshRemoteProcessRunner 44 | 45 | \brief Convenience class for running a remote process over an SSH connection. 46 | */ 47 | 48 | class QSSH_EXPORT SshRemoteProcessRunner : public QObject 49 | { 50 | Q_OBJECT 51 | 52 | public: 53 | SshRemoteProcessRunner(QObject *parent = nullptr); 54 | ~SshRemoteProcessRunner(); 55 | 56 | void run(const QByteArray &command, const SshConnectionParameters &sshParams); 57 | void runInTerminal(const QByteArray &command, const SshPseudoTerminal &terminal, 58 | const SshConnectionParameters &sshParams); 59 | QByteArray command() const; 60 | 61 | QSsh::SshError lastConnectionError() const; 62 | QString lastConnectionErrorString() const; 63 | 64 | bool isProcessRunning() const; 65 | void writeDataToProcess(const QByteArray &data); 66 | void sendSignalToProcess(SshRemoteProcess::Signal signal); // No effect with OpenSSH server. 67 | void cancel(); // Does not stop remote process, just frees SSH-related process resources. 68 | SshRemoteProcess::ExitStatus processExitStatus() const; 69 | SshRemoteProcess::Signal processExitSignal() const; 70 | int processExitCode() const; 71 | QString processErrorString() const; 72 | QByteArray readAllStandardOutput(); 73 | QByteArray readAllStandardError(); 74 | 75 | signals: 76 | void connectionError(); 77 | void processStarted(); 78 | void readyReadStandardOutput(); 79 | void readyReadStandardError(); 80 | void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus 81 | 82 | private: 83 | void handleConnected(); 84 | void handleConnectionError(QSsh::SshError error); 85 | void handleDisconnected(); 86 | void handleProcessStarted(); 87 | void handleProcessFinished(int exitStatus); 88 | void handleStdout(); 89 | void handleStderr(); 90 | void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams); 91 | void setState(int newState); 92 | 93 | Internal::SshRemoteProcessRunnerPrivate * const d; 94 | }; 95 | 96 | } // namespace QSsh 97 | 98 | #endif // SSHREMOTEPROCESSRUNNER_H 99 | -------------------------------------------------------------------------------- /src/libs/qssh/sshtcpipforwardserver.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 "sshtcpipforwardserver.h" 27 | #include "sshtcpipforwardserver_p.h" 28 | 29 | #include "sshlogging_p.h" 30 | #include "sshsendfacility_p.h" 31 | 32 | namespace QSsh { 33 | namespace Internal { 34 | 35 | SshTcpIpForwardServerPrivate::SshTcpIpForwardServerPrivate(const QString &bindAddress, 36 | quint16 bindPort, SshSendFacility &sendFacility) 37 | : m_sendFacility(sendFacility), 38 | m_bindAddress(bindAddress), 39 | m_bindPort(bindPort), 40 | m_state(SshTcpIpForwardServer::Inactive) 41 | { 42 | } 43 | 44 | } // namespace Internal 45 | 46 | using namespace Internal; 47 | 48 | SshTcpIpForwardServer::SshTcpIpForwardServer(const QString &bindAddress, quint16 bindPort, 49 | SshSendFacility &sendFacility) 50 | : d(new SshTcpIpForwardServerPrivate(bindAddress, bindPort, sendFacility)) 51 | { 52 | d->m_timeoutTimer.setTimerType(Qt::VeryCoarseTimer); 53 | connect(&d->m_timeoutTimer, &QTimer::timeout, this, &SshTcpIpForwardServer::setClosed); 54 | } 55 | 56 | void SshTcpIpForwardServer::setListening(quint16 port) 57 | { 58 | QSSH_ASSERT_AND_RETURN(d->m_state != Listening); 59 | d->m_bindPort = port; 60 | d->m_state = Listening; 61 | emit stateChanged(Listening); 62 | } 63 | 64 | void SshTcpIpForwardServer::setClosed() 65 | { 66 | QSSH_ASSERT_AND_RETURN(d->m_state != Inactive); 67 | d->m_state = Inactive; 68 | emit stateChanged(Inactive); 69 | } 70 | 71 | void SshTcpIpForwardServer::setNewConnection(const SshForwardedTcpIpTunnel::Ptr &connection) 72 | { 73 | d->m_pendingConnections.append(connection); 74 | emit newConnection(); 75 | } 76 | 77 | SshTcpIpForwardServer::~SshTcpIpForwardServer() 78 | { 79 | delete d; 80 | } 81 | 82 | void SshTcpIpForwardServer::initialize() 83 | { 84 | if (d->m_state == Inactive || d->m_state == Closing) { 85 | try { 86 | d->m_state = Initializing; 87 | emit stateChanged(Initializing); 88 | d->m_sendFacility.sendTcpIpForwardPacket(d->m_bindAddress.toUtf8(), d->m_bindPort); 89 | d->m_timeoutTimer.start(SshTcpIpForwardServerPrivate::ReplyTimeout); 90 | } catch (const std::exception &e) { 91 | qCWarning(sshLog, "Botan error: %s", e.what()); 92 | d->m_timeoutTimer.stop(); 93 | setClosed(); 94 | } 95 | } 96 | } 97 | 98 | void SshTcpIpForwardServer::close() 99 | { 100 | d->m_timeoutTimer.stop(); 101 | 102 | if (d->m_state == Initializing || d->m_state == Listening) { 103 | try { 104 | d->m_state = Closing; 105 | emit stateChanged(Closing); 106 | d->m_sendFacility.sendCancelTcpIpForwardPacket(d->m_bindAddress.toUtf8(), 107 | d->m_bindPort); 108 | d->m_timeoutTimer.start(SshTcpIpForwardServerPrivate::ReplyTimeout); 109 | } catch (const std::exception &e) { 110 | qCWarning(sshLog, "Botan error: %s", e.what()); 111 | d->m_timeoutTimer.stop(); 112 | setClosed(); 113 | } 114 | } 115 | } 116 | 117 | const QString &SshTcpIpForwardServer::bindAddress() const 118 | { 119 | return d->m_bindAddress; 120 | } 121 | 122 | quint16 SshTcpIpForwardServer::port() const 123 | { 124 | return d->m_bindPort; 125 | } 126 | 127 | SshTcpIpForwardServer::State SshTcpIpForwardServer::state() const 128 | { 129 | return d->m_state; 130 | } 131 | 132 | SshForwardedTcpIpTunnel::Ptr SshTcpIpForwardServer::nextPendingConnection() 133 | { 134 | return d->m_pendingConnections.takeFirst(); 135 | } 136 | 137 | } // namespace QSsh 138 | -------------------------------------------------------------------------------- /src/libs/qssh/sshtcpipforwardserver.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 | #pragma once 27 | 28 | #include "ssh_global.h" 29 | #include "sshforwardedtcpiptunnel.h" 30 | #include 31 | 32 | namespace QSsh { 33 | 34 | namespace Internal { 35 | class SshChannelManager; 36 | class SshTcpIpForwardServerPrivate; 37 | class SshSendFacility; 38 | class SshConnectionPrivate; 39 | } // namespace Internal 40 | 41 | class QSSH_EXPORT SshTcpIpForwardServer : public QObject 42 | { 43 | Q_OBJECT 44 | friend class Internal::SshChannelManager; 45 | friend class Internal::SshConnectionPrivate; 46 | 47 | public: 48 | enum State { 49 | Inactive, 50 | Initializing, 51 | Listening, 52 | Closing 53 | }; 54 | 55 | typedef QSharedPointer Ptr; 56 | ~SshTcpIpForwardServer(); 57 | 58 | const QString &bindAddress() const; 59 | quint16 port() const; 60 | State state() const; 61 | void initialize(); 62 | void close(); 63 | 64 | SshForwardedTcpIpTunnel::Ptr nextPendingConnection(); 65 | 66 | signals: 67 | void error(const QString &reason); 68 | void newConnection(); 69 | void stateChanged(State state); 70 | 71 | private: 72 | SshTcpIpForwardServer(const QString &bindAddress, quint16 bindPort, 73 | Internal::SshSendFacility &sendFacility); 74 | void setListening(quint16 port); 75 | void setClosed(); 76 | void setNewConnection(const SshForwardedTcpIpTunnel::Ptr &connection); 77 | 78 | Internal::SshTcpIpForwardServerPrivate * const d; 79 | }; 80 | 81 | } // namespace QSsh 82 | -------------------------------------------------------------------------------- /src/libs/qssh/sshtcpipforwardserver_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 | #pragma once 27 | 28 | #include "sshtcpipforwardserver.h" 29 | #include 30 | #include 31 | 32 | namespace QSsh { 33 | namespace Internal { 34 | 35 | class SshTcpIpForwardServerPrivate 36 | { 37 | public: 38 | static const int ReplyTimeout = 10000; // milli seconds 39 | 40 | SshTcpIpForwardServerPrivate(const QString &bindAddress, quint16 bindPort, 41 | SshSendFacility &sendFacility); 42 | 43 | SshSendFacility &m_sendFacility; 44 | QTimer m_timeoutTimer; 45 | 46 | const QString m_bindAddress; 47 | quint16 m_bindPort; 48 | SshTcpIpForwardServer::State m_state; 49 | 50 | QList m_pendingConnections; 51 | }; 52 | 53 | } // namespace Internal 54 | } // namespace QSsh 55 | -------------------------------------------------------------------------------- /src/libs/qssh/sshtcpiptunnel.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 "sshsendfacility_p.h" 27 | #include "sshtcpiptunnel_p.h" 28 | 29 | #include "sshincomingpacket_p.h" 30 | #include "sshexception_p.h" 31 | #include "sshlogging_p.h" 32 | 33 | namespace QSsh { 34 | 35 | namespace Internal { 36 | SshTcpIpTunnelPrivate::SshTcpIpTunnelPrivate(quint32 channelId, SshSendFacility &sendFacility) 37 | : AbstractSshChannel(channelId, sendFacility) 38 | { 39 | connect(this, &AbstractSshChannel::eof, this, &SshTcpIpTunnelPrivate::handleEof); 40 | } 41 | 42 | SshTcpIpTunnelPrivate::~SshTcpIpTunnelPrivate() 43 | { 44 | closeChannel(); 45 | } 46 | 47 | 48 | 49 | void SshTcpIpTunnelPrivate::handleChannelSuccess() 50 | { 51 | throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR, 52 | "Unexpected SSH_MSG_CHANNEL_SUCCESS message."); 53 | } 54 | 55 | void SshTcpIpTunnelPrivate::handleChannelFailure() 56 | { 57 | throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR, 58 | "Unexpected SSH_MSG_CHANNEL_FAILURE message."); 59 | } 60 | 61 | void SshTcpIpTunnelPrivate::handleOpenFailureInternal(const QString &reason) 62 | { 63 | emit error(reason); 64 | closeChannel(); 65 | } 66 | 67 | void SshTcpIpTunnelPrivate::handleChannelDataInternal(const QByteArray &data) 68 | { 69 | m_data += data; 70 | emit readyRead(); 71 | } 72 | 73 | void SshTcpIpTunnelPrivate::handleChannelExtendedDataInternal(quint32 type, 74 | const QByteArray &data) 75 | { 76 | qCWarning(sshLog, "%s: Unexpected extended channel data. Type is %u, content is '%s'.", 77 | Q_FUNC_INFO, type, data.constData()); 78 | } 79 | 80 | void SshTcpIpTunnelPrivate::handleExitStatus(const SshChannelExitStatus &exitStatus) 81 | { 82 | qCWarning(sshLog, "%s: Unexpected exit status %d.", Q_FUNC_INFO, exitStatus.exitStatus); 83 | } 84 | 85 | void SshTcpIpTunnelPrivate::handleExitSignal(const SshChannelExitSignal &signal) 86 | { 87 | qCWarning(sshLog, "%s: Unexpected exit signal %s.", Q_FUNC_INFO, signal.signal.constData()); 88 | } 89 | 90 | void SshTcpIpTunnelPrivate::closeHook() 91 | { 92 | emit closed(); 93 | } 94 | 95 | void SshTcpIpTunnelPrivate::handleEof() 96 | { 97 | /* 98 | * For some reason, the OpenSSH server only sends EOF when the remote port goes away, 99 | * but does not close the channel, even though it becomes useless in that case. 100 | * So we close it ourselves. 101 | */ 102 | closeChannel(); 103 | } 104 | 105 | qint64 SshTcpIpTunnelPrivate::readData(char *data, qint64 maxlen) 106 | { 107 | const qint64 bytesRead = qMin(qint64(m_data.count()), maxlen); 108 | memcpy(data, m_data.constData(), bytesRead); 109 | m_data.remove(0, bytesRead); 110 | return bytesRead; 111 | } 112 | 113 | qint64 SshTcpIpTunnelPrivate::writeData(const char *data, qint64 len) 114 | { 115 | QSSH_ASSERT_AND_RETURN_VALUE(channelState() == AbstractSshChannel::SessionEstablished, 0); 116 | 117 | sendData(QByteArray(data, len)); 118 | return len; 119 | } 120 | 121 | } // namespace Internal 122 | 123 | } // namespace QSsh 124 | -------------------------------------------------------------------------------- /src/libs/qssh/sshtcpiptunnel_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 | #pragma once 27 | 28 | #include "sshchannel_p.h" 29 | #include 30 | #include 31 | 32 | namespace QSsh { 33 | namespace Internal { 34 | 35 | class SshTcpIpTunnelPrivate : public AbstractSshChannel 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | SshTcpIpTunnelPrivate(quint32 channelId, SshSendFacility &sendFacility); 41 | ~SshTcpIpTunnelPrivate(); 42 | 43 | template 44 | void init(SshTcpIpTunnel *q) 45 | { 46 | connect(this, &SshTcpIpTunnelPrivate::closed, 47 | q, &SshTcpIpTunnel::close, Qt::QueuedConnection); 48 | connect(this, &SshTcpIpTunnelPrivate::readyRead, 49 | q, &SshTcpIpTunnel::readyRead, Qt::QueuedConnection); 50 | connect(this, &SshTcpIpTunnelPrivate::error, q, [q](const QString &reason) { 51 | q->setErrorString(reason); 52 | emit q->error(reason); 53 | }, Qt::QueuedConnection); 54 | } 55 | 56 | void handleChannelSuccess() override; 57 | void handleChannelFailure() override; 58 | 59 | qint64 readData(char *data, qint64 maxlen); 60 | qint64 writeData(const char *data, qint64 len); 61 | 62 | signals: 63 | void readyRead(); 64 | void error(const QString &reason); 65 | void closed(); 66 | 67 | protected: 68 | void handleOpenFailureInternal(const QString &reason) override; 69 | void handleChannelDataInternal(const QByteArray &data) override; 70 | void handleChannelExtendedDataInternal(quint32 type, const QByteArray &data) override; 71 | void handleExitStatus(const SshChannelExitStatus &exitStatus) override; 72 | void handleExitSignal(const SshChannelExitSignal &signal) override; 73 | void closeHook() override; 74 | 75 | QByteArray m_data; 76 | 77 | private: 78 | void handleEof(); 79 | }; 80 | 81 | } // namespace Internal 82 | } // namespace QSsh 83 | -------------------------------------------------------------------------------- /src/libs/qssh/sshx11channel_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 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 | #pragma once 27 | 28 | #include "sshchannel_p.h" 29 | 30 | #include "sshx11displayinfo_p.h" 31 | 32 | #include 33 | 34 | namespace QSsh { 35 | namespace Internal { 36 | class SshChannelManager; 37 | class SshSendFacility; 38 | class X11Socket; 39 | 40 | class SshX11Channel : public AbstractSshChannel 41 | { 42 | Q_OBJECT 43 | 44 | friend class Internal::SshChannelManager; 45 | 46 | signals: 47 | void error(const QString &message); 48 | 49 | private: 50 | SshX11Channel(const X11DisplayInfo &displayInfo, quint32 channelId, 51 | SshSendFacility &sendFacility); 52 | 53 | void handleChannelSuccess() override; 54 | void handleChannelFailure() override; 55 | 56 | void handleOpenSuccessInternal() override; 57 | void handleOpenFailureInternal(const QString &reason) override; 58 | void handleChannelDataInternal(const QByteArray &data) override; 59 | void handleChannelExtendedDataInternal(quint32 type, const QByteArray &data) override; 60 | void handleExitStatus(const SshChannelExitStatus &exitStatus) override; 61 | void handleExitSignal(const SshChannelExitSignal &signal) override; 62 | void closeHook() override; 63 | 64 | void handleRemoteData(const QByteArray &data); 65 | 66 | X11Socket * const m_x11Socket; 67 | const X11DisplayInfo m_displayInfo; 68 | QByteArray m_queuedRemoteData; 69 | bool m_haveReplacedRandomCookie = false; 70 | }; 71 | 72 | } // namespace Internal 73 | } // namespace QSsh 74 | -------------------------------------------------------------------------------- /src/libs/qssh/sshx11displayinfo_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 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 | #pragma once 27 | 28 | #include "ssh_global.h" 29 | 30 | #include 31 | #include 32 | 33 | namespace QSsh { 34 | namespace Internal { 35 | 36 | class QSSH_EXPORT X11DisplayInfo 37 | { 38 | public: 39 | QString displayName; 40 | QString hostName; 41 | QByteArray protocol; 42 | QByteArray cookie; 43 | QByteArray randomCookie; 44 | int display = 0; 45 | int screen = 0; 46 | }; 47 | 48 | } // namespace Internal 49 | } // namespace QSsh 50 | -------------------------------------------------------------------------------- /src/libs/qssh/sshx11inforetriever_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 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 | #pragma once 27 | 28 | #include "ssh_global.h" 29 | 30 | #include 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | class QByteArray; 35 | class QProcess; 36 | class QTemporaryFile; 37 | QT_END_NAMESPACE 38 | 39 | namespace QSsh { 40 | namespace Internal { 41 | class X11DisplayInfo; 42 | 43 | class QSSH_EXPORT SshX11InfoRetriever : public QObject 44 | { 45 | Q_OBJECT 46 | public: 47 | SshX11InfoRetriever(const QString &displayName, QObject *parent = nullptr); 48 | void start(); 49 | 50 | signals: 51 | void failure(const QString &message); 52 | void success(const X11DisplayInfo &displayInfo); 53 | 54 | private: 55 | void emitFailure(const QString &reason); 56 | 57 | const QString m_displayName; 58 | QProcess * const m_xauthProc; 59 | QTemporaryFile * const m_xauthFile; 60 | 61 | enum class State { Inactive, RunningGenerate, RunningList } m_state = State::Inactive; 62 | }; 63 | 64 | } // namespace Internal 65 | } // namespace QSsh 66 | -------------------------------------------------------------------------------- /src/qtcreatorlibrary.pri: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/rpath.pri: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandsmark/QSsh/3942e51b529165a2ca7c7f5bd09b298fee8b41a4/src/rpath.pri -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | 4 | SUBDIRS = \ 5 | libs 6 | -------------------------------------------------------------------------------- /tests/auto/auto.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | ssh \ 5 | 6 | -------------------------------------------------------------------------------- /tests/auto/qttest.pri: -------------------------------------------------------------------------------- 1 | include(../../qssh.pri) 2 | include(qttestrpath.pri) 3 | 4 | TEMPLATE=app 5 | QT += testlib 6 | CONFIG += qt warn_on console depend_includepath testcase no_testcase_installs 7 | CONFIG -= app_bundle 8 | 9 | DEFINES -= QT_RESTRICTED_CAST_FROM_ASCII 10 | 11 | win32 { 12 | lib = $$IDE_LIBRARY_PATH;$$IDE_PLUGIN_PATH 13 | lib ~= s,/,\\,g 14 | # the below gets added to later by testcase.prf 15 | check.commands = cd . & set PATH=$$lib;%PATH%& cmd /c 16 | } 17 | -------------------------------------------------------------------------------- /tests/auto/qttestrpath.pri: -------------------------------------------------------------------------------- 1 | linux-* { 2 | QMAKE_RPATHDIR += $$IDE_BUILD_TREE/$$IDE_LIBRARY_BASENAME/ 3 | QMAKE_RPATHDIR += $$IDE_PLUGIN_PATH 4 | 5 | IDE_PLUGIN_RPATH = $$join(QMAKE_RPATHDIR, ":") 6 | 7 | QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${IDE_PLUGIN_RPATH}\' 8 | } else:macx { 9 | QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_BIN_PATH/../\" 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/auto/ssh/README.md: -------------------------------------------------------------------------------- 1 | ssh/sftp auto test 2 | ================== 3 | 4 | This example needs or uses the following environment variables to know where 5 | and how to connect to run the tests. I've just tested with an openssh server, 6 | but in theory any should work. 7 | 8 | * `QTC_SSH_TEST_HOST`: The hostname of the server to connect to. 9 | * `QTC_SSH_TEST_PORT`: The port to connect to. 10 | * `QTC_SSH_TEST_USER`: The username to use when connecting. 11 | * `QTC_SSH_TEST_PASSWORD`: The password to use when connecting. 12 | * `QTC_SSH_TEST_KEYFILE`: The key file to use when connecting. 13 | * `QTC_SSH_TEST_KEYFILE`: The key file to use when connecting. 14 | 15 | For the tunnel tests (uses `localhost` instead of `QTC_SSH_TEST_HOST`): 16 | * `QTC_SSH_TEST_PORT_TUNNEL` 17 | * `QTC_SSH_TEST_USER_TUNNEL` 18 | * `QTC_SSH_TEST_PASSWORD_TUNNEL` 19 | * `QTC_SSH_TEST_KEYFILE_TUNNEL` 20 | -------------------------------------------------------------------------------- /tests/auto/ssh/ssh.pro: -------------------------------------------------------------------------------- 1 | QT = core network 2 | LIBS += -lQSsh 3 | include(../qttest.pri) 4 | 5 | SOURCES += tst_ssh.cpp 6 | -------------------------------------------------------------------------------- /tests/manual/manual.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE=subdirs 2 | 3 | 4 | unix { 5 | SUBDIRS += ssh 6 | } 7 | -------------------------------------------------------------------------------- /tests/manual/ssh/qssh.pri: -------------------------------------------------------------------------------- 1 | QT = core network 2 | 3 | include (../../../qssh.pri) 4 | include (../../../src/libs/qssh/qssh.pri) 5 | 6 | macx:QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_BIN_PATH/..\" 7 | INCLUDEPATH *= $$IDE_SOURCE_TREE/src/plugins 8 | LIBS *= -L$$IDE_LIBRARY_PATH 9 | unix { 10 | QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_LIBRARY_PATH\" 11 | } 12 | 13 | CONFIG += console 14 | CONFIG -= app_bundle 15 | TEMPLATE = app 16 | 17 | DEPENDPATH+=. 18 | INCLUDEPATH+=. 19 | -------------------------------------------------------------------------------- /tests/manual/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 | -------------------------------------------------------------------------------- /tests/manual/ssh/sftpfsmodel/sftpfsmodel.pro: -------------------------------------------------------------------------------- 1 | include(../qssh.pri) 2 | 3 | QT += gui widgets 4 | 5 | TARGET=sftpfsmodel 6 | SOURCES+=main.cpp window.cpp 7 | HEADERS+=window.h 8 | FORMS=window.ui 9 | -------------------------------------------------------------------------------- /tests/manual/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 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | using namespace QSsh; 41 | 42 | SftpFsWindow::SftpFsWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::Window) 43 | { 44 | m_ui->setupUi(this); 45 | connect(m_ui->connectButton, &QAbstractButton::clicked, this, &SftpFsWindow::connectToHost); 46 | connect(m_ui->downloadButton, &QAbstractButton::clicked, this, &SftpFsWindow::downloadFile); 47 | } 48 | 49 | SftpFsWindow::~SftpFsWindow() 50 | { 51 | delete m_ui; 52 | } 53 | 54 | void SftpFsWindow::connectToHost() 55 | { 56 | m_ui->connectButton->setEnabled(false); 57 | SshConnectionParameters sshParams; 58 | sshParams.setHost(m_ui->hostLineEdit->text()); 59 | sshParams.setUserName(m_ui->userLineEdit->text()); 60 | sshParams.authenticationType 61 | = SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods; 62 | sshParams.setPassword(m_ui->passwordLineEdit->text()); 63 | sshParams.setPort(m_ui->portSpinBox->value()); 64 | sshParams.timeout = 10; 65 | m_fsModel = new SftpFileSystemModel(this); 66 | connect(m_fsModel, &SftpFileSystemModel::sftpOperationFailed, 67 | this, &SftpFsWindow::handleSftpOperationFailed); 68 | connect(m_fsModel, &SftpFileSystemModel::connectionError, 69 | this, &SftpFsWindow::handleConnectionError); 70 | connect(m_fsModel, &SftpFileSystemModel::sftpOperationFinished, 71 | this, &SftpFsWindow::handleSftpOperationFinished); 72 | m_fsModel->setSshConnection(sshParams); 73 | m_ui->fsView->setModel(m_fsModel); 74 | } 75 | 76 | void SftpFsWindow::downloadFile() 77 | { 78 | const QModelIndexList selectedIndexes = m_ui->fsView->selectionModel()->selectedIndexes(); 79 | if (selectedIndexes.count() != 2) 80 | return; 81 | const QString targetFilePath = QFileDialog::getSaveFileName(this, tr("Choose Target File"), 82 | QDir::tempPath()); 83 | if (targetFilePath.isEmpty()) 84 | return; 85 | const SftpJobId jobId = m_fsModel->downloadFile(selectedIndexes.at(1), targetFilePath); 86 | QString message; 87 | if (jobId == SftpInvalidJob) 88 | message = tr("Download failed."); 89 | else 90 | message = tr("Queuing download operation %1.").arg(jobId); 91 | m_ui->outputTextEdit->appendPlainText(message); 92 | } 93 | 94 | void SftpFsWindow::handleSftpOperationFailed(const QString &errorMessage) 95 | { 96 | m_ui->outputTextEdit->appendPlainText(errorMessage); 97 | } 98 | 99 | void SftpFsWindow::handleSftpOperationFinished(SftpJobId jobId, const QString &error) 100 | { 101 | QString message; 102 | if (error.isEmpty()) 103 | message = tr("Operation %1 finished successfully.").arg(jobId); 104 | else 105 | message = tr("Operation %1 failed: %2.").arg(jobId).arg(error); 106 | m_ui->outputTextEdit->appendPlainText(message); 107 | } 108 | 109 | void SftpFsWindow::handleConnectionError(const QString &errorMessage) 110 | { 111 | QMessageBox::warning(this, tr("Connection Error"), 112 | tr("Fatal SSH error: %1").arg(errorMessage)); 113 | QCoreApplication::quit(); 114 | } 115 | -------------------------------------------------------------------------------- /tests/manual/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: 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 | QSsh::SftpFileSystemModel *m_fsModel; 51 | Ui::Window *m_ui; 52 | }; 53 | -------------------------------------------------------------------------------- /tests/manual/ssh/ssh.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2010-07-01T09:44:44 4 | # 5 | #------------------------------------------------- 6 | 7 | TEMPLATE = subdirs 8 | SUBDIRS = sftpfsmodel 9 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE=subdirs 2 | SUBDIRS += manual auto 3 | --------------------------------------------------------------------------------