mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-21 02:15:51 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07c7fc66d3 | ||
|
|
f852ff6dff |
@@ -1,39 +0,0 @@
|
||||
BasedOnStyle: WebKit
|
||||
AccessModifierOffset: '-4'
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllArgumentsOnNextLine: 'true'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'true'
|
||||
AllowShortBlocksOnASingleLine: 'false'
|
||||
AllowShortCaseLabelsOnASingleLine: 'true'
|
||||
AllowShortEnumsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AlwaysBreakTemplateDeclarations: 'No'
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
ColumnLimit: '120'
|
||||
CommentPragmas: '"^!|^:"'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
ConstructorInitializerIndentWidth: '4'
|
||||
ContinuationIndentWidth: '8'
|
||||
IndentPPDirectives: BeforeHash
|
||||
NamespaceIndentation: All
|
||||
PenaltyExcessCharacter: '10'
|
||||
PointerAlignment: Right
|
||||
SortIncludes: 'true'
|
||||
SpaceAfterTemplateKeyword: 'false'
|
||||
Standard: Auto
|
||||
@@ -1,20 +0,0 @@
|
||||
/client/3rd
|
||||
/client/3rd-prebuild
|
||||
/client/android
|
||||
/client/cmake
|
||||
/client/core/utils/serialization
|
||||
/client/daemon
|
||||
/client/fonts
|
||||
/client/images
|
||||
/client/ios
|
||||
/client/mozilla
|
||||
/client/platforms/dummy
|
||||
/client/platforms/linux
|
||||
/client/platforms/macos
|
||||
/client/platforms/windows
|
||||
/client/server_scripts
|
||||
/client/translations
|
||||
/deploy
|
||||
/docs
|
||||
/metadata
|
||||
/service/src
|
||||
6
.gitattributes
vendored
6
.gitattributes
vendored
@@ -1,6 +0,0 @@
|
||||
deploy/data/windows/x64/tap/windows_7/OemVista.inf eol=crlf
|
||||
deploy/data/windows/x64/tap/windows_10/OemVista.inf eol=crlf
|
||||
deploy/data/windows/x32/tap/windows_7/OemVista.inf eol=crlf
|
||||
deploy/data/windows/x32/tap/windows_10/OemVista.inf eol=crlf
|
||||
client/3rd/* linguist-vendored
|
||||
client/android/gradlew.bat eol=crlf
|
||||
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,42 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Log files**
|
||||
Attach log files to help explain your problem.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. Windows 10]
|
||||
- Version [e.g. 2.1.2]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Version [e.g. 2.1.2]
|
||||
|
||||
**Server (please complete the following information):**
|
||||
- OS: [e.g. Ubuntu 22.04]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
38
.github/actions/apple-install-cert/action.yml
vendored
38
.github/actions/apple-install-cert/action.yml
vendored
@@ -1,38 +0,0 @@
|
||||
# .github/actions/apple-install-cert/action.yml
|
||||
|
||||
name: Setup apple keychain
|
||||
description: Creates and configures a temporary build keychain
|
||||
|
||||
inputs:
|
||||
keychain-path:
|
||||
description: Path to the keychain
|
||||
required: true
|
||||
keychain-password:
|
||||
description: Password to the keychain
|
||||
required: true
|
||||
cert-base64:
|
||||
description: Base64-encoded certificate
|
||||
required: true
|
||||
cert-password:
|
||||
description: Certificate password
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Create keychain
|
||||
shell: bash
|
||||
env:
|
||||
KEYCHAIN_PATH: ${{ inputs.keychain-path }}
|
||||
KEYCHAIN_PASSWORD: ${{ inputs.keychain-password }}
|
||||
CERT_BASE64: ${{ inputs.cert-base64 }}
|
||||
CERT_PASSWORD: ${{ inputs.cert-password }}
|
||||
run: |
|
||||
CERT_PATH=$(mktemp /tmp/cert_XXXXXX.p12)
|
||||
trap "rm -f '$CERT_PATH'" EXIT
|
||||
|
||||
echo -n "$CERT_BASE64" | base64 --decode -o "$CERT_PATH"
|
||||
|
||||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
|
||||
security import "$CERT_PATH" -k "$KEYCHAIN_PATH" -P "$CERT_PASSWORD" -A -t cert -f pkcs12
|
||||
security set-key-partition-list -S apple-tool:,apple:,codesign: -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
|
||||
Binary file not shown.
Binary file not shown.
57
.github/actions/apple-setup-keychain/action.yml
vendored
57
.github/actions/apple-setup-keychain/action.yml
vendored
@@ -1,57 +0,0 @@
|
||||
# .github/actions/apple-setup-keychain/action.yml
|
||||
|
||||
name: Setup apple keychain
|
||||
description: Creates and configures a temporary build keychain
|
||||
|
||||
inputs:
|
||||
keychain-name:
|
||||
description: Name of the keychain
|
||||
required: false
|
||||
default: "ci-amnezia"
|
||||
keychain-password:
|
||||
description: The keychain password
|
||||
required: true
|
||||
lock-timeout:
|
||||
description: A timeout after exceeding which the keychain would be locked
|
||||
required: false
|
||||
default: "0"
|
||||
|
||||
outputs:
|
||||
keychain-path:
|
||||
description: "Full path to the keychain created"
|
||||
value: ${{ steps.setup.outputs.keychain-path }}
|
||||
keychain-name:
|
||||
description: "Actual name of the keychain created"
|
||||
value: ${{ steps.setup.outputs.keychain-name }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup keychain
|
||||
id: setup
|
||||
shell: bash
|
||||
env:
|
||||
KEYCHAIN_NAME: ${{ inputs.keychain-name }}
|
||||
KEYCHAIN_PASSWORD: ${{ inputs.keychain-password }}
|
||||
LOCK_TIMEOUT: ${{ inputs.lock-timeout }}
|
||||
run: |
|
||||
KEYCHAIN_PATH="$HOME/Library/Keychains/$KEYCHAIN_NAME.keychain-db"
|
||||
|
||||
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
|
||||
|
||||
if [[ "$LOCK_TIMEOUT" == "0" ]]; then
|
||||
security set-keychain-settings "$KEYCHAIN_PATH"
|
||||
else
|
||||
security set-keychain-settings -u -t "$LOCK_TIMEOUT" "$KEYCHAIN_PATH"
|
||||
fi
|
||||
|
||||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
|
||||
|
||||
security import "${{ github.action_path }}/DeveloperIDG2CA.cer" -k "$KEYCHAIN_PATH" -A
|
||||
security import "${{ github.action_path }}/AppleWWDRCAG3.cer" -k "$KEYCHAIN_PATH" -A
|
||||
|
||||
security list-keychains -d user -s "$KEYCHAIN_PATH"
|
||||
security default-keychain -s "$KEYCHAIN_PATH"
|
||||
|
||||
echo "keychain-name=$KEYCHAIN_NAME" >> $GITHUB_OUTPUT
|
||||
echo "keychain-path=$KEYCHAIN_PATH" >> $GITHUB_OUTPUT
|
||||
@@ -1,31 +0,0 @@
|
||||
# .github/actions/apple-setup-provisioning-profile/action.yml
|
||||
|
||||
name: Setup provisioning profiles
|
||||
description: Decodes and installs provisioning profiles
|
||||
|
||||
inputs:
|
||||
provisioning_profile_base64:
|
||||
description: Base64-encoded provisioning profile
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup provisioning profile
|
||||
shell: bash
|
||||
run: |
|
||||
PROFILES_DIR="$HOME/Library/MobileDevice/Provisioning Profiles"
|
||||
TEMP_FILE=$(mktemp)
|
||||
|
||||
echo "${{ inputs.provisioning_profile_base64 }}" | base64 --decode > "$TEMP_FILE"
|
||||
|
||||
PROFILE_UUID=$(grep UUID -A1 -a "$TEMP_FILE" | grep -io "[-A-F0-9]\{36\}")
|
||||
if [[ -z "$PROFILE_UUID" ]]; then
|
||||
echo "Failed to extract UUID from provisioning profile"
|
||||
rm -f "$TEMP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$PROFILES_DIR"
|
||||
mv "$TEMP_FILE" "$PROFILES_DIR/$PROFILE_UUID.mobileprovision"
|
||||
echo "Installed profile: $PROFILE_UUID"
|
||||
914
.github/workflows/deploy.yml
vendored
914
.github/workflows/deploy.yml
vendored
@@ -1,914 +0,0 @@
|
||||
name: 'Deploy workflow'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
QT_MIRROR: https://mirrors.ocf.berkeley.edu/qt/ # https://download.qt.io/static/mirrorlist/
|
||||
|
||||
jobs:
|
||||
Detect-Changes:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
recipes_changed: ${{ steps.filter.outputs.recipes }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dorny/paths-filter@v3
|
||||
id: filter
|
||||
with:
|
||||
filters: |
|
||||
recipes:
|
||||
- 'recipes/**'
|
||||
- 'conanfile.py'
|
||||
|
||||
Bake-Prebuilts-Linux:
|
||||
runs-on: ubuntu-latest
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
shell: bash
|
||||
run: |
|
||||
for build_type in Release Debug; do
|
||||
cmake -S . -B build -DPREBUILTS_ONLY=1 "-DCMAKE_BUILD_TYPE=$build_type"
|
||||
done
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-Linux-Ubuntu:
|
||||
runs-on: android-runner
|
||||
|
||||
needs: Bake-Prebuilts-Linux
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
QIF_VERSION: 4.7
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'desktop'
|
||||
arch: 'linux_gcc_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
tools: 'tools_ifw'
|
||||
set-env: 'true'
|
||||
aqtversion: '==3.3.0'
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Install system packages'
|
||||
run: sudo apt-get install libxkbcommon-x11-0 libsecret-1-dev
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Build project'
|
||||
shell: bash
|
||||
env:
|
||||
QT_INSTALL_DIR: ${{ runner.temp }}
|
||||
run: deploy/build.sh --generator Ninja --installer all
|
||||
|
||||
- name: 'Upload installer artifact'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/AmneziaVPN_*_linux_x64.run
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload translations artifact'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_translations
|
||||
path: client/translations
|
||||
retention-days: 7
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Bake-Prebuilts-Windows:
|
||||
runs-on: windows-latest
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
run: cmake -S . -B build -G "Visual Studio 17 2022" -DPREBUILTS_ONLY=1
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-Windows:
|
||||
runs-on: windows-latest
|
||||
|
||||
needs: Bake-Prebuilts-Windows
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
QIF_VERSION: 4.7
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'windows'
|
||||
target: 'desktop'
|
||||
arch: 'win64_msvc2022_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
tools: 'tools_ifw'
|
||||
set-env: 'true'
|
||||
aqtversion: '==3.3.0'
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup mvsc'
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
with:
|
||||
arch: 'x64'
|
||||
|
||||
- name: 'Setup .NET SDK'
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: 'Install WiX Toolset'
|
||||
shell: powershell
|
||||
run: |
|
||||
dotnet tool install --global wix --version 4.0.6
|
||||
wix extension add -g WixToolset.UI.wixext/4.0.6
|
||||
wix extension add -g WixToolset.Util.wixext/4.0.6
|
||||
wix extension list -g
|
||||
$wixBinDir = Join-Path $env:USERPROFILE ".dotnet\tools"
|
||||
echo "WIX_BIN_DIR=$wixBinDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build project'
|
||||
shell: cmd
|
||||
env:
|
||||
QT_INSTALL_DIR: ${{ runner.temp }}
|
||||
run: |
|
||||
set WIX_ROOT_PATH="${{ env.USERPROFILE }}\.dotnet\tools"
|
||||
deploy\build.bat --installer all
|
||||
|
||||
- name: 'Upload WIX installer artifact'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/AmneziaVPN_*_windows_x64.msi
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload IFW installer artifact'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/AmneziaVPN_*_windows_x64.exe
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Bake-Prebuilts-iOS:
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
xcode-version: [26.0, 26.4]
|
||||
include:
|
||||
- xcode-version: 26.4
|
||||
os: macos-26
|
||||
|
||||
runs-on: ${{ matrix.os || 'macos-latest' }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: ${{ matrix.xcode-version }}
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
run: cmake -S . -B build -G Xcode -DPREBUILTS_ONLY=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-iOS:
|
||||
runs-on: macos-latest
|
||||
|
||||
needs: Bake-Prebuilts-iOS
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
KEYCHAIN_PASSWORD: ""
|
||||
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: ./.github/actions/apple-setup-keychain
|
||||
id: setup-keychain
|
||||
with:
|
||||
keychain-password: ${{ env.KEYCHAIN_PASSWORD }}
|
||||
|
||||
- name: 'Install signing certificate'
|
||||
uses: ./.github/actions/apple-install-cert
|
||||
with:
|
||||
keychain-path: ${{ steps.setup-keychain.outputs.keychain-path }}
|
||||
keychain-password: ${{ env.KEYCHAIN_PASSWORD }}
|
||||
cert-base64: ${{ secrets.IOS_SIGNING_CERT_BASE64 }}
|
||||
cert-password: ${{ secrets.IOS_SIGNING_CERT_PASSWORD }}
|
||||
|
||||
- name: 'Install app provisioning profile'
|
||||
uses: ./.github/actions/apple-setup-provisioning-profile
|
||||
with:
|
||||
provisioning_profile_base64: ${{ secrets.IOS_APP_PROVISIONING_PROFILE }}
|
||||
|
||||
- name: 'Install NE provisioning profile'
|
||||
uses: ./.github/actions/apple-setup-provisioning-profile
|
||||
with:
|
||||
provisioning_profile_base64: ${{ secrets.IOS_NE_PROVISIONING_PROFILE }}
|
||||
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '26.0'
|
||||
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'mac'
|
||||
target: 'desktop'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia'
|
||||
arch: 'clang_64'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install iOS Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'mac'
|
||||
target: 'ios'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install deps'
|
||||
run: pip install "conan==2.28.0" jsonschema jinja2
|
||||
|
||||
- name: 'Build project'
|
||||
env:
|
||||
QT_INSTALL_DIR: ${{ runner.temp }}
|
||||
APPSTORE_CONNECT_KEY_ID: ${{ secrets.APPSTORE_CONNECT_KEY_ID }}
|
||||
APPSTORE_CONNECT_ISSUER_ID: ${{ secrets.APPSTORE_CONNECT_ISSUER_ID }}
|
||||
APPSTORE_CONNECT_PRIVATE_KEY: ${{ secrets.APPSTORE_CONNECT_PRIVATE_KEY }}
|
||||
run: |
|
||||
sh deploy/build.sh -t ios | \
|
||||
sed -e '/-Xcc -DPROD_AGW_PUBLIC_KEY/,/-Xcc/ { /-Xcc/!d; }' -e '/-Xcc -DPROD_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-Xcc -DDEV_AGW_PUBLIC_KEY/,/-Xcc/ { /-Xcc/!d; }' -e '/-Xcc -DDEV_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-DPROD_AGW_PUBLIC_KEY/,/-D/ { /-D/!d; }' -e '/-DPROD_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-DDEV_AGW_PUBLIC_KEY/,/-D/ { /-D/!d; }' -e '/-DDEV_AGW_PUBLIC_KEY/d'
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Bake-Prebuilts-MacOS:
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
xcode-version: [16.2, 16.4, 26.4]
|
||||
include:
|
||||
- xcode-version: 26.4
|
||||
os: macos-26
|
||||
|
||||
runs-on: ${{ matrix.os || 'macos-latest' }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: ${{ matrix.xcode-version }}
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
run: cmake -S . -B build -G Xcode -DPREBUILTS_ONLY=1
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-MacOS:
|
||||
runs-on: macos-latest
|
||||
|
||||
needs: Bake-Prebuilts-MacOS
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
KEYCHAIN_PASSWORD: ""
|
||||
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: ./.github/actions/apple-setup-keychain
|
||||
id: setup-keychain
|
||||
with:
|
||||
keychain-password: ${{ env.KEYCHAIN_PASSWORD }}
|
||||
|
||||
- uses: ./.github/actions/apple-install-cert
|
||||
with:
|
||||
keychain-path: ${{ steps.setup-keychain.outputs.keychain-path }}
|
||||
keychain-password: ${{ env.KEYCHAIN_PASSWORD }}
|
||||
cert-base64: ${{ secrets.MAC_APP_CERT_CERT }}
|
||||
cert-password: ${{ secrets.MAC_APP_CERT_PW }}
|
||||
|
||||
- uses: ./.github/actions/apple-install-cert
|
||||
with:
|
||||
keychain-path: ${{ steps.setup-keychain.outputs.keychain-path }}
|
||||
keychain-password: ${{ env.KEYCHAIN_PASSWORD }}
|
||||
cert-base64: ${{ secrets.MAC_INSTALLER_SIGNER_CERT }}
|
||||
cert-password: ${{ secrets.MAC_INSTALL_CERT_PW }}
|
||||
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '16.2.0'
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'mac'
|
||||
target: 'desktop'
|
||||
arch: 'clang_64'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
aqtversion: '==3.3.0'
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build project'
|
||||
env:
|
||||
QT_INSTALL_DIR: ${{ runner.temp }}
|
||||
CODESIGN_SIGNATURE: ${{ secrets.MAC_SIGNER_ID }}
|
||||
CODESIGN_INSTALLER_SIGNATURE: ${{ secrets.MAC_INSTALLER_SIGNER_ID }}
|
||||
NOTARYTOOL_TEAM_ID: ${{ secrets.MAC_TEAM_ID }}
|
||||
NOTARYTOOL_EMAIL: ${{ secrets.APPLE_DEV_EMAIL }}
|
||||
NOTARYTOOL_PASSWORD: ${{ secrets.APPLE_DEV_PASSWORD }}
|
||||
shell: bash
|
||||
run: deploy/build.sh --generator Ninja --installer all
|
||||
|
||||
- name: 'Upload installer artifact'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/AmneziaVPN_*_macos_x64.pkg
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Bake-Prebuilts-MacOS-NE:
|
||||
runs-on: macos-latest
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
xcode-version: [16.2, 16.4]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: ${{ matrix.xcode-version }}
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
run: cmake -S . -B build -G Xcode -DPREBUILTS_ONLY=1 -DMACOS_NE=TRUE
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-MacOS-NE:
|
||||
runs-on: macos-latest
|
||||
|
||||
needs: Bake-Prebuilts-MacOS-NE
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.10.1
|
||||
|
||||
MAC_TEAM_ID: ${{ secrets.MAC_TEAM_ID }}
|
||||
|
||||
MAC_APP_CERT_CERT: ${{ secrets.MAC_APP_CERT_CERT }}
|
||||
MAC_SIGNER_ID: ${{ secrets.MAC_SIGNER_ID }}
|
||||
MAC_APP_CERT_PW: ${{ secrets.MAC_APP_CERT_PW }}
|
||||
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- uses: ./.github/actions/apple-setup-provisioning-profile
|
||||
with:
|
||||
provisioning_profile_base64: ${{ secrets.MAC_APP_PROVISIONING_PROFILE }}
|
||||
|
||||
- uses: ./.github/actions/apple-setup-provisioning-profile
|
||||
with:
|
||||
provisioning_profile_base64: ${{ secrets.MAC_NE_PROVISIONING_PROFILE }}
|
||||
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '26.1'
|
||||
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'mac'
|
||||
target: 'desktop'
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia'
|
||||
arch: 'clang_64'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install go'
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.24'
|
||||
cache: false
|
||||
|
||||
- name: 'Setup gomobile'
|
||||
run: |
|
||||
export PATH=$PATH:~/go/bin
|
||||
go install golang.org/x/mobile/cmd/gomobile@latest
|
||||
gomobile init
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Build project'
|
||||
run: |
|
||||
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin"
|
||||
bash deploy/build_macos_ne.sh
|
||||
|
||||
- name: 'Upload unpacked artifact'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_MacOS_unpacked
|
||||
path: deploy/build/client/AmneziaVPN.app
|
||||
retention-days: 7
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Bake-Prebuilts-Android:
|
||||
runs-on: android-runner
|
||||
needs: Detect-Changes
|
||||
if: needs.Detect-Changes.outputs.recipes_changed == 'true'
|
||||
|
||||
env:
|
||||
ANDROID_PLATFORM: android-28
|
||||
NDK_VERSION: 27.0.11718014
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Setup Android SDK'
|
||||
uses: android-actions/setup-android@v4
|
||||
with:
|
||||
packages: "platforms;${{ env.ANDROID_PLATFORM }} ndk;${{ env.NDK_VERSION }}"
|
||||
|
||||
- name: 'Build dependencies'
|
||||
run: |
|
||||
CMAKE_ANDROID_NDK="$ANDROID_HOME/ndk/$NDK_VERSION"
|
||||
args=(
|
||||
-G Ninja
|
||||
-DPREBUILTS_ONLY=1
|
||||
-DCMAKE_SYSTEM_NAME=Android
|
||||
"-DANDROID_PLATFORM=$ANDROID_PLATFORM"
|
||||
"-DCMAKE_ANDROID_NDK=$CMAKE_ANDROID_NDK"
|
||||
)
|
||||
|
||||
for abi in arm64-v8a armeabi-v7a x86 x86_64; do
|
||||
for build_type in Release Debug; do
|
||||
cmake -S . -B build_${abi//-/_} "${args[@]}" "-DCMAKE_ANDROID_ARCH_ABI=$abi" "-DCMAKE_BUILD_TYPE=$build_type"
|
||||
done
|
||||
done
|
||||
|
||||
- name: 'Authorize in remote'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan remote login amnezia "${{ secrets.CONAN_USER }}" -p "${{ secrets.CONAN_PASSWORD }}"
|
||||
|
||||
- name: 'Upload baked prebuilts'
|
||||
if: github.ref == 'refs/heads/dev'
|
||||
run: conan upload -r amnezia "*" -c
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-Android:
|
||||
runs-on: android-runner
|
||||
|
||||
needs: Bake-Prebuilts-Android
|
||||
if: ${{ always() }}
|
||||
|
||||
env:
|
||||
ANDROID_PLATFORM: android-28
|
||||
NDK_VERSION: 27.0.11718014
|
||||
QT_VERSION: 6.10.3
|
||||
QT_MODULES: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'desktop'
|
||||
arch: 'linux_gcc_64'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_x86_64 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_x86_64'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_x86 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_x86'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_armv7 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_armv7'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_arm64_v8a Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_arm64_v8a'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
py7zrversion: '==0.22.*'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup Java'
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
- name: 'Setup Android SDK'
|
||||
uses: android-actions/setup-android@v4
|
||||
with:
|
||||
packages: "platforms;${{ env.ANDROID_PLATFORM }} ndk;${{ env.NDK_VERSION }}"
|
||||
|
||||
- name: 'Setup python'
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.14
|
||||
|
||||
- name: 'Install conan'
|
||||
run: pip install "conan==2.28.0"
|
||||
|
||||
- name: 'Decode keystore secret to file'
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.ANDROID_RELEASE_KEYSTORE_BASE64 }}
|
||||
shell: bash
|
||||
run: |
|
||||
echo $KEYSTORE_BASE64 | base64 --decode > android.keystore
|
||||
|
||||
- name: 'Build project'
|
||||
env:
|
||||
QT_INSTALL_DIR: ${{ runner.temp }}
|
||||
QT_ANDROID_KEYSTORE_PATH: ${{ github.workspace }}/android.keystore
|
||||
QT_ANDROID_KEYSTORE_ALIAS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_ALIAS }}
|
||||
QT_ANDROID_KEYSTORE_STORE_PASS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_PASS }}
|
||||
shell: bash
|
||||
run: |
|
||||
deploy/build.sh -t android --sign --aab
|
||||
|
||||
VERSION=$(grep CMAKE_PROJECT_VERSION:STATIC deploy/build/CMakeCache.txt | cut -d= -f2)
|
||||
|
||||
(cd deploy/build/client/android-build && mv AmneziaVPN.apk AmneziaVPN_${VERSION}_android9+_universal.apk)
|
||||
(cd deploy/build/client/android-build/build/outputs/bundle/release && mv android-build-release.aab AmneziaVPN_${VERSION}.aab)
|
||||
|
||||
for abi in arm64-v8a armeabi-v7a x86 x86_64; do
|
||||
deploy/build.sh -t android --sign --abi ${abi} --build ./deploy/build/${abi}
|
||||
(cd deploy/build/${abi}/client/android-build && mv AmneziaVPN.apk AmneziaVPN_${VERSION}_android9+_${abi}.apk)
|
||||
done
|
||||
|
||||
- name: 'Upload universal APK'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/client/android-build/*.apk
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload AAB'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/client/android-build/build/outputs/bundle/release/*.aab
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload arm64-v8a APK'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/arm64-v8a/client/android-build/*.apk
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload armeabi-v7a APK'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/armeabi-v7a/client/android-build/*.apk
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload x86 APK'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/x86/client/android-build/*.apk
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload x86_64 APK'
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: deploy/build/x86_64/client/android-build/*.apk
|
||||
archive: false
|
||||
retention-days: 7
|
||||
|
||||
Extra:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Search a corresponding PR
|
||||
uses: octokit/request-action@v2.x
|
||||
id: pull_request
|
||||
with:
|
||||
route: GET /repos/${{ github.repository }}/pulls
|
||||
head: ${{ github.repository_owner }}:${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Add PR link to build summary
|
||||
if: ${{ fromJSON(steps.pull_request.outputs.data)[0].number != '' }}
|
||||
run: |
|
||||
echo "Pull request:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "[[#${{ fromJSON(steps.pull_request.outputs.data)[0].number }}] ${{ fromJSON(steps.pull_request.outputs.data)[0].title }}](${{ fromJSON(steps.pull_request.outputs.data)[0].html_url }})" >> $GITHUB_STEP_SUMMARY
|
||||
150
.github/workflows/tag-deploy.yml
vendored
150
.github/workflows/tag-deploy.yml
vendored
@@ -1,150 +0,0 @@
|
||||
name: 'Release deploy workflow'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# tags:
|
||||
# - **
|
||||
|
||||
jobs:
|
||||
|
||||
Build-Android-Release:
|
||||
name: 'Build-Android-Release'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.4.1
|
||||
QIF_VERSION: 4.5
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||
FALLBACK_S3_ENDPOINT: ${{ secrets.FALLBACK_S3_ENDPOINT }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_ENDPOINT: ${{ secrets.DEV_AGW_ENDPOINT }}
|
||||
DEV_S3_ENDPOINT: ${{ secrets.DEV_S3_ENDPOINT }}
|
||||
FREE_V2_ENDPOINT: ${{ secrets.FREE_V2_ENDPOINT }}
|
||||
PREM_V1_ENDPOINT: ${{ secrets.PREM_V1_ENDPOINT }}
|
||||
|
||||
steps:
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'desktop'
|
||||
arch: 'gcc_64'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
|
||||
- name: 'Install android Qt x86_64'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_x86_64'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
|
||||
- name: 'Install android Qt x86'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_x86'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
|
||||
- name: 'Install android Qt arm_v7'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_armv7'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
|
||||
- name: 'Install android Qt arm_v8'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_arm64_v8a'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: main
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
|
||||
- name: 'Preparations before keystore fetching'
|
||||
run: |
|
||||
mkdir keystore
|
||||
|
||||
- name: 'Getting keystore'
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: amnezia-vpn/amnezia-android-certificates
|
||||
ssh-key: ${{ secrets.ANDROID_CERTS_SSH_PRIVATE_KEY }}
|
||||
path: keystore
|
||||
|
||||
- name: 'Setup ccache'
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
|
||||
- name: 'Setup Java'
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
|
||||
- name: 'Build project'
|
||||
run: |
|
||||
export QT_HOST_PATH="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/gcc_64"
|
||||
export NDK_VERSION=23c
|
||||
export ANDROID_NDK_PLATFORM=android-23
|
||||
export ANDROID_NDK_HOME=${{ runner.temp }}/android-ndk-r${NDK_VERSION}
|
||||
export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
|
||||
|
||||
if [ ! -f $ANDROID_NDK_ROOT/ndk-build ]; then
|
||||
wget https://dl.google.com/android/repository/android-ndk-r${NDK_VERSION}-linux.zip -qO ${{ runner.temp }}/ndk.zip &&
|
||||
unzip -q -d ${{ runner.temp }} ${{ runner.temp }}/ndk.zip ;
|
||||
fi
|
||||
|
||||
export QT_BIN_DIR=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/android_arm64_v8a/bin
|
||||
cd main
|
||||
bash deploy/build_android.sh
|
||||
|
||||
- name: 'Signing APK'
|
||||
run: |
|
||||
pwd
|
||||
|
||||
ANDROID_BUILD_TOOLS_VERSION=30.0.3
|
||||
|
||||
${ANDROID_HOME}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}/zipalign -f -v 4 AmneziaVPN-release-unsigned.apk AmneziaVPN-release-aligned.apk
|
||||
${ANDROID_HOME}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}/apksigner sign --out AmneziaVPN-release-signed.apk --ks keystore/debug.keystore --ks-key-alias ${{ secrets.DEBUG_ANDROID_KEYSTORE_KEY_ALIAS }} --ks-pass pass:${{secrets.DEBUG_ANDROID_KEYSTOTE_KEY_PASS }} AmneziaVPN-release-aligned.apk
|
||||
|
||||
- name: 'Upload'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Release APK
|
||||
path: ${{ runner.temp }}/main/AmneziaVPN-release-signed.apk
|
||||
41
.github/workflows/tag-upload.yml
vendored
41
.github/workflows/tag-upload.yml
vendored
@@ -1,41 +0,0 @@
|
||||
name: 'Upload a new version'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
RELEASE_VERSION:
|
||||
description: 'Release version (e.g. 1.2.3.4)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
Upload-S3:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ inputs.RELEASE_VERSION }}
|
||||
sparse-checkout: |
|
||||
CMakeLists.txt
|
||||
deploy/deploy_s3.sh
|
||||
sparse-checkout-cone-mode: false
|
||||
|
||||
- name: Verify git tag
|
||||
run: |
|
||||
TAG_NAME=${{ inputs.RELEASE_VERSION }}
|
||||
CMAKE_TAG=$(grep 'set(AMNEZIAVPN_VERSION' CMakeLists.txt | sed -E 's/.*AMNEZIAVPN_VERSION ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/')
|
||||
if [[ "$TAG_NAME" == "$CMAKE_TAG" ]]; then
|
||||
echo "Git tag ($TAG_NAME) matches CMakeLists.txt version ($CMAKE_TAG)."
|
||||
else
|
||||
echo "::error::Mismatch: Git tag ($TAG_NAME) != CMakeLists.txt version ($CMAKE_TAG). Exiting with error..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Setup Rclone
|
||||
uses: AnimMouse/setup-rclone@v1
|
||||
with:
|
||||
rclone_config: ${{ secrets.RCLONE_CONFIG }}
|
||||
|
||||
- name: Send dist to S3
|
||||
run: bash deploy/deploy_s3.sh ${{ inputs.RELEASE_VERSION }}
|
||||
100
.gitignore
vendored
100
.gitignore
vendored
@@ -8,9 +8,6 @@ deploy/build/*
|
||||
deploy/build_32/*
|
||||
deploy/build_64/*
|
||||
winbuild*.bat
|
||||
.cache/
|
||||
.vscode/
|
||||
|
||||
|
||||
# Qt-es
|
||||
/.qmake.cache
|
||||
@@ -25,39 +22,7 @@ qrc_*.cpp
|
||||
ui_*.h
|
||||
Makefile*
|
||||
*build-*
|
||||
compile_commands.json
|
||||
|
||||
# fastlane
|
||||
client/fastlane/report.xml
|
||||
client/fastlane/build/*
|
||||
|
||||
# Qt-es
|
||||
client/Release-iphoneos/
|
||||
client/Debug-iphoneos/
|
||||
client/.xcode/
|
||||
client/.qmake.cache
|
||||
client/.qmake.stash
|
||||
client/*.pro.user
|
||||
client/*.pro.user.*
|
||||
client/*.qbs.user
|
||||
client/*.qbs.user.*
|
||||
client/*.moc
|
||||
client/moc_*.cpp
|
||||
client/qrc_*.cpp
|
||||
client/ui_*.h
|
||||
client/ui_*.cpp
|
||||
client/Makefile*
|
||||
client/fastlane/build/
|
||||
client/*build-*
|
||||
client/AmneziaVPN.xcodeproj
|
||||
client/Debug-iphonesimulator/
|
||||
client/amneziavpn_plugin_import.cpp
|
||||
client/amneziavpn_qml_plugin_import.cpp
|
||||
client/qmlcache_loader.cpp
|
||||
client/rep_ipc_interface_replica.h
|
||||
client/resources_qmlcache.qrc
|
||||
client/3rd/OpenVPNAdpter/build/
|
||||
client/3rd/ShadowSocks/build/
|
||||
# QtCreator
|
||||
|
||||
*.autosave
|
||||
@@ -69,78 +34,13 @@ client/3rd/ShadowSocks/build/
|
||||
# QtCtreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# Linux files
|
||||
*.7z
|
||||
deploy/AppDir
|
||||
deploy/Tools
|
||||
deploy/AmneziaVPN*Installer*
|
||||
|
||||
# MACOS files
|
||||
.DS_Store
|
||||
client/.DS_Store
|
||||
._.DS_Store
|
||||
._*
|
||||
*.dmg
|
||||
deploy/data/macos/pf/amn.400.allowPIA.conf
|
||||
|
||||
# tmp files
|
||||
*.*~
|
||||
|
||||
######################### Android
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
|
||||
# Android Profiling
|
||||
*.hprof
|
||||
client/3rd/ShadowSocks/ss_ios.xcconfig
|
||||
|
||||
# UML generated pics
|
||||
out/
|
||||
|
||||
# CMake files
|
||||
CMakeFiles/
|
||||
|
||||
ios-ne-build.sh
|
||||
macos-ne-build.sh
|
||||
macos-signed-build.sh
|
||||
macos-with-sign-build.sh
|
||||
DeveloperIdApplicationCertificate.p12
|
||||
DeveloperIdInstallerCertificate.p12
|
||||
|
||||
|
||||
27
.gitlab-ci.yml
Normal file
27
.gitlab-ci.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
||||
build-windows:
|
||||
stage: build
|
||||
tags:
|
||||
- windows
|
||||
script:
|
||||
- cmd.exe /k "deploy\windows-env.bat && cd deploy && windows.bat"
|
||||
artifacts:
|
||||
name: artifacts-windows
|
||||
paths:
|
||||
- AmneziaVPN.exe
|
||||
|
||||
build-macos:
|
||||
stage: build
|
||||
tags:
|
||||
- macos
|
||||
script:
|
||||
- cd deploy && ./macos.sh
|
||||
artifacts:
|
||||
name: artifacts-macos
|
||||
paths:
|
||||
- AmneziaVPN.dmg
|
||||
19
.gitmodules
vendored
19
.gitmodules
vendored
@@ -1,16 +1,3 @@
|
||||
[submodule "client/3rd/qtkeychain"]
|
||||
path = client/3rd/qtkeychain
|
||||
url = https://github.com/frankosterfeld/qtkeychain.git
|
||||
[submodule "client/3rd/SortFilterProxyModel"]
|
||||
path = client/3rd/SortFilterProxyModel
|
||||
url = https://github.com/mitchcurtis/SortFilterProxyModel.git
|
||||
[submodule "client/3rd/amneziawg-apple"]
|
||||
path = client/3rd/amneziawg-apple
|
||||
url = https://github.com/amnezia-vpn/amneziawg-apple
|
||||
[submodule "client/3rd/QSimpleCrypto"]
|
||||
path = client/3rd/QSimpleCrypto
|
||||
url = https://github.com/amnezia-vpn/QSimpleCrypto.git
|
||||
[submodule "client/3rd/qtgamepad"]
|
||||
path = client/3rd/qtgamepad
|
||||
url = https://github.com/amnezia-vpn/qtgamepad.git
|
||||
branch = 6.6
|
||||
[submodule "3rd/QtSsh"]
|
||||
path = 3rd/QtSsh
|
||||
url = https://github.com/amnezia-vpn/QtSsh.git
|
||||
|
||||
47
.gitpod.Dockerfile
vendored
47
.gitpod.Dockerfile
vendored
@@ -1,47 +0,0 @@
|
||||
FROM gitpod/workspace-full-vnc
|
||||
|
||||
USER gitpod
|
||||
|
||||
RUN sudo apt-get -q update \
|
||||
&& sudo apt-get install -yq \
|
||||
build-essential \
|
||||
libgl1-mesa-dev \
|
||||
libgstreamer-gl1.0-0 \
|
||||
libpulse-dev \
|
||||
libsecret-1-dev \
|
||||
libxcb-glx0 \
|
||||
libxcb-icccm4 \
|
||||
libxcb-image0 \
|
||||
libxcb-keysyms1 \
|
||||
libxcb-randr0 \
|
||||
libxcb-render-util0 \
|
||||
libxcb-render0 \
|
||||
libxcb-shape0 \
|
||||
libxcb-shm0 \
|
||||
libxcb-sync1 \
|
||||
libxcb-util1 \
|
||||
libxcb-xfixes0 \
|
||||
libxcb-xinerama0 \
|
||||
libxcb1 \
|
||||
libxkbcommon-dev \
|
||||
libxkbcommon-x11-0 \
|
||||
libxcb-xkb-dev \
|
||||
p7zip-full \
|
||||
&& sudo rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN sudo pip3 install aqtinstall
|
||||
|
||||
ARG QT_VERSION=6.4.1
|
||||
ARG QT_ARCH=gcc_64
|
||||
|
||||
ARG QT_DIR=/opt/qt
|
||||
RUN sudo aqt install-qt --outputdir ${QT_DIR} linux desktop ${QT_VERSION} ${QT_ARCH} --modules \
|
||||
qtremoteobjects \
|
||||
qt5compat \
|
||||
qtshadertools
|
||||
ENV QT_BIN_DIR=${QT_DIR}/${QT_VERSION}/${QT_ARCH}/bin
|
||||
|
||||
ARG QIF_VERSION=4.5
|
||||
ARG QIF_DIR=/opt/qif
|
||||
RUN sudo aqt install-tool --outputdir ${QIF_DIR} linux desktop tools_ifw
|
||||
ENV QIF_BIN_DIR=${QIF_DIR}/Tools/QtInstallerFramework/${QIF_VERSION}/bin
|
||||
@@ -1,8 +0,0 @@
|
||||
tasks:
|
||||
- init: >-
|
||||
deploy/build_linux.sh
|
||||
image:
|
||||
file: .gitpod.Dockerfile
|
||||
vscode:
|
||||
extensions:
|
||||
- llvm-vs-code-extensions.vscode-clangd
|
||||
144
.travis.yml
Normal file
144
.travis.yml
Normal file
@@ -0,0 +1,144 @@
|
||||
language: cpp
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- dev
|
||||
- /\d+\.\d+/
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- name: MacOS
|
||||
os: osx
|
||||
osx_image: xcode12.5
|
||||
|
||||
env:
|
||||
- QT_VERSION=5.15.2
|
||||
- QIF_VERSION=4.1
|
||||
- QT_BIN_DIR=$HOME/Qt/$QT_VERSION/clang_64/bin
|
||||
- QIF_BIN_DIR=$QT_BIN_DIR/../../../Tools/QtInstallerFramework/$QIF_VERSION/bin
|
||||
|
||||
script:
|
||||
- |
|
||||
if [ ! -f $HOME/Qt/$QT_VERSION/clang_64/bin/qmake ]; then \
|
||||
brew install p7zip && \
|
||||
python3 -m pip install --upgrade pip && \
|
||||
pip install -U aqtinstall requests py7zr && \
|
||||
pip show aqtinstall && \
|
||||
python3 -m aqt install --outputdir $HOME/Qt $QT_VERSION mac desktop clang_64 -m qtbase && \
|
||||
python3 -m aqt tool --outputdir $HOME/Qt mac tools_ifw $QIF_VERSION qt.tools.ifw.${QIF_VERSION/./};
|
||||
fi
|
||||
- bash deploy/build_macos.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
token: $GH_TOKEN
|
||||
skip_cleanup: true
|
||||
file:
|
||||
- "AmneziaVPN_unsigned.dmg"
|
||||
on:
|
||||
tags: true
|
||||
branch: master
|
||||
|
||||
- name: Windows_x64
|
||||
os: windows
|
||||
|
||||
env:
|
||||
- PATH=/c/Python39:/c/Python39/Scripts:$PATH
|
||||
- QT_VERSION=5.14.2
|
||||
- QIF_VERSION=4.1
|
||||
- QT_BIN_DIR="c:\\Qt\\$QT_VERSION\\msvc2017_64\\bin"
|
||||
- QIF_BIN_DIR="c:\\Qt\\Tools\\QtInstallerFramework\\${QIF_VERSION}\\bin"
|
||||
- BUILD_ARCH=64
|
||||
|
||||
before_install:
|
||||
- if [ ! -f /C/Qt/$QT_VERSION/msvc2017_64/bin/qmake ]; then choco install python --version 3.9.1; fi
|
||||
|
||||
script:
|
||||
- dir "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build"
|
||||
- dir "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools"
|
||||
- |
|
||||
if [ ! -f /C/Qt/$QT_VERSION/msvc2017_64/bin/qmake ]; then \
|
||||
python -m pip install --upgrade pip && \
|
||||
pip3 install -U aqtinstall requests py7zr && \
|
||||
pip3 show aqtinstall && \
|
||||
python -m aqt install --outputdir /C/Qt $QT_VERSION windows desktop win64_msvc2017_64 -m qtbase && \
|
||||
python -m aqt tool --outputdir /C/Qt windows tools_ifw $QIF_VERSION qt.tools.ifw.${QIF_VERSION/./}; \
|
||||
fi
|
||||
- echo set BUILD_ARCH=$BUILD_ARCH > winbuild.bat
|
||||
- echo set QT_BIN_DIR="$QT_BIN_DIR" >> winbuild.bat
|
||||
- echo set QIF_BIN_DIR="$QIF_BIN_DIR" >> winbuild.bat
|
||||
- echo call \""C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvars${BUILD_ARCH}.bat\"" >> winbuild.bat
|
||||
- echo call \""C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=amd64" >> winbuild.bat
|
||||
- echo set WIN_CERT_PW=$WIN_CERT_PW >> winbuild.bat
|
||||
- echo call deploy\\build_windows.bat >> winbuild.bat
|
||||
- cmd //c winbuild.bat
|
||||
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
token: $GH_TOKEN
|
||||
skip_cleanup: true
|
||||
file:
|
||||
- "AmneziaVPN_x64.exe"
|
||||
on:
|
||||
tags: true
|
||||
branch: master
|
||||
|
||||
- name: Windows_x32
|
||||
os: windows
|
||||
|
||||
env:
|
||||
- PATH=/c/Python39:/c/Python39/Scripts:$PATH
|
||||
- QT_VERSION=5.14.2
|
||||
- QIF_VERSION=4.1
|
||||
- QT_BIN_DIR="c:\\Qt\\${QT_VERSION}\\msvc2017\\bin"
|
||||
- QIF_BIN_DIR="c:\\Qt\\Tools\\QtInstallerFramework\\${QIF_VERSION}\\bin"
|
||||
- BUILD_ARCH=32
|
||||
|
||||
before_install:
|
||||
- if [ ! -f /C/Qt/$QT_VERSION/msvc2017/bin/qmake ]; then choco install python --version 3.9.1; fi
|
||||
|
||||
script:
|
||||
- dir "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build"
|
||||
- dir "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools"
|
||||
- |
|
||||
if [ ! -f /C/Qt/$QT_VERSION/msvc2017/bin/qmake ]; then \
|
||||
python -m pip install --upgrade pip && \
|
||||
pip3 install -U aqtinstall requests py7zr && \
|
||||
pip3 show aqtinstall && \
|
||||
python -m aqt install --outputdir /C/Qt $QT_VERSION windows desktop win32_msvc2017 -m qtbase && \
|
||||
python -m aqt tool --outputdir /C/Qt windows tools_ifw $QIF_VERSION qt.tools.ifw.${QIF_VERSION/./}; \
|
||||
fi
|
||||
- echo call \""C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\"" > winbuild.bat
|
||||
- echo set BUILD_ARCH=$BUILD_ARCH >> winbuild.bat
|
||||
- echo set QT_BIN_DIR="$QT_BIN_DIR" >> winbuild.bat
|
||||
- echo set QIF_BIN_DIR="$QIF_BIN_DIR" >> winbuild.bat
|
||||
- echo call \""C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvars${BUILD_ARCH}.bat\"" >> winbuild.bat
|
||||
- echo set WIN_CERT_PW=$WIN_CERT_PW >> winbuild.bat
|
||||
- echo call deploy\\build_windows.bat >> winbuild.bat
|
||||
- cmd //c winbuild.bat
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
token: $GH_TOKEN
|
||||
skip_cleanup: true
|
||||
file:
|
||||
- "AmneziaVPN_x32.exe"
|
||||
on:
|
||||
tags: true
|
||||
branch: master
|
||||
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
|
||||
before_cache:
|
||||
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew cleanup; fi
|
||||
# Cache only .git files under "/usr/local/Homebrew" so "brew update" does not take 5min every build
|
||||
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then find /usr/local/Homebrew \! -regex ".+\.git.+" -delete; fi
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/Qt
|
||||
- /C/Qt
|
||||
- $HOME/Library/Caches/Homebrew
|
||||
3
AmneziaVPN.pro
Executable file
3
AmneziaVPN.pro
Executable file
@@ -0,0 +1,3 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = client service platform
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(PROJECT AmneziaVPN)
|
||||
set(AMNEZIAVPN_VERSION 4.8.9.0)
|
||||
|
||||
set(QT_CREATOR_SKIP_PACKAGE_MANAGER_SETUP ON CACHE BOOL "" FORCE)
|
||||
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES
|
||||
${CMAKE_SOURCE_DIR}/cmake/platform_settings.cmake
|
||||
${CMAKE_SOURCE_DIR}/cmake/recipes_bootstrap.cmake
|
||||
${CMAKE_SOURCE_DIR}/cmake/conan_provider.cmake
|
||||
CACHE STRING "" FORCE)
|
||||
|
||||
project(${PROJECT} VERSION ${AMNEZIAVPN_VERSION}
|
||||
DESCRIPTION "AmneziaVPN"
|
||||
HOMEPAGE_URL "https://amnezia.org/"
|
||||
)
|
||||
|
||||
if (PREBUILTS_ONLY)
|
||||
# trigger conan to kick off `conan install`
|
||||
find_package(OpenSSL REQUIRED)
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
||||
set(RELEASE_DATE "${CURRENT_DATE}")
|
||||
|
||||
set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})
|
||||
set(APP_ANDROID_VERSION_CODE 2122)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(MZ_PLATFORM_NAME "linux")
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(MZ_PLATFORM_NAME "windows")
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
set(MZ_PLATFORM_NAME "macos")
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
set(MZ_PLATFORM_NAME "android")
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
||||
set(MZ_PLATFORM_NAME "ios")
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
|
||||
set(MZ_PLATFORM_NAME "wasm")
|
||||
endif()
|
||||
|
||||
set(QT_BUILD_TOOLS_WHEN_CROSS_COMPILING ON)
|
||||
|
||||
if(APPLE AND NOT IOS)
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(AMN_PF_RULE_IDENTITY "user { root }")
|
||||
else()
|
||||
set(AMN_PF_RULE_IDENTITY "group { amnvpn }")
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_SOURCE_DIR}/deploy/data/pf-templates/amn.400.allowPIA.conf.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/amn.400.allowPIA.conf"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
file(COPY_FILE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/amn.400.allowPIA.conf"
|
||||
"${CMAKE_SOURCE_DIR}/deploy/data/macos/pf/amn.400.allowPIA.conf"
|
||||
ONLY_IF_DIFFERENT
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_subdirectory(client)
|
||||
|
||||
if(NOT IOS AND NOT ANDROID AND NOT MACOS_NE)
|
||||
add_subdirectory(service)
|
||||
endif()
|
||||
|
||||
if ((LINUX AND NOT ANDROID) OR (APPLE AND NOT IOS AND NOT MACOS_NE) OR (WIN32))
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/CPack.cmake)
|
||||
endif()
|
||||
191
README.md
Normal file → Executable file
191
README.md
Normal file → Executable file
@@ -1,185 +1,50 @@
|
||||
# Amnezia VPN
|
||||
## _The best client for self-hosted VPN_
|
||||
|
||||
### _The best client for self-hosted VPN_
|
||||
[](https://travis-ci.com/amnezia-vpn/desktop-client)
|
||||
|
||||
|
||||
[](https://github.com/amnezia-vpn/amnezia-client/actions/workflows/deploy.yml?query=branch:dev)
|
||||
[](https://gitpod.io/#https://github.com/amnezia-vpn/amnezia-client)
|
||||
|
||||
### [English]([https://github.com/amnezia-vpn/amnezia-client/blob/dev/README_RU.md](https://github.com/amnezia-vpn/amnezia-client/tree/dev?tab=readme-ov-file#)) | [Русский](https://github.com/amnezia-vpn/amnezia-client/blob/dev/README_RU.md)
|
||||
|
||||
|
||||
[Amnezia](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-en) is an open-source VPN client, with a key feature that enables you to deploy your own VPN server on your server.
|
||||
|
||||
[](https://amnezia.org)
|
||||
|
||||
### [Website](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-en) | [Alt website link](https://storage.googleapis.com/amnezia/amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-en-mirror) | [Documentation](https://docs.amnezia.org) | [Troubleshooting](https://docs.amnezia.org/troubleshooting)
|
||||
|
||||
> [!TIP]
|
||||
> If the [Amnezia website](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-en) is blocked in your region, you can use an [Alternative website link](https://storage.googleapis.com/amnezia/amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-en-mirror).
|
||||
|
||||
<a href="https://amnezia.org/en/downloads?utm_source=github&utm_campaign=amnezia_button-readme-en"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/download-website.svg" width="150" style="max-width: 100%; margin-right: 10px"></a>
|
||||
<a href="https://storage.googleapis.com/amnezia/amnezia.org?m-path=/en/downloads&utm_source=github&utm_campaign=amnezia_button-readme-en-mirrow"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/download-alt.svg" width="150" style="max-width: 100%;"></a>
|
||||
|
||||
[All releases](https://github.com/amnezia-vpn/amnezia-client/releases)
|
||||
|
||||
<br/>
|
||||
|
||||
<a href="https://www.testiny.io"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/testiny.png" height="28px"></a>
|
||||
Amnezia is a VPN client with the key feature of deploying your own VPN server on you virtual server.
|
||||
|
||||
## Features
|
||||
|
||||
- Very easy to use - enter your IP address, SSH login, password and Amnezia will automatically install VPN docker containers to your server and connect to the VPN.
|
||||
- Classic VPN-protocols: OpenVPN, WireGuard and IKEv2 protocols.
|
||||
- Protocols with traffic Masking (Obfuscation): OpenVPN over [Cloak](https://github.com/cbeuw/Cloak) plugin, Shadowsocks (OpenVPN over Shadowsocks), [AmneziaWG](https://docs.amnezia.org/documentation/amnezia-wg/) and XRay.
|
||||
- Split tunneling support - add any sites to the client to enable VPN only for them or add Apps (only for Android and Desktop).
|
||||
- Windows, MacOS, Linux, Android, iOS releases.
|
||||
- Support for AmneziaWG protocol configuration on [Keenetic beta firmware](https://docs.keenetic.com/ua/air/kn-1611/en/6319-latest-development-release.html#UUID-186c4108-5afd-c10b-f38a-cdff6c17fab3_section-idm33192196168192-improved).
|
||||
|
||||
## Links
|
||||
|
||||
- [https://amnezia.org](https://amnezia.org) - Project website | [Alternative link (mirror)](https://storage.googleapis.com/kldscp/amnezia.org)
|
||||
- [https://docs.amnezia.org](https://docs.amnezia.org) - Documentation
|
||||
- [https://www.reddit.com/r/AmneziaVPN](https://www.reddit.com/r/AmneziaVPN) - Reddit
|
||||
- [https://t.me/amnezia_vpn_en](https://t.me/amnezia_vpn_en) - Telegram support channel (English)
|
||||
- [https://t.me/amnezia_vpn_ir](https://t.me/amnezia_vpn_ir) - Telegram support channel (Farsi)
|
||||
- [https://t.me/amnezia_vpn_mm](https://t.me/amnezia_vpn_mm) - Telegram support channel (Myanmar)
|
||||
- [https://t.me/amnezia_vpn](https://t.me/amnezia_vpn) - Telegram support channel (Russian)
|
||||
- [https://vpnpay.io/en/amnezia-premium/](https://vpnpay.io/en/amnezia-premium/) - Amnezia Premium
|
||||
- Very easy to use - enter your ip address, ssh login and password, and Amnezia client will automatically install VPN docker containers to your server and connect to VPN.
|
||||
- OpenVPN and OpenVPN over ShadowSocks protocols support.
|
||||
- Custom VPN routing mode support - add any sites to client to enable VPN only for them.
|
||||
- Windows and MacOS support.
|
||||
- Unsecure sharing connection profile for family use.
|
||||
|
||||
## Tech
|
||||
|
||||
AmneziaVPN uses several open-source projects to work:
|
||||
AmneziaVPN uses a number of open source projects to work:
|
||||
|
||||
- [OpenSSL](https://www.openssl.org/)
|
||||
- [OpenVPN](https://openvpn.net/)
|
||||
- [ShadowSocks](https://shadowsocks.org/)
|
||||
- [Qt](https://www.qt.io/)
|
||||
- [LibSsh](https://libssh.org)
|
||||
- [WireGuard](https://www.wireguard.com/)
|
||||
- [Xray-core](https://xtls.github.io/en/)
|
||||
- [Conan](https://conan.io/)
|
||||
- [EasyRSA](https://github.com/OpenVPN/easy-rsa) - part of OpenVPN
|
||||
- [CygWin](https://www.cygwin.com/) - only for Windiws, used for launching EasyRSA scripts
|
||||
- [QtSsh](https://github.com/jaredtao/QtSsh) - forked form Qt Creator
|
||||
- and more...
|
||||
|
||||
## Help us with translations
|
||||
|
||||
Download the most actual translation files.
|
||||
|
||||
Go to ["Actions" tab](https://github.com/amnezia-vpn/amnezia-client/actions?query=is%3Asuccess+branch%3Adev), click on the first line.
|
||||
Then scroll down to the "Artifacts" section and download "AmneziaVPN_translations".
|
||||
|
||||
Unzip this file.
|
||||
Each *.ts file contains strings for one corresponding language.
|
||||
|
||||
Translate or correct some strings in one or multiple *.ts files and commit them back to this repository into the ``client/translations`` folder.
|
||||
You can do it via a web-interface or any other method you're familiar with.
|
||||
|
||||
## Checking out the source code
|
||||
|
||||
Make sure to pull all submodules after checking out the repo.
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## Hacking guide
|
||||
## Development
|
||||
|
||||
Want to contribute? Welcome!
|
||||
|
||||
### Build requirements
|
||||
|
||||
* [`CMake`](https://cmake.org/download/)
|
||||
* Compiler and underlying build system, depending on the target:
|
||||
- [Linux] Any of `make` and `gcc`
|
||||
- [Apple] [`Xcode`](https://developer.apple.com/xcode/) or [`Xcode command line tools`](https://developer.apple.com/xcode/)
|
||||
- [Windows] [`Visual Studio 2022`](https://aka.ms/vs/17/release/vs_community.exe) or [`VS 2022 Build Tools`](https://aka.ms/vs/17/release/vs_buildtools.exe)
|
||||
- [Android] [`Android SDK`](#installing-android-sdk) and [`Ninja`](https://ninja-build.org/)
|
||||
* [`Qt 6.10+`](https://www.qt.io/download-open-source) with the following modules:
|
||||
- Core module for targeting platform (Desktop/Android/iOS)
|
||||
- Qt 5 Compatibility module
|
||||
- Qt Remote Objects
|
||||
* [`Conan`](https://conan.io/downloads) package manager
|
||||
- On MacOS is enough just to use `homebrew` or install it in `.venv` in project root
|
||||
- Other systems must have it in `PATH`
|
||||
* (Optional) Installer dependencies:
|
||||
- [Windows/Linux] [`Qt Installer Framework`](https://www.qt.io/download-open-source)
|
||||
- [Windows] [`WIX toolset`](https://github.com/wixtoolset/wix/releases)
|
||||
|
||||
### Building the project using scripts
|
||||
|
||||
* Run scripts located in `deploy` directory
|
||||
* Basically, if dependencies are located in default installation paths, the scripts will find them automatically.
|
||||
* If they differ, specify them using the following variables:
|
||||
- `QT_INSTALL_DIR` - Qt root installation folder
|
||||
- `QT_ROOT_PATH` - Qt framework root directory
|
||||
- `QIF_ROOT_PATH` - Qt Installer Framework root path
|
||||
- `ANDROID_HOME` - Path to Android SDK root folder
|
||||
- and others. Check scripts for more
|
||||
|
||||
Unix-like:
|
||||
```bash
|
||||
# Build executables for the host platform
|
||||
deploy/build.sh
|
||||
|
||||
# Or just
|
||||
deploy/build.sh
|
||||
|
||||
# Build executables and installers for the host platform
|
||||
deploy/build.sh --installer all
|
||||
|
||||
# Build Android APK and AAB
|
||||
deploy/build.sh -t android --aab
|
||||
|
||||
# Call for help
|
||||
deploy/build.sh -h
|
||||
```
|
||||
|
||||
Windows:
|
||||
```batch
|
||||
:: Build executables for Windows
|
||||
deploy/build.bat
|
||||
|
||||
:: Build executables with IFW installer for Windows
|
||||
deploy/build.bat --installer ifw
|
||||
|
||||
:: Build executables with IFW and WIX installer for Windows
|
||||
deploy/build.bat --installer ifw --installer wix
|
||||
|
||||
:: Or just
|
||||
deploy/build.bat --installer all
|
||||
```
|
||||
|
||||
### Developing the project in IDEs
|
||||
|
||||
* Basically, you can use any IDE that handles CMake and Qt kits properly to run configure and build steps, and to navigate through the code nicely. For example:
|
||||
- `Qt Creator`
|
||||
- `Visual Studio Code` with `Qt Extension Pack`
|
||||
- and so on
|
||||
|
||||
* To use `Xcode`, you have to configure project first by using `cmake`. The easiest way to do it is to use `Qt Creator` for configuration. Then open `AmneziaVPN.xcodeproj` file from the build folder by using `Xcode`. Note that none of the files changed are saved - the files actually getting changed in build directory. Copy them manually if necessary
|
||||
|
||||
* `Android studio` could be used in the same way - just configure the project by using `cmake` manually or by using `Qt Creator`. Open `<build-dir>/client/android-build` in `Android studio` then. Do not forget to copy the changes - everything you do is saved under the build directory actually.
|
||||
|
||||
### Installing Android SDK
|
||||
|
||||
* Android SDK could be installed using the following methods:
|
||||
- Using `Qt Creator`. Use `Preferences`->`SDKs`
|
||||
- Using `Android studio`. By default it installs necessary `SDKs` automatically during the installation
|
||||
- Manually by using `sdk-manager`. Check [this](https://developer.android.com/tools) page for details
|
||||
### Building sources and deployment
|
||||
Easiest way to build your own executables - is to fork project and configure [Travis CI](https://travis-ci.com/)
|
||||
Or you can build sources manually using Qt Creator. Qt >= 14.2 supported.
|
||||
Look to the `build_macos.sh` and `build_windows.bat` scripts in `deploy` folder for details.
|
||||
|
||||
## License
|
||||
GPL v.3
|
||||
|
||||
This project is licensed under the GNU General Public License v3.0 (see LICENSE) and also includes third-party components distributed under their own terms (see THIRD_PARTY_LICENSES.md).
|
||||
## Contacts
|
||||
[https://t.me/amnezia_vpn_en](https://t.me/amnezia_vpn_en) - Telegram support channel (English)
|
||||
[https://t.me/amnezia_vpn](https://t.me/amnezia_vpn) - Telegram support channel (Russian)
|
||||
[https://signal.group/...](https://signal.group/#CjQKIB2gUf8QH_IXnOJMGQWMDjYz9cNfmRQipGWLFiIgc4MwEhAKBONrSiWHvoUFbbD0xwdh) - Signal channel
|
||||
[https://amnezia.org](https://amnezia.org) - project website
|
||||
|
||||
## Donate
|
||||
|
||||
Patreon: [https://www.patreon.com/amneziavpn](https://www.patreon.com/amneziavpn)
|
||||
|
||||
Bitcoin: bc1qmhtgcf9637rl3kqyy22r2a8wa8laka4t9rx2mf <br>
|
||||
USDT BEP20: 0x6abD576765a826f87D1D95183438f9408C901bE4 <br>
|
||||
USDT TRC20: TELAitazF1MZGmiNjTcnxDjEiH5oe7LC9d <br>
|
||||
XMR: 48spms39jt1L2L5vyw2RQW6CXD6odUd4jFu19GZcDyKKQV9U88wsJVjSbL4CfRys37jVMdoaWVPSvezCQPhHXUW5UKLqUp3 <br>
|
||||
TON: UQDpU1CyKRmg7L8mNScKk9FRc2SlESuI7N-Hby4nX-CcVmns
|
||||
## Acknowledgments
|
||||
|
||||
This project is tested with BrowserStack.
|
||||
We express our gratitude to [BrowserStack](https://www.browserstack.com) for supporting our project.
|
||||
Bitcoin: bc1qn9rhsffuxwnhcuuu4qzrwp4upkrq94xnh8r26u
|
||||
XMR: 48spms39jt1L2L5vyw2RQW6CXD6odUd4jFu19GZcDyKKQV9U88wsJVjSbL4CfRys37jVMdoaWVPSvezCQPhHXUW5UKLqUp3
|
||||
payeer.com: P2561305
|
||||
ko-fi.com: [https://ko-fi.com/amnezia_vpn](https://ko-fi.com/amnezia_vpn)
|
||||
|
||||
180
README_RU.md
180
README_RU.md
@@ -1,180 +0,0 @@
|
||||
# Amnezia VPN
|
||||
|
||||
### _Лучший клиент для создания VPN на собственном сервере_
|
||||
|
||||
[](https://github.com/amnezia-vpn/amnezia-client/actions/workflows/deploy.yml?query=branch:dev)
|
||||
[](https://gitpod.io/#https://github.com/amnezia-vpn/amnezia-client)
|
||||
|
||||
### [English](https://github.com/amnezia-vpn/amnezia-client/blob/dev/README.md) | Русский
|
||||
[AmneziaVPN](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-ru) — это open source VPN-клиент, ключевая особенность которого заключается в возможности развернуть собственный VPN на вашем сервере.
|
||||
|
||||
[](https://amnezia.org)
|
||||
|
||||
### [Сайт](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-ru) | [Зеркало сайта](https://storage.googleapis.com/amnezia/amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-ru-mirror) | [Документация](https://docs.amnezia.org) | [Решение проблем](https://docs.amnezia.org/troubleshooting)
|
||||
|
||||
> [!TIP]
|
||||
> Если [сайт Amnezia](https://amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-ru) заблокирован в вашем регионе, вы можете воспользоваться [ссылкой на зеркало](https://storage.googleapis.com/amnezia/amnezia.org?utm_source=github&utm_campaign=amnezia_website-readme-ru-mirror).
|
||||
|
||||
<a href="https://storage.googleapis.com/amnezia/amnezia.org?m-path=/ru/downloads&utm_source=github&utm_campaign=amnezia_button-readme-ru-mirror"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/download-website-ru.svg" width="150" style="max-width: 100%; margin-right: 10px"></a>
|
||||
|
||||
|
||||
[Все релизы](https://github.com/amnezia-vpn/amnezia-client/releases)
|
||||
|
||||
<br/>
|
||||
|
||||
<a href="https://www.testiny.io"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/testiny.png" height="28px"></a>
|
||||
|
||||
## Особенности
|
||||
|
||||
- Простой в использовании — введите IP-адрес, SSH-логин и пароль, и Amnezia автоматически установит VPN-контейнеры Docker на ваш сервер и подключится к VPN.
|
||||
- Классические VPN-протоколы: OpenVPN, WireGuard и IKEv2.
|
||||
- Протоколы с маскировкой трафика (обфускацией): OpenVPN с плагином [Cloak](https://github.com/cbeuw/Cloak), Shadowsocks (OpenVPN over Shadowsocks), [AmneziaWG](https://docs.amnezia.org/documentation/amnezia-wg/) and XRay.
|
||||
- Поддержка Split Tunneling — добавляйте любые сайты или приложения в список, чтобы включить VPN только для них.
|
||||
- Поддерживает платформы: Windows, macOS, Linux, Android, iOS.
|
||||
- Поддержка конфигурации протокола AmneziaWG на [бета-прошивке Keenetic](https://docs.keenetic.com/ua/air/kn-1611/en/6319-latest-development-release.html#UUID-186c4108-5afd-c10b-f38a-cdff6c17fab3_section-idm33192196168192-improved).
|
||||
|
||||
## Ссылки
|
||||
|
||||
- [https://amnezia.org](https://amnezia.org) - Веб-сайт проекта | [Альтернативная ссылка (зеркало)](https://storage.googleapis.com/kldscp/amnezia.org)
|
||||
- [https://docs.amnezia.org](https://docs.amnezia.org) - Документация
|
||||
- [https://www.reddit.com/r/AmneziaVPN](https://www.reddit.com/r/AmneziaVPN) - Reddit
|
||||
- [https://t.me/amnezia_vpn_en](https://t.me/amnezia_vpn_en) - Канал поддержки в Telegram (Английский)
|
||||
- [https://t.me/amnezia_vpn_ir](https://t.me/amnezia_vpn_ir) - Канал поддержки в Telegram (Фарси)
|
||||
- [https://t.me/amnezia_vpn_mm](https://t.me/amnezia_vpn_mm) - Канал поддержки в Telegram (Мьянма)
|
||||
- [https://t.me/amnezia_vpn](https://t.me/amnezia_vpn) - Канал поддержки в Telegram (Русский)
|
||||
- [https://vpnpay.io/en/amnezia-premium/](https://vpnpay.io/en/amnezia-premium/) - Amnezia Premium | [Зеркало](https://storage.googleapis.com/kldscp/vpnpay.io/ru/amnezia-premium\)
|
||||
|
||||
## Технологии
|
||||
|
||||
AmneziaVPN использует несколько проектов с открытым исходным кодом:
|
||||
|
||||
- [OpenSSL](https://www.openssl.org/)
|
||||
- [OpenVPN](https://openvpn.net/)
|
||||
- [Qt](https://www.qt.io/)
|
||||
- [LibSsh](https://libssh.org)
|
||||
- [WireGuard](https://www.wireguard.com/)
|
||||
- [Xray-core](https://xtls.github.io/en/)
|
||||
- [Conan](https://conan.io/)
|
||||
- и другие...
|
||||
|
||||
## Помощь с переводами
|
||||
|
||||
Загрузите самые актуальные файлы перевода.
|
||||
|
||||
Перейдите на [вкладку "Actions"](https://github.com/amnezia-vpn/amnezia-client/actions?query=is%3Asuccess+branch%3Adev), нажмите на первую строку. Затем прокрутите вниз до раздела "Artifacts" и скачайте "AmneziaVPN_translations".
|
||||
|
||||
Распакуйте этот файл. Каждый файл с расширением *.ts содержит строки для соответствующего языка.
|
||||
|
||||
Переведите или исправьте строки в одном или нескольких файлах *.ts и загрузите их обратно в этот репозиторий в папку ``client/translations``. Это можно сделать через веб-интерфейс или любым другим знакомым вам способом.
|
||||
|
||||
## Проверка исходного кода
|
||||
|
||||
После клонирования репозитория обязательно загрузите все подмодули.
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## Руководство по разработке
|
||||
|
||||
Хотите внести свой вклад? Добро пожаловать!
|
||||
|
||||
### Требования для сборки
|
||||
|
||||
* [`CMake`](https://cmake.org/download/)
|
||||
* Компилятор и система сборки, в зависимости от таргета:
|
||||
- [Linux] Любые `make` и `gcc`
|
||||
- [Apple] [`Xcode`](https://developer.apple.com/xcode/) или [`Xcode command line tools`](https://developer.apple.com/xcode/)
|
||||
- [Windows] [`Visual Studio 2022`](https://aka.ms/vs/17/release/vs_community.exe) или [`VS 2022 Build Tools`](https://aka.ms/vs/17/release/vs_buildtools.exe)
|
||||
- [Android] [`Android SDK`](#установка-android-sdk) и [`Ninja`](https://ninja-build.org/)
|
||||
* [`Qt 6.10+`](https://www.qt.io/download-open-source) со следующими модулями:
|
||||
- Основные модули для таргета (Desktop/Android/iOS)
|
||||
- Qt 5 Compatibility module
|
||||
- Qt Remote Objects
|
||||
* Пакетный менеджер [`Conan`](https://conan.io/downloads)
|
||||
- На MacOS достаточно использовать `homebrew` или установить в `.venv` в корень проекта
|
||||
- Для остальных систем необходимо прописать пути в `PATH`
|
||||
* (Необязательно) Заивисимости для установщиков:
|
||||
- [Windows/Linux] [`Qt Installer Framework`](https://www.qt.io/download-open-source)
|
||||
- [Windows] [`WIX toolset`](https://github.com/wixtoolset/wix/releases)
|
||||
|
||||
### Сборка проекта через скрипты
|
||||
|
||||
* Запустите скрипты, находящиеся в папке `deploy`
|
||||
* Если все зависимости установлены в стандартных локациях, скрипт найдёт их самостоятельно
|
||||
* Если пути отличаются, их нужно явно указать используя:
|
||||
- `QT_INSTALL_DIR` - корневая папка установки Qt
|
||||
- `QT_ROOT_PATH` - корневая папка Qt Framework
|
||||
- `QIF_ROOT_PATH` - корневая папка Qt Installer Framework
|
||||
- `ANDROID_HOME` - путь к Android SDK
|
||||
- и другие. Их можно получить из вышеуказанных скриптов
|
||||
|
||||
Unix-like:
|
||||
```bash
|
||||
# Build executables for the host platform
|
||||
deploy/build.sh
|
||||
|
||||
# Or just
|
||||
deploy/build.sh
|
||||
|
||||
# Build executables and installers for the host platform
|
||||
deploy/build.sh --installer all
|
||||
|
||||
# Build Android APK and AAB
|
||||
deploy/build.sh -t android --aab
|
||||
|
||||
# Call for help
|
||||
deploy/build.sh -h
|
||||
```
|
||||
|
||||
Windows:
|
||||
```batch
|
||||
:: Build executables for Windows
|
||||
deploy/build.bat
|
||||
|
||||
:: Build executables with IFW installer for Windows
|
||||
deploy/build.bat --installer ifw
|
||||
|
||||
:: Build executables with IFW and WIX installer for Windows
|
||||
deploy/build.bat --installer ifw --installer wix
|
||||
|
||||
:: Or just
|
||||
deploy/build.bat --installer all
|
||||
```
|
||||
|
||||
### Разработка в IDE
|
||||
|
||||
* Можно использовать любые IDE которые умеют работать с CMake и находить Qt Kits. Например:
|
||||
- `Qt Creator`
|
||||
- `Visual Studio Code` with `Qt Extension Pack`
|
||||
- и так далее
|
||||
|
||||
* Для использования `Xcode` нужно сконфигурировать проект с помощью `cmake`. Самый простой способ это сделать - использовать `Qt Creator` для конфигурации. Затем, нужно открыть файл `AmneziaVPN.xcodeproj` из папки сборки с помощью `Xcode`. Учтите, что никакие файлы фактически не сохраняются - они сохраняются в директории сборки. Если требуется, скопируйте файлы вручную
|
||||
|
||||
* `Android studio` может быть использована подобным вышеуказанному способу - нужно использовать `cmake` вручную или через `Qt Creator` для конфигурации. Далее, откройте `<build-dir>/client/android-build` в `Android studio`. Не забудьте скопировать изменённые файлы в папку с исходным кодом - все файлы, изменённые в IDE, сохраняются фактически в папке сборки.
|
||||
|
||||
### Установка Android SDK
|
||||
|
||||
* Android SDK может быть установлен следующими способами:
|
||||
- Используя `Qt Creator`, через настройки в пунктах `Preferences`->`SDKs`
|
||||
- Используя `Android studio`. По умолчанию необходимые `SDK` устанавливаются автоматически.
|
||||
- Вручную, используя `sdk-manager`. Подробности можно найти [здесь](https://developer.android.com/tools)
|
||||
|
||||
## Лицензия
|
||||
|
||||
GPL v3.0
|
||||
|
||||
## Донаты
|
||||
|
||||
Patreon: [https://www.patreon.com/amneziavpn](https://www.patreon.com/amneziavpn)
|
||||
|
||||
Bitcoin: bc1qmhtgcf9637rl3kqyy22r2a8wa8laka4t9rx2mf <br>
|
||||
USDT BEP20: 0x6abD576765a826f87D1D95183438f9408C901bE4 <br>
|
||||
USDT TRC20: TELAitazF1MZGmiNjTcnxDjEiH5oe7LC9d <br>
|
||||
XMR: 48spms39jt1L2L5vyw2RQW6CXD6odUd4jFu19GZcDyKKQV9U88wsJVjSbL4CfRys37jVMdoaWVPSvezCQPhHXUW5UKLqUp3 <br>
|
||||
TON: UQDpU1CyKRmg7L8mNScKk9FRc2SlESuI7N-Hby4nX-CcVmns
|
||||
|
||||
## Благодарности
|
||||
|
||||
Этот проект тестируется с помощью BrowserStack.
|
||||
Мы выражаем благодарность [BrowserStack](https://www.browserstack.com) за поддержку нашего проекта.
|
||||
@@ -1,149 +0,0 @@
|
||||
# Third-Party Licenses
|
||||
|
||||
This project is licensed under the GNU General Public License v3.0.
|
||||
This file lists third-party software components used by this repository.
|
||||
Each component is distributed under its own license as linked below.
|
||||
|
||||
---
|
||||
|
||||
## QtKeychain
|
||||
|
||||
- Source: https://github.com/frankosterfeld/qtkeychain
|
||||
- License: BSD License
|
||||
- License Text: https://www.gnu.org/licenses/license-list.html#ModifiedBSD
|
||||
|
||||
---
|
||||
|
||||
## QSimpleCrypto
|
||||
|
||||
- Source: https://github.com/n1flh31mur/QSimpleCrypto
|
||||
- License: Apache License 2.0
|
||||
- License Text: https://github.com/n1flh31mur/QSimpleCrypto/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## SortFilterProxyModel
|
||||
|
||||
- Source: https://github.com/oKcerG/SortFilterProxyModel
|
||||
- License: MIT License
|
||||
- License Text: https://github.com/oKcerG/SortFilterProxyModel/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## QJsonStruct
|
||||
|
||||
- Source: https://github.com/Qv2ray/QJsonStruct
|
||||
- License: MIT License
|
||||
- License Text: https://github.com/Qv2ray/QJsonStruct/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## QR Code Generator (qrcodegen)
|
||||
|
||||
- Source: https://github.com/nayuki/QR-Code-generator
|
||||
- License: MIT License
|
||||
- License Text: https://www.nayuki.io/page/qr-code-generator-library
|
||||
|
||||
---
|
||||
|
||||
## Qt Gamepad
|
||||
|
||||
- Source: https://github.com/qt/qtgamepad
|
||||
- License: GNU General Public License v3.0 (GPL-3.0)
|
||||
- License Text: https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
---
|
||||
|
||||
## AmneziaWG Apple (WireGuard)
|
||||
|
||||
- Source: https://github.com/amnezia-vpn/amneziawg-apple
|
||||
- License: MIT License
|
||||
- License Text: https://github.com/amnezia-vpn/amneziawg-apple/blob/master/COPYING
|
||||
|
||||
---
|
||||
|
||||
## AmneziaWG Android
|
||||
|
||||
- Source: https://github.com/amnezia-vpn/amneziawg-go
|
||||
- License: MIT License
|
||||
- License Text: https://github.com/amnezia-vpn/amneziawg-go/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## Xray Core
|
||||
|
||||
- Source: https://github.com/XTLS/Xray-core
|
||||
- License: Mozilla Public License 2.0 (MPL-2.0)
|
||||
- License Text: https://github.com/XTLS/Xray-core/blob/main/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## Cloak
|
||||
|
||||
- Source: https://github.com/cbeuw/Cloak
|
||||
- License: GNU General Public License v3.0 (GPL-3.0)
|
||||
- License Text: https://github.com/cbeuw/Cloak/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## Shadowsocks
|
||||
|
||||
- Source: https://github.com/shadowsocks/shadowsocks-libev
|
||||
- License: GPL-3.0-or-later
|
||||
- License Text: http://www.gnu.org/licenses/
|
||||
|
||||
---
|
||||
|
||||
## OpenSSL
|
||||
|
||||
- Source: https://github.com/openssl/openssl
|
||||
- License: Apache License 2.0
|
||||
- License Text: https://www.openssl.org/source/license.html
|
||||
|
||||
---
|
||||
|
||||
## libssh
|
||||
|
||||
- Source: https://www.libssh.org/
|
||||
- License: GNU Lesser General Public License (LGPL)
|
||||
- License Text: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
||||
|
||||
---
|
||||
|
||||
## OpenVPNAdapter
|
||||
|
||||
- Source: https://github.com/ss-abramchuk/OpenVPNAdapter
|
||||
- License: GNU Affero General Public License v3.0 (AGPL-3.0)
|
||||
- License Text: https://github.com/ss-abramchuk/OpenVPNAdapter/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## Wintun
|
||||
|
||||
- Source: https://www.wintun.net/
|
||||
- License: Prebuilt Binaries License
|
||||
- License Text: https://github.com/WireGuard/wintun/blob/master/prebuilt-binaries-license.txt
|
||||
|
||||
---
|
||||
|
||||
## Mullvad Split Tunnel Driver
|
||||
|
||||
- Source: https://github.com/mullvad/win-split-tunnel
|
||||
- License: GNU General Public License v3.0 (GPL-3.0) and Mozilla Public License Version 2.0
|
||||
- License Text: https://github.com/mullvad/win-split-tunnel/blob/master/LICENSE-GPL.md https://github.com/mullvad/win-split-tunnel/blob/master/LICENSE-MPL.txt
|
||||
|
||||
---
|
||||
|
||||
## tun2socks
|
||||
|
||||
- Source: https://github.com/eycorsican/go-tun2socks
|
||||
- License: MIT License
|
||||
- License Text: https://github.com/eycorsican/go-tun2socks/blob/master/LICENSE
|
||||
|
||||
---
|
||||
|
||||
## TAP-Windows Driver
|
||||
|
||||
- Source: https://github.com/OpenVPN/tap-windows6
|
||||
- License: tap-windows6 license
|
||||
- License Text: https://github.com/OpenVPN/tap-windows6/blob/master/COPYING
|
||||
2
client/3rd/QJsonStruct/.gitignore
vendored
2
client/3rd/QJsonStruct/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*.user
|
||||
build/
|
||||
@@ -1,19 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(QJsonStruct LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(BUILD_TESTING ON)
|
||||
|
||||
include(QJsonStruct.cmake)
|
||||
find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
include(CTest)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Qv2ray Workgroup
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,190 +0,0 @@
|
||||
#pragma once
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QList>
|
||||
#include <tuple>
|
||||
|
||||
enum class QJsonIOPathType
|
||||
{
|
||||
JSONIO_MODE_ARRAY,
|
||||
JSONIO_MODE_OBJECT
|
||||
};
|
||||
|
||||
typedef QPair<QString, QJsonIOPathType> QJsonIONodeType;
|
||||
|
||||
struct QJsonIOPath : QList<QJsonIONodeType>
|
||||
{
|
||||
template<typename type1, typename type2, typename... types>
|
||||
QJsonIOPath(const type1 t1, const type2 t2, const types... ts)
|
||||
{
|
||||
AppendPath(t1);
|
||||
AppendPath(t2);
|
||||
(AppendPath(ts), ...);
|
||||
}
|
||||
|
||||
void AppendPath(size_t index)
|
||||
{
|
||||
append({ QString::number(index), QJsonIOPathType::JSONIO_MODE_ARRAY });
|
||||
}
|
||||
|
||||
void AppendPath(const QString &key)
|
||||
{
|
||||
append({ key, QJsonIOPathType::JSONIO_MODE_OBJECT });
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
QJsonIOPath &operator<<(const t &str)
|
||||
{
|
||||
AppendPath(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
QJsonIOPath &operator+=(const t &val)
|
||||
{
|
||||
AppendPath(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
QJsonIOPath &operator<<(const QJsonIOPath &other)
|
||||
{
|
||||
for (const auto &x : other)
|
||||
this->append(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
QJsonIOPath &operator<<(const t &val) const
|
||||
{
|
||||
auto _new = *this;
|
||||
return _new << val;
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
QJsonIOPath operator+(const t &val) const
|
||||
{
|
||||
auto _new = *this;
|
||||
return _new << val;
|
||||
}
|
||||
|
||||
QJsonIOPath operator+(const QJsonIOPath &other) const
|
||||
{
|
||||
auto _new = *this;
|
||||
for (const auto &x : other)
|
||||
_new.append(x);
|
||||
return _new;
|
||||
}
|
||||
};
|
||||
|
||||
class QJsonIO
|
||||
{
|
||||
public:
|
||||
const static inline QJsonValue Null = QJsonValue::Null;
|
||||
const static inline QJsonValue Undefined = QJsonValue::Undefined;
|
||||
|
||||
template<typename current_key_type, typename... t_other_types>
|
||||
static QJsonValue GetValue(const QJsonValue &parent, const current_key_type ¤t, const t_other_types &...other)
|
||||
{
|
||||
if constexpr (sizeof...(t_other_types) == 0)
|
||||
if constexpr (std::is_integral_v<current_key_type>)
|
||||
return parent.toArray()[current];
|
||||
else
|
||||
return parent.toObject()[current];
|
||||
else if constexpr (std::is_integral_v<current_key_type>)
|
||||
return GetValue(parent.toArray()[current], other...);
|
||||
else
|
||||
return GetValue(parent.toObject()[current], other...);
|
||||
}
|
||||
|
||||
template<typename... key_types_t>
|
||||
static QJsonValue GetValue(QJsonValue value, const std::tuple<key_types_t...> &keys, const QJsonValue &defaultValue = Undefined)
|
||||
{
|
||||
std::apply([&](auto &&...args) { ((value = value[args]), ...); }, keys);
|
||||
return value.isUndefined() ? defaultValue : value;
|
||||
}
|
||||
|
||||
template<typename parent_type, typename t_value_type, typename current_key_type, typename... t_other_key_types>
|
||||
static void SetValue(parent_type &parent, const t_value_type &val, const current_key_type ¤t, const t_other_key_types &...other)
|
||||
{
|
||||
// If current parent is an array, increase its size to fit the "key"
|
||||
if constexpr (std::is_integral_v<current_key_type>)
|
||||
for (auto i = parent.size(); i <= current; i++)
|
||||
parent.insert(i, {});
|
||||
|
||||
// If the t_other_key_types has nothing....
|
||||
// Means we have reached the end of recursion.
|
||||
if constexpr (sizeof...(t_other_key_types) == 0)
|
||||
parent[current] = val;
|
||||
else if constexpr (std::is_integral_v<typename std::tuple_element_t<0, std::tuple<t_other_key_types...>>>)
|
||||
{
|
||||
// Means we still have many keys
|
||||
// So this element is an array.
|
||||
auto _array = parent[current].toArray();
|
||||
SetValue(_array, val, other...);
|
||||
parent[current] = _array;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto _object = parent[current].toObject();
|
||||
SetValue(_object, val, other...);
|
||||
parent[current] = _object;
|
||||
}
|
||||
}
|
||||
|
||||
static QJsonValue GetValue(const QJsonValue &parent, const QJsonIOPath &path, const QJsonValue &defaultValue = QJsonIO::Undefined)
|
||||
{
|
||||
QJsonValue val = parent;
|
||||
for (const auto &[k, t] : path)
|
||||
{
|
||||
if (t == QJsonIOPathType::JSONIO_MODE_ARRAY)
|
||||
val = val.toArray()[k.toInt()];
|
||||
else
|
||||
val = val.toObject()[k];
|
||||
}
|
||||
return val.isUndefined() ? defaultValue : val;
|
||||
}
|
||||
|
||||
template<typename parent_type, typename value_type>
|
||||
static void SetValue(parent_type &parent, const value_type &t, const QJsonIOPath &path)
|
||||
{
|
||||
QList<std::tuple<QString, QJsonIOPathType, QJsonValue>> _stack;
|
||||
QJsonValue lastNode = parent;
|
||||
for (const auto &[key, type] : path)
|
||||
{
|
||||
_stack.prepend({ key, type, lastNode });
|
||||
if (type == QJsonIOPathType::JSONIO_MODE_ARRAY)
|
||||
lastNode = lastNode.toArray().at(key.toInt());
|
||||
else
|
||||
lastNode = lastNode.toObject()[key];
|
||||
}
|
||||
|
||||
lastNode = t;
|
||||
|
||||
for (const auto &[key, type, node] : _stack)
|
||||
{
|
||||
if (type == QJsonIOPathType::JSONIO_MODE_ARRAY)
|
||||
{
|
||||
const auto index = key.toInt();
|
||||
auto nodeArray = node.toArray();
|
||||
for (auto i = nodeArray.size(); i <= index; i++)
|
||||
nodeArray.insert(i, {});
|
||||
nodeArray[index] = lastNode;
|
||||
lastNode = nodeArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto nodeObject = node.toObject();
|
||||
nodeObject[key] = lastNode;
|
||||
lastNode = nodeObject;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<parent_type, QJsonObject>)
|
||||
parent = lastNode.toObject();
|
||||
else if constexpr (std::is_same_v<parent_type, QJsonArray>)
|
||||
parent = lastNode.toArray();
|
||||
else
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set(QJSONSTRUCT_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/QJsonStruct.hpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/QJsonIO.hpp)
|
||||
@@ -1,215 +0,0 @@
|
||||
#pragma once
|
||||
#include "macroexpansion.hpp"
|
||||
|
||||
#ifndef _X
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#endif
|
||||
|
||||
/// macro to define an operator==
|
||||
#define ___JSONSTRUCT_DEFAULT_COMPARE_IMPL(x) (this->x == ___another___instance__.x) &&
|
||||
#define JSONSTRUCT_COMPARE(CLASS, ...) \
|
||||
bool operator==(const CLASS &___another___instance__) const \
|
||||
{ \
|
||||
return FOR_EACH(___JSONSTRUCT_DEFAULT_COMPARE_IMPL, __VA_ARGS__) true; \
|
||||
}
|
||||
|
||||
// ============================================================================================
|
||||
// Load JSON IMPL
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_B_FUNC_IMPL(name) name::loadJson(___json_object_);
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_A_FUNC(name) ___DESERIALIZE_FROM_JSON_CONVERT_F_FUNC(name)
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_B_FUNC(...) FOREACH_CALL_FUNC_3(___DESERIALIZE_FROM_JSON_CONVERT_B_FUNC_IMPL, __VA_ARGS__)
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_F_FUNC(name) \
|
||||
if (___json_object_.toObject().contains(#name)) \
|
||||
{ \
|
||||
JsonStructHelper::Deserialize(this->name, ___json_object_.toObject()[#name]); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
this->name = ___qjsonstruct_default_check.name; \
|
||||
}
|
||||
|
||||
// ============================================================================================
|
||||
// To JSON IMPL
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_F_FUNC(name) \
|
||||
if (!(___qjsonstruct_default_check.name == this->name)) \
|
||||
{ \
|
||||
___json_object_.insert(#name, JsonStructHelper::Serialize(name)); \
|
||||
}
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_A_FUNC(name) ___json_object_.insert(#name, JsonStructHelper::Serialize(name));
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_B_FUNC_IMPL(name) JsonStructHelper::MergeJson(___json_object_, name::toJson());
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_B_FUNC(...) FOREACH_CALL_FUNC_3(___SERIALIZE_TO_JSON_CONVERT_B_FUNC_IMPL, __VA_ARGS__)
|
||||
|
||||
// ============================================================================================
|
||||
// Load JSON Wrapper
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_FUNC_DECL_A(...) FOREACH_CALL_FUNC_2(___DESERIALIZE_FROM_JSON_CONVERT_A_FUNC, __VA_ARGS__)
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_FUNC_DECL_F(...) FOREACH_CALL_FUNC_2(___DESERIALIZE_FROM_JSON_CONVERT_F_FUNC, __VA_ARGS__)
|
||||
#define ___DESERIALIZE_FROM_JSON_CONVERT_FUNC_DECL_B(...) FOREACH_CALL_FUNC_2(___DESERIALIZE_FROM_JSON_CONVERT_B_FUNC, __VA_ARGS__)
|
||||
#define ___DESERIALIZE_FROM_JSON_EXTRACT_B_F(name_option) ___DESERIALIZE_FROM_JSON_CONVERT_FUNC_DECL_##name_option
|
||||
|
||||
// ============================================================================================
|
||||
// To JSON Wrapper
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_FUNC_DECL_A(...) FOREACH_CALL_FUNC_2(___SERIALIZE_TO_JSON_CONVERT_A_FUNC, __VA_ARGS__)
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_FUNC_DECL_F(...) FOREACH_CALL_FUNC_2(___SERIALIZE_TO_JSON_CONVERT_F_FUNC, __VA_ARGS__)
|
||||
#define ___SERIALIZE_TO_JSON_CONVERT_FUNC_DECL_B(...) FOREACH_CALL_FUNC_2(___SERIALIZE_TO_JSON_CONVERT_B_FUNC, __VA_ARGS__)
|
||||
#define ___SERIALIZE_TO_JSON_EXTRACT_B_F(name_option) ___SERIALIZE_TO_JSON_CONVERT_FUNC_DECL_##name_option
|
||||
|
||||
// ============================================================================================
|
||||
#define JSONSTRUCT_REGISTER_NOCOPYMOVE(___class_type_, ...) \
|
||||
void loadJson(const QJsonValue &___json_object_) \
|
||||
{ \
|
||||
___class_type_ ___qjsonstruct_default_check; \
|
||||
FOREACH_CALL_FUNC(___DESERIALIZE_FROM_JSON_EXTRACT_B_F, __VA_ARGS__); \
|
||||
} \
|
||||
[[nodiscard]] const QJsonObject toJson() const \
|
||||
{ \
|
||||
___class_type_ ___qjsonstruct_default_check; \
|
||||
QJsonObject ___json_object_; \
|
||||
FOREACH_CALL_FUNC(___SERIALIZE_TO_JSON_EXTRACT_B_F, __VA_ARGS__); \
|
||||
return ___json_object_; \
|
||||
}
|
||||
|
||||
#define JSONSTRUCT_REGISTER(___class_type_, ...) \
|
||||
JSONSTRUCT_REGISTER_NOCOPYMOVE(___class_type_, __VA_ARGS__); \
|
||||
[[nodiscard]] static auto fromJson(const QJsonValue &___json_object_) \
|
||||
{ \
|
||||
___class_type_ _t; \
|
||||
_t.loadJson(___json_object_); \
|
||||
return _t; \
|
||||
}
|
||||
|
||||
#define ___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(type, convert_func) \
|
||||
static void Deserialize(type &t, const QJsonValue &d) \
|
||||
{ \
|
||||
t = d.convert_func; \
|
||||
}
|
||||
|
||||
class JsonStructHelper
|
||||
{
|
||||
public:
|
||||
static void MergeJson(QJsonObject &mergeTo, const QJsonObject &mergeIn)
|
||||
{
|
||||
for (const auto &key : mergeIn.keys())
|
||||
mergeTo[key] = mergeIn.value(key);
|
||||
}
|
||||
//
|
||||
template<typename T>
|
||||
static void Deserialize(T &t, const QJsonValue &d)
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
t = (T) d.toInt();
|
||||
else if constexpr (std::is_same_v<T, QJsonObject>)
|
||||
t = d.toObject();
|
||||
else if constexpr (std::is_same_v<T, QJsonArray>)
|
||||
t = d.toArray();
|
||||
else
|
||||
t.loadJson(d);
|
||||
}
|
||||
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(QString, toString());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(QChar, toVariant().toChar());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(std::string, toString().toStdString());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(std::wstring, toString().toStdWString());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(bool, toBool());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(double, toDouble());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(float, toVariant().toFloat());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(int, toInt());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(long, toVariant().toLongLong());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(long long, toVariant().toLongLong());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(unsigned int, toVariant().toUInt());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(unsigned long, toVariant().toULongLong());
|
||||
___DECL_JSON_STRUCT_LOAD_SIMPLE_TYPE_FUNC(unsigned long long, toVariant().toULongLong());
|
||||
|
||||
template<typename T>
|
||||
static void Deserialize(QList<T> &t, const QJsonValue &d)
|
||||
{
|
||||
t.clear();
|
||||
for (const auto &val : d.toArray())
|
||||
{
|
||||
T data;
|
||||
Deserialize(data, val);
|
||||
t.push_back(data);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TKey, typename TValue>
|
||||
static void Deserialize(QMap<TKey, TValue> &t, const QJsonValue &d)
|
||||
{
|
||||
t.clear();
|
||||
const auto &jsonObject = d.toObject();
|
||||
TKey keyVal;
|
||||
TValue valueVal;
|
||||
for (const auto &key : jsonObject.keys())
|
||||
{
|
||||
Deserialize(keyVal, key);
|
||||
Deserialize(valueVal, jsonObject.value(key));
|
||||
t.insert(keyVal, valueVal);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================== Store Json Data ===========================
|
||||
|
||||
template<typename T>
|
||||
static QJsonValue Serialize(const T &t)
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
return (int) t;
|
||||
else if constexpr (std::is_same_v<T, QJsonObject> || std::is_same_v<T, QJsonArray>)
|
||||
return t;
|
||||
else
|
||||
return t.toJson();
|
||||
}
|
||||
|
||||
#define pure_func(x) (x)
|
||||
#define ___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(type) \
|
||||
static QJsonValue Serialize(const type &t) \
|
||||
{ \
|
||||
return QJsonValue(t); \
|
||||
}
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(int);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(bool);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(QJsonArray);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(QJsonObject);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(QString);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(long long);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(float);
|
||||
___DECL_JSON_STRUCT_STORE_SIMPLE_TYPE_FUNC(double);
|
||||
|
||||
#define ___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(type, func) \
|
||||
static QJsonValue Serialize(const type &t) \
|
||||
{ \
|
||||
return QJsonValue::fromVariant(func); \
|
||||
}
|
||||
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(std::string, QString::fromStdString(t))
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(std::wstring, QString::fromStdWString(t))
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(long, QVariant::fromValue<long>(t))
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(unsigned int, QVariant::fromValue<unsigned int>(t))
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(unsigned long, QVariant::fromValue<unsigned long>(t))
|
||||
___DECL_JSON_STRUCT_STORE_VARIANT_TYPE_FUNC(unsigned long long, QVariant::fromValue<unsigned long long>(t))
|
||||
|
||||
template<typename TValue>
|
||||
static QJsonValue Serialize(const QMap<QString, TValue> &t)
|
||||
{
|
||||
QJsonObject mapObject;
|
||||
for (const auto &key : t.keys())
|
||||
{
|
||||
auto valueVal = Serialize(t.value(key));
|
||||
mapObject.insert(key, valueVal);
|
||||
}
|
||||
return mapObject;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static QJsonValue Serialize(const QList<T> &t)
|
||||
{
|
||||
QJsonArray listObject;
|
||||
for (const auto &item : t)
|
||||
{
|
||||
listObject.push_back(Serialize(item));
|
||||
}
|
||||
return listObject;
|
||||
}
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
|
||||
#define CONCATENATE2(arg1, arg2) arg1##arg2
|
||||
#define CONCATENATE(x, y) x##y
|
||||
|
||||
#define EXPAND(...) __VA_ARGS__
|
||||
#define FOR_EACH_1(what, x, ...) what(x)
|
||||
#define FOR_EACH_2(what, x, ...) what(x) EXPAND(FOR_EACH_1(what, __VA_ARGS__))
|
||||
#define FOR_EACH_3(what, x, ...) what(x) EXPAND(FOR_EACH_2(what, __VA_ARGS__))
|
||||
#define FOR_EACH_4(what, x, ...) what(x) EXPAND(FOR_EACH_3(what, __VA_ARGS__))
|
||||
#define FOR_EACH_5(what, x, ...) what(x) EXPAND(FOR_EACH_4(what, __VA_ARGS__))
|
||||
#define FOR_EACH_6(what, x, ...) what(x) EXPAND(FOR_EACH_5(what, __VA_ARGS__))
|
||||
#define FOR_EACH_7(what, x, ...) what(x) EXPAND(FOR_EACH_6(what, __VA_ARGS__))
|
||||
#define FOR_EACH_8(what, x, ...) what(x) EXPAND(FOR_EACH_7(what, __VA_ARGS__))
|
||||
#define FOR_EACH_9(what, x, ...) what(x) EXPAND(FOR_EACH_8(what, __VA_ARGS__))
|
||||
#define FOR_EACH_10(what, x, ...) what(x) EXPAND(FOR_EACH_9(what, __VA_ARGS__))
|
||||
#define FOR_EACH_11(what, x, ...) what(x) EXPAND(FOR_EACH_10(what, __VA_ARGS__))
|
||||
#define FOR_EACH_12(what, x, ...) what(x) EXPAND(FOR_EACH_11(what, __VA_ARGS__))
|
||||
#define FOR_EACH_13(what, x, ...) what(x) EXPAND(FOR_EACH_12(what, __VA_ARGS__))
|
||||
#define FOR_EACH_14(what, x, ...) what(x) EXPAND(FOR_EACH_13(what, __VA_ARGS__))
|
||||
#define FOR_EACH_15(what, x, ...) what(x) EXPAND(FOR_EACH_14(what, __VA_ARGS__))
|
||||
#define FOR_EACH_16(what, x, ...) what(x) EXPAND(FOR_EACH_15(what, __VA_ARGS__))
|
||||
|
||||
#define FOR_EACH_NARG(...) FOR_EACH_NARG_(__VA_ARGS__, FOR_EACH_RSEQ_N())
|
||||
#define FOR_EACH_NARG_(...) EXPAND(FOR_EACH_ARG_N(__VA_ARGS__))
|
||||
#define FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N
|
||||
#define FOR_EACH_RSEQ_N() 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||
|
||||
#define FOR_EACH_(N, what, ...) EXPAND(CONCATENATE(FOR_EACH_, N)(what, __VA_ARGS__))
|
||||
#define FOR_EACH(what, ...) FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
|
||||
#define FOREACH_CALL_FUNC(func, ...) FOR_EACH(func, __VA_ARGS__)
|
||||
|
||||
// Bad hack ==========================================================================================================================
|
||||
#define _2X_FOR_EACH_1(what, x, ...) what(x)
|
||||
#define _2X_FOR_EACH_2(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_1(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_3(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_2(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_4(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_3(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_5(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_4(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_6(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_5(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_7(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_6(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_8(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_7(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_9(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_8(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_10(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_9(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_11(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_10(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_12(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_11(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_13(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_12(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_14(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_13(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_15(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_14(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_16(what, x, ...) what(x) EXPAND(_2X_FOR_EACH_15(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH_(N, what, ...) EXPAND(CONCATENATE(_2X_FOR_EACH_, N)(what, __VA_ARGS__))
|
||||
#define _2X_FOR_EACH(what, ...) _2X_FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
|
||||
#define FOREACH_CALL_FUNC_2(func, ...) _2X_FOR_EACH(func, __VA_ARGS__)
|
||||
|
||||
// Bad hack ==========================================================================================================================
|
||||
#define _3X_FOR_EACH_1(what, x, ...) what(x)
|
||||
#define _3X_FOR_EACH_2(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_1(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_3(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_2(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_4(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_3(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_5(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_4(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_6(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_5(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_7(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_6(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_8(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_7(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_9(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_8(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_10(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_9(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_11(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_10(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_12(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_11(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_13(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_12(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_14(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_13(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_15(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_14(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_16(what, x, ...) what(x) EXPAND(_3X_FOR_EACH_15(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH_(N, what, ...) EXPAND(CONCATENATE(_3X_FOR_EACH_, N)(what, __VA_ARGS__))
|
||||
#define _3X_FOR_EACH(what, ...) _3X_FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
|
||||
#define FOREACH_CALL_FUNC_3(func, ...) _3X_FOR_EACH(func, __VA_ARGS__)
|
||||
@@ -1,16 +0,0 @@
|
||||
function(QJSONSTRUCT_ADD_TEST TEST_NAME TEST_SOURCE)
|
||||
add_executable(${TEST_NAME} ${TEST_SOURCE} catch.hpp ${QJSONSTRUCT_SOURCES})
|
||||
target_include_directories(${TEST_NAME}
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
)
|
||||
target_link_libraries(
|
||||
${TEST_NAME}
|
||||
PRIVATE
|
||||
Qt::Core
|
||||
)
|
||||
add_test(NAME QJSONSTRUCT_TEST_${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}> -s)
|
||||
endfunction()
|
||||
|
||||
QJSONSTRUCT_ADD_TEST(serialization serialize/main.cpp)
|
||||
#QJSONSTRUCT_ADD_TEST(serialize_strings serialize/strings.cpp)
|
||||
@@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
#include "QJsonStruct.hpp"
|
||||
#ifndef _X
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#endif
|
||||
|
||||
struct BaseStruct
|
||||
{
|
||||
QString baseStr;
|
||||
int o;
|
||||
JSONSTRUCT_REGISTER(BaseStruct, F(baseStr, o))
|
||||
};
|
||||
|
||||
struct BaseStruct2
|
||||
{
|
||||
QString baseStr2;
|
||||
int o2;
|
||||
JSONSTRUCT_REGISTER(BaseStruct, F(baseStr2, o2))
|
||||
};
|
||||
struct TestInnerStruct
|
||||
: BaseStruct
|
||||
, BaseStruct2
|
||||
{
|
||||
QJsonObject jobj;
|
||||
QJsonArray jarray;
|
||||
QString str;
|
||||
JSONSTRUCT_REGISTER(TestInnerStruct, B(BaseStruct, BaseStruct2), F(str, jobj, jarray))
|
||||
};
|
||||
|
||||
struct JsonIOTest
|
||||
{
|
||||
QString str;
|
||||
QList<int> listOfNumber;
|
||||
QList<bool> listOfBool;
|
||||
QList<QString> listOfString;
|
||||
QList<QList<QString>> listOfListOfString;
|
||||
|
||||
QMap<QString, QString> map;
|
||||
TestInnerStruct inner;
|
||||
|
||||
JSONSTRUCT_REGISTER(JsonIOTest, F(str, listOfNumber, listOfBool, listOfString, listOfListOfString, map, inner));
|
||||
JsonIOTest(){};
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
#include "QJsonStruct.hpp"
|
||||
|
||||
struct SubData
|
||||
{
|
||||
QString subString;
|
||||
JSONSTRUCT_REGISTER_TOJSON(subString)
|
||||
};
|
||||
|
||||
struct ToJsonOnlyData
|
||||
{
|
||||
QString x;
|
||||
int y;
|
||||
int z;
|
||||
QList<int> ints;
|
||||
SubData sub;
|
||||
QMap<QString, SubData> subs;
|
||||
JSONSTRUCT_REGISTER_TOJSON(x, y, z, sub, ints, subs)
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,70 +0,0 @@
|
||||
#include "QJsonIO.hpp"
|
||||
#include "QJsonStruct.hpp"
|
||||
#include "TestIO.hpp"
|
||||
#include "TestOut.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonDocument>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Q_UNUSED(argc)
|
||||
Q_UNUSED(argv)
|
||||
|
||||
{
|
||||
ToJsonOnlyData data;
|
||||
data.x = "1string";
|
||||
data.y = 2;
|
||||
data.ints << 0;
|
||||
data.ints << 100;
|
||||
data.ints << 900;
|
||||
data.sub.subString = "subs";
|
||||
data.subs["subs-1"] = { "subs1-data" };
|
||||
data.subs["subs-2"] = { "subs2-data" };
|
||||
data.subs["subs-3"] = { "subs3-data" };
|
||||
data.z = 3;
|
||||
auto x = data.toJson();
|
||||
std::cout << QJsonDocument(x).toJson().toStdString() << std::endl;
|
||||
}
|
||||
//
|
||||
{
|
||||
auto f = JsonIOTest::fromJson( //
|
||||
QJsonObject{
|
||||
{ "inner", QJsonObject{ { "str", "innerString" }, //
|
||||
{ "jobj", QJsonObject{ { "key", "value" } } }, //
|
||||
{ "jarray", QJsonArray{ "array0", "array1", "array2" } }, //
|
||||
{ "baseStr", "baseInnerString" } } }, //
|
||||
{ "str", "data1" }, //
|
||||
{ "map", QJsonObject{ { "mapStr", "mapData" } } }, //
|
||||
{ "listOfString", QJsonArray{ "1", "2", "3", "4", "5" } }, //
|
||||
{ "listOfNumber", QJsonArray{ 1, 2, 3, 4, 5 } }, //
|
||||
{ "listOfBool", QJsonArray{ true, false, false, true, true } }, //
|
||||
{ "listOfListOfString", QJsonArray{ QJsonArray{ "1" }, //
|
||||
QJsonArray{ "1", "2" }, //
|
||||
QJsonArray{ "1", "2", "3" }, //
|
||||
QJsonArray{ "1", "2", "3", "4" }, //
|
||||
QJsonArray{ "1", "2", "3", "4", "5" } } }, //
|
||||
});
|
||||
auto x = f.toJson();
|
||||
std::cout << QJsonDocument(x).toJson().toStdString() << std::endl;
|
||||
}
|
||||
{
|
||||
QJsonObject obj{
|
||||
{ "inner", QJsonObject{ { "str", "innerString" }, { "baseStr", "baseInnerString" } } }, //
|
||||
{ "str", "data1" }, //
|
||||
{ "map", QJsonObject{ { "mapStr", "mapData" } } }, //
|
||||
{ "listOfString", QJsonArray{ "1", "2", "3", "4", "5" } }, //
|
||||
{ "listOfNumber", QJsonArray{ 1, 2, 3, 4, 5 } }, //
|
||||
{ "listOfBool", QJsonArray{ true, false, false, true, true } }, //
|
||||
{ "listOfListOfString", QJsonArray{ QJsonArray{ "1" }, //
|
||||
QJsonArray{ "1", "2" }, //
|
||||
QJsonArray{ "1", "2", "3" }, //
|
||||
QJsonArray{ "1", "2", "3", "4" }, //
|
||||
QJsonArray{ "1", "2", "3", "4", "5" } } }, //
|
||||
};
|
||||
auto y = QJsonIO::GetValue(obj, std::tuple{ "listOfListOfString", 2 });
|
||||
y.toObject();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
#include "QJsonStruct.hpp"
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
const static inline auto INT_TEST_MAX = std::numeric_limits<int>::max() - 1;
|
||||
const static inline auto INT_TEST_MIN = -(std::numeric_limits<int>::min() + 1);
|
||||
|
||||
#define SINGLE_ELEMENT_CLASS_DECL(CLASS, TYPE, field, defaultvalue, existance) \
|
||||
class CLASS \
|
||||
{ \
|
||||
public: \
|
||||
TYPE field = defaultvalue; \
|
||||
JSONSTRUCT_REGISTER(CLASS, existance(field)); \
|
||||
};
|
||||
|
||||
// SINGLE_ELEMENT_REQUIRE( CLASS_NAME , TYPE , FIELD , DEFAULT_VALUE , SET VALUE , CHECK VALUE )
|
||||
#define SINGLE_ELEMENT_REQUIRE(CLASS, TYPE, field, defaultvalue, value, checkvalue, existance) \
|
||||
SINGLE_ELEMENT_CLASS_DECL(CLASS, TYPE, field, defaultvalue, existance); \
|
||||
CLASS CLASS##_class; \
|
||||
CLASS##_class.field = value; \
|
||||
REQUIRE(CLASS##_class.toJson()[#field] == checkvalue);
|
||||
|
||||
using namespace std;
|
||||
SCENARIO("Test Serialization", "[Serialize]")
|
||||
{
|
||||
GIVEN("Single Element")
|
||||
{
|
||||
const static QList<QString> defaultList{ "entry 1", "entry 2" };
|
||||
const static QMap<QString, QString> defaultMap{ { "key1", "value1" }, { "key2", "value2" } };
|
||||
typedef QMap<QString, QString> QStringQStringMap;
|
||||
|
||||
WHEN("Serialize a single element")
|
||||
{
|
||||
const static QStringQStringMap setValueMap{ { "newkey1", "newvalue1" } };
|
||||
const static QJsonObject setValueJson{ { "newkey1", QJsonValue{ "newvalue1" } } };
|
||||
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_Empty, QString, a, "empty", "", "", F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest, QString, a, "empty", "Some QString", "Some QString", F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_WithQoutes, QString, a, "empty", "\"", "\"", F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_zint, int, a, -10, 0, 0, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_nint, int, a, -10, 1, 1, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_pint, int, a, -10, -1, -1, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_pmint, int, a, -1, INT_TEST_MAX, INT_TEST_MAX, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_zmint, int, a, -1, INT_TEST_MIN, INT_TEST_MIN, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_zuint, uint, a, -10, 0, 0, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QStringTest_puint, uint, a, -10, 1, 1, F);
|
||||
SINGLE_ELEMENT_REQUIRE(BoolTest_True, bool, a, false, true, true, F);
|
||||
SINGLE_ELEMENT_REQUIRE(BoolTest_False, bool, a, true, false, false, F);
|
||||
SINGLE_ELEMENT_REQUIRE(StdStringTest, string, a, "def", "std::string _test", "std::string _test", F);
|
||||
SINGLE_ELEMENT_REQUIRE(QListTest, QList<QString>, a, defaultList, { "newEntry" }, QJsonArray{ "newEntry" }, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QMapTest, QStringQStringMap, a, defaultMap, {}, QJsonObject{}, F);
|
||||
SINGLE_ELEMENT_REQUIRE(QMapValueTest, QStringQStringMap, a, defaultMap, setValueMap, setValueJson, F);
|
||||
}
|
||||
|
||||
WHEN("Serialize a default value")
|
||||
{
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultQString, QString, a, "defaultvalue", "defaultvalue", QJsonValue::Undefined, F);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultInteger, int, a, 12345, 12345, QJsonValue::Undefined, F);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultList, QList<QString>, a, defaultList, defaultList, QJsonValue::Undefined, F);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultMap, QStringQStringMap, a, defaultMap, defaultMap, QJsonValue::Undefined, F);
|
||||
}
|
||||
|
||||
WHEN("Serialize a force existance default value")
|
||||
{
|
||||
const static QJsonArray defaultListJson{ "entry 1", "entry 2" };
|
||||
const static QJsonObject defaultMapJson{ { "key1", "value1" }, { "key2", "value2" } };
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultQString, QString, a, "defaultvalue", "defaultvalue", "defaultvalue", A);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultInteger, int, a, 12345, 12345, 12345, A);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultList, QList<QString>, a, defaultList, defaultList, defaultListJson, A);
|
||||
SINGLE_ELEMENT_REQUIRE(DefaultMap, QStringQStringMap, a, defaultMap, defaultMap, defaultMapJson, A);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Multiple Simple Elements")
|
||||
{
|
||||
WHEN("Can Omit Default Value")
|
||||
{
|
||||
class MultipleNonDefaultElementTestClass
|
||||
{
|
||||
public:
|
||||
QString astring;
|
||||
int integer = 0;
|
||||
double adouble = 0.0;
|
||||
QList<QString> myList;
|
||||
JSONSTRUCT_REGISTER(MultipleNonDefaultElementTestClass, F(astring, integer, adouble, myList))
|
||||
};
|
||||
MultipleNonDefaultElementTestClass instance;
|
||||
const auto json = instance.toJson();
|
||||
REQUIRE(json["astring"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["integer"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["adouble"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["myList"] == QJsonValue::Undefined);
|
||||
}
|
||||
|
||||
WHEN("Forcing Existance")
|
||||
{
|
||||
class MultipleNonDefaultExistanceElementTestClass
|
||||
{
|
||||
public:
|
||||
QString astring;
|
||||
int integer = 0;
|
||||
double adouble = 0.0;
|
||||
QList<QString> myList;
|
||||
JSONSTRUCT_REGISTER(MultipleNonDefaultExistanceElementTestClass, A(astring, integer, adouble, myList))
|
||||
};
|
||||
MultipleNonDefaultExistanceElementTestClass instance;
|
||||
const auto json = instance.toJson();
|
||||
REQUIRE(json["astring"] == "");
|
||||
REQUIRE(json["integer"] == 0);
|
||||
REQUIRE(json["adouble"] == 0.0);
|
||||
REQUIRE(json["myList"] == QJsonArray{});
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Nested Elements")
|
||||
{
|
||||
WHEN("Can Omit Default Value")
|
||||
{
|
||||
class Parent
|
||||
{
|
||||
class NestedChild
|
||||
{
|
||||
class NestedChild2
|
||||
{
|
||||
public:
|
||||
int childChildInt = 13579;
|
||||
JSONSTRUCT_COMPARE(NestedChild2, childChildInt)
|
||||
JSONSTRUCT_REGISTER(NestedChild2, F(childChildInt))
|
||||
};
|
||||
|
||||
public:
|
||||
int childInt = 54321;
|
||||
QString childQString = "A QString";
|
||||
NestedChild2 anotherChild;
|
||||
JSONSTRUCT_COMPARE(NestedChild, childInt, childQString, anotherChild)
|
||||
JSONSTRUCT_REGISTER(NestedChild, F(childInt, childQString, anotherChild))
|
||||
};
|
||||
|
||||
public:
|
||||
int parentInt = 12345;
|
||||
NestedChild child;
|
||||
JSONSTRUCT_REGISTER(Parent, F(parentInt, child))
|
||||
};
|
||||
|
||||
WHEN("Omitted whole child element")
|
||||
{
|
||||
Parent parent;
|
||||
const auto json = parent.toJson();
|
||||
REQUIRE(json["parentInt"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["child"] == QJsonValue::Undefined);
|
||||
}
|
||||
|
||||
WHEN("Omitted one element in the child")
|
||||
{
|
||||
const auto childJson = QJsonObject{ { "childInt", 1314 } };
|
||||
Parent parent;
|
||||
parent.child.childInt = 1314;
|
||||
const auto json = parent.toJson();
|
||||
REQUIRE(json["parentInt"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["child"] == childJson);
|
||||
REQUIRE(json["child"]["childInt"] == 1314);
|
||||
REQUIRE(json["child"]["childQString"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["child"]["child"]["anotherChild"] == QJsonValue::Undefined);
|
||||
}
|
||||
|
||||
WHEN("Omitted one element in the child child")
|
||||
{
|
||||
Parent parent;
|
||||
parent.child.childInt = 1314;
|
||||
parent.child.anotherChild.childChildInt = 97531;
|
||||
const auto json = parent.toJson();
|
||||
REQUIRE(json["parentInt"] == QJsonValue::Undefined);
|
||||
REQUIRE(json["child"]["childInt"] == 1314);
|
||||
REQUIRE(json["child"]["childQString"] == QJsonValue::Undefined);
|
||||
const QJsonObject childChild{ { "childChildInt", 97531 } };
|
||||
REQUIRE(json["child"]["anotherChild"] == childChild);
|
||||
REQUIRE(json["child"]["anotherChild"]["childChildInt"] == 97531);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1802
client/3rd/QRCodeGenerator/QRCodeGenerator.cpp
Executable file
1802
client/3rd/QRCodeGenerator/QRCodeGenerator.cpp
Executable file
File diff suppressed because it is too large
Load Diff
129
client/3rd/QRCodeGenerator/QRCodeGenerator.h
Executable file
129
client/3rd/QRCodeGenerator/QRCodeGenerator.h
Executable file
@@ -0,0 +1,129 @@
|
||||
|
||||
#if !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
||||
#define AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
#define QR_LEVEL_L 0
|
||||
#define QR_LEVEL_M 1
|
||||
#define QR_LEVEL_Q 2
|
||||
#define QR_LEVEL_H 3
|
||||
|
||||
//
|
||||
#define QR_MODE_NUMERAL 0
|
||||
#define QR_MODE_ALPHABET 1
|
||||
#define QR_MODE_8BIT 2
|
||||
#define QR_MODE_KANJI 3
|
||||
|
||||
//
|
||||
#define QR_VRESION_S 0
|
||||
#define QR_VRESION_M 1
|
||||
#define QR_VRESION_L 2
|
||||
|
||||
#define MAX_ALLCODEWORD 3706
|
||||
#define MAX_DATACODEWORD 2956
|
||||
#define MAX_CODEBLOCK 153
|
||||
#define MAX_MODULESIZE 177
|
||||
|
||||
#define QR_MARGIN 0
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
typedef struct tagRS_BLOCKINFO
|
||||
{
|
||||
int ncRSBlock;
|
||||
int ncAllCodeWord;
|
||||
int ncDataCodeWord;
|
||||
|
||||
} RS_BLOCKINFO, *LPRS_BLOCKINFO;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct tagQR_VERSIONINFO
|
||||
{
|
||||
int nVersionNo;
|
||||
int ncAllCodeWord;
|
||||
|
||||
int ncDataCodeWord[4];
|
||||
|
||||
int ncAlignPoint;
|
||||
int nAlignPoint[6];
|
||||
|
||||
RS_BLOCKINFO RS_BlockInfo1[4];
|
||||
RS_BLOCKINFO RS_BlockInfo2[4];
|
||||
|
||||
} QR_VERSIONINFO, *LPQR_VERSIONINFO;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CQR_Encode
|
||||
{
|
||||
public:
|
||||
CQR_Encode();
|
||||
~CQR_Encode();
|
||||
|
||||
public:
|
||||
int m_nLevel;
|
||||
int m_nVersion;
|
||||
bool m_bAutoExtent;
|
||||
int m_nMaskingNo;
|
||||
|
||||
public:
|
||||
int m_nSymbleSize;
|
||||
unsigned char m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y]
|
||||
|
||||
private:
|
||||
int m_ncDataCodeWordBit;
|
||||
unsigned char m_byDataCodeWord[MAX_DATACODEWORD];
|
||||
|
||||
int m_ncDataBlock;
|
||||
unsigned char m_byBlockMode[MAX_DATACODEWORD];
|
||||
int m_nBlockLength[MAX_DATACODEWORD];
|
||||
|
||||
int m_ncAllCodeWord;
|
||||
unsigned char m_byAllCodeWord[MAX_ALLCODEWORD];
|
||||
unsigned char m_byRSWork[MAX_CODEBLOCK];
|
||||
|
||||
public:
|
||||
bool EncodeData(int nLevel, int nVersion, bool bAutoExtent, int nMaskingNo, char* lpsSource, int ncSource = 0);
|
||||
|
||||
private:
|
||||
int GetEncodeVersion(int nVersion, char* lpsSource, int ncLength);
|
||||
bool EncodeSourceData(char* lpsSource, int ncLength, int nVerGroup);
|
||||
|
||||
int GetBitLength(unsigned char nMode, int ncData, int nVerGroup);
|
||||
|
||||
int SetBitStream(int nIndex, unsigned short wData, int ncData);
|
||||
|
||||
bool IsNumeralData(unsigned char c);
|
||||
bool IsAlphabetData(unsigned char c);
|
||||
bool IsKanjiData(unsigned char c1, unsigned char c2);
|
||||
|
||||
unsigned char AlphabetToBinaly(unsigned char c);
|
||||
unsigned short KanjiToBinaly(unsigned short wc);
|
||||
|
||||
void GetRSCodeWord(unsigned char * lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
|
||||
|
||||
private:
|
||||
void FormatModule();
|
||||
|
||||
void SetFunctionModule();
|
||||
void SetFinderPattern(int x, int y);
|
||||
void SetAlignmentPattern(int x, int y);
|
||||
void SetVersionPattern();
|
||||
void SetCodeWordPattern();
|
||||
void SetMaskingPattern(int nPatternNo);
|
||||
void SetFormatInfoPattern(int nPatternNo);
|
||||
int CountPenalty();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
||||
5
client/3rd/QRCodeGenerator/QRCodeGenerator.pri
Executable file
5
client/3rd/QRCodeGenerator/QRCodeGenerator.pri
Executable file
@@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
3rd/QRCodeGenerator/QRCodeGenerator.h \
|
||||
|
||||
SOURCES += \
|
||||
3rd/QRCodeGenerator/QRCodeGenerator.cpp \
|
||||
Submodule client/3rd/QSimpleCrypto deleted from c99b33f0e0
50
client/3rd/QtSsh/.gitignore
vendored
Executable file
50
client/3rd/QtSsh/.gitignore
vendored
Executable file
@@ -0,0 +1,50 @@
|
||||
# User settings
|
||||
*.user
|
||||
macOSPackage/
|
||||
|
||||
# C++ objects and libs
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.a
|
||||
*.la
|
||||
*.lai
|
||||
*.so
|
||||
*.dll
|
||||
*.dylib
|
||||
|
||||
# Qt-es
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
*.pro.user
|
||||
*.pro.user.*
|
||||
*.qbs.user
|
||||
*.qbs.user.*
|
||||
*.moc
|
||||
moc_*.cpp
|
||||
qrc_*.cpp
|
||||
ui_*.h
|
||||
Makefile*
|
||||
*build-*
|
||||
|
||||
# QtCreator
|
||||
|
||||
*.autosave
|
||||
|
||||
# QtCtreator Qml
|
||||
*.qmlproject.user
|
||||
*.qmlproject.user.*
|
||||
|
||||
# QtCtreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# MACOS files
|
||||
.DS_Store
|
||||
._.DS_Store
|
||||
._*
|
||||
|
||||
# tmp files
|
||||
*.*~
|
||||
|
||||
# Certificates
|
||||
*.p12
|
||||
3
client/3rd/QtSsh/.qmake.conf
Executable file
3
client/3rd/QtSsh/.qmake.conf
Executable file
@@ -0,0 +1,3 @@
|
||||
load(qt_build_config)
|
||||
|
||||
MODULE_VERSION = 4.3.1
|
||||
1
client/3rd/QtSsh/QtSsh.pro
Executable file
1
client/3rd/QtSsh/QtSsh.pro
Executable file
@@ -0,0 +1 @@
|
||||
load(qt_parts)
|
||||
46
client/3rd/QtSsh/README.md
Executable file
46
client/3rd/QtSsh/README.md
Executable file
@@ -0,0 +1,46 @@
|
||||
# QSsh
|
||||
|
||||
this project is base on Qt-creator-open-source-4.3.1
|
||||
project is at
|
||||
|
||||
`http://code.qt.io/cgit/qt-creator/qt-creator.git/`
|
||||
|
||||
you can download code zip at
|
||||
|
||||
`http://download.qt.io/official_releases/qtcreator/4.3/4.3.1/`
|
||||
|
||||
## Getting Started
|
||||
|
||||
> * For linux user, if your Qt is installed through package manager tools such "apt-get", make sure that you have installed the Qt5 develop package *qtbase5-private-dev*
|
||||
|
||||
### Usage(1): Use QtSsh as Qt5's addon module
|
||||
|
||||
#### Building the module
|
||||
|
||||
> **Note**: Perl is needed in this step.
|
||||
|
||||
* Download the source code.
|
||||
|
||||
* Put the source code in any directory you like
|
||||
|
||||
* Go to top directory of the project in a terminal and run
|
||||
|
||||
```
|
||||
qmake
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
The library, the header files, and others will be installed to your system.
|
||||
|
||||
#### Import the module
|
||||
|
||||
` QT += ssh`
|
||||
|
||||
#### Include Headerfile
|
||||
|
||||
` #include<QtSsh/sshconnection.h>`
|
||||
|
||||
#### Close qtc.ssh log
|
||||
|
||||
` QLoggingCategory::setFilterRules(QStringLiteral("qtc.ssh=false")`
|
||||
2
client/3rd/QtSsh/examples/examples.pro
Executable file
2
client/3rd/QtSsh/examples/examples.pro
Executable file
@@ -0,0 +1,2 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = gitlab
|
||||
5
client/3rd/QtSsh/examples/gitlab/Qml.qrc
Executable file
5
client/3rd/QtSsh/examples/gitlab/Qml.qrc
Executable file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>Qml/Main.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
51
client/3rd/QtSsh/examples/gitlab/Qml/Main.qml
Executable file
51
client/3rd/QtSsh/examples/gitlab/Qml/Main.qml
Executable file
@@ -0,0 +1,51 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.0
|
||||
import Ssh 1.0
|
||||
Item {
|
||||
width: 1024
|
||||
height: 768
|
||||
|
||||
TextField {
|
||||
id: input
|
||||
x: 104
|
||||
y: 44
|
||||
width: 482
|
||||
height: 40
|
||||
implicitWidth: 200
|
||||
selectByMouse: true
|
||||
text: "https://www.zhihu.com"
|
||||
}
|
||||
function get(url) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
console.log(xhr.responseXML, xhr.responseText.toString())
|
||||
} else if (xhr.readyState === XMLHttpRequest) {
|
||||
|
||||
}
|
||||
}
|
||||
xhr.open('GET', url)
|
||||
xhr.send()
|
||||
}
|
||||
Button {
|
||||
x: 627
|
||||
y: 44
|
||||
text: "get"
|
||||
onClicked: {
|
||||
get(input.text)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: button
|
||||
x: 104
|
||||
y: 170
|
||||
text: qsTr("Ssh")
|
||||
onClicked: ssh.connectToHost()
|
||||
}
|
||||
Ssh {
|
||||
id: ssh
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
17
client/3rd/QtSsh/examples/gitlab/Src/Main.cpp
Executable file
17
client/3rd/QtSsh/examples/gitlab/Src/Main.cpp
Executable file
@@ -0,0 +1,17 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickView>
|
||||
#include "Ssh.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
qmlRegisterType<Ssh> ("Ssh", 1, 0, "Ssh");
|
||||
|
||||
QQuickView view;
|
||||
view.setSource(QUrl("qrc:/Qml/Main.qml"));
|
||||
view.show();
|
||||
return app.exec();
|
||||
}
|
||||
61
client/3rd/QtSsh/examples/gitlab/Src/Ssh.cpp
Executable file
61
client/3rd/QtSsh/examples/gitlab/Src/Ssh.cpp
Executable file
@@ -0,0 +1,61 @@
|
||||
#include "Ssh.hpp"
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Ssh::Ssh(QObject *parent) : QObject(parent) {
|
||||
//关掉qtc.ssh中的各种打印信息
|
||||
QLoggingCategory::setFilterRules(QStringLiteral("qtc.ssh=false"));
|
||||
|
||||
mParams.host="ftb.autoio.org";
|
||||
mParams.userName = "ftb";
|
||||
mParams.port = 11122;
|
||||
|
||||
mParams.privateKeyFile = QDir::homePath() + QStringLiteral("/.ssh/id_rsa");
|
||||
mParams.timeout = 5;
|
||||
mParams.authenticationType = SshConnectionParameters::AuthenticationTypePublicKey;
|
||||
mParams.options = SshIgnoreDefaultProxy;
|
||||
mParams.hostKeyCheckingMode = SshHostKeyCheckingNone;
|
||||
|
||||
mConnections = std::make_shared<SshConnection>(mParams);
|
||||
connect(mConnections.get(), &SshConnection::error, [&](QSsh::SshError){
|
||||
qWarning() << "Error: " << mConnections->errorString();
|
||||
});
|
||||
connect(mConnections.get(), &SshConnection::connected, [&](){
|
||||
qWarning() << "Connected";
|
||||
create();
|
||||
});
|
||||
connect(mConnections.get(), &SshConnection::disconnected, [](){
|
||||
qWarning() << "Disconnected";
|
||||
});
|
||||
connect(mConnections.get(), &SshConnection::dataAvailable, [](const QString &message){
|
||||
qWarning() << "Message: " << message;
|
||||
});
|
||||
}
|
||||
|
||||
void Ssh::connectToHost() {
|
||||
mConnections->connectToHost();
|
||||
}
|
||||
|
||||
void Ssh::create() {
|
||||
mRemoteProcess = mConnections->createRemoteProcess(QString::fromLatin1("/bin/ls -a").toUtf8());
|
||||
if (!mRemoteProcess) {
|
||||
qWarning() << QLatin1String("Error: UnmRemoteProcess SSH connection creates remote process.");
|
||||
return;
|
||||
}
|
||||
connect(mRemoteProcess.data(), &SshRemoteProcess::started, [&](){
|
||||
qWarning() << "started";
|
||||
});
|
||||
connect(mRemoteProcess.data(), &SshRemoteProcess::readyReadStandardOutput, [&](){
|
||||
qWarning() << "StandardOutput";
|
||||
qWarning() << QString::fromLatin1(mRemoteProcess->readAllStandardOutput()).split('\n');
|
||||
});
|
||||
connect(mRemoteProcess.data(), &SshRemoteProcess::readyReadStandardError, [&](){
|
||||
qWarning() << "StandardError" << mRemoteProcess->readAllStandardError();
|
||||
});
|
||||
connect(mRemoteProcess.data(), &SshRemoteProcess::closed, [&](int exitStatus){
|
||||
qWarning() << "Exit" << exitStatus;
|
||||
});
|
||||
mRemoteProcess->start();
|
||||
}
|
||||
|
||||
26
client/3rd/QtSsh/examples/gitlab/Src/Ssh.hpp
Executable file
26
client/3rd/QtSsh/examples/gitlab/Src/Ssh.hpp
Executable file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
|
||||
#include <QObject>
|
||||
#include <QtSsh/sshconnection.h>
|
||||
#include <QtSsh/sshremoteprocess.h>
|
||||
|
||||
using namespace QSsh;
|
||||
|
||||
class Ssh : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Ssh(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void connectToHost();
|
||||
void create();
|
||||
|
||||
private:
|
||||
SshConnectionParameters mParams;
|
||||
std::shared_ptr<SshConnection> mConnections;
|
||||
QSharedPointer<SshRemoteProcess> mRemoteProcess;
|
||||
};
|
||||
|
||||
29
client/3rd/QtSsh/examples/gitlab/gitlab.pro
Executable file
29
client/3rd/QtSsh/examples/gitlab/gitlab.pro
Executable file
@@ -0,0 +1,29 @@
|
||||
QT += quick network ssh
|
||||
CONFIG += c++11
|
||||
TEMPLATE = app
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
#DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += Src/Main.cpp \
|
||||
Src/Ssh.cpp
|
||||
|
||||
RESOURCES += Qml.qrc
|
||||
|
||||
# Additional import path used to resolve QML modules in Qt Creator's code model
|
||||
QML_IMPORT_PATH =
|
||||
|
||||
# Additional import path used to resolve QML modules just for Qt Quick Designer
|
||||
QML_DESIGNER_IMPORT_PATH =
|
||||
|
||||
HEADERS += \
|
||||
Src/Ssh.hpp
|
||||
|
||||
|
||||
47176
client/3rd/QtSsh/src/botan/botan.cpp
Executable file
47176
client/3rd/QtSsh/src/botan/botan.cpp
Executable file
File diff suppressed because it is too large
Load Diff
16210
client/3rd/QtSsh/src/botan/botan.h
Executable file
16210
client/3rd/QtSsh/src/botan/botan.h
Executable file
File diff suppressed because it is too large
Load Diff
50
client/3rd/QtSsh/src/botan/botan.pri
Executable file
50
client/3rd/QtSsh/src/botan/botan.pri
Executable file
@@ -0,0 +1,50 @@
|
||||
INCLUDEPATH *= $$PWD/..
|
||||
HEADERS += $$PWD/botan.h
|
||||
|
||||
SOURCES += $$PWD/botan.cpp
|
||||
|
||||
CONFIG += exceptions
|
||||
|
||||
DEPENDPATH += .
|
||||
|
||||
DEFINES += BOTAN_DLL=
|
||||
unix:DEFINES += BOTAN_TARGET_OS_HAS_GETTIMEOFDAY BOTAN_HAS_ALLOC_MMAP \
|
||||
BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM BOTAN_HAS_ENTROPY_SRC_EGD BOTAN_HAS_ENTROPY_SRC_FTW \
|
||||
BOTAN_HAS_ENTROPY_SRC_UNIX BOTAN_HAS_MUTEX_PTHREAD BOTAN_HAS_PIPE_UNIXFD_IO
|
||||
*linux*:DEFINES += BOTAN_TARGET_OS_IS_LINUX BOTAN_TARGET_OS_HAS_CLOCK_GETTIME \
|
||||
BOTAN_TARGET_OS_HAS_DLOPEN BOTAN_TARGET_OS_HAS_GMTIME_R BOTAN_TARGET_OS_HAS_POSIX_MLOCK \
|
||||
BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE BOTAN_HAS_DYNAMIC_LOADER
|
||||
macx:DEFINES += BOTAN_TARGET_OS_IS_DARWIN
|
||||
*g++*:DEFINES += BOTAN_BUILD_COMPILER_IS_GCC
|
||||
*clang*:DEFINES += BOTAN_BUILD_COMPILER_IS_CLANG
|
||||
*icc*:DEFINES += BOTAN_BUILD_COMPILER_IS_INTEL
|
||||
|
||||
CONFIG(x86_64):DEFINES += BOTAN_TARGET_ARCH_IS_X86_64
|
||||
|
||||
win32 {
|
||||
DEFINES += BOTAN_TARGET_OS_IS_WINDOWS \
|
||||
BOTAN_TARGET_OS_HAS_LOADLIBRARY BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME \
|
||||
BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK \
|
||||
BOTAN_HAS_ENTROPY_SRC_CAPI BOTAN_HAS_ENTROPY_SRC_WIN32 \
|
||||
BOTAN_HAS_MUTEX_WIN32
|
||||
|
||||
msvc {
|
||||
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
|
||||
QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250 -wd4297 -wd4267 -wd4334
|
||||
DEFINES += BOTAN_BUILD_COMPILER_IS_MSVC BOTAN_TARGET_OS_HAS_GMTIME_S _SCL_SECURE_NO_WARNINGS
|
||||
} else {
|
||||
QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long
|
||||
QMAKE_CXXFLAGS += -fpermissive -finline-functions -Wno-long-long
|
||||
}
|
||||
LIBS += -ladvapi32 -luser32
|
||||
}
|
||||
|
||||
unix:*-g++* {
|
||||
QMAKE_CFLAGS += -fPIC -fpermissive -finline-functions -Wno-long-long
|
||||
QMAKE_CXXFLAGS += -fPIC -fpermissive -finline-functions -Wno-long-long
|
||||
}
|
||||
|
||||
linux*|freebsd* {
|
||||
LIBS += -lrt $$QMAKE_LIBS_DYNLOAD
|
||||
}
|
||||
|
||||
1881
client/3rd/QtSsh/src/botan/configure.py
Executable file
1881
client/3rd/QtSsh/src/botan/configure.py
Executable file
File diff suppressed because it is too large
Load Diff
49
client/3rd/QtSsh/src/botan/doc/license.txt
Executable file
49
client/3rd/QtSsh/src/botan/doc/license.txt
Executable file
@@ -0,0 +1,49 @@
|
||||
|
||||
.. _license:
|
||||
.. highlight:: none
|
||||
|
||||
License
|
||||
========================================
|
||||
|
||||
Botan (http://botan.randombit.net/) is distributed under these terms::
|
||||
|
||||
Copyright (C) 1999-2011 Jack Lloyd
|
||||
2001 Peter J Jones
|
||||
2004-2007 Justin Karneges
|
||||
2004 Vaclav Ovsik
|
||||
2005 Matthew Gregan
|
||||
2005-2006 Matt Johnston
|
||||
2006 Luca Piccarreta
|
||||
2007 Yves Jerschow
|
||||
2007-2008 FlexSecure GmbH
|
||||
2007-2008 Technische Universitat Darmstadt
|
||||
2007-2008 Falko Strenzke
|
||||
2007-2008 Martin Doering
|
||||
2007 Manuel Hartl
|
||||
2007 Christoph Ludwig
|
||||
2007 Patrick Sona
|
||||
2010 Olivier de Gaalon
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
15
client/3rd/QtSsh/src/botan/readme.txt
Executable file
15
client/3rd/QtSsh/src/botan/readme.txt
Executable file
@@ -0,0 +1,15 @@
|
||||
Botan 1.10.2, 2012-06-17
|
||||
http://botan.randombit.net/
|
||||
|
||||
Botan is a C++ class library for performing a wide variety of
|
||||
cryptographic operations. It is released under the 2 clause BSD
|
||||
license; see doc/license.txt for the specifics. You can file bugs in
|
||||
Bugzilla (http://bugs.randombit.net/) or by sending a report to the
|
||||
botan-devel mailing list. More information about the mailing list is
|
||||
at http://lists.randombit.net/mailman/listinfo/botan-devel/
|
||||
|
||||
You can find documentation online at http://botan.randombit.net/ as
|
||||
well as in the doc directory in the distribution. Several examples can
|
||||
be found in doc/examples as well.
|
||||
|
||||
Jack Lloyd (lloyd@randombit.net)
|
||||
3
client/3rd/QtSsh/src/src.pro
Executable file
3
client/3rd/QtSsh/src/src.pro
Executable file
@@ -0,0 +1,3 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = ssh
|
||||
972
client/3rd/QtSsh/src/ssh/sftpchannel.cpp
Executable file
972
client/3rd/QtSsh/src/ssh/sftpchannel.cpp
Executable file
@@ -0,0 +1,972 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpchannel.h"
|
||||
#include "sftpchannel_p.h"
|
||||
|
||||
#include "sshexception_p.h"
|
||||
#include "sshincomingpacket_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
/*!
|
||||
\class QSsh::SftpChannel
|
||||
|
||||
\brief The SftpChannel class provides SFTP operations.
|
||||
|
||||
Objects are created via SshConnection::createSftpChannel().
|
||||
The channel needs to be initialized with
|
||||
a call to initialize() and is closed via closeChannel(). After closing
|
||||
a channel, no more operations are possible. It cannot be re-opened
|
||||
using initialize(); use SshConnection::createSftpChannel() if you need
|
||||
a new one.
|
||||
|
||||
After the initialized() signal has been emitted, operations can be started.
|
||||
All SFTP operations are asynchronous (non-blocking) and can be in-flight
|
||||
simultaneously (though callers must ensure that concurrently running jobs
|
||||
are independent of each other, e.g. they must not write to the same file).
|
||||
Operations are identified by their job id, which is returned by
|
||||
the respective member function. If the function can right away detect that
|
||||
the operation cannot succeed, it returns SftpInvalidJob. If an error occurs
|
||||
later, the finished() signal is emitted for the respective job with a
|
||||
non-empty error string.
|
||||
|
||||
Note that directory names must not have a trailing slash.
|
||||
*/
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
namespace {
|
||||
const quint32 ProtocolVersion = 3;
|
||||
|
||||
QString errorMessage(const QString &serverMessage,
|
||||
const QString &alternativeMessage)
|
||||
{
|
||||
return serverMessage.isEmpty() ? alternativeMessage : serverMessage;
|
||||
}
|
||||
|
||||
QString errorMessage(const SftpStatusResponse &response,
|
||||
const QString &alternativeMessage)
|
||||
{
|
||||
return response.status == SSH_FX_OK ? QString()
|
||||
: errorMessage(response.errorString, alternativeMessage);
|
||||
}
|
||||
} // anonymous namespace
|
||||
} // namespace Internal
|
||||
|
||||
SftpChannel::SftpChannel(quint32 channelId,
|
||||
Internal::SshSendFacility &sendFacility)
|
||||
: d(new Internal::SftpChannelPrivate(channelId, sendFacility, this))
|
||||
{
|
||||
connect(d, &Internal::SftpChannelPrivate::initialized,
|
||||
this, &SftpChannel::initialized, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SftpChannelPrivate::channelError,
|
||||
this, &SftpChannel::channelError, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SftpChannelPrivate::dataAvailable,
|
||||
this, &SftpChannel::dataAvailable, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SftpChannelPrivate::fileInfoAvailable,
|
||||
this, &SftpChannel::fileInfoAvailable, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SftpChannelPrivate::finished,
|
||||
this, &SftpChannel::finished, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SftpChannelPrivate::closed,
|
||||
this, &SftpChannel::closed, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
SftpChannel::State SftpChannel::state() const
|
||||
{
|
||||
switch (d->channelState()) {
|
||||
case Internal::AbstractSshChannel::Inactive:
|
||||
return Uninitialized;
|
||||
case Internal::AbstractSshChannel::SessionRequested:
|
||||
return Initializing;
|
||||
case Internal::AbstractSshChannel::CloseRequested:
|
||||
return Closing;
|
||||
case Internal::AbstractSshChannel::Closed:
|
||||
return Closed;
|
||||
case Internal::AbstractSshChannel::SessionEstablished:
|
||||
return d->m_sftpState == Internal::SftpChannelPrivate::Initialized
|
||||
? Initialized : Initializing;
|
||||
default:
|
||||
Q_ASSERT(!"Oh no, we forgot to handle a channel state!");
|
||||
return Closed; // For the compiler.
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannel::initialize()
|
||||
{
|
||||
d->requestSessionStart();
|
||||
d->m_sftpState = Internal::SftpChannelPrivate::SubsystemRequested;
|
||||
}
|
||||
|
||||
void SftpChannel::closeChannel()
|
||||
{
|
||||
d->closeChannel();
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::statFile(const QString &path)
|
||||
{
|
||||
return d->createJob(Internal::SftpStatFile::Ptr(
|
||||
new Internal::SftpStatFile(++d->m_nextJobId, path)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::listDirectory(const QString &path)
|
||||
{
|
||||
return d->createJob(Internal::SftpListDir::Ptr(
|
||||
new Internal::SftpListDir(++d->m_nextJobId, path)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::createDirectory(const QString &path)
|
||||
{
|
||||
return d->createJob(Internal::SftpMakeDir::Ptr(
|
||||
new Internal::SftpMakeDir(++d->m_nextJobId, path)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::removeDirectory(const QString &path)
|
||||
{
|
||||
return d->createJob(Internal::SftpRmDir::Ptr(
|
||||
new Internal::SftpRmDir(++d->m_nextJobId, path)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::removeFile(const QString &path)
|
||||
{
|
||||
return d->createJob(Internal::SftpRm::Ptr(
|
||||
new Internal::SftpRm(++d->m_nextJobId, path)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::renameFileOrDirectory(const QString &oldPath,
|
||||
const QString &newPath)
|
||||
{
|
||||
return d->createJob(Internal::SftpRename::Ptr(
|
||||
new Internal::SftpRename(++d->m_nextJobId, oldPath, newPath)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::createLink(const QString &filePath, const QString &target)
|
||||
{
|
||||
return d->createJob(Internal::SftpCreateLink::Ptr(
|
||||
new Internal::SftpCreateLink(++d->m_nextJobId, filePath, target)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::createFile(const QString &path, SftpOverwriteMode mode)
|
||||
{
|
||||
return d->createJob(Internal::SftpCreateFile::Ptr(
|
||||
new Internal::SftpCreateFile(++d->m_nextJobId, path, mode)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::uploadFile(const QString &localFilePath,
|
||||
const QString &remoteFilePath, SftpOverwriteMode mode)
|
||||
{
|
||||
QSharedPointer<QFile> localFile(new QFile(localFilePath));
|
||||
if (!localFile->open(QIODevice::ReadOnly))
|
||||
return SftpInvalidJob;
|
||||
return d->createJob(Internal::SftpUploadFile::Ptr(
|
||||
new Internal::SftpUploadFile(++d->m_nextJobId, remoteFilePath, localFile, mode)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::downloadFile(const QString &remoteFilePath,
|
||||
const QString &localFilePath, SftpOverwriteMode mode)
|
||||
{
|
||||
QSharedPointer<QFile> localFile(new QFile(localFilePath));
|
||||
if (mode == SftpSkipExisting && localFile->exists())
|
||||
return SftpInvalidJob;
|
||||
QIODevice::OpenMode openMode = QIODevice::WriteOnly;
|
||||
if (mode == SftpOverwriteExisting)
|
||||
openMode |= QIODevice::Truncate;
|
||||
else if (mode == SftpAppendToExisting)
|
||||
openMode |= QIODevice::Append;
|
||||
if (!localFile->open(openMode))
|
||||
return SftpInvalidJob;
|
||||
return d->createJob(Internal::SftpDownload::Ptr(
|
||||
new Internal::SftpDownload(++d->m_nextJobId, remoteFilePath, localFile)));
|
||||
}
|
||||
|
||||
SftpJobId SftpChannel::uploadDir(const QString &localDirPath,
|
||||
const QString &remoteParentDirPath)
|
||||
{
|
||||
if (state() != Initialized)
|
||||
return SftpInvalidJob;
|
||||
const QDir localDir(localDirPath);
|
||||
if (!localDir.exists() || !localDir.isReadable())
|
||||
return SftpInvalidJob;
|
||||
const Internal::SftpUploadDir::Ptr uploadDirOp(
|
||||
new Internal::SftpUploadDir(++d->m_nextJobId));
|
||||
const QString remoteDirPath
|
||||
= remoteParentDirPath + QLatin1Char('/') + localDir.dirName();
|
||||
const Internal::SftpMakeDir::Ptr mkdirOp(
|
||||
new Internal::SftpMakeDir(++d->m_nextJobId, remoteDirPath, uploadDirOp));
|
||||
uploadDirOp->mkdirsInProgress.insert(mkdirOp,
|
||||
Internal::SftpUploadDir::Dir(localDirPath, remoteDirPath));
|
||||
d->createJob(mkdirOp);
|
||||
return uploadDirOp->jobId;
|
||||
}
|
||||
|
||||
SftpChannel::~SftpChannel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
namespace Internal {
|
||||
|
||||
SftpChannelPrivate::SftpChannelPrivate(quint32 channelId,
|
||||
SshSendFacility &sendFacility, SftpChannel *sftp)
|
||||
: AbstractSshChannel(channelId, sendFacility),
|
||||
m_nextJobId(0), m_sftpState(Inactive), m_sftp(sftp)
|
||||
{
|
||||
}
|
||||
|
||||
SftpJobId SftpChannelPrivate::createJob(const AbstractSftpOperation::Ptr &job)
|
||||
{
|
||||
if (m_sftp->state() != SftpChannel::Initialized)
|
||||
return SftpInvalidJob;
|
||||
m_jobs.insert(job->jobId, job);
|
||||
sendData(job->initialPacket(m_outgoingPacket).rawData());
|
||||
return job->jobId;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleChannelSuccess()
|
||||
{
|
||||
if (channelState() == CloseRequested)
|
||||
return;
|
||||
qCDebug(sshLog, "sftp subsystem initialized");
|
||||
sendData(m_outgoingPacket.generateInit(ProtocolVersion).rawData());
|
||||
m_sftpState = InitSent;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleChannelFailure()
|
||||
{
|
||||
if (channelState() == CloseRequested)
|
||||
return;
|
||||
|
||||
if (m_sftpState != SubsystemRequested) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_FAILURE packet.");
|
||||
}
|
||||
emit channelError(tr("Server could not start SFTP subsystem."));
|
||||
closeChannel();
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleChannelDataInternal(const QByteArray &data)
|
||||
{
|
||||
if (channelState() == CloseRequested)
|
||||
return;
|
||||
|
||||
m_incomingData += data;
|
||||
m_incomingPacket.consumeData(m_incomingData);
|
||||
while (m_incomingPacket.isComplete()) {
|
||||
handleCurrentPacket();
|
||||
m_incomingPacket.clear();
|
||||
m_incomingPacket.consumeData(m_incomingData);
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleChannelExtendedDataInternal(quint32 type,
|
||||
const QByteArray &data)
|
||||
{
|
||||
qCWarning(sshLog, "Unexpected extended data '%s' of type %d on SFTP channel.",
|
||||
data.data(), type);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleExitStatus(const SshChannelExitStatus &exitStatus)
|
||||
{
|
||||
qCDebug(sshLog, "Remote SFTP service exited with exit code %d", exitStatus.exitStatus);
|
||||
|
||||
if (channelState() == CloseRequested || channelState() == Closed)
|
||||
return;
|
||||
|
||||
emit channelError(tr("The SFTP server finished unexpectedly with exit code %1.")
|
||||
.arg(exitStatus.exitStatus));
|
||||
|
||||
// Note: According to the specs, the server must close the channel after this happens,
|
||||
// but OpenSSH doesn't do that, so we need to initiate the closing procedure ourselves.
|
||||
closeChannel();
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleExitSignal(const SshChannelExitSignal &signal)
|
||||
{
|
||||
emit channelError(tr("The SFTP server crashed: %1.").arg(signal.error));
|
||||
closeChannel(); // See above.
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleCurrentPacket()
|
||||
{
|
||||
qCDebug(sshLog, "Handling SFTP packet of type %d", m_incomingPacket.type());
|
||||
switch (m_incomingPacket.type()) {
|
||||
case SSH_FXP_VERSION:
|
||||
handleServerVersion();
|
||||
break;
|
||||
case SSH_FXP_HANDLE:
|
||||
handleHandle();
|
||||
break;
|
||||
case SSH_FXP_NAME:
|
||||
handleName();
|
||||
break;
|
||||
case SSH_FXP_STATUS:
|
||||
handleStatus();
|
||||
break;
|
||||
case SSH_FXP_DATA:
|
||||
handleReadData();
|
||||
break;
|
||||
case SSH_FXP_ATTRS:
|
||||
handleAttrs();
|
||||
break;
|
||||
default:
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet.",
|
||||
tr("Unexpected packet of type %1.").arg(m_incomingPacket.type()));
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleServerVersion()
|
||||
{
|
||||
checkChannelActive();
|
||||
if (m_sftpState != InitSent) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_VERSION packet.");
|
||||
}
|
||||
|
||||
qCDebug(sshLog, "sftp init received");
|
||||
const quint32 serverVersion = m_incomingPacket.extractServerVersion();
|
||||
if (serverVersion != ProtocolVersion) {
|
||||
emit channelError(tr("Protocol version mismatch: Expected %1, got %2")
|
||||
.arg(serverVersion).arg(ProtocolVersion));
|
||||
closeChannel();
|
||||
} else {
|
||||
m_sftpState = Initialized;
|
||||
emit initialized();
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleHandle()
|
||||
{
|
||||
const SftpHandleResponse &response = m_incomingPacket.asHandleResponse();
|
||||
JobMap::Iterator it = lookupJob(response.requestId);
|
||||
const QSharedPointer<AbstractSftpOperationWithHandle> job
|
||||
= it.value().dynamicCast<AbstractSftpOperationWithHandle>();
|
||||
if (job.isNull()) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_HANDLE packet.");
|
||||
}
|
||||
if (job->state != AbstractSftpOperationWithHandle::OpenRequested) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_HANDLE packet.");
|
||||
}
|
||||
job->remoteHandle = response.handle;
|
||||
job->state = AbstractSftpOperationWithHandle::Open;
|
||||
|
||||
switch (it.value()->type()) {
|
||||
case AbstractSftpOperation::ListDir:
|
||||
handleLsHandle(it);
|
||||
break;
|
||||
case AbstractSftpOperation::CreateFile:
|
||||
handleCreateFileHandle(it);
|
||||
break;
|
||||
case AbstractSftpOperation::Download:
|
||||
handleGetHandle(it);
|
||||
break;
|
||||
case AbstractSftpOperation::UploadFile:
|
||||
handlePutHandle(it);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(!"Oh no, I forgot to handle an SFTP operation type!");
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleLsHandle(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpListDir::Ptr op = it.value().staticCast<SftpListDir>();
|
||||
sendData(m_outgoingPacket.generateReadDir(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleCreateFileHandle(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpCreateFile::Ptr op = it.value().staticCast<SftpCreateFile>();
|
||||
sendData(m_outgoingPacket.generateCloseHandle(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleGetHandle(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpDownload::Ptr op = it.value().staticCast<SftpDownload>();
|
||||
sendData(m_outgoingPacket.generateFstat(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
op->statRequested = true;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handlePutHandle(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpUploadFile::Ptr op = it.value().staticCast<SftpUploadFile>();
|
||||
if (op->parentJob && op->parentJob->hasError)
|
||||
sendTransferCloseHandle(op, it.key());
|
||||
|
||||
// OpenSSH does not implement the RFC's append functionality, so we
|
||||
// have to emulate it.
|
||||
if (op->mode == SftpAppendToExisting) {
|
||||
sendData(m_outgoingPacket.generateFstat(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
op->statRequested = true;
|
||||
} else {
|
||||
spawnWriteRequests(it);
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleStatus()
|
||||
{
|
||||
const SftpStatusResponse &response = m_incomingPacket.asStatusResponse();
|
||||
qCDebug(sshLog, "%s: status = %d", Q_FUNC_INFO, response.status);
|
||||
JobMap::Iterator it = lookupJob(response.requestId);
|
||||
switch (it.value()->type()) {
|
||||
case AbstractSftpOperation::ListDir:
|
||||
handleLsStatus(it, response);
|
||||
break;
|
||||
case AbstractSftpOperation::Download:
|
||||
handleGetStatus(it, response);
|
||||
break;
|
||||
case AbstractSftpOperation::UploadFile:
|
||||
handlePutStatus(it, response);
|
||||
break;
|
||||
case AbstractSftpOperation::MakeDir:
|
||||
handleMkdirStatus(it, response);
|
||||
break;
|
||||
case AbstractSftpOperation::StatFile:
|
||||
case AbstractSftpOperation::RmDir:
|
||||
case AbstractSftpOperation::Rm:
|
||||
case AbstractSftpOperation::Rename:
|
||||
case AbstractSftpOperation::CreateFile:
|
||||
case AbstractSftpOperation::CreateLink:
|
||||
handleStatusGeneric(it, response);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleStatusGeneric(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response)
|
||||
{
|
||||
AbstractSftpOperation::Ptr op = it.value();
|
||||
const QString error = errorMessage(response, tr("Unknown error."));
|
||||
emit finished(op->jobId, error);
|
||||
m_jobs.erase(it);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleMkdirStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response)
|
||||
{
|
||||
SftpMakeDir::Ptr op = it.value().staticCast<SftpMakeDir>();
|
||||
QSharedPointer<SftpUploadDir> parentJob = op->parentJob;
|
||||
if (parentJob == SftpUploadDir::Ptr()) {
|
||||
handleStatusGeneric(it, response);
|
||||
return;
|
||||
}
|
||||
if (parentJob->hasError) {
|
||||
m_jobs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
typedef QMap<SftpMakeDir::Ptr, SftpUploadDir::Dir>::Iterator DirIt;
|
||||
DirIt dirIt = parentJob->mkdirsInProgress.find(op);
|
||||
Q_ASSERT(dirIt != parentJob->mkdirsInProgress.end());
|
||||
const QString &remoteDir = dirIt.value().remoteDir;
|
||||
if (response.status == SSH_FX_OK) {
|
||||
emit dataAvailable(parentJob->jobId,
|
||||
tr("Created remote directory \"%1\".").arg(remoteDir));
|
||||
} else if (response.status == SSH_FX_FAILURE) {
|
||||
emit dataAvailable(parentJob->jobId,
|
||||
tr("Remote directory \"%1\" already exists.").arg(remoteDir));
|
||||
} else {
|
||||
parentJob->setError();
|
||||
emit finished(parentJob->jobId,
|
||||
tr("Error creating directory \"%1\": %2")
|
||||
.arg(remoteDir, response.errorString));
|
||||
m_jobs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
QDir localDir(dirIt.value().localDir);
|
||||
const QFileInfoList &dirInfos
|
||||
= localDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QFileInfo &dirInfo, dirInfos) {
|
||||
const QString remoteSubDir = remoteDir + QLatin1Char('/') + dirInfo.fileName();
|
||||
const SftpMakeDir::Ptr mkdirOp(
|
||||
new SftpMakeDir(++m_nextJobId, remoteSubDir, parentJob));
|
||||
parentJob->mkdirsInProgress.insert(mkdirOp,
|
||||
SftpUploadDir::Dir(dirInfo.absoluteFilePath(), remoteSubDir));
|
||||
createJob(mkdirOp);
|
||||
}
|
||||
|
||||
const QFileInfoList &fileInfos = localDir.entryInfoList(QDir::Files);
|
||||
foreach (const QFileInfo &fileInfo, fileInfos) {
|
||||
QSharedPointer<QFile> localFile(new QFile(fileInfo.absoluteFilePath()));
|
||||
if (!localFile->open(QIODevice::ReadOnly)) {
|
||||
parentJob->setError();
|
||||
emit finished(parentJob->jobId,
|
||||
tr("Could not open local file \"%1\": %2")
|
||||
.arg(fileInfo.absoluteFilePath(), localFile->errorString()));
|
||||
m_jobs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString remoteFilePath = remoteDir + QLatin1Char('/') + fileInfo.fileName();
|
||||
SftpUploadFile::Ptr uploadFileOp(new SftpUploadFile(++m_nextJobId,
|
||||
remoteFilePath, localFile, SftpOverwriteExisting, parentJob));
|
||||
createJob(uploadFileOp);
|
||||
parentJob->uploadsInProgress.append(uploadFileOp);
|
||||
}
|
||||
|
||||
parentJob->mkdirsInProgress.erase(dirIt);
|
||||
if (parentJob->mkdirsInProgress.isEmpty()
|
||||
&& parentJob->uploadsInProgress.isEmpty())
|
||||
emit finished(parentJob->jobId);
|
||||
m_jobs.erase(it);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleLsStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response)
|
||||
{
|
||||
SftpListDir::Ptr op = it.value().staticCast<SftpListDir>();
|
||||
switch (op->state) {
|
||||
case SftpListDir::OpenRequested:
|
||||
emit finished(op->jobId, errorMessage(response.errorString,
|
||||
tr("Remote directory could not be opened for reading.")));
|
||||
m_jobs.erase(it);
|
||||
break;
|
||||
case SftpListDir::Open:
|
||||
if (response.status != SSH_FX_EOF)
|
||||
reportRequestError(op, errorMessage(response.errorString,
|
||||
tr("Failed to list remote directory contents.")));
|
||||
op->state = SftpListDir::CloseRequested;
|
||||
sendData(m_outgoingPacket.generateCloseHandle(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
break;
|
||||
case SftpListDir::CloseRequested:
|
||||
if (!op->hasError) {
|
||||
const QString error = errorMessage(response,
|
||||
tr("Failed to close remote directory."));
|
||||
emit finished(op->jobId, error);
|
||||
}
|
||||
m_jobs.erase(it);
|
||||
break;
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_STATUS packet.");
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleGetStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response)
|
||||
{
|
||||
SftpDownload::Ptr op = it.value().staticCast<SftpDownload>();
|
||||
switch (op->state) {
|
||||
case SftpDownload::OpenRequested:
|
||||
emit finished(op->jobId,
|
||||
errorMessage(response.errorString,
|
||||
tr("Failed to open remote file for reading.")));
|
||||
m_jobs.erase(it);
|
||||
break;
|
||||
case SftpDownload::Open:
|
||||
if (op->statRequested) {
|
||||
reportRequestError(op, errorMessage(response.errorString,
|
||||
tr("Failed to retrieve information on the remote file ('stat' failed).")));
|
||||
sendTransferCloseHandle(op, response.requestId);
|
||||
} else {
|
||||
if ((response.status != SSH_FX_EOF || response.requestId != op->eofId)
|
||||
&& !op->hasError)
|
||||
reportRequestError(op, errorMessage(response.errorString,
|
||||
tr("Failed to read remote file.")));
|
||||
finishTransferRequest(it);
|
||||
}
|
||||
break;
|
||||
case SftpDownload::CloseRequested:
|
||||
Q_ASSERT(op->inFlightCount == 1);
|
||||
if (!op->hasError) {
|
||||
if (response.status == SSH_FX_OK)
|
||||
emit finished(op->jobId);
|
||||
else
|
||||
reportRequestError(op, errorMessage(response.errorString,
|
||||
tr("Failed to close remote file.")));
|
||||
}
|
||||
removeTransferRequest(it);
|
||||
break;
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_STATUS packet.");
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handlePutStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response)
|
||||
{
|
||||
SftpUploadFile::Ptr job = it.value().staticCast<SftpUploadFile>();
|
||||
switch (job->state) {
|
||||
case SftpUploadFile::OpenRequested: {
|
||||
bool emitError = false;
|
||||
if (job->parentJob) {
|
||||
if (!job->parentJob->hasError) {
|
||||
job->parentJob->setError();
|
||||
emitError = true;
|
||||
}
|
||||
} else {
|
||||
emitError = true;
|
||||
}
|
||||
|
||||
if (emitError) {
|
||||
emit finished(job->jobId,
|
||||
errorMessage(response.errorString,
|
||||
tr("Failed to open remote file for writing.")));
|
||||
}
|
||||
m_jobs.erase(it);
|
||||
break;
|
||||
}
|
||||
case SftpUploadFile::Open:
|
||||
if (job->hasError || (job->parentJob && job->parentJob->hasError)) {
|
||||
job->hasError = true;
|
||||
finishTransferRequest(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.status == SSH_FX_OK) {
|
||||
sendWriteRequest(it);
|
||||
} else {
|
||||
if (job->parentJob)
|
||||
job->parentJob->setError();
|
||||
reportRequestError(job, errorMessage(response.errorString,
|
||||
tr("Failed to write remote file.")));
|
||||
finishTransferRequest(it);
|
||||
}
|
||||
break;
|
||||
case SftpUploadFile::CloseRequested:
|
||||
Q_ASSERT(job->inFlightCount == 1);
|
||||
if (job->hasError || (job->parentJob && job->parentJob->hasError)) {
|
||||
m_jobs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.status == SSH_FX_OK) {
|
||||
if (job->parentJob) {
|
||||
job->parentJob->uploadsInProgress.removeOne(job);
|
||||
if (job->parentJob->mkdirsInProgress.isEmpty()
|
||||
&& job->parentJob->uploadsInProgress.isEmpty())
|
||||
emit finished(job->parentJob->jobId);
|
||||
} else {
|
||||
emit finished(job->jobId);
|
||||
}
|
||||
} else {
|
||||
const QString error = errorMessage(response.errorString,
|
||||
tr("Failed to close remote file."));
|
||||
if (job->parentJob) {
|
||||
job->parentJob->setError();
|
||||
emit finished(job->parentJob->jobId, error);
|
||||
} else {
|
||||
emit finished(job->jobId, error);
|
||||
}
|
||||
}
|
||||
m_jobs.erase(it);
|
||||
break;
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_STATUS packet.");
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleName()
|
||||
{
|
||||
const SftpNameResponse &response = m_incomingPacket.asNameResponse();
|
||||
JobMap::Iterator it = lookupJob(response.requestId);
|
||||
switch (it.value()->type()) {
|
||||
case AbstractSftpOperation::ListDir: {
|
||||
SftpListDir::Ptr op = it.value().staticCast<SftpListDir>();
|
||||
if (op->state != SftpListDir::Open) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_NAME packet.");
|
||||
}
|
||||
|
||||
QList<SftpFileInfo> fileInfoList;
|
||||
for (int i = 0; i < response.files.count(); ++i) {
|
||||
const SftpFile &file = response.files.at(i);
|
||||
|
||||
SftpFileInfo fileInfo;
|
||||
fileInfo.name = file.fileName;
|
||||
attributesToFileInfo(file.attributes, fileInfo);
|
||||
fileInfoList << fileInfo;
|
||||
}
|
||||
emit fileInfoAvailable(op->jobId, fileInfoList);
|
||||
sendData(m_outgoingPacket.generateReadDir(op->remoteHandle,
|
||||
op->jobId).rawData());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_NAME packet.");
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleReadData()
|
||||
{
|
||||
const SftpDataResponse &response = m_incomingPacket.asDataResponse();
|
||||
JobMap::Iterator it = lookupJob(response.requestId);
|
||||
if (it.value()->type() != AbstractSftpOperation::Download) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_DATA packet.");
|
||||
}
|
||||
|
||||
SftpDownload::Ptr op = it.value().staticCast<SftpDownload>();
|
||||
if (op->hasError) {
|
||||
finishTransferRequest(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!op->localFile->seek(op->offsets[response.requestId])) {
|
||||
reportRequestError(op, op->localFile->errorString());
|
||||
finishTransferRequest(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (op->localFile->write(response.data) != response.data.size()) {
|
||||
reportRequestError(op, op->localFile->errorString());
|
||||
finishTransferRequest(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (op->offset >= op->fileSize && op->fileSize != 0)
|
||||
finishTransferRequest(it);
|
||||
else
|
||||
sendReadRequest(op, response.requestId);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleAttrs()
|
||||
{
|
||||
const SftpAttrsResponse &response = m_incomingPacket.asAttrsResponse();
|
||||
JobMap::Iterator it = lookupJob(response.requestId);
|
||||
|
||||
SftpStatFile::Ptr statOp = it.value().dynamicCast<SftpStatFile>();
|
||||
if (statOp) {
|
||||
SftpFileInfo fileInfo;
|
||||
fileInfo.name = QFileInfo(statOp->path).fileName();
|
||||
attributesToFileInfo(response.attrs, fileInfo);
|
||||
emit fileInfoAvailable(it.key(), QList<SftpFileInfo>() << fileInfo);
|
||||
emit finished(it.key());
|
||||
m_jobs.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractSftpTransfer::Ptr transfer
|
||||
= it.value().dynamicCast<AbstractSftpTransfer>();
|
||||
if (!transfer || transfer->state != AbstractSftpTransfer::Open
|
||||
|| !transfer->statRequested) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_FXP_ATTRS packet.");
|
||||
}
|
||||
Q_ASSERT(transfer->type() == AbstractSftpOperation::UploadFile
|
||||
|| transfer->type() == AbstractSftpOperation::Download);
|
||||
|
||||
if (transfer->type() == AbstractSftpOperation::Download) {
|
||||
SftpDownload::Ptr op = transfer.staticCast<SftpDownload>();
|
||||
if (response.attrs.sizePresent) {
|
||||
op->fileSize = response.attrs.size;
|
||||
} else {
|
||||
op->fileSize = 0;
|
||||
op->eofId = op->jobId;
|
||||
}
|
||||
op->statRequested = false;
|
||||
spawnReadRequests(op);
|
||||
} else {
|
||||
SftpUploadFile::Ptr op = transfer.staticCast<SftpUploadFile>();
|
||||
if (op->parentJob && op->parentJob->hasError) {
|
||||
op->hasError = true;
|
||||
sendTransferCloseHandle(op, op->jobId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.attrs.sizePresent) {
|
||||
op->offset = response.attrs.size;
|
||||
spawnWriteRequests(it);
|
||||
} else {
|
||||
if (op->parentJob)
|
||||
op->parentJob->setError();
|
||||
reportRequestError(op, tr("Cannot append to remote file: "
|
||||
"Server does not support the file size attribute."));
|
||||
sendTransferCloseHandle(op, op->jobId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SftpChannelPrivate::JobMap::Iterator SftpChannelPrivate::lookupJob(SftpJobId id)
|
||||
{
|
||||
JobMap::Iterator it = m_jobs.find(id);
|
||||
if (it == m_jobs.end()) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid request id in SFTP packet.");
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::closeHook()
|
||||
{
|
||||
for (JobMap::ConstIterator it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it)
|
||||
emit finished(it.key(), tr("SFTP channel closed unexpectedly."));
|
||||
m_jobs.clear();
|
||||
m_incomingData.clear();
|
||||
m_incomingPacket.clear();
|
||||
emit closed();
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleOpenSuccessInternal()
|
||||
{
|
||||
qCDebug(sshLog, "SFTP session started");
|
||||
m_sendFacility.sendSftpPacket(remoteChannel());
|
||||
m_sftpState = SubsystemRequested;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::handleOpenFailureInternal(const QString &reason)
|
||||
{
|
||||
if (channelState() != SessionRequested) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_OPEN_FAILURE packet.");
|
||||
}
|
||||
emit channelError(tr("Server could not start session: %1").arg(reason));
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::sendReadRequest(const SftpDownload::Ptr &job,
|
||||
quint32 requestId)
|
||||
{
|
||||
Q_ASSERT(job->eofId == SftpInvalidJob);
|
||||
sendData(m_outgoingPacket.generateReadFile(job->remoteHandle, job->offset,
|
||||
AbstractSftpPacket::MaxDataSize, requestId).rawData());
|
||||
job->offsets[requestId] = job->offset;
|
||||
job->offset += AbstractSftpPacket::MaxDataSize;
|
||||
if (job->offset >= job->fileSize)
|
||||
job->eofId = requestId;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::reportRequestError(const AbstractSftpOperationWithHandle::Ptr &job,
|
||||
const QString &error)
|
||||
{
|
||||
emit finished(job->jobId, error);
|
||||
job->hasError = true;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::finishTransferRequest(const JobMap::Iterator &it)
|
||||
{
|
||||
AbstractSftpTransfer::Ptr job = it.value().staticCast<AbstractSftpTransfer>();
|
||||
if (job->inFlightCount == 1)
|
||||
sendTransferCloseHandle(job, it.key());
|
||||
else
|
||||
removeTransferRequest(it);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::sendTransferCloseHandle(const AbstractSftpTransfer::Ptr &job,
|
||||
quint32 requestId)
|
||||
{
|
||||
sendData(m_outgoingPacket.generateCloseHandle(job->remoteHandle,
|
||||
requestId).rawData());
|
||||
job->state = SftpDownload::CloseRequested;
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::attributesToFileInfo(const SftpFileAttributes &attributes,
|
||||
SftpFileInfo &fileInfo) const
|
||||
{
|
||||
if (attributes.sizePresent) {
|
||||
fileInfo.sizeValid = true;
|
||||
fileInfo.size = attributes.size;
|
||||
}
|
||||
if (attributes.permissionsPresent) {
|
||||
if (attributes.permissions & 0x8000) // S_IFREG
|
||||
fileInfo.type = FileTypeRegular;
|
||||
else if (attributes.permissions & 0x4000) // S_IFDIR
|
||||
fileInfo.type = FileTypeDirectory;
|
||||
else
|
||||
fileInfo.type = FileTypeOther;
|
||||
fileInfo.permissionsValid = true;
|
||||
fileInfo.permissions = 0;
|
||||
if (attributes.permissions & 00001) // S_IXOTH
|
||||
fileInfo.permissions |= QFile::ExeOther;
|
||||
if (attributes.permissions & 00002) // S_IWOTH
|
||||
fileInfo.permissions |= QFile::WriteOther;
|
||||
if (attributes.permissions & 00004) // S_IROTH
|
||||
fileInfo.permissions |= QFile::ReadOther;
|
||||
if (attributes.permissions & 00010) // S_IXGRP
|
||||
fileInfo.permissions |= QFile::ExeGroup;
|
||||
if (attributes.permissions & 00020) // S_IWGRP
|
||||
fileInfo.permissions |= QFile::WriteGroup;
|
||||
if (attributes.permissions & 00040) // S_IRGRP
|
||||
fileInfo.permissions |= QFile::ReadGroup;
|
||||
if (attributes.permissions & 00100) // S_IXUSR
|
||||
fileInfo.permissions |= QFile::ExeUser | QFile::ExeOwner;
|
||||
if (attributes.permissions & 00200) // S_IWUSR
|
||||
fileInfo.permissions |= QFile::WriteUser | QFile::WriteOwner;
|
||||
if (attributes.permissions & 00400) // S_IRUSR
|
||||
fileInfo.permissions |= QFile::ReadUser | QFile::ReadOwner;
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::removeTransferRequest(const JobMap::Iterator &it)
|
||||
{
|
||||
--it.value().staticCast<AbstractSftpTransfer>()->inFlightCount;
|
||||
m_jobs.erase(it);
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::sendWriteRequest(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpUploadFile::Ptr job = it.value().staticCast<SftpUploadFile>();
|
||||
QByteArray data = job->localFile->read(AbstractSftpPacket::MaxDataSize);
|
||||
if (job->localFile->error() != QFile::NoError) {
|
||||
if (job->parentJob)
|
||||
job->parentJob->setError();
|
||||
reportRequestError(job, tr("Error reading local file: %1")
|
||||
.arg(job->localFile->errorString()));
|
||||
finishTransferRequest(it);
|
||||
} else if (data.isEmpty()) {
|
||||
finishTransferRequest(it);
|
||||
} else {
|
||||
sendData(m_outgoingPacket.generateWriteFile(job->remoteHandle,
|
||||
job->offset, data, it.key()).rawData());
|
||||
job->offset += AbstractSftpPacket::MaxDataSize;
|
||||
}
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::spawnWriteRequests(const JobMap::Iterator &it)
|
||||
{
|
||||
SftpUploadFile::Ptr op = it.value().staticCast<SftpUploadFile>();
|
||||
op->calculateInFlightCount(AbstractSftpPacket::MaxDataSize);
|
||||
sendWriteRequest(it);
|
||||
for (int i = 1; !op->hasError && i < op->inFlightCount; ++i)
|
||||
sendWriteRequest(m_jobs.insert(++m_nextJobId, op));
|
||||
}
|
||||
|
||||
void SftpChannelPrivate::spawnReadRequests(const SftpDownload::Ptr &job)
|
||||
{
|
||||
job->calculateInFlightCount(AbstractSftpPacket::MaxDataSize);
|
||||
sendReadRequest(job, job->jobId);
|
||||
for (int i = 1; i < job->inFlightCount; ++i) {
|
||||
const quint32 requestId = ++m_nextJobId;
|
||||
m_jobs.insert(requestId, job);
|
||||
sendReadRequest(job, requestId);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
103
client/3rd/QtSsh/src/ssh/sftpchannel.h
Executable file
103
client/3rd/QtSsh/src/ssh/sftpchannel.h
Executable file
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftpdefs.h"
|
||||
#include "sftpincomingpacket_p.h"
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
namespace Internal {
|
||||
class SftpChannelPrivate;
|
||||
class SshChannelManager;
|
||||
class SshSendFacility;
|
||||
} // namespace Internal
|
||||
|
||||
class QSSH_EXPORT SftpChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class Internal::SftpChannelPrivate;
|
||||
friend class Internal::SshChannelManager;
|
||||
public:
|
||||
typedef QSharedPointer<SftpChannel> Ptr;
|
||||
|
||||
enum State { Uninitialized, Initializing, Initialized, Closing, Closed };
|
||||
State state() const;
|
||||
|
||||
void initialize();
|
||||
void closeChannel();
|
||||
|
||||
SftpJobId statFile(const QString &path);
|
||||
SftpJobId listDirectory(const QString &dirPath);
|
||||
SftpJobId createDirectory(const QString &dirPath);
|
||||
SftpJobId removeDirectory(const QString &dirPath);
|
||||
SftpJobId removeFile(const QString &filePath);
|
||||
SftpJobId renameFileOrDirectory(const QString &oldPath,
|
||||
const QString &newPath);
|
||||
SftpJobId createFile(const QString &filePath, SftpOverwriteMode mode);
|
||||
SftpJobId createLink(const QString &filePath, const QString &target);
|
||||
SftpJobId uploadFile(const QString &localFilePath,
|
||||
const QString &remoteFilePath, SftpOverwriteMode mode);
|
||||
SftpJobId downloadFile(const QString &remoteFilePath,
|
||||
const QString &localFilePath, SftpOverwriteMode mode);
|
||||
SftpJobId uploadDir(const QString &localDirPath,
|
||||
const QString &remoteParentDirPath);
|
||||
|
||||
~SftpChannel();
|
||||
|
||||
signals:
|
||||
void initialized();
|
||||
void channelError(const QString &reason);
|
||||
void closed();
|
||||
|
||||
// error.isEmpty <=> finished successfully
|
||||
void finished(QSsh::SftpJobId job, const QString &error = QString());
|
||||
|
||||
// TODO: Also emit for each file copied by uploadDir().
|
||||
void dataAvailable(QSsh::SftpJobId job, const QString &data);
|
||||
|
||||
/*
|
||||
* This signal is emitted as a result of:
|
||||
* - statFile() (with the list having exactly one element)
|
||||
* - listDirectory() (potentially more than once)
|
||||
*/
|
||||
void fileInfoAvailable(QSsh::SftpJobId job, const QList<QSsh::SftpFileInfo> &fileInfoList);
|
||||
|
||||
private:
|
||||
SftpChannel(quint32 channelId, Internal::SshSendFacility &sendFacility);
|
||||
|
||||
Internal::SftpChannelPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
124
client/3rd/QtSsh/src/ssh/sftpchannel_p.h
Executable file
124
client/3rd/QtSsh/src/ssh/sftpchannel_p.h
Executable file
@@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftpdefs.h"
|
||||
#include "sftpincomingpacket_p.h"
|
||||
#include "sftpoperation_p.h"
|
||||
#include "sftpoutgoingpacket_p.h"
|
||||
#include "sshchannel_p.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QMap>
|
||||
|
||||
namespace QSsh {
|
||||
class SftpChannel;
|
||||
namespace Internal {
|
||||
|
||||
class SftpChannelPrivate : public AbstractSshChannel
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class QSsh::SftpChannel;
|
||||
public:
|
||||
enum SftpState { Inactive, SubsystemRequested, InitSent, Initialized };
|
||||
|
||||
signals:
|
||||
void initialized();
|
||||
void channelError(const QString &reason);
|
||||
void closed();
|
||||
void finished(QSsh::SftpJobId job, const QString &error = QString());
|
||||
void dataAvailable(QSsh::SftpJobId job, const QString &data);
|
||||
void fileInfoAvailable(QSsh::SftpJobId job, const QList<QSsh::SftpFileInfo> &fileInfoList);
|
||||
|
||||
private:
|
||||
typedef QMap<SftpJobId, AbstractSftpOperation::Ptr> JobMap;
|
||||
|
||||
SftpChannelPrivate(quint32 channelId, SshSendFacility &sendFacility,
|
||||
SftpChannel *sftp);
|
||||
SftpJobId createJob(const AbstractSftpOperation::Ptr &job);
|
||||
|
||||
virtual void handleChannelSuccess();
|
||||
virtual void handleChannelFailure();
|
||||
|
||||
virtual void handleOpenSuccessInternal();
|
||||
virtual void handleOpenFailureInternal(const QString &reason);
|
||||
virtual void handleChannelDataInternal(const QByteArray &data);
|
||||
virtual void handleChannelExtendedDataInternal(quint32 type,
|
||||
const QByteArray &data);
|
||||
virtual void handleExitStatus(const SshChannelExitStatus &exitStatus);
|
||||
virtual void handleExitSignal(const SshChannelExitSignal &signal);
|
||||
|
||||
virtual void closeHook();
|
||||
|
||||
void handleCurrentPacket();
|
||||
void handleServerVersion();
|
||||
void handleHandle();
|
||||
void handleStatus();
|
||||
void handleName();
|
||||
void handleReadData();
|
||||
void handleAttrs();
|
||||
|
||||
void handleStatusGeneric(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response);
|
||||
void handleMkdirStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response);
|
||||
void handleLsStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response);
|
||||
void handleGetStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response);
|
||||
void handlePutStatus(const JobMap::Iterator &it,
|
||||
const SftpStatusResponse &response);
|
||||
|
||||
void handleLsHandle(const JobMap::Iterator &it);
|
||||
void handleCreateFileHandle(const JobMap::Iterator &it);
|
||||
void handleGetHandle(const JobMap::Iterator &it);
|
||||
void handlePutHandle(const JobMap::Iterator &it);
|
||||
|
||||
void spawnReadRequests(const SftpDownload::Ptr &job);
|
||||
void spawnWriteRequests(const JobMap::Iterator &it);
|
||||
void sendReadRequest(const SftpDownload::Ptr &job, quint32 requestId);
|
||||
void sendWriteRequest(const JobMap::Iterator &it);
|
||||
void finishTransferRequest(const JobMap::Iterator &it);
|
||||
void removeTransferRequest(const JobMap::Iterator &it);
|
||||
void reportRequestError(const AbstractSftpOperationWithHandle::Ptr &job,
|
||||
const QString &error);
|
||||
void sendTransferCloseHandle(const AbstractSftpTransfer::Ptr &job,
|
||||
quint32 requestId);
|
||||
|
||||
void attributesToFileInfo(const SftpFileAttributes &attributes, SftpFileInfo &fileInfo) const;
|
||||
|
||||
JobMap::Iterator lookupJob(SftpJobId id);
|
||||
JobMap m_jobs;
|
||||
SftpOutgoingPacket m_outgoingPacket;
|
||||
SftpIncomingPacket m_incomingPacket;
|
||||
QByteArray m_incomingData;
|
||||
SftpJobId m_nextJobId;
|
||||
SftpState m_sftpState;
|
||||
SftpChannel *m_sftp;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
28
client/3rd/QtSsh/src/ssh/sftpdefs.cpp
Executable file
28
client/3rd/QtSsh/src/ssh/sftpdefs.cpp
Executable file
@@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpdefs.h"
|
||||
|
||||
namespace QSsh { const SftpJobId SftpInvalidJob = 0; }
|
||||
59
client/3rd/QtSsh/src/ssh/sftpdefs.h
Executable file
59
client/3rd/QtSsh/src/ssh/sftpdefs.h
Executable file
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
typedef quint32 SftpJobId;
|
||||
QSSH_EXPORT extern const SftpJobId SftpInvalidJob;
|
||||
|
||||
enum SftpOverwriteMode {
|
||||
SftpOverwriteExisting, SftpAppendToExisting, SftpSkipExisting
|
||||
};
|
||||
|
||||
enum SftpFileType { FileTypeRegular, FileTypeDirectory, FileTypeOther, FileTypeUnknown };
|
||||
|
||||
class QSSH_EXPORT SftpFileInfo
|
||||
{
|
||||
public:
|
||||
SftpFileInfo() : type(FileTypeUnknown), sizeValid(false), permissionsValid(false) { }
|
||||
|
||||
QString name;
|
||||
SftpFileType type;
|
||||
quint64 size;
|
||||
QFile::Permissions permissions;
|
||||
|
||||
// The RFC allows an SFTP server not to support any file attributes beyond the name.
|
||||
bool sizeValid;
|
||||
bool permissionsValid;
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
383
client/3rd/QtSsh/src/ssh/sftpfilesystemmodel.cpp
Executable file
383
client/3rd/QtSsh/src/ssh/sftpfilesystemmodel.cpp
Executable file
@@ -0,0 +1,383 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpfilesystemmodel.h"
|
||||
|
||||
#include "sftpchannel.h"
|
||||
#include "sshconnection.h"
|
||||
#include "sshconnectionmanager.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
#include <QIcon>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
namespace {
|
||||
|
||||
class SftpDirNode;
|
||||
class SftpFileNode
|
||||
{
|
||||
public:
|
||||
SftpFileNode() : parent(0) { }
|
||||
virtual ~SftpFileNode() { }
|
||||
|
||||
QString path;
|
||||
SftpFileInfo fileInfo;
|
||||
SftpDirNode *parent;
|
||||
};
|
||||
|
||||
class SftpDirNode : public SftpFileNode
|
||||
{
|
||||
public:
|
||||
SftpDirNode() : lsState(LsNotYetCalled) { }
|
||||
~SftpDirNode() { qDeleteAll(children); }
|
||||
|
||||
enum { LsNotYetCalled, LsRunning, LsFinished } lsState;
|
||||
QList<SftpFileNode *> children;
|
||||
};
|
||||
|
||||
typedef QHash<SftpJobId, SftpDirNode *> DirNodeHash;
|
||||
|
||||
SftpFileNode *indexToFileNode(const QModelIndex &index)
|
||||
{
|
||||
return static_cast<SftpFileNode *>(index.internalPointer());
|
||||
}
|
||||
|
||||
SftpDirNode *indexToDirNode(const QModelIndex &index)
|
||||
{
|
||||
SftpFileNode * const fileNode = indexToFileNode(index);
|
||||
QSSH_ASSERT(fileNode);
|
||||
return dynamic_cast<SftpDirNode *>(fileNode);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class SftpFileSystemModelPrivate
|
||||
{
|
||||
public:
|
||||
SshConnection *sshConnection;
|
||||
SftpChannel::Ptr sftpChannel;
|
||||
QString rootDirectory;
|
||||
SftpFileNode *rootNode;
|
||||
SftpJobId statJobId;
|
||||
DirNodeHash lsOps;
|
||||
QList<SftpJobId> externalJobs;
|
||||
};
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
SftpFileSystemModel::SftpFileSystemModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), d(new SftpFileSystemModelPrivate)
|
||||
{
|
||||
d->sshConnection = 0;
|
||||
d->rootDirectory = QLatin1Char('/');
|
||||
d->rootNode = 0;
|
||||
d->statJobId = SftpInvalidJob;
|
||||
}
|
||||
|
||||
SftpFileSystemModel::~SftpFileSystemModel()
|
||||
{
|
||||
shutDown();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::setSshConnection(const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN(!d->sshConnection);
|
||||
d->sshConnection = QSsh::acquireConnection(sshParams);
|
||||
connect(d->sshConnection, &SshConnection::error,
|
||||
this, &SftpFileSystemModel::handleSshConnectionFailure);
|
||||
if (d->sshConnection->state() == SshConnection::Connected) {
|
||||
handleSshConnectionEstablished();
|
||||
return;
|
||||
}
|
||||
connect(d->sshConnection, &SshConnection::connected,
|
||||
this, &SftpFileSystemModel::handleSshConnectionEstablished);
|
||||
if (d->sshConnection->state() == SshConnection::Unconnected)
|
||||
d->sshConnection->connectToHost();
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::setRootDirectory(const QString &path)
|
||||
{
|
||||
beginResetModel();
|
||||
d->rootDirectory = path;
|
||||
delete d->rootNode;
|
||||
d->rootNode = 0;
|
||||
d->lsOps.clear();
|
||||
d->statJobId = SftpInvalidJob;
|
||||
endResetModel();
|
||||
statRootDirectory();
|
||||
}
|
||||
|
||||
QString SftpFileSystemModel::rootDirectory() const
|
||||
{
|
||||
return d->rootDirectory;
|
||||
}
|
||||
|
||||
SftpJobId SftpFileSystemModel::downloadFile(const QModelIndex &index, const QString &targetFilePath)
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(d->rootNode, SftpInvalidJob);
|
||||
const SftpFileNode * const fileNode = indexToFileNode(index);
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(fileNode, SftpInvalidJob);
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(fileNode->fileInfo.type == FileTypeRegular, SftpInvalidJob);
|
||||
const SftpJobId jobId = d->sftpChannel->downloadFile(fileNode->path, targetFilePath,
|
||||
SftpOverwriteExisting);
|
||||
if (jobId != SftpInvalidJob)
|
||||
d->externalJobs << jobId;
|
||||
return jobId;
|
||||
}
|
||||
|
||||
int SftpFileSystemModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 2; // type + name
|
||||
}
|
||||
|
||||
QVariant SftpFileSystemModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
const SftpFileNode * const node = indexToFileNode(index);
|
||||
if (index.column() == 0 && role == Qt::DecorationRole) {
|
||||
switch (node->fileInfo.type) {
|
||||
case FileTypeRegular:
|
||||
case FileTypeOther:
|
||||
return QIcon(":/utils/images/unknownfile.png");
|
||||
case FileTypeDirectory:
|
||||
return QIcon(":/utils/images/dir.png");
|
||||
case FileTypeUnknown:
|
||||
return QIcon(":/utils/images/help.png"); // Shows a question mark.
|
||||
}
|
||||
}
|
||||
if (index.column() == 1) {
|
||||
if (role == Qt::DisplayRole)
|
||||
return node->fileInfo.name;
|
||||
if (role == PathRole)
|
||||
return node->path;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags SftpFileSystemModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
QVariant SftpFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation != Qt::Horizontal)
|
||||
return QVariant();
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
if (section == 0)
|
||||
return tr("File Type");
|
||||
if (section == 1)
|
||||
return tr("File Name");
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex SftpFileSystemModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
|
||||
return QModelIndex();
|
||||
if (!d->rootNode)
|
||||
return QModelIndex();
|
||||
if (!parent.isValid())
|
||||
return createIndex(row, column, d->rootNode);
|
||||
const SftpDirNode * const parentNode = indexToDirNode(parent);
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(parentNode, QModelIndex());
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(row < parentNode->children.count(), QModelIndex());
|
||||
SftpFileNode * const childNode = parentNode->children.at(row);
|
||||
return createIndex(row, column, childNode);
|
||||
}
|
||||
|
||||
QModelIndex SftpFileSystemModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
if (!child.isValid()) // Don't assert on this, since the model tester tries it.
|
||||
return QModelIndex();
|
||||
|
||||
const SftpFileNode * const childNode = indexToFileNode(child);
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(childNode, QModelIndex());
|
||||
if (childNode == d->rootNode)
|
||||
return QModelIndex();
|
||||
SftpDirNode * const parentNode = childNode->parent;
|
||||
if (parentNode == d->rootNode)
|
||||
return createIndex(0, 0, d->rootNode);
|
||||
const SftpDirNode * const grandParentNode = parentNode->parent;
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(grandParentNode, QModelIndex());
|
||||
return createIndex(grandParentNode->children.indexOf(parentNode), 0, parentNode);
|
||||
}
|
||||
|
||||
int SftpFileSystemModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!d->rootNode)
|
||||
return 0;
|
||||
if (!parent.isValid())
|
||||
return 1;
|
||||
if (parent.column() != 0)
|
||||
return 0;
|
||||
SftpDirNode * const dirNode = indexToDirNode(parent);
|
||||
if (!dirNode)
|
||||
return 0;
|
||||
if (dirNode->lsState != SftpDirNode::LsNotYetCalled)
|
||||
return dirNode->children.count();
|
||||
d->lsOps.insert(d->sftpChannel->listDirectory(dirNode->path), dirNode);
|
||||
dirNode->lsState = SftpDirNode::LsRunning;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::statRootDirectory()
|
||||
{
|
||||
d->statJobId = d->sftpChannel->statFile(d->rootDirectory);
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::shutDown()
|
||||
{
|
||||
if (d->sftpChannel) {
|
||||
disconnect(d->sftpChannel.data(), 0, this, 0);
|
||||
d->sftpChannel->closeChannel();
|
||||
d->sftpChannel.clear();
|
||||
}
|
||||
if (d->sshConnection) {
|
||||
disconnect(d->sshConnection, 0, this, 0);
|
||||
QSsh::releaseConnection(d->sshConnection);
|
||||
d->sshConnection = 0;
|
||||
}
|
||||
delete d->rootNode;
|
||||
d->rootNode = 0;
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleSshConnectionFailure()
|
||||
{
|
||||
emit connectionError(d->sshConnection->errorString());
|
||||
beginResetModel();
|
||||
shutDown();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleSftpChannelInitialized()
|
||||
{
|
||||
connect(d->sftpChannel.data(),
|
||||
&SftpChannel::fileInfoAvailable,
|
||||
this, &SftpFileSystemModel::handleFileInfo);
|
||||
connect(d->sftpChannel.data(), &SftpChannel::finished,
|
||||
this, &SftpFileSystemModel::handleSftpJobFinished);
|
||||
statRootDirectory();
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleSshConnectionEstablished()
|
||||
{
|
||||
d->sftpChannel = d->sshConnection->createSftpChannel();
|
||||
connect(d->sftpChannel.data(), &SftpChannel::initialized,
|
||||
this, &SftpFileSystemModel::handleSftpChannelInitialized);
|
||||
connect(d->sftpChannel.data(), &SftpChannel::channelError,
|
||||
this, &SftpFileSystemModel::handleSftpChannelError);
|
||||
d->sftpChannel->initialize();
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleSftpChannelError(const QString &reason)
|
||||
{
|
||||
emit connectionError(reason);
|
||||
beginResetModel();
|
||||
shutDown();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleFileInfo(SftpJobId jobId, const QList<SftpFileInfo> &fileInfoList)
|
||||
{
|
||||
if (jobId == d->statJobId) {
|
||||
QSSH_ASSERT_AND_RETURN(!d->rootNode);
|
||||
beginInsertRows(QModelIndex(), 0, 0);
|
||||
d->rootNode = new SftpDirNode;
|
||||
d->rootNode->path = d->rootDirectory;
|
||||
d->rootNode->fileInfo = fileInfoList.first();
|
||||
d->rootNode->fileInfo.name = d->rootDirectory == QLatin1String("/")
|
||||
? d->rootDirectory : QFileInfo(d->rootDirectory).fileName();
|
||||
endInsertRows();
|
||||
return;
|
||||
}
|
||||
SftpDirNode * const parentNode = d->lsOps.value(jobId);
|
||||
QSSH_ASSERT_AND_RETURN(parentNode);
|
||||
QList<SftpFileInfo> filteredList;
|
||||
foreach (const SftpFileInfo &fi, fileInfoList) {
|
||||
if (fi.name != QLatin1String(".") && fi.name != QLatin1String(".."))
|
||||
filteredList << fi;
|
||||
}
|
||||
if (filteredList.isEmpty())
|
||||
return;
|
||||
|
||||
// In theory beginInsertRows() should suffice, but that fails to have an effect
|
||||
// if rowCount() returned 0 earlier.
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
foreach (const SftpFileInfo &fileInfo, filteredList) {
|
||||
SftpFileNode *childNode;
|
||||
if (fileInfo.type == FileTypeDirectory)
|
||||
childNode = new SftpDirNode;
|
||||
else
|
||||
childNode = new SftpFileNode;
|
||||
childNode->path = parentNode->path;
|
||||
if (!childNode->path.endsWith(QLatin1Char('/')))
|
||||
childNode->path += QLatin1Char('/');
|
||||
childNode->path += fileInfo.name;
|
||||
childNode->fileInfo = fileInfo;
|
||||
childNode->parent = parentNode;
|
||||
parentNode->children << childNode;
|
||||
}
|
||||
emit layoutChanged(); // Should be endInsertRows(), see above.
|
||||
}
|
||||
|
||||
void SftpFileSystemModel::handleSftpJobFinished(SftpJobId jobId, const QString &errorMessage)
|
||||
{
|
||||
if (jobId == d->statJobId) {
|
||||
d->statJobId = SftpInvalidJob;
|
||||
if (!errorMessage.isEmpty())
|
||||
emit sftpOperationFailed(tr("Error getting \"stat\" info about \"%1\": %2")
|
||||
.arg(rootDirectory(), errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
DirNodeHash::Iterator it = d->lsOps.find(jobId);
|
||||
if (it != d->lsOps.end()) {
|
||||
QSSH_ASSERT(it.value()->lsState == SftpDirNode::LsRunning);
|
||||
it.value()->lsState = SftpDirNode::LsFinished;
|
||||
if (!errorMessage.isEmpty())
|
||||
emit sftpOperationFailed(tr("Error listing contents of directory \"%1\": %2")
|
||||
.arg(it.value()->path, errorMessage));
|
||||
d->lsOps.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
const int jobIndex = d->externalJobs.indexOf(jobId);
|
||||
QSSH_ASSERT_AND_RETURN(jobIndex != -1);
|
||||
d->externalJobs.removeAt(jobIndex);
|
||||
emit sftpOperationFinished(jobId, errorMessage);
|
||||
}
|
||||
|
||||
} // namespace QSsh
|
||||
100
client/3rd/QtSsh/src/ssh/sftpfilesystemmodel.h
Executable file
100
client/3rd/QtSsh/src/ssh/sftpfilesystemmodel.h
Executable file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftpdefs.h"
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
namespace QSsh {
|
||||
class SshConnectionParameters;
|
||||
|
||||
namespace Internal { class SftpFileSystemModelPrivate; }
|
||||
|
||||
// Very simple read-only model. Symbolic links are not followed.
|
||||
class QSSH_EXPORT SftpFileSystemModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SftpFileSystemModel(QObject *parent = 0);
|
||||
~SftpFileSystemModel();
|
||||
|
||||
/*
|
||||
* Once this is called, an SFTP connection is established and the model is populated.
|
||||
* The effect of additional calls is undefined.
|
||||
*/
|
||||
void setSshConnection(const SshConnectionParameters &sshParams);
|
||||
|
||||
void setRootDirectory(const QString &path); // Default is "/".
|
||||
QString rootDirectory() const;
|
||||
|
||||
SftpJobId downloadFile(const QModelIndex &index, const QString &targetFilePath);
|
||||
|
||||
// Use this to get the full path of a file or directory.
|
||||
static const int PathRole = Qt::UserRole;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
signals:
|
||||
/*
|
||||
* E.g. "Permission denied". Note that this can happen without direct user intervention,
|
||||
* due to e.g. the view calling rowCount() on a non-readable directory. This signal should
|
||||
* therefore not result in a message box or similar, since it might occur very often.
|
||||
*/
|
||||
void sftpOperationFailed(const QString &errorMessage);
|
||||
|
||||
/*
|
||||
* This error is not recoverable. The model will not have any content after
|
||||
* the signal has been emitted.
|
||||
*/
|
||||
void connectionError(const QString &errorMessage);
|
||||
|
||||
// Success <=> error.isEmpty().
|
||||
void sftpOperationFinished(QSsh::SftpJobId, const QString &error);
|
||||
|
||||
private:
|
||||
void handleSshConnectionEstablished();
|
||||
void handleSshConnectionFailure();
|
||||
void handleSftpChannelInitialized();
|
||||
void handleSftpChannelError(const QString &reason);
|
||||
void handleFileInfo(QSsh::SftpJobId jobId, const QList<QSsh::SftpFileInfo> &fileInfoList);
|
||||
void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage);
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
void statRootDirectory();
|
||||
void shutDown();
|
||||
|
||||
Internal::SftpFileSystemModelPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace QSsh;
|
||||
217
client/3rd/QtSsh/src/ssh/sftpincomingpacket.cpp
Executable file
217
client/3rd/QtSsh/src/ssh/sftpincomingpacket.cpp
Executable file
@@ -0,0 +1,217 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpincomingpacket_p.h"
|
||||
|
||||
#include "sshexception_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshpacketparser_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
SftpIncomingPacket::SftpIncomingPacket() : m_length(0)
|
||||
{
|
||||
}
|
||||
|
||||
void SftpIncomingPacket::consumeData(QByteArray &newData)
|
||||
{
|
||||
qCDebug(sshLog, "%s: current data size = %d, new data size = %d", Q_FUNC_INFO,
|
||||
m_data.size(), newData.size());
|
||||
|
||||
if (isComplete() || dataSize() + newData.size() < sizeof m_length)
|
||||
return;
|
||||
|
||||
if (dataSize() < sizeof m_length) {
|
||||
moveFirstBytes(m_data, newData, sizeof m_length - m_data.size());
|
||||
m_length = SshPacketParser::asUint32(m_data, static_cast<quint32>(0));
|
||||
if (m_length < static_cast<quint32>(TypeOffset + 1)
|
||||
|| m_length > MaxPacketSize) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid length field in SFTP packet.");
|
||||
}
|
||||
}
|
||||
|
||||
moveFirstBytes(m_data, newData,
|
||||
qMin<quint32>(m_length - dataSize() + 4, newData.size()));
|
||||
}
|
||||
|
||||
void SftpIncomingPacket::moveFirstBytes(QByteArray &target, QByteArray &source,
|
||||
int n)
|
||||
{
|
||||
target.append(source.left(n));
|
||||
source.remove(0, n);
|
||||
}
|
||||
|
||||
bool SftpIncomingPacket::isComplete() const
|
||||
{
|
||||
return m_length == dataSize() - 4;
|
||||
}
|
||||
|
||||
void SftpIncomingPacket::clear()
|
||||
{
|
||||
m_data.clear();
|
||||
m_length = 0;
|
||||
}
|
||||
|
||||
quint32 SftpIncomingPacket::extractServerVersion() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_VERSION);
|
||||
try {
|
||||
return SshPacketParser::asUint32(m_data, TypeOffset + 1);
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_VERSION packet.");
|
||||
}
|
||||
}
|
||||
|
||||
SftpHandleResponse SftpIncomingPacket::asHandleResponse() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_HANDLE);
|
||||
try {
|
||||
SftpHandleResponse response;
|
||||
quint32 offset = RequestIdOffset;
|
||||
response.requestId = SshPacketParser::asUint32(m_data, &offset);
|
||||
response.handle = SshPacketParser::asString(m_data, &offset);
|
||||
return response;
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_HANDLE packet");
|
||||
}
|
||||
}
|
||||
|
||||
SftpStatusResponse SftpIncomingPacket::asStatusResponse() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_STATUS);
|
||||
try {
|
||||
SftpStatusResponse response;
|
||||
quint32 offset = RequestIdOffset;
|
||||
response.requestId = SshPacketParser::asUint32(m_data, &offset);
|
||||
response.status = static_cast<SftpStatusCode>(SshPacketParser::asUint32(m_data, &offset));
|
||||
response.errorString = SshPacketParser::asUserString(m_data, &offset);
|
||||
response.language = SshPacketParser::asString(m_data, &offset);
|
||||
return response;
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_STATUS packet.");
|
||||
}
|
||||
}
|
||||
|
||||
SftpNameResponse SftpIncomingPacket::asNameResponse() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_NAME);
|
||||
try {
|
||||
SftpNameResponse response;
|
||||
quint32 offset = RequestIdOffset;
|
||||
response.requestId = SshPacketParser::asUint32(m_data, &offset);
|
||||
const quint32 count = SshPacketParser::asUint32(m_data, &offset);
|
||||
for (quint32 i = 0; i < count; ++i)
|
||||
response.files << asFile(offset);
|
||||
return response;
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_NAME packet.");
|
||||
}
|
||||
}
|
||||
|
||||
SftpDataResponse SftpIncomingPacket::asDataResponse() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_DATA);
|
||||
try {
|
||||
SftpDataResponse response;
|
||||
quint32 offset = RequestIdOffset;
|
||||
response.requestId = SshPacketParser::asUint32(m_data, &offset);
|
||||
response.data = SshPacketParser::asString(m_data, &offset);
|
||||
return response;
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_DATA packet.");
|
||||
}
|
||||
}
|
||||
|
||||
SftpAttrsResponse SftpIncomingPacket::asAttrsResponse() const
|
||||
{
|
||||
Q_ASSERT(isComplete());
|
||||
Q_ASSERT(type() == SSH_FXP_ATTRS);
|
||||
try {
|
||||
SftpAttrsResponse response;
|
||||
quint32 offset = RequestIdOffset;
|
||||
response.requestId = SshPacketParser::asUint32(m_data, &offset);
|
||||
response.attrs = asFileAttributes(offset);
|
||||
return response;
|
||||
} catch (const SshPacketParseException &) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid SSH_FXP_ATTRS packet.");
|
||||
}
|
||||
}
|
||||
|
||||
SftpFile SftpIncomingPacket::asFile(quint32 &offset) const
|
||||
{
|
||||
SftpFile file;
|
||||
file.fileName
|
||||
= QString::fromUtf8(SshPacketParser::asString(m_data, &offset));
|
||||
file.longName
|
||||
= QString::fromUtf8(SshPacketParser::asString(m_data, &offset));
|
||||
file.attributes = asFileAttributes(offset);
|
||||
return file;
|
||||
}
|
||||
|
||||
SftpFileAttributes SftpIncomingPacket::asFileAttributes(quint32 &offset) const
|
||||
{
|
||||
SftpFileAttributes attributes;
|
||||
const quint32 flags = SshPacketParser::asUint32(m_data, &offset);
|
||||
attributes.sizePresent = flags & SSH_FILEXFER_ATTR_SIZE;
|
||||
attributes.timesPresent = flags & SSH_FILEXFER_ATTR_ACMODTIME;
|
||||
attributes.uidAndGidPresent = flags & SSH_FILEXFER_ATTR_UIDGID;
|
||||
attributes.permissionsPresent = flags & SSH_FILEXFER_ATTR_PERMISSIONS;
|
||||
if (attributes.sizePresent)
|
||||
attributes.size = SshPacketParser::asUint64(m_data, &offset);
|
||||
if (attributes.uidAndGidPresent) {
|
||||
attributes.uid = SshPacketParser::asUint32(m_data, &offset);
|
||||
attributes.gid = SshPacketParser::asUint32(m_data, &offset);
|
||||
}
|
||||
if (attributes.permissionsPresent)
|
||||
attributes.permissions = SshPacketParser::asUint32(m_data, &offset);
|
||||
if (attributes.timesPresent) {
|
||||
attributes.atime = SshPacketParser::asUint32(m_data, &offset);
|
||||
attributes.mtime = SshPacketParser::asUint32(m_data, &offset);
|
||||
}
|
||||
if (flags & SSH_FILEXFER_ATTR_EXTENDED) {
|
||||
const quint32 count = SshPacketParser::asUint32(m_data, &offset);
|
||||
for (quint32 i = 0; i < count; ++i) {
|
||||
SshPacketParser::asString(m_data, &offset);
|
||||
SshPacketParser::asString(m_data, &offset);
|
||||
}
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
104
client/3rd/QtSsh/src/ssh/sftpincomingpacket_p.h
Executable file
104
client/3rd/QtSsh/src/ssh/sftpincomingpacket_p.h
Executable file
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftppacket_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
struct SftpHandleResponse {
|
||||
quint32 requestId;
|
||||
QByteArray handle;
|
||||
};
|
||||
|
||||
struct SftpStatusResponse {
|
||||
quint32 requestId;
|
||||
SftpStatusCode status;
|
||||
QString errorString;
|
||||
QByteArray language;
|
||||
};
|
||||
|
||||
struct SftpFileAttributes {
|
||||
bool sizePresent;
|
||||
bool timesPresent;
|
||||
bool uidAndGidPresent;
|
||||
bool permissionsPresent;
|
||||
quint64 size;
|
||||
quint32 uid;
|
||||
quint32 gid;
|
||||
quint32 permissions;
|
||||
quint32 atime;
|
||||
quint32 mtime;
|
||||
};
|
||||
|
||||
struct SftpFile {
|
||||
QString fileName;
|
||||
QString longName; // Not present in later RFCs, so we don't expose this to the user.
|
||||
SftpFileAttributes attributes;
|
||||
};
|
||||
|
||||
struct SftpNameResponse {
|
||||
quint32 requestId;
|
||||
QList<SftpFile> files;
|
||||
};
|
||||
|
||||
struct SftpDataResponse {
|
||||
quint32 requestId;
|
||||
QByteArray data;
|
||||
};
|
||||
|
||||
struct SftpAttrsResponse {
|
||||
quint32 requestId;
|
||||
SftpFileAttributes attrs;
|
||||
};
|
||||
|
||||
class SftpIncomingPacket : public AbstractSftpPacket
|
||||
{
|
||||
public:
|
||||
SftpIncomingPacket();
|
||||
|
||||
void consumeData(QByteArray &data);
|
||||
void clear();
|
||||
bool isComplete() const;
|
||||
quint32 extractServerVersion() const;
|
||||
SftpHandleResponse asHandleResponse() const;
|
||||
SftpStatusResponse asStatusResponse() const;
|
||||
SftpNameResponse asNameResponse() const;
|
||||
SftpDataResponse asDataResponse() const;
|
||||
SftpAttrsResponse asAttrsResponse() const;
|
||||
|
||||
private:
|
||||
void moveFirstBytes(QByteArray &target, QByteArray &source, int n);
|
||||
|
||||
SftpFileAttributes asFileAttributes(quint32 &offset) const;
|
||||
SftpFile asFile(quint32 &offset) const;
|
||||
|
||||
quint32 m_length;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
220
client/3rd/QtSsh/src/ssh/sftpoperation.cpp
Executable file
220
client/3rd/QtSsh/src/ssh/sftpoperation.cpp
Executable file
@@ -0,0 +1,220 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpoperation_p.h"
|
||||
|
||||
#include "sftpoutgoingpacket_p.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
AbstractSftpOperation::AbstractSftpOperation(SftpJobId jobId) : jobId(jobId)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractSftpOperation::~AbstractSftpOperation() { }
|
||||
|
||||
|
||||
SftpStatFile::SftpStatFile(SftpJobId jobId, const QString &path)
|
||||
: AbstractSftpOperation(jobId), path(path)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpStatFile::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateStat(path, jobId);
|
||||
}
|
||||
|
||||
SftpMakeDir::SftpMakeDir(SftpJobId jobId, const QString &path,
|
||||
const SftpUploadDir::Ptr &parentJob)
|
||||
: AbstractSftpOperation(jobId), parentJob(parentJob), remoteDir(path)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpMakeDir::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateMkDir(remoteDir, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpRmDir::SftpRmDir(SftpJobId id, const QString &path)
|
||||
: AbstractSftpOperation(id), remoteDir(path)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpRmDir::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateRmDir(remoteDir, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpRm::SftpRm(SftpJobId jobId, const QString &path)
|
||||
: AbstractSftpOperation(jobId), remoteFile(path) {}
|
||||
|
||||
SftpOutgoingPacket &SftpRm::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateRm(remoteFile, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpRename::SftpRename(SftpJobId jobId, const QString &oldPath,
|
||||
const QString &newPath)
|
||||
: AbstractSftpOperation(jobId), oldPath(oldPath), newPath(newPath)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpRename::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateRename(oldPath, newPath, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpCreateLink::SftpCreateLink(SftpJobId jobId, const QString &filePath, const QString &target)
|
||||
: AbstractSftpOperation(jobId), filePath(filePath), target(target)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpCreateLink::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
return packet.generateCreateLink(filePath, target, jobId);
|
||||
}
|
||||
|
||||
|
||||
AbstractSftpOperationWithHandle::AbstractSftpOperationWithHandle(SftpJobId jobId,
|
||||
const QString &remotePath)
|
||||
: AbstractSftpOperation(jobId),
|
||||
remotePath(remotePath), state(Inactive), hasError(false)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractSftpOperationWithHandle::~AbstractSftpOperationWithHandle() { }
|
||||
|
||||
|
||||
SftpListDir::SftpListDir(SftpJobId jobId, const QString &path)
|
||||
: AbstractSftpOperationWithHandle(jobId, path)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpListDir::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
state = OpenRequested;
|
||||
return packet.generateOpenDir(remotePath, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpCreateFile::SftpCreateFile(SftpJobId jobId, const QString &path,
|
||||
SftpOverwriteMode mode)
|
||||
: AbstractSftpOperationWithHandle(jobId, path), mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket & SftpCreateFile::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
state = OpenRequested;
|
||||
return packet.generateOpenFileForWriting(remotePath, mode,
|
||||
SftpOutgoingPacket::DefaultPermissions, jobId);
|
||||
}
|
||||
|
||||
|
||||
const int AbstractSftpTransfer::MaxInFlightCount = 10; // Experimentally found to be enough.
|
||||
|
||||
AbstractSftpTransfer::AbstractSftpTransfer(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile)
|
||||
: AbstractSftpOperationWithHandle(jobId, remotePath),
|
||||
localFile(localFile), fileSize(0), offset(0), inFlightCount(0),
|
||||
statRequested(false)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractSftpTransfer::~AbstractSftpTransfer() {}
|
||||
|
||||
void AbstractSftpTransfer::calculateInFlightCount(quint32 chunkSize)
|
||||
{
|
||||
if (fileSize == 0) {
|
||||
inFlightCount = 1;
|
||||
} else {
|
||||
inFlightCount = fileSize / chunkSize;
|
||||
if (fileSize % chunkSize)
|
||||
++inFlightCount;
|
||||
if (inFlightCount > MaxInFlightCount)
|
||||
inFlightCount = MaxInFlightCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SftpDownload::SftpDownload(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile)
|
||||
: AbstractSftpTransfer(jobId, remotePath, localFile), eofId(SftpInvalidJob)
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpDownload::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
state = OpenRequested;
|
||||
return packet.generateOpenFileForReading(remotePath, jobId);
|
||||
}
|
||||
|
||||
|
||||
SftpUploadFile::SftpUploadFile(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile, SftpOverwriteMode mode,
|
||||
const SftpUploadDir::Ptr &parentJob)
|
||||
: AbstractSftpTransfer(jobId, remotePath, localFile),
|
||||
parentJob(parentJob), mode(mode)
|
||||
{
|
||||
fileSize = localFile->size();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpUploadFile::initialPacket(SftpOutgoingPacket &packet)
|
||||
{
|
||||
state = OpenRequested;
|
||||
quint32 permissions = 0;
|
||||
const QFile::Permissions &qtPermissions = localFile->permissions();
|
||||
if (qtPermissions & QFile::ExeOther)
|
||||
permissions |= 1 << 0;
|
||||
if (qtPermissions & QFile::WriteOther)
|
||||
permissions |= 1 << 1;
|
||||
if (qtPermissions & QFile::ReadOther)
|
||||
permissions |= 1 << 2;
|
||||
if (qtPermissions & QFile::ExeGroup)
|
||||
permissions |= 1<< 3;
|
||||
if (qtPermissions & QFile::WriteGroup)
|
||||
permissions |= 1<< 4;
|
||||
if (qtPermissions & QFile::ReadGroup)
|
||||
permissions |= 1<< 5;
|
||||
if (qtPermissions & QFile::ExeOwner)
|
||||
permissions |= 1<< 6;
|
||||
if (qtPermissions & QFile::WriteOwner)
|
||||
permissions |= 1<< 7;
|
||||
if (qtPermissions & QFile::ReadOwner)
|
||||
permissions |= 1<< 8;
|
||||
return packet.generateOpenFileForWriting(remotePath, mode, permissions, jobId);
|
||||
}
|
||||
|
||||
SftpUploadDir::~SftpUploadDir() {}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
244
client/3rd/QtSsh/src/ssh/sftpoperation_p.h
Executable file
244
client/3rd/QtSsh/src/ssh/sftpoperation_p.h
Executable file
@@ -0,0 +1,244 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftpdefs.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSharedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QFile;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
class SftpOutgoingPacket;
|
||||
|
||||
struct AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<AbstractSftpOperation> Ptr;
|
||||
enum Type {
|
||||
StatFile, ListDir, MakeDir, RmDir, Rm, Rename, CreateLink, CreateFile, Download, UploadFile
|
||||
};
|
||||
|
||||
AbstractSftpOperation(SftpJobId jobId);
|
||||
virtual ~AbstractSftpOperation();
|
||||
virtual Type type() const = 0;
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet) = 0;
|
||||
|
||||
const SftpJobId jobId;
|
||||
|
||||
private:
|
||||
AbstractSftpOperation(const AbstractSftpOperation &);
|
||||
AbstractSftpOperation &operator=(const AbstractSftpOperation &);
|
||||
};
|
||||
|
||||
struct SftpUploadDir;
|
||||
|
||||
struct SftpStatFile : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpStatFile> Ptr;
|
||||
|
||||
SftpStatFile(SftpJobId jobId, const QString &path);
|
||||
virtual Type type() const { return StatFile; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QString path;
|
||||
};
|
||||
|
||||
struct SftpMakeDir : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpMakeDir> Ptr;
|
||||
|
||||
SftpMakeDir(SftpJobId jobId, const QString &path,
|
||||
const QSharedPointer<SftpUploadDir> &parentJob = QSharedPointer<SftpUploadDir>());
|
||||
virtual Type type() const { return MakeDir; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QSharedPointer<SftpUploadDir> parentJob;
|
||||
const QString remoteDir;
|
||||
};
|
||||
|
||||
struct SftpRmDir : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpRmDir> Ptr;
|
||||
|
||||
SftpRmDir(SftpJobId id, const QString &path);
|
||||
virtual Type type() const { return RmDir; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QString remoteDir;
|
||||
};
|
||||
|
||||
struct SftpRm : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpRm> Ptr;
|
||||
|
||||
SftpRm(SftpJobId jobId, const QString &path);
|
||||
virtual Type type() const { return Rm; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QString remoteFile;
|
||||
};
|
||||
|
||||
struct SftpRename : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpRename> Ptr;
|
||||
|
||||
SftpRename(SftpJobId jobId, const QString &oldPath, const QString &newPath);
|
||||
virtual Type type() const { return Rename; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QString oldPath;
|
||||
const QString newPath;
|
||||
};
|
||||
|
||||
struct SftpCreateLink : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<SftpCreateLink> Ptr;
|
||||
|
||||
SftpCreateLink(SftpJobId jobId, const QString &filePath, const QString &target);
|
||||
virtual Type type() const { return CreateLink; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QString filePath;
|
||||
const QString target;
|
||||
};
|
||||
|
||||
|
||||
struct AbstractSftpOperationWithHandle : public AbstractSftpOperation
|
||||
{
|
||||
typedef QSharedPointer<AbstractSftpOperationWithHandle> Ptr;
|
||||
enum State { Inactive, OpenRequested, Open, CloseRequested };
|
||||
|
||||
AbstractSftpOperationWithHandle(SftpJobId jobId, const QString &remotePath);
|
||||
~AbstractSftpOperationWithHandle();
|
||||
|
||||
const QString remotePath;
|
||||
QByteArray remoteHandle;
|
||||
State state;
|
||||
bool hasError;
|
||||
};
|
||||
|
||||
|
||||
struct SftpListDir : public AbstractSftpOperationWithHandle
|
||||
{
|
||||
typedef QSharedPointer<SftpListDir> Ptr;
|
||||
|
||||
SftpListDir(SftpJobId jobId, const QString &path);
|
||||
virtual Type type() const { return ListDir; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
};
|
||||
|
||||
|
||||
struct SftpCreateFile : public AbstractSftpOperationWithHandle
|
||||
{
|
||||
typedef QSharedPointer<SftpCreateFile> Ptr;
|
||||
|
||||
SftpCreateFile(SftpJobId jobId, const QString &path, SftpOverwriteMode mode);
|
||||
virtual Type type() const { return CreateFile; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const SftpOverwriteMode mode;
|
||||
};
|
||||
|
||||
struct AbstractSftpTransfer : public AbstractSftpOperationWithHandle
|
||||
{
|
||||
typedef QSharedPointer<AbstractSftpTransfer> Ptr;
|
||||
|
||||
AbstractSftpTransfer(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile);
|
||||
~AbstractSftpTransfer();
|
||||
void calculateInFlightCount(quint32 chunkSize);
|
||||
|
||||
static const int MaxInFlightCount;
|
||||
|
||||
const QSharedPointer<QFile> localFile;
|
||||
quint64 fileSize;
|
||||
quint64 offset;
|
||||
int inFlightCount;
|
||||
bool statRequested;
|
||||
};
|
||||
|
||||
struct SftpDownload : public AbstractSftpTransfer
|
||||
{
|
||||
typedef QSharedPointer<SftpDownload> Ptr;
|
||||
SftpDownload(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile);
|
||||
virtual Type type() const { return Download; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
QMap<quint32, quint64> offsets;
|
||||
SftpJobId eofId;
|
||||
};
|
||||
|
||||
struct SftpUploadFile : public AbstractSftpTransfer
|
||||
{
|
||||
typedef QSharedPointer<SftpUploadFile> Ptr;
|
||||
|
||||
SftpUploadFile(SftpJobId jobId, const QString &remotePath,
|
||||
const QSharedPointer<QFile> &localFile, SftpOverwriteMode mode,
|
||||
const QSharedPointer<SftpUploadDir> &parentJob = QSharedPointer<SftpUploadDir>());
|
||||
virtual Type type() const { return UploadFile; }
|
||||
virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
|
||||
|
||||
const QSharedPointer<SftpUploadDir> parentJob;
|
||||
SftpOverwriteMode mode;
|
||||
};
|
||||
|
||||
// Composite operation.
|
||||
struct SftpUploadDir
|
||||
{
|
||||
typedef QSharedPointer<SftpUploadDir> Ptr;
|
||||
|
||||
struct Dir {
|
||||
Dir(const QString &l, const QString &r) : localDir(l), remoteDir(r) {}
|
||||
QString localDir;
|
||||
QString remoteDir;
|
||||
};
|
||||
|
||||
SftpUploadDir(SftpJobId jobId) : jobId(jobId), hasError(false) {}
|
||||
~SftpUploadDir();
|
||||
|
||||
void setError()
|
||||
{
|
||||
hasError = true;
|
||||
uploadsInProgress.clear();
|
||||
mkdirsInProgress.clear();
|
||||
}
|
||||
|
||||
const SftpJobId jobId;
|
||||
bool hasError;
|
||||
QList<SftpUploadFile::Ptr> uploadsInProgress;
|
||||
QMap<SftpMakeDir::Ptr, Dir> mkdirsInProgress;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
220
client/3rd/QtSsh/src/ssh/sftpoutgoingpacket.cpp
Executable file
220
client/3rd/QtSsh/src/ssh/sftpoutgoingpacket.cpp
Executable file
@@ -0,0 +1,220 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftpoutgoingpacket_p.h"
|
||||
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshpacket_p.h"
|
||||
|
||||
#include <QtEndian>
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
namespace {
|
||||
const quint32 DefaultAttributes = 0;
|
||||
const quint32 SSH_FXF_READ = 0x00000001;
|
||||
const quint32 SSH_FXF_WRITE = 0x00000002;
|
||||
const quint32 SSH_FXF_APPEND = 0x00000004;
|
||||
const quint32 SSH_FXF_CREAT = 0x00000008;
|
||||
const quint32 SSH_FXF_TRUNC = 0x00000010;
|
||||
const quint32 SSH_FXF_EXCL = 0x00000020;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket::SftpOutgoingPacket()
|
||||
{
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateInit(quint32 version)
|
||||
{
|
||||
return init(SSH_FXP_INIT, 0).appendInt(version).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateStat(const QString &path, quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_LSTAT, requestId).appendString(path).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateOpenDir(const QString &path,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_OPENDIR, requestId).appendString(path).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateReadDir(const QByteArray &handle,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_READDIR, requestId).appendString(handle).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateCloseHandle(const QByteArray &handle,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_CLOSE, requestId).appendString(handle).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateMkDir(const QString &path,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_MKDIR, requestId).appendString(path)
|
||||
.appendInt(DefaultAttributes).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateRmDir(const QString &path,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_RMDIR, requestId).appendString(path).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateRm(const QString &path,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_REMOVE, requestId).appendString(path).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateRename(const QString &oldPath,
|
||||
const QString &newPath, quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_RENAME, requestId).appendString(oldPath)
|
||||
.appendString(newPath).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateOpenFileForWriting(const QString &path,
|
||||
SftpOverwriteMode mode, quint32 permissions, quint32 requestId)
|
||||
{
|
||||
QList<quint32> attributes;
|
||||
if (permissions != DefaultPermissions)
|
||||
attributes << SSH_FILEXFER_ATTR_PERMISSIONS << permissions;
|
||||
else
|
||||
attributes << DefaultAttributes;
|
||||
return generateOpenFile(path, Write, mode, attributes, requestId);
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateOpenFileForReading(const QString &path,
|
||||
quint32 requestId)
|
||||
{
|
||||
// Note: Overwrite mode is irrelevant and will be ignored.
|
||||
return generateOpenFile(path, Read, SftpSkipExisting, QList<quint32>() << DefaultAttributes,
|
||||
requestId);
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateReadFile(const QByteArray &handle,
|
||||
quint64 offset, quint32 length, quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_READ, requestId).appendString(handle).appendInt64(offset)
|
||||
.appendInt(length).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateFstat(const QByteArray &handle,
|
||||
quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_FSTAT, requestId).appendString(handle).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateWriteFile(const QByteArray &handle,
|
||||
quint64 offset, const QByteArray &data, quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_WRITE, requestId).appendString(handle)
|
||||
.appendInt64(offset).appendString(data).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateCreateLink(const QString &filePath,
|
||||
const QString &target, quint32 requestId)
|
||||
{
|
||||
return init(SSH_FXP_SYMLINK, requestId).appendString(filePath).appendString(target).finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::generateOpenFile(const QString &path,
|
||||
OpenType openType, SftpOverwriteMode mode, const QList<quint32> &attributes, quint32 requestId)
|
||||
{
|
||||
quint32 pFlags = 0;
|
||||
switch (openType) {
|
||||
case Read:
|
||||
pFlags = SSH_FXF_READ;
|
||||
break;
|
||||
case Write:
|
||||
pFlags = SSH_FXF_WRITE | SSH_FXF_CREAT;
|
||||
switch (mode) {
|
||||
case SftpOverwriteExisting: pFlags |= SSH_FXF_TRUNC; break;
|
||||
case SftpAppendToExisting: pFlags |= SSH_FXF_APPEND; break;
|
||||
case SftpSkipExisting: pFlags |= SSH_FXF_EXCL; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
init(SSH_FXP_OPEN, requestId).appendString(path).appendInt(pFlags);
|
||||
foreach (const quint32 attribute, attributes)
|
||||
appendInt(attribute);
|
||||
return finalize();
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::init(SftpPacketType type,
|
||||
quint32 requestId)
|
||||
{
|
||||
m_data.resize(TypeOffset + 1);
|
||||
m_data[TypeOffset] = type;
|
||||
if (type != SSH_FXP_INIT) {
|
||||
appendInt(requestId);
|
||||
qCDebug(sshLog, "Generating SFTP packet of type %d with request id %u", type, requestId);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::appendInt(quint32 val)
|
||||
{
|
||||
m_data.append(AbstractSshPacket::encodeInt(val));
|
||||
return *this;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::appendInt64(quint64 value)
|
||||
{
|
||||
m_data.append(AbstractSshPacket::encodeInt(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::appendString(const QString &string)
|
||||
{
|
||||
m_data.append(AbstractSshPacket::encodeString(string.toUtf8()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::appendString(const QByteArray &string)
|
||||
{
|
||||
m_data += AbstractSshPacket::encodeString(string);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SftpOutgoingPacket &SftpOutgoingPacket::finalize()
|
||||
{
|
||||
AbstractSshPacket::setLengthField(m_data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const quint32 SftpOutgoingPacket::DefaultPermissions = std::numeric_limits<quint32>::max();
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
84
client/3rd/QtSsh/src/ssh/sftpoutgoingpacket_p.h
Executable file
84
client/3rd/QtSsh/src/ssh/sftpoutgoingpacket_p.h
Executable file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sftppacket_p.h"
|
||||
#include "sftpdefs.h"
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
class SftpOutgoingPacket : public AbstractSftpPacket
|
||||
{
|
||||
public:
|
||||
SftpOutgoingPacket();
|
||||
SftpOutgoingPacket &generateInit(quint32 version);
|
||||
SftpOutgoingPacket &generateStat(const QString &path, quint32 requestId);
|
||||
SftpOutgoingPacket &generateOpenDir(const QString &path, quint32 requestId);
|
||||
SftpOutgoingPacket &generateReadDir(const QByteArray &handle,
|
||||
quint32 requestId);
|
||||
SftpOutgoingPacket &generateCloseHandle(const QByteArray &handle,
|
||||
quint32 requestId);
|
||||
SftpOutgoingPacket &generateMkDir(const QString &path, quint32 requestId);
|
||||
SftpOutgoingPacket &generateRmDir(const QString &path, quint32 requestId);
|
||||
SftpOutgoingPacket &generateRm(const QString &path, quint32 requestId);
|
||||
SftpOutgoingPacket &generateRename(const QString &oldPath,
|
||||
const QString &newPath, quint32 requestId);
|
||||
SftpOutgoingPacket &generateOpenFileForWriting(const QString &path,
|
||||
SftpOverwriteMode mode, quint32 permissions, quint32 requestId);
|
||||
SftpOutgoingPacket &generateOpenFileForReading(const QString &path,
|
||||
quint32 requestId);
|
||||
SftpOutgoingPacket &generateReadFile(const QByteArray &handle,
|
||||
quint64 offset, quint32 length, quint32 requestId);
|
||||
SftpOutgoingPacket &generateFstat(const QByteArray &handle,
|
||||
quint32 requestId);
|
||||
SftpOutgoingPacket &generateWriteFile(const QByteArray &handle,
|
||||
quint64 offset, const QByteArray &data, quint32 requestId);
|
||||
|
||||
// Note: OpenSSH's SFTP server has a bug that reverses the filePath and target
|
||||
// arguments, so this operation is not portable.
|
||||
SftpOutgoingPacket &generateCreateLink(const QString &filePath, const QString &target,
|
||||
quint32 requestId);
|
||||
|
||||
static const quint32 DefaultPermissions;
|
||||
|
||||
private:
|
||||
static QByteArray encodeString(const QString &string);
|
||||
|
||||
enum OpenType { Read, Write };
|
||||
SftpOutgoingPacket &generateOpenFile(const QString &path, OpenType openType,
|
||||
SftpOverwriteMode mode, const QList<quint32> &attributes, quint32 requestId);
|
||||
|
||||
SftpOutgoingPacket &init(SftpPacketType type, quint32 requestId);
|
||||
SftpOutgoingPacket &appendInt(quint32 value);
|
||||
SftpOutgoingPacket &appendInt64(quint64 value);
|
||||
SftpOutgoingPacket &appendString(const QString &string);
|
||||
SftpOutgoingPacket &appendString(const QByteArray &string);
|
||||
SftpOutgoingPacket &finalize();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
49
client/3rd/QtSsh/src/ssh/sftppacket.cpp
Executable file
49
client/3rd/QtSsh/src/ssh/sftppacket.cpp
Executable file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sftppacket_p.h"
|
||||
|
||||
#include "sshpacketparser_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
const quint32 AbstractSftpPacket::MaxDataSize = 32000;
|
||||
const quint32 AbstractSftpPacket::MaxPacketSize = 34000;
|
||||
const int AbstractSftpPacket::TypeOffset = 4;
|
||||
const int AbstractSftpPacket::RequestIdOffset = TypeOffset + 1;
|
||||
const int AbstractSftpPacket::PayloadOffset = RequestIdOffset + 4;
|
||||
|
||||
AbstractSftpPacket::AbstractSftpPacket()
|
||||
{
|
||||
}
|
||||
|
||||
quint32 AbstractSftpPacket::requestId() const
|
||||
{
|
||||
return SshPacketParser::asUint32(m_data, RequestIdOffset);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
109
client/3rd/QtSsh/src/ssh/sftppacket_p.h
Executable file
109
client/3rd/QtSsh/src/ssh/sftppacket_p.h
Executable file
@@ -0,0 +1,109 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
enum SftpPacketType {
|
||||
SSH_FXP_INIT = 1,
|
||||
SSH_FXP_VERSION = 2,
|
||||
SSH_FXP_OPEN = 3,
|
||||
SSH_FXP_CLOSE = 4,
|
||||
SSH_FXP_READ = 5,
|
||||
SSH_FXP_WRITE = 6,
|
||||
SSH_FXP_LSTAT = 7,
|
||||
SSH_FXP_FSTAT = 8,
|
||||
SSH_FXP_SETSTAT = 9,
|
||||
SSH_FXP_FSETSTAT = 10,
|
||||
SSH_FXP_OPENDIR = 11,
|
||||
SSH_FXP_READDIR = 12,
|
||||
SSH_FXP_REMOVE = 13,
|
||||
SSH_FXP_MKDIR = 14,
|
||||
SSH_FXP_RMDIR = 15,
|
||||
SSH_FXP_REALPATH = 16,
|
||||
SSH_FXP_STAT = 17,
|
||||
SSH_FXP_RENAME = 18,
|
||||
SSH_FXP_READLINK = 19,
|
||||
SSH_FXP_SYMLINK = 20, // Removed from later protocol versions. Try not to use.
|
||||
|
||||
SSH_FXP_STATUS = 101,
|
||||
SSH_FXP_HANDLE = 102,
|
||||
SSH_FXP_DATA = 103,
|
||||
SSH_FXP_NAME = 104,
|
||||
SSH_FXP_ATTRS = 105,
|
||||
|
||||
SSH_FXP_EXTENDED = 200,
|
||||
SSH_FXP_EXTENDED_REPLY = 201
|
||||
};
|
||||
|
||||
enum SftpStatusCode {
|
||||
SSH_FX_OK = 0,
|
||||
SSH_FX_EOF = 1,
|
||||
SSH_FX_NO_SUCH_FILE = 2,
|
||||
SSH_FX_PERMISSION_DENIED = 3,
|
||||
SSH_FX_FAILURE = 4,
|
||||
SSH_FX_BAD_MESSAGE = 5,
|
||||
SSH_FX_NO_CONNECTION = 6,
|
||||
SSH_FX_CONNECTION_LOST = 7,
|
||||
SSH_FX_OP_UNSUPPORTED = 8
|
||||
};
|
||||
|
||||
enum SftpAttributeType {
|
||||
SSH_FILEXFER_ATTR_SIZE = 0x00000001,
|
||||
SSH_FILEXFER_ATTR_UIDGID = 0x00000002,
|
||||
SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004,
|
||||
SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008,
|
||||
SSH_FILEXFER_ATTR_EXTENDED = 0x80000000
|
||||
};
|
||||
|
||||
class AbstractSftpPacket
|
||||
{
|
||||
public:
|
||||
AbstractSftpPacket();
|
||||
quint32 requestId() const;
|
||||
const QByteArray &rawData() const { return m_data; }
|
||||
SftpPacketType type() const { return static_cast<SftpPacketType>(m_data.at(TypeOffset)); }
|
||||
|
||||
static const quint32 MaxDataSize; // "Pure" data size per read/writepacket.
|
||||
static const quint32 MaxPacketSize;
|
||||
|
||||
protected:
|
||||
quint32 dataSize() const { return static_cast<quint32>(m_data.size()); }
|
||||
|
||||
static const int TypeOffset;
|
||||
static const int RequestIdOffset;
|
||||
static const int PayloadOffset;
|
||||
|
||||
QByteArray m_data;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
81
client/3rd/QtSsh/src/ssh/ssh.pri
Executable file
81
client/3rd/QtSsh/src/ssh/ssh.pri
Executable file
@@ -0,0 +1,81 @@
|
||||
QT += gui network widgets
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
SOURCES += $$PWD/sshsendfacility.cpp \
|
||||
$$PWD/sshremoteprocess.cpp \
|
||||
$$PWD/sshpacketparser.cpp \
|
||||
$$PWD/sshpacket.cpp \
|
||||
$$PWD/sshoutgoingpacket.cpp \
|
||||
$$PWD/sshkeygenerator.cpp \
|
||||
$$PWD/sshkeyexchange.cpp \
|
||||
$$PWD/sshincomingpacket.cpp \
|
||||
$$PWD/sshcryptofacility.cpp \
|
||||
$$PWD/sshconnection.cpp \
|
||||
$$PWD/sshchannelmanager.cpp \
|
||||
$$PWD/sshchannel.cpp \
|
||||
$$PWD/sshcapabilities.cpp \
|
||||
$$PWD/sftppacket.cpp \
|
||||
$$PWD/sftpoutgoingpacket.cpp \
|
||||
$$PWD/sftpoperation.cpp \
|
||||
$$PWD/sftpincomingpacket.cpp \
|
||||
$$PWD/sftpdefs.cpp \
|
||||
$$PWD/sftpchannel.cpp \
|
||||
$$PWD/sshremoteprocessrunner.cpp \
|
||||
$$PWD/sshconnectionmanager.cpp \
|
||||
$$PWD/sshkeypasswordretriever.cpp \
|
||||
$$PWD/sftpfilesystemmodel.cpp \
|
||||
$$PWD/sshkeycreationdialog.cpp \
|
||||
$$PWD/sshinit.cpp \
|
||||
$$PWD/sshdirecttcpiptunnel.cpp \
|
||||
$$PWD/sshlogging.cpp \
|
||||
$$PWD/sshhostkeydatabase.cpp \
|
||||
$$PWD/sshtcpipforwardserver.cpp \
|
||||
$$PWD/sshtcpiptunnel.cpp \
|
||||
$$PWD/sshforwardedtcpiptunnel.cpp
|
||||
|
||||
HEADERS += $$PWD/sshsendfacility_p.h \
|
||||
$$PWD/sshremoteprocess.h \
|
||||
$$PWD/sshremoteprocess_p.h \
|
||||
$$PWD/sshpacketparser_p.h \
|
||||
$$PWD/sshpacket_p.h \
|
||||
$$PWD/sshoutgoingpacket_p.h \
|
||||
$$PWD/sshkeygenerator.h \
|
||||
$$PWD/sshkeyexchange_p.h \
|
||||
$$PWD/sshincomingpacket_p.h \
|
||||
$$PWD/sshexception_p.h \
|
||||
$$PWD/ssherrors.h \
|
||||
$$PWD/sshcryptofacility_p.h \
|
||||
$$PWD/sshconnection.h \
|
||||
$$PWD/sshconnection_p.h \
|
||||
$$PWD/sshchannelmanager_p.h \
|
||||
$$PWD/sshchannel_p.h \
|
||||
$$PWD/sshcapabilities_p.h \
|
||||
$$PWD/sshbotanconversions_p.h \
|
||||
$$PWD/sftppacket_p.h \
|
||||
$$PWD/sftpoutgoingpacket_p.h \
|
||||
$$PWD/sftpoperation_p.h \
|
||||
$$PWD/sftpincomingpacket_p.h \
|
||||
$$PWD/sftpdefs.h \
|
||||
$$PWD/sftpchannel.h \
|
||||
$$PWD/sftpchannel_p.h \
|
||||
$$PWD/sshremoteprocessrunner.h \
|
||||
$$PWD/sshconnectionmanager.h \
|
||||
$$PWD/sshpseudoterminal.h \
|
||||
$$PWD/sshkeypasswordretriever_p.h \
|
||||
$$PWD/sftpfilesystemmodel.h \
|
||||
$$PWD/sshkeycreationdialog.h \
|
||||
$$PWD/ssh_global.h \
|
||||
$$PWD/sshdirecttcpiptunnel_p.h \
|
||||
$$PWD/sshinit_p.h \
|
||||
$$PWD/sshdirecttcpiptunnel.h \
|
||||
$$PWD/sshlogging_p.h \
|
||||
$$PWD/sshhostkeydatabase.h \
|
||||
$$PWD/sshtcpipforwardserver.h \
|
||||
$$PWD/sshtcpipforwardserver_p.h \
|
||||
$$PWD/sshtcpiptunnel_p.h \
|
||||
$$PWD/sshforwardedtcpiptunnel.h \
|
||||
$$PWD/sshforwardedtcpiptunnel_p.h
|
||||
|
||||
FORMS += $$PWD/sshkeycreationdialog.ui
|
||||
8
client/3rd/QtSsh/src/ssh/ssh.pro
Executable file
8
client/3rd/QtSsh/src/ssh/ssh.pro
Executable file
@@ -0,0 +1,8 @@
|
||||
TARGET = QtSsh
|
||||
|
||||
load(qt_module)
|
||||
|
||||
DEFINES += QTCSSH_LIBRARY
|
||||
|
||||
include($$PWD/ssh.pri)
|
||||
include($$PWD/../botan/botan.pri)
|
||||
1
client/3rd/QtSsh/src/ssh/ssh_dependencies.pri
Executable file
1
client/3rd/QtSsh/src/ssh/ssh_dependencies.pri
Executable file
@@ -0,0 +1 @@
|
||||
QTC_LIB_NAME = QtcSsh
|
||||
41
client/3rd/QtSsh/src/ssh/ssh_global.h
Executable file
41
client/3rd/QtSsh/src/ssh/ssh_global.h
Executable file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
//#if defined(QTCSSH_LIBRARY)
|
||||
//# define QSSH_EXPORT Q_DECL_EXPORT
|
||||
//#else
|
||||
//# define QSSH_EXPORT Q_DECL_IMPORT
|
||||
//#endif
|
||||
|
||||
#define QSSH_EXPORT
|
||||
|
||||
#define QSSH_PRINT_WARNING qWarning("Soft assert at %s:%d", __FILE__, __LINE__)
|
||||
#define QSSH_ASSERT(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; } } while (false)
|
||||
#define QSSH_ASSERT_AND_RETURN(cond) do { if (!(cond)) { QSSH_PRINT_WARNING; return; } } while (false)
|
||||
#define QSSH_ASSERT_AND_RETURN_VALUE(cond, value) do { if (!(cond)) { QSSH_PRINT_WARNING; return value; } } while (false)
|
||||
132
client/3rd/QtSsh/src/ssh/sshbotanconversions_p.h
Executable file
132
client/3rd/QtSsh/src/ssh/sshbotanconversions_p.h
Executable file
@@ -0,0 +1,132 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sshcapabilities_p.h"
|
||||
#include "sshexception_p.h"
|
||||
|
||||
#include <botan/botan.h>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
inline const Botan::byte *convertByteArray(const QByteArray &a)
|
||||
{
|
||||
return reinterpret_cast<const Botan::byte *>(a.constData());
|
||||
}
|
||||
|
||||
inline Botan::byte *convertByteArray(QByteArray &a)
|
||||
{
|
||||
return reinterpret_cast<Botan::byte *>(a.data());
|
||||
}
|
||||
|
||||
inline QByteArray convertByteArray(const Botan::SecureVector<Botan::byte> &v)
|
||||
{
|
||||
return QByteArray(reinterpret_cast<const char *>(v.begin()), static_cast<int>(v.size()));
|
||||
}
|
||||
|
||||
inline const char *botanKeyExchangeAlgoName(const QByteArray &rfcAlgoName)
|
||||
{
|
||||
if (rfcAlgoName == SshCapabilities::DiffieHellmanGroup1Sha1)
|
||||
return "modp/ietf/1024";
|
||||
if (rfcAlgoName == SshCapabilities::DiffieHellmanGroup14Sha1)
|
||||
return "modp/ietf/2048";
|
||||
if (rfcAlgoName == SshCapabilities::EcdhNistp256)
|
||||
return "secp256r1";
|
||||
if (rfcAlgoName == SshCapabilities::EcdhNistp384)
|
||||
return "secp384r1";
|
||||
if (rfcAlgoName == SshCapabilities::EcdhNistp521)
|
||||
return "secp521r1";
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected key exchange algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(rfcAlgoName)));
|
||||
}
|
||||
|
||||
inline const char *botanCryptAlgoName(const QByteArray &rfcAlgoName)
|
||||
{
|
||||
if (rfcAlgoName == SshCapabilities::CryptAlgoAes128Cbc
|
||||
|| rfcAlgoName == SshCapabilities::CryptAlgoAes128Ctr) {
|
||||
return "AES-128";
|
||||
}
|
||||
if (rfcAlgoName == SshCapabilities::CryptAlgo3DesCbc
|
||||
|| rfcAlgoName == SshCapabilities::CryptAlgo3DesCtr) {
|
||||
return "TripleDES";
|
||||
}
|
||||
if (rfcAlgoName == SshCapabilities::CryptAlgoAes192Ctr) {
|
||||
return "AES-192";
|
||||
}
|
||||
if (rfcAlgoName == SshCapabilities::CryptAlgoAes256Ctr) {
|
||||
return "AES-256";
|
||||
}
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected cipher \"%1\"")
|
||||
.arg(QString::fromLatin1(rfcAlgoName)));
|
||||
}
|
||||
|
||||
inline const char *botanEmsaAlgoName(const QByteArray &rfcAlgoName)
|
||||
{
|
||||
if (rfcAlgoName == SshCapabilities::PubKeyDss)
|
||||
return "EMSA1(SHA-1)";
|
||||
if (rfcAlgoName == SshCapabilities::PubKeyRsa)
|
||||
return "EMSA3(SHA-1)";
|
||||
if (rfcAlgoName == SshCapabilities::PubKeyEcdsa256)
|
||||
return "EMSA1_BSI(SHA-256)";
|
||||
if (rfcAlgoName == SshCapabilities::PubKeyEcdsa384)
|
||||
return "EMSA1_BSI(SHA-384)";
|
||||
if (rfcAlgoName == SshCapabilities::PubKeyEcdsa521)
|
||||
return "EMSA1_BSI(SHA-512)";
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected host key algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(rfcAlgoName)));
|
||||
}
|
||||
|
||||
inline const char *botanHMacAlgoName(const QByteArray &rfcAlgoName)
|
||||
{
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha1)
|
||||
return "SHA-1";
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha256)
|
||||
return "SHA-256";
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha384)
|
||||
return "SHA-384";
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha512)
|
||||
return "SHA-512";
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected hashing algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(rfcAlgoName)));
|
||||
}
|
||||
|
||||
inline quint32 botanHMacKeyLen(const QByteArray &rfcAlgoName)
|
||||
{
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha1)
|
||||
return 20;
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha256)
|
||||
return 32;
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha384)
|
||||
return 48;
|
||||
if (rfcAlgoName == SshCapabilities::HMacSha512)
|
||||
return 64;
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected hashing algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(rfcAlgoName)));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
170
client/3rd/QtSsh/src/ssh/sshcapabilities.cpp
Executable file
170
client/3rd/QtSsh/src/ssh/sshcapabilities.cpp
Executable file
@@ -0,0 +1,170 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshcapabilities_p.h"
|
||||
|
||||
#include "sshexception_p.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
namespace {
|
||||
QByteArray listAsByteArray(const QList<QByteArray> &list)
|
||||
{
|
||||
QByteArray array;
|
||||
foreach (const QByteArray &elem, list)
|
||||
array += elem + ',';
|
||||
if (!array.isEmpty())
|
||||
array.remove(array.count() - 1, 1);
|
||||
return array;
|
||||
}
|
||||
} // anonymous namspace
|
||||
|
||||
const QByteArray SshCapabilities::DiffieHellmanGroup1Sha1("diffie-hellman-group1-sha1");
|
||||
const QByteArray SshCapabilities::DiffieHellmanGroup14Sha1("diffie-hellman-group14-sha1");
|
||||
const QByteArray SshCapabilities::EcdhKexNamePrefix("ecdh-sha2-nistp");
|
||||
const QByteArray SshCapabilities::EcdhNistp256 = EcdhKexNamePrefix + "256";
|
||||
const QByteArray SshCapabilities::EcdhNistp384 = EcdhKexNamePrefix + "384";
|
||||
const QByteArray SshCapabilities::EcdhNistp521 = EcdhKexNamePrefix + "521";
|
||||
const QList<QByteArray> SshCapabilities::KeyExchangeMethods = QList<QByteArray>()
|
||||
<< SshCapabilities::EcdhNistp256
|
||||
<< SshCapabilities::EcdhNistp384
|
||||
<< SshCapabilities::EcdhNistp521
|
||||
<< SshCapabilities::DiffieHellmanGroup1Sha1
|
||||
<< SshCapabilities::DiffieHellmanGroup14Sha1;
|
||||
|
||||
const QByteArray SshCapabilities::PubKeyDss("ssh-dss");
|
||||
const QByteArray SshCapabilities::PubKeyRsa("ssh-rsa");
|
||||
const QByteArray SshCapabilities::PubKeyEcdsaPrefix("ecdsa-sha2-nistp");
|
||||
const QByteArray SshCapabilities::PubKeyEcdsa256 = SshCapabilities::PubKeyEcdsaPrefix + "256";
|
||||
const QByteArray SshCapabilities::PubKeyEcdsa384 = SshCapabilities::PubKeyEcdsaPrefix + "384";
|
||||
const QByteArray SshCapabilities::PubKeyEcdsa521 = SshCapabilities::PubKeyEcdsaPrefix + "521";
|
||||
const QList<QByteArray> SshCapabilities::PublicKeyAlgorithms = QList<QByteArray>()
|
||||
<< SshCapabilities::PubKeyEcdsa256
|
||||
<< SshCapabilities::PubKeyEcdsa384
|
||||
<< SshCapabilities::PubKeyEcdsa521
|
||||
<< SshCapabilities::PubKeyRsa
|
||||
<< SshCapabilities::PubKeyDss;
|
||||
|
||||
const QByteArray SshCapabilities::CryptAlgo3DesCbc("3des-cbc");
|
||||
const QByteArray SshCapabilities::CryptAlgo3DesCtr("3des-ctr");
|
||||
const QByteArray SshCapabilities::CryptAlgoAes128Cbc("aes128-cbc");
|
||||
const QByteArray SshCapabilities::CryptAlgoAes128Ctr("aes128-ctr");
|
||||
const QByteArray SshCapabilities::CryptAlgoAes192Ctr("aes192-ctr");
|
||||
const QByteArray SshCapabilities::CryptAlgoAes256Ctr("aes256-ctr");
|
||||
const QList<QByteArray> SshCapabilities::EncryptionAlgorithms
|
||||
= QList<QByteArray>() << SshCapabilities::CryptAlgoAes256Ctr
|
||||
<< SshCapabilities::CryptAlgoAes192Ctr
|
||||
<< SshCapabilities::CryptAlgoAes128Ctr
|
||||
<< SshCapabilities::CryptAlgo3DesCtr
|
||||
<< SshCapabilities::CryptAlgoAes128Cbc
|
||||
<< SshCapabilities::CryptAlgo3DesCbc;
|
||||
|
||||
const QByteArray SshCapabilities::HMacSha1("hmac-sha1");
|
||||
const QByteArray SshCapabilities::HMacSha196("hmac-sha1-96");
|
||||
const QByteArray SshCapabilities::HMacSha256("hmac-sha2-256");
|
||||
const QByteArray SshCapabilities::HMacSha384("hmac-sha2-384");
|
||||
const QByteArray SshCapabilities::HMacSha512("hmac-sha2-512");
|
||||
const QList<QByteArray> SshCapabilities::MacAlgorithms
|
||||
= QList<QByteArray>() /* << SshCapabilities::HMacSha196 */
|
||||
<< SshCapabilities::HMacSha256
|
||||
<< SshCapabilities::HMacSha384
|
||||
<< SshCapabilities::HMacSha512
|
||||
<< SshCapabilities::HMacSha1;
|
||||
|
||||
const QList<QByteArray> SshCapabilities::CompressionAlgorithms
|
||||
= QList<QByteArray>() << "none";
|
||||
|
||||
const QByteArray SshCapabilities::SshConnectionService("ssh-connection");
|
||||
|
||||
QList<QByteArray> SshCapabilities::commonCapabilities(const QList<QByteArray> &myCapabilities,
|
||||
const QList<QByteArray> &serverCapabilities)
|
||||
{
|
||||
QList<QByteArray> capabilities;
|
||||
foreach (const QByteArray &myCapability, myCapabilities) {
|
||||
if (serverCapabilities.contains(myCapability))
|
||||
capabilities << myCapability;
|
||||
}
|
||||
|
||||
if (!capabilities.isEmpty())
|
||||
return capabilities;
|
||||
|
||||
throw SshServerException(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
|
||||
"Server and client capabilities do not match.",
|
||||
QCoreApplication::translate("SshConnection",
|
||||
"Server and client capabilities don't match. "
|
||||
"Client list was: %1.\nServer list was %2.")
|
||||
.arg(QString::fromLocal8Bit(listAsByteArray(myCapabilities).data()))
|
||||
.arg(QString::fromLocal8Bit(listAsByteArray(serverCapabilities).data())));
|
||||
|
||||
}
|
||||
|
||||
QByteArray SshCapabilities::findBestMatch(const QList<QByteArray> &myCapabilities,
|
||||
const QList<QByteArray> &serverCapabilities)
|
||||
{
|
||||
return commonCapabilities(myCapabilities, serverCapabilities).first();
|
||||
}
|
||||
|
||||
int SshCapabilities::ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo)
|
||||
{
|
||||
if (ecdsaAlgo == PubKeyEcdsa256)
|
||||
return 32;
|
||||
if (ecdsaAlgo == PubKeyEcdsa384)
|
||||
return 48;
|
||||
if (ecdsaAlgo == PubKeyEcdsa521)
|
||||
return 66;
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected ecdsa algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(ecdsaAlgo)));
|
||||
}
|
||||
|
||||
QByteArray SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(int keyWidthInBytes)
|
||||
{
|
||||
if (keyWidthInBytes <= 32)
|
||||
return PubKeyEcdsa256;
|
||||
if (keyWidthInBytes <= 48)
|
||||
return PubKeyEcdsa384;
|
||||
if (keyWidthInBytes <= 66)
|
||||
return PubKeyEcdsa521;
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected ecdsa key size (%1 bytes)")
|
||||
.arg(keyWidthInBytes));
|
||||
}
|
||||
|
||||
const char *SshCapabilities::oid(const QByteArray &ecdsaAlgo)
|
||||
{
|
||||
if (ecdsaAlgo == PubKeyEcdsa256)
|
||||
return "secp256r1";
|
||||
if (ecdsaAlgo == PubKeyEcdsa384)
|
||||
return "secp384r1";
|
||||
if (ecdsaAlgo == PubKeyEcdsa521)
|
||||
return "secp521r1";
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected ecdsa algorithm \"%1\"")
|
||||
.arg(QString::fromLatin1(ecdsaAlgo)));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
83
client/3rd/QtSsh/src/ssh/sshcapabilities_p.h
Executable file
83
client/3rd/QtSsh/src/ssh/sshcapabilities_p.h
Executable file
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
class SshCapabilities
|
||||
{
|
||||
public:
|
||||
static const QByteArray DiffieHellmanGroup1Sha1;
|
||||
static const QByteArray DiffieHellmanGroup14Sha1;
|
||||
static const QByteArray EcdhKexNamePrefix;
|
||||
static const QByteArray EcdhNistp256;
|
||||
static const QByteArray EcdhNistp384;
|
||||
static const QByteArray EcdhNistp521; // sic
|
||||
static const QList<QByteArray> KeyExchangeMethods;
|
||||
|
||||
static const QByteArray PubKeyDss;
|
||||
static const QByteArray PubKeyRsa;
|
||||
static const QByteArray PubKeyEcdsaPrefix;
|
||||
static const QByteArray PubKeyEcdsa256;
|
||||
static const QByteArray PubKeyEcdsa384;
|
||||
static const QByteArray PubKeyEcdsa521;
|
||||
static const QList<QByteArray> PublicKeyAlgorithms;
|
||||
|
||||
static const QByteArray CryptAlgo3DesCbc;
|
||||
static const QByteArray CryptAlgo3DesCtr;
|
||||
static const QByteArray CryptAlgoAes128Cbc;
|
||||
static const QByteArray CryptAlgoAes128Ctr;
|
||||
static const QByteArray CryptAlgoAes192Ctr;
|
||||
static const QByteArray CryptAlgoAes256Ctr;
|
||||
static const QList<QByteArray> EncryptionAlgorithms;
|
||||
|
||||
static const QByteArray HMacSha1;
|
||||
static const QByteArray HMacSha196;
|
||||
static const QByteArray HMacSha256;
|
||||
static const QByteArray HMacSha384;
|
||||
static const QByteArray HMacSha512;
|
||||
static const QList<QByteArray> MacAlgorithms;
|
||||
|
||||
static const QList<QByteArray> CompressionAlgorithms;
|
||||
|
||||
static const QByteArray SshConnectionService;
|
||||
|
||||
static QList<QByteArray> commonCapabilities(const QList<QByteArray> &myCapabilities,
|
||||
const QList<QByteArray> &serverCapabilities);
|
||||
static QByteArray findBestMatch(const QList<QByteArray> &myCapabilities,
|
||||
const QList<QByteArray> &serverCapabilities);
|
||||
|
||||
static int ecdsaIntegerWidthInBytes(const QByteArray &ecdsaAlgo);
|
||||
static QByteArray ecdsaPubKeyAlgoForKeyWidth(int keyWidthInBytes);
|
||||
static const char *oid(const QByteArray &ecdsaAlgo);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
280
client/3rd/QtSsh/src/ssh/sshchannel.cpp
Executable file
280
client/3rd/QtSsh/src/ssh/sshchannel.cpp
Executable file
@@ -0,0 +1,280 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshchannel_p.h"
|
||||
|
||||
#include "sshincomingpacket_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
|
||||
#include <botan/botan.h>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
// "Payload length" (RFC 4253, 6.1), i.e. minus packet type, channel number
|
||||
// and length field for string.
|
||||
const quint32 MinMaxPacketSize = 32768 - sizeof(quint32) - sizeof(quint32) - 1;
|
||||
|
||||
const quint32 NoChannel = 0xffffffffu;
|
||||
|
||||
AbstractSshChannel::AbstractSshChannel(quint32 channelId,
|
||||
SshSendFacility &sendFacility)
|
||||
: m_sendFacility(sendFacility),
|
||||
m_localChannel(channelId), m_remoteChannel(NoChannel),
|
||||
m_localWindowSize(initialWindowSize()), m_remoteWindowSize(0),
|
||||
m_state(Inactive)
|
||||
{
|
||||
m_timeoutTimer.setSingleShot(true);
|
||||
connect(&m_timeoutTimer, &QTimer::timeout, this, &AbstractSshChannel::timeout);
|
||||
}
|
||||
|
||||
AbstractSshChannel::~AbstractSshChannel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AbstractSshChannel::setChannelState(ChannelState state)
|
||||
{
|
||||
m_state = state;
|
||||
if (state == Closed)
|
||||
closeHook();
|
||||
}
|
||||
|
||||
void AbstractSshChannel::requestSessionStart()
|
||||
{
|
||||
// Note: We are just being paranoid here about the Botan exceptions,
|
||||
// which are extremely unlikely to happen, because if there was a problem
|
||||
// with our cryptography stuff, it would have hit us before, on
|
||||
// establishing the connection.
|
||||
try {
|
||||
m_sendFacility.sendSessionPacket(m_localChannel, initialWindowSize(), maxPacketSize());
|
||||
setChannelState(SessionRequested);
|
||||
m_timeoutTimer.start(ReplyTimeout);
|
||||
} catch (const std::exception &e) {
|
||||
qCWarning(sshLog, "Botan error: %s", e.what());
|
||||
closeChannel();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractSshChannel::sendData(const QByteArray &data)
|
||||
{
|
||||
try {
|
||||
m_sendBuffer += data;
|
||||
flushSendBuffer();
|
||||
} catch (const std::exception &e) {
|
||||
qCWarning(sshLog, "Botan error: %s", e.what());
|
||||
closeChannel();
|
||||
}
|
||||
}
|
||||
|
||||
quint32 AbstractSshChannel::initialWindowSize()
|
||||
{
|
||||
return maxPacketSize();
|
||||
}
|
||||
|
||||
quint32 AbstractSshChannel::maxPacketSize()
|
||||
{
|
||||
return 16 * 1024 * 1024;
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleWindowAdjust(quint32 bytesToAdd)
|
||||
{
|
||||
checkChannelActive();
|
||||
|
||||
const quint64 newValue = m_remoteWindowSize + bytesToAdd;
|
||||
if (newValue > 0xffffffffu) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Illegal window size requested.");
|
||||
}
|
||||
|
||||
m_remoteWindowSize = newValue;
|
||||
flushSendBuffer();
|
||||
}
|
||||
|
||||
void AbstractSshChannel::flushSendBuffer()
|
||||
{
|
||||
while (true) {
|
||||
const quint32 bytesToSend = qMin(m_remoteMaxPacketSize,
|
||||
qMin<quint32>(m_remoteWindowSize, m_sendBuffer.size()));
|
||||
if (bytesToSend == 0)
|
||||
break;
|
||||
const QByteArray &data = m_sendBuffer.left(bytesToSend);
|
||||
m_sendFacility.sendChannelDataPacket(m_remoteChannel, data);
|
||||
m_sendBuffer.remove(0, bytesToSend);
|
||||
m_remoteWindowSize -= bytesToSend;
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleOpenSuccess(quint32 remoteChannelId,
|
||||
quint32 remoteWindowSize, quint32 remoteMaxPacketSize)
|
||||
{
|
||||
const ChannelState oldState = m_state;
|
||||
switch (oldState) {
|
||||
case CloseRequested: // closeChannel() was called while we were in SessionRequested state
|
||||
case SessionRequested:
|
||||
break; // Ok, continue.
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_OPEN_CONFIRMATION packet.");
|
||||
}
|
||||
|
||||
m_timeoutTimer.stop();
|
||||
|
||||
if (remoteMaxPacketSize < MinMaxPacketSize) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Maximum packet size too low.");
|
||||
}
|
||||
|
||||
qCDebug(sshLog, "Channel opened. remote channel id: %u, remote window size: %u, "
|
||||
"remote max packet size: %u",
|
||||
remoteChannelId, remoteWindowSize, remoteMaxPacketSize);
|
||||
m_remoteChannel = remoteChannelId;
|
||||
m_remoteWindowSize = remoteWindowSize;
|
||||
m_remoteMaxPacketSize = remoteMaxPacketSize;
|
||||
setChannelState(SessionEstablished);
|
||||
if (oldState == CloseRequested)
|
||||
closeChannel();
|
||||
else
|
||||
handleOpenSuccessInternal();
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleOpenFailure(const QString &reason)
|
||||
{
|
||||
switch (m_state) {
|
||||
case SessionRequested:
|
||||
break; // Ok, continue.
|
||||
case CloseRequested:
|
||||
return; // Late server reply; we requested a channel close in the meantime.
|
||||
default:
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_OPEN_FAILURE packet.");
|
||||
}
|
||||
|
||||
m_timeoutTimer.stop();
|
||||
|
||||
qCDebug(sshLog, "Channel open request failed for channel %u", m_localChannel);
|
||||
handleOpenFailureInternal(reason);
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleChannelEof()
|
||||
{
|
||||
if (m_state == Inactive || m_state == Closed) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_EOF message.");
|
||||
}
|
||||
m_localWindowSize = 0;
|
||||
emit eof();
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleChannelClose()
|
||||
{
|
||||
qCDebug(sshLog, "Receiving CLOSE for channel %u", m_localChannel);
|
||||
if (channelState() == Inactive || channelState() == Closed) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected SSH_MSG_CHANNEL_CLOSE message.");
|
||||
}
|
||||
closeChannel();
|
||||
setChannelState(Closed);
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleChannelData(const QByteArray &data)
|
||||
{
|
||||
const int bytesToDeliver = handleChannelOrExtendedChannelData(data);
|
||||
handleChannelDataInternal(bytesToDeliver == data.size()
|
||||
? data : data.left(bytesToDeliver));
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleChannelExtendedData(quint32 type, const QByteArray &data)
|
||||
{
|
||||
const int bytesToDeliver = handleChannelOrExtendedChannelData(data);
|
||||
handleChannelExtendedDataInternal(type, bytesToDeliver == data.size()
|
||||
? data : data.left(bytesToDeliver));
|
||||
}
|
||||
|
||||
void AbstractSshChannel::handleChannelRequest(const SshIncomingPacket &packet)
|
||||
{
|
||||
checkChannelActive();
|
||||
const QByteArray &requestType = packet.extractChannelRequestType();
|
||||
if (requestType == SshIncomingPacket::ExitStatusType)
|
||||
handleExitStatus(packet.extractChannelExitStatus());
|
||||
else if (requestType == SshIncomingPacket::ExitSignalType)
|
||||
handleExitSignal(packet.extractChannelExitSignal());
|
||||
else if (requestType != "eow@openssh.com") // Suppress warning for this one, as it's sent all the time.
|
||||
qCWarning(sshLog, "Ignoring unknown request type '%s'", requestType.data());
|
||||
}
|
||||
|
||||
int AbstractSshChannel::handleChannelOrExtendedChannelData(const QByteArray &data)
|
||||
{
|
||||
checkChannelActive();
|
||||
|
||||
const int bytesToDeliver = qMin<quint32>(data.size(), maxDataSize());
|
||||
if (bytesToDeliver != data.size())
|
||||
qCWarning(sshLog, "Misbehaving server does not respect local window, clipping.");
|
||||
|
||||
m_localWindowSize -= bytesToDeliver;
|
||||
if (m_localWindowSize < maxPacketSize()) {
|
||||
m_localWindowSize += maxPacketSize();
|
||||
m_sendFacility.sendWindowAdjustPacket(m_remoteChannel, maxPacketSize());
|
||||
}
|
||||
return bytesToDeliver;
|
||||
}
|
||||
|
||||
void AbstractSshChannel::closeChannel()
|
||||
{
|
||||
if (m_state == CloseRequested) {
|
||||
m_timeoutTimer.stop();
|
||||
} else if (m_state != Closed) {
|
||||
if (m_state == Inactive) {
|
||||
setChannelState(Closed);
|
||||
} else {
|
||||
const ChannelState oldState = m_state;
|
||||
setChannelState(CloseRequested);
|
||||
if (m_remoteChannel != NoChannel) {
|
||||
m_sendFacility.sendChannelEofPacket(m_remoteChannel);
|
||||
m_sendFacility.sendChannelClosePacket(m_remoteChannel);
|
||||
} else {
|
||||
QSSH_ASSERT(oldState == SessionRequested);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractSshChannel::checkChannelActive()
|
||||
{
|
||||
if (channelState() == Inactive || channelState() == Closed)
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Channel not open.");
|
||||
}
|
||||
|
||||
quint32 AbstractSshChannel::maxDataSize() const
|
||||
{
|
||||
return qMin(m_localWindowSize, maxPacketSize());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
117
client/3rd/QtSsh/src/ssh/sshchannel_p.h
Executable file
117
client/3rd/QtSsh/src/ssh/sshchannel_p.h
Executable file
@@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
struct SshChannelExitSignal;
|
||||
struct SshChannelExitStatus;
|
||||
class SshIncomingPacket;
|
||||
class SshSendFacility;
|
||||
|
||||
class AbstractSshChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ChannelState {
|
||||
Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
|
||||
};
|
||||
|
||||
quint32 localChannelId() const { return m_localChannel; }
|
||||
quint32 remoteChannel() const { return m_remoteChannel; }
|
||||
|
||||
virtual void handleChannelSuccess() = 0;
|
||||
virtual void handleChannelFailure() = 0;
|
||||
|
||||
void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize,
|
||||
quint32 remoteMaxPacketSize);
|
||||
void handleOpenFailure(const QString &reason);
|
||||
void handleWindowAdjust(quint32 bytesToAdd);
|
||||
void handleChannelEof();
|
||||
void handleChannelClose();
|
||||
void handleChannelData(const QByteArray &data);
|
||||
void handleChannelExtendedData(quint32 type, const QByteArray &data);
|
||||
void handleChannelRequest(const SshIncomingPacket &packet);
|
||||
|
||||
void closeChannel();
|
||||
|
||||
virtual ~AbstractSshChannel();
|
||||
|
||||
static const int ReplyTimeout = 10000; // milli seconds
|
||||
ChannelState channelState() const { return m_state; }
|
||||
|
||||
signals:
|
||||
void timeout();
|
||||
void eof();
|
||||
|
||||
protected:
|
||||
AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
|
||||
|
||||
void setChannelState(ChannelState state);
|
||||
|
||||
void requestSessionStart();
|
||||
void sendData(const QByteArray &data);
|
||||
|
||||
static quint32 initialWindowSize();
|
||||
static quint32 maxPacketSize();
|
||||
|
||||
quint32 maxDataSize() const;
|
||||
void checkChannelActive();
|
||||
|
||||
SshSendFacility &m_sendFacility;
|
||||
QTimer m_timeoutTimer;
|
||||
|
||||
private:
|
||||
virtual void handleOpenSuccessInternal() = 0;
|
||||
virtual void handleOpenFailureInternal(const QString &reason) = 0;
|
||||
virtual void handleChannelDataInternal(const QByteArray &data) = 0;
|
||||
virtual void handleChannelExtendedDataInternal(quint32 type,
|
||||
const QByteArray &data) = 0;
|
||||
virtual void handleExitStatus(const SshChannelExitStatus &exitStatus) = 0;
|
||||
virtual void handleExitSignal(const SshChannelExitSignal &signal) = 0;
|
||||
|
||||
virtual void closeHook() = 0;
|
||||
|
||||
void flushSendBuffer();
|
||||
int handleChannelOrExtendedChannelData(const QByteArray &data);
|
||||
|
||||
const quint32 m_localChannel;
|
||||
quint32 m_remoteChannel;
|
||||
quint32 m_localWindowSize;
|
||||
quint32 m_remoteWindowSize;
|
||||
quint32 m_remoteMaxPacketSize;
|
||||
ChannelState m_state;
|
||||
QByteArray m_sendBuffer;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
328
client/3rd/QtSsh/src/ssh/sshchannelmanager.cpp
Executable file
328
client/3rd/QtSsh/src/ssh/sshchannelmanager.cpp
Executable file
@@ -0,0 +1,328 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshchannelmanager_p.h"
|
||||
|
||||
#include "sftpchannel.h"
|
||||
#include "sftpchannel_p.h"
|
||||
#include "sshdirecttcpiptunnel.h"
|
||||
#include "sshdirecttcpiptunnel_p.h"
|
||||
#include "sshforwardedtcpiptunnel.h"
|
||||
#include "sshforwardedtcpiptunnel_p.h"
|
||||
#include "sshincomingpacket_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshremoteprocess.h"
|
||||
#include "sshremoteprocess_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
#include "sshtcpipforwardserver.h"
|
||||
#include "sshtcpipforwardserver_p.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
SshChannelManager::SshChannelManager(SshSendFacility &sendFacility,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_sendFacility(sendFacility), m_nextLocalChannelId(0)
|
||||
{
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelRequest(const SshIncomingPacket &packet)
|
||||
{
|
||||
lookupChannel(packet.extractRecipientChannel())
|
||||
->handleChannelRequest(packet);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelOpen(const SshIncomingPacket &packet)
|
||||
{
|
||||
SshChannelOpen channelOpen = packet.extractChannelOpen();
|
||||
|
||||
SshTcpIpForwardServer::Ptr server;
|
||||
|
||||
foreach (const SshTcpIpForwardServer::Ptr &candidate, m_listeningForwardServers) {
|
||||
if (candidate->port() == channelOpen.remotePort
|
||||
&& candidate->bindAddress().toUtf8() == channelOpen.remoteAddress) {
|
||||
server = candidate;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (server.isNull()) {
|
||||
// Apparently the server knows a remoteAddress we are not aware of. There are plenty of ways
|
||||
// to make that happen: /etc/hosts on the server, different writings for localhost,
|
||||
// different DNS servers, ...
|
||||
// Rather than trying to figure that out, we just use the first listening forwarder with the
|
||||
// same port.
|
||||
foreach (const SshTcpIpForwardServer::Ptr &candidate, m_listeningForwardServers) {
|
||||
if (candidate->port() == channelOpen.remotePort) {
|
||||
server = candidate;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (server.isNull()) {
|
||||
SshOpenFailureType reason = (channelOpen.remotePort == 0) ?
|
||||
SSH_OPEN_UNKNOWN_CHANNEL_TYPE : SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
|
||||
try {
|
||||
m_sendFacility.sendChannelOpenFailurePacket(channelOpen.remoteChannel, reason,
|
||||
QByteArray());
|
||||
} catch (const std::exception &e) {
|
||||
qCWarning(sshLog, "Botan error: %s", e.what());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SshForwardedTcpIpTunnel::Ptr tunnel(new SshForwardedTcpIpTunnel(m_nextLocalChannelId++,
|
||||
m_sendFacility));
|
||||
tunnel->d->handleOpenSuccess(channelOpen.remoteChannel, channelOpen.remoteWindowSize,
|
||||
channelOpen.remoteMaxPacketSize);
|
||||
tunnel->open(QIODevice::ReadWrite);
|
||||
server->setNewConnection(tunnel);
|
||||
insertChannel(tunnel->d, tunnel);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelOpenFailure(const SshIncomingPacket &packet)
|
||||
{
|
||||
const SshChannelOpenFailure &failure = packet.extractChannelOpenFailure();
|
||||
ChannelIterator it = lookupChannelAsIterator(failure.localChannel);
|
||||
try {
|
||||
it.value()->handleOpenFailure(failure.reasonString);
|
||||
} catch (const SshServerException &e) {
|
||||
removeChannel(it);
|
||||
throw e;
|
||||
}
|
||||
removeChannel(it);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelOpenConfirmation(const SshIncomingPacket &packet)
|
||||
{
|
||||
const SshChannelOpenConfirmation &confirmation
|
||||
= packet.extractChannelOpenConfirmation();
|
||||
lookupChannel(confirmation.localChannel)->handleOpenSuccess(confirmation.remoteChannel,
|
||||
confirmation.remoteWindowSize, confirmation.remoteMaxPacketSize);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelSuccess(const SshIncomingPacket &packet)
|
||||
{
|
||||
lookupChannel(packet.extractRecipientChannel())->handleChannelSuccess();
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelFailure(const SshIncomingPacket &packet)
|
||||
{
|
||||
lookupChannel(packet.extractRecipientChannel())->handleChannelFailure();
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelWindowAdjust(const SshIncomingPacket &packet)
|
||||
{
|
||||
const SshChannelWindowAdjust adjust = packet.extractWindowAdjust();
|
||||
lookupChannel(adjust.localChannel)->handleWindowAdjust(adjust.bytesToAdd);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelData(const SshIncomingPacket &packet)
|
||||
{
|
||||
const SshChannelData &data = packet.extractChannelData();
|
||||
lookupChannel(data.localChannel)->handleChannelData(data.data);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelExtendedData(const SshIncomingPacket &packet)
|
||||
{
|
||||
const SshChannelExtendedData &data = packet.extractChannelExtendedData();
|
||||
lookupChannel(data.localChannel)->handleChannelExtendedData(data.type, data.data);
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelEof(const SshIncomingPacket &packet)
|
||||
{
|
||||
AbstractSshChannel * const channel
|
||||
= lookupChannel(packet.extractRecipientChannel(), true);
|
||||
if (channel)
|
||||
channel->handleChannelEof();
|
||||
}
|
||||
|
||||
void SshChannelManager::handleChannelClose(const SshIncomingPacket &packet)
|
||||
{
|
||||
const quint32 channelId = packet.extractRecipientChannel();
|
||||
|
||||
ChannelIterator it = lookupChannelAsIterator(channelId, true);
|
||||
if (it != m_channels.end()) {
|
||||
it.value()->handleChannelClose();
|
||||
removeChannel(it);
|
||||
}
|
||||
}
|
||||
|
||||
void SshChannelManager::handleRequestSuccess(const SshIncomingPacket &packet)
|
||||
{
|
||||
if (m_waitingForwardServers.isEmpty()) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected request success packet.",
|
||||
tr("Unexpected request success packet."));
|
||||
}
|
||||
SshTcpIpForwardServer::Ptr server = m_waitingForwardServers.takeFirst();
|
||||
if (server->state() == SshTcpIpForwardServer::Closing) {
|
||||
server->setClosed();
|
||||
} else if (server->state() == SshTcpIpForwardServer::Initializing) {
|
||||
quint16 port = server->port();
|
||||
if (port == 0)
|
||||
port = packet.extractRequestSuccess().bindPort;
|
||||
server->setListening(port);
|
||||
m_listeningForwardServers.append(server);
|
||||
} else {
|
||||
QSSH_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SshChannelManager::handleRequestFailure(const SshIncomingPacket &packet)
|
||||
{
|
||||
Q_UNUSED(packet);
|
||||
if (m_waitingForwardServers.isEmpty()) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected request failure packet.",
|
||||
tr("Unexpected request failure packet."));
|
||||
}
|
||||
SshTcpIpForwardServer::Ptr tunnel = m_waitingForwardServers.takeFirst();
|
||||
tunnel->setClosed();
|
||||
}
|
||||
|
||||
SshChannelManager::ChannelIterator SshChannelManager::lookupChannelAsIterator(quint32 channelId,
|
||||
bool allowNotFound)
|
||||
{
|
||||
ChannelIterator it = m_channels.find(channelId);
|
||||
if (it == m_channels.end() && !allowNotFound) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid channel id.",
|
||||
tr("Invalid channel id %1").arg(channelId));
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
AbstractSshChannel *SshChannelManager::lookupChannel(quint32 channelId,
|
||||
bool allowNotFound)
|
||||
{
|
||||
ChannelIterator it = lookupChannelAsIterator(channelId, allowNotFound);
|
||||
return it == m_channels.end() ? 0 : it.value();
|
||||
}
|
||||
|
||||
QSsh::SshRemoteProcess::Ptr SshChannelManager::createRemoteProcess(const QByteArray &command)
|
||||
{
|
||||
SshRemoteProcess::Ptr proc(new SshRemoteProcess(command, m_nextLocalChannelId++, m_sendFacility));
|
||||
insertChannel(proc->d, proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
QSsh::SshRemoteProcess::Ptr SshChannelManager::createRemoteShell()
|
||||
{
|
||||
SshRemoteProcess::Ptr proc(new SshRemoteProcess(m_nextLocalChannelId++, m_sendFacility));
|
||||
insertChannel(proc->d, proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
QSsh::SftpChannel::Ptr SshChannelManager::createSftpChannel()
|
||||
{
|
||||
SftpChannel::Ptr sftp(new SftpChannel(m_nextLocalChannelId++, m_sendFacility));
|
||||
insertChannel(sftp->d, sftp);
|
||||
return sftp;
|
||||
}
|
||||
|
||||
SshDirectTcpIpTunnel::Ptr SshChannelManager::createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort)
|
||||
{
|
||||
SshDirectTcpIpTunnel::Ptr tunnel(new SshDirectTcpIpTunnel(m_nextLocalChannelId++,
|
||||
originatingHost, originatingPort, remoteHost, remotePort, m_sendFacility));
|
||||
insertChannel(tunnel->d, tunnel);
|
||||
return tunnel;
|
||||
}
|
||||
|
||||
SshTcpIpForwardServer::Ptr SshChannelManager::createForwardServer(const QString &remoteHost,
|
||||
quint16 remotePort)
|
||||
{
|
||||
SshTcpIpForwardServer::Ptr server(new SshTcpIpForwardServer(remoteHost, remotePort,
|
||||
m_sendFacility));
|
||||
connect(server.data(), &SshTcpIpForwardServer::stateChanged,
|
||||
this, [this, server](SshTcpIpForwardServer::State state) {
|
||||
switch (state) {
|
||||
case SshTcpIpForwardServer::Closing:
|
||||
m_listeningForwardServers.removeOne(server);
|
||||
// fall through
|
||||
case SshTcpIpForwardServer::Initializing:
|
||||
m_waitingForwardServers.append(server);
|
||||
break;
|
||||
case SshTcpIpForwardServer::Listening:
|
||||
case SshTcpIpForwardServer::Inactive:
|
||||
break;
|
||||
}
|
||||
});
|
||||
return server;
|
||||
}
|
||||
|
||||
void SshChannelManager::insertChannel(AbstractSshChannel *priv,
|
||||
const QSharedPointer<QObject> &pub)
|
||||
{
|
||||
connect(priv, &AbstractSshChannel::timeout, this, &SshChannelManager::timeout);
|
||||
m_channels.insert(priv->localChannelId(), priv);
|
||||
m_sessions.insert(priv, pub);
|
||||
}
|
||||
|
||||
int SshChannelManager::closeAllChannels(CloseAllMode mode)
|
||||
{
|
||||
int count = 0;
|
||||
for (ChannelIterator it = m_channels.begin(); it != m_channels.end(); ++it) {
|
||||
AbstractSshChannel * const channel = it.value();
|
||||
QSSH_ASSERT(channel->channelState() != AbstractSshChannel::Closed);
|
||||
if (channel->channelState() != AbstractSshChannel::CloseRequested) {
|
||||
channel->closeChannel();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
if (mode == CloseAllAndReset) {
|
||||
m_channels.clear();
|
||||
m_sessions.clear();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int SshChannelManager::channelCount() const
|
||||
{
|
||||
return m_channels.count();
|
||||
}
|
||||
|
||||
void SshChannelManager::removeChannel(ChannelIterator it)
|
||||
{
|
||||
if (it == m_channels.end()) {
|
||||
throw SshClientException(SshInternalError,
|
||||
QLatin1String("Internal error: Unexpected channel lookup failure"));
|
||||
}
|
||||
const int removeCount = m_sessions.remove(it.value());
|
||||
if (removeCount != 1) {
|
||||
throw SshClientException(SshInternalError,
|
||||
QString::fromLatin1("Internal error: Unexpected session count %1 for channel.")
|
||||
.arg(removeCount));
|
||||
}
|
||||
m_channels.erase(it);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
99
client/3rd/QtSsh/src/ssh/sshchannelmanager_p.h
Executable file
99
client/3rd/QtSsh/src/ssh/sshchannelmanager_p.h
Executable file
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace QSsh {
|
||||
class SftpChannel;
|
||||
class SshDirectTcpIpTunnel;
|
||||
class SshRemoteProcess;
|
||||
class SshTcpIpForwardServer;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class AbstractSshChannel;
|
||||
class SshIncomingPacket;
|
||||
class SshSendFacility;
|
||||
|
||||
class SshChannelManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SshChannelManager(SshSendFacility &sendFacility, QObject *parent);
|
||||
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
QSharedPointer<SshDirectTcpIpTunnel> createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort);
|
||||
QSharedPointer<SshTcpIpForwardServer> createForwardServer(const QString &remoteHost,
|
||||
quint16 remotePort);
|
||||
|
||||
int channelCount() const;
|
||||
enum CloseAllMode { CloseAllRegular, CloseAllAndReset };
|
||||
int closeAllChannels(CloseAllMode mode);
|
||||
|
||||
void handleChannelRequest(const SshIncomingPacket &packet);
|
||||
void handleChannelOpen(const SshIncomingPacket &packet);
|
||||
void handleChannelOpenFailure(const SshIncomingPacket &packet);
|
||||
void handleChannelOpenConfirmation(const SshIncomingPacket &packet);
|
||||
void handleChannelSuccess(const SshIncomingPacket &packet);
|
||||
void handleChannelFailure(const SshIncomingPacket &packet);
|
||||
void handleChannelWindowAdjust(const SshIncomingPacket &packet);
|
||||
void handleChannelData(const SshIncomingPacket &packet);
|
||||
void handleChannelExtendedData(const SshIncomingPacket &packet);
|
||||
void handleChannelEof(const SshIncomingPacket &packet);
|
||||
void handleChannelClose(const SshIncomingPacket &packet);
|
||||
void handleRequestSuccess(const SshIncomingPacket &packet);
|
||||
void handleRequestFailure(const SshIncomingPacket &packet);
|
||||
|
||||
signals:
|
||||
void timeout();
|
||||
|
||||
private:
|
||||
typedef QHash<quint32, AbstractSshChannel *>::Iterator ChannelIterator;
|
||||
|
||||
ChannelIterator lookupChannelAsIterator(quint32 channelId,
|
||||
bool allowNotFound = false);
|
||||
AbstractSshChannel *lookupChannel(quint32 channelId,
|
||||
bool allowNotFound = false);
|
||||
void removeChannel(ChannelIterator it);
|
||||
void insertChannel(AbstractSshChannel *priv,
|
||||
const QSharedPointer<QObject> &pub);
|
||||
|
||||
SshSendFacility &m_sendFacility;
|
||||
QHash<quint32, AbstractSshChannel *> m_channels;
|
||||
QHash<AbstractSshChannel *, QSharedPointer<QObject> > m_sessions;
|
||||
quint32 m_nextLocalChannelId;
|
||||
QList<QSharedPointer<SshTcpIpForwardServer>> m_waitingForwardServers;
|
||||
QList<QSharedPointer<SshTcpIpForwardServer>> m_listeningForwardServers;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
866
client/3rd/QtSsh/src/ssh/sshconnection.cpp
Executable file
866
client/3rd/QtSsh/src/ssh/sshconnection.cpp
Executable file
@@ -0,0 +1,866 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshconnection.h"
|
||||
#include "sshconnection_p.h"
|
||||
|
||||
#include "sftpchannel.h"
|
||||
#include "sshcapabilities_p.h"
|
||||
#include "sshchannelmanager_p.h"
|
||||
#include "sshcryptofacility_p.h"
|
||||
#include "sshdirecttcpiptunnel.h"
|
||||
#include "sshtcpipforwardserver.h"
|
||||
#include "sshexception_p.h"
|
||||
#include "sshinit_p.h"
|
||||
#include "sshkeyexchange_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshremoteprocess.h"
|
||||
|
||||
#include <botan/botan.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QNetworkProxy>
|
||||
#include <QRegExp>
|
||||
#include <QTcpSocket>
|
||||
|
||||
/*!
|
||||
\class QSsh::SshConnection
|
||||
|
||||
\brief The SshConnection class provides an SSH connection, implementing
|
||||
protocol version 2.0.
|
||||
|
||||
It can spawn channels for remote execution and SFTP operations (version 3).
|
||||
It operates asynchronously (non-blocking) and is not thread-safe.
|
||||
*/
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
const QByteArray ClientId("SSH-2.0-QtCreator\r\n");
|
||||
|
||||
SshConnectionParameters::SshConnectionParameters() :
|
||||
timeout(0), authenticationType(AuthenticationTypePublicKey), port(0),
|
||||
hostKeyCheckingMode(SshHostKeyCheckingNone)
|
||||
{
|
||||
options |= SshIgnoreDefaultProxy;
|
||||
options |= SshEnableStrictConformanceChecks;
|
||||
}
|
||||
|
||||
static inline bool equals(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
|
||||
{
|
||||
return p1.host == p2.host && p1.userName == p2.userName
|
||||
&& p1.authenticationType == p2.authenticationType
|
||||
&& (p1.authenticationType == SshConnectionParameters::AuthenticationTypePassword ?
|
||||
p1.password == p2.password : p1.privateKeyFile == p2.privateKeyFile)
|
||||
&& p1.hostKeyCheckingMode == p2.hostKeyCheckingMode
|
||||
&& p1.timeout == p2.timeout && p1.port == p2.port;
|
||||
}
|
||||
|
||||
bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
|
||||
{
|
||||
return equals(p1, p2);
|
||||
}
|
||||
|
||||
bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
|
||||
{
|
||||
return !equals(p1, p2);
|
||||
}
|
||||
|
||||
|
||||
SshConnection::SshConnection(const SshConnectionParameters &serverInfo, QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
Internal::initSsh();
|
||||
qRegisterMetaType<QSsh::SshError>("QSsh::SshError");
|
||||
qRegisterMetaType<QSsh::SftpJobId>("QSsh::SftpJobId");
|
||||
qRegisterMetaType<QSsh::SftpFileInfo>("QSsh::SftpFileInfo");
|
||||
qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>");
|
||||
|
||||
d = new Internal::SshConnectionPrivate(this, serverInfo);
|
||||
connect(d, &Internal::SshConnectionPrivate::connected, this, &SshConnection::connected,
|
||||
Qt::QueuedConnection);
|
||||
connect(d, &Internal::SshConnectionPrivate::dataAvailable, this,
|
||||
&SshConnection::dataAvailable, Qt::QueuedConnection);
|
||||
connect(d, &Internal::SshConnectionPrivate::disconnected, this, &SshConnection::disconnected,
|
||||
Qt::QueuedConnection);
|
||||
connect(d, &Internal::SshConnectionPrivate::error, this,
|
||||
&SshConnection::error, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SshConnection::connectToHost()
|
||||
{
|
||||
d->connectToHost();
|
||||
}
|
||||
|
||||
void SshConnection::disconnectFromHost()
|
||||
{
|
||||
d->closeConnection(Internal::SSH_DISCONNECT_BY_APPLICATION, SshNoError, "",
|
||||
QString());
|
||||
}
|
||||
|
||||
SshConnection::State SshConnection::state() const
|
||||
{
|
||||
switch (d->state()) {
|
||||
case Internal::SocketUnconnected:
|
||||
return Unconnected;
|
||||
case Internal::ConnectionEstablished:
|
||||
return Connected;
|
||||
default:
|
||||
return Connecting;
|
||||
}
|
||||
}
|
||||
|
||||
SshError SshConnection::errorState() const
|
||||
{
|
||||
return d->errorState();
|
||||
}
|
||||
|
||||
QString SshConnection::errorString() const
|
||||
{
|
||||
return d->errorString();
|
||||
}
|
||||
|
||||
SshConnectionParameters SshConnection::connectionParameters() const
|
||||
{
|
||||
return d->m_connParams;
|
||||
}
|
||||
|
||||
SshConnectionInfo SshConnection::connectionInfo() const
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, SshConnectionInfo());
|
||||
|
||||
return SshConnectionInfo(d->m_socket->localAddress(), d->m_socket->localPort(),
|
||||
d->m_socket->peerAddress(), d->m_socket->peerPort());
|
||||
}
|
||||
|
||||
SshConnection::~SshConnection()
|
||||
{
|
||||
disconnect();
|
||||
disconnectFromHost();
|
||||
delete d;
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnection::createRemoteProcess(const QByteArray &command)
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, QSharedPointer<SshRemoteProcess>());
|
||||
return d->createRemoteProcess(command);
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnection::createRemoteShell()
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, QSharedPointer<SshRemoteProcess>());
|
||||
return d->createRemoteShell();
|
||||
}
|
||||
|
||||
QSharedPointer<SftpChannel> SshConnection::createSftpChannel()
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, QSharedPointer<SftpChannel>());
|
||||
return d->createSftpChannel();
|
||||
}
|
||||
|
||||
SshDirectTcpIpTunnel::Ptr SshConnection::createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort)
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, SshDirectTcpIpTunnel::Ptr());
|
||||
return d->createDirectTunnel(originatingHost, originatingPort, remoteHost, remotePort);
|
||||
}
|
||||
|
||||
QSharedPointer<SshTcpIpForwardServer> SshConnection::createForwardServer(const QString &remoteHost,
|
||||
quint16 remotePort)
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN_VALUE(state() == Connected, SshTcpIpForwardServer::Ptr());
|
||||
return d->createForwardServer(remoteHost, remotePort);
|
||||
}
|
||||
|
||||
int SshConnection::closeAllChannels()
|
||||
{
|
||||
try {
|
||||
return d->m_channelManager->closeAllChannels(Internal::SshChannelManager::CloseAllRegular);
|
||||
} catch (const std::exception &e) {
|
||||
qCWarning(Internal::sshLog, "%s: %s", Q_FUNC_INFO, e.what());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int SshConnection::channelCount() const
|
||||
{
|
||||
return d->m_channelManager->channelCount();
|
||||
}
|
||||
|
||||
namespace Internal {
|
||||
|
||||
SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn,
|
||||
const SshConnectionParameters &serverInfo)
|
||||
: m_socket(new QTcpSocket(this)), m_state(SocketUnconnected),
|
||||
m_sendFacility(m_socket),
|
||||
m_channelManager(new SshChannelManager(m_sendFacility, this)),
|
||||
m_connParams(serverInfo), m_error(SshNoError), m_ignoreNextPacket(false),
|
||||
m_conn(conn)
|
||||
{
|
||||
setupPacketHandlers();
|
||||
m_socket->setProxy((m_connParams.options & SshIgnoreDefaultProxy)
|
||||
? QNetworkProxy::NoProxy : QNetworkProxy::DefaultProxy);
|
||||
m_timeoutTimer.setSingleShot(true);
|
||||
m_timeoutTimer.setInterval(m_connParams.timeout * 1000);
|
||||
m_keepAliveTimer.setSingleShot(true);
|
||||
m_keepAliveTimer.setInterval(10000);
|
||||
connect(m_channelManager, &SshChannelManager::timeout,
|
||||
this, &SshConnectionPrivate::handleTimeout);
|
||||
}
|
||||
|
||||
SshConnectionPrivate::~SshConnectionPrivate()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::setupPacketHandlers()
|
||||
{
|
||||
typedef SshConnectionPrivate This;
|
||||
|
||||
setupPacketHandler(SSH_MSG_KEXINIT, StateList() << SocketConnected
|
||||
<< ConnectionEstablished, &This::handleKeyExchangeInitPacket);
|
||||
setupPacketHandler(SSH_MSG_KEXDH_REPLY, StateList() << SocketConnected
|
||||
<< ConnectionEstablished, &This::handleKeyExchangeReplyPacket);
|
||||
|
||||
setupPacketHandler(SSH_MSG_NEWKEYS, StateList() << SocketConnected
|
||||
<< ConnectionEstablished, &This::handleNewKeysPacket);
|
||||
setupPacketHandler(SSH_MSG_SERVICE_ACCEPT,
|
||||
StateList() << UserAuthServiceRequested,
|
||||
&This::handleServiceAcceptPacket);
|
||||
if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypePassword
|
||||
|| m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods) {
|
||||
setupPacketHandler(SSH_MSG_USERAUTH_PASSWD_CHANGEREQ,
|
||||
StateList() << UserAuthRequested, &This::handlePasswordExpiredPacket);
|
||||
}
|
||||
setupPacketHandler(SSH_MSG_GLOBAL_REQUEST,
|
||||
StateList() << ConnectionEstablished, &This::handleGlobalRequest);
|
||||
|
||||
const StateList authReqList = StateList() << UserAuthRequested;
|
||||
setupPacketHandler(SSH_MSG_USERAUTH_BANNER, authReqList,
|
||||
&This::handleUserAuthBannerPacket);
|
||||
setupPacketHandler(SSH_MSG_USERAUTH_SUCCESS, authReqList,
|
||||
&This::handleUserAuthSuccessPacket);
|
||||
setupPacketHandler(SSH_MSG_USERAUTH_FAILURE, authReqList,
|
||||
&This::handleUserAuthFailurePacket);
|
||||
if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypeKeyboardInteractive
|
||||
|| m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods) {
|
||||
setupPacketHandler(SSH_MSG_USERAUTH_INFO_REQUEST, authReqList,
|
||||
&This::handleUserAuthInfoRequestPacket);
|
||||
}
|
||||
|
||||
const StateList connectedList
|
||||
= StateList() << ConnectionEstablished;
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_REQUEST, connectedList,
|
||||
&This::handleChannelRequest);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_OPEN, connectedList,
|
||||
&This::handleChannelOpen);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_OPEN_FAILURE, connectedList,
|
||||
&This::handleChannelOpenFailure);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, connectedList,
|
||||
&This::handleChannelOpenConfirmation);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_SUCCESS, connectedList,
|
||||
&This::handleChannelSuccess);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_FAILURE, connectedList,
|
||||
&This::handleChannelFailure);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_WINDOW_ADJUST, connectedList,
|
||||
&This::handleChannelWindowAdjust);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_DATA, connectedList,
|
||||
&This::handleChannelData);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_EXTENDED_DATA, connectedList,
|
||||
&This::handleChannelExtendedData);
|
||||
|
||||
const StateList connectedOrClosedList
|
||||
= StateList() << SocketUnconnected << ConnectionEstablished;
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_EOF, connectedOrClosedList,
|
||||
&This::handleChannelEof);
|
||||
setupPacketHandler(SSH_MSG_CHANNEL_CLOSE, connectedOrClosedList,
|
||||
&This::handleChannelClose);
|
||||
|
||||
setupPacketHandler(SSH_MSG_DISCONNECT, StateList() << SocketConnected
|
||||
<< UserAuthServiceRequested << UserAuthRequested
|
||||
<< ConnectionEstablished, &This::handleDisconnect);
|
||||
|
||||
setupPacketHandler(SSH_MSG_UNIMPLEMENTED,
|
||||
StateList() << ConnectionEstablished, &This::handleUnimplementedPacket);
|
||||
|
||||
setupPacketHandler(SSH_MSG_REQUEST_SUCCESS, connectedList,
|
||||
&This::handleRequestSuccess);
|
||||
setupPacketHandler(SSH_MSG_REQUEST_FAILURE, connectedList,
|
||||
&This::handleRequestFailure);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::setupPacketHandler(SshPacketType type,
|
||||
const SshConnectionPrivate::StateList &states,
|
||||
SshConnectionPrivate::PacketHandler handler)
|
||||
{
|
||||
m_packetHandlers.insert(type, HandlerInStates(states, handler));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleSocketConnected()
|
||||
{
|
||||
m_state = SocketConnected;
|
||||
sendData(ClientId);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleIncomingData()
|
||||
{
|
||||
if (m_state == SocketUnconnected)
|
||||
return; // For stuff queued in the event loop after we've called closeConnection();
|
||||
|
||||
try {
|
||||
if (!canUseSocket())
|
||||
return;
|
||||
m_incomingData += m_socket->readAll();
|
||||
qCDebug(sshLog, "state = %d, remote data size = %d", m_state, m_incomingData.count());
|
||||
if (m_serverId.isEmpty())
|
||||
handleServerId();
|
||||
handlePackets();
|
||||
} catch (const SshServerException &e) {
|
||||
closeConnection(e.error, SshProtocolError, e.errorStringServer,
|
||||
tr("SSH Protocol error: %1").arg(e.errorStringUser));
|
||||
} catch (const SshClientException &e) {
|
||||
closeConnection(SSH_DISCONNECT_BY_APPLICATION, e.error, "",
|
||||
e.errorString);
|
||||
} catch (const std::exception &e) {
|
||||
closeConnection(SSH_DISCONNECT_BY_APPLICATION, SshInternalError, "",
|
||||
tr("Botan library exception: %1").arg(QString::fromLatin1(e.what())));
|
||||
}
|
||||
}
|
||||
|
||||
// RFC 4253, 4.2.
|
||||
void SshConnectionPrivate::handleServerId()
|
||||
{
|
||||
qCDebug(sshLog, "%s: incoming data size = %d, incoming data = '%s'",
|
||||
Q_FUNC_INFO, m_incomingData.count(), m_incomingData.data());
|
||||
const int newLinePos = m_incomingData.indexOf('\n');
|
||||
if (newLinePos == -1)
|
||||
return; // Not enough data yet.
|
||||
|
||||
// Lines not starting with "SSH-" are ignored.
|
||||
if (!m_incomingData.startsWith("SSH-")) {
|
||||
m_incomingData.remove(0, newLinePos + 1);
|
||||
m_serverHasSentDataBeforeId = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (newLinePos > 255 - 1) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Identification string too long.",
|
||||
tr("Server identification string is %n characters long, but the maximum "
|
||||
"allowed length is 255.", 0, newLinePos + 1));
|
||||
}
|
||||
|
||||
const bool hasCarriageReturn = m_incomingData.at(newLinePos - 1) == '\r';
|
||||
m_serverId = m_incomingData.left(newLinePos);
|
||||
if (hasCarriageReturn)
|
||||
m_serverId.chop(1);
|
||||
m_incomingData.remove(0, newLinePos + 1);
|
||||
|
||||
if (m_serverId.contains('\0')) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Identification string contains illegal NUL character.",
|
||||
tr("Server identification string contains illegal NUL character."));
|
||||
}
|
||||
|
||||
// "printable US-ASCII characters, with the exception of whitespace characters
|
||||
// and the minus sign"
|
||||
QString legalString = QLatin1String("[]!\"#$!&'()*+,./0-9:;<=>?@A-Z[\\\\^_`a-z{|}~]+");
|
||||
const QRegExp versionIdpattern(QString::fromLatin1("SSH-(%1)-%1(?: .+)?").arg(legalString));
|
||||
if (!versionIdpattern.exactMatch(QString::fromLatin1(m_serverId))) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Identification string is invalid.",
|
||||
tr("Server Identification string \"%1\" is invalid.")
|
||||
.arg(QString::fromLatin1(m_serverId)));
|
||||
}
|
||||
const QString serverProtoVersion = versionIdpattern.cap(1);
|
||||
if (serverProtoVersion != QLatin1String("2.0") && serverProtoVersion != QLatin1String("1.99")) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED,
|
||||
"Invalid protocol version.",
|
||||
tr("Server protocol version is \"%1\", but needs to be 2.0 or 1.99.")
|
||||
.arg(serverProtoVersion));
|
||||
}
|
||||
|
||||
if (m_connParams.options & SshEnableStrictConformanceChecks) {
|
||||
if (serverProtoVersion == QLatin1String("2.0") && !hasCarriageReturn) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Identification string is invalid.",
|
||||
tr("Server identification string is invalid (missing carriage return)."));
|
||||
}
|
||||
|
||||
if (serverProtoVersion == QLatin1String("1.99") && m_serverHasSentDataBeforeId) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"No extra data preceding identification string allowed for 1.99.",
|
||||
tr("Server reports protocol version 1.99, but sends data "
|
||||
"before the identification string, which is not allowed."));
|
||||
}
|
||||
}
|
||||
|
||||
m_keyExchange.reset(new SshKeyExchange(m_connParams, m_sendFacility));
|
||||
m_keyExchange->sendKexInitPacket(m_serverId);
|
||||
m_keyExchangeState = KexInitSent;
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handlePackets()
|
||||
{
|
||||
m_incomingPacket.consumeData(m_incomingData);
|
||||
while (m_incomingPacket.isComplete()) {
|
||||
handleCurrentPacket();
|
||||
m_incomingPacket.clear();
|
||||
m_incomingPacket.consumeData(m_incomingData);
|
||||
}
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleCurrentPacket()
|
||||
{
|
||||
Q_ASSERT(m_incomingPacket.isComplete());
|
||||
Q_ASSERT(m_keyExchangeState == DhInitSent || !m_ignoreNextPacket);
|
||||
|
||||
if (m_ignoreNextPacket) {
|
||||
m_ignoreNextPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
QHash<SshPacketType, HandlerInStates>::ConstIterator it
|
||||
= m_packetHandlers.constFind(m_incomingPacket.type());
|
||||
if (it == m_packetHandlers.constEnd()) {
|
||||
m_sendFacility.sendMsgUnimplementedPacket(m_incomingPacket.serverSeqNr());
|
||||
return;
|
||||
}
|
||||
if (!it.value().first.contains(m_state)) {
|
||||
handleUnexpectedPacket();
|
||||
return;
|
||||
}
|
||||
(this->*it.value().second)();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleKeyExchangeInitPacket()
|
||||
{
|
||||
if (m_keyExchangeState != NoKeyExchange
|
||||
&& m_keyExchangeState != KexInitSent) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet.", tr("Unexpected packet of type %1.")
|
||||
.arg(m_incomingPacket.type()));
|
||||
}
|
||||
|
||||
// Server-initiated re-exchange.
|
||||
if (m_keyExchangeState == NoKeyExchange) {
|
||||
m_keyExchange.reset(new SshKeyExchange(m_connParams, m_sendFacility));
|
||||
m_keyExchange->sendKexInitPacket(m_serverId);
|
||||
}
|
||||
|
||||
// If the server sends a guessed packet, the guess must be wrong,
|
||||
// because the algorithms we support require us to initiate the
|
||||
// key exchange.
|
||||
if (m_keyExchange->sendDhInitPacket(m_incomingPacket))
|
||||
m_ignoreNextPacket = true;
|
||||
|
||||
m_keyExchangeState = DhInitSent;
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleKeyExchangeReplyPacket()
|
||||
{
|
||||
if (m_keyExchangeState != DhInitSent) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet.", tr("Unexpected packet of type %1.")
|
||||
.arg(m_incomingPacket.type()));
|
||||
}
|
||||
|
||||
m_keyExchange->sendNewKeysPacket(m_incomingPacket,
|
||||
ClientId.left(ClientId.size() - 2));
|
||||
m_sendFacility.recreateKeys(*m_keyExchange);
|
||||
m_keyExchangeState = NewKeysSent;
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleNewKeysPacket()
|
||||
{
|
||||
if (m_keyExchangeState != NewKeysSent) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet.", tr("Unexpected packet of type %1.")
|
||||
.arg(m_incomingPacket.type()));
|
||||
}
|
||||
|
||||
m_incomingPacket.recreateKeys(*m_keyExchange);
|
||||
m_keyExchange.reset();
|
||||
m_keyExchangeState = NoKeyExchange;
|
||||
|
||||
if (m_state == SocketConnected) {
|
||||
m_sendFacility.sendUserAuthServiceRequestPacket();
|
||||
m_state = UserAuthServiceRequested;
|
||||
}
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleServiceAcceptPacket()
|
||||
{
|
||||
switch (m_connParams.authenticationType) {
|
||||
case SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods:
|
||||
m_triedAllPasswordBasedMethods = false;
|
||||
// Fall-through.
|
||||
case SshConnectionParameters::AuthenticationTypePassword:
|
||||
m_sendFacility.sendUserAuthByPasswordRequestPacket(m_connParams.userName.toUtf8(),
|
||||
SshCapabilities::SshConnectionService, m_connParams.password.toUtf8());
|
||||
break;
|
||||
case SshConnectionParameters::AuthenticationTypeKeyboardInteractive:
|
||||
m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(m_connParams.userName.toUtf8(),
|
||||
SshCapabilities::SshConnectionService);
|
||||
break;
|
||||
case SshConnectionParameters::AuthenticationTypePublicKey:
|
||||
m_sendFacility.sendUserAuthByPublicKeyRequestPacket(m_connParams.userName.toUtf8(),
|
||||
SshCapabilities::SshConnectionService);
|
||||
break;
|
||||
}
|
||||
m_state = UserAuthRequested;
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handlePasswordExpiredPacket()
|
||||
{
|
||||
if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
|
||||
&& m_triedAllPasswordBasedMethods) {
|
||||
// This means we just tried to authorize via "keyboard-interactive", in which case
|
||||
// this type of packet is not allowed.
|
||||
handleUnexpectedPacket();
|
||||
return;
|
||||
}
|
||||
throw SshClientException(SshAuthenticationError, tr("Password expired."));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUserAuthInfoRequestPacket()
|
||||
{
|
||||
if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
|
||||
&& !m_triedAllPasswordBasedMethods) {
|
||||
// This means we just tried to authorize via "password", in which case
|
||||
// this type of packet is not allowed.
|
||||
handleUnexpectedPacket();
|
||||
return;
|
||||
}
|
||||
|
||||
const SshUserAuthInfoRequestPacket requestPacket
|
||||
= m_incomingPacket.extractUserAuthInfoRequest();
|
||||
QStringList responses;
|
||||
responses.reserve(requestPacket.prompts.count());
|
||||
|
||||
// Not very interactive, admittedly, but we don't want to be for now.
|
||||
for (int i = 0; i < requestPacket.prompts.count(); ++i)
|
||||
responses << m_connParams.password;
|
||||
m_sendFacility.sendUserAuthInfoResponsePacket(responses);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUserAuthBannerPacket()
|
||||
{
|
||||
emit dataAvailable(m_incomingPacket.extractUserAuthBanner().message);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUnexpectedPacket()
|
||||
{
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet.", tr("Unexpected packet of type %1.")
|
||||
.arg(m_incomingPacket.type()));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleGlobalRequest()
|
||||
{
|
||||
m_sendFacility.sendRequestFailurePacket();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUserAuthSuccessPacket()
|
||||
{
|
||||
m_state = ConnectionEstablished;
|
||||
m_timeoutTimer.stop();
|
||||
emit connected();
|
||||
m_lastInvalidMsgSeqNr = InvalidSeqNr;
|
||||
connect(&m_keepAliveTimer, &QTimer::timeout, this, &SshConnectionPrivate::sendKeepAlivePacket);
|
||||
m_keepAliveTimer.start();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUserAuthFailurePacket()
|
||||
{
|
||||
// TODO: Evaluate "authentications that can continue" field and act on it.
|
||||
if (m_connParams.authenticationType
|
||||
== SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
|
||||
&& !m_triedAllPasswordBasedMethods) {
|
||||
m_triedAllPasswordBasedMethods = true;
|
||||
m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(
|
||||
m_connParams.userName.toUtf8(),
|
||||
SshCapabilities::SshConnectionService);
|
||||
return;
|
||||
}
|
||||
|
||||
m_timeoutTimer.stop();
|
||||
const QString errorMsg = m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypePublicKey
|
||||
? tr("Server rejected key.") : tr("Server rejected password.");
|
||||
throw SshClientException(SshAuthenticationError, errorMsg);
|
||||
}
|
||||
void SshConnectionPrivate::handleDebugPacket()
|
||||
{
|
||||
const SshDebug &msg = m_incomingPacket.extractDebug();
|
||||
if (msg.display)
|
||||
emit dataAvailable(msg.message);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleUnimplementedPacket()
|
||||
{
|
||||
const SshUnimplemented &msg = m_incomingPacket.extractUnimplemented();
|
||||
if (msg.invalidMsgSeqNr != m_lastInvalidMsgSeqNr) {
|
||||
throw SshServerException(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Unexpected packet", tr("The server sent an unexpected SSH packet "
|
||||
"of type SSH_MSG_UNIMPLEMENTED."));
|
||||
}
|
||||
m_lastInvalidMsgSeqNr = InvalidSeqNr;
|
||||
m_timeoutTimer.stop();
|
||||
m_keepAliveTimer.start();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelRequest()
|
||||
{
|
||||
m_channelManager->handleChannelRequest(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelOpen()
|
||||
{
|
||||
m_channelManager->handleChannelOpen(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelOpenFailure()
|
||||
{
|
||||
m_channelManager->handleChannelOpenFailure(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelOpenConfirmation()
|
||||
{
|
||||
m_channelManager->handleChannelOpenConfirmation(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelSuccess()
|
||||
{
|
||||
m_channelManager->handleChannelSuccess(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelFailure()
|
||||
{
|
||||
m_channelManager->handleChannelFailure(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelWindowAdjust()
|
||||
{
|
||||
m_channelManager->handleChannelWindowAdjust(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelData()
|
||||
{
|
||||
m_channelManager->handleChannelData(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelExtendedData()
|
||||
{
|
||||
m_channelManager->handleChannelExtendedData(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelEof()
|
||||
{
|
||||
m_channelManager->handleChannelEof(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleChannelClose()
|
||||
{
|
||||
m_channelManager->handleChannelClose(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleDisconnect()
|
||||
{
|
||||
const SshDisconnect msg = m_incomingPacket.extractDisconnect();
|
||||
throw SshServerException(SSH_DISCONNECT_CONNECTION_LOST,
|
||||
"", tr("Server closed connection: %1").arg(msg.description));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleRequestSuccess()
|
||||
{
|
||||
m_channelManager->handleRequestSuccess(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleRequestFailure()
|
||||
{
|
||||
m_channelManager->handleRequestFailure(m_incomingPacket);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::sendData(const QByteArray &data)
|
||||
{
|
||||
if (canUseSocket())
|
||||
m_socket->write(data);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleSocketDisconnected()
|
||||
{
|
||||
closeConnection(SSH_DISCONNECT_CONNECTION_LOST, SshClosedByServerError,
|
||||
"Connection closed unexpectedly.",
|
||||
tr("Connection closed unexpectedly."));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleSocketError()
|
||||
{
|
||||
if (m_error == SshNoError) {
|
||||
closeConnection(SSH_DISCONNECT_CONNECTION_LOST, SshSocketError,
|
||||
"Network error", m_socket->errorString());
|
||||
}
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::handleTimeout()
|
||||
{
|
||||
closeConnection(SSH_DISCONNECT_BY_APPLICATION, SshTimeoutError, "",
|
||||
tr("Timeout waiting for reply from server."));
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::sendKeepAlivePacket()
|
||||
{
|
||||
// This type of message is not allowed during key exchange.
|
||||
if (m_keyExchangeState != NoKeyExchange) {
|
||||
m_keepAliveTimer.start();
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_lastInvalidMsgSeqNr == InvalidSeqNr);
|
||||
m_lastInvalidMsgSeqNr = m_sendFacility.nextClientSeqNr();
|
||||
m_sendFacility.sendInvalidPacket();
|
||||
m_timeoutTimer.start();
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::connectToHost()
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN(m_state == SocketUnconnected);
|
||||
|
||||
m_incomingData.clear();
|
||||
m_incomingPacket.reset();
|
||||
m_sendFacility.reset();
|
||||
m_error = SshNoError;
|
||||
m_ignoreNextPacket = false;
|
||||
m_errorString.clear();
|
||||
m_serverId.clear();
|
||||
m_serverHasSentDataBeforeId = false;
|
||||
|
||||
try {
|
||||
if (m_connParams.authenticationType == SshConnectionParameters::AuthenticationTypePublicKey)
|
||||
createPrivateKey();
|
||||
} catch (const SshClientException &ex) {
|
||||
m_error = ex.error;
|
||||
m_errorString = ex.errorString;
|
||||
emit error(m_error);
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_socket, &QAbstractSocket::connected,
|
||||
this, &SshConnectionPrivate::handleSocketConnected);
|
||||
connect(m_socket, &QIODevice::readyRead,
|
||||
this, &SshConnectionPrivate::handleIncomingData);
|
||||
connect(m_socket,
|
||||
static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error),
|
||||
this, &SshConnectionPrivate::handleSocketError);
|
||||
connect(m_socket, &QAbstractSocket::disconnected,
|
||||
this, &SshConnectionPrivate::handleSocketDisconnected);
|
||||
connect(&m_timeoutTimer, &QTimer::timeout, this, &SshConnectionPrivate::handleTimeout);
|
||||
m_state = SocketConnecting;
|
||||
m_keyExchangeState = NoKeyExchange;
|
||||
m_timeoutTimer.start();
|
||||
m_socket->connectToHost(m_connParams.host, m_connParams.port);
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::closeConnection(SshErrorCode sshError,
|
||||
SshError userError, const QByteArray &serverErrorString,
|
||||
const QString &userErrorString)
|
||||
{
|
||||
// Prevent endless loops by recursive exceptions.
|
||||
if (m_state == SocketUnconnected || m_error != SshNoError)
|
||||
return;
|
||||
|
||||
m_error = userError;
|
||||
m_errorString = userErrorString;
|
||||
m_timeoutTimer.stop();
|
||||
disconnect(m_socket, 0, this, 0);
|
||||
disconnect(&m_timeoutTimer, 0, this, 0);
|
||||
m_keepAliveTimer.stop();
|
||||
disconnect(&m_keepAliveTimer, 0, this, 0);
|
||||
try {
|
||||
m_channelManager->closeAllChannels(SshChannelManager::CloseAllAndReset);
|
||||
m_sendFacility.sendDisconnectPacket(sshError, serverErrorString);
|
||||
} catch (...) {} // Nothing sensible to be done here.
|
||||
if (m_error != SshNoError)
|
||||
emit error(userError);
|
||||
if (m_state == ConnectionEstablished)
|
||||
emit disconnected();
|
||||
if (canUseSocket())
|
||||
m_socket->disconnectFromHost();
|
||||
m_state = SocketUnconnected;
|
||||
}
|
||||
|
||||
bool SshConnectionPrivate::canUseSocket() const
|
||||
{
|
||||
return m_socket->isValid()
|
||||
&& m_socket->state() == QAbstractSocket::ConnectedState;
|
||||
}
|
||||
|
||||
void SshConnectionPrivate::createPrivateKey()
|
||||
{
|
||||
if (m_connParams.privateKeyFile.isEmpty())
|
||||
throw SshClientException(SshKeyFileError, tr("No private key file given."));
|
||||
QFile keyFile(m_connParams.privateKeyFile);
|
||||
|
||||
if (keyFile.open(QIODevice::ReadOnly)) {
|
||||
m_sendFacility.createAuthenticationKey(keyFile.readAll());
|
||||
}
|
||||
else {
|
||||
m_sendFacility.createAuthenticationKey(m_connParams.privateKeyFile.toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnectionPrivate::createRemoteProcess(const QByteArray &command)
|
||||
{
|
||||
return m_channelManager->createRemoteProcess(command);
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnectionPrivate::createRemoteShell()
|
||||
{
|
||||
return m_channelManager->createRemoteShell();
|
||||
}
|
||||
|
||||
QSharedPointer<SftpChannel> SshConnectionPrivate::createSftpChannel()
|
||||
{
|
||||
return m_channelManager->createSftpChannel();
|
||||
}
|
||||
|
||||
SshDirectTcpIpTunnel::Ptr SshConnectionPrivate::createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort)
|
||||
{
|
||||
return m_channelManager->createDirectTunnel(originatingHost, originatingPort, remoteHost,
|
||||
remotePort);
|
||||
}
|
||||
|
||||
SshTcpIpForwardServer::Ptr SshConnectionPrivate::createForwardServer(const QString &bindAddress,
|
||||
quint16 bindPort)
|
||||
{
|
||||
return m_channelManager->createForwardServer(bindAddress, bindPort);
|
||||
}
|
||||
|
||||
const quint64 SshConnectionPrivate::InvalidSeqNr = static_cast<quint64>(-1);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
145
client/3rd/QtSsh/src/ssh/sshconnection.h
Executable file
145
client/3rd/QtSsh/src/ssh/sshconnection.h
Executable file
@@ -0,0 +1,145 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ssherrors.h"
|
||||
#include "sshhostkeydatabase.h"
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QFlags>
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QHostAddress>
|
||||
|
||||
namespace QSsh {
|
||||
class SftpChannel;
|
||||
class SshDirectTcpIpTunnel;
|
||||
class SshRemoteProcess;
|
||||
class SshTcpIpForwardServer;
|
||||
|
||||
namespace Internal { class SshConnectionPrivate; }
|
||||
|
||||
enum SshConnectionOption {
|
||||
SshIgnoreDefaultProxy = 0x1,
|
||||
SshEnableStrictConformanceChecks = 0x2
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(SshConnectionOptions, SshConnectionOption)
|
||||
|
||||
enum SshHostKeyCheckingMode {
|
||||
SshHostKeyCheckingNone,
|
||||
SshHostKeyCheckingStrict,
|
||||
SshHostKeyCheckingAllowNoMatch,
|
||||
SshHostKeyCheckingAllowMismatch
|
||||
};
|
||||
|
||||
class QSSH_EXPORT SshConnectionParameters
|
||||
{
|
||||
public:
|
||||
enum AuthenticationType {
|
||||
AuthenticationTypePassword,
|
||||
AuthenticationTypePublicKey,
|
||||
AuthenticationTypeKeyboardInteractive,
|
||||
|
||||
// Some servers disable "password", others disable "keyboard-interactive".
|
||||
AuthenticationTypeTryAllPasswordBasedMethods
|
||||
};
|
||||
|
||||
SshConnectionParameters();
|
||||
|
||||
QString host;
|
||||
QString userName;
|
||||
QString password;
|
||||
QString privateKeyFile;
|
||||
int timeout; // In seconds.
|
||||
AuthenticationType authenticationType;
|
||||
quint16 port;
|
||||
SshConnectionOptions options;
|
||||
SshHostKeyCheckingMode hostKeyCheckingMode;
|
||||
SshHostKeyDatabasePtr hostKeyDatabase;
|
||||
};
|
||||
|
||||
QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
||||
QSSH_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
||||
|
||||
class QSSH_EXPORT SshConnectionInfo
|
||||
{
|
||||
public:
|
||||
SshConnectionInfo() : localPort(0), peerPort(0) {}
|
||||
SshConnectionInfo(const QHostAddress &la, quint16 lp, const QHostAddress &pa, quint16 pp)
|
||||
: localAddress(la), localPort(lp), peerAddress(pa), peerPort(pp) {}
|
||||
|
||||
QHostAddress localAddress;
|
||||
quint16 localPort;
|
||||
QHostAddress peerAddress;
|
||||
quint16 peerPort;
|
||||
};
|
||||
|
||||
class QSSH_EXPORT SshConnection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum State { Unconnected, Connecting, Connected };
|
||||
|
||||
explicit SshConnection(const SshConnectionParameters &serverInfo, QObject *parent = 0);
|
||||
|
||||
void connectToHost();
|
||||
void disconnectFromHost();
|
||||
State state() const;
|
||||
SshError errorState() const;
|
||||
QString errorString() const;
|
||||
SshConnectionParameters connectionParameters() const;
|
||||
SshConnectionInfo connectionInfo() const;
|
||||
~SshConnection();
|
||||
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
QSharedPointer<SshDirectTcpIpTunnel> createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort);
|
||||
QSharedPointer<SshTcpIpForwardServer> createForwardServer(const QString &remoteHost,
|
||||
quint16 remotePort);
|
||||
|
||||
// -1 if an error occurred, number of channels closed otherwise.
|
||||
int closeAllChannels();
|
||||
|
||||
int channelCount() const;
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void dataAvailable(const QString &message);
|
||||
void error(QSsh::SshError);
|
||||
|
||||
private:
|
||||
Internal::SshConnectionPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
179
client/3rd/QtSsh/src/ssh/sshconnection_p.h
Executable file
179
client/3rd/QtSsh/src/ssh/sshconnection_p.h
Executable file
@@ -0,0 +1,179 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sshconnection.h"
|
||||
#include "sshexception_p.h"
|
||||
#include "sshincomingpacket_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTcpSocket;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace QSsh {
|
||||
class SftpChannel;
|
||||
class SshRemoteProcess;
|
||||
class SshDirectTcpIpTunnel;
|
||||
class SshTcpIpForwardServer;
|
||||
|
||||
namespace Internal {
|
||||
class SshChannelManager;
|
||||
|
||||
// NOTE: When you add stuff here, don't forget to update m_packetHandlers.
|
||||
enum SshStateInternal {
|
||||
SocketUnconnected, // initial and after disconnect
|
||||
SocketConnecting, // After connectToHost()
|
||||
SocketConnected, // After socket's connected() signal
|
||||
UserAuthServiceRequested,
|
||||
UserAuthRequested,
|
||||
ConnectionEstablished // After service has been started
|
||||
// ...
|
||||
};
|
||||
|
||||
enum SshKeyExchangeState {
|
||||
NoKeyExchange,
|
||||
KexInitSent,
|
||||
DhInitSent,
|
||||
NewKeysSent,
|
||||
KeyExchangeSuccess // After server's DH_REPLY message
|
||||
};
|
||||
|
||||
class SshConnectionPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class QSsh::SshConnection;
|
||||
public:
|
||||
SshConnectionPrivate(SshConnection *conn,
|
||||
const SshConnectionParameters &serverInfo);
|
||||
~SshConnectionPrivate();
|
||||
|
||||
void connectToHost();
|
||||
void closeConnection(SshErrorCode sshError, SshError userError,
|
||||
const QByteArray &serverErrorString, const QString &userErrorString);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
QSharedPointer<SshDirectTcpIpTunnel> createDirectTunnel(const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort);
|
||||
QSharedPointer<SshTcpIpForwardServer> createForwardServer(const QString &remoteHost,
|
||||
quint16 remotePort);
|
||||
|
||||
SshStateInternal state() const { return m_state; }
|
||||
SshError errorState() const { return m_error; }
|
||||
QString errorString() const { return m_errorString; }
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void dataAvailable(const QString &message);
|
||||
void error(QSsh::SshError);
|
||||
|
||||
private:
|
||||
void handleSocketConnected();
|
||||
void handleIncomingData();
|
||||
void handleSocketError();
|
||||
void handleSocketDisconnected();
|
||||
void handleTimeout();
|
||||
void sendKeepAlivePacket();
|
||||
|
||||
void handleServerId();
|
||||
void handlePackets();
|
||||
void handleCurrentPacket();
|
||||
void handleKeyExchangeInitPacket();
|
||||
void handleKeyExchangeReplyPacket();
|
||||
void handleNewKeysPacket();
|
||||
void handleServiceAcceptPacket();
|
||||
void handlePasswordExpiredPacket();
|
||||
void handleUserAuthInfoRequestPacket();
|
||||
void handleUserAuthSuccessPacket();
|
||||
void handleUserAuthFailurePacket();
|
||||
void handleUserAuthBannerPacket();
|
||||
void handleUnexpectedPacket();
|
||||
void handleGlobalRequest();
|
||||
void handleDebugPacket();
|
||||
void handleUnimplementedPacket();
|
||||
void handleChannelRequest();
|
||||
void handleChannelOpen();
|
||||
void handleChannelOpenFailure();
|
||||
void handleChannelOpenConfirmation();
|
||||
void handleChannelSuccess();
|
||||
void handleChannelFailure();
|
||||
void handleChannelWindowAdjust();
|
||||
void handleChannelData();
|
||||
void handleChannelExtendedData();
|
||||
void handleChannelEof();
|
||||
void handleChannelClose();
|
||||
void handleDisconnect();
|
||||
void handleRequestSuccess();
|
||||
void handleRequestFailure();
|
||||
|
||||
bool canUseSocket() const;
|
||||
void createPrivateKey();
|
||||
|
||||
void sendData(const QByteArray &data);
|
||||
|
||||
typedef void (SshConnectionPrivate::*PacketHandler)();
|
||||
typedef QList<SshStateInternal> StateList;
|
||||
void setupPacketHandlers();
|
||||
void setupPacketHandler(SshPacketType type, const StateList &states,
|
||||
PacketHandler handler);
|
||||
|
||||
typedef QPair<StateList, PacketHandler> HandlerInStates;
|
||||
QHash<SshPacketType, HandlerInStates> m_packetHandlers;
|
||||
|
||||
static const quint64 InvalidSeqNr;
|
||||
|
||||
QTcpSocket *m_socket;
|
||||
SshStateInternal m_state;
|
||||
SshKeyExchangeState m_keyExchangeState;
|
||||
SshIncomingPacket m_incomingPacket;
|
||||
SshSendFacility m_sendFacility;
|
||||
SshChannelManager * const m_channelManager;
|
||||
const SshConnectionParameters m_connParams;
|
||||
QByteArray m_incomingData;
|
||||
SshError m_error;
|
||||
QString m_errorString;
|
||||
QScopedPointer<SshKeyExchange> m_keyExchange;
|
||||
QTimer m_timeoutTimer;
|
||||
QTimer m_keepAliveTimer;
|
||||
bool m_ignoreNextPacket;
|
||||
SshConnection *m_conn;
|
||||
quint64 m_lastInvalidMsgSeqNr;
|
||||
QByteArray m_serverId;
|
||||
bool m_serverHasSentDataBeforeId;
|
||||
bool m_triedAllPasswordBasedMethods;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
270
client/3rd/QtSsh/src/ssh/sshconnectionmanager.cpp
Executable file
270
client/3rd/QtSsh/src/ssh/sshconnectionmanager.cpp
Executable file
@@ -0,0 +1,270 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshconnectionmanager.h"
|
||||
|
||||
#include "sshconnection.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
class UnaquiredConnection {
|
||||
public:
|
||||
UnaquiredConnection(SshConnection *conn) : connection(conn), scheduledForRemoval(false) {}
|
||||
|
||||
SshConnection *connection;
|
||||
bool scheduledForRemoval;
|
||||
};
|
||||
bool operator==(const UnaquiredConnection &c1, const UnaquiredConnection &c2) {
|
||||
return c1.connection == c2.connection;
|
||||
}
|
||||
bool operator!=(const UnaquiredConnection &c1, const UnaquiredConnection &c2) {
|
||||
return !(c1 == c2);
|
||||
}
|
||||
|
||||
class SshConnectionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SshConnectionManager()
|
||||
{
|
||||
moveToThread(QCoreApplication::instance()->thread());
|
||||
connect(&m_removalTimer, &QTimer::timeout,
|
||||
this, &SshConnectionManager::removeInactiveConnections);
|
||||
m_removalTimer.start(150000); // For a total timeout of five minutes.
|
||||
}
|
||||
|
||||
~SshConnectionManager()
|
||||
{
|
||||
foreach (const UnaquiredConnection &connection, m_unacquiredConnections) {
|
||||
disconnect(connection.connection, 0, this, 0);
|
||||
delete connection.connection;
|
||||
}
|
||||
|
||||
QSSH_ASSERT(m_acquiredConnections.isEmpty());
|
||||
QSSH_ASSERT(m_deprecatedConnections.isEmpty());
|
||||
}
|
||||
|
||||
SshConnection *acquireConnection(const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
|
||||
// Check in-use connections:
|
||||
foreach (SshConnection * const connection, m_acquiredConnections) {
|
||||
if (connection->connectionParameters() != sshParams)
|
||||
continue;
|
||||
|
||||
if (connection->thread() != QThread::currentThread())
|
||||
continue;
|
||||
|
||||
if (m_deprecatedConnections.contains(connection)) // we were asked to no longer use this one...
|
||||
continue;
|
||||
|
||||
m_acquiredConnections.append(connection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
// Check cached open connections:
|
||||
foreach (const UnaquiredConnection &c, m_unacquiredConnections) {
|
||||
SshConnection * const connection = c.connection;
|
||||
if (connection->state() != SshConnection::Connected
|
||||
|| connection->connectionParameters() != sshParams)
|
||||
continue;
|
||||
|
||||
if (connection->thread() != QThread::currentThread()) {
|
||||
if (connection->channelCount() != 0)
|
||||
continue;
|
||||
QMetaObject::invokeMethod(this, "switchToCallerThread",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_ARG(SshConnection *, connection),
|
||||
Q_ARG(QObject *, QThread::currentThread()));
|
||||
}
|
||||
|
||||
m_unacquiredConnections.removeOne(c);
|
||||
m_acquiredConnections.append(connection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
// create a new connection:
|
||||
SshConnection * const connection = new SshConnection(sshParams);
|
||||
connect(connection, &SshConnection::disconnected,
|
||||
this, &SshConnectionManager::cleanup);
|
||||
m_acquiredConnections.append(connection);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
void releaseConnection(SshConnection *connection)
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
|
||||
const bool wasAquired = m_acquiredConnections.removeOne(connection);
|
||||
QSSH_ASSERT_AND_RETURN(wasAquired);
|
||||
if (m_acquiredConnections.contains(connection))
|
||||
return;
|
||||
|
||||
bool doDelete = false;
|
||||
connection->moveToThread(QCoreApplication::instance()->thread());
|
||||
if (m_deprecatedConnections.removeOne(connection)
|
||||
|| connection->state() != SshConnection::Connected) {
|
||||
doDelete = true;
|
||||
} else {
|
||||
QSSH_ASSERT_AND_RETURN(!m_unacquiredConnections.contains(UnaquiredConnection(connection)));
|
||||
|
||||
// It can happen that two or more connections with the same parameters were acquired
|
||||
// if the clients were running in different threads. Only keep one of them in
|
||||
// such a case.
|
||||
bool haveConnection = false;
|
||||
foreach (const UnaquiredConnection &c, m_unacquiredConnections) {
|
||||
if (c.connection->connectionParameters() == connection->connectionParameters()) {
|
||||
haveConnection = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!haveConnection) {
|
||||
connection->closeAllChannels(); // Clean up after neglectful clients.
|
||||
m_unacquiredConnections.append(UnaquiredConnection(connection));
|
||||
} else {
|
||||
doDelete = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doDelete) {
|
||||
disconnect(connection, 0, this, 0);
|
||||
m_deprecatedConnections.removeAll(connection);
|
||||
connection->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void forceNewConnection(const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
|
||||
for (int i = 0; i < m_unacquiredConnections.count(); ++i) {
|
||||
SshConnection * const connection = m_unacquiredConnections.at(i).connection;
|
||||
if (connection->connectionParameters() == sshParams) {
|
||||
disconnect(connection, 0, this, 0);
|
||||
delete connection;
|
||||
m_unacquiredConnections.removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (SshConnection * const connection, m_acquiredConnections) {
|
||||
if (connection->connectionParameters() == sshParams) {
|
||||
if (!m_deprecatedConnections.contains(connection))
|
||||
m_deprecatedConnections.append(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Q_INVOKABLE void switchToCallerThread(SshConnection *connection, QObject *threadObj)
|
||||
{
|
||||
connection->moveToThread(qobject_cast<QThread *>(threadObj));
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
|
||||
SshConnection *currentConnection = qobject_cast<SshConnection *>(sender());
|
||||
if (!currentConnection)
|
||||
return;
|
||||
|
||||
if (m_unacquiredConnections.removeOne(UnaquiredConnection(currentConnection))) {
|
||||
disconnect(currentConnection, 0, this, 0);
|
||||
currentConnection->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void removeInactiveConnections()
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
for (int i = m_unacquiredConnections.count() - 1; i >= 0; --i) {
|
||||
UnaquiredConnection &c = m_unacquiredConnections[i];
|
||||
if (c.scheduledForRemoval) {
|
||||
disconnect(c.connection, 0, this, 0);
|
||||
c.connection->deleteLater();
|
||||
m_unacquiredConnections.removeAt(i);
|
||||
} else {
|
||||
c.scheduledForRemoval = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// We expect the number of concurrently open connections to be small.
|
||||
// If that turns out to not be the case, we can still use a data
|
||||
// structure with faster access.
|
||||
QList<UnaquiredConnection> m_unacquiredConnections;
|
||||
|
||||
// Can contain the same connection more than once; this acts as a reference count.
|
||||
QList<SshConnection *> m_acquiredConnections;
|
||||
|
||||
QList<SshConnection *> m_deprecatedConnections;
|
||||
QMutex m_listMutex;
|
||||
QTimer m_removalTimer;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
static QMutex instanceMutex;
|
||||
|
||||
static Internal::SshConnectionManager &instance()
|
||||
{
|
||||
static Internal::SshConnectionManager manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
SshConnection *acquireConnection(const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QMutexLocker locker(&instanceMutex);
|
||||
return instance().acquireConnection(sshParams);
|
||||
}
|
||||
|
||||
void releaseConnection(SshConnection *connection)
|
||||
{
|
||||
QMutexLocker locker(&instanceMutex);
|
||||
instance().releaseConnection(connection);
|
||||
}
|
||||
|
||||
void forceNewConnection(const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QMutexLocker locker(&instanceMutex);
|
||||
instance().forceNewConnection(sshParams);
|
||||
}
|
||||
|
||||
} // namespace QSsh
|
||||
|
||||
#include "sshconnectionmanager.moc"
|
||||
41
client/3rd/QtSsh/src/ssh/sshconnectionmanager.h
Executable file
41
client/3rd/QtSsh/src/ssh/sshconnectionmanager.h
Executable file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
class SshConnection;
|
||||
class SshConnectionParameters;
|
||||
|
||||
QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams);
|
||||
QSSH_EXPORT void releaseConnection(SshConnection *connection);
|
||||
|
||||
// Make sure the next acquireConnection with the given parameters will return a new connection.
|
||||
QSSH_EXPORT void forceNewConnection(const SshConnectionParameters &sshParams);
|
||||
|
||||
} // namespace QSsh
|
||||
439
client/3rd/QtSsh/src/ssh/sshcryptofacility.cpp
Executable file
439
client/3rd/QtSsh/src/ssh/sshcryptofacility.cpp
Executable file
@@ -0,0 +1,439 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshcryptofacility_p.h"
|
||||
|
||||
#include "sshbotanconversions_p.h"
|
||||
#include "sshcapabilities_p.h"
|
||||
#include "sshexception_p.h"
|
||||
#include "sshkeyexchange_p.h"
|
||||
#include "sshkeypasswordretriever_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshpacket_p.h"
|
||||
|
||||
#include <botan/botan.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Botan;
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
SshAbstractCryptoFacility::SshAbstractCryptoFacility()
|
||||
: m_cipherBlockSize(0), m_macLength(0)
|
||||
{
|
||||
}
|
||||
|
||||
SshAbstractCryptoFacility::~SshAbstractCryptoFacility() {}
|
||||
|
||||
void SshAbstractCryptoFacility::clearKeys()
|
||||
{
|
||||
m_cipherBlockSize = 0;
|
||||
m_macLength = 0;
|
||||
m_sessionId.clear();
|
||||
m_pipe.reset(0);
|
||||
m_hMac.reset(0);
|
||||
}
|
||||
|
||||
SshAbstractCryptoFacility::Mode SshAbstractCryptoFacility::getMode(const QByteArray &algoName)
|
||||
{
|
||||
if (algoName.endsWith("-ctr"))
|
||||
return CtrMode;
|
||||
if (algoName.endsWith("-cbc"))
|
||||
return CbcMode;
|
||||
throw SshClientException(SshInternalError, SSH_TR("Unexpected cipher \"%1\"")
|
||||
.arg(QString::fromLatin1(algoName)));
|
||||
}
|
||||
|
||||
void SshAbstractCryptoFacility::recreateKeys(const SshKeyExchange &kex)
|
||||
{
|
||||
checkInvariant();
|
||||
|
||||
if (m_sessionId.isEmpty())
|
||||
m_sessionId = kex.h();
|
||||
Algorithm_Factory &af = global_state().algorithm_factory();
|
||||
const QByteArray &rfcCryptAlgoName = cryptAlgoName(kex);
|
||||
BlockCipher * const cipher
|
||||
= af.prototype_block_cipher(botanCryptAlgoName(rfcCryptAlgoName))->clone();
|
||||
|
||||
m_cipherBlockSize = static_cast<quint32>(cipher->block_size());
|
||||
const QByteArray ivData = generateHash(kex, ivChar(), m_cipherBlockSize);
|
||||
const InitializationVector iv(convertByteArray(ivData), m_cipherBlockSize);
|
||||
|
||||
const quint32 keySize = static_cast<quint32>(cipher->key_spec().maximum_keylength());
|
||||
const QByteArray cryptKeyData = generateHash(kex, keyChar(), keySize);
|
||||
SymmetricKey cryptKey(convertByteArray(cryptKeyData), keySize);
|
||||
Keyed_Filter * const cipherMode
|
||||
= makeCipherMode(cipher, getMode(rfcCryptAlgoName), iv, cryptKey);
|
||||
m_pipe.reset(new Pipe(cipherMode));
|
||||
|
||||
m_macLength = botanHMacKeyLen(hMacAlgoName(kex));
|
||||
const QByteArray hMacKeyData = generateHash(kex, macChar(), macLength());
|
||||
SymmetricKey hMacKey(convertByteArray(hMacKeyData), macLength());
|
||||
const HashFunction * const hMacProto
|
||||
= af.prototype_hash_function(botanHMacAlgoName(hMacAlgoName(kex)));
|
||||
m_hMac.reset(new HMAC(hMacProto->clone()));
|
||||
m_hMac->set_key(hMacKey);
|
||||
}
|
||||
|
||||
void SshAbstractCryptoFacility::convert(QByteArray &data, quint32 offset,
|
||||
quint32 dataSize) const
|
||||
{
|
||||
Q_ASSERT(offset + dataSize <= static_cast<quint32>(data.size()));
|
||||
checkInvariant();
|
||||
|
||||
// Session id empty => No key exchange has happened yet.
|
||||
if (dataSize == 0 || m_sessionId.isEmpty())
|
||||
return;
|
||||
|
||||
if (dataSize % cipherBlockSize() != 0) {
|
||||
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_PROTOCOL_ERROR,
|
||||
"Invalid packet size");
|
||||
}
|
||||
m_pipe->process_msg(reinterpret_cast<const byte *>(data.constData()) + offset,
|
||||
dataSize);
|
||||
// Can't use Pipe::LAST_MESSAGE because of a VC bug.
|
||||
quint32 bytesRead = static_cast<quint32>(m_pipe->read(
|
||||
reinterpret_cast<byte *>(data.data()) + offset, dataSize, m_pipe->message_count() - 1));
|
||||
if (bytesRead != dataSize) {
|
||||
throw SshClientException(SshInternalError,
|
||||
QLatin1String("Internal error: Botan::Pipe::read() returned unexpected value"));
|
||||
}
|
||||
}
|
||||
|
||||
Keyed_Filter *SshAbstractCryptoFacility::makeCtrCipherMode(BlockCipher *cipher,
|
||||
const InitializationVector &iv, const SymmetricKey &key)
|
||||
{
|
||||
StreamCipher_Filter * const filter = new StreamCipher_Filter(new CTR_BE(cipher));
|
||||
filter->set_key(key);
|
||||
filter->set_iv(iv);
|
||||
return filter;
|
||||
}
|
||||
|
||||
QByteArray SshAbstractCryptoFacility::generateMac(const QByteArray &data,
|
||||
quint32 dataSize) const
|
||||
{
|
||||
return m_sessionId.isEmpty()
|
||||
? QByteArray()
|
||||
: convertByteArray(m_hMac->process(reinterpret_cast<const byte *>(data.constData()),
|
||||
dataSize));
|
||||
}
|
||||
|
||||
QByteArray SshAbstractCryptoFacility::generateHash(const SshKeyExchange &kex,
|
||||
char c, quint32 length)
|
||||
{
|
||||
const QByteArray &k = kex.k();
|
||||
const QByteArray &h = kex.h();
|
||||
QByteArray data(k);
|
||||
data.append(h).append(c).append(m_sessionId);
|
||||
SecureVector<byte> key
|
||||
= kex.hash()->process(convertByteArray(data), data.size());
|
||||
while (key.size() < length) {
|
||||
SecureVector<byte> tmpKey;
|
||||
tmpKey += SecureVector<byte>(convertByteArray(k), k.size());
|
||||
tmpKey += SecureVector<byte>(convertByteArray(h), h.size());
|
||||
tmpKey += key;
|
||||
key += kex.hash()->process(tmpKey);
|
||||
}
|
||||
return QByteArray(reinterpret_cast<const char *>(key.begin()), length);
|
||||
}
|
||||
|
||||
void SshAbstractCryptoFacility::checkInvariant() const
|
||||
{
|
||||
Q_ASSERT(m_sessionId.isEmpty() == !m_pipe);
|
||||
}
|
||||
|
||||
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileStartLineRsa("-----BEGIN RSA PRIVATE KEY-----");
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileStartLineDsa("-----BEGIN DSA PRIVATE KEY-----");
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileEndLineRsa("-----END RSA PRIVATE KEY-----");
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileEndLineDsa("-----END DSA PRIVATE KEY-----");
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileStartLineEcdsa("-----BEGIN EC PRIVATE KEY-----");
|
||||
const QByteArray SshEncryptionFacility::PrivKeyFileEndLineEcdsa("-----END EC PRIVATE KEY-----");
|
||||
|
||||
QByteArray SshEncryptionFacility::cryptAlgoName(const SshKeyExchange &kex) const
|
||||
{
|
||||
return kex.encryptionAlgo();
|
||||
}
|
||||
|
||||
QByteArray SshEncryptionFacility::hMacAlgoName(const SshKeyExchange &kex) const
|
||||
{
|
||||
return kex.hMacAlgoClientToServer();
|
||||
}
|
||||
|
||||
Keyed_Filter *SshEncryptionFacility::makeCipherMode(BlockCipher *cipher, Mode mode,
|
||||
const InitializationVector &iv, const SymmetricKey &key)
|
||||
{
|
||||
switch (mode) {
|
||||
case CbcMode:
|
||||
return new CBC_Encryption(cipher, new Null_Padding, key, iv);
|
||||
case CtrMode:
|
||||
return makeCtrCipherMode(cipher, iv, key);
|
||||
}
|
||||
return 0; // For dumb compilers.
|
||||
}
|
||||
|
||||
void SshEncryptionFacility::encrypt(QByteArray &data) const
|
||||
{
|
||||
convert(data, 0, data.size());
|
||||
}
|
||||
|
||||
void SshEncryptionFacility::createAuthenticationKey(const QByteArray &privKeyFileContents)
|
||||
{
|
||||
if (privKeyFileContents == m_cachedPrivKeyContents)
|
||||
return;
|
||||
|
||||
m_authKeyAlgoName.clear();
|
||||
qCDebug(sshLog, "%s: Key not cached, reading", Q_FUNC_INFO);
|
||||
QList<BigInt> pubKeyParams;
|
||||
QList<BigInt> allKeyParams;
|
||||
QString error1;
|
||||
QString error2;
|
||||
if (!createAuthenticationKeyFromPKCS8(privKeyFileContents, pubKeyParams, allKeyParams, error1)
|
||||
&& !createAuthenticationKeyFromOpenSSL(privKeyFileContents, pubKeyParams, allKeyParams,
|
||||
error2)) {
|
||||
qCDebug(sshLog, "%s: %s\n\t%s\n", Q_FUNC_INFO, qPrintable(error1), qPrintable(error2));
|
||||
throw SshClientException(SshKeyFileError, SSH_TR("Decoding of private key file failed: "
|
||||
"Format not understood."));
|
||||
}
|
||||
|
||||
foreach (const BigInt &b, allKeyParams) {
|
||||
if (b.is_zero()) {
|
||||
throw SshClientException(SshKeyFileError,
|
||||
SSH_TR("Decoding of private key file failed: Invalid zero parameter."));
|
||||
}
|
||||
}
|
||||
|
||||
m_authPubKeyBlob = AbstractSshPacket::encodeString(m_authKeyAlgoName);
|
||||
auto * const ecdsaKey = dynamic_cast<ECDSA_PrivateKey *>(m_authKey.data());
|
||||
if (ecdsaKey) {
|
||||
m_authPubKeyBlob += AbstractSshPacket::encodeString(m_authKeyAlgoName.mid(11)); // Without "ecdsa-sha2-" prefix.
|
||||
m_authPubKeyBlob += AbstractSshPacket::encodeString(
|
||||
convertByteArray(EC2OSP(ecdsaKey->public_point(), PointGFp::UNCOMPRESSED)));
|
||||
} else {
|
||||
foreach (const BigInt &b, pubKeyParams)
|
||||
m_authPubKeyBlob += AbstractSshPacket::encodeMpInt(b);
|
||||
}
|
||||
m_cachedPrivKeyContents = privKeyFileContents;
|
||||
}
|
||||
|
||||
bool SshEncryptionFacility::createAuthenticationKeyFromPKCS8(const QByteArray &privKeyFileContents,
|
||||
QList<BigInt> &pubKeyParams, QList<BigInt> &allKeyParams, QString &error)
|
||||
{
|
||||
try {
|
||||
Pipe pipe;
|
||||
pipe.process_msg(convertByteArray(privKeyFileContents), privKeyFileContents.size());
|
||||
m_authKey.reset(PKCS8::load_key(pipe, m_rng, SshKeyPasswordRetriever()));
|
||||
if (auto * const dsaKey = dynamic_cast<DSA_PrivateKey *>(m_authKey.data())) {
|
||||
m_authKeyAlgoName = SshCapabilities::PubKeyDss;
|
||||
pubKeyParams << dsaKey->group_p() << dsaKey->group_q()
|
||||
<< dsaKey->group_g() << dsaKey->get_y();
|
||||
allKeyParams << pubKeyParams << dsaKey->get_x();
|
||||
} else if (auto * const rsaKey = dynamic_cast<RSA_PrivateKey *>(m_authKey.data())) {
|
||||
m_authKeyAlgoName = SshCapabilities::PubKeyRsa;
|
||||
pubKeyParams << rsaKey->get_e() << rsaKey->get_n();
|
||||
allKeyParams << pubKeyParams << rsaKey->get_p() << rsaKey->get_q()
|
||||
<< rsaKey->get_d();
|
||||
} else if (auto * const ecdsaKey = dynamic_cast<ECDSA_PrivateKey *>(m_authKey.data())) {
|
||||
const BigInt value = ecdsaKey->private_value();
|
||||
m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(
|
||||
static_cast<int>(value.bytes()));
|
||||
pubKeyParams << ecdsaKey->public_point().get_affine_x()
|
||||
<< ecdsaKey->public_point().get_affine_y();
|
||||
allKeyParams << pubKeyParams << value;
|
||||
} else {
|
||||
qCWarning(sshLog, "%s: Unexpected code flow, expected success or exception.",
|
||||
Q_FUNC_INFO);
|
||||
return false;
|
||||
}
|
||||
} catch (const std::exception &ex) {
|
||||
error = QLatin1String(ex.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SshEncryptionFacility::createAuthenticationKeyFromOpenSSL(const QByteArray &privKeyFileContents,
|
||||
QList<BigInt> &pubKeyParams, QList<BigInt> &allKeyParams, QString &error)
|
||||
{
|
||||
try {
|
||||
bool syntaxOk = true;
|
||||
QList<QByteArray> lines = privKeyFileContents.split('\n');
|
||||
while (lines.last().isEmpty())
|
||||
lines.removeLast();
|
||||
if (lines.count() < 3) {
|
||||
syntaxOk = false;
|
||||
} else if (lines.first() == PrivKeyFileStartLineRsa) {
|
||||
if (lines.last() != PrivKeyFileEndLineRsa)
|
||||
syntaxOk = false;
|
||||
else
|
||||
m_authKeyAlgoName = SshCapabilities::PubKeyRsa;
|
||||
} else if (lines.first() == PrivKeyFileStartLineDsa) {
|
||||
if (lines.last() != PrivKeyFileEndLineDsa)
|
||||
syntaxOk = false;
|
||||
else
|
||||
m_authKeyAlgoName = SshCapabilities::PubKeyDss;
|
||||
} else if (lines.first() == PrivKeyFileStartLineEcdsa) {
|
||||
if (lines.last() != PrivKeyFileEndLineEcdsa)
|
||||
syntaxOk = false;
|
||||
// m_authKeyAlgoName set below, as we don't know the size yet.
|
||||
} else {
|
||||
syntaxOk = false;
|
||||
}
|
||||
if (!syntaxOk) {
|
||||
error = SSH_TR("Unexpected format.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray privateKeyBlob;
|
||||
for (int i = 1; i < lines.size() - 1; ++i)
|
||||
privateKeyBlob += lines.at(i);
|
||||
privateKeyBlob = QByteArray::fromBase64(privateKeyBlob);
|
||||
|
||||
BER_Decoder decoder(convertByteArray(privateKeyBlob), privateKeyBlob.size());
|
||||
BER_Decoder sequence = decoder.start_cons(SEQUENCE);
|
||||
size_t version;
|
||||
sequence.decode (version);
|
||||
const size_t expectedVersion = m_authKeyAlgoName.isEmpty() ? 1 : 0;
|
||||
if (version != expectedVersion) {
|
||||
error = SSH_TR("Key encoding has version %1, expected %2.")
|
||||
.arg(version).arg(expectedVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_authKeyAlgoName == SshCapabilities::PubKeyDss) {
|
||||
BigInt p, q, g, y, x;
|
||||
sequence.decode (p).decode (q).decode (g).decode (y).decode (x);
|
||||
DSA_PrivateKey * const dsaKey = new DSA_PrivateKey(m_rng, DL_Group(p, q, g), x);
|
||||
m_authKey.reset(dsaKey);
|
||||
pubKeyParams << p << q << g << y;
|
||||
allKeyParams << pubKeyParams << x;
|
||||
} else if (m_authKeyAlgoName == SshCapabilities::PubKeyRsa) {
|
||||
BigInt p, q, e, d, n;
|
||||
sequence.decode(n).decode(e).decode(d).decode(p).decode(q);
|
||||
RSA_PrivateKey * const rsaKey = new RSA_PrivateKey(m_rng, p, q, e, d, n);
|
||||
m_authKey.reset(rsaKey);
|
||||
pubKeyParams << e << n;
|
||||
allKeyParams << pubKeyParams << p << q << d;
|
||||
} else {
|
||||
BigInt privKey;
|
||||
sequence.decode_octet_string_bigint(privKey);
|
||||
m_authKeyAlgoName = SshCapabilities::ecdsaPubKeyAlgoForKeyWidth(
|
||||
static_cast<int>(privKey.bytes()));
|
||||
const EC_Group group(SshCapabilities::oid(m_authKeyAlgoName));
|
||||
auto * const key = new ECDSA_PrivateKey(m_rng, group, privKey);
|
||||
m_authKey.reset(key);
|
||||
pubKeyParams << key->public_point().get_affine_x()
|
||||
<< key->public_point().get_affine_y();
|
||||
allKeyParams << pubKeyParams << privKey;
|
||||
}
|
||||
|
||||
sequence.discard_remaining();
|
||||
sequence.verify_end();
|
||||
} catch (const std::exception &ex) {
|
||||
error = QLatin1String(ex.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray SshEncryptionFacility::authenticationAlgorithmName() const
|
||||
{
|
||||
Q_ASSERT(m_authKey);
|
||||
return m_authKeyAlgoName;
|
||||
}
|
||||
|
||||
QByteArray SshEncryptionFacility::authenticationKeySignature(const QByteArray &data) const
|
||||
{
|
||||
Q_ASSERT(m_authKey);
|
||||
|
||||
QScopedPointer<PK_Signer> signer(new PK_Signer(*m_authKey,
|
||||
botanEmsaAlgoName(m_authKeyAlgoName)));
|
||||
QByteArray dataToSign = AbstractSshPacket::encodeString(sessionId()) + data;
|
||||
QByteArray signature
|
||||
= convertByteArray(signer->sign_message(convertByteArray(dataToSign),
|
||||
dataToSign.size(), m_rng));
|
||||
if (m_authKeyAlgoName.startsWith(SshCapabilities::PubKeyEcdsaPrefix)) {
|
||||
// The Botan output is not quite in the format that SSH defines.
|
||||
const int halfSize = signature.count() / 2;
|
||||
const BigInt r = BigInt::decode(convertByteArray(signature), halfSize);
|
||||
const BigInt s = BigInt::decode(convertByteArray(signature.mid(halfSize)), halfSize);
|
||||
signature = AbstractSshPacket::encodeMpInt(r) + AbstractSshPacket::encodeMpInt(s);
|
||||
}
|
||||
return AbstractSshPacket::encodeString(m_authKeyAlgoName)
|
||||
+ AbstractSshPacket::encodeString(signature);
|
||||
}
|
||||
|
||||
QByteArray SshEncryptionFacility::getRandomNumbers(int count) const
|
||||
{
|
||||
QByteArray data;
|
||||
data.resize(count);
|
||||
m_rng.randomize(convertByteArray(data), count);
|
||||
return data;
|
||||
}
|
||||
|
||||
SshEncryptionFacility::~SshEncryptionFacility() {}
|
||||
|
||||
|
||||
QByteArray SshDecryptionFacility::cryptAlgoName(const SshKeyExchange &kex) const
|
||||
{
|
||||
return kex.decryptionAlgo();
|
||||
}
|
||||
|
||||
QByteArray SshDecryptionFacility::hMacAlgoName(const SshKeyExchange &kex) const
|
||||
{
|
||||
return kex.hMacAlgoServerToClient();
|
||||
}
|
||||
|
||||
Keyed_Filter *SshDecryptionFacility::makeCipherMode(BlockCipher *cipher, Mode mode, const InitializationVector &iv,
|
||||
const SymmetricKey &key)
|
||||
{
|
||||
switch (mode) {
|
||||
case CbcMode:
|
||||
return new CBC_Decryption(cipher, new Null_Padding, key, iv);
|
||||
case CtrMode:
|
||||
return makeCtrCipherMode(cipher, iv, key);
|
||||
}
|
||||
return 0; // For dumb compilers.
|
||||
}
|
||||
|
||||
void SshDecryptionFacility::decrypt(QByteArray &data, quint32 offset,
|
||||
quint32 dataSize) const
|
||||
{
|
||||
convert(data, offset, dataSize);
|
||||
qCDebug(sshLog, "Decrypted data:");
|
||||
const char * const start = data.constData() + offset;
|
||||
const char * const end = start + dataSize;
|
||||
for (const char *c = start; c < end; ++c)
|
||||
qCDebug(sshLog, ) << "'" << *c << "' (0x" << (static_cast<int>(*c) & 0xff) << ")";
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
138
client/3rd/QtSsh/src/ssh/sshcryptofacility_p.h
Executable file
138
client/3rd/QtSsh/src/ssh/sshcryptofacility_p.h
Executable file
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <botan/botan.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
class SshKeyExchange;
|
||||
|
||||
class SshAbstractCryptoFacility
|
||||
{
|
||||
public:
|
||||
virtual ~SshAbstractCryptoFacility();
|
||||
|
||||
void clearKeys();
|
||||
void recreateKeys(const SshKeyExchange &kex);
|
||||
QByteArray generateMac(const QByteArray &data, quint32 dataSize) const;
|
||||
quint32 cipherBlockSize() const { return m_cipherBlockSize; }
|
||||
quint32 macLength() const { return m_macLength; }
|
||||
|
||||
protected:
|
||||
enum Mode { CbcMode, CtrMode };
|
||||
|
||||
SshAbstractCryptoFacility();
|
||||
void convert(QByteArray &data, quint32 offset, quint32 dataSize) const;
|
||||
QByteArray sessionId() const { return m_sessionId; }
|
||||
Botan::Keyed_Filter *makeCtrCipherMode(Botan::BlockCipher *cipher,
|
||||
const Botan::InitializationVector &iv, const Botan::SymmetricKey &key);
|
||||
|
||||
private:
|
||||
SshAbstractCryptoFacility(const SshAbstractCryptoFacility &);
|
||||
SshAbstractCryptoFacility &operator=(const SshAbstractCryptoFacility &);
|
||||
|
||||
virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const = 0;
|
||||
virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const = 0;
|
||||
virtual Botan::Keyed_Filter *makeCipherMode(Botan::BlockCipher *cipher,
|
||||
Mode mode, const Botan::InitializationVector &iv, const Botan::SymmetricKey &key) = 0;
|
||||
virtual char ivChar() const = 0;
|
||||
virtual char keyChar() const = 0;
|
||||
virtual char macChar() const = 0;
|
||||
|
||||
QByteArray generateHash(const SshKeyExchange &kex, char c, quint32 length);
|
||||
void checkInvariant() const;
|
||||
static Mode getMode(const QByteArray &algoName);
|
||||
|
||||
QByteArray m_sessionId;
|
||||
QScopedPointer<Botan::Pipe> m_pipe;
|
||||
QScopedPointer<Botan::HMAC> m_hMac;
|
||||
quint32 m_cipherBlockSize;
|
||||
quint32 m_macLength;
|
||||
};
|
||||
|
||||
class SshEncryptionFacility : public SshAbstractCryptoFacility
|
||||
{
|
||||
public:
|
||||
void encrypt(QByteArray &data) const;
|
||||
|
||||
void createAuthenticationKey(const QByteArray &privKeyFileContents);
|
||||
QByteArray authenticationAlgorithmName() const;
|
||||
QByteArray authenticationPublicKey() const { return m_authPubKeyBlob; }
|
||||
QByteArray authenticationKeySignature(const QByteArray &data) const;
|
||||
QByteArray getRandomNumbers(int count) const;
|
||||
|
||||
~SshEncryptionFacility();
|
||||
|
||||
private:
|
||||
virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const;
|
||||
virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const;
|
||||
virtual Botan::Keyed_Filter *makeCipherMode(Botan::BlockCipher *cipher,
|
||||
Mode mode, const Botan::InitializationVector &iv, const Botan::SymmetricKey &key);
|
||||
virtual char ivChar() const { return 'A'; }
|
||||
virtual char keyChar() const { return 'C'; }
|
||||
virtual char macChar() const { return 'E'; }
|
||||
|
||||
bool createAuthenticationKeyFromPKCS8(const QByteArray &privKeyFileContents,
|
||||
QList<Botan::BigInt> &pubKeyParams, QList<Botan::BigInt> &allKeyParams, QString &error);
|
||||
bool createAuthenticationKeyFromOpenSSL(const QByteArray &privKeyFileContents,
|
||||
QList<Botan::BigInt> &pubKeyParams, QList<Botan::BigInt> &allKeyParams, QString &error);
|
||||
|
||||
static const QByteArray PrivKeyFileStartLineRsa;
|
||||
static const QByteArray PrivKeyFileStartLineDsa;
|
||||
static const QByteArray PrivKeyFileEndLineRsa;
|
||||
static const QByteArray PrivKeyFileEndLineDsa;
|
||||
static const QByteArray PrivKeyFileStartLineEcdsa;
|
||||
static const QByteArray PrivKeyFileEndLineEcdsa;
|
||||
|
||||
QByteArray m_authKeyAlgoName;
|
||||
QByteArray m_authPubKeyBlob;
|
||||
QByteArray m_cachedPrivKeyContents;
|
||||
QScopedPointer<Botan::Private_Key> m_authKey;
|
||||
mutable Botan::AutoSeeded_RNG m_rng;
|
||||
};
|
||||
|
||||
class SshDecryptionFacility : public SshAbstractCryptoFacility
|
||||
{
|
||||
public:
|
||||
void decrypt(QByteArray &data, quint32 offset, quint32 dataSize) const;
|
||||
|
||||
private:
|
||||
virtual QByteArray cryptAlgoName(const SshKeyExchange &kex) const;
|
||||
virtual QByteArray hMacAlgoName(const SshKeyExchange &kex) const;
|
||||
virtual Botan::Keyed_Filter *makeCipherMode(Botan::BlockCipher *cipher,
|
||||
Mode mode, const Botan::InitializationVector &iv, const Botan::SymmetricKey &key);
|
||||
virtual char ivChar() const { return 'B'; }
|
||||
virtual char keyChar() const { return 'D'; }
|
||||
virtual char macChar() const { return 'F'; }
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
122
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel.cpp
Executable file
122
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel.cpp
Executable file
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshdirecttcpiptunnel.h"
|
||||
#include "sshdirecttcpiptunnel_p.h"
|
||||
|
||||
#include "sshincomingpacket_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
SshDirectTcpIpTunnelPrivate::SshDirectTcpIpTunnelPrivate(quint32 channelId,
|
||||
const QString &originatingHost, quint16 originatingPort, const QString &remoteHost,
|
||||
quint16 remotePort, SshSendFacility &sendFacility)
|
||||
: SshTcpIpTunnelPrivate(channelId, sendFacility),
|
||||
m_originatingHost(originatingHost),
|
||||
m_originatingPort(originatingPort),
|
||||
m_remoteHost(remoteHost),
|
||||
m_remotePort(remotePort)
|
||||
{
|
||||
}
|
||||
|
||||
void SshDirectTcpIpTunnelPrivate::handleOpenSuccessInternal()
|
||||
{
|
||||
emit initialized();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
SshDirectTcpIpTunnel::SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort,
|
||||
SshSendFacility &sendFacility)
|
||||
: d(new SshDirectTcpIpTunnelPrivate(channelId, originatingHost, originatingPort, remoteHost,
|
||||
remotePort, sendFacility))
|
||||
{
|
||||
d->init(this);
|
||||
connect(d, &SshDirectTcpIpTunnelPrivate::initialized,
|
||||
this, &SshDirectTcpIpTunnel::initialized, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
SshDirectTcpIpTunnel::~SshDirectTcpIpTunnel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool SshDirectTcpIpTunnel::atEnd() const
|
||||
{
|
||||
return QIODevice::atEnd() && d->m_data.isEmpty();
|
||||
}
|
||||
|
||||
qint64 SshDirectTcpIpTunnel::bytesAvailable() const
|
||||
{
|
||||
return QIODevice::bytesAvailable() + d->m_data.count();
|
||||
}
|
||||
|
||||
bool SshDirectTcpIpTunnel::canReadLine() const
|
||||
{
|
||||
return QIODevice::canReadLine() || d->m_data.contains('\n');
|
||||
}
|
||||
|
||||
void SshDirectTcpIpTunnel::close()
|
||||
{
|
||||
d->closeChannel();
|
||||
QIODevice::close();
|
||||
}
|
||||
|
||||
void SshDirectTcpIpTunnel::initialize()
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN(d->channelState() == AbstractSshChannel::Inactive);
|
||||
|
||||
try {
|
||||
QIODevice::open(QIODevice::ReadWrite);
|
||||
d->m_sendFacility.sendDirectTcpIpPacket(d->localChannelId(), d->initialWindowSize(),
|
||||
d->maxPacketSize(), d->m_remoteHost.toUtf8(), d->m_remotePort,
|
||||
d->m_originatingHost.toUtf8(), d->m_originatingPort);
|
||||
d->setChannelState(AbstractSshChannel::SessionRequested);
|
||||
d->m_timeoutTimer.start(d->ReplyTimeout);
|
||||
} catch (const std::exception &e) { // Won't happen, but let's play it safe.
|
||||
qCWarning(sshLog, "Botan error: %s", e.what());
|
||||
d->closeChannel();
|
||||
}
|
||||
}
|
||||
|
||||
qint64 SshDirectTcpIpTunnel::readData(char *data, qint64 maxlen)
|
||||
{
|
||||
return d->readData(data, maxlen);
|
||||
}
|
||||
|
||||
qint64 SshDirectTcpIpTunnel::writeData(const char *data, qint64 len)
|
||||
{
|
||||
return d->writeData(data, len);
|
||||
}
|
||||
|
||||
} // namespace QSsh
|
||||
79
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel.h
Executable file
79
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel.h
Executable file
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ssh_global.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
namespace Internal {
|
||||
class SshChannelManager;
|
||||
class SshDirectTcpIpTunnelPrivate;
|
||||
class SshSendFacility;
|
||||
class SshTcpIpTunnelPrivate;
|
||||
} // namespace Internal
|
||||
|
||||
class QSSH_EXPORT SshDirectTcpIpTunnel : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class Internal::SshChannelManager;
|
||||
friend class Internal::SshTcpIpTunnelPrivate;
|
||||
|
||||
public:
|
||||
typedef QSharedPointer<SshDirectTcpIpTunnel> Ptr;
|
||||
|
||||
~SshDirectTcpIpTunnel();
|
||||
|
||||
// QIODevice stuff
|
||||
bool atEnd() const;
|
||||
qint64 bytesAvailable() const;
|
||||
bool canReadLine() const;
|
||||
void close();
|
||||
bool isSequential() const { return true; }
|
||||
|
||||
void initialize();
|
||||
|
||||
signals:
|
||||
void initialized();
|
||||
void error(const QString &reason);
|
||||
|
||||
private:
|
||||
SshDirectTcpIpTunnel(quint32 channelId, const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort,
|
||||
Internal::SshSendFacility &sendFacility);
|
||||
|
||||
// QIODevice stuff
|
||||
qint64 readData(char *data, qint64 maxlen);
|
||||
qint64 writeData(const char *data, qint64 len);
|
||||
|
||||
Internal::SshDirectTcpIpTunnelPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
59
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel_p.h
Executable file
59
client/3rd/QtSsh/src/ssh/sshdirecttcpiptunnel_p.h
Executable file
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sshtcpiptunnel_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
class SshDirectTcpIpTunnel;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class SshDirectTcpIpTunnelPrivate : public SshTcpIpTunnelPrivate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class QSsh::SshDirectTcpIpTunnel;
|
||||
|
||||
public:
|
||||
explicit SshDirectTcpIpTunnelPrivate(quint32 channelId, const QString &originatingHost,
|
||||
quint16 originatingPort, const QString &remoteHost, quint16 remotePort,
|
||||
SshSendFacility &sendFacility);
|
||||
|
||||
signals:
|
||||
void initialized();
|
||||
|
||||
private:
|
||||
void handleOpenSuccessInternal();
|
||||
|
||||
const QString m_originatingHost;
|
||||
const quint16 m_originatingPort;
|
||||
const QString m_remoteHost;
|
||||
const quint16 m_remotePort;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
37
client/3rd/QtSsh/src/ssh/ssherrors.h
Executable file
37
client/3rd/QtSsh/src/ssh/ssherrors.h
Executable file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#define SSHERRORS_P_H
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
enum SshError {
|
||||
SshNoError, SshSocketError, SshTimeoutError, SshProtocolError,
|
||||
SshHostKeyError, SshKeyFileError, SshAuthenticationError,
|
||||
SshClosedByServerError, SshInternalError
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
82
client/3rd/QtSsh/src/ssh/sshexception_p.h
Executable file
82
client/3rd/QtSsh/src/ssh/sshexception_p.h
Executable file
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ssherrors.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
enum SshErrorCode {
|
||||
SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1,
|
||||
SSH_DISCONNECT_PROTOCOL_ERROR = 2,
|
||||
SSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3,
|
||||
SSH_DISCONNECT_RESERVED = 4,
|
||||
SSH_DISCONNECT_MAC_ERROR = 5,
|
||||
SSH_DISCONNECT_COMPRESSION_ERROR = 6,
|
||||
SSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7,
|
||||
SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8,
|
||||
SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9,
|
||||
SSH_DISCONNECT_CONNECTION_LOST = 10,
|
||||
SSH_DISCONNECT_BY_APPLICATION = 11,
|
||||
SSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12,
|
||||
SSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13,
|
||||
SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14,
|
||||
SSH_DISCONNECT_ILLEGAL_USER_NAME = 15
|
||||
};
|
||||
|
||||
#define SSH_TR(string) QCoreApplication::translate("SshConnection", string)
|
||||
|
||||
#define SSH_SERVER_EXCEPTION(error, errorString) \
|
||||
SshServerException((error), (errorString), SSH_TR(errorString))
|
||||
|
||||
struct SshServerException
|
||||
{
|
||||
SshServerException(SshErrorCode error, const QByteArray &errorStringServer,
|
||||
const QString &errorStringUser)
|
||||
: error(error), errorStringServer(errorStringServer),
|
||||
errorStringUser(errorStringUser) {}
|
||||
|
||||
const SshErrorCode error;
|
||||
const QByteArray errorStringServer;
|
||||
const QString errorStringUser;
|
||||
};
|
||||
|
||||
struct SshClientException
|
||||
{
|
||||
SshClientException(SshError error, const QString &errorString)
|
||||
: error(error), errorString(errorString) {}
|
||||
|
||||
const SshError error;
|
||||
const QString errorString;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
100
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel.cpp
Executable file
100
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel.cpp
Executable file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sshforwardedtcpiptunnel.h"
|
||||
#include "sshforwardedtcpiptunnel_p.h"
|
||||
#include "sshlogging_p.h"
|
||||
#include "sshsendfacility_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
namespace Internal {
|
||||
SshForwardedTcpIpTunnelPrivate::SshForwardedTcpIpTunnelPrivate(quint32 channelId,
|
||||
SshSendFacility &sendFacility) :
|
||||
SshTcpIpTunnelPrivate(channelId, sendFacility)
|
||||
{
|
||||
setChannelState(SessionRequested);
|
||||
}
|
||||
|
||||
void SshForwardedTcpIpTunnelPrivate::handleOpenSuccessInternal()
|
||||
{
|
||||
QSSH_ASSERT_AND_RETURN(channelState() == AbstractSshChannel::SessionEstablished);
|
||||
|
||||
try {
|
||||
m_sendFacility.sendChannelOpenConfirmationPacket(remoteChannel(), localChannelId(),
|
||||
initialWindowSize(), maxPacketSize());
|
||||
} catch (const std::exception &e) { // Won't happen, but let's play it safe.
|
||||
qCWarning(sshLog, "Botan error: %s", e.what());
|
||||
closeChannel();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
SshForwardedTcpIpTunnel::SshForwardedTcpIpTunnel(quint32 channelId, SshSendFacility &sendFacility) :
|
||||
d(new SshForwardedTcpIpTunnelPrivate(channelId, sendFacility))
|
||||
{
|
||||
d->init(this);
|
||||
}
|
||||
|
||||
SshForwardedTcpIpTunnel::~SshForwardedTcpIpTunnel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool SshForwardedTcpIpTunnel::atEnd() const
|
||||
{
|
||||
return QIODevice::atEnd() && d->m_data.isEmpty();
|
||||
}
|
||||
|
||||
qint64 SshForwardedTcpIpTunnel::bytesAvailable() const
|
||||
{
|
||||
return QIODevice::bytesAvailable() + d->m_data.count();
|
||||
}
|
||||
|
||||
bool SshForwardedTcpIpTunnel::canReadLine() const
|
||||
{
|
||||
return QIODevice::canReadLine() || d->m_data.contains('\n');
|
||||
}
|
||||
|
||||
void SshForwardedTcpIpTunnel::close()
|
||||
{
|
||||
d->closeChannel();
|
||||
QIODevice::close();
|
||||
}
|
||||
|
||||
qint64 SshForwardedTcpIpTunnel::readData(char *data, qint64 maxlen)
|
||||
{
|
||||
return d->readData(data, maxlen);
|
||||
}
|
||||
|
||||
qint64 SshForwardedTcpIpTunnel::writeData(const char *data, qint64 len)
|
||||
{
|
||||
return d->writeData(data, len);
|
||||
}
|
||||
|
||||
} // namespace QSsh
|
||||
70
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel.h
Executable file
70
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel.h
Executable file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "ssh_global.h"
|
||||
#include <QIODevice>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace QSsh {
|
||||
|
||||
namespace Internal {
|
||||
class SshChannelManager;
|
||||
class SshForwardedTcpIpTunnelPrivate;
|
||||
class SshSendFacility;
|
||||
class SshTcpIpTunnelPrivate;
|
||||
} // namespace Internal
|
||||
|
||||
class QSSH_EXPORT SshForwardedTcpIpTunnel : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class Internal::SshChannelManager;
|
||||
friend class Internal::SshTcpIpTunnelPrivate;
|
||||
|
||||
public:
|
||||
typedef QSharedPointer<SshForwardedTcpIpTunnel> Ptr;
|
||||
~SshForwardedTcpIpTunnel() override;
|
||||
|
||||
// QIODevice stuff
|
||||
bool atEnd() const override;
|
||||
qint64 bytesAvailable() const override;
|
||||
bool canReadLine() const override;
|
||||
void close() override;
|
||||
bool isSequential() const override { return true; }
|
||||
|
||||
signals:
|
||||
void error(const QString &reason);
|
||||
|
||||
private:
|
||||
SshForwardedTcpIpTunnel(quint32 channelId, Internal::SshSendFacility &sendFacility);
|
||||
|
||||
// QIODevice stuff
|
||||
qint64 readData(char *data, qint64 maxlen) override;
|
||||
qint64 writeData(const char *data, qint64 len) override;
|
||||
|
||||
Internal::SshForwardedTcpIpTunnelPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace QSsh
|
||||
44
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel_p.h
Executable file
44
client/3rd/QtSsh/src/ssh/sshforwardedtcpiptunnel_p.h
Executable file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sshforwardedtcpiptunnel.h"
|
||||
#include "sshtcpiptunnel_p.h"
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
|
||||
class SshForwardedTcpIpTunnelPrivate : public SshTcpIpTunnelPrivate
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class QSsh::SshForwardedTcpIpTunnel;
|
||||
public:
|
||||
SshForwardedTcpIpTunnelPrivate(quint32 channelId, SshSendFacility &sendFacility);
|
||||
void handleOpenSuccessInternal() override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QSsh
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user