Compare commits
	
		
			67 Commits
		
	
	
		
			v1.12-r9-b
			...
			feature/up
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					da245f3f88 | ||
| 
						 | 
					1e18763f8d | ||
| 
						 | 
					82c3b0546c | ||
| 
						 | 
					f246726ab7 | ||
| 
						 | 
					331daa7e12 | ||
| 
						 | 
					9be215c295 | ||
| 
						 | 
					bb97a023de | ||
| 
						 | 
					edb4907bf5 | ||
| 
						 | 
					a718c7ed7e | ||
| 
						 | 
					4f11789f26 | ||
| 
						 | 
					eb15861b13 | ||
| 
						 | 
					8c2c8049c8 | ||
| 
						 | 
					2f3761b0a7 | ||
| 
						 | 
					260bc8adb2 | ||
| 
						 | 
					87e979635b | ||
| 
						 | 
					0c9c163755 | ||
| 
						 | 
					74ceea562b | ||
| 
						 | 
					c6a5362ecb | ||
| 
						 | 
					f655a89be0 | ||
| 
						 | 
					0d6f837578 | ||
| 
						 | 
					8c61b028b7 | ||
| 
						 | 
					a3d5273285 | ||
| 
						 | 
					93cf4f790c | ||
| 
						 | 
					cd323c0a22 | ||
| 
						 | 
					99ca8bf953 | ||
| 
						 | 
					d40b3dc15c | ||
| 
						 | 
					057a7e2f7a | ||
| 
						 | 
					1b73c536d5 | ||
| 
						 | 
					2593a8548f | ||
| 
						 | 
					13306a9076 | ||
| 
						 | 
					cfb5098b38 | ||
| 
						 | 
					d04d455fbd | ||
| 
						 | 
					b83c4b3772 | ||
| 
						 | 
					f03c11381e | ||
| 
						 | 
					8a03ddb7f3 | ||
| 
						 | 
					913222d7cb | ||
| 
						 | 
					3e6d86c206 | ||
| 
						 | 
					d6ce2a32e9 | ||
| 
						 | 
					21f1c8404c | ||
| 
						 | 
					16ff81cf81 | ||
| 
						 | 
					0636f687ac | ||
| 
						 | 
					60d8900473 | ||
| 
						 | 
					4b2d2ef768 | ||
| 
						 | 
					48899ba9a0 | ||
| 
						 | 
					092b8689b8 | ||
| 
						 | 
					3d3ba45cb1 | ||
| 
						 | 
					b380100307 | ||
| 
						 | 
					4c5ddd59d8 | ||
| 
						 | 
					5ed183f318 | ||
| 
						 | 
					9c27fd3e78 | ||
| 
						 | 
					62c361feb0 | ||
| 
						 | 
					0ee2495528 | ||
| 
						 | 
					7dc635a625 | ||
| 
						 | 
					e15112c3b4 | ||
| 
						 | 
					1d85fffb18 | ||
| 
						 | 
					5e2f29e737 | ||
| 
						 | 
					89a09ea142 | ||
| 
						 | 
					628c0d2c19 | ||
| 
						 | 
					426fbc2510 | ||
| 
						 | 
					e89a961c02 | ||
| 
						 | 
					766c29b7a9 | ||
| 
						 | 
					c4206e58bf | ||
| 
						 | 
					630ededf3b | ||
| 
						 | 
					ba7b02cd1e | ||
| 
						 | 
					aec9441de4 | ||
| 
						 | 
					5edf42254d | ||
| 
						 | 
					a51bfb102f | 
							
								
								
									
										16
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							@@ -325,15 +325,21 @@ jobs:
 | 
			
		||||
        make dotnetbuild Flavor=Net          
 | 
			
		||||
 | 
			
		||||
    - name: Build APK (net)
 | 
			
		||||
      if: github.ref == 'refs/heads/master'
 | 
			
		||||
      env:
 | 
			
		||||
        DropboxAppKey: ${{ secrets.DROPBOX_APP_KEY }}
 | 
			
		||||
        DropboxAppSecret: ${{ secrets.DROPBOX_APP_SECRET }}
 | 
			
		||||
        DropboxAppFolderAppKey: ${{ secrets.DROPBOX_APP_FOLDER_APP_KEY }}
 | 
			
		||||
        DropboxAppFolderAppSecret: ${{ secrets.DROPBOX_APP_FOLDER_APP_SECRET }}
 | 
			
		||||
      run: |
 | 
			
		||||
        make apk Flavor=Net
 | 
			
		||||
        make apk Configuration=Release Flavor=Net
 | 
			
		||||
 | 
			
		||||
    - name: Archive production artifacts (net)
 | 
			
		||||
      uses: actions/upload-artifact@v4
 | 
			
		||||
      with:
 | 
			
		||||
        name: signed APK ('net' built on ${{ github.job }})
 | 
			
		||||
        name: archive APK ('net' built on ${{ github.job }})
 | 
			
		||||
        path: |
 | 
			
		||||
          src/keepass2android/bin/*/*-Signed.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk
 | 
			
		||||
 | 
			
		||||
    - name: Select the manifest
 | 
			
		||||
      run: |
 | 
			
		||||
@@ -357,7 +363,7 @@ jobs:
 | 
			
		||||
    - name: Archive production artifacts (nonet)
 | 
			
		||||
      uses: actions/upload-artifact@v4
 | 
			
		||||
      with:
 | 
			
		||||
        name: signed APK ('nonet' built on ${{ github.job }})
 | 
			
		||||
        name: archive APK ('nonet' built on ${{ github.job }})
 | 
			
		||||
        path: |
 | 
			
		||||
          src/keepass2android/bin/*/*-Signed.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							@@ -3,9 +3,9 @@ env:
 | 
			
		||||
  NAME: 'Release'
 | 
			
		||||
 | 
			
		||||
on:
 | 
			
		||||
  push:
 | 
			
		||||
    tags:
 | 
			
		||||
      - "v1.*"
 | 
			
		||||
  # the workflow is always triggered manually. This allows to test the apks
 | 
			
		||||
  # before publishing the release and not having a broken tag in the repo if that test fails.
 | 
			
		||||
  workflow_dispatch: 
 | 
			
		||||
jobs:
 | 
			
		||||
 | 
			
		||||
  build-release:
 | 
			
		||||
@@ -128,17 +128,19 @@ jobs:
 | 
			
		||||
      uses: actions/upload-artifact@v4
 | 
			
		||||
      with:
 | 
			
		||||
        name: keepass2android_${{ matrix.target }}_${{ matrix.flavor }}
 | 
			
		||||
        # the first line is for "apk" target, the second line is for "apk_split" target
 | 
			
		||||
        path: |
 | 
			
		||||
          src/keepass2android-app/bin/Release/net8.0-android/publish/*.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net8.0-android/*/publish/*.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/*/publish/*.apk
 | 
			
		||||
    
 | 
			
		||||
    - name: List apks
 | 
			
		||||
      run:  find . -type f -name "*.apk"
 | 
			
		||||
      shell: bash
 | 
			
		||||
      
 | 
			
		||||
    #- name: Upload APK to GitHub Release
 | 
			
		||||
    #  uses: softprops/action-gh-release@v2
 | 
			
		||||
    #  if: github.ref_type == 'tag'
 | 
			
		||||
    #  with:
 | 
			
		||||
    #    files: |
 | 
			
		||||
    #        src/keepass2android-app/bin/Release/net8.0-android/*/publish/*.apk src/keepass2android-app/bin/Release/net8.0-android/publish/*.apk
 | 
			
		||||
    - name: Upload APK to GitHub Release
 | 
			
		||||
      uses: softprops/action-gh-release@v2
 | 
			
		||||
      with:
 | 
			
		||||
        draft: true
 | 
			
		||||
        files: |
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk
 | 
			
		||||
          src/keepass2android-app/bin/Release/net9.0-android/*/publish/*.apk
 | 
			
		||||
 
 | 
			
		||||
@@ -11,10 +11,10 @@ Regular stable releases of Keepass2Android are available on [Google Play](https:
 | 
			
		||||
Beta-releases can be obtained by opting in to the [Beta testing channel](https://play.google.com/apps/testing/keepass2android.keepass2android) or [Beta testing channel for Keepass2Android Offline](https://play.google.com/apps/testing/keepass2android.keepass2android_nonet).
 | 
			
		||||
 | 
			
		||||
# How can I contribute?
 | 
			
		||||
* Help to translate Keepass2Android into your language or improve translations at [our Crowdin page](http://crowdin.net/project/keepass2android)
 | 
			
		||||
* Help to translate Keepass2Android into your language or improve translations at [our Crowdin page](https://crowdin.net/project/keepass2android)
 | 
			
		||||
* Add features by [creating a plugin](How-to-create-a-plug-in_.md) or creating a pull request. You might want to contact me before you start working so I can coordinate efforts.
 | 
			
		||||
* [Become a GitHub sponsor to boost 🚀 development](https://github.com/sponsors/PhilippC)
 | 
			
		||||
* [Make a donation](http://philipp.crocoll.net/donate.php)
 | 
			
		||||
* [Make a donation](https://philipp.crocoll.net/donate.php)
 | 
			
		||||
 | 
			
		||||
# How do I learn more?
 | 
			
		||||
Please see the [wiki](https://github.com/PhilippC/keepass2android/wiki/Documentation) for further information.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
@@ -34,5 +34,6 @@
 | 
			
		||||
    <AndroidLibrary Bind="False" Update="okhttp-digest-3.1.0.jar" />
 | 
			
		||||
    <AndroidLibrary Bind="False" Update="okio-3.6.0.jar" />
 | 
			
		||||
    <AndroidLibrary Bind="False" Update="okio-jvm-3.6.0.jar" />
 | 
			
		||||
    <AndroidLibrary Bind="False" Update="jsch-2.27.2.jar" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								src/JavaFileStorageBindings/jsch-2.27.2.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/JavaFileStorageBindings/jsch-2.27.2.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -40,8 +40,8 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        Null = 0,
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
		/// A variant of the ARCFour algorithm (RC4 incompatible).
 | 
			
		||||
		/// </summary>
 | 
			
		||||
        /// A variant of the ArcFour algorithm (RC4 incompatible).
 | 
			
		||||
        /// Insecure; for backward compatibility only.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        ArcFourVariant = 1,
 | 
			
		||||
 | 
			
		||||
@@ -66,56 +66,60 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class CryptoRandomStream : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
		private readonly CrsAlgorithm m_crsAlgorithm;
 | 
			
		||||
        private readonly CrsAlgorithm m_alg;
 | 
			
		||||
        private bool m_bDisposed = false;
 | 
			
		||||
 | 
			
		||||
		private byte[] m_pbState = null;
 | 
			
		||||
        private readonly byte[] m_pbKey = null;
 | 
			
		||||
        private readonly byte[] m_pbIV = null;
 | 
			
		||||
 | 
			
		||||
        private readonly ChaCha20Cipher m_chacha20 = null;
 | 
			
		||||
        private readonly Salsa20Cipher m_salsa20 = null;
 | 
			
		||||
 | 
			
		||||
        private readonly byte[] m_pbState = null;
 | 
			
		||||
        private byte m_i = 0;
 | 
			
		||||
        private byte m_j = 0;
 | 
			
		||||
 | 
			
		||||
		private Salsa20Cipher m_salsa20 = null;
 | 
			
		||||
		private ChaCha20Cipher m_chacha20 = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Construct a new cryptographically secure random stream object.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
		/// <param name="genAlgorithm">Algorithm to use.</param>
 | 
			
		||||
		/// <param name="pbKey">Initialization key. Must not be <c>null</c> and
 | 
			
		||||
		/// must contain at least 1 byte.</param>
 | 
			
		||||
        /// <param name="a">Algorithm to use.</param>
 | 
			
		||||
        /// <param name="pbKey">Initialization key. Must not be <c>null</c>
 | 
			
		||||
        /// and must contain at least 1 byte.</param>
 | 
			
		||||
        public CryptoRandomStream(CrsAlgorithm a, byte[] pbKey)
 | 
			
		||||
        {
 | 
			
		||||
            if (pbKey == null) { Debug.Assert(false); throw new ArgumentNullException("pbKey"); }
 | 
			
		||||
		/// <exception cref="System.ArgumentNullException">Thrown if the
 | 
			
		||||
 | 
			
		||||
            int cbKey = pbKey.Length;
 | 
			
		||||
            if (cbKey <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                Debug.Assert(false); // Need at least one byte
 | 
			
		||||
                throw new ArgumentOutOfRangeException("pbKey");
 | 
			
		||||
            }
 | 
			
		||||
		/// <paramref name="pbKey" /> parameter is <c>null</c>.</exception>
 | 
			
		||||
			m_crsAlgorithm = a;
 | 
			
		||||
		/// <exception cref="System.ArgumentException">Thrown if the
 | 
			
		||||
 | 
			
		||||
            m_alg = a;
 | 
			
		||||
 | 
			
		||||
            if (a == CrsAlgorithm.ChaCha20)
 | 
			
		||||
            {
 | 
			
		||||
				byte[] pbKey32 = new byte[32];
 | 
			
		||||
				byte[] pbIV12 = new byte[12];
 | 
			
		||||
		/// <paramref name="pbKey" /> parameter contains no bytes or the
 | 
			
		||||
                m_pbKey = new byte[32];
 | 
			
		||||
                m_pbIV = new byte[12];
 | 
			
		||||
 | 
			
		||||
                using (SHA512Managed h = new SHA512Managed())
 | 
			
		||||
                {
 | 
			
		||||
                    byte[] pbHash = h.ComputeHash(pbKey);
 | 
			
		||||
					Array.Copy(pbHash, pbKey32, 32);
 | 
			
		||||
					Array.Copy(pbHash, 32, pbIV12, 0, 12);
 | 
			
		||||
                    Array.Copy(pbHash, m_pbKey, 32);
 | 
			
		||||
                    Array.Copy(pbHash, 32, m_pbIV, 0, 12);
 | 
			
		||||
                    MemUtil.ZeroByteArray(pbHash);
 | 
			
		||||
                }
 | 
			
		||||
		/// algorithm is unknown.</exception>
 | 
			
		||||
				m_chacha20 = new ChaCha20Cipher(pbKey32, pbIV12, true);
 | 
			
		||||
 | 
			
		||||
                m_chacha20 = new ChaCha20Cipher(m_pbKey, m_pbIV, true);
 | 
			
		||||
            }
 | 
			
		||||
            else if (a == CrsAlgorithm.Salsa20)
 | 
			
		||||
            {
 | 
			
		||||
				byte[] pbKey32 = CryptoUtil.HashSha256(pbKey);
 | 
			
		||||
				byte[] pbIV8 = new byte[8] { 0xE8, 0x30, 0x09, 0x4B,
 | 
			
		||||
                m_pbKey = CryptoUtil.HashSha256(pbKey);
 | 
			
		||||
                m_pbIV = new byte[8] { 0xE8, 0x30, 0x09, 0x4B,
 | 
			
		||||
                    0x97, 0x20, 0x5D, 0x2A }; // Unique constant
 | 
			
		||||
 | 
			
		||||
				m_salsa20 = new Salsa20Cipher(pbKey32, pbIV8);
 | 
			
		||||
                m_salsa20 = new Salsa20Cipher(m_pbKey, m_pbIV);
 | 
			
		||||
            }
 | 
			
		||||
            else if (a == CrsAlgorithm.ArcFourVariant)
 | 
			
		||||
            {
 | 
			
		||||
@@ -159,17 +163,22 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        {
 | 
			
		||||
            if (disposing)
 | 
			
		||||
            {
 | 
			
		||||
				if(m_crsAlgorithm == CrsAlgorithm.ChaCha20)
 | 
			
		||||
                if (m_alg == CrsAlgorithm.ChaCha20)
 | 
			
		||||
                    m_chacha20.Dispose();
 | 
			
		||||
				else if(m_crsAlgorithm == CrsAlgorithm.Salsa20)
 | 
			
		||||
                else if (m_alg == CrsAlgorithm.Salsa20)
 | 
			
		||||
                    m_salsa20.Dispose();
 | 
			
		||||
				else if(m_crsAlgorithm == CrsAlgorithm.ArcFourVariant)
 | 
			
		||||
                else if (m_alg == CrsAlgorithm.ArcFourVariant)
 | 
			
		||||
                {
 | 
			
		||||
                    MemUtil.ZeroByteArray(m_pbState);
 | 
			
		||||
                    m_i = 0;
 | 
			
		||||
                    m_j = 0;
 | 
			
		||||
                }
 | 
			
		||||
                else { Debug.Assert(false); }
 | 
			
		||||
 | 
			
		||||
                if (m_pbKey != null) MemUtil.ZeroByteArray(m_pbKey);
 | 
			
		||||
                if (m_pbIV != null) MemUtil.ZeroByteArray(m_pbIV);
 | 
			
		||||
 | 
			
		||||
                m_bDisposed = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -180,19 +189,20 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        /// <returns>Returns <paramref name="uRequestedCount" /> random bytes.</returns>
 | 
			
		||||
        public byte[] GetRandomBytes(uint uRequestedCount)
 | 
			
		||||
        {
 | 
			
		||||
			if(uRequestedCount == 0) return MemUtil.EmptyByteArray;
 | 
			
		||||
            if (m_bDisposed) throw new ObjectDisposedException(null);
 | 
			
		||||
 | 
			
		||||
            if (uRequestedCount == 0) return MemUtil.EmptyByteArray;
 | 
			
		||||
            if (uRequestedCount > (uint)int.MaxValue)
 | 
			
		||||
                throw new ArgumentOutOfRangeException("uRequestedCount");
 | 
			
		||||
            int cb = (int)uRequestedCount;
 | 
			
		||||
 | 
			
		||||
            byte[] pbRet = new byte[cb];
 | 
			
		||||
 | 
			
		||||
			if(m_crsAlgorithm == CrsAlgorithm.ChaCha20)
 | 
			
		||||
            if (m_alg == CrsAlgorithm.ChaCha20)
 | 
			
		||||
                m_chacha20.Encrypt(pbRet, 0, cb);
 | 
			
		||||
			else if(m_crsAlgorithm == CrsAlgorithm.Salsa20)
 | 
			
		||||
            else if (m_alg == CrsAlgorithm.Salsa20)
 | 
			
		||||
                m_salsa20.Encrypt(pbRet, 0, cb);
 | 
			
		||||
			else if(m_crsAlgorithm == CrsAlgorithm.ArcFourVariant)
 | 
			
		||||
            else if (m_alg == CrsAlgorithm.ArcFourVariant)
 | 
			
		||||
            {
 | 
			
		||||
                unchecked
 | 
			
		||||
                {
 | 
			
		||||
@@ -221,6 +231,25 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
            return MemUtil.BytesToUInt64(pb);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal ulong GetRandomUInt64(ulong uMaxExcl)
 | 
			
		||||
        {
 | 
			
		||||
            if (uMaxExcl == 0) { Debug.Assert(false); throw new ArgumentOutOfRangeException("uMaxExcl"); }
 | 
			
		||||
 | 
			
		||||
            ulong uGen, uRem;
 | 
			
		||||
            do
 | 
			
		||||
            {
 | 
			
		||||
                uGen = GetRandomUInt64();
 | 
			
		||||
                uRem = uGen % uMaxExcl;
 | 
			
		||||
            }
 | 
			
		||||
            while ((uGen - uRem) > (ulong.MaxValue - (uMaxExcl - 1UL)));
 | 
			
		||||
            // This ensures that the last number of the block (i.e.
 | 
			
		||||
            // (uGen - uRem) + (uMaxExcl - 1)) is generatable;
 | 
			
		||||
            // for signed longs, overflow to negative number:
 | 
			
		||||
            // while((uGen - uRem) + (uMaxExcl - 1) < 0);
 | 
			
		||||
 | 
			
		||||
            return uRem;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if CRSBENCHMARK
 | 
			
		||||
		public static string Benchmark()
 | 
			
		||||
		{
 | 
			
		||||
@@ -237,21 +266,20 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
			return str;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static int BenchTime(CrsAlgorithm cra, int nRounds, int nDataSize)
 | 
			
		||||
		private static int BenchTime(CrsAlgorithm a, int nRounds, int cbData)
 | 
			
		||||
		{
 | 
			
		||||
			byte[] pbKey = new byte[4] { 0x00, 0x01, 0x02, 0x03 };
 | 
			
		||||
 | 
			
		||||
			int nStart = Environment.TickCount;
 | 
			
		||||
			int tStart = Environment.TickCount;
 | 
			
		||||
			for(int i = 0; i < nRounds; ++i)
 | 
			
		||||
			{
 | 
			
		||||
				using(CryptoRandomStream c = new CryptoRandomStream(cra, pbKey))
 | 
			
		||||
				using(CryptoRandomStream crs = new CryptoRandomStream(a, pbKey))
 | 
			
		||||
				{
 | 
			
		||||
					c.GetRandomBytes((uint)nDataSize);
 | 
			
		||||
					crs.GetRandomBytes((uint)cbData);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			int nEnd = Environment.TickCount;
 | 
			
		||||
 | 
			
		||||
			return (nEnd - nStart);
 | 
			
		||||
			return (Environment.TickCount - tStart);
 | 
			
		||||
		}
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,65 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
  the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
  (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
  This program is distributed in the hope that it will be useful,
 | 
			
		||||
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
  GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
  You should have received a copy of the GNU General Public License
 | 
			
		||||
  along with this program; if not, write to the Free Software
 | 
			
		||||
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Security;
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
 | 
			
		||||
namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
{
 | 
			
		||||
	internal static class CharSetBasedGenerator
 | 
			
		||||
	{
 | 
			
		||||
		internal static PwgError Generate(out ProtectedString psOut,
 | 
			
		||||
			PwProfile pwProfile, CryptoRandomStream crsRandomSource)
 | 
			
		||||
		{
 | 
			
		||||
			psOut = ProtectedString.Empty;
 | 
			
		||||
			if(pwProfile.Length == 0) return PwgError.Success;
 | 
			
		||||
 | 
			
		||||
			PwCharSet pcs = new PwCharSet(pwProfile.CharSet.ToString());
 | 
			
		||||
			char[] vGenerated = new char[pwProfile.Length];
 | 
			
		||||
 | 
			
		||||
			PwGenerator.PrepareCharSet(pcs, pwProfile);
 | 
			
		||||
 | 
			
		||||
			for(int nIndex = 0; nIndex < (int)pwProfile.Length; ++nIndex)
 | 
			
		||||
			{
 | 
			
		||||
				char ch = PwGenerator.GenerateCharacter(pwProfile, pcs,
 | 
			
		||||
					crsRandomSource);
 | 
			
		||||
 | 
			
		||||
				if(ch == char.MinValue)
 | 
			
		||||
				{
 | 
			
		||||
					MemUtil.ZeroArray<char>(vGenerated);
 | 
			
		||||
					return PwgError.TooFewCharacters;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				vGenerated[nIndex] = ch;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			byte[] pbUtf8 = StrUtil.Utf8.GetBytes(vGenerated);
 | 
			
		||||
			psOut = new ProtectedString(true, pbUtf8);
 | 
			
		||||
			MemUtil.ZeroByteArray(pbUtf8);
 | 
			
		||||
			MemUtil.ZeroArray<char>(vGenerated);
 | 
			
		||||
 | 
			
		||||
			return PwgError.Success;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,173 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
  the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
  (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
  This program is distributed in the hope that it will be useful,
 | 
			
		||||
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
  GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
  You should have received a copy of the GNU General Public License
 | 
			
		||||
  along with this program; if not, write to the Free Software
 | 
			
		||||
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Security;
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
 | 
			
		||||
namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
{
 | 
			
		||||
	internal static class PatternBasedGenerator
 | 
			
		||||
	{
 | 
			
		||||
		internal static PwgError Generate(out ProtectedString psOut,
 | 
			
		||||
			PwProfile pwProfile, CryptoRandomStream crsRandomSource)
 | 
			
		||||
		{
 | 
			
		||||
			psOut = ProtectedString.Empty;
 | 
			
		||||
			LinkedList<char> vGenerated = new LinkedList<char>();
 | 
			
		||||
			PwCharSet pcsCurrent = new PwCharSet();
 | 
			
		||||
			PwCharSet pcsCustom = new PwCharSet();
 | 
			
		||||
			PwCharSet pcsUsed = new PwCharSet();
 | 
			
		||||
			bool bInCharSetDef = false;
 | 
			
		||||
 | 
			
		||||
			string strPattern = ExpandPattern(pwProfile.Pattern);
 | 
			
		||||
			if(strPattern.Length == 0) return PwgError.Success;
 | 
			
		||||
 | 
			
		||||
			CharStream csStream = new CharStream(strPattern);
 | 
			
		||||
			char ch = csStream.ReadChar();
 | 
			
		||||
 | 
			
		||||
			while(ch != char.MinValue)
 | 
			
		||||
			{
 | 
			
		||||
				pcsCurrent.Clear();
 | 
			
		||||
 | 
			
		||||
				bool bGenerateChar = false;
 | 
			
		||||
 | 
			
		||||
				if(ch == '\\')
 | 
			
		||||
				{
 | 
			
		||||
					ch = csStream.ReadChar();
 | 
			
		||||
					if(ch == char.MinValue) // Backslash at the end
 | 
			
		||||
					{
 | 
			
		||||
						vGenerated.AddLast('\\');
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					if(bInCharSetDef) pcsCustom.Add(ch);
 | 
			
		||||
					else
 | 
			
		||||
					{
 | 
			
		||||
						vGenerated.AddLast(ch);
 | 
			
		||||
						pcsUsed.Add(ch);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				else if(ch == '[')
 | 
			
		||||
				{
 | 
			
		||||
					pcsCustom.Clear();
 | 
			
		||||
					bInCharSetDef = true;
 | 
			
		||||
				}
 | 
			
		||||
				else if(ch == ']')
 | 
			
		||||
				{
 | 
			
		||||
					pcsCurrent.Add(pcsCustom.ToString());
 | 
			
		||||
 | 
			
		||||
					bInCharSetDef = false;
 | 
			
		||||
					bGenerateChar = true;
 | 
			
		||||
				}
 | 
			
		||||
				else if(bInCharSetDef)
 | 
			
		||||
				{
 | 
			
		||||
					if(pcsCustom.AddCharSet(ch) == false)
 | 
			
		||||
						pcsCustom.Add(ch);
 | 
			
		||||
				}
 | 
			
		||||
				else if(pcsCurrent.AddCharSet(ch) == false)
 | 
			
		||||
				{
 | 
			
		||||
					vGenerated.AddLast(ch);
 | 
			
		||||
					pcsUsed.Add(ch);
 | 
			
		||||
				}
 | 
			
		||||
				else bGenerateChar = true;
 | 
			
		||||
 | 
			
		||||
				if(bGenerateChar)
 | 
			
		||||
				{
 | 
			
		||||
					PwGenerator.PrepareCharSet(pcsCurrent, pwProfile);
 | 
			
		||||
 | 
			
		||||
					if(pwProfile.NoRepeatingCharacters)
 | 
			
		||||
						pcsCurrent.Remove(pcsUsed.ToString());
 | 
			
		||||
 | 
			
		||||
					char chGen = PwGenerator.GenerateCharacter(pwProfile,
 | 
			
		||||
						pcsCurrent, crsRandomSource);
 | 
			
		||||
 | 
			
		||||
					if(chGen == char.MinValue) return PwgError.TooFewCharacters;
 | 
			
		||||
 | 
			
		||||
					vGenerated.AddLast(chGen);
 | 
			
		||||
					pcsUsed.Add(chGen);
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				ch = csStream.ReadChar();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if(vGenerated.Count == 0) return PwgError.Success;
 | 
			
		||||
 | 
			
		||||
			char[] vArray = new char[vGenerated.Count];
 | 
			
		||||
			vGenerated.CopyTo(vArray, 0);
 | 
			
		||||
 | 
			
		||||
			if(pwProfile.PatternPermutePassword)
 | 
			
		||||
				PwGenerator.ShufflePassword(vArray, crsRandomSource);
 | 
			
		||||
 | 
			
		||||
			byte[] pbUtf8 = StrUtil.Utf8.GetBytes(vArray);
 | 
			
		||||
			psOut = new ProtectedString(true, pbUtf8);
 | 
			
		||||
			MemUtil.ZeroByteArray(pbUtf8);
 | 
			
		||||
			MemUtil.ZeroArray<char>(vArray);
 | 
			
		||||
			vGenerated.Clear();
 | 
			
		||||
 | 
			
		||||
			return PwgError.Success;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static string ExpandPattern(string strPattern)
 | 
			
		||||
		{
 | 
			
		||||
			Debug.Assert(strPattern != null); if(strPattern == null) return string.Empty;
 | 
			
		||||
			string str = strPattern;
 | 
			
		||||
 | 
			
		||||
			while(true)
 | 
			
		||||
			{
 | 
			
		||||
				int nOpen = FindFirstUnescapedChar(str, '{');
 | 
			
		||||
				int nClose = FindFirstUnescapedChar(str, '}');
 | 
			
		||||
 | 
			
		||||
				if((nOpen >= 0) && (nOpen < nClose))
 | 
			
		||||
				{
 | 
			
		||||
					string strCount = str.Substring(nOpen + 1, nClose - nOpen - 1);
 | 
			
		||||
					str = str.Remove(nOpen, nClose - nOpen + 1);
 | 
			
		||||
 | 
			
		||||
					uint uRepeat;
 | 
			
		||||
					if(StrUtil.TryParseUInt(strCount, out uRepeat) && (nOpen >= 1))
 | 
			
		||||
					{
 | 
			
		||||
						if(uRepeat == 0)
 | 
			
		||||
							str = str.Remove(nOpen - 1, 1);
 | 
			
		||||
						else
 | 
			
		||||
							str = str.Insert(nOpen, new string(str[nOpen - 1], (int)uRepeat - 1));
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				else break;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return str;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static int FindFirstUnescapedChar(string str, char ch)
 | 
			
		||||
		{
 | 
			
		||||
			for(int i = 0; i < str.Length; ++i)
 | 
			
		||||
			{
 | 
			
		||||
				char chCur = str[i];
 | 
			
		||||
 | 
			
		||||
				if(chCur == '\\') ++i; // Next is escaped, skip it
 | 
			
		||||
				else if(chCur == ch) return i;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return -1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -19,122 +19,81 @@
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
 | 
			
		||||
namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
{
 | 
			
		||||
	public sealed class PwCharSet
 | 
			
		||||
    public sealed class PwCharSet : IEquatable<PwCharSet>
 | 
			
		||||
    {
 | 
			
		||||
		public const string UpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 | 
			
		||||
		public const string LowerCase = "abcdefghijklmnopqrstuvwxyz";
 | 
			
		||||
		public const string Digits = "0123456789";
 | 
			
		||||
        public static readonly string UpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 | 
			
		||||
        public static readonly string LowerCase = "abcdefghijklmnopqrstuvwxyz";
 | 
			
		||||
        public static readonly string Digits = "0123456789";
 | 
			
		||||
 | 
			
		||||
		public const string UpperConsonants = "BCDFGHJKLMNPQRSTVWXYZ";
 | 
			
		||||
		public const string LowerConsonants = "bcdfghjklmnpqrstvwxyz";
 | 
			
		||||
		public const string UpperVowels = "AEIOU";
 | 
			
		||||
		public const string LowerVowels = "aeiou";
 | 
			
		||||
        public static readonly string UpperConsonants = "BCDFGHJKLMNPQRSTVWXYZ";
 | 
			
		||||
        public static readonly string LowerConsonants = "bcdfghjklmnpqrstvwxyz";
 | 
			
		||||
        public static readonly string UpperVowels = "AEIOU";
 | 
			
		||||
        public static readonly string LowerVowels = "aeiou";
 | 
			
		||||
 | 
			
		||||
		public const string Punctuation = @",.;:";
 | 
			
		||||
		public const string Brackets = @"[]{}()<>";
 | 
			
		||||
        public static readonly string Punctuation = ",.;:";
 | 
			
		||||
        public static readonly string Brackets = @"[]{}()<>";
 | 
			
		||||
 | 
			
		||||
		public const string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
 | 
			
		||||
        public static readonly string Special = "!\"#$%&'*+,./:;=?@\\^`|~";
 | 
			
		||||
        public static readonly string PrintableAsciiSpecial = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
 | 
			
		||||
 | 
			
		||||
		public const string UpperHex = "0123456789ABCDEF";
 | 
			
		||||
		public const string LowerHex = "0123456789abcdef";
 | 
			
		||||
        public static readonly string UpperHex = "0123456789ABCDEF";
 | 
			
		||||
        public static readonly string LowerHex = "0123456789abcdef";
 | 
			
		||||
 | 
			
		||||
		public const string Invalid = "\t\r\n";
 | 
			
		||||
		public const string LookAlike = @"O0l1I|";
 | 
			
		||||
 | 
			
		||||
		internal const string MenuAccels = PwCharSet.LowerCase + PwCharSet.Digits;
 | 
			
		||||
 | 
			
		||||
		private const int CharTabSize = (0x10000 / 8);
 | 
			
		||||
 | 
			
		||||
		private List<char> m_vChars = new List<char>();
 | 
			
		||||
		private byte[] m_vTab = new byte[CharTabSize];
 | 
			
		||||
 | 
			
		||||
		private static string m_strHighAnsi = null;
 | 
			
		||||
		public static string HighAnsiChars
 | 
			
		||||
		{
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				if(m_strHighAnsi == null) { new PwCharSet(); } // Create string
 | 
			
		||||
				Debug.Assert(m_strHighAnsi != null);
 | 
			
		||||
				return m_strHighAnsi;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static string m_strSpecial = null;
 | 
			
		||||
		public static string SpecialChars
 | 
			
		||||
		{
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				if(m_strSpecial == null) { new PwCharSet(); } // Create string
 | 
			
		||||
				Debug.Assert(m_strSpecial != null);
 | 
			
		||||
				return m_strSpecial;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
        public static readonly string LookAlike = "O0Il1|";
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
		/// Create a new, empty character set collection object.
 | 
			
		||||
        /// Latin-1 Supplement except U+00A0 (NBSP) and U+00AD (SHY).
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static readonly string Latin1S =
 | 
			
		||||
            "\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7" +
 | 
			
		||||
            "\u00A8\u00A9\u00AA\u00AB\u00AC\u00AE\u00AF" +
 | 
			
		||||
            "\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7" +
 | 
			
		||||
            "\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF" +
 | 
			
		||||
            "\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7" +
 | 
			
		||||
            "\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF" +
 | 
			
		||||
            "\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7" +
 | 
			
		||||
            "\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF" +
 | 
			
		||||
            "\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7" +
 | 
			
		||||
            "\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF" +
 | 
			
		||||
            "\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7" +
 | 
			
		||||
            "\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF";
 | 
			
		||||
 | 
			
		||||
        // internal static readonly string MenuAccels = PwCharSet.LowerCase + PwCharSet.Digits;
 | 
			
		||||
 | 
			
		||||
        [Obsolete]
 | 
			
		||||
        public static string SpecialChars { get { return PwCharSet.Special; } }
 | 
			
		||||
        [Obsolete]
 | 
			
		||||
        public static string HighAnsiChars { get { return PwCharSet.Latin1S; } }
 | 
			
		||||
 | 
			
		||||
        private readonly List<char> m_lChars = new List<char>();
 | 
			
		||||
        private readonly byte[] m_vTab = new byte[0x10000 / 8];
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Create a new, empty character set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public PwCharSet()
 | 
			
		||||
        {
 | 
			
		||||
			Initialize(true);
 | 
			
		||||
            Debug.Assert(PwCharSet.Latin1S.Length == (16 * 6 - 2));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public PwCharSet(string strCharSet)
 | 
			
		||||
        {
 | 
			
		||||
			Initialize(true);
 | 
			
		||||
            Add(strCharSet);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		private PwCharSet(bool bFullInitialize)
 | 
			
		||||
		{
 | 
			
		||||
			Initialize(bFullInitialize);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void Initialize(bool bFullInitialize)
 | 
			
		||||
		{
 | 
			
		||||
			Clear();
 | 
			
		||||
 | 
			
		||||
			if(!bFullInitialize) return;
 | 
			
		||||
 | 
			
		||||
			if(m_strHighAnsi == null)
 | 
			
		||||
			{
 | 
			
		||||
				StringBuilder sbHighAnsi = new StringBuilder();
 | 
			
		||||
				// [U+0080, U+009F] are C1 control characters,
 | 
			
		||||
				// U+00A0 is non-breaking space
 | 
			
		||||
				for(char ch = '\u00A1'; ch <= '\u00AC'; ++ch)
 | 
			
		||||
					sbHighAnsi.Append(ch);
 | 
			
		||||
				// U+00AD is soft hyphen (format character)
 | 
			
		||||
				for(char ch = '\u00AE'; ch < '\u00FF'; ++ch)
 | 
			
		||||
					sbHighAnsi.Append(ch);
 | 
			
		||||
				sbHighAnsi.Append('\u00FF');
 | 
			
		||||
 | 
			
		||||
				m_strHighAnsi = sbHighAnsi.ToString();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if(m_strSpecial == null)
 | 
			
		||||
			{
 | 
			
		||||
				PwCharSet pcs = new PwCharSet(false);
 | 
			
		||||
				pcs.AddRange('!', '/');
 | 
			
		||||
				pcs.AddRange(':', '@');
 | 
			
		||||
				pcs.AddRange('[', '`');
 | 
			
		||||
				pcs.Add(@"|~");
 | 
			
		||||
				pcs.Remove(@"-_ ");
 | 
			
		||||
				pcs.Remove(PwCharSet.Brackets);
 | 
			
		||||
 | 
			
		||||
				m_strSpecial = pcs.ToString();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Number of characters in this set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public uint Size
 | 
			
		||||
        {
 | 
			
		||||
			get { return (uint)m_vChars.Count; }
 | 
			
		||||
            get { return (uint)m_lChars.Count; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -147,19 +106,39 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
				if(uPos >= (uint)m_vChars.Count)
 | 
			
		||||
                if (uPos >= (uint)m_lChars.Count)
 | 
			
		||||
                    throw new ArgumentOutOfRangeException("uPos");
 | 
			
		||||
 | 
			
		||||
				return m_vChars[(int)uPos];
 | 
			
		||||
                return m_lChars[(int)uPos];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Equals(PwCharSet other)
 | 
			
		||||
        {
 | 
			
		||||
            if (object.ReferenceEquals(other, this)) return true;
 | 
			
		||||
            if (object.ReferenceEquals(other, null)) return false;
 | 
			
		||||
 | 
			
		||||
            if (m_lChars.Count != other.m_lChars.Count) return false;
 | 
			
		||||
 | 
			
		||||
            return MemUtil.ArraysEqual(m_vTab, other.m_vTab);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override bool Equals(object obj)
 | 
			
		||||
        {
 | 
			
		||||
            return Equals(obj as PwCharSet);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int GetHashCode()
 | 
			
		||||
        {
 | 
			
		||||
            return (int)MemUtil.Hash32(m_vTab, 0, m_vTab.Length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Remove all characters from this set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void Clear()
 | 
			
		||||
        {
 | 
			
		||||
			m_vChars.Clear();
 | 
			
		||||
            m_lChars.Clear();
 | 
			
		||||
            Array.Clear(m_vTab, 0, m_vTab.Length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -191,7 +170,7 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
 | 
			
		||||
            if (!Contains(ch))
 | 
			
		||||
            {
 | 
			
		||||
				m_vChars.Add(ch);
 | 
			
		||||
                m_lChars.Add(ch);
 | 
			
		||||
                m_vTab[ch / 8] |= (byte)(1 << (ch % 8));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -205,8 +184,6 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            Debug.Assert(strCharSet != null);
 | 
			
		||||
            if (strCharSet == null) throw new ArgumentNullException("strCharSet");
 | 
			
		||||
 | 
			
		||||
			m_vChars.Capacity = m_vChars.Count + strCharSet.Length;
 | 
			
		||||
 | 
			
		||||
            foreach (char ch in strCharSet)
 | 
			
		||||
                Add(ch);
 | 
			
		||||
        }
 | 
			
		||||
@@ -226,8 +203,6 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
 | 
			
		||||
        public void AddRange(char chMin, char chMax)
 | 
			
		||||
        {
 | 
			
		||||
			m_vChars.Capacity = m_vChars.Count + (chMax - chMin) + 1;
 | 
			
		||||
 | 
			
		||||
            for (char ch = chMin; ch < chMax; ++ch)
 | 
			
		||||
                Add(ch);
 | 
			
		||||
 | 
			
		||||
@@ -241,11 +216,13 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            switch (chCharSetIdentifier)
 | 
			
		||||
            {
 | 
			
		||||
                case 'a': Add(PwCharSet.LowerCase, PwCharSet.Digits); break;
 | 
			
		||||
				case 'A': Add(PwCharSet.LowerCase, PwCharSet.UpperCase,
 | 
			
		||||
                case 'A':
 | 
			
		||||
                    Add(PwCharSet.LowerCase, PwCharSet.UpperCase,
 | 
			
		||||
                    PwCharSet.Digits); break;
 | 
			
		||||
                case 'U': Add(PwCharSet.UpperCase, PwCharSet.Digits); break;
 | 
			
		||||
                case 'c': Add(PwCharSet.LowerConsonants); break;
 | 
			
		||||
				case 'C': Add(PwCharSet.LowerConsonants,
 | 
			
		||||
                case 'C':
 | 
			
		||||
                    Add(PwCharSet.LowerConsonants,
 | 
			
		||||
                    PwCharSet.UpperConsonants); break;
 | 
			
		||||
                case 'z': Add(PwCharSet.UpperConsonants); break;
 | 
			
		||||
                case 'd': Add(PwCharSet.Digits); break; // Digit
 | 
			
		||||
@@ -257,12 +234,13 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
                case 'p': Add(PwCharSet.Punctuation); break;
 | 
			
		||||
                case 'b': Add(PwCharSet.Brackets); break;
 | 
			
		||||
                case 's': Add(PwCharSet.PrintableAsciiSpecial); break;
 | 
			
		||||
				case 'S': Add(PwCharSet.UpperCase, PwCharSet.LowerCase);
 | 
			
		||||
                case 'S':
 | 
			
		||||
                    Add(PwCharSet.UpperCase, PwCharSet.LowerCase);
 | 
			
		||||
                    Add(PwCharSet.Digits, PwCharSet.PrintableAsciiSpecial); break;
 | 
			
		||||
                case 'v': Add(PwCharSet.LowerVowels); break;
 | 
			
		||||
                case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
 | 
			
		||||
                case 'Z': Add(PwCharSet.UpperVowels); break;
 | 
			
		||||
				case 'x': Add(m_strHighAnsi); break;
 | 
			
		||||
                case 'x': Add(PwCharSet.Latin1S); break;
 | 
			
		||||
                default: bResult = false; break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -272,7 +250,7 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
        public bool Remove(char ch)
 | 
			
		||||
        {
 | 
			
		||||
            m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8)));
 | 
			
		||||
			return m_vChars.Remove(ch);
 | 
			
		||||
            return m_lChars.Remove(ch);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Remove(string strCharacters)
 | 
			
		||||
@@ -306,8 +284,8 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
        /// <returns>String containing all character set characters.</returns>
 | 
			
		||||
        public override string ToString()
 | 
			
		||||
        {
 | 
			
		||||
			StringBuilder sb = new StringBuilder();
 | 
			
		||||
			foreach(char ch in m_vChars)
 | 
			
		||||
            StringBuilder sb = new StringBuilder(m_lChars.Count);
 | 
			
		||||
            foreach (char ch in m_lChars)
 | 
			
		||||
                sb.Append(ch);
 | 
			
		||||
 | 
			
		||||
            return sb.ToString();
 | 
			
		||||
@@ -320,13 +298,13 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_');
 | 
			
		||||
			sb.Append(RemoveIfAllExist(m_strSpecial) ? 'S' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.Special) ? 'S' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.Punctuation) ? 'P' : '_');
 | 
			
		||||
			sb.Append(RemoveIfAllExist(@"-") ? 'm' : '_');
 | 
			
		||||
			sb.Append(RemoveIfAllExist(@"_") ? 'u' : '_');
 | 
			
		||||
			sb.Append(RemoveIfAllExist(@" ") ? 's' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist("-") ? 'm' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist("_") ? 'u' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(" ") ? 's' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
 | 
			
		||||
			sb.Append(RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_');
 | 
			
		||||
            sb.Append(RemoveIfAllExist(PwCharSet.Latin1S) ? 'H' : '_');
 | 
			
		||||
 | 
			
		||||
            return sb.ToString();
 | 
			
		||||
        }
 | 
			
		||||
@@ -339,13 +317,13 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            if (strRanges[0] != '_') Add(PwCharSet.UpperCase);
 | 
			
		||||
            if (strRanges[1] != '_') Add(PwCharSet.LowerCase);
 | 
			
		||||
            if (strRanges[2] != '_') Add(PwCharSet.Digits);
 | 
			
		||||
			if(strRanges[3] != '_') Add(m_strSpecial);
 | 
			
		||||
            if (strRanges[3] != '_') Add(PwCharSet.Special);
 | 
			
		||||
            if (strRanges[4] != '_') Add(PwCharSet.Punctuation);
 | 
			
		||||
            if (strRanges[5] != '_') Add('-');
 | 
			
		||||
            if (strRanges[6] != '_') Add('_');
 | 
			
		||||
            if (strRanges[7] != '_') Add(' ');
 | 
			
		||||
            if (strRanges[8] != '_') Add(PwCharSet.Brackets);
 | 
			
		||||
			if(strRanges[9] != '_') Add(m_strHighAnsi);
 | 
			
		||||
            if (strRanges[9] != '_') Add(PwCharSet.Latin1S);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2016 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -20,9 +20,13 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Security.Cryptography;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
#if !KeePassUAP
 | 
			
		||||
using System.Security.Cryptography;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Resources;
 | 
			
		||||
using KeePassLib.Security;
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
 | 
			
		||||
@@ -33,95 +37,78 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
        Success = 0,
 | 
			
		||||
        Unknown = 1,
 | 
			
		||||
        TooFewCharacters = 2,
 | 
			
		||||
		UnknownAlgorithm = 3
 | 
			
		||||
        UnknownAlgorithm = 3,
 | 
			
		||||
        InvalidCharSet = 4,
 | 
			
		||||
        InvalidPattern = 5
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
	/// Utility functions for generating random passwords.
 | 
			
		||||
    /// Password generator.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class PwGenerator
 | 
			
		||||
    {
 | 
			
		||||
		public static PwgError Generate(out ProtectedString psOut,
 | 
			
		||||
			PwProfile pwProfile, byte[] pbUserEntropy,
 | 
			
		||||
			CustomPwGeneratorPool pwAlgorithmPool)
 | 
			
		||||
 | 
			
		||||
        private static CryptoRandomStream CreateRandomStream(byte[] pbAdditionalEntropy,
 | 
			
		||||
            out byte[] pbKey)
 | 
			
		||||
        {
 | 
			
		||||
			Debug.Assert(pwProfile != null);
 | 
			
		||||
			if (pwProfile == null) throw new ArgumentNullException("pwProfile");
 | 
			
		||||
 | 
			
		||||
			CryptoRandomStream crs = CreateCryptoStream(pbUserEntropy);
 | 
			
		||||
			PwgError e = PwgError.Unknown;
 | 
			
		||||
 | 
			
		||||
			if (pwProfile.GeneratorType == PasswordGeneratorType.CharSet)
 | 
			
		||||
				e = CharSetBasedGenerator.Generate(out psOut, pwProfile, crs);
 | 
			
		||||
			else if (pwProfile.GeneratorType == PasswordGeneratorType.Pattern)
 | 
			
		||||
				e = PatternBasedGenerator.Generate(out psOut, pwProfile, crs);
 | 
			
		||||
			else if (pwProfile.GeneratorType == PasswordGeneratorType.Custom)
 | 
			
		||||
				e = GenerateCustom(out psOut, pwProfile, crs, pwAlgorithmPool);
 | 
			
		||||
			else { Debug.Assert(false); psOut = ProtectedString.Empty; }
 | 
			
		||||
 | 
			
		||||
			return e;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static CryptoRandomStream CreateCryptoStream(byte[] pbAdditionalEntropy)
 | 
			
		||||
		{
 | 
			
		||||
			byte[] pbKey = CryptoRandom.Instance.GetRandomBytes(128);
 | 
			
		||||
            pbKey = CryptoRandom.Instance.GetRandomBytes(128);
 | 
			
		||||
 | 
			
		||||
            // Mix in additional entropy
 | 
			
		||||
            Debug.Assert(pbKey.Length >= 64);
 | 
			
		||||
			if ((pbAdditionalEntropy != null) && (pbAdditionalEntropy.Length > 0))
 | 
			
		||||
            if ((pbAdditionalEntropy != null) && (pbAdditionalEntropy.Length != 0))
 | 
			
		||||
            {
 | 
			
		||||
                using (SHA512Managed h = new SHA512Managed())
 | 
			
		||||
                {
 | 
			
		||||
                    byte[] pbHash = h.ComputeHash(pbAdditionalEntropy);
 | 
			
		||||
                    MemUtil.XorArray(pbHash, 0, pbKey, 0, pbHash.Length);
 | 
			
		||||
                    MemUtil.ZeroByteArray(pbHash);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new CryptoRandomStream(CrsAlgorithm.ChaCha20, pbKey);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		internal static char GenerateCharacter(PwProfile pwProfile,
 | 
			
		||||
			PwCharSet pwCharSet, CryptoRandomStream crsRandomSource)
 | 
			
		||||
        internal static char GenerateCharacter(PwCharSet pwCharSet,
 | 
			
		||||
            CryptoRandomStream crsRandomSource)
 | 
			
		||||
        {
 | 
			
		||||
			if (pwCharSet.Size == 0) return char.MinValue;
 | 
			
		||||
            uint cc = pwCharSet.Size;
 | 
			
		||||
            if (cc == 0) return char.MinValue;
 | 
			
		||||
 | 
			
		||||
			ulong uIndex = crsRandomSource.GetRandomUInt64();
 | 
			
		||||
			uIndex %= (ulong)pwCharSet.Size;
 | 
			
		||||
 | 
			
		||||
			char ch = pwCharSet[(uint)uIndex];
 | 
			
		||||
 | 
			
		||||
			if (pwProfile.NoRepeatingCharacters)
 | 
			
		||||
				pwCharSet.Remove(ch);
 | 
			
		||||
 | 
			
		||||
			return ch;
 | 
			
		||||
            uint i = (uint)crsRandomSource.GetRandomUInt64(cc);
 | 
			
		||||
            return pwCharSet[i];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		internal static void PrepareCharSet(PwCharSet pwCharSet, PwProfile pwProfile)
 | 
			
		||||
        internal static bool PrepareCharSet(PwCharSet pwCharSet, PwProfile pwProfile)
 | 
			
		||||
        {
 | 
			
		||||
			pwCharSet.Remove(PwCharSet.Invalid);
 | 
			
		||||
            uint cc = pwCharSet.Size;
 | 
			
		||||
            for (uint i = 0; i < cc; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                char ch = pwCharSet[i];
 | 
			
		||||
                if ((ch == char.MinValue) || (ch == '\t') || (ch == '\r') ||
 | 
			
		||||
                    (ch == '\n') || char.IsSurrogate(ch))
 | 
			
		||||
                    return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (pwProfile.ExcludeLookAlike) pwCharSet.Remove(PwCharSet.LookAlike);
 | 
			
		||||
 | 
			
		||||
			if (pwProfile.ExcludeCharacters.Length > 0)
 | 
			
		||||
            if (!string.IsNullOrEmpty(pwProfile.ExcludeCharacters))
 | 
			
		||||
                pwCharSet.Remove(pwProfile.ExcludeCharacters);
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		internal static void ShufflePassword(char[] pPassword,
 | 
			
		||||
			CryptoRandomStream crsRandomSource)
 | 
			
		||||
        internal static void Shuffle(char[] v, CryptoRandomStream crsRandomSource)
 | 
			
		||||
        {
 | 
			
		||||
			Debug.Assert(pPassword != null); if (pPassword == null) return;
 | 
			
		||||
			Debug.Assert(crsRandomSource != null); if (crsRandomSource == null) return;
 | 
			
		||||
            if (v == null) { Debug.Assert(false); return; }
 | 
			
		||||
            if (crsRandomSource == null) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
			if (pPassword.Length <= 1) return; // Nothing to shuffle
 | 
			
		||||
 | 
			
		||||
			for (int nSelect = 0; nSelect < pPassword.Length; ++nSelect)
 | 
			
		||||
            for (int i = v.Length - 1; i >= 1; --i)
 | 
			
		||||
            {
 | 
			
		||||
				ulong uRandomIndex = crsRandomSource.GetRandomUInt64();
 | 
			
		||||
				uRandomIndex %= (ulong)(pPassword.Length - nSelect);
 | 
			
		||||
                int j = (int)crsRandomSource.GetRandomUInt64((ulong)(i + 1));
 | 
			
		||||
 | 
			
		||||
				char chTemp = pPassword[nSelect];
 | 
			
		||||
				pPassword[nSelect] = pPassword[nSelect + (int)uRandomIndex];
 | 
			
		||||
				pPassword[nSelect + (int)uRandomIndex] = chTemp;
 | 
			
		||||
                char t = v[i];
 | 
			
		||||
                v[i] = v[j];
 | 
			
		||||
                v[j] = t;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -135,7 +122,7 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            if (pwAlgorithmPool == null) return PwgError.UnknownAlgorithm;
 | 
			
		||||
 | 
			
		||||
            string strID = pwProfile.CustomAlgorithmUuid;
 | 
			
		||||
			if (string.IsNullOrEmpty(strID)) { Debug.Assert(false); return PwgError.UnknownAlgorithm; }
 | 
			
		||||
            if (string.IsNullOrEmpty(strID)) return PwgError.UnknownAlgorithm;
 | 
			
		||||
 | 
			
		||||
            byte[] pbUuid = Convert.FromBase64String(strID);
 | 
			
		||||
            PwUuid uuid = new PwUuid(pbUuid);
 | 
			
		||||
@@ -148,5 +135,57 @@ namespace KeePassLib.Cryptography.PasswordGenerator
 | 
			
		||||
            psOut = pwd;
 | 
			
		||||
            return PwgError.Success;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static string ErrorToString(PwgError e, bool bHeader)
 | 
			
		||||
        {
 | 
			
		||||
            if (e == PwgError.Success) { Debug.Assert(false); return string.Empty; }
 | 
			
		||||
            if ((e == PwgError.Unknown) && bHeader) return KLRes.PwGenFailed;
 | 
			
		||||
 | 
			
		||||
            string str = KLRes.UnknownError;
 | 
			
		||||
            switch (e)
 | 
			
		||||
            {
 | 
			
		||||
                // case PwgError.Success:
 | 
			
		||||
                //	break;
 | 
			
		||||
 | 
			
		||||
                case PwgError.Unknown:
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case PwgError.TooFewCharacters:
 | 
			
		||||
                    str = KLRes.CharSetTooFewChars;
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case PwgError.UnknownAlgorithm:
 | 
			
		||||
                    str = KLRes.AlgorithmUnknown;
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case PwgError.InvalidCharSet:
 | 
			
		||||
                    str = KLRes.CharSetInvalid;
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case PwgError.InvalidPattern:
 | 
			
		||||
                    str = KLRes.PatternInvalid;
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                    Debug.Assert(false);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (bHeader)
 | 
			
		||||
                str = KLRes.PwGenFailed + MessageService.NewParagraph + str;
 | 
			
		||||
 | 
			
		||||
            return str;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static string ErrorToString(Exception ex, bool bHeader)
 | 
			
		||||
        {
 | 
			
		||||
            string str = ((ex == null) ? KLRes.UnknownError :
 | 
			
		||||
                StrUtil.FormatException(ex));
 | 
			
		||||
 | 
			
		||||
            if (bHeader)
 | 
			
		||||
                str = KLRes.PwGenFailed + MessageService.NewParagraph + str;
 | 
			
		||||
 | 
			
		||||
            return str;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -19,8 +19,8 @@
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
 | 
			
		||||
@@ -28,15 +28,17 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
{
 | 
			
		||||
    public static class PopularPasswords
 | 
			
		||||
    {
 | 
			
		||||
		private static Dictionary<int, Dictionary<string, bool>> m_dicts =
 | 
			
		||||
			new Dictionary<int, Dictionary<string, bool>>();
 | 
			
		||||
        private static readonly Dictionary<int, Dictionary<char[], bool>> g_dicts =
 | 
			
		||||
            new Dictionary<int, Dictionary<char[], bool>>();
 | 
			
		||||
 | 
			
		||||
        internal static int MaxLength
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                Debug.Assert(g_dicts.Count > 0); // Should be initialized
 | 
			
		||||
 | 
			
		||||
                int iMaxLen = 0;
 | 
			
		||||
				foreach(int iLen in m_dicts.Keys)
 | 
			
		||||
                foreach (int iLen in g_dicts.Keys)
 | 
			
		||||
                {
 | 
			
		||||
                    if (iLen > iMaxLen) iMaxLen = iLen;
 | 
			
		||||
                }
 | 
			
		||||
@@ -47,8 +49,8 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
 | 
			
		||||
        internal static bool ContainsLength(int nLength)
 | 
			
		||||
        {
 | 
			
		||||
			Dictionary<string, bool> dDummy;
 | 
			
		||||
			return m_dicts.TryGetValue(nLength, out dDummy);
 | 
			
		||||
            Dictionary<char[], bool> dDummy;
 | 
			
		||||
            return g_dicts.TryGetValue(nLength, out dDummy);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static bool IsPopularPassword(char[] vPassword)
 | 
			
		||||
@@ -62,28 +64,30 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
            if (vPassword == null) throw new ArgumentNullException("vPassword");
 | 
			
		||||
            if (vPassword.Length == 0) { uDictSize = 0; return false; }
 | 
			
		||||
 | 
			
		||||
			string str = new string(vPassword);
 | 
			
		||||
#if DEBUG
 | 
			
		||||
            Array.ForEach(vPassword, ch => Debug.Assert(ch == char.ToLower(ch)));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
			try { return IsPopularPasswordPriv(str, out uDictSize); }
 | 
			
		||||
            try { return IsPopularPasswordPriv(vPassword, out uDictSize); }
 | 
			
		||||
            catch (Exception) { Debug.Assert(false); }
 | 
			
		||||
 | 
			
		||||
            uDictSize = 0;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		private static bool IsPopularPasswordPriv(string str, out ulong uDictSize)
 | 
			
		||||
        private static bool IsPopularPasswordPriv(char[] vPassword, out ulong uDictSize)
 | 
			
		||||
        {
 | 
			
		||||
			Debug.Assert(m_dicts.Count > 0); // Should be initialized with data
 | 
			
		||||
            Debug.Assert(g_dicts.Count > 0); // Should be initialized with data
 | 
			
		||||
 | 
			
		||||
			Dictionary<string, bool> d;
 | 
			
		||||
			if(!m_dicts.TryGetValue(str.Length, out d))
 | 
			
		||||
            Dictionary<char[], bool> d;
 | 
			
		||||
            if (!g_dicts.TryGetValue(vPassword.Length, out d))
 | 
			
		||||
            {
 | 
			
		||||
                uDictSize = 0;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            uDictSize = (ulong)d.Count;
 | 
			
		||||
			return d.ContainsKey(str);
 | 
			
		||||
            return d.ContainsKey(vPassword);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void Add(byte[] pbData, bool bGZipped)
 | 
			
		||||
@@ -96,30 +100,27 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                string strData = StrUtil.Utf8.GetString(pbData, 0, pbData.Length);
 | 
			
		||||
                if (string.IsNullOrEmpty(strData)) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
				if(!char.IsWhiteSpace(strData[strData.Length - 1]))
 | 
			
		||||
					strData += "\n";
 | 
			
		||||
 | 
			
		||||
                StringBuilder sb = new StringBuilder();
 | 
			
		||||
				for(int i = 0; i < strData.Length; ++i)
 | 
			
		||||
                for (int i = 0; i <= strData.Length; ++i)
 | 
			
		||||
                {
 | 
			
		||||
					char ch = strData[i];
 | 
			
		||||
                    char ch = ((i == strData.Length) ? ' ' : strData[i]);
 | 
			
		||||
 | 
			
		||||
                    if (char.IsWhiteSpace(ch))
 | 
			
		||||
                    {
 | 
			
		||||
                        int cc = sb.Length;
 | 
			
		||||
                        if (cc > 0)
 | 
			
		||||
                        {
 | 
			
		||||
							string strWord = sb.ToString();
 | 
			
		||||
							Debug.Assert(strWord.Length == cc);
 | 
			
		||||
                            char[] vWord = new char[cc];
 | 
			
		||||
                            sb.CopyTo(0, vWord, 0, cc);
 | 
			
		||||
 | 
			
		||||
							Dictionary<string, bool> d;
 | 
			
		||||
							if(!m_dicts.TryGetValue(cc, out d))
 | 
			
		||||
                            Dictionary<char[], bool> d;
 | 
			
		||||
                            if (!g_dicts.TryGetValue(cc, out d))
 | 
			
		||||
                            {
 | 
			
		||||
								d = new Dictionary<string, bool>();
 | 
			
		||||
								m_dicts[cc] = d;
 | 
			
		||||
                                d = new Dictionary<char[], bool>(MemUtil.ArrayHelperExOfChar);
 | 
			
		||||
                                g_dicts[cc] = d;
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
							d[strWord] = true;
 | 
			
		||||
                            d[vWord] = true;
 | 
			
		||||
                            sb.Remove(0, cc);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -19,8 +19,8 @@
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Cryptography.PasswordGenerator;
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
@@ -35,19 +35,19 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
    {
 | 
			
		||||
        private static class PatternID
 | 
			
		||||
        {
 | 
			
		||||
			public const char LowerAlpha = 'L';
 | 
			
		||||
			public const char UpperAlpha = 'U';
 | 
			
		||||
			public const char Digit = 'D';
 | 
			
		||||
			public const char Special = 'S';
 | 
			
		||||
			public const char High = 'H';
 | 
			
		||||
			public const char Other = 'X';
 | 
			
		||||
            internal const char LowerAlpha = 'L';
 | 
			
		||||
            internal const char UpperAlpha = 'U';
 | 
			
		||||
            internal const char Digit = 'D';
 | 
			
		||||
            internal const char Special = 'S';
 | 
			
		||||
            internal const char Latin1S = 'H';
 | 
			
		||||
            internal const char Other = 'X';
 | 
			
		||||
 | 
			
		||||
			public const char Dictionary = 'W';
 | 
			
		||||
			public const char Repetition = 'R';
 | 
			
		||||
			public const char Number = 'N';
 | 
			
		||||
			public const char DiffSeq = 'C';
 | 
			
		||||
            internal const char Dictionary = 'W';
 | 
			
		||||
            internal const char Repetition = 'R';
 | 
			
		||||
            internal const char Number = 'N';
 | 
			
		||||
            internal const char DiffSeq = 'C';
 | 
			
		||||
 | 
			
		||||
			public const string All = "LUDSHXWRNC";
 | 
			
		||||
            internal const string All = "LUDSHXWRNC";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // private static class CharDistrib
 | 
			
		||||
@@ -125,7 +125,7 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        private sealed class EntropyEncoder
 | 
			
		||||
        {
 | 
			
		||||
            private readonly string m_strAlph;
 | 
			
		||||
			private Dictionary<char, ulong> m_dHisto = new Dictionary<char, ulong>();
 | 
			
		||||
            private readonly Dictionary<char, ulong> m_dHisto = new Dictionary<char, ulong>();
 | 
			
		||||
            private readonly ulong m_uBaseWeight;
 | 
			
		||||
            private readonly ulong m_uCharWeight;
 | 
			
		||||
            private readonly ulong m_uOccExclThreshold;
 | 
			
		||||
@@ -189,7 +189,7 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
 | 
			
		||||
        private sealed class MultiEntropyEncoder
 | 
			
		||||
        {
 | 
			
		||||
			private Dictionary<char, EntropyEncoder> m_dEncs =
 | 
			
		||||
            private readonly Dictionary<char, EntropyEncoder> m_dEncs =
 | 
			
		||||
                new Dictionary<char, EntropyEncoder>();
 | 
			
		||||
 | 
			
		||||
            public MultiEntropyEncoder()
 | 
			
		||||
@@ -281,7 +281,7 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		private static object m_objSyncInit = new object();
 | 
			
		||||
        private static readonly object m_objSyncInit = new object();
 | 
			
		||||
        private static List<QeCharType> m_lCharTypes = null;
 | 
			
		||||
 | 
			
		||||
        private static void EnsureInitialized()
 | 
			
		||||
@@ -292,25 +292,20 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                {
 | 
			
		||||
                    string strSpecial = PwCharSet.PrintableAsciiSpecial;
 | 
			
		||||
                    if (strSpecial.IndexOf(' ') >= 0) { Debug.Assert(false); }
 | 
			
		||||
					else strSpecial = strSpecial + " ";
 | 
			
		||||
                    else strSpecial += " ";
 | 
			
		||||
 | 
			
		||||
                    int nSp = strSpecial.Length;
 | 
			
		||||
					int nHi = PwCharSet.HighAnsiChars.Length;
 | 
			
		||||
                    int nL1S = PwCharSet.Latin1S.Length;
 | 
			
		||||
 | 
			
		||||
					m_lCharTypes = new List<QeCharType>();
 | 
			
		||||
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.LowerAlpha,
 | 
			
		||||
						PwCharSet.LowerCase, true));
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.UpperAlpha,
 | 
			
		||||
						PwCharSet.UpperCase, true));
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.Digit,
 | 
			
		||||
						PwCharSet.Digits, true));
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.Special,
 | 
			
		||||
						strSpecial, false));
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.High,
 | 
			
		||||
						PwCharSet.HighAnsiChars, false));
 | 
			
		||||
					m_lCharTypes.Add(new QeCharType(PatternID.Other,
 | 
			
		||||
						0x10000 - (2 * 26) - 10 - nSp - nHi));
 | 
			
		||||
                    m_lCharTypes = new List<QeCharType>()
 | 
			
		||||
                    {
 | 
			
		||||
                        new QeCharType(PatternID.LowerAlpha, PwCharSet.LowerCase, true),
 | 
			
		||||
                        new QeCharType(PatternID.UpperAlpha, PwCharSet.UpperCase, true),
 | 
			
		||||
                        new QeCharType(PatternID.Digit, PwCharSet.Digits, true),
 | 
			
		||||
                        new QeCharType(PatternID.Special, strSpecial, false),
 | 
			
		||||
                        new QeCharType(PatternID.Latin1S, PwCharSet.Latin1S, false),
 | 
			
		||||
                        new QeCharType(PatternID.Other, 0x10000 - (2 * 26) - 10 - nSp - nL1S)
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -318,30 +313,30 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Estimate the quality of a password.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
		/// <param name="vPasswordChars">Password to check.</param>
 | 
			
		||||
        /// <param name="vPassword">Password to check.</param>
 | 
			
		||||
        /// <returns>Estimated bit-strength of the password.</returns>
 | 
			
		||||
		public static uint EstimatePasswordBits(char[] vPasswordChars)
 | 
			
		||||
        public static uint EstimatePasswordBits(char[] vPassword)
 | 
			
		||||
        {
 | 
			
		||||
			if(vPasswordChars == null) { Debug.Assert(false); return 0; }
 | 
			
		||||
			if(vPasswordChars.Length == 0) return 0;
 | 
			
		||||
            if (vPassword == null) { Debug.Assert(false); return 0; }
 | 
			
		||||
            if (vPassword.Length == 0) return 0;
 | 
			
		||||
 | 
			
		||||
            EnsureInitialized();
 | 
			
		||||
 | 
			
		||||
			int n = vPasswordChars.Length;
 | 
			
		||||
            int n = vPassword.Length;
 | 
			
		||||
            List<QePatternInstance>[] vPatterns = new List<QePatternInstance>[n];
 | 
			
		||||
            for (int i = 0; i < n; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                vPatterns[i] = new List<QePatternInstance>();
 | 
			
		||||
 | 
			
		||||
                QePatternInstance piChar = new QePatternInstance(i, 1,
 | 
			
		||||
					GetCharType(vPasswordChars[i]));
 | 
			
		||||
                    GetCharType(vPassword[i]));
 | 
			
		||||
                vPatterns[i].Add(piChar);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			FindRepetitions(vPasswordChars, vPatterns);
 | 
			
		||||
			FindNumbers(vPasswordChars, vPatterns);
 | 
			
		||||
			FindDiffSeqs(vPasswordChars, vPatterns);
 | 
			
		||||
			FindPopularPasswords(vPasswordChars, vPatterns);
 | 
			
		||||
            FindRepetitions(vPassword, vPatterns);
 | 
			
		||||
            FindNumbers(vPassword, vPatterns);
 | 
			
		||||
            FindDiffSeqs(vPassword, vPatterns);
 | 
			
		||||
            FindPopularPasswords(vPassword, vPatterns);
 | 
			
		||||
 | 
			
		||||
            // Encoders must not be static, because the entropy estimation
 | 
			
		||||
            // may run concurrently in multiple threads and the encoders are
 | 
			
		||||
@@ -382,7 +377,7 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                {
 | 
			
		||||
                    Debug.Assert(s.Position == n);
 | 
			
		||||
 | 
			
		||||
					double dblCost = ComputePathCost(s.Path, vPasswordChars,
 | 
			
		||||
                    double dblCost = ComputePathCost(s.Path, vPassword,
 | 
			
		||||
                        ecPattern, mcData);
 | 
			
		||||
                    if (dblCost < dblMinCost) dblMinCost = dblCost;
 | 
			
		||||
                }
 | 
			
		||||
@@ -420,11 +415,12 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        {
 | 
			
		||||
            if (pbUnprotectedUtf8 == null) { Debug.Assert(false); return 0; }
 | 
			
		||||
 | 
			
		||||
			char[] vChars = StrUtil.Utf8.GetChars(pbUnprotectedUtf8);
 | 
			
		||||
			uint uResult = EstimatePasswordBits(vChars);
 | 
			
		||||
			MemUtil.ZeroArray<char>(vChars);
 | 
			
		||||
            char[] v = StrUtil.Utf8.GetChars(pbUnprotectedUtf8);
 | 
			
		||||
            uint r;
 | 
			
		||||
            try { r = EstimatePasswordBits(v); }
 | 
			
		||||
            finally { MemUtil.ZeroArray<char>(v); }
 | 
			
		||||
 | 
			
		||||
			return uResult;
 | 
			
		||||
            return r;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static QeCharType GetCharType(char ch)
 | 
			
		||||
@@ -482,7 +478,7 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                vLeet[i] = char.ToLower(DecodeLeetChar(ch));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			char chErased = default(char);
 | 
			
		||||
            char chErased = default(char); // The value that Array.Clear uses
 | 
			
		||||
            Debug.Assert(chErased == char.MinValue);
 | 
			
		||||
 | 
			
		||||
            int nMaxLen = Math.Min(n, PopularPasswords.MaxLength);
 | 
			
		||||
@@ -515,7 +511,12 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                        Debug.Assert(vLower[i] == chErased);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                MemUtil.ZeroArray<char>(vSub);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            MemUtil.ZeroArray<char>(vLower);
 | 
			
		||||
            MemUtil.ZeroArray<char>(vLeet);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool EvalAddPopularPasswordPattern(List<QePatternInstance>[] vPatterns,
 | 
			
		||||
@@ -659,6 +660,8 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
                    if (bFoundRep) ErasePart(v, x1, m, ref chErased);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            MemUtil.ZeroArray<char>(v);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool PartsEqual(char[] v, int x1, int x2, int nLength)
 | 
			
		||||
@@ -685,23 +688,25 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        {
 | 
			
		||||
            int n = vPassword.Length;
 | 
			
		||||
            StringBuilder sb = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < n; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                char ch = vPassword[i];
 | 
			
		||||
                if ((ch >= '0') && (ch <= '9')) sb.Append(ch);
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
					AddNumberPattern(vPatterns, sb.ToString(), i - sb.Length);
 | 
			
		||||
                    AddNumberPattern(vPatterns, sb, i - sb.Length);
 | 
			
		||||
                    sb.Remove(0, sb.Length);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
			AddNumberPattern(vPatterns, sb.ToString(), n - sb.Length);
 | 
			
		||||
            AddNumberPattern(vPatterns, sb, n - sb.Length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void AddNumberPattern(List<QePatternInstance>[] vPatterns,
 | 
			
		||||
			string strNumber, int i)
 | 
			
		||||
            StringBuilder sb, int i)
 | 
			
		||||
        {
 | 
			
		||||
			if(strNumber.Length <= 2) return;
 | 
			
		||||
            if (sb.Length <= 2) return;
 | 
			
		||||
            string strNumber = sb.ToString();
 | 
			
		||||
 | 
			
		||||
            int nZeros = 0;
 | 
			
		||||
            for (int j = 0; j < strNumber.Length; ++j)
 | 
			
		||||
@@ -733,17 +738,18 @@ namespace KeePassLib.Cryptography
 | 
			
		||||
        private static void FindDiffSeqs(char[] vPassword,
 | 
			
		||||
            List<QePatternInstance>[] vPatterns)
 | 
			
		||||
        {
 | 
			
		||||
			int d = int.MinValue, p = 0;
 | 
			
		||||
			string str = new string(vPassword) + new string(char.MaxValue, 1);
 | 
			
		||||
            int n = vPassword.Length;
 | 
			
		||||
            int d = int.MaxValue, p = 0;
 | 
			
		||||
 | 
			
		||||
			for(int i = 1; i < str.Length; ++i)
 | 
			
		||||
            for (int i = 1; i <= n; ++i)
 | 
			
		||||
            {
 | 
			
		||||
				int dCur = (int)str[i] - (int)str[i - 1];
 | 
			
		||||
                int dCur = ((i == n) ? int.MinValue :
 | 
			
		||||
                    ((int)vPassword[i] - (int)vPassword[i - 1]));
 | 
			
		||||
                if (dCur != d)
 | 
			
		||||
                {
 | 
			
		||||
                    if ((i - p) >= 3) // At least 3 chars involved
 | 
			
		||||
                    {
 | 
			
		||||
						QeCharType ct = GetCharType(str[p]);
 | 
			
		||||
                        QeCharType ct = GetCharType(vPassword[p]);
 | 
			
		||||
                        double dblCost = ct.CharSize + Log2(i - p - 1);
 | 
			
		||||
 | 
			
		||||
                        vPatterns[p].Add(new QePatternInstance(p,
 | 
			
		||||
 
 | 
			
		||||
@@ -46,4 +46,12 @@ namespace KeePassLib.Delegates
 | 
			
		||||
	public delegate void VoidDelegate();
 | 
			
		||||
 | 
			
		||||
	public delegate string StrPwEntryDelegate(string str, PwEntry pe);
 | 
			
		||||
 | 
			
		||||
    public delegate TResult GFunc<TResult>();
 | 
			
		||||
    public delegate TResult GFunc<T, TResult>(T o);
 | 
			
		||||
    public delegate TResult GFunc<T1, T2, TResult>(T1 o1, T2 o2);
 | 
			
		||||
    public delegate TResult GFunc<T1, T2, T3, TResult>(T1 o1, T2 o2, T3 o3);
 | 
			
		||||
    public delegate TResult GFunc<T1, T2, T3, T4, TResult>(T1 o1, T2 o2, T3 o3, T4 o4);
 | 
			
		||||
    public delegate TResult GFunc<T1, T2, T3, T4, T5, TResult>(T1 o1, T2 o2, T3 o3, T4 o4, T5 o5);
 | 
			
		||||
    public delegate TResult GFunc<T1, T2, T3, T4, T5, T6, TResult>(T1 o1, T2 o2, T3 o3, T4 o4, T5 o5, T6 o6);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
  KeePass Password Safe - The Open-Source Password Manager
 | 
			
		||||
  Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
  Copyright (C) 2003-2025 Dominik Reichl <dominik.reichl@t-online.de>
 | 
			
		||||
 | 
			
		||||
  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
  it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -22,6 +22,7 @@ using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Runtime.CompilerServices;
 | 
			
		||||
using System.Runtime.InteropServices;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
#if KeePassLibSD
 | 
			
		||||
@@ -30,81 +31,26 @@ using KeePassLibSD;
 | 
			
		||||
using System.IO.Compression;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using KeePassLib.Delegates;
 | 
			
		||||
 | 
			
		||||
namespace KeePassLib.Utility
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
	/// Contains static buffer manipulation and string conversion routines.
 | 
			
		||||
    /// Buffer manipulation and conversion routines.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class MemUtil
 | 
			
		||||
    {
 | 
			
		||||
        public static readonly byte[] EmptyByteArray = new byte[0];
 | 
			
		||||
 | 
			
		||||
		private static readonly uint[] m_vSBox = new uint[256] {
 | 
			
		||||
			0xCD2FACB3, 0xE78A7F5C, 0x6F0803FC, 0xBCF6E230,
 | 
			
		||||
			0x3A321712, 0x06403DB1, 0xD2F84B95, 0xDF22A6E4,
 | 
			
		||||
			0x07CE9E5B, 0x31788A0C, 0xF683F6F4, 0xEA061F49,
 | 
			
		||||
			0xFA5C2ACA, 0x4B9E494E, 0xB0AB25BA, 0x767731FC,
 | 
			
		||||
			0x261893A7, 0x2B09F2CE, 0x046261E4, 0x41367B4B,
 | 
			
		||||
			0x18A7F225, 0x8F923C0E, 0x5EF3A325, 0x28D0435E,
 | 
			
		||||
			0x84C22919, 0xED66873C, 0x8CEDE444, 0x7FC47C24,
 | 
			
		||||
			0xFCFC6BA3, 0x676F928D, 0xB4147187, 0xD8FB126E,
 | 
			
		||||
			0x7D798D17, 0xFF82E424, 0x1712FA5B, 0xABB09DD5,
 | 
			
		||||
			0x8156BA63, 0x84E4D969, 0xC937FB9A, 0x2F1E5BFC,
 | 
			
		||||
			0x178ECA11, 0x0E71CD5F, 0x52AAC6F4, 0x71EEFC8F,
 | 
			
		||||
			0x7090D749, 0x21CACA31, 0x92996378, 0x0939A8A8,
 | 
			
		||||
			0xE9EE1934, 0xD2718616, 0xF2500543, 0xB911873C,
 | 
			
		||||
			0xD3CB3EEC, 0x2BA0DBEB, 0xB42D0A27, 0xECE67C0F,
 | 
			
		||||
			0x302925F0, 0x6114F839, 0xD39E6307, 0xE28970D6,
 | 
			
		||||
			0xEB982F99, 0x941B4CDF, 0xC540E550, 0x8124FC45,
 | 
			
		||||
			0x98B025C7, 0xE2BF90EA, 0x4F57C976, 0xCF546FE4,
 | 
			
		||||
			0x59566DC8, 0xE3F4360D, 0xF5F9D231, 0xD6180B22,
 | 
			
		||||
			0xB54E088A, 0xB5DFE6A6, 0x3637A36F, 0x056E9284,
 | 
			
		||||
			0xAFF8FBC5, 0x19E01648, 0x8611F043, 0xDAE44337,
 | 
			
		||||
			0xF61B6A1C, 0x257ACD9E, 0xDD35F507, 0xEF05CAFA,
 | 
			
		||||
			0x05EB4A83, 0xFC25CA92, 0x0A4728E6, 0x9CF150EF,
 | 
			
		||||
			0xAEEF67DE, 0xA9472337, 0x57C81EFE, 0x3E5E009F,
 | 
			
		||||
			0x02CB03BB, 0x2BA85674, 0xF21DC251, 0x78C34A34,
 | 
			
		||||
			0xABB1F5BF, 0xB95A2FBD, 0x1FB47777, 0x9A96E8AC,
 | 
			
		||||
			0x5D2D2838, 0x55AAC92A, 0x99EE324E, 0x10F6214B,
 | 
			
		||||
			0x58ABDFB1, 0x2008794D, 0xBEC880F0, 0xE75E5341,
 | 
			
		||||
			0x88015C34, 0x352D8FBF, 0x622B7F6C, 0xF5C59EA2,
 | 
			
		||||
			0x1F759D8E, 0xADE56159, 0xCC7B4C25, 0x5B8BC48C,
 | 
			
		||||
			0xB6BD15AF, 0x3C5B5110, 0xE74A7C3D, 0xEE613161,
 | 
			
		||||
			0x156A1C67, 0x72C06817, 0xEA0A6F69, 0x4CECF993,
 | 
			
		||||
			0xCA9D554C, 0x8E20361F, 0x42D396B9, 0x595DE578,
 | 
			
		||||
			0x749D7955, 0xFD1BA5FD, 0x81FC160E, 0xDB97E28C,
 | 
			
		||||
			0x7CF148F7, 0x0B0B3CF5, 0x534DE605, 0x46421066,
 | 
			
		||||
			0xD4B68DD1, 0x9E479CE6, 0xAE667A9D, 0xBC082082,
 | 
			
		||||
			0xB06DD6EF, 0x20F0F23F, 0xB99E1551, 0xF47A2E3A,
 | 
			
		||||
			0x71DA50C6, 0x67B65779, 0x2A8CB376, 0x1EA71EEE,
 | 
			
		||||
			0x29ABCD50, 0xB6EB0C6B, 0x23C10511, 0x6F3F2144,
 | 
			
		||||
			0x6AF23012, 0xF696BD9E, 0xB94099D8, 0xAD5A9C81,
 | 
			
		||||
			0x7A0794FA, 0x7EDF59D6, 0x1E72E574, 0x8561913C,
 | 
			
		||||
			0x4E4D568F, 0xEECB9928, 0x9C124D2E, 0x0848B82C,
 | 
			
		||||
			0xF1CA395F, 0x9DAF43DC, 0xF77EC323, 0x394E9B59,
 | 
			
		||||
			0x7E200946, 0x8B811D68, 0x16DA3305, 0xAB8DE2C3,
 | 
			
		||||
			0xE6C53B64, 0x98C2D321, 0x88A97D81, 0xA7106419,
 | 
			
		||||
			0x8E52F7BF, 0x8ED262AF, 0x7CCA974E, 0xF0933241,
 | 
			
		||||
			0x040DD437, 0xE143B3D4, 0x3019F56F, 0xB741521D,
 | 
			
		||||
			0xF1745362, 0x4C435F9F, 0xB4214D0D, 0x0B0C348B,
 | 
			
		||||
			0x5051D189, 0x4C30447E, 0x7393D722, 0x95CEDD0B,
 | 
			
		||||
			0xDD994E80, 0xC3D22ED9, 0x739CD900, 0x131EB9C4,
 | 
			
		||||
			0xEF1062B2, 0x4F0DE436, 0x52920073, 0x9A7F3D80,
 | 
			
		||||
			0x896E7B1B, 0x2C8BBE5A, 0xBD304F8A, 0xA993E22C,
 | 
			
		||||
			0x134C41A0, 0xFA989E00, 0x39CE9726, 0xFB89FCCF,
 | 
			
		||||
			0xE8FBAC97, 0xD4063FFC, 0x935A2B5A, 0x44C8EE83,
 | 
			
		||||
			0xCB2BC7B6, 0x02989E92, 0x75478BEA, 0x144378D0,
 | 
			
		||||
			0xD853C087, 0x8897A34E, 0xDD23629D, 0xBDE2A2A2,
 | 
			
		||||
			0x581D8ECC, 0x5DA8AEE8, 0xFF8AAFD0, 0xBA2BCF6E,
 | 
			
		||||
			0x4BD98DAC, 0xF2EDB9E4, 0xFA2DC868, 0x47E84661,
 | 
			
		||||
			0xECEB1C7D, 0x41705CA4, 0x5982E4D4, 0xEB5204A1,
 | 
			
		||||
			0xD196CAFB, 0x6414804D, 0x3ABD4B46, 0x8B494C26,
 | 
			
		||||
			0xB432D52B, 0x39C5356B, 0x6EC80BF7, 0x71BE5483,
 | 
			
		||||
			0xCEC4A509, 0xE9411D61, 0x52F341E5, 0xD2E6197B,
 | 
			
		||||
			0x4F02826C, 0xA9E48838, 0xD1F8F247, 0xE4957FB3,
 | 
			
		||||
			0x586CCA99, 0x9A8B6A5B, 0x4998FBEA, 0xF762BE4C,
 | 
			
		||||
			0x90DFE33C, 0x9731511E, 0x88C6A82F, 0xDD65A4D4
 | 
			
		||||
		};
 | 
			
		||||
        internal static readonly ArrayHelperEx<char> ArrayHelperExOfChar =
 | 
			
		||||
            new ArrayHelperEx<char>();
 | 
			
		||||
 | 
			
		||||
        private const MethodImplOptions MioNoOptimize =
 | 
			
		||||
#if KeePassLibSD
 | 
			
		||||
			MethodImplOptions.NoInlining;
 | 
			
		||||
#else
 | 
			
		||||
            (MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Convert a hexadecimal string to a byte array. The input string must be
 | 
			
		||||
@@ -143,11 +89,11 @@ namespace KeePassLib.Utility
 | 
			
		||||
 | 
			
		||||
                ch = strHex[i + 1];
 | 
			
		||||
                if ((ch >= '0') && (ch <= '9'))
 | 
			
		||||
					bt += (byte)(ch - '0');
 | 
			
		||||
                    bt |= (byte)(ch - '0');
 | 
			
		||||
                else if ((ch >= 'a') && (ch <= 'f'))
 | 
			
		||||
					bt += (byte)(ch - 'a' + 10);
 | 
			
		||||
                    bt |= (byte)(ch - 'a' + 10);
 | 
			
		||||
                else if ((ch >= 'A') && (ch <= 'F'))
 | 
			
		||||
					bt += (byte)(ch - 'A' + 10);
 | 
			
		||||
                    bt |= (byte)(ch - 'A' + 10);
 | 
			
		||||
                else { Debug.Assert(false); }
 | 
			
		||||
 | 
			
		||||
                pb[i >> 1] = bt;
 | 
			
		||||
@@ -246,20 +192,26 @@ namespace KeePassLib.Utility
 | 
			
		||||
            return l.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static byte[] ParseBase32(string str, bool bAutoPad)
 | 
			
		||||
        {
 | 
			
		||||
            if (str == null) { Debug.Assert(false); return null; }
 | 
			
		||||
 | 
			
		||||
            // https://sourceforge.net/p/keepass/discussion/329220/thread/59b61fddea/
 | 
			
		||||
            if (bAutoPad && ((str.Length % 8) != 0))
 | 
			
		||||
                str = str.PadRight((str.Length & ~7) + 8, '=');
 | 
			
		||||
 | 
			
		||||
            return ParseBase32(str);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Set all bytes in a byte array to zero.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="pbArray">Input array. All bytes of this array
 | 
			
		||||
        /// will be set to zero.</param>
 | 
			
		||||
#if KeePassLibSD
 | 
			
		||||
		[MethodImpl(MethodImplOptions.NoInlining)]
 | 
			
		||||
#else
 | 
			
		||||
		[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
 | 
			
		||||
#endif
 | 
			
		||||
        [MethodImpl(MioNoOptimize)]
 | 
			
		||||
        public static void ZeroByteArray(byte[] pbArray)
 | 
			
		||||
        {
 | 
			
		||||
			Debug.Assert(pbArray != null);
 | 
			
		||||
			if(pbArray == null) throw new ArgumentNullException("pbArray");
 | 
			
		||||
            if (pbArray == null) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
            Array.Clear(pbArray, 0, pbArray.Length);
 | 
			
		||||
        }
 | 
			
		||||
@@ -268,18 +220,41 @@ namespace KeePassLib.Utility
 | 
			
		||||
        /// Set all elements of an array to the default value.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="v">Input array.</param>
 | 
			
		||||
#if KeePassLibSD
 | 
			
		||||
		[MethodImpl(MethodImplOptions.NoInlining)]
 | 
			
		||||
#else
 | 
			
		||||
		[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
 | 
			
		||||
#endif
 | 
			
		||||
        [MethodImpl(MioNoOptimize)]
 | 
			
		||||
        public static void ZeroArray<T>(T[] v)
 | 
			
		||||
        {
 | 
			
		||||
			if(v == null) { Debug.Assert(false); throw new ArgumentNullException("v"); }
 | 
			
		||||
            if (v == null) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
            Array.Clear(v, 0, v.Length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static byte[] g_pbZero = null;
 | 
			
		||||
        [MethodImpl(MioNoOptimize)]
 | 
			
		||||
        public static void ZeroMemory(IntPtr pb, long cb)
 | 
			
		||||
        {
 | 
			
		||||
            if (pb == IntPtr.Zero) { Debug.Assert(false); return; }
 | 
			
		||||
            if (cb < 0) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
            byte[] pbZero = g_pbZero;
 | 
			
		||||
            if (pbZero == null)
 | 
			
		||||
            {
 | 
			
		||||
                pbZero = new byte[4096];
 | 
			
		||||
                g_pbZero = pbZero;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            long cbZero = pbZero.Length;
 | 
			
		||||
 | 
			
		||||
            while (cb != 0)
 | 
			
		||||
            {
 | 
			
		||||
                long cbBlock = Math.Min(cb, cbZero);
 | 
			
		||||
 | 
			
		||||
                Marshal.Copy(pbZero, 0, pb, (int)cbBlock);
 | 
			
		||||
 | 
			
		||||
                pb = AddPtr(pb, cbBlock);
 | 
			
		||||
                cb -= cbBlock;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Convert 2 bytes to a 16-bit unsigned integer (little-endian).
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -396,15 +371,7 @@ namespace KeePassLib.Utility
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static byte[] UInt16ToBytes(ushort uValue)
 | 
			
		||||
        {
 | 
			
		||||
			byte[] pb = new byte[2];
 | 
			
		||||
 | 
			
		||||
			unchecked
 | 
			
		||||
			{
 | 
			
		||||
				pb[0] = (byte)uValue;
 | 
			
		||||
				pb[1] = (byte)(uValue >> 8);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return pb;
 | 
			
		||||
            return new byte[2] { (byte)uValue, (byte)(uValue >> 8) };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -412,17 +379,8 @@ namespace KeePassLib.Utility
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static byte[] UInt32ToBytes(uint uValue)
 | 
			
		||||
        {
 | 
			
		||||
			byte[] pb = new byte[4];
 | 
			
		||||
 | 
			
		||||
			unchecked
 | 
			
		||||
			{
 | 
			
		||||
				pb[0] = (byte)uValue;
 | 
			
		||||
				pb[1] = (byte)(uValue >> 8);
 | 
			
		||||
				pb[2] = (byte)(uValue >> 16);
 | 
			
		||||
				pb[3] = (byte)(uValue >> 24);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return pb;
 | 
			
		||||
            return new byte[4] { (byte)uValue, (byte)(uValue >> 8),
 | 
			
		||||
                (byte)(uValue >> 16), (byte)(uValue >> 24) };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -431,41 +389,27 @@ namespace KeePassLib.Utility
 | 
			
		||||
        public static void UInt32ToBytesEx(uint uValue, byte[] pb, int iOffset)
 | 
			
		||||
        {
 | 
			
		||||
            if (pb == null) { Debug.Assert(false); throw new ArgumentNullException("pb"); }
 | 
			
		||||
			if((iOffset < 0) || ((iOffset + 3) >= pb.Length))
 | 
			
		||||
            if ((iOffset < 0) || (iOffset >= (pb.Length - 3)))
 | 
			
		||||
            {
 | 
			
		||||
                Debug.Assert(false);
 | 
			
		||||
                throw new ArgumentOutOfRangeException("iOffset");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			unchecked
 | 
			
		||||
			{
 | 
			
		||||
            pb[iOffset] = (byte)uValue;
 | 
			
		||||
            pb[iOffset + 1] = (byte)(uValue >> 8);
 | 
			
		||||
            pb[iOffset + 2] = (byte)(uValue >> 16);
 | 
			
		||||
            pb[iOffset + 3] = (byte)(uValue >> 24);
 | 
			
		||||
        }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Convert a 64-bit unsigned integer to 8 bytes (little-endian).
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static byte[] UInt64ToBytes(ulong uValue)
 | 
			
		||||
        {
 | 
			
		||||
			byte[] pb = new byte[8];
 | 
			
		||||
 | 
			
		||||
			unchecked
 | 
			
		||||
			{
 | 
			
		||||
				pb[0] = (byte)uValue;
 | 
			
		||||
				pb[1] = (byte)(uValue >> 8);
 | 
			
		||||
				pb[2] = (byte)(uValue >> 16);
 | 
			
		||||
				pb[3] = (byte)(uValue >> 24);
 | 
			
		||||
				pb[4] = (byte)(uValue >> 32);
 | 
			
		||||
				pb[5] = (byte)(uValue >> 40);
 | 
			
		||||
				pb[6] = (byte)(uValue >> 48);
 | 
			
		||||
				pb[7] = (byte)(uValue >> 56);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return pb;
 | 
			
		||||
            return new byte[8] { (byte)uValue, (byte)(uValue >> 8),
 | 
			
		||||
                (byte)(uValue >> 16), (byte)(uValue >> 24),
 | 
			
		||||
                (byte)(uValue >> 32), (byte)(uValue >> 40),
 | 
			
		||||
                (byte)(uValue >> 48), (byte)(uValue >> 56) };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -474,14 +418,12 @@ namespace KeePassLib.Utility
 | 
			
		||||
        public static void UInt64ToBytesEx(ulong uValue, byte[] pb, int iOffset)
 | 
			
		||||
        {
 | 
			
		||||
            if (pb == null) { Debug.Assert(false); throw new ArgumentNullException("pb"); }
 | 
			
		||||
			if((iOffset < 0) || ((iOffset + 7) >= pb.Length))
 | 
			
		||||
            if ((iOffset < 0) || (iOffset >= (pb.Length - 7)))
 | 
			
		||||
            {
 | 
			
		||||
                Debug.Assert(false);
 | 
			
		||||
                throw new ArgumentOutOfRangeException("iOffset");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			unchecked
 | 
			
		||||
			{
 | 
			
		||||
            pb[iOffset] = (byte)uValue;
 | 
			
		||||
            pb[iOffset + 1] = (byte)(uValue >> 8);
 | 
			
		||||
            pb[iOffset + 2] = (byte)(uValue >> 16);
 | 
			
		||||
@@ -491,18 +433,27 @@ namespace KeePassLib.Utility
 | 
			
		||||
            pb[iOffset + 6] = (byte)(uValue >> 48);
 | 
			
		||||
            pb[iOffset + 7] = (byte)(uValue >> 56);
 | 
			
		||||
        }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        public static byte[] Int32ToBytes(int iValue)
 | 
			
		||||
        {
 | 
			
		||||
            return UInt32ToBytes((uint)iValue);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void Int32ToBytesEx(int iValue, byte[] pb, int iOffset)
 | 
			
		||||
        {
 | 
			
		||||
            UInt32ToBytesEx((uint)iValue, pb, iOffset);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static byte[] Int64ToBytes(long lValue)
 | 
			
		||||
        {
 | 
			
		||||
            return UInt64ToBytes((ulong)lValue);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void Int64ToBytesEx(long lValue, byte[] pb, int iOffset)
 | 
			
		||||
        {
 | 
			
		||||
            UInt64ToBytesEx((ulong)lValue, pb, iOffset);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static uint RotateLeft32(uint u, int nBits)
 | 
			
		||||
        {
 | 
			
		||||
            return ((u << nBits) | (u >> (32 - nBits)));
 | 
			
		||||
@@ -523,14 +474,35 @@ namespace KeePassLib.Utility
 | 
			
		||||
            return ((u >> nBits) | (u << (64 - nBits)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void AddVersionComponent(ref ulong uVersion, int iValue)
 | 
			
		||||
        {
 | 
			
		||||
            if (iValue < 0) iValue = 0;
 | 
			
		||||
            else if (iValue > 0xFFFF) { Debug.Assert(false); iValue = 0xFFFF; }
 | 
			
		||||
 | 
			
		||||
            uVersion = (uVersion << 16) | (uint)iValue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static ulong VersionToUInt64(Version v)
 | 
			
		||||
        {
 | 
			
		||||
            if (v == null) { Debug.Assert(false); return 0; }
 | 
			
		||||
 | 
			
		||||
            ulong u = 0;
 | 
			
		||||
            AddVersionComponent(ref u, v.Major);
 | 
			
		||||
            AddVersionComponent(ref u, v.Minor);
 | 
			
		||||
            AddVersionComponent(ref u, v.Build);
 | 
			
		||||
            AddVersionComponent(ref u, v.Revision);
 | 
			
		||||
            return u;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static bool ArraysEqual(byte[] x, byte[] y)
 | 
			
		||||
        {
 | 
			
		||||
            // Return false if one of them is null (not comparable)!
 | 
			
		||||
            if ((x == null) || (y == null)) { Debug.Assert(false); return false; }
 | 
			
		||||
 | 
			
		||||
			if(x.Length != y.Length) return false;
 | 
			
		||||
            int cb = x.Length;
 | 
			
		||||
            if (cb != y.Length) return false;
 | 
			
		||||
 | 
			
		||||
			for(int i = 0; i < x.Length; ++i)
 | 
			
		||||
            for (int i = 0; i < cb; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                if (x[i] != y[i]) return false;
 | 
			
		||||
            }
 | 
			
		||||
@@ -556,28 +528,90 @@ namespace KeePassLib.Utility
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
		/// Fast hash that can be used e.g. for hash tables.
 | 
			
		||||
        /// Fast 32-bit hash (e.g. for hash tables).
 | 
			
		||||
        /// The algorithm might change in the future; do not store
 | 
			
		||||
        /// the hashes for later use.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
		public static uint Hash32(byte[] v, int iStart, int iLength)
 | 
			
		||||
        public static uint Hash32(byte[] pb, int iOffset, int cb)
 | 
			
		||||
        {
 | 
			
		||||
			uint u = 0x326F637B;
 | 
			
		||||
            const ulong hI = 0x4295DC458269ED9DUL;
 | 
			
		||||
            const uint hI32 = (uint)(hI >> 32);
 | 
			
		||||
 | 
			
		||||
			if(v == null) { Debug.Assert(false); return u; }
 | 
			
		||||
			if(iStart < 0) { Debug.Assert(false); return u; }
 | 
			
		||||
			if(iLength < 0) { Debug.Assert(false); return u; }
 | 
			
		||||
            if (pb == null) { Debug.Assert(false); return hI32; }
 | 
			
		||||
            if (iOffset < 0) { Debug.Assert(false); return hI32; }
 | 
			
		||||
            if (cb < 0) { Debug.Assert(false); return hI32; }
 | 
			
		||||
 | 
			
		||||
			int m = iStart + iLength;
 | 
			
		||||
			if(m > v.Length) { Debug.Assert(false); return u; }
 | 
			
		||||
            int m = iOffset + cb;
 | 
			
		||||
            if ((m < 0) || (m > pb.Length)) { Debug.Assert(false); return hI32; }
 | 
			
		||||
 | 
			
		||||
			for(int i = iStart; i < m; ++i)
 | 
			
		||||
            int m4 = iOffset + (cb & ~3), cbR = cb & 3;
 | 
			
		||||
            ulong h = hI;
 | 
			
		||||
 | 
			
		||||
            for (int i = iOffset; i < m4; i += 4)
 | 
			
		||||
                h = (pb[i] ^ ((ulong)pb[i + 1] << 8) ^ ((ulong)pb[i + 2] << 16) ^
 | 
			
		||||
                    ((ulong)pb[i + 3] << 24) ^ h) * 0x5EA4A1E35C8ACDA3UL;
 | 
			
		||||
 | 
			
		||||
            switch (cbR)
 | 
			
		||||
            {
 | 
			
		||||
				u ^= m_vSBox[v[i]];
 | 
			
		||||
				u *= 3;
 | 
			
		||||
                case 1:
 | 
			
		||||
                    Debug.Assert(m4 == (m - 1));
 | 
			
		||||
                    h = (pb[m4] ^ h) * 0x54A1CC5970AF27BBUL;
 | 
			
		||||
                    break;
 | 
			
		||||
                case 2:
 | 
			
		||||
                    Debug.Assert(m4 == (m - 2));
 | 
			
		||||
                    h = (pb[m4] ^ ((ulong)pb[m4 + 1] << 8) ^ h) *
 | 
			
		||||
                        0x6C45CB2537A4271DUL;
 | 
			
		||||
                    break;
 | 
			
		||||
                case 3:
 | 
			
		||||
                    Debug.Assert(m4 == (m - 3));
 | 
			
		||||
                    h = (pb[m4] ^ ((ulong)pb[m4 + 1] << 8) ^
 | 
			
		||||
                        ((ulong)pb[m4 + 2] << 16) ^ h) * 0x59B8E8939E19695DUL;
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    Debug.Assert(m4 == m);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			return u;
 | 
			
		||||
            Debug.Assert((cb != 0) || ((uint)(h >> 32) == hI32));
 | 
			
		||||
            return (uint)(h >> 32);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static uint Hash32Ex<T>(T[] v, int iOffset, int c)
 | 
			
		||||
        {
 | 
			
		||||
            const ulong hI = 0x4295DC458269ED9DUL;
 | 
			
		||||
            const uint hI32 = (uint)(hI >> 32);
 | 
			
		||||
 | 
			
		||||
            if (v == null) { Debug.Assert(false); return hI32; }
 | 
			
		||||
            if (iOffset < 0) { Debug.Assert(false); return hI32; }
 | 
			
		||||
            if (c < 0) { Debug.Assert(false); return hI32; }
 | 
			
		||||
 | 
			
		||||
            int m = iOffset + c;
 | 
			
		||||
            if ((m < 0) || (m > v.Length)) { Debug.Assert(false); return hI32; }
 | 
			
		||||
 | 
			
		||||
            ulong h = hI;
 | 
			
		||||
 | 
			
		||||
            for (int i = iOffset; i < m; ++i)
 | 
			
		||||
                h = (h ^ (uint)v[i].GetHashCode()) * 0x5EA4A1E35C8ACDA3UL;
 | 
			
		||||
 | 
			
		||||
            Debug.Assert((c != 0) || ((uint)(h >> 32) == hI32));
 | 
			
		||||
            return (uint)(h >> 32);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static ulong Hash64(int[] v, int iOffset, int ci)
 | 
			
		||||
        {
 | 
			
		||||
            ulong h = 0x4295DC458269ED9DUL;
 | 
			
		||||
 | 
			
		||||
            if (v == null) { Debug.Assert(false); return h; }
 | 
			
		||||
            if (iOffset < 0) { Debug.Assert(false); return h; }
 | 
			
		||||
            if (ci < 0) { Debug.Assert(false); return h; }
 | 
			
		||||
 | 
			
		||||
            int m = iOffset + ci;
 | 
			
		||||
            if ((m < 0) || (m > v.Length)) { Debug.Assert(false); return h; }
 | 
			
		||||
 | 
			
		||||
            for (int i = iOffset; i < m; ++i)
 | 
			
		||||
                h = (h ^ (uint)v[i]) * 0x5EA4A1E35C8ACDA3UL;
 | 
			
		||||
 | 
			
		||||
            return ((h ^ (h >> 32)) * 0x59B8E8939E19695DUL);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void CopyStream(Stream sSource, Stream sTarget)
 | 
			
		||||
@@ -586,20 +620,31 @@ namespace KeePassLib.Utility
 | 
			
		||||
            if (sSource == null) throw new ArgumentNullException("sSource");
 | 
			
		||||
            if (sTarget == null) throw new ArgumentNullException("sTarget");
 | 
			
		||||
 | 
			
		||||
			const int nBufSize = 4096;
 | 
			
		||||
			byte[] pbBuf = new byte[nBufSize];
 | 
			
		||||
            const int cbBuf = 4096;
 | 
			
		||||
            byte[] pbBuf = new byte[cbBuf];
 | 
			
		||||
 | 
			
		||||
            while (true)
 | 
			
		||||
            {
 | 
			
		||||
				int nRead = sSource.Read(pbBuf, 0, nBufSize);
 | 
			
		||||
				if(nRead == 0) break;
 | 
			
		||||
                int cbRead = sSource.Read(pbBuf, 0, cbBuf);
 | 
			
		||||
                if (cbRead == 0) break;
 | 
			
		||||
 | 
			
		||||
				sTarget.Write(pbBuf, 0, nRead);
 | 
			
		||||
                sTarget.Write(pbBuf, 0, cbRead);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Do not close any of the streams
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static byte[] Read(Stream s)
 | 
			
		||||
        {
 | 
			
		||||
            if (s == null) throw new ArgumentNullException("s");
 | 
			
		||||
 | 
			
		||||
            using (MemoryStream ms = new MemoryStream())
 | 
			
		||||
            {
 | 
			
		||||
                CopyStream(s, ms);
 | 
			
		||||
                return ms.ToArray();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static byte[] Read(Stream s, int nCount)
 | 
			
		||||
        {
 | 
			
		||||
            if (s == null) throw new ArgumentNullException("s");
 | 
			
		||||
@@ -626,6 +671,17 @@ namespace KeePassLib.Utility
 | 
			
		||||
            return pb;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static string ReadString(Stream s, Encoding enc)
 | 
			
		||||
        {
 | 
			
		||||
            if (s == null) throw new ArgumentNullException("s");
 | 
			
		||||
            if (enc == null) throw new ArgumentNullException("enc");
 | 
			
		||||
 | 
			
		||||
            using (StreamReader sr = new StreamReader(s, enc, true))
 | 
			
		||||
            {
 | 
			
		||||
                return sr.ReadToEnd();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void Write(Stream s, byte[] pbData)
 | 
			
		||||
        {
 | 
			
		||||
            if (s == null) { Debug.Assert(false); return; }
 | 
			
		||||
@@ -640,7 +696,6 @@ namespace KeePassLib.Utility
 | 
			
		||||
            if (pbData == null) throw new ArgumentNullException("pbData");
 | 
			
		||||
            if (pbData.Length == 0) return pbData;
 | 
			
		||||
 | 
			
		||||
			byte[] pbCompressed;
 | 
			
		||||
            using (MemoryStream msSource = new MemoryStream(pbData, false))
 | 
			
		||||
            {
 | 
			
		||||
                using (MemoryStream msCompressed = new MemoryStream())
 | 
			
		||||
@@ -648,14 +703,12 @@ namespace KeePassLib.Utility
 | 
			
		||||
                    using (GZipStream gz = new GZipStream(msCompressed,
 | 
			
		||||
                        CompressionMode.Compress))
 | 
			
		||||
                    {
 | 
			
		||||
						MemUtil.CopyStream(msSource, gz);
 | 
			
		||||
                        CopyStream(msSource, gz);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
					pbCompressed = msCompressed.ToArray();
 | 
			
		||||
                    return msCompressed.ToArray();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			return pbCompressed;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static byte[] Decompress(byte[] pbCompressed)
 | 
			
		||||
@@ -663,7 +716,6 @@ namespace KeePassLib.Utility
 | 
			
		||||
            if (pbCompressed == null) throw new ArgumentNullException("pbCompressed");
 | 
			
		||||
            if (pbCompressed.Length == 0) return pbCompressed;
 | 
			
		||||
 | 
			
		||||
			byte[] pbData;
 | 
			
		||||
            using (MemoryStream msData = new MemoryStream())
 | 
			
		||||
            {
 | 
			
		||||
                using (MemoryStream msCompressed = new MemoryStream(pbCompressed, false))
 | 
			
		||||
@@ -671,14 +723,12 @@ namespace KeePassLib.Utility
 | 
			
		||||
                    using (GZipStream gz = new GZipStream(msCompressed,
 | 
			
		||||
                        CompressionMode.Decompress))
 | 
			
		||||
                    {
 | 
			
		||||
						MemUtil.CopyStream(gz, msData);
 | 
			
		||||
                        CopyStream(gz, msData);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
				pbData = msData.ToArray();
 | 
			
		||||
                return msData.ToArray();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			return pbData;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int IndexOf<T>(T[] vHaystack, T[] vNeedle)
 | 
			
		||||
@@ -688,10 +738,13 @@ namespace KeePassLib.Utility
 | 
			
		||||
            if (vNeedle == null) throw new ArgumentNullException("vNeedle");
 | 
			
		||||
            if (vNeedle.Length == 0) return 0;
 | 
			
		||||
 | 
			
		||||
			for(int i = 0; i <= (vHaystack.Length - vNeedle.Length); ++i)
 | 
			
		||||
            int cN = vNeedle.Length;
 | 
			
		||||
            int iMax = vHaystack.Length - cN;
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i <= iMax; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                bool bFound = true;
 | 
			
		||||
				for(int m = 0; m < vNeedle.Length; ++m)
 | 
			
		||||
                for (int m = 0; m < cN; ++m)
 | 
			
		||||
                {
 | 
			
		||||
                    if (!vHaystack[i + m].Equals(vNeedle[m]))
 | 
			
		||||
                    {
 | 
			
		||||
@@ -786,6 +839,44 @@ namespace KeePassLib.Utility
 | 
			
		||||
 | 
			
		||||
            yield break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static IEnumerable<T> Distinct<T, TKey>(IEnumerable<T> s,
 | 
			
		||||
            GFunc<T, TKey> fGetKey, bool bPreferLast)
 | 
			
		||||
        {
 | 
			
		||||
            if (s == null) throw new ArgumentNullException("s");
 | 
			
		||||
            if (fGetKey == null) throw new ArgumentNullException("fGetKey");
 | 
			
		||||
 | 
			
		||||
            Dictionary<TKey, bool> d = new Dictionary<TKey, bool>();
 | 
			
		||||
 | 
			
		||||
            if (bPreferLast)
 | 
			
		||||
            {
 | 
			
		||||
                List<T> l = new List<T>(s);
 | 
			
		||||
                int n = l.Count;
 | 
			
		||||
                bool[] v = new bool[n];
 | 
			
		||||
 | 
			
		||||
                for (int i = n - 1; i >= 0; --i)
 | 
			
		||||
                {
 | 
			
		||||
                    TKey k = fGetKey(l[i]);
 | 
			
		||||
                    if (!d.ContainsKey(k)) { d[k] = true; v[i] = true; }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                for (int i = 0; i < n; ++i)
 | 
			
		||||
                {
 | 
			
		||||
                    if (v[i]) yield return l[i];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                foreach (T t in s)
 | 
			
		||||
                {
 | 
			
		||||
                    TKey k = fGetKey(t);
 | 
			
		||||
                    if (!d.ContainsKey(k)) { d[k] = true; yield return t; }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            yield break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static bool ListsEqual<T>(List<T> a, List<T> b)
 | 
			
		||||
            where T : class, IEquatable<T>
 | 
			
		||||
        {
 | 
			
		||||
@@ -809,5 +900,164 @@ namespace KeePassLib.Utility
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static int Count(byte[] pb, byte bt)
 | 
			
		||||
        {
 | 
			
		||||
            if (pb == null) { Debug.Assert(false); return 0; }
 | 
			
		||||
 | 
			
		||||
            int cb = pb.Length, r = 0;
 | 
			
		||||
            for (int i = 0; i < cb; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                if (pb[i] == bt) ++r;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return r;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [MethodImpl(MioNoOptimize)]
 | 
			
		||||
        internal static void DisposeIfPossible(object o)
 | 
			
		||||
        {
 | 
			
		||||
            if (o == null) { Debug.Assert(false); return; }
 | 
			
		||||
 | 
			
		||||
            IDisposable d = (o as IDisposable);
 | 
			
		||||
            if (d != null) d.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static object GetEnumValue(Type tEnum, string strName)
 | 
			
		||||
        {
 | 
			
		||||
            if (tEnum == null) { Debug.Assert(false); return null; }
 | 
			
		||||
            if (!tEnum.IsEnum) { Debug.Assert(false); return null; }
 | 
			
		||||
            if (string.IsNullOrEmpty(strName)) { Debug.Assert(false); return null; }
 | 
			
		||||
 | 
			
		||||
            return ((Array.IndexOf<string>(Enum.GetNames(tEnum), strName) >= 0) ?
 | 
			
		||||
                Enum.Parse(tEnum, strName) : null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static T ConvertObject<T>(object o, T tDefault)
 | 
			
		||||
        {
 | 
			
		||||
            if (o == null) return tDefault;
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                if (o is T) return (T)o;
 | 
			
		||||
                return (T)Convert.ChangeType(o, typeof(T));
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception) { Debug.Assert(false); }
 | 
			
		||||
 | 
			
		||||
            try { return (T)o; }
 | 
			
		||||
            catch (Exception) { Debug.Assert(false); }
 | 
			
		||||
 | 
			
		||||
            return tDefault;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static T BytesToStruct<T>(byte[] pb, int iOffset)
 | 
			
		||||
            where T : struct
 | 
			
		||||
        {
 | 
			
		||||
            if (pb == null) throw new ArgumentNullException("pb");
 | 
			
		||||
            if (iOffset < 0) throw new ArgumentOutOfRangeException("iOffset");
 | 
			
		||||
 | 
			
		||||
            int cb = Marshal.SizeOf(typeof(T));
 | 
			
		||||
            if (cb <= 0) { Debug.Assert(false); return default(T); }
 | 
			
		||||
 | 
			
		||||
            if (iOffset > (pb.Length - cb)) throw new ArgumentOutOfRangeException("iOffset");
 | 
			
		||||
 | 
			
		||||
            IntPtr p = Marshal.AllocCoTaskMem(cb);
 | 
			
		||||
            if (p == IntPtr.Zero) throw new OutOfMemoryException();
 | 
			
		||||
 | 
			
		||||
            object o;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Marshal.Copy(pb, iOffset, p, cb);
 | 
			
		||||
                o = Marshal.PtrToStructure(p, typeof(T));
 | 
			
		||||
            }
 | 
			
		||||
            finally { Marshal.FreeCoTaskMem(p); }
 | 
			
		||||
 | 
			
		||||
            return (T)o;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static byte[] StructToBytes<T>(ref T t)
 | 
			
		||||
            where T : struct
 | 
			
		||||
        {
 | 
			
		||||
            int cb = Marshal.SizeOf(typeof(T));
 | 
			
		||||
            if (cb <= 0) { Debug.Assert(false); return MemUtil.EmptyByteArray; }
 | 
			
		||||
 | 
			
		||||
            byte[] pb = new byte[cb];
 | 
			
		||||
 | 
			
		||||
            IntPtr p = Marshal.AllocCoTaskMem(cb);
 | 
			
		||||
            if (p == IntPtr.Zero) throw new OutOfMemoryException();
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Marshal.StructureToPtr(t, p, false);
 | 
			
		||||
                Marshal.Copy(p, pb, 0, cb);
 | 
			
		||||
            }
 | 
			
		||||
            finally { Marshal.FreeCoTaskMem(p); }
 | 
			
		||||
 | 
			
		||||
            return pb;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static IntPtr AddPtr(IntPtr p, long cb)
 | 
			
		||||
        {
 | 
			
		||||
            // IntPtr.operator+ and IntPtr.Add are not available in .NET 2.0
 | 
			
		||||
 | 
			
		||||
            if (IntPtr.Size >= 8)
 | 
			
		||||
                return new IntPtr(unchecked(p.ToInt64() + cb));
 | 
			
		||||
            return new IntPtr(unchecked(p.ToInt32() + (int)cb));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Cf. Array.Empty<T>() of .NET 4.6
 | 
			
		||||
        private static class EmptyArrayEx<T>
 | 
			
		||||
        {
 | 
			
		||||
            internal static readonly T[] Instance = new T[0];
 | 
			
		||||
        }
 | 
			
		||||
        internal static T[] EmptyArray<T>()
 | 
			
		||||
        {
 | 
			
		||||
            return EmptyArrayEx<T>.Instance;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal sealed class ArrayHelperEx<T> : IEqualityComparer<T[]>, IComparer<T[]>
 | 
			
		||||
        where T : IEquatable<T>, IComparable<T>
 | 
			
		||||
    {
 | 
			
		||||
        public int GetHashCode(T[] obj)
 | 
			
		||||
        {
 | 
			
		||||
            if (obj == null) { Debug.Assert(false); throw new ArgumentNullException("obj"); }
 | 
			
		||||
 | 
			
		||||
            return (int)MemUtil.Hash32Ex<T>(obj, 0, obj.Length);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Equals(T[] x, T[] y)
 | 
			
		||||
        {
 | 
			
		||||
            if (object.ReferenceEquals(x, y)) return true;
 | 
			
		||||
            if ((x == null) || (y == null)) return false;
 | 
			
		||||
 | 
			
		||||
            int n = x.Length;
 | 
			
		||||
            if (n != y.Length) return false;
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < n; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                if (!x[i].Equals(y[i])) return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int Compare(T[] x, T[] y)
 | 
			
		||||
        {
 | 
			
		||||
            if (object.ReferenceEquals(x, y)) return 0;
 | 
			
		||||
            if (x == null) return -1;
 | 
			
		||||
            if (y == null) return 1;
 | 
			
		||||
 | 
			
		||||
            int n = x.Length, m = y.Length;
 | 
			
		||||
            if (n != m) return ((n < m) ? -1 : 1);
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < n; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                T tX = x[i], tY = y[i];
 | 
			
		||||
                if (!tX.Equals(tY)) return tX.CompareTo(tY);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -140,6 +140,10 @@ namespace keepass2android
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
        int WebDavChunkedUploadSize
 | 
			
		||||
        {
 | 
			
		||||
            get;
 | 
			
		||||
        }
 | 
			
		||||
	    
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -15,6 +15,8 @@ namespace keepass2android.Io
 | 
			
		||||
	    {
 | 
			
		||||
	        get { return false; }
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
        static public bool IsConfigured => !string.IsNullOrEmpty(AppKey) && !string.IsNullOrEmpty(AppSecret);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	public partial class DropboxAppFolderFileStorage: JavaFileStorage
 | 
			
		||||
@@ -29,6 +31,7 @@ namespace keepass2android.Io
 | 
			
		||||
	        get { return false; }
 | 
			
		||||
	    }
 | 
			
		||||
 | 
			
		||||
        static public bool IsConfigured => !string.IsNullOrEmpty(AppKey) && !string.IsNullOrEmpty(AppSecret);
 | 
			
		||||
    }
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -123,7 +123,7 @@ namespace keepass2android.Io
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
 | 
			
		||||
		public virtual IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
 | 
			
		||||
		{
 | 
			
		||||
			return new JavaFileStorageWriteTransaction(IocToPath(ioc), useFileTransaction, this);
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ using Android.Content;
 | 
			
		||||
using Android.OS;
 | 
			
		||||
using FluentFTP;
 | 
			
		||||
using FluentFTP.Exceptions;
 | 
			
		||||
using FluentFTP.GnuTLS;
 | 
			
		||||
using KeePass.Util;
 | 
			
		||||
using KeePassLib;
 | 
			
		||||
using KeePassLib.Serialization;
 | 
			
		||||
@@ -140,6 +141,7 @@ namespace keepass2android.Io
 | 
			
		||||
			var settings = ConnectionSettings.FromIoc(ioc);
 | 
			
		||||
			
 | 
			
		||||
			FtpClient client = new FtpClient();
 | 
			
		||||
            client.Config.CustomStream = typeof(GnuTlsStream);
 | 
			
		||||
			client.Config.RetryAttempts = 3;
 | 
			
		||||
			if ((settings.Username.Length > 0) || (settings.Password.Length > 0))
 | 
			
		||||
				client.Credentials = new NetworkCredential(settings.Username, settings.Password);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										617
									
								
								src/Kp2aBusinessLogic/Io/SmbFileStorage.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										617
									
								
								src/Kp2aBusinessLogic/Io/SmbFileStorage.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,617 @@
 | 
			
		||||
#if !NoNet
 | 
			
		||||
using System.Net;
 | 
			
		||||
using Android.Content;
 | 
			
		||||
using keepass2android;
 | 
			
		||||
using keepass2android.Io;
 | 
			
		||||
using KeePassLib.Serialization;
 | 
			
		||||
using SMBLibrary.Client;
 | 
			
		||||
using SMBLibrary;
 | 
			
		||||
using FileAttributes = SMBLibrary.FileAttributes;
 | 
			
		||||
using KeePassLib.Utility;
 | 
			
		||||
using Java.Nio.FileNio;
 | 
			
		||||
 | 
			
		||||
namespace Kp2aBusinessLogic.Io
 | 
			
		||||
{
 | 
			
		||||
    public class SmbFileStorage : IFileStorage
 | 
			
		||||
    {
 | 
			
		||||
        public IEnumerable<string> SupportedProtocols
 | 
			
		||||
        {
 | 
			
		||||
            get { yield return "smb"; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool UserShouldBackup
 | 
			
		||||
        {
 | 
			
		||||
            get { return false; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Delete(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            throw new NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool CheckForFileChangeFast(IOConnectionInfo ioc, string previousFileVersion)
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetCurrentFileVersionFast(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public struct SmbConnectionInfo
 | 
			
		||||
        {
 | 
			
		||||
            public string Host;
 | 
			
		||||
            public string Username;
 | 
			
		||||
            public string Password;
 | 
			
		||||
            public string? Domain;
 | 
			
		||||
            public string? Share;
 | 
			
		||||
            public string? LocalPath;
 | 
			
		||||
 | 
			
		||||
            public static SmbConnectionInfo FromUrlAndCredentials(string url, string username, string password, string? domain)
 | 
			
		||||
            {
 | 
			
		||||
                string userDomain = username;
 | 
			
		||||
                if (domain != null)
 | 
			
		||||
                {
 | 
			
		||||
                    userDomain = domain + "\\" + username;
 | 
			
		||||
                }
 | 
			
		||||
                if (url.StartsWith("smb://"))
 | 
			
		||||
                {
 | 
			
		||||
                    url = url.Substring(6);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (url.StartsWith("\\\\"))
 | 
			
		||||
                {
 | 
			
		||||
                    url = url.Substring(2);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                url = url.Replace("\\", "/");
 | 
			
		||||
            
 | 
			
		||||
                string fullPath = "smb://" + WebUtility.UrlEncode(userDomain) + ":" + WebUtility.UrlEncode(password) + "@" + url;
 | 
			
		||||
                return new SmbConnectionInfo(new IOConnectionInfo() { Path = fullPath} );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            public SmbConnectionInfo(IOConnectionInfo ioc)
 | 
			
		||||
            {
 | 
			
		||||
                string fullpath = ioc.Path;
 | 
			
		||||
                if (!fullpath.StartsWith("smb://"))
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Invalid smb path!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                fullpath = fullpath.Substring(6);
 | 
			
		||||
                string[] authAndPath = fullpath.Split('@');
 | 
			
		||||
                if (authAndPath.Length != 2)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Invalid smb path!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                string[] userAndPwd = authAndPath[0].Split(':');
 | 
			
		||||
                if (userAndPwd.Length != 2)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Invalid smb path!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                string[] pathParts = authAndPath[1].Split('/');
 | 
			
		||||
                if (pathParts.Length < 1)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Invalid smb path!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Host = pathParts[0];
 | 
			
		||||
                if (pathParts.Length > 1)
 | 
			
		||||
                {
 | 
			
		||||
                    Share = pathParts[1];
 | 
			
		||||
                }
 | 
			
		||||
                LocalPath = String.Join("/", pathParts.Skip(2));
 | 
			
		||||
                if (LocalPath.EndsWith("/"))
 | 
			
		||||
                {
 | 
			
		||||
                    LocalPath = LocalPath.Substring(0, LocalPath.Length - 1);
 | 
			
		||||
                }
 | 
			
		||||
            
 | 
			
		||||
                Username = WebUtility.UrlDecode(userAndPwd[0]);
 | 
			
		||||
                if (Username.Contains("\\"))
 | 
			
		||||
                {
 | 
			
		||||
                    string[] domainAndUser = Username.Split('\\');
 | 
			
		||||
                    Domain = domainAndUser[0];
 | 
			
		||||
                    Username = domainAndUser[1];
 | 
			
		||||
                }
 | 
			
		||||
                else Domain = null;
 | 
			
		||||
 | 
			
		||||
                Password = WebUtility.UrlDecode(userAndPwd[1]);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public string ToPath()
 | 
			
		||||
            {
 | 
			
		||||
                string domainUser = Username;
 | 
			
		||||
                if (Domain != null)
 | 
			
		||||
                {
 | 
			
		||||
                    domainUser = Domain + "\\" + Username;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return "smb://" + WebUtility.UrlEncode(domainUser) + ":" + WebUtility.UrlEncode(Password) + "@" + Host +
 | 
			
		||||
                       "/" + Share + "/" + LocalPath;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public string GetPathWithoutCredentials()
 | 
			
		||||
            {
 | 
			
		||||
                return "smb://" + Host + "/" + Share + "/" + LocalPath;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public string GetLocalSmbPath()
 | 
			
		||||
            {
 | 
			
		||||
                return LocalPath?.Replace("/", "\\") ?? "";
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public SmbConnectionInfo GetParent()
 | 
			
		||||
            {
 | 
			
		||||
                SmbConnectionInfo parent = new SmbConnectionInfo
 | 
			
		||||
                {
 | 
			
		||||
                    Host = Host,
 | 
			
		||||
                    Username = Username,
 | 
			
		||||
                    Password = Password,
 | 
			
		||||
                    Domain = Domain,
 | 
			
		||||
                    Share = Share
 | 
			
		||||
                };
 | 
			
		||||
                string[] pathParts = LocalPath?.Split('/') ?? [];
 | 
			
		||||
                if (pathParts.Length > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    parent.LocalPath = string.Join("/", pathParts.Take(pathParts.Length - 1));
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    parent.LocalPath = "";
 | 
			
		||||
                    parent.Share = "";
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return parent;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public string Stem()
 | 
			
		||||
            {
 | 
			
		||||
                return LocalPath?.Split('/').Last() ?? "";
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            public SmbConnectionInfo GetChild(string childName)
 | 
			
		||||
            {
 | 
			
		||||
                SmbConnectionInfo child = new SmbConnectionInfo();
 | 
			
		||||
                child.Host = Host;
 | 
			
		||||
                child.Username = Username;
 | 
			
		||||
                child.Password = Password;
 | 
			
		||||
                child.Domain = Domain;
 | 
			
		||||
                if (string.IsNullOrEmpty(Share))
 | 
			
		||||
                {
 | 
			
		||||
                    child.Share = childName;
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
 | 
			
		||||
                    child.Share = Share;
 | 
			
		||||
                    var pathPartsList = LocalPath?.Split('/').Where(p => !string.IsNullOrEmpty(p)).ToList() ?? [];
 | 
			
		||||
                    pathPartsList.Add(childName);
 | 
			
		||||
                    child.LocalPath = string.Join("/", pathPartsList);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return child;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public string ToDisplayString()
 | 
			
		||||
            {
 | 
			
		||||
                return "smb://" + Host + "/" + Share + "/" + LocalPath;
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        class SmbConnection: IDisposable
 | 
			
		||||
        {
 | 
			
		||||
            public SmbConnection(SmbConnectionInfo info)
 | 
			
		||||
            {
 | 
			
		||||
                _isLoggedIn = false;
 | 
			
		||||
                var isConnected = Client.Connect(info.Host, SMBTransportType.DirectTCPTransport);
 | 
			
		||||
                if (!isConnected)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception($"Failed to connect to SMB server {info.Host}");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var status = Client.Login(info.Domain ?? string.Empty, info.Username, info.Password);
 | 
			
		||||
                if (status != NTStatus.STATUS_SUCCESS)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception($"Failed to login to SMB as {info.Username}");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                _isLoggedIn = true;
 | 
			
		||||
 | 
			
		||||
                if (!string.IsNullOrEmpty(info.Share))
 | 
			
		||||
                {
 | 
			
		||||
                    FileStore = Client.TreeConnect(info.Share, out status);
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            public readonly SMB2Client Client = new SMB2Client();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            public readonly ISMBFileStore? FileStore;
 | 
			
		||||
            private readonly bool _isLoggedIn;
 | 
			
		||||
 | 
			
		||||
            public void Dispose()
 | 
			
		||||
            {
 | 
			
		||||
                FileStore?.Disconnect();
 | 
			
		||||
                
 | 
			
		||||
                if (_isLoggedIn)
 | 
			
		||||
                    Client.Logoff();
 | 
			
		||||
 | 
			
		||||
                if (!Client.IsConnected) return;
 | 
			
		||||
                Client.Disconnect();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Stream OpenFileForRead(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            SmbConnectionInfo info = new SmbConnectionInfo(ioc);
 | 
			
		||||
            using SmbConnection conn = new SmbConnection(info);
 | 
			
		||||
 | 
			
		||||
            if (conn.FileStore == null)
 | 
			
		||||
            {
 | 
			
		||||
                throw new Exception($"Failed to read to {info.GetPathWithoutCredentials()}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            NTStatus status = conn.FileStore.CreateFile(out var fileHandle, out _, info.GetLocalSmbPath(),
 | 
			
		||||
                AccessMask.GENERIC_READ | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.Read,
 | 
			
		||||
                CreateDisposition.FILE_OPEN,
 | 
			
		||||
                CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
 | 
			
		||||
 | 
			
		||||
            if (status != NTStatus.STATUS_SUCCESS)
 | 
			
		||||
            {
 | 
			
		||||
                throw new Exception($"Failed to open file {info.LocalPath}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var stream = new MemoryStream();
 | 
			
		||||
            long bytesRead = 0;
 | 
			
		||||
            while (true)
 | 
			
		||||
            {
 | 
			
		||||
                status = conn.FileStore.ReadFile(out var data, fileHandle, bytesRead, (int)conn.Client.MaxReadSize);
 | 
			
		||||
                if (status != NTStatus.STATUS_SUCCESS && status != NTStatus.STATUS_END_OF_FILE)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Failed to read from file");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (status == NTStatus.STATUS_END_OF_FILE || data.Length == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                bytesRead += data.Length;
 | 
			
		||||
                stream.Write(data, 0, data.Length);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            stream.Seek(0, SeekOrigin.Begin);
 | 
			
		||||
            return stream;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        class SmbFileStorageWriteTransaction : IWriteTransaction
 | 
			
		||||
        {
 | 
			
		||||
            private bool UseFileTransaction { get; }
 | 
			
		||||
            private readonly string _path;
 | 
			
		||||
            private readonly string _uploadPath;
 | 
			
		||||
            private readonly SmbFileStorage _fileStorage;
 | 
			
		||||
            private MemoryStream? _memoryStream;
 | 
			
		||||
 | 
			
		||||
            public SmbFileStorageWriteTransaction(string path, SmbFileStorage fileStorage, bool useFileTransaction)
 | 
			
		||||
            {
 | 
			
		||||
                UseFileTransaction = useFileTransaction;
 | 
			
		||||
                _path = path;
 | 
			
		||||
                if (useFileTransaction)
 | 
			
		||||
                {
 | 
			
		||||
                    _uploadPath = _path + Guid.NewGuid().ToString().Substring(0, 8) + ".tmp";
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    _uploadPath = _path;
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
                _fileStorage = fileStorage;
 | 
			
		||||
                _memoryStream = null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public void Dispose()
 | 
			
		||||
            {
 | 
			
		||||
                _memoryStream?.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public Stream OpenFile()
 | 
			
		||||
            {
 | 
			
		||||
                _memoryStream = new MemoryStream();
 | 
			
		||||
                return _memoryStream;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public void CommitWrite()
 | 
			
		||||
            {
 | 
			
		||||
                _fileStorage.UploadData(new MemoryStream(_memoryStream!.ToArray()), new SmbConnectionInfo(new IOConnectionInfo() { Path = _uploadPath}));
 | 
			
		||||
                if (UseFileTransaction)
 | 
			
		||||
                {
 | 
			
		||||
                    SmbConnectionInfo uploadPath = new SmbConnectionInfo(new IOConnectionInfo() { Path = _uploadPath });
 | 
			
		||||
                    SmbConnectionInfo finalPath = new SmbConnectionInfo(new IOConnectionInfo() { Path = _path });
 | 
			
		||||
                    _fileStorage.RenameFile(uploadPath, finalPath);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void RenameFile(SmbConnectionInfo fromPath, SmbConnectionInfo toPath)
 | 
			
		||||
        {
 | 
			
		||||
            using var connection = new SmbConnection(fromPath);
 | 
			
		||||
 | 
			
		||||
            // Open existing file
 | 
			
		||||
            var status = connection.FileStore!.CreateFile(out var handle, out _, fromPath.GetLocalSmbPath(), AccessMask.MAXIMUM_ALLOWED, 0, ShareAccess.Read, CreateDisposition.FILE_OPEN, CreateOptions.FILE_NON_DIRECTORY_FILE, null);
 | 
			
		||||
            if (status != NTStatus.STATUS_SUCCESS)
 | 
			
		||||
                throw new Exception($"Failed to open {fromPath.LocalPath} for renaming!");
 | 
			
		||||
        
 | 
			
		||||
            FileRenameInformationType2 renameInfo = new FileRenameInformationType2
 | 
			
		||||
            {
 | 
			
		||||
                FileName = toPath.GetLocalSmbPath(),
 | 
			
		||||
                ReplaceIfExists = true
 | 
			
		||||
            };
 | 
			
		||||
            connection.FileStore.SetFileInformation(handle, renameInfo);
 | 
			
		||||
            connection.FileStore.CloseFile(handle);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void UploadData(Stream data, SmbConnectionInfo uploadPath)
 | 
			
		||||
        {
 | 
			
		||||
            using var connection = new SmbConnection(uploadPath);
 | 
			
		||||
            var status = connection.FileStore!.CreateFile(out var fileHandle, out _, uploadPath.GetLocalSmbPath(), AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_CREATE, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
 | 
			
		||||
            if (status == NTStatus.STATUS_OBJECT_NAME_COLLISION)
 | 
			
		||||
                status = connection.FileStore!.CreateFile(out fileHandle, out _, uploadPath.GetLocalSmbPath(), AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_OVERWRITE, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
 | 
			
		||||
            if (status != NTStatus.STATUS_SUCCESS)
 | 
			
		||||
            {
 | 
			
		||||
                throw new Exception($"Failed to open {uploadPath.LocalPath} for writing!");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            long writeOffset = 0;
 | 
			
		||||
            while (data.Position < data.Length)
 | 
			
		||||
            {
 | 
			
		||||
                byte[] buffer = new byte[(int)connection.Client.MaxWriteSize];
 | 
			
		||||
                int bytesRead = data.Read(buffer, 0, buffer.Length);
 | 
			
		||||
                if (bytesRead < (int)connection.Client.MaxWriteSize)
 | 
			
		||||
                {
 | 
			
		||||
                    Array.Resize(ref buffer, bytesRead);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                status = connection.FileStore.WriteFile(out _, fileHandle, writeOffset, buffer);
 | 
			
		||||
                if (status != NTStatus.STATUS_SUCCESS)
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("Failed to write to file");
 | 
			
		||||
                }
 | 
			
		||||
                writeOffset += bytesRead;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
 | 
			
		||||
        {
 | 
			
		||||
            return new SmbFileStorageWriteTransaction(ioc.Path, this, useFileTransaction);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetFilenameWithoutPathAndExt(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return UrlUtil.StripExtension(
 | 
			
		||||
                UrlUtil.GetFileName(ioc.Path));
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetFileExtension(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return UrlUtil.GetExtension(ioc.Path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool RequiresCredentials(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
 | 
			
		||||
        {
 | 
			
		||||
            throw new NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static IEnumerable<FileDescription> ListShares(SmbConnection conn, SmbConnectionInfo parent)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (string share in conn.Client.ListShares(out _))
 | 
			
		||||
            {
 | 
			
		||||
                yield return new FileDescription()
 | 
			
		||||
                {
 | 
			
		||||
                    CanRead = true,
 | 
			
		||||
                    CanWrite = true,
 | 
			
		||||
                    DisplayName = share,
 | 
			
		||||
                    IsDirectory = true,
 | 
			
		||||
                    Path = parent.GetChild(share).ToPath()
 | 
			
		||||
                };
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            List<FileDescription> result = [];
 | 
			
		||||
            SmbConnectionInfo info = new SmbConnectionInfo(ioc);
 | 
			
		||||
            using SmbConnection conn = new SmbConnection(info);
 | 
			
		||||
            if (string.IsNullOrEmpty(info.Share))
 | 
			
		||||
            {
 | 
			
		||||
                var shares = ListShares(conn, info).ToList();
 | 
			
		||||
                return shares;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            NTStatus status = conn.FileStore!.CreateFile(out var directoryHandle, out _, info.GetLocalSmbPath(), AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
 | 
			
		||||
            if (status == NTStatus.STATUS_SUCCESS)
 | 
			
		||||
            {
 | 
			
		||||
                conn.FileStore.QueryDirectory(out List<QueryDirectoryFileInformation> fileList, directoryHandle, "*", FileInformationClass.FileDirectoryInformation);
 | 
			
		||||
                foreach (var fi in fileList)
 | 
			
		||||
                {
 | 
			
		||||
                    var fileDirectoryInformation = fi as FileDirectoryInformation;
 | 
			
		||||
                    if (fileDirectoryInformation == null)
 | 
			
		||||
                        continue;
 | 
			
		||||
 | 
			
		||||
                    if (fileDirectoryInformation.FileName is "." or "..")
 | 
			
		||||
                        continue;
 | 
			
		||||
 | 
			
		||||
                    var fileDescription = FileDescriptionConvert(ioc, fileDirectoryInformation);
 | 
			
		||||
 | 
			
		||||
                    result.Add(fileDescription);
 | 
			
		||||
                }
 | 
			
		||||
                conn.FileStore.CloseFile(directoryHandle);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private FileDescription FileDescriptionConvert(IOConnectionInfo parentIoc,
 | 
			
		||||
            FileDirectoryInformation fileDirectoryInformation)
 | 
			
		||||
        {
 | 
			
		||||
            FileDescription fileDescription = new FileDescription
 | 
			
		||||
            {
 | 
			
		||||
                CanRead = true,
 | 
			
		||||
                CanWrite = true,
 | 
			
		||||
                IsDirectory = (fileDirectoryInformation.FileAttributes & FileAttributes.Directory) != 0,
 | 
			
		||||
                DisplayName = fileDirectoryInformation.FileName
 | 
			
		||||
            };
 | 
			
		||||
            fileDescription.Path = CreateFilePath(parentIoc.Path, fileDescription.DisplayName);
 | 
			
		||||
            fileDescription.LastModified = fileDirectoryInformation.LastWriteTime;
 | 
			
		||||
                        
 | 
			
		||||
            fileDescription.SizeInBytes = fileDirectoryInformation.EndOfFile;
 | 
			
		||||
            return fileDescription;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public FileDescription GetFileDescription(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            SmbConnectionInfo info = new SmbConnectionInfo(ioc);
 | 
			
		||||
 | 
			
		||||
            if (string.IsNullOrEmpty(info.Share))
 | 
			
		||||
            {
 | 
			
		||||
                return new FileDescription
 | 
			
		||||
                {
 | 
			
		||||
                    CanRead = true, CanWrite = true,
 | 
			
		||||
                    DisplayName = info.Host,
 | 
			
		||||
                    IsDirectory = true,
 | 
			
		||||
                    Path = info.ToPath()
 | 
			
		||||
                };
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            using SmbConnection conn = new SmbConnection(info);
 | 
			
		||||
            NTStatus status = conn.FileStore!.CreateFile(out var directoryHandle, out _, info.GetParent().GetLocalSmbPath(), AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
 | 
			
		||||
            if (status != NTStatus.STATUS_SUCCESS) throw new Exception($"Failed to query details for {info.LocalPath}");
 | 
			
		||||
            conn.FileStore.QueryDirectory(out List<QueryDirectoryFileInformation> fileList, directoryHandle, info.Stem(), FileInformationClass.FileDirectoryInformation);
 | 
			
		||||
            foreach (var fi in fileList)
 | 
			
		||||
            {
 | 
			
		||||
                var fileDirectoryInformation = fi as FileDirectoryInformation;
 | 
			
		||||
                if (fileDirectoryInformation == null)
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                if (fileDirectoryInformation.FileName is "." or "..")
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                return FileDescriptionConvert(ioc, fileDirectoryInformation);
 | 
			
		||||
 | 
			
		||||
                        
 | 
			
		||||
            }
 | 
			
		||||
            conn.FileStore.CloseFile(directoryHandle);
 | 
			
		||||
 | 
			
		||||
            throw new Exception($"Failed to query details for {info.LocalPath}");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool RequiresSetup(IOConnectionInfo ioConnection)
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string IocToPath(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return ioc.Path;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void StartSelectFile(IFileStorageSetupInitiatorActivity activity, bool isForSave, int requestCode, string protocolId)
 | 
			
		||||
        {
 | 
			
		||||
            activity.PerformManualFileSelect(isForSave, requestCode, protocolId);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void PrepareFileUsage(IFileStorageSetupInitiatorActivity activity, IOConnectionInfo ioc, int requestCode,
 | 
			
		||||
            bool alwaysReturnSuccess)
 | 
			
		||||
        {
 | 
			
		||||
            Intent intent = new Intent();
 | 
			
		||||
            activity.IocToIntent(intent, ioc);
 | 
			
		||||
            activity.OnImmediateResult(requestCode, (int)FileStorageResults.FileUsagePrepared, intent);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void PrepareFileUsage(Context ctx, IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnCreate(IFileStorageSetupActivity activity, Bundle savedInstanceState)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnResume(IFileStorageSetupActivity activity)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnStart(IFileStorageSetupActivity activity)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnActivityResult(IFileStorageSetupActivity activity, int requestCode, int resultCode, Intent data)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetDisplayName(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return new SmbConnectionInfo(ioc).ToDisplayString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string CreateFilePath(string parent, string newFilename)
 | 
			
		||||
        {
 | 
			
		||||
            return new SmbConnectionInfo(new IOConnectionInfo() { Path = parent}).GetChild(newFilename).ToPath();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IOConnectionInfo GetParentPath(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            SmbConnectionInfo connectionInfo = new SmbConnectionInfo(ioc);
 | 
			
		||||
            return new IOConnectionInfo() { Path = connectionInfo.GetParent().ToPath() };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IOConnectionInfo GetFilePath(IOConnectionInfo folderPath, string filename)
 | 
			
		||||
        {
 | 
			
		||||
            return new IOConnectionInfo() { Path = CreateFilePath(folderPath.Path, filename)};
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool IsPermanentLocation(IOConnectionInfo ioc)
 | 
			
		||||
        {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool IsReadOnly(IOConnectionInfo ioc, OptionalOut<UiStringKey> reason = null)
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
@@ -6,10 +6,12 @@ using System.Text;
 | 
			
		||||
using Android.App;
 | 
			
		||||
using Android.Content;
 | 
			
		||||
using Android.OS;
 | 
			
		||||
using Android.Preferences;
 | 
			
		||||
using Android.Runtime;
 | 
			
		||||
using Android.Views;
 | 
			
		||||
using Android.Widget;
 | 
			
		||||
#if !NoNet && !EXCLUDE_JAVAFILESTORAGE
 | 
			
		||||
 | 
			
		||||
using Keepass2android.Javafilestorage;
 | 
			
		||||
#endif
 | 
			
		||||
using KeePassLib.Serialization;
 | 
			
		||||
@@ -19,8 +21,14 @@ namespace keepass2android.Io
 | 
			
		||||
#if !NoNet && !EXCLUDE_JAVAFILESTORAGE
 | 
			
		||||
	public class WebDavFileStorage: JavaFileStorage
 | 
			
		||||
	{
 | 
			
		||||
		public WebDavFileStorage(IKp2aApp app) : base(new Keepass2android.Javafilestorage.WebDavStorage(app.CertificateErrorHandler), app)
 | 
			
		||||
        private readonly IKp2aApp _app;
 | 
			
		||||
        private readonly WebDavStorage baseWebdavStorage;
 | 
			
		||||
 | 
			
		||||
        public WebDavFileStorage(IKp2aApp app, int chunkSize) : base(new Keepass2android.Javafilestorage.WebDavStorage(app.CertificateErrorHandler, chunkSize), app)
 | 
			
		||||
        {
 | 
			
		||||
            _app = app;
 | 
			
		||||
            baseWebdavStorage = (WebDavStorage)Jfs;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public override IEnumerable<string> SupportedProtocols
 | 
			
		||||
@@ -75,6 +83,15 @@ namespace keepass2android.Io
 | 
			
		||||
			}
 | 
			
		||||
			return base.IocToPath(ioc);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public override IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
 | 
			
		||||
        {
 | 
			
		||||
            baseWebdavStorage.SetUploadChunkSize(_app.WebDavChunkedUploadSize);
 | 
			
		||||
            return base.OpenWriteTransaction(ioc, useFileTransaction);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
@@ -10,10 +10,12 @@
 | 
			
		||||
    <Folder Include="Resources\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="FluentFTP" Version="51.1.0" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="FluentFTP" Version="52.1.0" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="FluentFTP.GnuTLS" Version="1.0.37" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="MegaApiClient" Version="1.10.4"  Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="Microsoft.Graph" Version="5.68.0" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="Microsoft.Identity.Client" Version="4.67.1" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="SMBLibrary" Version="1.5.4" Condition="'$(Flavor)'!='NoNet'"/>
 | 
			
		||||
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.8.0" />
 | 
			
		||||
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.5" />
 | 
			
		||||
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.11.0.3" />
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0-android</TargetFramework>
 | 
			
		||||
    <TargetFramework>net9.0-android</TargetFramework>
 | 
			
		||||
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
 
 | 
			
		||||
@@ -51,4 +51,6 @@ dependencies {
 | 
			
		||||
    implementation 'com.pcloud.sdk:android:1.9.1'
 | 
			
		||||
    implementation 'com.google.code.gson:gson:2.8.6'
 | 
			
		||||
 | 
			
		||||
    implementation 'com.github.mwiede:jsch:2.27.2'
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2011 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface AgentConnector {
 | 
			
		||||
  String getName();
 | 
			
		||||
  boolean isAvailable();
 | 
			
		||||
  void query(Buffer buffer) throws AgentProxyException;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,80 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2011 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class AgentIdentity implements Identity {
 | 
			
		||||
 | 
			
		||||
  private AgentProxy agent;
 | 
			
		||||
  private byte[] blob;
 | 
			
		||||
  private String comment;
 | 
			
		||||
  private String algname;
 | 
			
		||||
  AgentIdentity(AgentProxy agent, byte[] blob, String comment) {
 | 
			
		||||
    this.agent = agent;
 | 
			
		||||
    this.blob = blob;
 | 
			
		||||
    this.comment = comment;
 | 
			
		||||
    algname = Util.byte2str((new Buffer(blob)).getString());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean setPassphrase(byte[] passphrase) throws JSchException{
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getPublicKeyBlob() { return blob; }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getSignature(byte[] data){
 | 
			
		||||
    return agent.sign(blob, data, null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getSignature(byte[] data, String alg){
 | 
			
		||||
    return agent.sign(blob, data, alg);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  @Deprecated
 | 
			
		||||
  public boolean decrypt() {
 | 
			
		||||
    throw new RuntimeException("not implemented");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getAlgName() { return algname; }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getName() { return comment; }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isEncrypted() { return false; }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void clear() { }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,75 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2011 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public class AgentIdentityRepository implements IdentityRepository {
 | 
			
		||||
 | 
			
		||||
  private AgentProxy agent;
 | 
			
		||||
  public AgentIdentityRepository(AgentConnector connector) {
 | 
			
		||||
    this.agent = new AgentProxy(connector);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public Vector<Identity> getIdentities() {
 | 
			
		||||
    return agent.getIdentities();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean add(byte[] identity) {
 | 
			
		||||
    return agent.addIdentity(identity);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean remove(byte[] blob) {
 | 
			
		||||
    return agent.removeIdentity(blob);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void removeAll() {
 | 
			
		||||
    agent.removeAllIdentities();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getName() {
 | 
			
		||||
    return agent.getConnector().getName();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getStatus() {
 | 
			
		||||
    if(agent.getConnector().isAvailable()){
 | 
			
		||||
      return RUNNING;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      return NOTRUNNING;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,256 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2012 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
class AgentProxy {
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
 | 
			
		||||
  private static final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
 | 
			
		||||
  private static final byte SSH_AGENTC_RSA_CHALLENGE = 3;
 | 
			
		||||
  private static final byte SSH_AGENT_RSA_RESPONSE = 4;
 | 
			
		||||
  private static final byte SSH_AGENT_FAILURE = 5;
 | 
			
		||||
  private static final byte SSH_AGENT_SUCCESS = 6;
 | 
			
		||||
  private static final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
 | 
			
		||||
  private static final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
 | 
			
		||||
  private static final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH2_AGENTC_REQUEST_IDENTITIES = 11;
 | 
			
		||||
  private static final byte SSH2_AGENT_IDENTITIES_ANSWER = 12;
 | 
			
		||||
  private static final byte SSH2_AGENTC_SIGN_REQUEST = 13;
 | 
			
		||||
  private static final byte SSH2_AGENT_SIGN_RESPONSE = 14;
 | 
			
		||||
  private static final byte SSH2_AGENTC_ADD_IDENTITY = 17;
 | 
			
		||||
  private static final byte SSH2_AGENTC_REMOVE_IDENTITY = 18;
 | 
			
		||||
  private static final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES = 19;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_AGENTC_ADD_SMARTCARD_KEY = 20;
 | 
			
		||||
  private static final byte SSH_AGENTC_REMOVE_SMARTCARD_KEY = 21;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_AGENTC_LOCK = 22;
 | 
			
		||||
  private static final byte SSH_AGENTC_UNLOCK = 23;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_AGENTC_ADD_RSA_ID_CONSTRAINED = 24;
 | 
			
		||||
  private static final byte SSH2_AGENTC_ADD_ID_CONSTRAINED = 25;
 | 
			
		||||
  private static final byte SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED = 26;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_AGENT_CONSTRAIN_LIFETIME = 1;
 | 
			
		||||
  private static final byte SSH_AGENT_CONSTRAIN_CONFIRM = 2;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH2_AGENT_FAILURE = 30;
 | 
			
		||||
 | 
			
		||||
  private static final byte SSH_COM_AGENT2_FAILURE = 102;
 | 
			
		||||
 | 
			
		||||
  //private static final byte SSH_AGENT_OLD_SIGNATURE = 0x1;
 | 
			
		||||
  private static final int SSH_AGENT_RSA_SHA2_256 = 0x2;
 | 
			
		||||
  private static final int SSH_AGENT_RSA_SHA2_512 = 0x4;
 | 
			
		||||
 | 
			
		||||
  private static final int MAX_AGENT_IDENTITIES = 2048;
 | 
			
		||||
 | 
			
		||||
  private final byte[] buf = new byte[1024];
 | 
			
		||||
  private final Buffer buffer = new Buffer(buf);
 | 
			
		||||
 | 
			
		||||
  private AgentConnector connector;
 | 
			
		||||
 | 
			
		||||
  AgentProxy(AgentConnector connector){
 | 
			
		||||
    this.connector = connector;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized Vector<Identity> getIdentities() {
 | 
			
		||||
    Vector<Identity> identities = new Vector<>();
 | 
			
		||||
 | 
			
		||||
    int required_size = 1 + 4;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_REQUEST_IDENTITIES);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      buffer.rewind();
 | 
			
		||||
      buffer.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
      return identities;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH2_AGENT_IDENTITIES_ANSWER);
 | 
			
		||||
 | 
			
		||||
    if(rcode != SSH2_AGENT_IDENTITIES_ANSWER) {
 | 
			
		||||
      return identities;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int count = buffer.getInt();
 | 
			
		||||
    //System.out.println(count);
 | 
			
		||||
    if(count <= 0 || count > MAX_AGENT_IDENTITIES) {
 | 
			
		||||
      return identities;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for(int i=0; i<count; i++){
 | 
			
		||||
      byte[] blob = buffer.getString();
 | 
			
		||||
      String comment = Util.byte2str(buffer.getString());
 | 
			
		||||
      identities.add(new AgentIdentity(this, blob, comment));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return identities;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized byte[] sign(byte[] blob, byte[] data, String alg) {
 | 
			
		||||
    int flags = 0x0;
 | 
			
		||||
    if(alg != null) {
 | 
			
		||||
      if(alg.equals("rsa-sha2-256")) {
 | 
			
		||||
        flags = SSH_AGENT_RSA_SHA2_256;
 | 
			
		||||
      }
 | 
			
		||||
      else if(alg.equals("rsa-sha2-512")) {
 | 
			
		||||
        flags = SSH_AGENT_RSA_SHA2_512;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int required_size = 1 + 4*4 + blob.length + data.length;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_SIGN_REQUEST);
 | 
			
		||||
    buffer.putString(blob);
 | 
			
		||||
    buffer.putString(data);
 | 
			
		||||
    buffer.putInt(flags);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      buffer.rewind();
 | 
			
		||||
      buffer.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH2_AGENT_SIGN_RESPONSE);
 | 
			
		||||
 | 
			
		||||
    if(rcode != SSH2_AGENT_SIGN_RESPONSE) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return buffer.getString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized boolean removeIdentity(byte[] blob) {
 | 
			
		||||
    int required_size = 1 + 4*2 + blob.length;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_REMOVE_IDENTITY);
 | 
			
		||||
    buffer.putString(blob);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      buffer.rewind();
 | 
			
		||||
      buffer.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH_AGENT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    return rcode == SSH_AGENT_SUCCESS;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized void removeAllIdentities() {
 | 
			
		||||
    int required_size = 1 + 4;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_REMOVE_ALL_IDENTITIES);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      buffer.rewind();
 | 
			
		||||
      buffer.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH_AGENT_SUCCESS);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized boolean addIdentity(byte[] identity) {
 | 
			
		||||
    int required_size = 1 + 4 + identity.length;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_ADD_IDENTITY);
 | 
			
		||||
    buffer.putByte(identity);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      buffer.rewind();
 | 
			
		||||
      buffer.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH_AGENT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    return rcode == SSH_AGENT_SUCCESS;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized boolean isRunning(){
 | 
			
		||||
    int required_size = 1 + 4;
 | 
			
		||||
    buffer.reset();
 | 
			
		||||
    buffer.checkFreeSize(required_size);
 | 
			
		||||
    buffer.putInt(required_size - 4);
 | 
			
		||||
    buffer.putByte(SSH2_AGENTC_REQUEST_IDENTITIES);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      connector.query(buffer);
 | 
			
		||||
    }
 | 
			
		||||
    catch(AgentProxyException e){
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int rcode = buffer.getByte();
 | 
			
		||||
 | 
			
		||||
    //System.out.println(rcode == SSH2_AGENT_IDENTITIES_ANSWER);
 | 
			
		||||
 | 
			
		||||
    return rcode == SSH2_AGENT_IDENTITIES_ANSWER;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  synchronized AgentConnector getConnector() {
 | 
			
		||||
    return connector;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,40 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2011 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public class AgentProxyException extends Exception {
 | 
			
		||||
  private static final long serialVersionUID=-1L;
 | 
			
		||||
  public AgentProxyException(String message){
 | 
			
		||||
    super(message);
 | 
			
		||||
  }
 | 
			
		||||
  public AgentProxyException(String message, Throwable e){
 | 
			
		||||
    super(message, e);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,297 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public class Buffer{
 | 
			
		||||
  final byte[] tmp=new byte[4];
 | 
			
		||||
  byte[] buffer;
 | 
			
		||||
  int index;
 | 
			
		||||
  int s;
 | 
			
		||||
  public Buffer(int size){
 | 
			
		||||
    buffer=new byte[size];
 | 
			
		||||
    index=0;
 | 
			
		||||
    s=0;
 | 
			
		||||
  }
 | 
			
		||||
  public Buffer(byte[] buffer){
 | 
			
		||||
    this.buffer=buffer;
 | 
			
		||||
    index=0;
 | 
			
		||||
    s=0;
 | 
			
		||||
  }
 | 
			
		||||
  public Buffer(){ this(1024*10*2); }
 | 
			
		||||
  public void putByte(byte foo){
 | 
			
		||||
    buffer[index++]=foo;
 | 
			
		||||
  }
 | 
			
		||||
  public void putByte(byte[] foo) {
 | 
			
		||||
    putByte(foo, 0, foo.length);
 | 
			
		||||
  }
 | 
			
		||||
  public void putByte(byte[] foo, int begin, int length) {
 | 
			
		||||
    System.arraycopy(foo, begin, buffer, index, length);
 | 
			
		||||
    index+=length;
 | 
			
		||||
  }
 | 
			
		||||
  public void putString(byte[] foo){
 | 
			
		||||
    putString(foo, 0, foo.length);
 | 
			
		||||
  }
 | 
			
		||||
  public void putString(byte[] foo, int begin, int length) {
 | 
			
		||||
    putInt(length);
 | 
			
		||||
    putByte(foo, begin, length);
 | 
			
		||||
  }
 | 
			
		||||
  public void putInt(int val) {
 | 
			
		||||
    tmp[0]=(byte)(val >>> 24);
 | 
			
		||||
    tmp[1]=(byte)(val >>> 16);
 | 
			
		||||
    tmp[2]=(byte)(val >>> 8);
 | 
			
		||||
    tmp[3]=(byte)(val);
 | 
			
		||||
    System.arraycopy(tmp, 0, buffer, index, 4);
 | 
			
		||||
    index+=4;
 | 
			
		||||
  }
 | 
			
		||||
  public void putLong(long val) {
 | 
			
		||||
    tmp[0]=(byte)(val >>> 56);
 | 
			
		||||
    tmp[1]=(byte)(val >>> 48);
 | 
			
		||||
    tmp[2]=(byte)(val >>> 40);
 | 
			
		||||
    tmp[3]=(byte)(val >>> 32);
 | 
			
		||||
    System.arraycopy(tmp, 0, buffer, index, 4);
 | 
			
		||||
    tmp[0]=(byte)(val >>> 24);
 | 
			
		||||
    tmp[1]=(byte)(val >>> 16);
 | 
			
		||||
    tmp[2]=(byte)(val >>> 8);
 | 
			
		||||
    tmp[3]=(byte)(val);
 | 
			
		||||
    System.arraycopy(tmp, 0, buffer, index+4, 4);
 | 
			
		||||
    index+=8;
 | 
			
		||||
  }
 | 
			
		||||
  void skip(int n) {
 | 
			
		||||
    index+=n;
 | 
			
		||||
  }
 | 
			
		||||
  void putPad(int n) {
 | 
			
		||||
    while(n>0){
 | 
			
		||||
      buffer[index++]=(byte)0;
 | 
			
		||||
      n--;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  public void putMPInt(byte[] foo){
 | 
			
		||||
    int i=foo.length;
 | 
			
		||||
    if((foo[0]&0x80)!=0){
 | 
			
		||||
      i++;
 | 
			
		||||
      putInt(i);
 | 
			
		||||
      putByte((byte)0);
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      putInt(i);
 | 
			
		||||
    }
 | 
			
		||||
    putByte(foo);
 | 
			
		||||
  }
 | 
			
		||||
  public int getLength(){
 | 
			
		||||
    return index-s;
 | 
			
		||||
  }
 | 
			
		||||
  public int getOffSet(){
 | 
			
		||||
    return s;
 | 
			
		||||
  }
 | 
			
		||||
  public void setOffSet(int s){
 | 
			
		||||
    this.s=s;
 | 
			
		||||
  }
 | 
			
		||||
  public long getLong(){
 | 
			
		||||
    long foo = getInt()&0xffffffffL;
 | 
			
		||||
    foo = ((foo<<32)) | (getInt()&0xffffffffL);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public int getInt(){
 | 
			
		||||
    int foo = getShort();
 | 
			
		||||
    foo = ((foo<<16)&0xffff0000) | (getShort()&0xffff);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public long getUInt(){
 | 
			
		||||
    long foo = 0L;
 | 
			
		||||
    long bar = 0L;
 | 
			
		||||
    foo = getByte();
 | 
			
		||||
    foo = ((foo<<8)&0xff00)|(getByte()&0xff);
 | 
			
		||||
    bar = getByte();
 | 
			
		||||
    bar = ((bar<<8)&0xff00)|(getByte()&0xff);
 | 
			
		||||
    foo = ((foo<<16)&0xffff0000) | (bar&0xffff);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  int getShort() {
 | 
			
		||||
    int foo = getByte();
 | 
			
		||||
    foo = ((foo<<8)&0xff00)|(getByte()&0xff);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public int getByte() {
 | 
			
		||||
    return (buffer[s++]&0xff);
 | 
			
		||||
  }
 | 
			
		||||
  public void getByte(byte[] foo) {
 | 
			
		||||
    getByte(foo, 0, foo.length);
 | 
			
		||||
  }
 | 
			
		||||
  void getByte(byte[] foo, int start, int len) {
 | 
			
		||||
    System.arraycopy(buffer, s, foo, start, len); 
 | 
			
		||||
    s+=len;
 | 
			
		||||
  }
 | 
			
		||||
  public int getByte(int len) {
 | 
			
		||||
    int foo=s;
 | 
			
		||||
    s+=len;
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public byte[] getMPInt() {
 | 
			
		||||
    int i=getInt();  // uint32
 | 
			
		||||
    if(i<0 ||  // bigger than 0x7fffffff
 | 
			
		||||
       i>8*1024){
 | 
			
		||||
      // TODO: an exception should be thrown.
 | 
			
		||||
      i = 8*1024; // the session will be broken, but working around OOME.
 | 
			
		||||
    }
 | 
			
		||||
    byte[] foo=new byte[i];
 | 
			
		||||
    getByte(foo, 0, i);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public byte[] getMPIntBits() {
 | 
			
		||||
    int bits=getInt();
 | 
			
		||||
    int bytes=(bits+7)/8;
 | 
			
		||||
    byte[] foo=new byte[bytes];
 | 
			
		||||
    getByte(foo, 0, bytes);
 | 
			
		||||
    if((foo[0]&0x80)!=0){
 | 
			
		||||
      byte[] bar=new byte[foo.length+1];
 | 
			
		||||
      bar[0]=0; // ??
 | 
			
		||||
      System.arraycopy(foo, 0, bar, 1, foo.length);
 | 
			
		||||
      foo=bar;
 | 
			
		||||
    }
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  public byte[] getString() {
 | 
			
		||||
    int i = getInt();  // uint32
 | 
			
		||||
    if(i<0 ||  // bigger than 0x7fffffff
 | 
			
		||||
       i>256*1024){
 | 
			
		||||
      // TODO: an exception should be thrown.
 | 
			
		||||
      i = 256*1024; // the session will be broken, but working around OOME.
 | 
			
		||||
    }
 | 
			
		||||
    byte[] foo=new byte[i];
 | 
			
		||||
    getByte(foo, 0, i);
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
  byte[] getString(int[]start, int[]len) {
 | 
			
		||||
    int i=getInt();
 | 
			
		||||
    start[0]=getByte(i);
 | 
			
		||||
    len[0]=i;
 | 
			
		||||
    return buffer;
 | 
			
		||||
  }
 | 
			
		||||
  public void reset(){
 | 
			
		||||
    index=0;
 | 
			
		||||
    s=0;
 | 
			
		||||
  }
 | 
			
		||||
  public void shift(){
 | 
			
		||||
    if(s==0)return;
 | 
			
		||||
    System.arraycopy(buffer, s, buffer, 0, index-s);
 | 
			
		||||
    index=index-s;
 | 
			
		||||
    s=0;
 | 
			
		||||
  }
 | 
			
		||||
  void rewind(){
 | 
			
		||||
    s=0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  byte getCommand(){
 | 
			
		||||
    return buffer[5];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void checkFreeSize(int n){
 | 
			
		||||
    int size = index+n+Session.buffer_margin;
 | 
			
		||||
    if(buffer.length<size){
 | 
			
		||||
      int i = buffer.length*2;
 | 
			
		||||
      if(i<size) i = size;
 | 
			
		||||
      byte[] tmp = new byte[i];
 | 
			
		||||
      System.arraycopy(buffer, 0, tmp, 0, index);
 | 
			
		||||
      buffer = tmp;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  byte[][] getBytes(int n, String msg) throws JSchException {
 | 
			
		||||
    byte[][] tmp = new byte[n][];
 | 
			
		||||
    for(int i = 0; i < n; i++){
 | 
			
		||||
      int j = getInt();
 | 
			
		||||
      if(getLength() < j){
 | 
			
		||||
        throw new JSchException(msg);
 | 
			
		||||
      }
 | 
			
		||||
      tmp[i] = new byte[j];
 | 
			
		||||
      getByte(tmp[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return tmp;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
  static Buffer fromBytes(byte[]... args){
 | 
			
		||||
    int length = args.length*4;
 | 
			
		||||
    for(int i = 0; i < args.length; i++){
 | 
			
		||||
      length += args[i].length;
 | 
			
		||||
    }
 | 
			
		||||
    Buffer buf = new Buffer(length);
 | 
			
		||||
    for(int i = 0; i < args.length; i++){
 | 
			
		||||
      buf.putString(args[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return buf;
 | 
			
		||||
  }
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
  static Buffer fromBytes(byte[][] args){
 | 
			
		||||
    int length = args.length*4;
 | 
			
		||||
    for(int i = 0; i < args.length; i++){
 | 
			
		||||
      length += args[i].length;
 | 
			
		||||
    }
 | 
			
		||||
    Buffer buf = new Buffer(length);
 | 
			
		||||
    for(int i = 0; i < args.length; i++){
 | 
			
		||||
      buf.putString(args[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return buf;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  static String[] chars={
 | 
			
		||||
    "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f"
 | 
			
		||||
  };
 | 
			
		||||
  static void dump_buffer(){
 | 
			
		||||
    int foo;
 | 
			
		||||
    for(int i=0; i<tmp_buffer_index; i++){
 | 
			
		||||
        foo=tmp_buffer[i]&0xff;
 | 
			
		||||
        System.err.print(chars[(foo>>>4)&0xf]);
 | 
			
		||||
        System.err.print(chars[foo&0xf]);
 | 
			
		||||
        if(i%16==15){
 | 
			
		||||
          System.err.println("");
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
        if(i>0 && i%2==1){
 | 
			
		||||
          System.err.print(" ");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    System.err.println("");
 | 
			
		||||
  }
 | 
			
		||||
  static void dump(byte[] b){
 | 
			
		||||
    dump(b, 0, b.length);
 | 
			
		||||
  }
 | 
			
		||||
  static void dump(byte[] b, int s, int l){
 | 
			
		||||
    for(int i=s; i<s+l; i++){
 | 
			
		||||
      System.err.print(Integer.toHexString(b[i]&0xff)+":");
 | 
			
		||||
    }
 | 
			
		||||
    System.err.println("");
 | 
			
		||||
  }
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,782 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public abstract class Channel{
 | 
			
		||||
 | 
			
		||||
  static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION=      91;
 | 
			
		||||
  static final int SSH_MSG_CHANNEL_OPEN_FAILURE=           92;
 | 
			
		||||
  static final int SSH_MSG_CHANNEL_WINDOW_ADJUST=          93;
 | 
			
		||||
 | 
			
		||||
  static final int SSH_OPEN_ADMINISTRATIVELY_PROHIBITED=    1;
 | 
			
		||||
  static final int SSH_OPEN_CONNECT_FAILED=                 2;
 | 
			
		||||
  static final int SSH_OPEN_UNKNOWN_CHANNEL_TYPE=           3;
 | 
			
		||||
  static final int SSH_OPEN_RESOURCE_SHORTAGE=              4;
 | 
			
		||||
 | 
			
		||||
  static int index=0; 
 | 
			
		||||
  private static Vector<Channel> pool=new Vector<>();
 | 
			
		||||
  static Channel getChannel(String type, Session session){
 | 
			
		||||
    Channel ret = null;
 | 
			
		||||
    if(type.equals("session")){
 | 
			
		||||
      ret = new ChannelSession();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("shell")){
 | 
			
		||||
      ret = new ChannelShell();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("exec")){
 | 
			
		||||
      ret = new ChannelExec();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("x11")){
 | 
			
		||||
      ret = new ChannelX11();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("auth-agent@openssh.com")){
 | 
			
		||||
      ret = new ChannelAgentForwarding();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("direct-tcpip")){
 | 
			
		||||
      ret = new ChannelDirectTCPIP();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("forwarded-tcpip")){
 | 
			
		||||
      ret = new ChannelForwardedTCPIP();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("sftp")){
 | 
			
		||||
      ret = new ChannelSftp();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("subsystem")){
 | 
			
		||||
      ret = new ChannelSubsystem();
 | 
			
		||||
    }
 | 
			
		||||
    if(type.equals("direct-streamlocal@openssh.com")){
 | 
			
		||||
      ret = new ChannelDirectStreamLocal();
 | 
			
		||||
    }
 | 
			
		||||
    if (ret == null) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
    ret.setSession(session);
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  static Channel getChannel(int id, Session session){
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      for(int i=0; i<pool.size(); i++){
 | 
			
		||||
        Channel c=pool.elementAt(i);
 | 
			
		||||
        if(c.id==id && c.session==session) return c;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
  static void del(Channel c){
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      pool.removeElement(c);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int id;
 | 
			
		||||
  volatile int recipient=-1;
 | 
			
		||||
  protected byte[] type=Util.str2byte("foo");
 | 
			
		||||
  volatile int lwsize_max=0x100000;
 | 
			
		||||
  volatile int lwsize=lwsize_max;     // local initial window size
 | 
			
		||||
  volatile int lmpsize=0x4000;     // local maximum packet size
 | 
			
		||||
 | 
			
		||||
  volatile long rwsize=0;         // remote initial window size
 | 
			
		||||
  volatile int rmpsize=0;        // remote maximum packet size
 | 
			
		||||
 | 
			
		||||
  IO io=null;    
 | 
			
		||||
  Thread thread=null;
 | 
			
		||||
 | 
			
		||||
  volatile boolean eof_local=false;
 | 
			
		||||
  volatile boolean eof_remote=false;
 | 
			
		||||
 | 
			
		||||
  volatile boolean close=false;
 | 
			
		||||
  volatile boolean connected=false;
 | 
			
		||||
  volatile boolean open_confirmation=false;
 | 
			
		||||
 | 
			
		||||
  volatile int exitstatus=-1;
 | 
			
		||||
 | 
			
		||||
  volatile int reply=0; 
 | 
			
		||||
  volatile int connectTimeout=0;
 | 
			
		||||
 | 
			
		||||
  protected Session session;
 | 
			
		||||
 | 
			
		||||
  int notifyme=0; 
 | 
			
		||||
 | 
			
		||||
  Channel(){
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      id=index++;
 | 
			
		||||
      pool.addElement(this);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  synchronized void setRecipient(int foo){
 | 
			
		||||
    this.recipient=foo;
 | 
			
		||||
    if(notifyme>0)
 | 
			
		||||
      notifyAll();
 | 
			
		||||
  }
 | 
			
		||||
  int getRecipient(){
 | 
			
		||||
    return recipient;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void init() throws JSchException {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void connect() throws JSchException{
 | 
			
		||||
    connect(0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void connect(int connectTimeout) throws JSchException{
 | 
			
		||||
    this.connectTimeout=connectTimeout;
 | 
			
		||||
    try{
 | 
			
		||||
      sendChannelOpen();
 | 
			
		||||
      start();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      connected=false;
 | 
			
		||||
      disconnect();
 | 
			
		||||
      if(e instanceof JSchException) 
 | 
			
		||||
        throw (JSchException)e;
 | 
			
		||||
      throw new JSchException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setXForwarding(boolean foo){
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void start() throws JSchException{}
 | 
			
		||||
 | 
			
		||||
  public boolean isEOF() {return eof_remote;}
 | 
			
		||||
 | 
			
		||||
  void getData(Buffer buf){
 | 
			
		||||
    setRecipient(buf.getInt());
 | 
			
		||||
    setRemoteWindowSize(buf.getUInt());
 | 
			
		||||
    setRemotePacketSize(buf.getInt());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setInputStream(InputStream in){
 | 
			
		||||
    io.setInputStream(in, false);
 | 
			
		||||
  }
 | 
			
		||||
  public void setInputStream(InputStream in, boolean dontclose){
 | 
			
		||||
    io.setInputStream(in, dontclose);
 | 
			
		||||
  }
 | 
			
		||||
  public void setOutputStream(OutputStream out){
 | 
			
		||||
    io.setOutputStream(out, false);
 | 
			
		||||
  }
 | 
			
		||||
  public void setOutputStream(OutputStream out, boolean dontclose){
 | 
			
		||||
    io.setOutputStream(out, dontclose);
 | 
			
		||||
  }
 | 
			
		||||
  public void setExtOutputStream(OutputStream out){
 | 
			
		||||
    io.setExtOutputStream(out, false);
 | 
			
		||||
  }
 | 
			
		||||
  public void setExtOutputStream(OutputStream out, boolean dontclose){
 | 
			
		||||
    io.setExtOutputStream(out, dontclose);
 | 
			
		||||
  }
 | 
			
		||||
  public InputStream getInputStream() throws IOException {
 | 
			
		||||
    int max_input_buffer_size = 32*1024;
 | 
			
		||||
    try {
 | 
			
		||||
      max_input_buffer_size =
 | 
			
		||||
        Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){}
 | 
			
		||||
    PipedInputStream in =
 | 
			
		||||
      new MyPipedInputStream(
 | 
			
		||||
                             32*1024,  // this value should be customizable.
 | 
			
		||||
                             max_input_buffer_size
 | 
			
		||||
                             );
 | 
			
		||||
    boolean resizable = 32*1024<max_input_buffer_size;
 | 
			
		||||
    io.setOutputStream(new PassiveOutputStream(in, resizable), false);
 | 
			
		||||
    return in;
 | 
			
		||||
  }
 | 
			
		||||
  public InputStream getExtInputStream() throws IOException {
 | 
			
		||||
    int max_input_buffer_size = 32*1024;
 | 
			
		||||
    try {
 | 
			
		||||
      max_input_buffer_size =
 | 
			
		||||
        Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){}
 | 
			
		||||
    PipedInputStream in =
 | 
			
		||||
      new MyPipedInputStream(
 | 
			
		||||
                             32*1024,  // this value should be customizable.
 | 
			
		||||
                             max_input_buffer_size
 | 
			
		||||
                             );
 | 
			
		||||
    boolean resizable = 32*1024<max_input_buffer_size;
 | 
			
		||||
    io.setExtOutputStream(new PassiveOutputStream(in, resizable), false);
 | 
			
		||||
    return in;
 | 
			
		||||
  }
 | 
			
		||||
  public OutputStream getOutputStream() throws IOException {
 | 
			
		||||
 | 
			
		||||
    final Channel channel=this;
 | 
			
		||||
    OutputStream out=new OutputStream(){
 | 
			
		||||
        private int dataLen=0;
 | 
			
		||||
        private Buffer buffer=null;
 | 
			
		||||
        private Packet packet=null;
 | 
			
		||||
        private boolean closed=false;
 | 
			
		||||
        private synchronized void init() throws IOException{
 | 
			
		||||
          buffer=new Buffer(rmpsize);
 | 
			
		||||
          packet=new Packet(buffer);
 | 
			
		||||
 | 
			
		||||
          byte[] _buf=buffer.buffer;
 | 
			
		||||
          if(_buf.length-(14+0)-Session.buffer_margin<=0){
 | 
			
		||||
            buffer=null;
 | 
			
		||||
            packet=null;
 | 
			
		||||
            throw new IOException("failed to initialize the channel.");
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        byte[] b=new byte[1];
 | 
			
		||||
        @Override
 | 
			
		||||
        public void write(int w) throws IOException{
 | 
			
		||||
          b[0]=(byte)w;
 | 
			
		||||
          write(b, 0, 1);
 | 
			
		||||
        }
 | 
			
		||||
        @Override
 | 
			
		||||
        public void write(byte[] buf, int s, int l) throws IOException{
 | 
			
		||||
          if(packet==null){
 | 
			
		||||
            init();
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if(closed){
 | 
			
		||||
            throw new IOException("Already closed");
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          byte[] _buf=buffer.buffer;
 | 
			
		||||
          int _bufl=_buf.length;
 | 
			
		||||
          while(l>0){
 | 
			
		||||
            int _l=l;
 | 
			
		||||
            if(l>_bufl-(14+dataLen)-Session.buffer_margin){
 | 
			
		||||
              _l=_bufl-(14+dataLen)-Session.buffer_margin;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if(_l<=0){
 | 
			
		||||
              flush();
 | 
			
		||||
              continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            System.arraycopy(buf, s, _buf, 14+dataLen, _l);
 | 
			
		||||
            dataLen+=_l;
 | 
			
		||||
            s+=_l;
 | 
			
		||||
            l-=_l;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void flush() throws IOException{
 | 
			
		||||
          if(closed){
 | 
			
		||||
            throw new IOException("Already closed");
 | 
			
		||||
          }
 | 
			
		||||
          if(dataLen==0)
 | 
			
		||||
            return;
 | 
			
		||||
          packet.reset();
 | 
			
		||||
          buffer.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
          buffer.putInt(recipient);
 | 
			
		||||
          buffer.putInt(dataLen);
 | 
			
		||||
          buffer.skip(dataLen);
 | 
			
		||||
          try{
 | 
			
		||||
            int foo=dataLen;
 | 
			
		||||
            dataLen=0;
 | 
			
		||||
            synchronized(channel){
 | 
			
		||||
              if(!channel.close)
 | 
			
		||||
                getSession().write(packet, channel, foo);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          catch(Exception e){
 | 
			
		||||
            close();
 | 
			
		||||
            throw new IOException(e.toString(), e);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        @Override
 | 
			
		||||
        public void close() throws IOException{
 | 
			
		||||
          if(packet==null){
 | 
			
		||||
            try{
 | 
			
		||||
              init();
 | 
			
		||||
            }
 | 
			
		||||
            catch(IOException e){
 | 
			
		||||
              // close should be finished silently.
 | 
			
		||||
              return;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          if(closed){
 | 
			
		||||
            return;
 | 
			
		||||
          }
 | 
			
		||||
          if(dataLen>0){
 | 
			
		||||
            flush();
 | 
			
		||||
          }
 | 
			
		||||
          channel.eof();
 | 
			
		||||
          closed=true;
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
    return out;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static class MyPipedInputStream extends PipedInputStream{
 | 
			
		||||
    private int BUFFER_SIZE = 1024;
 | 
			
		||||
    private int max_buffer_size = BUFFER_SIZE;
 | 
			
		||||
    MyPipedInputStream() throws IOException{ super(); }
 | 
			
		||||
    MyPipedInputStream(int size) throws IOException{
 | 
			
		||||
      super();
 | 
			
		||||
      buffer=new byte[size];
 | 
			
		||||
      BUFFER_SIZE = size;
 | 
			
		||||
      max_buffer_size = size;
 | 
			
		||||
    }
 | 
			
		||||
    MyPipedInputStream(int size, int max_buffer_size) throws IOException{
 | 
			
		||||
      this(size);
 | 
			
		||||
      this.max_buffer_size = max_buffer_size;
 | 
			
		||||
    }
 | 
			
		||||
    MyPipedInputStream(PipedOutputStream out) throws IOException{ super(out); }
 | 
			
		||||
    MyPipedInputStream(PipedOutputStream out, int size) throws IOException{
 | 
			
		||||
      super(out);
 | 
			
		||||
      buffer=new byte[size];
 | 
			
		||||
      BUFFER_SIZE=size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * TODO: We should have our own Piped[I/O]Stream implementation.
 | 
			
		||||
     * Before accepting data, JDK's PipedInputStream will check the existence of
 | 
			
		||||
     * reader thread, and if it is not alive, the stream will be closed.
 | 
			
		||||
     * That behavior may cause the problem if multiple threads make access to it.
 | 
			
		||||
     */
 | 
			
		||||
    public synchronized void updateReadSide() throws IOException {
 | 
			
		||||
      if(available() != 0){ // not empty
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      in = 0;
 | 
			
		||||
      out = 0;
 | 
			
		||||
      buffer[in++] = 0;
 | 
			
		||||
      read();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int freeSpace(){
 | 
			
		||||
      int size = 0;
 | 
			
		||||
      if(out < in) {
 | 
			
		||||
        size = buffer.length-in;
 | 
			
		||||
      }
 | 
			
		||||
      else if(in < out){
 | 
			
		||||
        if(in == -1) size = buffer.length;
 | 
			
		||||
        else size = out - in;
 | 
			
		||||
      }
 | 
			
		||||
      return size;
 | 
			
		||||
    } 
 | 
			
		||||
    synchronized void checkSpace(int len) throws IOException {
 | 
			
		||||
      int size = freeSpace();
 | 
			
		||||
      if(size<len){
 | 
			
		||||
        int datasize=buffer.length-size;
 | 
			
		||||
        int foo = buffer.length;
 | 
			
		||||
        while((foo - datasize) < len){
 | 
			
		||||
          foo*=2;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(foo > max_buffer_size){
 | 
			
		||||
          foo = max_buffer_size;
 | 
			
		||||
        }
 | 
			
		||||
        if((foo - datasize) < len) return;
 | 
			
		||||
 | 
			
		||||
        byte[] tmp = new byte[foo];
 | 
			
		||||
        if(out < in) {
 | 
			
		||||
          System.arraycopy(buffer, 0, tmp, 0, buffer.length);
 | 
			
		||||
        }
 | 
			
		||||
        else if(in < out){
 | 
			
		||||
          if(in == -1) {
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            System.arraycopy(buffer, 0, tmp, 0, in);
 | 
			
		||||
            System.arraycopy(buffer, out, 
 | 
			
		||||
                             tmp, tmp.length-(buffer.length-out),
 | 
			
		||||
                             (buffer.length-out));
 | 
			
		||||
            out = tmp.length-(buffer.length-out);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else if(in == out){
 | 
			
		||||
          System.arraycopy(buffer, 0, tmp, 0, buffer.length);
 | 
			
		||||
          in=buffer.length;
 | 
			
		||||
        }
 | 
			
		||||
        buffer=tmp;
 | 
			
		||||
      }
 | 
			
		||||
      else if(buffer.length == size && size > BUFFER_SIZE) { 
 | 
			
		||||
        int  i = size/2;
 | 
			
		||||
        if(i<BUFFER_SIZE) i = BUFFER_SIZE;
 | 
			
		||||
        byte[] tmp = new byte[i];
 | 
			
		||||
        buffer=tmp;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; }
 | 
			
		||||
  void setLocalWindowSize(int foo){ this.lwsize=foo; }
 | 
			
		||||
  void setLocalPacketSize(int foo){ this.lmpsize=foo; }
 | 
			
		||||
  synchronized void setRemoteWindowSize(long foo){ this.rwsize=foo; }
 | 
			
		||||
  synchronized void addRemoteWindowSize(long foo){ 
 | 
			
		||||
    this.rwsize+=foo; 
 | 
			
		||||
    if(notifyme>0)
 | 
			
		||||
      notifyAll();
 | 
			
		||||
  }
 | 
			
		||||
  void setRemotePacketSize(int foo){ this.rmpsize=foo; }
 | 
			
		||||
 | 
			
		||||
  abstract void run();
 | 
			
		||||
 | 
			
		||||
  void write(byte[] foo) throws IOException {
 | 
			
		||||
    write(foo, 0, foo.length);
 | 
			
		||||
  }
 | 
			
		||||
  void write(byte[] foo, int s, int l) throws IOException {
 | 
			
		||||
    try{
 | 
			
		||||
      io.put(foo, s, l);
 | 
			
		||||
    }catch(NullPointerException e){}
 | 
			
		||||
  }
 | 
			
		||||
  void write_ext(byte[] foo, int s, int l) throws IOException {
 | 
			
		||||
    try{
 | 
			
		||||
      io.put_ext(foo, s, l);
 | 
			
		||||
    }catch(NullPointerException e){}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void eof_remote(){
 | 
			
		||||
    eof_remote=true;
 | 
			
		||||
    try{
 | 
			
		||||
      io.out_close();
 | 
			
		||||
    }
 | 
			
		||||
    catch(NullPointerException e){}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void eof(){
 | 
			
		||||
    if(eof_local)return;
 | 
			
		||||
    eof_local=true;
 | 
			
		||||
 | 
			
		||||
    int i = getRecipient();
 | 
			
		||||
    if(i == -1) return;
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Buffer buf=new Buffer(100);
 | 
			
		||||
      Packet packet=new Packet(buf);
 | 
			
		||||
      packet.reset();
 | 
			
		||||
      buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
 | 
			
		||||
      buf.putInt(i);
 | 
			
		||||
      synchronized(this){
 | 
			
		||||
        if(!close)
 | 
			
		||||
          getSession().write(packet);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println("Channel.eof");
 | 
			
		||||
      //e.printStackTrace();
 | 
			
		||||
    }
 | 
			
		||||
    /*
 | 
			
		||||
    if(!isConnected()){ disconnect(); }
 | 
			
		||||
    */
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
  http://www1.ietf.org/internet-drafts/draft-ietf-secsh-connect-24.txt
 | 
			
		||||
 | 
			
		||||
5.3  Closing a Channel
 | 
			
		||||
  When a party will no longer send more data to a channel, it SHOULD
 | 
			
		||||
   send SSH_MSG_CHANNEL_EOF.
 | 
			
		||||
 | 
			
		||||
            byte      SSH_MSG_CHANNEL_EOF
 | 
			
		||||
            uint32    recipient_channel
 | 
			
		||||
 | 
			
		||||
  No explicit response is sent to this message.  However, the
 | 
			
		||||
   application may send EOF to whatever is at the other end of the
 | 
			
		||||
  channel.  Note that the channel remains open after this message, and
 | 
			
		||||
   more data may still be sent in the other direction.  This message
 | 
			
		||||
   does not consume window space and can be sent even if no window space
 | 
			
		||||
   is available.
 | 
			
		||||
 | 
			
		||||
     When either party wishes to terminate the channel, it sends
 | 
			
		||||
     SSH_MSG_CHANNEL_CLOSE.  Upon receiving this message, a party MUST
 | 
			
		||||
   send back a SSH_MSG_CHANNEL_CLOSE unless it has already sent this
 | 
			
		||||
   message for the channel.  The channel is considered closed for a
 | 
			
		||||
     party when it has both sent and received SSH_MSG_CHANNEL_CLOSE, and
 | 
			
		||||
   the party may then reuse the channel number.  A party MAY send
 | 
			
		||||
   SSH_MSG_CHANNEL_CLOSE without having sent or received
 | 
			
		||||
   SSH_MSG_CHANNEL_EOF.
 | 
			
		||||
 | 
			
		||||
            byte      SSH_MSG_CHANNEL_CLOSE
 | 
			
		||||
            uint32    recipient_channel
 | 
			
		||||
 | 
			
		||||
   This message does not consume window space and can be sent even if no
 | 
			
		||||
   window space is available.
 | 
			
		||||
 | 
			
		||||
   It is recommended that any data sent before this message is delivered
 | 
			
		||||
     to the actual destination, if possible.
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
  void close(){
 | 
			
		||||
    if(close)return;
 | 
			
		||||
    close=true;
 | 
			
		||||
    eof_local=eof_remote=true;
 | 
			
		||||
 | 
			
		||||
    int i = getRecipient();
 | 
			
		||||
    if(i == -1) return;
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Buffer buf=new Buffer(100);
 | 
			
		||||
      Packet packet=new Packet(buf);
 | 
			
		||||
      packet.reset();
 | 
			
		||||
      buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE);
 | 
			
		||||
      buf.putInt(i);
 | 
			
		||||
      synchronized(this){
 | 
			
		||||
        getSession().write(packet);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //e.printStackTrace();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  public boolean isClosed(){
 | 
			
		||||
    return close;
 | 
			
		||||
  }
 | 
			
		||||
  static void disconnect(Session session){
 | 
			
		||||
    Channel[] channels=null;
 | 
			
		||||
    int count=0;
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      channels=new Channel[pool.size()];
 | 
			
		||||
      for(int i=0; i<pool.size(); i++){
 | 
			
		||||
        try{
 | 
			
		||||
          Channel c=pool.elementAt(i);
 | 
			
		||||
          if(c.session==session){
 | 
			
		||||
            channels[count++]=c;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        catch(Exception e){
 | 
			
		||||
        }
 | 
			
		||||
      } 
 | 
			
		||||
    }
 | 
			
		||||
    for(int i=0; i<count; i++){
 | 
			
		||||
      channels[i].disconnect();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void disconnect(){
 | 
			
		||||
    //System.err.println(this+":disconnect "+io+" "+connected);
 | 
			
		||||
    //Thread.dumpStack();
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
 | 
			
		||||
      synchronized(this){
 | 
			
		||||
        if(!connected){
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
        connected=false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      close();
 | 
			
		||||
 | 
			
		||||
      eof_remote=eof_local=true;
 | 
			
		||||
 | 
			
		||||
      thread=null;
 | 
			
		||||
 | 
			
		||||
      try{
 | 
			
		||||
        if(io!=null){
 | 
			
		||||
          io.close();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      catch(Exception e){
 | 
			
		||||
        //e.printStackTrace();
 | 
			
		||||
      }
 | 
			
		||||
      // io=null;
 | 
			
		||||
    }
 | 
			
		||||
    finally{
 | 
			
		||||
      Channel.del(this);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isConnected(){
 | 
			
		||||
    Session _session=this.session;
 | 
			
		||||
    if(_session!=null){
 | 
			
		||||
      return _session.isConnected() && connected;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void sendSignal(String signal) throws Exception {
 | 
			
		||||
    RequestSignal request=new RequestSignal();
 | 
			
		||||
    request.setSignal(signal);
 | 
			
		||||
    request.request(getSession(), this);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
//  public String toString(){
 | 
			
		||||
//      return "Channel: type="+new String(type)+",id="+id+",recipient="+recipient+",window_size="+window_size+",packet_size="+packet_size;
 | 
			
		||||
//  }
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  class OutputThread extends Thread{
 | 
			
		||||
    Channel c;
 | 
			
		||||
    OutputThread(Channel c){ this.c=c;}
 | 
			
		||||
    public void run(){c.output_thread();}
 | 
			
		||||
  }
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
  static class PassiveInputStream extends MyPipedInputStream{
 | 
			
		||||
    PipedOutputStream os;
 | 
			
		||||
    PassiveInputStream(PipedOutputStream out, int size) throws IOException{
 | 
			
		||||
      super(out, size);
 | 
			
		||||
      this.os=out;
 | 
			
		||||
    }
 | 
			
		||||
    PassiveInputStream(PipedOutputStream out) throws IOException{
 | 
			
		||||
      super(out);
 | 
			
		||||
      this.os=out;
 | 
			
		||||
    }
 | 
			
		||||
    @Override
 | 
			
		||||
    public void close() throws IOException{
 | 
			
		||||
      if(this.os!=null){
 | 
			
		||||
        this.os.close();
 | 
			
		||||
      }
 | 
			
		||||
      this.os=null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  static class PassiveOutputStream extends PipedOutputStream{
 | 
			
		||||
    private MyPipedInputStream _sink=null;
 | 
			
		||||
    PassiveOutputStream(PipedInputStream in,
 | 
			
		||||
                        boolean resizable_buffer) throws IOException{
 | 
			
		||||
      super(in);
 | 
			
		||||
      if(resizable_buffer && (in instanceof MyPipedInputStream)) {
 | 
			
		||||
        this._sink=(MyPipedInputStream)in;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    @Override
 | 
			
		||||
    public void write(int b) throws IOException {
 | 
			
		||||
      if(_sink != null) {
 | 
			
		||||
        _sink.checkSpace(1);
 | 
			
		||||
      }
 | 
			
		||||
      super.write(b);
 | 
			
		||||
    }
 | 
			
		||||
    @Override
 | 
			
		||||
    public void write(byte[] b, int off, int len) throws IOException {
 | 
			
		||||
      if(_sink != null) {
 | 
			
		||||
        _sink.checkSpace(len);
 | 
			
		||||
      }
 | 
			
		||||
      super.write(b, off, len); 
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void setExitStatus(int status){ exitstatus=status; }
 | 
			
		||||
  public int getExitStatus(){ return exitstatus; }
 | 
			
		||||
 | 
			
		||||
  void setSession(Session session){
 | 
			
		||||
    this.session=session;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Session getSession() throws JSchException{ 
 | 
			
		||||
    Session _session=session;
 | 
			
		||||
    if(_session==null){
 | 
			
		||||
      throw new JSchException("session is not available");
 | 
			
		||||
    }
 | 
			
		||||
    return _session;
 | 
			
		||||
  }
 | 
			
		||||
  public int getId(){ return id; }
 | 
			
		||||
 | 
			
		||||
  protected void sendOpenConfirmation() throws Exception{
 | 
			
		||||
    Buffer buf=new Buffer(200);
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
 | 
			
		||||
    buf.putInt(getRecipient());
 | 
			
		||||
    buf.putInt(id);
 | 
			
		||||
    buf.putInt(lwsize);
 | 
			
		||||
    buf.putInt(lmpsize);
 | 
			
		||||
    getSession().write(packet);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void sendOpenFailure(int reasoncode){
 | 
			
		||||
    try{
 | 
			
		||||
      Buffer buf=new Buffer(200);
 | 
			
		||||
      Packet packet=new Packet(buf);
 | 
			
		||||
      packet.reset();
 | 
			
		||||
      buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE);
 | 
			
		||||
      buf.putInt(getRecipient());
 | 
			
		||||
      buf.putInt(reasoncode);
 | 
			
		||||
      buf.putString(Util.str2byte("open failed"));
 | 
			
		||||
      buf.putString(Util.empty);
 | 
			
		||||
      getSession().write(packet);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected Packet genChannelOpenPacket(){
 | 
			
		||||
    Buffer buf=new Buffer(200);
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
    // byte   SSH_MSG_CHANNEL_OPEN(90)
 | 
			
		||||
    // string channel type         //
 | 
			
		||||
    // uint32 sender channel       // 0
 | 
			
		||||
    // uint32 initial window size  // 0x100000(65536)
 | 
			
		||||
    // uint32 maxmum packet size   // 0x4000(16384)
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)90);
 | 
			
		||||
    buf.putString(this.type);
 | 
			
		||||
    buf.putInt(this.id);
 | 
			
		||||
    buf.putInt(this.lwsize);
 | 
			
		||||
    buf.putInt(this.lmpsize);
 | 
			
		||||
    return packet;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void sendChannelOpen() throws Exception {
 | 
			
		||||
    Session _session=getSession();
 | 
			
		||||
    if(!_session.isConnected()){
 | 
			
		||||
      throw new JSchException("session is down");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Packet packet = genChannelOpenPacket();
 | 
			
		||||
    _session.write(packet);
 | 
			
		||||
 | 
			
		||||
    int retry=2000;
 | 
			
		||||
    long start=System.currentTimeMillis();
 | 
			
		||||
    long timeout=connectTimeout;
 | 
			
		||||
    if(timeout!=0L) retry = 1;
 | 
			
		||||
    synchronized(this){
 | 
			
		||||
      while(this.getRecipient()==-1 &&
 | 
			
		||||
            _session.isConnected() &&
 | 
			
		||||
             retry>0){
 | 
			
		||||
        if(timeout>0L){
 | 
			
		||||
          if((System.currentTimeMillis()-start)>timeout){
 | 
			
		||||
            retry=0;
 | 
			
		||||
            continue;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        try{
 | 
			
		||||
          long t = timeout==0L ? 10L : timeout;
 | 
			
		||||
          this.notifyme=1;
 | 
			
		||||
          wait(t);
 | 
			
		||||
        }
 | 
			
		||||
        catch(InterruptedException e){
 | 
			
		||||
        }
 | 
			
		||||
        finally{
 | 
			
		||||
          this.notifyme=0;
 | 
			
		||||
        }
 | 
			
		||||
        retry--;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if(!_session.isConnected()){
 | 
			
		||||
      throw new JSchException("session is down");
 | 
			
		||||
    }
 | 
			
		||||
    if(this.getRecipient()==-1){  // timeout
 | 
			
		||||
      throw new JSchException("channel is not opened.");
 | 
			
		||||
    }
 | 
			
		||||
    if(this.open_confirmation==false){  // SSH_MSG_CHANNEL_OPEN_FAILURE
 | 
			
		||||
      throw new JSchException("channel is not opened.");
 | 
			
		||||
    }
 | 
			
		||||
    connected=true;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,287 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2006-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.*;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
class ChannelAgentForwarding extends Channel{
 | 
			
		||||
 | 
			
		||||
  static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
 | 
			
		||||
  static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
 | 
			
		||||
 | 
			
		||||
  static private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
 | 
			
		||||
  static private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
 | 
			
		||||
  static private final byte SSH_AGENTC_RSA_CHALLENGE = 3;
 | 
			
		||||
  static private final byte SSH_AGENT_RSA_RESPONSE = 4;
 | 
			
		||||
  static private final byte SSH_AGENT_FAILURE = 5;
 | 
			
		||||
  static private final byte SSH_AGENT_SUCCESS = 6;
 | 
			
		||||
  static private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
 | 
			
		||||
  static private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
 | 
			
		||||
  static private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
 | 
			
		||||
 | 
			
		||||
  static private final byte SSH2_AGENTC_REQUEST_IDENTITIES=11;
 | 
			
		||||
  static private final byte SSH2_AGENT_IDENTITIES_ANSWER=12;
 | 
			
		||||
  static private final byte SSH2_AGENTC_SIGN_REQUEST=13;
 | 
			
		||||
  static private final byte SSH2_AGENT_SIGN_RESPONSE=14;
 | 
			
		||||
  static private final byte SSH2_AGENTC_ADD_IDENTITY=17;
 | 
			
		||||
  static private final byte SSH2_AGENTC_REMOVE_IDENTITY=18;
 | 
			
		||||
  static private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19;
 | 
			
		||||
  static private final byte SSH2_AGENT_FAILURE=30;
 | 
			
		||||
 | 
			
		||||
  //static private final int SSH_AGENT_OLD_SIGNATURE=0x1;
 | 
			
		||||
  static private final int SSH_AGENT_RSA_SHA2_256=0x2;
 | 
			
		||||
  static private final int SSH_AGENT_RSA_SHA2_512=0x4;
 | 
			
		||||
 | 
			
		||||
  private Buffer rbuf=null;
 | 
			
		||||
  private Buffer wbuf=null;
 | 
			
		||||
  private Packet packet=null;
 | 
			
		||||
  private Buffer mbuf=null;
 | 
			
		||||
 | 
			
		||||
  ChannelAgentForwarding(){
 | 
			
		||||
    super();
 | 
			
		||||
 | 
			
		||||
    setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
 | 
			
		||||
 | 
			
		||||
    type=Util.str2byte("auth-agent@openssh.com");
 | 
			
		||||
    rbuf=new Buffer();
 | 
			
		||||
    rbuf.reset();
 | 
			
		||||
    //wbuf=new Buffer(rmpsize);
 | 
			
		||||
    //packet=new Packet(wbuf);
 | 
			
		||||
    mbuf=new Buffer();
 | 
			
		||||
    connected=true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void run(){
 | 
			
		||||
    try{
 | 
			
		||||
      sendOpenConfirmation();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      close=true;
 | 
			
		||||
      disconnect();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void write(byte[] foo, int s, int l) throws IOException {
 | 
			
		||||
 | 
			
		||||
    if(packet==null){
 | 
			
		||||
      wbuf=new Buffer(rmpsize);
 | 
			
		||||
      packet=new Packet(wbuf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rbuf.shift();
 | 
			
		||||
    if(rbuf.buffer.length<rbuf.index+l){
 | 
			
		||||
      byte[] newbuf=new byte[rbuf.s+l];
 | 
			
		||||
      System.arraycopy(rbuf.buffer, 0, newbuf, 0, rbuf.buffer.length);
 | 
			
		||||
      rbuf.buffer=newbuf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rbuf.putByte(foo, s, l);
 | 
			
		||||
 | 
			
		||||
    int mlen=rbuf.getInt();
 | 
			
		||||
    if(mlen>rbuf.getLength()){
 | 
			
		||||
      rbuf.s-=4;
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int typ=rbuf.getByte();
 | 
			
		||||
 | 
			
		||||
    Session _session=null;
 | 
			
		||||
    try{
 | 
			
		||||
      _session=getSession();
 | 
			
		||||
    }
 | 
			
		||||
    catch(JSchException e){
 | 
			
		||||
      throw new IOException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    IdentityRepository irepo = _session.getIdentityRepository();
 | 
			
		||||
    UserInfo userinfo=_session.getUserInfo();
 | 
			
		||||
 | 
			
		||||
    mbuf.reset();
 | 
			
		||||
 | 
			
		||||
    if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){ 
 | 
			
		||||
      mbuf.putByte(SSH2_AGENT_IDENTITIES_ANSWER);
 | 
			
		||||
      Vector<Identity> identities = irepo.getIdentities();
 | 
			
		||||
      synchronized(identities){
 | 
			
		||||
        int count=0;
 | 
			
		||||
        for(int i=0; i<identities.size(); i++){
 | 
			
		||||
          Identity identity=identities.elementAt(i);
 | 
			
		||||
          if(identity.getPublicKeyBlob()!=null)
 | 
			
		||||
            count++;
 | 
			
		||||
        }
 | 
			
		||||
        mbuf.putInt(count);
 | 
			
		||||
        for(int i=0; i<identities.size(); i++){
 | 
			
		||||
          Identity identity=identities.elementAt(i);
 | 
			
		||||
          byte[] pubkeyblob=identity.getPublicKeyBlob();
 | 
			
		||||
          if(pubkeyblob==null)
 | 
			
		||||
            continue;
 | 
			
		||||
          mbuf.putString(pubkeyblob);
 | 
			
		||||
          mbuf.putString(Util.empty);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH_AGENTC_REQUEST_RSA_IDENTITIES) {
 | 
			
		||||
      mbuf.putByte(SSH_AGENT_RSA_IDENTITIES_ANSWER);
 | 
			
		||||
      mbuf.putInt(0);
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH2_AGENTC_SIGN_REQUEST){
 | 
			
		||||
      byte[] blob=rbuf.getString();
 | 
			
		||||
      byte[] data=rbuf.getString();
 | 
			
		||||
      int flags=rbuf.getInt();
 | 
			
		||||
 | 
			
		||||
//      if((flags & SSH_AGENT_OLD_SIGNATURE)!=0){ // old OpenSSH 2.0, 2.1
 | 
			
		||||
//        datafellows = SSH_BUG_SIGBLOB;
 | 
			
		||||
//      }
 | 
			
		||||
 | 
			
		||||
      Vector<Identity> identities = irepo.getIdentities();
 | 
			
		||||
      Identity identity = null;
 | 
			
		||||
      synchronized(identities){
 | 
			
		||||
        for(int i=0; i<identities.size(); i++){
 | 
			
		||||
          Identity _identity=identities.elementAt(i);
 | 
			
		||||
          if(_identity.getPublicKeyBlob()==null)
 | 
			
		||||
            continue;
 | 
			
		||||
          if(!Util.array_equals(blob, _identity.getPublicKeyBlob())){
 | 
			
		||||
            continue;
 | 
			
		||||
          }
 | 
			
		||||
          if(_identity.isEncrypted()){
 | 
			
		||||
            if(userinfo==null)
 | 
			
		||||
              continue;
 | 
			
		||||
            while(_identity.isEncrypted()){
 | 
			
		||||
              if(!userinfo.promptPassphrase("Passphrase for "+_identity.getName())){
 | 
			
		||||
                break;
 | 
			
		||||
              }
 | 
			
		||||
 | 
			
		||||
              String _passphrase=userinfo.getPassphrase();
 | 
			
		||||
              if(_passphrase==null){
 | 
			
		||||
                break;
 | 
			
		||||
              }
 | 
			
		||||
 | 
			
		||||
              byte[] passphrase=Util.str2byte(_passphrase);
 | 
			
		||||
              try{
 | 
			
		||||
                if(_identity.setPassphrase(passphrase)){
 | 
			
		||||
                  break;
 | 
			
		||||
                }
 | 
			
		||||
              }
 | 
			
		||||
              catch(JSchException e){
 | 
			
		||||
                break;
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if(!_identity.isEncrypted()){
 | 
			
		||||
            identity=_identity;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      byte[] signature=null;
 | 
			
		||||
 | 
			
		||||
      if(identity!=null){
 | 
			
		||||
        Buffer kbuf=new Buffer(blob);
 | 
			
		||||
        String keytype=Util.byte2str(kbuf.getString());
 | 
			
		||||
        if(keytype.equals("ssh-rsa")){
 | 
			
		||||
          if((flags & SSH_AGENT_RSA_SHA2_256)!=0){
 | 
			
		||||
            signature=identity.getSignature(data, "rsa-sha2-256");
 | 
			
		||||
          }
 | 
			
		||||
          else if((flags & SSH_AGENT_RSA_SHA2_512)!=0){
 | 
			
		||||
            signature=identity.getSignature(data, "rsa-sha2-512");
 | 
			
		||||
          }
 | 
			
		||||
          else{
 | 
			
		||||
            signature=identity.getSignature(data, "ssh-rsa");
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
          signature=identity.getSignature(data);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(signature==null){
 | 
			
		||||
        mbuf.putByte(SSH2_AGENT_FAILURE);
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        mbuf.putByte(SSH2_AGENT_SIGN_RESPONSE);
 | 
			
		||||
        mbuf.putString(signature);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH2_AGENTC_REMOVE_IDENTITY){
 | 
			
		||||
      byte[] blob=rbuf.getString();
 | 
			
		||||
      irepo.remove(blob);
 | 
			
		||||
      mbuf.putByte(SSH_AGENT_SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES){
 | 
			
		||||
      mbuf.putByte(SSH_AGENT_SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH2_AGENTC_REMOVE_ALL_IDENTITIES){
 | 
			
		||||
      irepo.removeAll();
 | 
			
		||||
      mbuf.putByte(SSH_AGENT_SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
    else if(typ==SSH2_AGENTC_ADD_IDENTITY){
 | 
			
		||||
      int fooo = rbuf.getLength();
 | 
			
		||||
      byte[] tmp = new byte[fooo];
 | 
			
		||||
      rbuf.getByte(tmp);
 | 
			
		||||
      boolean result = irepo.add(tmp);
 | 
			
		||||
      mbuf.putByte(result ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      rbuf.skip(rbuf.getLength()-1);
 | 
			
		||||
      mbuf.putByte(SSH_AGENT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    byte[] response = new byte[mbuf.getLength()];
 | 
			
		||||
    mbuf.getByte(response);
 | 
			
		||||
    send(response);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void send(byte[] message){
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    wbuf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
    wbuf.putInt(recipient);
 | 
			
		||||
    wbuf.putInt(4+message.length);
 | 
			
		||||
    wbuf.putString(message);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      getSession().write(packet, this, 4+message.length);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void eof_remote(){
 | 
			
		||||
    super.eof_remote();
 | 
			
		||||
    eof();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,71 +0,0 @@
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import static com.jcraft.jsch.Session.SSH_MSG_CHANNEL_OPEN;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Extension of {@link ChannelDirectTCPIP} to support socket forwarding.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * https://raw.githubusercontent.com/openssh/openssh-portable/master/PROTOCOL
 | 
			
		||||
 */
 | 
			
		||||
public class ChannelDirectStreamLocal extends ChannelDirectTCPIP {
 | 
			
		||||
 | 
			
		||||
    static private final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
 | 
			
		||||
    static private final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
 | 
			
		||||
    static private final byte[] _type = Util.str2byte("direct-streamlocal@openssh.com");
 | 
			
		||||
 | 
			
		||||
    private String socketPath;
 | 
			
		||||
 | 
			
		||||
    ChannelDirectStreamLocal() {
 | 
			
		||||
        super();
 | 
			
		||||
        type = _type;
 | 
			
		||||
        setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
        setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
        setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected Packet genChannelOpenPacket() {
 | 
			
		||||
 | 
			
		||||
        if (socketPath == null) {
 | 
			
		||||
            session.getLogger().log(Logger.FATAL, "socketPath must be set");
 | 
			
		||||
            throw new RuntimeException("socketPath must be set");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
        Similar to direct-tcpip, direct-streamlocal is sent by the client
 | 
			
		||||
        to request that the server make a connection to a Unix domain socket.
 | 
			
		||||
 | 
			
		||||
            byte      SSH_MSG_CHANNEL_OPEN
 | 
			
		||||
            string    "direct-streamlocal@openssh.com"
 | 
			
		||||
            uint32    sender channel
 | 
			
		||||
            uint32    initial window size
 | 
			
		||||
            uint32    maximum packet size
 | 
			
		||||
            string    socket path
 | 
			
		||||
            string    reserved
 | 
			
		||||
            uint32    reserved
 | 
			
		||||
         */
 | 
			
		||||
 | 
			
		||||
        Buffer buf = new Buffer(50 +
 | 
			
		||||
                socketPath.length() +
 | 
			
		||||
                Session.buffer_margin);
 | 
			
		||||
        Packet packet = new Packet(buf);
 | 
			
		||||
        packet.reset();
 | 
			
		||||
        buf.putByte((byte) SSH_MSG_CHANNEL_OPEN);
 | 
			
		||||
        buf.putString(this.type);
 | 
			
		||||
        buf.putInt(id);
 | 
			
		||||
        buf.putInt(lwsize);
 | 
			
		||||
        buf.putInt(lmpsize);
 | 
			
		||||
        buf.putString(Util.str2byte(socketPath));
 | 
			
		||||
        buf.putString(Util.str2byte(originator_IP_address));
 | 
			
		||||
        buf.putInt(originator_port);
 | 
			
		||||
        return packet;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSocketPath() {
 | 
			
		||||
        return socketPath;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSocketPath(String socketPath) {
 | 
			
		||||
        this.socketPath = socketPath;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,176 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
public class ChannelDirectTCPIP extends Channel{
 | 
			
		||||
 | 
			
		||||
  static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
 | 
			
		||||
  static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
 | 
			
		||||
  static private final byte[] _type = Util.str2byte("direct-tcpip");
 | 
			
		||||
  String host;
 | 
			
		||||
  int port;
 | 
			
		||||
 | 
			
		||||
  String originator_IP_address="127.0.0.1";
 | 
			
		||||
  int originator_port=0;
 | 
			
		||||
 | 
			
		||||
  ChannelDirectTCPIP(){
 | 
			
		||||
    super();
 | 
			
		||||
    type = _type;
 | 
			
		||||
    setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void init (){
 | 
			
		||||
    io=new IO();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void connect(int connectTimeout) throws JSchException{
 | 
			
		||||
    this.connectTimeout=connectTimeout;
 | 
			
		||||
    try{
 | 
			
		||||
      Session _session=getSession();
 | 
			
		||||
      if(!_session.isConnected()){
 | 
			
		||||
        throw new JSchException("session is down");
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(io.in!=null){
 | 
			
		||||
        thread=new Thread(this::run);
 | 
			
		||||
        thread.setName("DirectTCPIP thread "+_session.getHost());
 | 
			
		||||
        if(_session.daemon_thread){
 | 
			
		||||
          thread.setDaemon(_session.daemon_thread);
 | 
			
		||||
        }
 | 
			
		||||
        thread.start();
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        sendChannelOpen();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      io.close();
 | 
			
		||||
      io=null;
 | 
			
		||||
      Channel.del(this);
 | 
			
		||||
      if (e instanceof JSchException) {
 | 
			
		||||
        throw (JSchException) e;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void run(){
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      sendChannelOpen();
 | 
			
		||||
 | 
			
		||||
      Buffer buf=new Buffer(rmpsize);
 | 
			
		||||
      Packet packet=new Packet(buf);
 | 
			
		||||
      Session _session=getSession();
 | 
			
		||||
      int i=0;
 | 
			
		||||
 | 
			
		||||
      while(isConnected() &&
 | 
			
		||||
            thread!=null && 
 | 
			
		||||
            io!=null && 
 | 
			
		||||
            io.in!=null){
 | 
			
		||||
        i=io.in.read(buf.buffer, 
 | 
			
		||||
                     14, 
 | 
			
		||||
                     buf.buffer.length-14
 | 
			
		||||
                     -Session.buffer_margin
 | 
			
		||||
                     );
 | 
			
		||||
        if(i<=0){
 | 
			
		||||
          eof();
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        packet.reset();
 | 
			
		||||
        buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
        buf.putInt(recipient);
 | 
			
		||||
        buf.putInt(i);
 | 
			
		||||
        buf.skip(i);
 | 
			
		||||
        synchronized(this){
 | 
			
		||||
          if(close)
 | 
			
		||||
            break;
 | 
			
		||||
          _session.write(packet, this, i);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      // Whenever an exception is thrown by sendChannelOpen(),
 | 
			
		||||
      // 'connected' is false.
 | 
			
		||||
      if(!connected){
 | 
			
		||||
        connected=true;
 | 
			
		||||
      }
 | 
			
		||||
      disconnect();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    eof();
 | 
			
		||||
    disconnect();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void setInputStream(InputStream in){
 | 
			
		||||
    io.setInputStream(in);
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public void setOutputStream(OutputStream out){
 | 
			
		||||
    io.setOutputStream(out);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setHost(String host){this.host=host;}
 | 
			
		||||
  public void setPort(int port){this.port=port;}
 | 
			
		||||
  public void setOrgIPAddress(String foo){this.originator_IP_address=foo;}
 | 
			
		||||
  public void setOrgPort(int foo){this.originator_port=foo;}
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected Packet genChannelOpenPacket(){
 | 
			
		||||
    Buffer buf = new Buffer(50 + // 6 + 4*8 + 12
 | 
			
		||||
                            host.length() + originator_IP_address.length() +
 | 
			
		||||
                            Session.buffer_margin);
 | 
			
		||||
    Packet packet = new Packet(buf);
 | 
			
		||||
    // byte   SSH_MSG_CHANNEL_OPEN(90)
 | 
			
		||||
    // string channel type         //
 | 
			
		||||
    // uint32 sender channel       // 0
 | 
			
		||||
    // uint32 initial window size  // 0x100000(65536)
 | 
			
		||||
    // uint32 maxmum packet size   // 0x4000(16384)
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)90);
 | 
			
		||||
    buf.putString(this.type);
 | 
			
		||||
    buf.putInt(id);
 | 
			
		||||
    buf.putInt(lwsize);
 | 
			
		||||
    buf.putInt(lmpsize);
 | 
			
		||||
    buf.putString(Util.str2byte(host));
 | 
			
		||||
    buf.putInt(port);
 | 
			
		||||
    buf.putString(Util.str2byte(originator_IP_address));
 | 
			
		||||
    buf.putInt(originator_port);
 | 
			
		||||
    return packet;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,84 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class ChannelExec extends ChannelSession{
 | 
			
		||||
 | 
			
		||||
  byte[] command=new byte[0];
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void start() throws JSchException{
 | 
			
		||||
    Session _session=getSession();
 | 
			
		||||
    try{
 | 
			
		||||
      sendRequests();
 | 
			
		||||
      Request request=new RequestExec(command);
 | 
			
		||||
      request.request(_session, this);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      if(e instanceof JSchException) throw (JSchException)e;
 | 
			
		||||
      throw new JSchException("ChannelExec", e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(io.in!=null){
 | 
			
		||||
      thread=new Thread(this::run);
 | 
			
		||||
      thread.setName("Exec thread "+_session.getHost());
 | 
			
		||||
      if(_session.daemon_thread){
 | 
			
		||||
        thread.setDaemon(_session.daemon_thread);
 | 
			
		||||
      }
 | 
			
		||||
      thread.start();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setCommand(String command){ 
 | 
			
		||||
    this.command=Util.str2byte(command);
 | 
			
		||||
  }
 | 
			
		||||
  public void setCommand(byte[] command){ 
 | 
			
		||||
    this.command=command;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void init() throws JSchException {
 | 
			
		||||
    io.setInputStream(getSession().in);
 | 
			
		||||
    io.setOutputStream(getSession().out);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setErrStream(OutputStream out){
 | 
			
		||||
    setExtOutputStream(out);
 | 
			
		||||
  }
 | 
			
		||||
  public void setErrStream(OutputStream out, boolean dontclose){
 | 
			
		||||
    setExtOutputStream(out, dontclose);
 | 
			
		||||
  }
 | 
			
		||||
  public InputStream getErrStream() throws IOException {
 | 
			
		||||
    return getExtInputStream();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,335 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.net.*;
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public class ChannelForwardedTCPIP extends Channel{
 | 
			
		||||
 | 
			
		||||
  private static Vector<Config> pool = new Vector<>();
 | 
			
		||||
 | 
			
		||||
  static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
 | 
			
		||||
//static private final int LOCAL_WINDOW_SIZE_MAX=0x100000;
 | 
			
		||||
  static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
 | 
			
		||||
 | 
			
		||||
  static private final int TIMEOUT=10*1000;
 | 
			
		||||
 | 
			
		||||
  private Socket socket=null;
 | 
			
		||||
  private ForwardedTCPIPDaemon daemon=null;
 | 
			
		||||
  private Config config = null;
 | 
			
		||||
 | 
			
		||||
  ChannelForwardedTCPIP(){
 | 
			
		||||
    super();
 | 
			
		||||
    setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
 | 
			
		||||
    io=new IO();
 | 
			
		||||
    connected=true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void run(){
 | 
			
		||||
    try{ 
 | 
			
		||||
      if(config instanceof ConfigDaemon){
 | 
			
		||||
        ConfigDaemon _config = (ConfigDaemon)config;
 | 
			
		||||
        Class<? extends ForwardedTCPIPDaemon> c=Class.forName(_config.target).asSubclass(ForwardedTCPIPDaemon.class);
 | 
			
		||||
        daemon=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
 | 
			
		||||
        PipedOutputStream out=new PipedOutputStream();
 | 
			
		||||
        io.setInputStream(new PassiveInputStream(out
 | 
			
		||||
                                                 , 32*1024
 | 
			
		||||
                                                 ), false);
 | 
			
		||||
 | 
			
		||||
        daemon.setChannel(this, getInputStream(), out);
 | 
			
		||||
        daemon.setArg(_config.arg);
 | 
			
		||||
        new Thread(daemon).start();
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        ConfigLHost _config = (ConfigLHost)config;
 | 
			
		||||
        socket=(_config.factory==null) ? 
 | 
			
		||||
           Util.createSocket(_config.target, _config.lport, TIMEOUT) : 
 | 
			
		||||
          _config.factory.createSocket(_config.target, _config.lport);
 | 
			
		||||
        socket.setTcpNoDelay(true);
 | 
			
		||||
        io.setInputStream(socket.getInputStream());
 | 
			
		||||
        io.setOutputStream(socket.getOutputStream());
 | 
			
		||||
      }
 | 
			
		||||
      sendOpenConfirmation();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
 | 
			
		||||
      close=true;
 | 
			
		||||
      disconnect();
 | 
			
		||||
      return; 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    thread=Thread.currentThread();
 | 
			
		||||
    Buffer buf=new Buffer(rmpsize);
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
    int i=0;
 | 
			
		||||
    try{
 | 
			
		||||
      Session _session = getSession();
 | 
			
		||||
      while(thread!=null && 
 | 
			
		||||
            io!=null && 
 | 
			
		||||
            io.in!=null){
 | 
			
		||||
        i=io.in.read(buf.buffer, 
 | 
			
		||||
                     14, 
 | 
			
		||||
                     buf.buffer.length-14
 | 
			
		||||
                     -Session.buffer_margin
 | 
			
		||||
                     );
 | 
			
		||||
        if(i<=0){
 | 
			
		||||
          eof();
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        packet.reset();
 | 
			
		||||
        buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
        buf.putInt(recipient);
 | 
			
		||||
        buf.putInt(i);
 | 
			
		||||
        buf.skip(i);
 | 
			
		||||
        synchronized(this){
 | 
			
		||||
          if(close)
 | 
			
		||||
            break;
 | 
			
		||||
          _session.write(packet, this, i);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
    //thread=null;
 | 
			
		||||
    //eof();
 | 
			
		||||
    disconnect();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void getData(Buffer buf){
 | 
			
		||||
    setRecipient(buf.getInt());
 | 
			
		||||
    setRemoteWindowSize(buf.getUInt());
 | 
			
		||||
    setRemotePacketSize(buf.getInt());
 | 
			
		||||
    byte[] addr=buf.getString();
 | 
			
		||||
    int port=buf.getInt();
 | 
			
		||||
    byte[] orgaddr=buf.getString();
 | 
			
		||||
    int orgport=buf.getInt();
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    System.err.println("addr: "+Util.byte2str(addr));
 | 
			
		||||
    System.err.println("port: "+port);
 | 
			
		||||
    System.err.println("orgaddr: "+Util.byte2str(orgaddr));
 | 
			
		||||
    System.err.println("orgport: "+orgport);
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    Session _session=null;
 | 
			
		||||
    try{
 | 
			
		||||
      _session=getSession();
 | 
			
		||||
    }
 | 
			
		||||
    catch(JSchException e){
 | 
			
		||||
      // session has been already down.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.config = getPort(_session, Util.byte2str(addr), port);
 | 
			
		||||
    if(this.config == null)
 | 
			
		||||
      this.config = getPort(_session, null, port);
 | 
			
		||||
 | 
			
		||||
    if(this.config == null){
 | 
			
		||||
      if(_session.getLogger().isEnabled(Logger.ERROR)){
 | 
			
		||||
          _session.getLogger().log(Logger.ERROR, 
 | 
			
		||||
                             "ChannelForwardedTCPIP: "+Util.byte2str(addr)+":"+port+" is not registered.");
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Config getPort(Session session, String address_to_bind, int rport){
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      for(int i=0; i<pool.size(); i++){
 | 
			
		||||
        Config bar = pool.elementAt(i);
 | 
			
		||||
        if(bar.session != session) continue;
 | 
			
		||||
        if(bar.rport != rport) {
 | 
			
		||||
          if(bar.rport != 0 || bar.allocated_rport != rport)
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        if(address_to_bind != null &&
 | 
			
		||||
           !bar.address_to_bind.equals(address_to_bind)) continue;
 | 
			
		||||
        return bar;
 | 
			
		||||
      }
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static String[] getPortForwarding(Session session){
 | 
			
		||||
    Vector<String> foo = new Vector<>();
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      for(int i=0; i<pool.size(); i++){
 | 
			
		||||
        Config config = pool.elementAt(i);
 | 
			
		||||
        if(config.session==session){
 | 
			
		||||
          if(config instanceof ConfigDaemon)
 | 
			
		||||
            foo.addElement(config.allocated_rport+":"+config.target+":");
 | 
			
		||||
          else
 | 
			
		||||
            foo.addElement(config.allocated_rport+":"+config.target+":"+((ConfigLHost)config).lport);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    String[] bar=new String[foo.size()];
 | 
			
		||||
    for(int i=0; i<foo.size(); i++){
 | 
			
		||||
      bar[i]=foo.elementAt(i);
 | 
			
		||||
    }
 | 
			
		||||
    return bar;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static String normalize(String address){
 | 
			
		||||
    if(address==null){ return "localhost"; }
 | 
			
		||||
    else if(address.length()==0 || address.equals("*")){ return ""; }
 | 
			
		||||
    else{ return address; }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static void addPort(Session session, String _address_to_bind,
 | 
			
		||||
                      int port, int allocated_port, String target, int lport, SocketFactory factory) throws JSchException{
 | 
			
		||||
    String address_to_bind=normalize(_address_to_bind);
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      if(getPort(session, address_to_bind, port)!=null){
 | 
			
		||||
        throw new JSchException("PortForwardingR: remote port "+port+" is already registered.");
 | 
			
		||||
      }
 | 
			
		||||
      ConfigLHost config = new ConfigLHost();
 | 
			
		||||
      config.session = session;
 | 
			
		||||
      config.rport = port;
 | 
			
		||||
      config.allocated_rport = allocated_port;
 | 
			
		||||
      config.target = target;
 | 
			
		||||
      config.lport =lport;
 | 
			
		||||
      config.address_to_bind = address_to_bind;
 | 
			
		||||
      config.factory = factory;
 | 
			
		||||
      pool.addElement(config);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  static void addPort(Session session, String _address_to_bind,
 | 
			
		||||
                      int port, int allocated_port, String daemon, Object[] arg) throws JSchException{
 | 
			
		||||
    String address_to_bind=normalize(_address_to_bind);
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      if(getPort(session, address_to_bind, port)!=null){
 | 
			
		||||
        throw new JSchException("PortForwardingR: remote port "+port+" is already registered.");
 | 
			
		||||
      }
 | 
			
		||||
      ConfigDaemon config = new ConfigDaemon();
 | 
			
		||||
      config.session = session;
 | 
			
		||||
      config.rport = port;
 | 
			
		||||
      config.allocated_rport = port;
 | 
			
		||||
      config.target = daemon;
 | 
			
		||||
      config.arg = arg;
 | 
			
		||||
      config.address_to_bind = address_to_bind;
 | 
			
		||||
      pool.addElement(config);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  static void delPort(ChannelForwardedTCPIP c){
 | 
			
		||||
    Session _session=null;
 | 
			
		||||
    try{
 | 
			
		||||
      _session=c.getSession();
 | 
			
		||||
    }
 | 
			
		||||
    catch(JSchException e){
 | 
			
		||||
      // session has been already down.
 | 
			
		||||
    }
 | 
			
		||||
    if(_session!=null && c.config!=null)
 | 
			
		||||
      delPort(_session, c.config.rport);
 | 
			
		||||
  }
 | 
			
		||||
  static void delPort(Session session, int rport){
 | 
			
		||||
    delPort(session, null, rport);
 | 
			
		||||
  }
 | 
			
		||||
  static void delPort(Session session, String address_to_bind, int rport){
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      Config foo = getPort(session, normalize(address_to_bind), rport);
 | 
			
		||||
      if(foo == null)
 | 
			
		||||
        foo = getPort(session, null, rport);
 | 
			
		||||
      if(foo==null) return;
 | 
			
		||||
      pool.removeElement(foo);
 | 
			
		||||
      if(address_to_bind==null){
 | 
			
		||||
        address_to_bind=foo.address_to_bind;
 | 
			
		||||
      }
 | 
			
		||||
      if(address_to_bind==null){
 | 
			
		||||
        address_to_bind="0.0.0.0";
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Buffer buf=new Buffer(200); // ??
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      // byte SSH_MSG_GLOBAL_REQUEST 80
 | 
			
		||||
      // string "cancel-tcpip-forward"
 | 
			
		||||
      // boolean want_reply
 | 
			
		||||
      // string  address_to_bind (e.g. "127.0.0.1")
 | 
			
		||||
      // uint32  port number to bind
 | 
			
		||||
      packet.reset();
 | 
			
		||||
      buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/);
 | 
			
		||||
      buf.putString(Util.str2byte("cancel-tcpip-forward"));
 | 
			
		||||
      buf.putByte((byte)0);
 | 
			
		||||
      buf.putString(Util.str2byte(address_to_bind));
 | 
			
		||||
      buf.putInt(rport);
 | 
			
		||||
      session.write(packet);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
//    throw new JSchException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  static void delPort(Session session){
 | 
			
		||||
    int[] rport=null;
 | 
			
		||||
    int count=0;
 | 
			
		||||
    synchronized(pool){
 | 
			
		||||
      rport=new int[pool.size()];
 | 
			
		||||
      for(int i=0; i<pool.size(); i++){
 | 
			
		||||
        Config config = pool.elementAt(i);
 | 
			
		||||
        if(config.session == session) {
 | 
			
		||||
          rport[count++]=config.rport; // ((Integer)bar[1]).intValue();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    for(int i=0; i<count; i++){
 | 
			
		||||
      delPort(session, rport[i]);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public int getRemotePort(){return (config!=null ? config.rport: 0);}
 | 
			
		||||
  private void setSocketFactory(SocketFactory factory){
 | 
			
		||||
    if(config!=null && (config instanceof ConfigLHost) )
 | 
			
		||||
      ((ConfigLHost)config).factory = factory;
 | 
			
		||||
  }
 | 
			
		||||
  static abstract class Config {
 | 
			
		||||
    Session session;
 | 
			
		||||
    int rport;
 | 
			
		||||
    int allocated_rport;
 | 
			
		||||
    String address_to_bind;
 | 
			
		||||
    String target;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static class ConfigDaemon extends Config {
 | 
			
		||||
    Object[] arg;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static class ConfigLHost extends Config {
 | 
			
		||||
    int lport;
 | 
			
		||||
    SocketFactory factory;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,279 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
class ChannelSession extends Channel{
 | 
			
		||||
  private static byte[] _session=Util.str2byte("session");
 | 
			
		||||
 | 
			
		||||
  protected boolean agent_forwarding=false;
 | 
			
		||||
  protected boolean xforwading=false;
 | 
			
		||||
  protected Hashtable<byte[], byte[]> env=null;
 | 
			
		||||
 | 
			
		||||
  protected boolean pty=false;
 | 
			
		||||
 | 
			
		||||
  protected String ttype="vt100";
 | 
			
		||||
  protected int tcol=80;
 | 
			
		||||
  protected int trow=24;
 | 
			
		||||
  protected int twp=640;
 | 
			
		||||
  protected int thp=480;
 | 
			
		||||
  protected byte[] terminal_mode=null;
 | 
			
		||||
 | 
			
		||||
  ChannelSession(){
 | 
			
		||||
    super();
 | 
			
		||||
    type=_session;
 | 
			
		||||
    io=new IO();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Enable the agent forwarding.
 | 
			
		||||
   *
 | 
			
		||||
   * @param enable
 | 
			
		||||
   */
 | 
			
		||||
  public void setAgentForwarding(boolean enable){ 
 | 
			
		||||
    agent_forwarding=enable;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Enable the X11 forwarding.
 | 
			
		||||
   * Refer to RFC4254 6.3.1. Requesting X11 Forwarding.
 | 
			
		||||
   *
 | 
			
		||||
   * @param enable
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public void setXForwarding(boolean enable){
 | 
			
		||||
    xforwading=enable; 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @deprecated Use #setEnv(String, String) or #setEnv(byte[], byte[]) instead.
 | 
			
		||||
   * @see #setEnv(String, String)
 | 
			
		||||
   * @see #setEnv(byte[], byte[])
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated
 | 
			
		||||
  public void setEnv(Hashtable<byte[], byte[]> env){ 
 | 
			
		||||
    synchronized(this){
 | 
			
		||||
      this.env=env; 
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Set the environment variable. 
 | 
			
		||||
   * If <code>name</code> and <code>value</code> are needed to be passed 
 | 
			
		||||
   * to the remote in your favorite encoding,
 | 
			
		||||
   * use {@link #setEnv(byte[], byte[])}.
 | 
			
		||||
   * Refer to RFC4254 6.4 Environment Variable Passing.
 | 
			
		||||
   *
 | 
			
		||||
   * @param name A name for environment variable.
 | 
			
		||||
   * @param value A value for environment variable.
 | 
			
		||||
   */
 | 
			
		||||
  public void setEnv(String name, String value){
 | 
			
		||||
    setEnv(Util.str2byte(name), Util.str2byte(value));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Set the environment variable.
 | 
			
		||||
   * Refer to RFC4254 6.4 Environment Variable Passing.
 | 
			
		||||
   *
 | 
			
		||||
   * @param name A name of environment variable.
 | 
			
		||||
   * @param value A value of environment variable.
 | 
			
		||||
   * @see #setEnv(String, String)
 | 
			
		||||
   */
 | 
			
		||||
  public void setEnv(byte[] name, byte[] value){
 | 
			
		||||
    synchronized(this){
 | 
			
		||||
      getEnv().put(name, value);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private Hashtable<byte[], byte[]> getEnv(){
 | 
			
		||||
    if(env==null)
 | 
			
		||||
      env=new Hashtable<>();
 | 
			
		||||
    return env;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Allocate a Pseudo-Terminal.
 | 
			
		||||
   * Refer to RFC4254 6.2. Requesting a Pseudo-Terminal.
 | 
			
		||||
   *
 | 
			
		||||
   * @param enable
 | 
			
		||||
   */
 | 
			
		||||
  public void setPty(boolean enable){ 
 | 
			
		||||
    pty=enable; 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Set the terminal mode.
 | 
			
		||||
   * 
 | 
			
		||||
   * @param terminal_mode
 | 
			
		||||
   */
 | 
			
		||||
  public void setTerminalMode(byte[] terminal_mode){
 | 
			
		||||
    this.terminal_mode=terminal_mode;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Change the window dimension interactively.
 | 
			
		||||
   * Refer to RFC4254 6.7. Window Dimension Change Message.
 | 
			
		||||
   *
 | 
			
		||||
   * @param col terminal width, columns
 | 
			
		||||
   * @param row terminal height, rows
 | 
			
		||||
   * @param wp terminal width, pixels
 | 
			
		||||
   * @param hp terminal height, pixels
 | 
			
		||||
   */
 | 
			
		||||
  public void setPtySize(int col, int row, int wp, int hp){
 | 
			
		||||
    setPtyType(this.ttype, col, row, wp, hp);
 | 
			
		||||
    if(!pty || !isConnected()){
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    try{
 | 
			
		||||
      RequestWindowChange request=new RequestWindowChange();
 | 
			
		||||
      request.setSize(col, row, wp, hp);
 | 
			
		||||
      request.request(getSession(), this);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println("ChannelSessio.setPtySize: "+e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Set the terminal type.
 | 
			
		||||
   * This method is not effective after Channel#connect().
 | 
			
		||||
   *
 | 
			
		||||
   * @param ttype terminal type(for example, "vt100")
 | 
			
		||||
   * @see #setPtyType(String, int, int, int, int)
 | 
			
		||||
   */
 | 
			
		||||
  public void setPtyType(String ttype){
 | 
			
		||||
    setPtyType(ttype, 80, 24, 640, 480);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Set the terminal type.
 | 
			
		||||
   * This method is not effective after Channel#connect().
 | 
			
		||||
   *
 | 
			
		||||
   * @param ttype terminal type(for example, "vt100")
 | 
			
		||||
   * @param col terminal width, columns
 | 
			
		||||
   * @param row terminal height, rows
 | 
			
		||||
   * @param wp terminal width, pixels
 | 
			
		||||
   * @param hp terminal height, pixels
 | 
			
		||||
   */
 | 
			
		||||
  public void setPtyType(String ttype, int col, int row, int wp, int hp){
 | 
			
		||||
    this.ttype=ttype;
 | 
			
		||||
    this.tcol=col;
 | 
			
		||||
    this.trow=row;
 | 
			
		||||
    this.twp=wp;
 | 
			
		||||
    this.thp=hp;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void sendRequests() throws Exception{
 | 
			
		||||
    Session _session=getSession();
 | 
			
		||||
    Request request;
 | 
			
		||||
    if(agent_forwarding){
 | 
			
		||||
      request=new RequestAgentForwarding();
 | 
			
		||||
      request.request(_session, this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(xforwading){
 | 
			
		||||
      request=new RequestX11();
 | 
			
		||||
      request.request(_session, this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(pty){
 | 
			
		||||
      request=new RequestPtyReq();
 | 
			
		||||
      ((RequestPtyReq)request).setTType(ttype);
 | 
			
		||||
      ((RequestPtyReq)request).setTSize(tcol, trow, twp, thp);
 | 
			
		||||
      if(terminal_mode!=null){
 | 
			
		||||
        ((RequestPtyReq)request).setTerminalMode(terminal_mode);
 | 
			
		||||
      }
 | 
			
		||||
      request.request(_session, this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(env!=null){
 | 
			
		||||
      for(Enumeration<byte[]> _env=env.keys(); _env.hasMoreElements();){
 | 
			
		||||
        byte[] name=_env.nextElement();
 | 
			
		||||
        byte[] value=env.get(name);
 | 
			
		||||
        request=new RequestEnv();
 | 
			
		||||
        ((RequestEnv)request).setEnv(toByteArray(name), 
 | 
			
		||||
                                     toByteArray(value));
 | 
			
		||||
        request.request(_session, this);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private byte[] toByteArray(Object o){
 | 
			
		||||
    if(o instanceof String){
 | 
			
		||||
      return Util.str2byte((String)o);
 | 
			
		||||
    }
 | 
			
		||||
    return (byte[])o;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void run(){
 | 
			
		||||
    //System.err.println(this+":run >");
 | 
			
		||||
 | 
			
		||||
    Buffer buf=new Buffer(rmpsize);
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
    int i=-1;
 | 
			
		||||
    try{
 | 
			
		||||
      while(isConnected() &&
 | 
			
		||||
            thread!=null && 
 | 
			
		||||
            io!=null && 
 | 
			
		||||
            io.in!=null){
 | 
			
		||||
        i=io.in.read(buf.buffer, 
 | 
			
		||||
                     14,    
 | 
			
		||||
                     buf.buffer.length-14
 | 
			
		||||
                     -Session.buffer_margin
 | 
			
		||||
                     );
 | 
			
		||||
        if(i==0)continue;
 | 
			
		||||
        if(i==-1){
 | 
			
		||||
          eof();
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        if(close)break;
 | 
			
		||||
        //System.out.println("write: "+i);
 | 
			
		||||
        packet.reset();
 | 
			
		||||
        buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
        buf.putInt(recipient);
 | 
			
		||||
        buf.putInt(i);
 | 
			
		||||
        buf.skip(i);
 | 
			
		||||
        getSession().write(packet, this, i);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println("# ChannelExec.run");
 | 
			
		||||
      //e.printStackTrace();
 | 
			
		||||
    }
 | 
			
		||||
    Thread _thread=thread; 
 | 
			
		||||
    if(_thread!=null){
 | 
			
		||||
      synchronized(_thread){ _thread.notifyAll(); }
 | 
			
		||||
    }
 | 
			
		||||
    thread=null;
 | 
			
		||||
    //System.err.println(this+":run <");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,70 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
public class ChannelShell extends ChannelSession{
 | 
			
		||||
 | 
			
		||||
  ChannelShell(){
 | 
			
		||||
    super();
 | 
			
		||||
    pty=true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void start() throws JSchException{
 | 
			
		||||
    Session _session=getSession();
 | 
			
		||||
    try{
 | 
			
		||||
      sendRequests();
 | 
			
		||||
 | 
			
		||||
      Request request=new RequestShell();
 | 
			
		||||
      request.request(_session, this);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      if(e instanceof JSchException) throw (JSchException)e;
 | 
			
		||||
      throw new JSchException("ChannelShell", e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(io.in!=null){
 | 
			
		||||
      thread=new Thread(this::run);
 | 
			
		||||
      thread.setName("Shell for "+_session.host);
 | 
			
		||||
      if(_session.daemon_thread){
 | 
			
		||||
        thread.setDaemon(_session.daemon_thread);
 | 
			
		||||
      }
 | 
			
		||||
      thread.start();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void init() throws JSchException {
 | 
			
		||||
    io.setInputStream(getSession().in);
 | 
			
		||||
    io.setOutputStream(getSession().out);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,81 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2005-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
public class ChannelSubsystem extends ChannelSession{
 | 
			
		||||
  boolean want_reply=true;
 | 
			
		||||
  String subsystem="";
 | 
			
		||||
  public void setWantReply(boolean foo){ want_reply=foo; }
 | 
			
		||||
  public void setSubsystem(String foo){ subsystem=foo; }
 | 
			
		||||
  @Override
 | 
			
		||||
  public void start() throws JSchException{
 | 
			
		||||
    Session _session=getSession();
 | 
			
		||||
    try{
 | 
			
		||||
      Request request;
 | 
			
		||||
      if(xforwading){
 | 
			
		||||
        request=new RequestX11();
 | 
			
		||||
        request.request(_session, this);
 | 
			
		||||
      }
 | 
			
		||||
      if(pty){
 | 
			
		||||
        request=new RequestPtyReq();
 | 
			
		||||
        request.request(_session, this);
 | 
			
		||||
      }
 | 
			
		||||
      request=new RequestSubsystem();
 | 
			
		||||
      ((RequestSubsystem)request).request(_session, this, subsystem, want_reply);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      if(e instanceof JSchException){ throw (JSchException)e; }
 | 
			
		||||
      throw new JSchException("ChannelSubsystem", e);
 | 
			
		||||
    }
 | 
			
		||||
    if(io.in!=null){
 | 
			
		||||
      thread=new Thread(this::run);
 | 
			
		||||
      thread.setName("Subsystem for "+_session.host);
 | 
			
		||||
      if(_session.daemon_thread){
 | 
			
		||||
        thread.setDaemon(_session.daemon_thread);
 | 
			
		||||
      }
 | 
			
		||||
      thread.start();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void init() throws JSchException {
 | 
			
		||||
    io.setInputStream(getSession().in);
 | 
			
		||||
    io.setOutputStream(getSession().out);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setErrStream(OutputStream out){
 | 
			
		||||
    setExtOutputStream(out);
 | 
			
		||||
  }
 | 
			
		||||
  public InputStream getErrStream() throws IOException {
 | 
			
		||||
    return getExtInputStream();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,277 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.*;
 | 
			
		||||
import java.util.Hashtable;
 | 
			
		||||
 | 
			
		||||
class ChannelX11 extends Channel{
 | 
			
		||||
 | 
			
		||||
  static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
 | 
			
		||||
  static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
 | 
			
		||||
 | 
			
		||||
  static private final int TIMEOUT=10*1000;
 | 
			
		||||
 | 
			
		||||
  private static String host="127.0.0.1";
 | 
			
		||||
  private static int port=6000;
 | 
			
		||||
 | 
			
		||||
  private boolean init=true;
 | 
			
		||||
 | 
			
		||||
  static byte[] cookie=null;
 | 
			
		||||
  private static byte[] cookie_hex=null;
 | 
			
		||||
 | 
			
		||||
  private static Hashtable<Session, byte[]> faked_cookie_pool=new Hashtable<>();
 | 
			
		||||
  private static Hashtable<Session, byte[]> faked_cookie_hex_pool=new Hashtable<>();
 | 
			
		||||
 | 
			
		||||
  private static byte[] table={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
 | 
			
		||||
                               0x61,0x62,0x63,0x64,0x65,0x66};
 | 
			
		||||
 | 
			
		||||
  private Socket socket = null;
 | 
			
		||||
 | 
			
		||||
  static int revtable(byte foo){
 | 
			
		||||
    for(int i=0; i<table.length; i++){
 | 
			
		||||
      if(table[i]==foo)return i;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  static void setCookie(String foo){
 | 
			
		||||
    cookie_hex=Util.str2byte(foo); 
 | 
			
		||||
    cookie=new byte[16];
 | 
			
		||||
    for(int i=0; i<16; i++){
 | 
			
		||||
        cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |
 | 
			
		||||
                         ((revtable(cookie_hex[i*2+1]))&0xf));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  static void setHost(String foo){ host=foo; }
 | 
			
		||||
  static void setPort(int foo){ port=foo; }
 | 
			
		||||
  static byte[] getFakedCookie(Session session){
 | 
			
		||||
    synchronized(faked_cookie_hex_pool){
 | 
			
		||||
      byte[] foo=faked_cookie_hex_pool.get(session);
 | 
			
		||||
      if(foo==null){
 | 
			
		||||
        Random random=Session.random;
 | 
			
		||||
        foo=new byte[16];
 | 
			
		||||
        synchronized(random){
 | 
			
		||||
          random.fill(foo, 0, 16);
 | 
			
		||||
        }
 | 
			
		||||
/*
 | 
			
		||||
System.err.print("faked_cookie: ");
 | 
			
		||||
for(int i=0; i<foo.length; i++){
 | 
			
		||||
    System.err.print(Integer.toHexString(foo[i]&0xff)+":");
 | 
			
		||||
}
 | 
			
		||||
System.err.println("");
 | 
			
		||||
*/
 | 
			
		||||
        faked_cookie_pool.put(session, foo);
 | 
			
		||||
        byte[] bar=new byte[32];
 | 
			
		||||
        for(int i=0; i<16; i++){
 | 
			
		||||
          bar[2*i]=table[(foo[i]>>>4)&0xf];
 | 
			
		||||
          bar[2*i+1]=table[(foo[i])&0xf];
 | 
			
		||||
        }
 | 
			
		||||
        faked_cookie_hex_pool.put(session, bar);
 | 
			
		||||
        foo=bar;
 | 
			
		||||
      }
 | 
			
		||||
      return foo;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static void removeFakedCookie(Session session){
 | 
			
		||||
    synchronized(faked_cookie_hex_pool){
 | 
			
		||||
      faked_cookie_hex_pool.remove(session);
 | 
			
		||||
      faked_cookie_pool.remove(session);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ChannelX11(){
 | 
			
		||||
    super();
 | 
			
		||||
 | 
			
		||||
    setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
 | 
			
		||||
    setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
 | 
			
		||||
 | 
			
		||||
    type=Util.str2byte("x11");
 | 
			
		||||
 | 
			
		||||
    connected=true;
 | 
			
		||||
    /*
 | 
			
		||||
    try{ 
 | 
			
		||||
      socket=Util.createSocket(host, port, TIMEOUT);
 | 
			
		||||
      socket.setTcpNoDelay(true);
 | 
			
		||||
      io=new IO();
 | 
			
		||||
      io.setInputStream(socket.getInputStream());
 | 
			
		||||
      io.setOutputStream(socket.getOutputStream());
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void run(){
 | 
			
		||||
 | 
			
		||||
    try{ 
 | 
			
		||||
      socket=Util.createSocket(host, port, TIMEOUT);
 | 
			
		||||
      socket.setTcpNoDelay(true);
 | 
			
		||||
      io=new IO();
 | 
			
		||||
      io.setInputStream(socket.getInputStream());
 | 
			
		||||
      io.setOutputStream(socket.getOutputStream());
 | 
			
		||||
      sendOpenConfirmation();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
 | 
			
		||||
      close=true;
 | 
			
		||||
      disconnect();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    thread=Thread.currentThread();
 | 
			
		||||
    Buffer buf=new Buffer(rmpsize);
 | 
			
		||||
    Packet packet=new Packet(buf);
 | 
			
		||||
    int i=0;
 | 
			
		||||
    try{
 | 
			
		||||
      while(thread!=null &&
 | 
			
		||||
            io!=null &&
 | 
			
		||||
            io.in!=null){
 | 
			
		||||
        i=io.in.read(buf.buffer, 
 | 
			
		||||
                     14, 
 | 
			
		||||
                     buf.buffer.length-14-Session.buffer_margin);
 | 
			
		||||
        if(i<=0){
 | 
			
		||||
          eof();
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        if(close)break;
 | 
			
		||||
        packet.reset();
 | 
			
		||||
        buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 | 
			
		||||
        buf.putInt(recipient);
 | 
			
		||||
        buf.putInt(i);
 | 
			
		||||
        buf.skip(i);
 | 
			
		||||
        getSession().write(packet, this, i);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
    disconnect();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private byte[] cache=new byte[0];
 | 
			
		||||
  private byte[] addCache(byte[] foo, int s, int l){
 | 
			
		||||
    byte[] bar=new byte[cache.length+l];
 | 
			
		||||
    System.arraycopy(foo, s, bar, cache.length, l);
 | 
			
		||||
    if(cache.length>0)
 | 
			
		||||
      System.arraycopy(cache, 0, bar, 0, cache.length);
 | 
			
		||||
    cache=bar;
 | 
			
		||||
    return cache;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  void write(byte[] foo, int s, int l) throws IOException {
 | 
			
		||||
    //if(eof_local)return;
 | 
			
		||||
 | 
			
		||||
    if(init){
 | 
			
		||||
 | 
			
		||||
      Session _session=null;
 | 
			
		||||
      try{
 | 
			
		||||
        _session=getSession();
 | 
			
		||||
      }
 | 
			
		||||
      catch(JSchException e){
 | 
			
		||||
        throw new IOException(e.toString(), e);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      foo=addCache(foo, s, l);
 | 
			
		||||
      s=0; 
 | 
			
		||||
      l=foo.length;
 | 
			
		||||
 | 
			
		||||
      if(l<9)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
      int plen=(foo[s+6]&0xff)*256+(foo[s+7]&0xff);
 | 
			
		||||
      int dlen=(foo[s+8]&0xff)*256+(foo[s+9]&0xff);
 | 
			
		||||
 | 
			
		||||
      if((foo[s]&0xff)==0x42){
 | 
			
		||||
      }
 | 
			
		||||
      else if((foo[s]&0xff)==0x6c){
 | 
			
		||||
         plen=((plen>>>8)&0xff)|((plen<<8)&0xff00);
 | 
			
		||||
         dlen=((dlen>>>8)&0xff)|((dlen<<8)&0xff00);
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
          // ??
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(l<12+plen+((-plen)&3)+dlen)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
      byte[] bar=new byte[dlen];
 | 
			
		||||
      System.arraycopy(foo, s+12+plen+((-plen)&3), bar, 0, dlen);
 | 
			
		||||
      byte[] faked_cookie=null;
 | 
			
		||||
 | 
			
		||||
      synchronized(faked_cookie_pool){
 | 
			
		||||
        faked_cookie=faked_cookie_pool.get(_session);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      /*
 | 
			
		||||
System.err.print("faked_cookie: ");
 | 
			
		||||
for(int i=0; i<faked_cookie.length; i++){
 | 
			
		||||
    System.err.print(Integer.toHexString(faked_cookie[i]&0xff)+":");
 | 
			
		||||
}
 | 
			
		||||
System.err.println("");
 | 
			
		||||
System.err.print("bar: ");
 | 
			
		||||
for(int i=0; i<bar.length; i++){
 | 
			
		||||
    System.err.print(Integer.toHexString(bar[i]&0xff)+":");
 | 
			
		||||
}
 | 
			
		||||
System.err.println("");
 | 
			
		||||
      */
 | 
			
		||||
 | 
			
		||||
      if(equals(bar, faked_cookie)){
 | 
			
		||||
        if(cookie!=null)
 | 
			
		||||
          System.arraycopy(cookie, 0, foo, s+12+plen+((-plen)&3), dlen);
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
          //System.err.println("wrong cookie");
 | 
			
		||||
          thread=null;
 | 
			
		||||
          eof();
 | 
			
		||||
          io.close();
 | 
			
		||||
          disconnect();
 | 
			
		||||
      }
 | 
			
		||||
      init=false;
 | 
			
		||||
      io.put(foo, s, l);
 | 
			
		||||
      cache=null;
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    io.put(foo, s, l);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean equals(byte[] foo, byte[] bar){
 | 
			
		||||
    if(foo.length!=bar.length)return false;
 | 
			
		||||
    for(int i=0; i<foo.length; i++){
 | 
			
		||||
      if(foo[i]!=bar[i])return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface Cipher{
 | 
			
		||||
  static int ENCRYPT_MODE=0;
 | 
			
		||||
  static int DECRYPT_MODE=1;
 | 
			
		||||
  int getIVSize(); 
 | 
			
		||||
  int getBlockSize(); 
 | 
			
		||||
  default int getTagSize() {return 0;}
 | 
			
		||||
  void init(int mode, byte[] key, byte[] iv) throws Exception; 
 | 
			
		||||
  default void update(int foo) throws Exception {}
 | 
			
		||||
  void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception;
 | 
			
		||||
  default void updateAAD(byte[] foo, int s1, int len) throws Exception {}
 | 
			
		||||
  default void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception {}
 | 
			
		||||
  boolean isCBC();
 | 
			
		||||
  default boolean isAEAD() {return false;}
 | 
			
		||||
  default boolean isChaCha20() {return false;}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,47 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class CipherNone implements Cipher{
 | 
			
		||||
  private static final int ivsize=8;
 | 
			
		||||
  private static final int bsize=16;
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getIVSize(){return ivsize;} 
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getBlockSize(){return bsize;}
 | 
			
		||||
  @Override
 | 
			
		||||
  public void init(int mode, byte[] key, byte[] iv) throws Exception{
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isCBC(){return false; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface Compression{
 | 
			
		||||
  static public final int INFLATER=0;
 | 
			
		||||
  static public final int DEFLATER=1;
 | 
			
		||||
  
 | 
			
		||||
  default void init(int type, int level, Session session) {
 | 
			
		||||
    init(type, level);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  default void end() {}
 | 
			
		||||
 | 
			
		||||
  void init(int type, int level);
 | 
			
		||||
  byte[] compress(byte[] buf, int start, int[] len);
 | 
			
		||||
  byte[] uncompress(byte[] buf, int start, int[] len);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,61 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2013-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface ConfigRepository {
 | 
			
		||||
 | 
			
		||||
  public Config getConfig(String host);
 | 
			
		||||
 | 
			
		||||
  public interface Config {
 | 
			
		||||
    public String getHostname();
 | 
			
		||||
    public String getUser();
 | 
			
		||||
    public int getPort();
 | 
			
		||||
    public String getValue(String key);
 | 
			
		||||
    public String[] getValues(String key);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static final Config defaultConfig = new Config() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getHostname() {return null;}
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getUser() {return null;}
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getPort() {return -1;}
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getValue(String key) {return null;}
 | 
			
		||||
    @Override
 | 
			
		||||
    public String[] getValues(String key) {return null;}
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  static final ConfigRepository nullConfig = new ConfigRepository(){
 | 
			
		||||
    @Override
 | 
			
		||||
    public Config getConfig(String host) { return defaultConfig; }
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -1,43 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface DH{
 | 
			
		||||
  void init() throws Exception;
 | 
			
		||||
  void setP(byte[] p);
 | 
			
		||||
  void setG(byte[] g);
 | 
			
		||||
  byte[] getE() throws Exception;
 | 
			
		||||
  void setF(byte[] f);
 | 
			
		||||
  byte[] getK() throws Exception;
 | 
			
		||||
 | 
			
		||||
  // checkRange() will check if e and f are in [1,p-1]
 | 
			
		||||
  // as defined at https://tools.ietf.org/html/rfc4253#section-8
 | 
			
		||||
  void checkRange() throws Exception;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DH25519 extends DHXEC {
 | 
			
		||||
  public DH25519(){
 | 
			
		||||
    sha_name="sha-256";
 | 
			
		||||
    curve_name="X25519";
 | 
			
		||||
    key_len=32;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DH448 extends DHXEC {
 | 
			
		||||
  public DH448(){
 | 
			
		||||
    sha_name="sha-512";
 | 
			
		||||
    curve_name="X448";
 | 
			
		||||
    key_len=56;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHEC256 extends DHECN {
 | 
			
		||||
  public DHEC256(){
 | 
			
		||||
    sha_name="sha-256";
 | 
			
		||||
    key_size=256;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHEC384 extends DHECN {
 | 
			
		||||
  public DHEC384(){
 | 
			
		||||
    sha_name="sha-384";
 | 
			
		||||
    key_size=384;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHEC521 extends DHECN {
 | 
			
		||||
  public DHEC521(){
 | 
			
		||||
    sha_name="sha-512";
 | 
			
		||||
    key_size=521;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,187 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHECN extends KeyExchange{
 | 
			
		||||
 | 
			
		||||
  private static final int SSH_MSG_KEX_ECDH_INIT =                 30;
 | 
			
		||||
  private static final int SSH_MSG_KEX_ECDH_REPLY=                 31;
 | 
			
		||||
  private int state;
 | 
			
		||||
 | 
			
		||||
  byte[] Q_C;
 | 
			
		||||
 | 
			
		||||
  byte[] V_S;
 | 
			
		||||
  byte[] V_C;
 | 
			
		||||
  byte[] I_S;
 | 
			
		||||
  byte[] I_C;
 | 
			
		||||
 | 
			
		||||
  byte[] e;
 | 
			
		||||
 | 
			
		||||
  private Buffer buf;
 | 
			
		||||
  private Packet packet;
 | 
			
		||||
 | 
			
		||||
  private ECDH ecdh;
 | 
			
		||||
 | 
			
		||||
  protected String sha_name; 
 | 
			
		||||
  protected int key_size;
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void init(Session session,
 | 
			
		||||
                   byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
 | 
			
		||||
    this.V_S=V_S;      
 | 
			
		||||
    this.V_C=V_C;      
 | 
			
		||||
    this.I_S=I_S;      
 | 
			
		||||
    this.I_C=I_C;      
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
 | 
			
		||||
      sha=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      sha.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    buf=new Buffer();
 | 
			
		||||
    packet=new Packet(buf);
 | 
			
		||||
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)SSH_MSG_KEX_ECDH_INIT);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends ECDH> c=Class.forName(session.getConfig("ecdh-sha2-nistp")).asSubclass(ECDH.class);
 | 
			
		||||
      ecdh=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      ecdh.init(key_size);
 | 
			
		||||
 | 
			
		||||
      Q_C = ecdh.getQ();
 | 
			
		||||
      buf.putString(Q_C);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      throw new JSchException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(V_S==null){  // This is a really ugly hack for Session.checkKexes ;-(
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    session.write(packet);
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "SSH_MSG_KEX_ECDH_INIT sent");
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "expecting SSH_MSG_KEX_ECDH_REPLY");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    state=SSH_MSG_KEX_ECDH_REPLY;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean next(Buffer _buf) throws Exception{
 | 
			
		||||
    int i,j;
 | 
			
		||||
    switch(state){
 | 
			
		||||
    case SSH_MSG_KEX_ECDH_REPLY:
 | 
			
		||||
      // The server responds with:
 | 
			
		||||
      // byte     SSH_MSG_KEX_ECDH_REPLY
 | 
			
		||||
      // string   K_S, server's public host key
 | 
			
		||||
      // string   Q_S, server's ephemeral public key octet string
 | 
			
		||||
      // string   the signature on the exchange hash
 | 
			
		||||
      j=_buf.getInt();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      if(j!=SSH_MSG_KEX_ECDH_REPLY){
 | 
			
		||||
        System.err.println("type: must be SSH_MSG_KEX_ECDH_REPLY "+j);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      byte[] Q_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      byte[][] r_s = KeyPairECDSA.fromPoint(Q_S);
 | 
			
		||||
 | 
			
		||||
      // RFC 5656,
 | 
			
		||||
      // 4. ECDH Key Exchange
 | 
			
		||||
      //   All elliptic curve public keys MUST be validated after they are
 | 
			
		||||
      //   received.  An example of a validation algorithm can be found in
 | 
			
		||||
      //   Section 3.2.2 of [SEC1].  If a key fails validation,
 | 
			
		||||
      //   the key exchange MUST fail.
 | 
			
		||||
      if(!ecdh.validate(r_s[0], r_s[1])){
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K = ecdh.getSecret(r_s[0], r_s[1]);
 | 
			
		||||
      K=normalize(K);
 | 
			
		||||
 | 
			
		||||
      byte[] sig_of_H=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      //The hash H is computed as the HASH hash of the concatenation of the
 | 
			
		||||
      //following:
 | 
			
		||||
      // string   V_C, client's identification string (CR and LF excluded)
 | 
			
		||||
      // string   V_S, server's identification string (CR and LF excluded)
 | 
			
		||||
      // string   I_C, payload of the client's SSH_MSG_KEXINIT
 | 
			
		||||
      // string   I_S, payload of the server's SSH_MSG_KEXINIT
 | 
			
		||||
      // string   K_S, server's public host key
 | 
			
		||||
      // string   Q_C, client's ephemeral public key octet string
 | 
			
		||||
      // string   Q_S, server's ephemeral public key octet string
 | 
			
		||||
      // mpint    K,   shared secret
 | 
			
		||||
 | 
			
		||||
      // This value is called the exchange hash, and it is used to authenti-
 | 
			
		||||
      // cate the key exchange.
 | 
			
		||||
      buf.reset();
 | 
			
		||||
      buf.putString(V_C); buf.putString(V_S);
 | 
			
		||||
      buf.putString(I_C); buf.putString(I_S);
 | 
			
		||||
      buf.putString(K_S);
 | 
			
		||||
      buf.putString(Q_C); buf.putString(Q_S);
 | 
			
		||||
      buf.putMPInt(K);
 | 
			
		||||
      byte[] foo=new byte[buf.getLength()];
 | 
			
		||||
      buf.getByte(foo);
 | 
			
		||||
 | 
			
		||||
      sha.update(foo, 0, foo.length);
 | 
			
		||||
      H=sha.digest();
 | 
			
		||||
 | 
			
		||||
      i=0;
 | 
			
		||||
      j=0;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      String alg=Util.byte2str(K_S, i, j);
 | 
			
		||||
      i+=j;
 | 
			
		||||
 | 
			
		||||
      boolean result = verify(alg, K_S, i, sig_of_H);
 | 
			
		||||
 | 
			
		||||
      state=STATE_END;
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getState(){return state; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,61 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG1 extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF, 
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE6,(byte)0x53,(byte)0x81,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-1"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG14 extends DHG14N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-1"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG14224 extends DHG14N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-224"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG14256 extends DHG14N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-256"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,75 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHG14N extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
 | 
			
		||||
(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
 | 
			
		||||
(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
 | 
			
		||||
(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
 | 
			
		||||
(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
 | 
			
		||||
(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
 | 
			
		||||
(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
 | 
			
		||||
(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
 | 
			
		||||
(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
 | 
			
		||||
(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
 | 
			
		||||
(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
 | 
			
		||||
(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
 | 
			
		||||
(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
 | 
			
		||||
(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
 | 
			
		||||
(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
 | 
			
		||||
(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
 | 
			
		||||
(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAC,(byte)0xAA,(byte)0x68,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG15 extends DHG15N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-512"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG15256 extends DHG15N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-256"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG15384 extends DHG15N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-384"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,91 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHG15N extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
 | 
			
		||||
(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
 | 
			
		||||
(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
 | 
			
		||||
(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
 | 
			
		||||
(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
 | 
			
		||||
(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
 | 
			
		||||
(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
 | 
			
		||||
(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
 | 
			
		||||
(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
 | 
			
		||||
(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
 | 
			
		||||
(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
 | 
			
		||||
(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
 | 
			
		||||
(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
 | 
			
		||||
(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
 | 
			
		||||
(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
 | 
			
		||||
(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
 | 
			
		||||
(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAA,(byte)0xC4,(byte)0x2D,
 | 
			
		||||
(byte)0xAD,(byte)0x33,(byte)0x17,(byte)0x0D,(byte)0x04,(byte)0x50,(byte)0x7A,(byte)0x33,
 | 
			
		||||
(byte)0xA8,(byte)0x55,(byte)0x21,(byte)0xAB,(byte)0xDF,(byte)0x1C,(byte)0xBA,(byte)0x64,
 | 
			
		||||
(byte)0xEC,(byte)0xFB,(byte)0x85,(byte)0x04,(byte)0x58,(byte)0xDB,(byte)0xEF,(byte)0x0A,
 | 
			
		||||
(byte)0x8A,(byte)0xEA,(byte)0x71,(byte)0x57,(byte)0x5D,(byte)0x06,(byte)0x0C,(byte)0x7D,
 | 
			
		||||
(byte)0xB3,(byte)0x97,(byte)0x0F,(byte)0x85,(byte)0xA6,(byte)0xE1,(byte)0xE4,(byte)0xC7,
 | 
			
		||||
(byte)0xAB,(byte)0xF5,(byte)0xAE,(byte)0x8C,(byte)0xDB,(byte)0x09,(byte)0x33,(byte)0xD7,
 | 
			
		||||
(byte)0x1E,(byte)0x8C,(byte)0x94,(byte)0xE0,(byte)0x4A,(byte)0x25,(byte)0x61,(byte)0x9D,
 | 
			
		||||
(byte)0xCE,(byte)0xE3,(byte)0xD2,(byte)0x26,(byte)0x1A,(byte)0xD2,(byte)0xEE,(byte)0x6B,
 | 
			
		||||
(byte)0xF1,(byte)0x2F,(byte)0xFA,(byte)0x06,(byte)0xD9,(byte)0x8A,(byte)0x08,(byte)0x64,
 | 
			
		||||
(byte)0xD8,(byte)0x76,(byte)0x02,(byte)0x73,(byte)0x3E,(byte)0xC8,(byte)0x6A,(byte)0x64,
 | 
			
		||||
(byte)0x52,(byte)0x1F,(byte)0x2B,(byte)0x18,(byte)0x17,(byte)0x7B,(byte)0x20,(byte)0x0C,
 | 
			
		||||
(byte)0xBB,(byte)0xE1,(byte)0x17,(byte)0x57,(byte)0x7A,(byte)0x61,(byte)0x5D,(byte)0x6C,
 | 
			
		||||
(byte)0x77,(byte)0x09,(byte)0x88,(byte)0xC0,(byte)0xBA,(byte)0xD9,(byte)0x46,(byte)0xE2,
 | 
			
		||||
(byte)0x08,(byte)0xE2,(byte)0x4F,(byte)0xA0,(byte)0x74,(byte)0xE5,(byte)0xAB,(byte)0x31,
 | 
			
		||||
(byte)0x43,(byte)0xDB,(byte)0x5B,(byte)0xFC,(byte)0xE0,(byte)0xFD,(byte)0x10,(byte)0x8E,
 | 
			
		||||
(byte)0x4B,(byte)0x82,(byte)0xD1,(byte)0x20,(byte)0xA9,(byte)0x3A,(byte)0xD2,(byte)0xCA,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG16 extends DHG16N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-512"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG16384 extends DHG16N{
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-384"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,107 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHG16N extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
 | 
			
		||||
(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
 | 
			
		||||
(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
 | 
			
		||||
(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
 | 
			
		||||
(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
 | 
			
		||||
(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
 | 
			
		||||
(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
 | 
			
		||||
(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
 | 
			
		||||
(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
 | 
			
		||||
(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
 | 
			
		||||
(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
 | 
			
		||||
(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
 | 
			
		||||
(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
 | 
			
		||||
(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
 | 
			
		||||
(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
 | 
			
		||||
(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
 | 
			
		||||
(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAA,(byte)0xC4,(byte)0x2D,
 | 
			
		||||
(byte)0xAD,(byte)0x33,(byte)0x17,(byte)0x0D,(byte)0x04,(byte)0x50,(byte)0x7A,(byte)0x33,
 | 
			
		||||
(byte)0xA8,(byte)0x55,(byte)0x21,(byte)0xAB,(byte)0xDF,(byte)0x1C,(byte)0xBA,(byte)0x64,
 | 
			
		||||
(byte)0xEC,(byte)0xFB,(byte)0x85,(byte)0x04,(byte)0x58,(byte)0xDB,(byte)0xEF,(byte)0x0A,
 | 
			
		||||
(byte)0x8A,(byte)0xEA,(byte)0x71,(byte)0x57,(byte)0x5D,(byte)0x06,(byte)0x0C,(byte)0x7D,
 | 
			
		||||
(byte)0xB3,(byte)0x97,(byte)0x0F,(byte)0x85,(byte)0xA6,(byte)0xE1,(byte)0xE4,(byte)0xC7,
 | 
			
		||||
(byte)0xAB,(byte)0xF5,(byte)0xAE,(byte)0x8C,(byte)0xDB,(byte)0x09,(byte)0x33,(byte)0xD7,
 | 
			
		||||
(byte)0x1E,(byte)0x8C,(byte)0x94,(byte)0xE0,(byte)0x4A,(byte)0x25,(byte)0x61,(byte)0x9D,
 | 
			
		||||
(byte)0xCE,(byte)0xE3,(byte)0xD2,(byte)0x26,(byte)0x1A,(byte)0xD2,(byte)0xEE,(byte)0x6B,
 | 
			
		||||
(byte)0xF1,(byte)0x2F,(byte)0xFA,(byte)0x06,(byte)0xD9,(byte)0x8A,(byte)0x08,(byte)0x64,
 | 
			
		||||
(byte)0xD8,(byte)0x76,(byte)0x02,(byte)0x73,(byte)0x3E,(byte)0xC8,(byte)0x6A,(byte)0x64,
 | 
			
		||||
(byte)0x52,(byte)0x1F,(byte)0x2B,(byte)0x18,(byte)0x17,(byte)0x7B,(byte)0x20,(byte)0x0C,
 | 
			
		||||
(byte)0xBB,(byte)0xE1,(byte)0x17,(byte)0x57,(byte)0x7A,(byte)0x61,(byte)0x5D,(byte)0x6C,
 | 
			
		||||
(byte)0x77,(byte)0x09,(byte)0x88,(byte)0xC0,(byte)0xBA,(byte)0xD9,(byte)0x46,(byte)0xE2,
 | 
			
		||||
(byte)0x08,(byte)0xE2,(byte)0x4F,(byte)0xA0,(byte)0x74,(byte)0xE5,(byte)0xAB,(byte)0x31,
 | 
			
		||||
(byte)0x43,(byte)0xDB,(byte)0x5B,(byte)0xFC,(byte)0xE0,(byte)0xFD,(byte)0x10,(byte)0x8E,
 | 
			
		||||
(byte)0x4B,(byte)0x82,(byte)0xD1,(byte)0x20,(byte)0xA9,(byte)0x21,(byte)0x08,(byte)0x01,
 | 
			
		||||
(byte)0x1A,(byte)0x72,(byte)0x3C,(byte)0x12,(byte)0xA7,(byte)0x87,(byte)0xE6,(byte)0xD7,
 | 
			
		||||
(byte)0x88,(byte)0x71,(byte)0x9A,(byte)0x10,(byte)0xBD,(byte)0xBA,(byte)0x5B,(byte)0x26,
 | 
			
		||||
(byte)0x99,(byte)0xC3,(byte)0x27,(byte)0x18,(byte)0x6A,(byte)0xF4,(byte)0xE2,(byte)0x3C,
 | 
			
		||||
(byte)0x1A,(byte)0x94,(byte)0x68,(byte)0x34,(byte)0xB6,(byte)0x15,(byte)0x0B,(byte)0xDA,
 | 
			
		||||
(byte)0x25,(byte)0x83,(byte)0xE9,(byte)0xCA,(byte)0x2A,(byte)0xD4,(byte)0x4C,(byte)0xE8,
 | 
			
		||||
(byte)0xDB,(byte)0xBB,(byte)0xC2,(byte)0xDB,(byte)0x04,(byte)0xDE,(byte)0x8E,(byte)0xF9,
 | 
			
		||||
(byte)0x2E,(byte)0x8E,(byte)0xFC,(byte)0x14,(byte)0x1F,(byte)0xBE,(byte)0xCA,(byte)0xA6,
 | 
			
		||||
(byte)0x28,(byte)0x7C,(byte)0x59,(byte)0x47,(byte)0x4E,(byte)0x6B,(byte)0xC0,(byte)0x5D,
 | 
			
		||||
(byte)0x99,(byte)0xB2,(byte)0x96,(byte)0x4F,(byte)0xA0,(byte)0x90,(byte)0xC3,(byte)0xA2,
 | 
			
		||||
(byte)0x23,(byte)0x3B,(byte)0xA1,(byte)0x86,(byte)0x51,(byte)0x5B,(byte)0xE7,(byte)0xED,
 | 
			
		||||
(byte)0x1F,(byte)0x61,(byte)0x29,(byte)0x70,(byte)0xCE,(byte)0xE2,(byte)0xD7,(byte)0xAF,
 | 
			
		||||
(byte)0xB8,(byte)0x1B,(byte)0xDD,(byte)0x76,(byte)0x21,(byte)0x70,(byte)0x48,(byte)0x1C,
 | 
			
		||||
(byte)0xD0,(byte)0x06,(byte)0x91,(byte)0x27,(byte)0xD5,(byte)0xB0,(byte)0x5A,(byte)0xA9,
 | 
			
		||||
(byte)0x93,(byte)0xB4,(byte)0xEA,(byte)0x98,(byte)0x8D,(byte)0x8F,(byte)0xDD,(byte)0xC1,
 | 
			
		||||
(byte)0x86,(byte)0xFF,(byte)0xB7,(byte)0xDC,(byte)0x90,(byte)0xA6,(byte)0xC0,(byte)0x8F,
 | 
			
		||||
(byte)0x4D,(byte)0xF4,(byte)0x35,(byte)0xC9,(byte)0x34,(byte)0x06,(byte)0x31,(byte)0x99,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,141 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG17 extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
 | 
			
		||||
(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
 | 
			
		||||
(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
 | 
			
		||||
(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
 | 
			
		||||
(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
 | 
			
		||||
(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
 | 
			
		||||
(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
 | 
			
		||||
(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
 | 
			
		||||
(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
 | 
			
		||||
(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
 | 
			
		||||
(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
 | 
			
		||||
(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
 | 
			
		||||
(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
 | 
			
		||||
(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
 | 
			
		||||
(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
 | 
			
		||||
(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
 | 
			
		||||
(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAA,(byte)0xC4,(byte)0x2D,
 | 
			
		||||
(byte)0xAD,(byte)0x33,(byte)0x17,(byte)0x0D,(byte)0x04,(byte)0x50,(byte)0x7A,(byte)0x33,
 | 
			
		||||
(byte)0xA8,(byte)0x55,(byte)0x21,(byte)0xAB,(byte)0xDF,(byte)0x1C,(byte)0xBA,(byte)0x64,
 | 
			
		||||
(byte)0xEC,(byte)0xFB,(byte)0x85,(byte)0x04,(byte)0x58,(byte)0xDB,(byte)0xEF,(byte)0x0A,
 | 
			
		||||
(byte)0x8A,(byte)0xEA,(byte)0x71,(byte)0x57,(byte)0x5D,(byte)0x06,(byte)0x0C,(byte)0x7D,
 | 
			
		||||
(byte)0xB3,(byte)0x97,(byte)0x0F,(byte)0x85,(byte)0xA6,(byte)0xE1,(byte)0xE4,(byte)0xC7,
 | 
			
		||||
(byte)0xAB,(byte)0xF5,(byte)0xAE,(byte)0x8C,(byte)0xDB,(byte)0x09,(byte)0x33,(byte)0xD7,
 | 
			
		||||
(byte)0x1E,(byte)0x8C,(byte)0x94,(byte)0xE0,(byte)0x4A,(byte)0x25,(byte)0x61,(byte)0x9D,
 | 
			
		||||
(byte)0xCE,(byte)0xE3,(byte)0xD2,(byte)0x26,(byte)0x1A,(byte)0xD2,(byte)0xEE,(byte)0x6B,
 | 
			
		||||
(byte)0xF1,(byte)0x2F,(byte)0xFA,(byte)0x06,(byte)0xD9,(byte)0x8A,(byte)0x08,(byte)0x64,
 | 
			
		||||
(byte)0xD8,(byte)0x76,(byte)0x02,(byte)0x73,(byte)0x3E,(byte)0xC8,(byte)0x6A,(byte)0x64,
 | 
			
		||||
(byte)0x52,(byte)0x1F,(byte)0x2B,(byte)0x18,(byte)0x17,(byte)0x7B,(byte)0x20,(byte)0x0C,
 | 
			
		||||
(byte)0xBB,(byte)0xE1,(byte)0x17,(byte)0x57,(byte)0x7A,(byte)0x61,(byte)0x5D,(byte)0x6C,
 | 
			
		||||
(byte)0x77,(byte)0x09,(byte)0x88,(byte)0xC0,(byte)0xBA,(byte)0xD9,(byte)0x46,(byte)0xE2,
 | 
			
		||||
(byte)0x08,(byte)0xE2,(byte)0x4F,(byte)0xA0,(byte)0x74,(byte)0xE5,(byte)0xAB,(byte)0x31,
 | 
			
		||||
(byte)0x43,(byte)0xDB,(byte)0x5B,(byte)0xFC,(byte)0xE0,(byte)0xFD,(byte)0x10,(byte)0x8E,
 | 
			
		||||
(byte)0x4B,(byte)0x82,(byte)0xD1,(byte)0x20,(byte)0xA9,(byte)0x21,(byte)0x08,(byte)0x01,
 | 
			
		||||
(byte)0x1A,(byte)0x72,(byte)0x3C,(byte)0x12,(byte)0xA7,(byte)0x87,(byte)0xE6,(byte)0xD7,
 | 
			
		||||
(byte)0x88,(byte)0x71,(byte)0x9A,(byte)0x10,(byte)0xBD,(byte)0xBA,(byte)0x5B,(byte)0x26,
 | 
			
		||||
(byte)0x99,(byte)0xC3,(byte)0x27,(byte)0x18,(byte)0x6A,(byte)0xF4,(byte)0xE2,(byte)0x3C,
 | 
			
		||||
(byte)0x1A,(byte)0x94,(byte)0x68,(byte)0x34,(byte)0xB6,(byte)0x15,(byte)0x0B,(byte)0xDA,
 | 
			
		||||
(byte)0x25,(byte)0x83,(byte)0xE9,(byte)0xCA,(byte)0x2A,(byte)0xD4,(byte)0x4C,(byte)0xE8,
 | 
			
		||||
(byte)0xDB,(byte)0xBB,(byte)0xC2,(byte)0xDB,(byte)0x04,(byte)0xDE,(byte)0x8E,(byte)0xF9,
 | 
			
		||||
(byte)0x2E,(byte)0x8E,(byte)0xFC,(byte)0x14,(byte)0x1F,(byte)0xBE,(byte)0xCA,(byte)0xA6,
 | 
			
		||||
(byte)0x28,(byte)0x7C,(byte)0x59,(byte)0x47,(byte)0x4E,(byte)0x6B,(byte)0xC0,(byte)0x5D,
 | 
			
		||||
(byte)0x99,(byte)0xB2,(byte)0x96,(byte)0x4F,(byte)0xA0,(byte)0x90,(byte)0xC3,(byte)0xA2,
 | 
			
		||||
(byte)0x23,(byte)0x3B,(byte)0xA1,(byte)0x86,(byte)0x51,(byte)0x5B,(byte)0xE7,(byte)0xED,
 | 
			
		||||
(byte)0x1F,(byte)0x61,(byte)0x29,(byte)0x70,(byte)0xCE,(byte)0xE2,(byte)0xD7,(byte)0xAF,
 | 
			
		||||
(byte)0xB8,(byte)0x1B,(byte)0xDD,(byte)0x76,(byte)0x21,(byte)0x70,(byte)0x48,(byte)0x1C,
 | 
			
		||||
(byte)0xD0,(byte)0x06,(byte)0x91,(byte)0x27,(byte)0xD5,(byte)0xB0,(byte)0x5A,(byte)0xA9,
 | 
			
		||||
(byte)0x93,(byte)0xB4,(byte)0xEA,(byte)0x98,(byte)0x8D,(byte)0x8F,(byte)0xDD,(byte)0xC1,
 | 
			
		||||
(byte)0x86,(byte)0xFF,(byte)0xB7,(byte)0xDC,(byte)0x90,(byte)0xA6,(byte)0xC0,(byte)0x8F,
 | 
			
		||||
(byte)0x4D,(byte)0xF4,(byte)0x35,(byte)0xC9,(byte)0x34,(byte)0x02,(byte)0x84,(byte)0x92,
 | 
			
		||||
(byte)0x36,(byte)0xC3,(byte)0xFA,(byte)0xB4,(byte)0xD2,(byte)0x7C,(byte)0x70,(byte)0x26,
 | 
			
		||||
(byte)0xC1,(byte)0xD4,(byte)0xDC,(byte)0xB2,(byte)0x60,(byte)0x26,(byte)0x46,(byte)0xDE,
 | 
			
		||||
(byte)0xC9,(byte)0x75,(byte)0x1E,(byte)0x76,(byte)0x3D,(byte)0xBA,(byte)0x37,(byte)0xBD,
 | 
			
		||||
(byte)0xF8,(byte)0xFF,(byte)0x94,(byte)0x06,(byte)0xAD,(byte)0x9E,(byte)0x53,(byte)0x0E,
 | 
			
		||||
(byte)0xE5,(byte)0xDB,(byte)0x38,(byte)0x2F,(byte)0x41,(byte)0x30,(byte)0x01,(byte)0xAE,
 | 
			
		||||
(byte)0xB0,(byte)0x6A,(byte)0x53,(byte)0xED,(byte)0x90,(byte)0x27,(byte)0xD8,(byte)0x31,
 | 
			
		||||
(byte)0x17,(byte)0x97,(byte)0x27,(byte)0xB0,(byte)0x86,(byte)0x5A,(byte)0x89,(byte)0x18,
 | 
			
		||||
(byte)0xDA,(byte)0x3E,(byte)0xDB,(byte)0xEB,(byte)0xCF,(byte)0x9B,(byte)0x14,(byte)0xED,
 | 
			
		||||
(byte)0x44,(byte)0xCE,(byte)0x6C,(byte)0xBA,(byte)0xCE,(byte)0xD4,(byte)0xBB,(byte)0x1B,
 | 
			
		||||
(byte)0xDB,(byte)0x7F,(byte)0x14,(byte)0x47,(byte)0xE6,(byte)0xCC,(byte)0x25,(byte)0x4B,
 | 
			
		||||
(byte)0x33,(byte)0x20,(byte)0x51,(byte)0x51,(byte)0x2B,(byte)0xD7,(byte)0xAF,(byte)0x42,
 | 
			
		||||
(byte)0x6F,(byte)0xB8,(byte)0xF4,(byte)0x01,(byte)0x37,(byte)0x8C,(byte)0xD2,(byte)0xBF,
 | 
			
		||||
(byte)0x59,(byte)0x83,(byte)0xCA,(byte)0x01,(byte)0xC6,(byte)0x4B,(byte)0x92,(byte)0xEC,
 | 
			
		||||
(byte)0xF0,(byte)0x32,(byte)0xEA,(byte)0x15,(byte)0xD1,(byte)0x72,(byte)0x1D,(byte)0x03,
 | 
			
		||||
(byte)0xF4,(byte)0x82,(byte)0xD7,(byte)0xCE,(byte)0x6E,(byte)0x74,(byte)0xFE,(byte)0xF6,
 | 
			
		||||
(byte)0xD5,(byte)0x5E,(byte)0x70,(byte)0x2F,(byte)0x46,(byte)0x98,(byte)0x0C,(byte)0x82,
 | 
			
		||||
(byte)0xB5,(byte)0xA8,(byte)0x40,(byte)0x31,(byte)0x90,(byte)0x0B,(byte)0x1C,(byte)0x9E,
 | 
			
		||||
(byte)0x59,(byte)0xE7,(byte)0xC9,(byte)0x7F,(byte)0xBE,(byte)0xC7,(byte)0xE8,(byte)0xF3,
 | 
			
		||||
(byte)0x23,(byte)0xA9,(byte)0x7A,(byte)0x7E,(byte)0x36,(byte)0xCC,(byte)0x88,(byte)0xBE,
 | 
			
		||||
(byte)0x0F,(byte)0x1D,(byte)0x45,(byte)0xB7,(byte)0xFF,(byte)0x58,(byte)0x5A,(byte)0xC5,
 | 
			
		||||
(byte)0x4B,(byte)0xD4,(byte)0x07,(byte)0xB2,(byte)0x2B,(byte)0x41,(byte)0x54,(byte)0xAA,
 | 
			
		||||
(byte)0xCC,(byte)0x8F,(byte)0x6D,(byte)0x7E,(byte)0xBF,(byte)0x48,(byte)0xE1,(byte)0xD8,
 | 
			
		||||
(byte)0x14,(byte)0xCC,(byte)0x5E,(byte)0xD2,(byte)0x0F,(byte)0x80,(byte)0x37,(byte)0xE0,
 | 
			
		||||
(byte)0xA7,(byte)0x97,(byte)0x15,(byte)0xEE,(byte)0xF2,(byte)0x9B,(byte)0xE3,(byte)0x28,
 | 
			
		||||
(byte)0x06,(byte)0xA1,(byte)0xD5,(byte)0x8B,(byte)0xB7,(byte)0xC5,(byte)0xDA,(byte)0x76,
 | 
			
		||||
(byte)0xF5,(byte)0x50,(byte)0xAA,(byte)0x3D,(byte)0x8A,(byte)0x1F,(byte)0xBF,(byte)0xF0,
 | 
			
		||||
(byte)0xEB,(byte)0x19,(byte)0xCC,(byte)0xB1,(byte)0xA3,(byte)0x13,(byte)0xD5,(byte)0x5C,
 | 
			
		||||
(byte)0xDA,(byte)0x56,(byte)0xC9,(byte)0xEC,(byte)0x2E,(byte)0xF2,(byte)0x96,(byte)0x32,
 | 
			
		||||
(byte)0x38,(byte)0x7F,(byte)0xE8,(byte)0xD7,(byte)0x6E,(byte)0x3C,(byte)0x04,(byte)0x68,
 | 
			
		||||
(byte)0x04,(byte)0x3E,(byte)0x8F,(byte)0x66,(byte)0x3F,(byte)0x48,(byte)0x60,(byte)0xEE,
 | 
			
		||||
(byte)0x12,(byte)0xBF,(byte)0x2D,(byte)0x5B,(byte)0x0B,(byte)0x74,(byte)0x74,(byte)0xD6,
 | 
			
		||||
(byte)0xE6,(byte)0x94,(byte)0xF9,(byte)0x1E,(byte)0x6D,(byte)0xCC,(byte)0x40,(byte)0x24,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-512"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,173 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHG18 extends DHGN{
 | 
			
		||||
 | 
			
		||||
  static final byte[] g={ 2 };
 | 
			
		||||
  static final byte[] p={
 | 
			
		||||
(byte)0x00,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
 | 
			
		||||
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
 | 
			
		||||
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
 | 
			
		||||
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
 | 
			
		||||
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
 | 
			
		||||
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
 | 
			
		||||
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
 | 
			
		||||
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
 | 
			
		||||
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
 | 
			
		||||
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
 | 
			
		||||
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
 | 
			
		||||
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
 | 
			
		||||
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
 | 
			
		||||
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
 | 
			
		||||
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
 | 
			
		||||
(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
 | 
			
		||||
(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
 | 
			
		||||
(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
 | 
			
		||||
(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
 | 
			
		||||
(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
 | 
			
		||||
(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
 | 
			
		||||
(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
 | 
			
		||||
(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
 | 
			
		||||
(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
 | 
			
		||||
(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
 | 
			
		||||
(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
 | 
			
		||||
(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
 | 
			
		||||
(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
 | 
			
		||||
(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
 | 
			
		||||
(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
 | 
			
		||||
(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAA,(byte)0xC4,(byte)0x2D,
 | 
			
		||||
(byte)0xAD,(byte)0x33,(byte)0x17,(byte)0x0D,(byte)0x04,(byte)0x50,(byte)0x7A,(byte)0x33,
 | 
			
		||||
(byte)0xA8,(byte)0x55,(byte)0x21,(byte)0xAB,(byte)0xDF,(byte)0x1C,(byte)0xBA,(byte)0x64,
 | 
			
		||||
(byte)0xEC,(byte)0xFB,(byte)0x85,(byte)0x04,(byte)0x58,(byte)0xDB,(byte)0xEF,(byte)0x0A,
 | 
			
		||||
(byte)0x8A,(byte)0xEA,(byte)0x71,(byte)0x57,(byte)0x5D,(byte)0x06,(byte)0x0C,(byte)0x7D,
 | 
			
		||||
(byte)0xB3,(byte)0x97,(byte)0x0F,(byte)0x85,(byte)0xA6,(byte)0xE1,(byte)0xE4,(byte)0xC7,
 | 
			
		||||
(byte)0xAB,(byte)0xF5,(byte)0xAE,(byte)0x8C,(byte)0xDB,(byte)0x09,(byte)0x33,(byte)0xD7,
 | 
			
		||||
(byte)0x1E,(byte)0x8C,(byte)0x94,(byte)0xE0,(byte)0x4A,(byte)0x25,(byte)0x61,(byte)0x9D,
 | 
			
		||||
(byte)0xCE,(byte)0xE3,(byte)0xD2,(byte)0x26,(byte)0x1A,(byte)0xD2,(byte)0xEE,(byte)0x6B,
 | 
			
		||||
(byte)0xF1,(byte)0x2F,(byte)0xFA,(byte)0x06,(byte)0xD9,(byte)0x8A,(byte)0x08,(byte)0x64,
 | 
			
		||||
(byte)0xD8,(byte)0x76,(byte)0x02,(byte)0x73,(byte)0x3E,(byte)0xC8,(byte)0x6A,(byte)0x64,
 | 
			
		||||
(byte)0x52,(byte)0x1F,(byte)0x2B,(byte)0x18,(byte)0x17,(byte)0x7B,(byte)0x20,(byte)0x0C,
 | 
			
		||||
(byte)0xBB,(byte)0xE1,(byte)0x17,(byte)0x57,(byte)0x7A,(byte)0x61,(byte)0x5D,(byte)0x6C,
 | 
			
		||||
(byte)0x77,(byte)0x09,(byte)0x88,(byte)0xC0,(byte)0xBA,(byte)0xD9,(byte)0x46,(byte)0xE2,
 | 
			
		||||
(byte)0x08,(byte)0xE2,(byte)0x4F,(byte)0xA0,(byte)0x74,(byte)0xE5,(byte)0xAB,(byte)0x31,
 | 
			
		||||
(byte)0x43,(byte)0xDB,(byte)0x5B,(byte)0xFC,(byte)0xE0,(byte)0xFD,(byte)0x10,(byte)0x8E,
 | 
			
		||||
(byte)0x4B,(byte)0x82,(byte)0xD1,(byte)0x20,(byte)0xA9,(byte)0x21,(byte)0x08,(byte)0x01,
 | 
			
		||||
(byte)0x1A,(byte)0x72,(byte)0x3C,(byte)0x12,(byte)0xA7,(byte)0x87,(byte)0xE6,(byte)0xD7,
 | 
			
		||||
(byte)0x88,(byte)0x71,(byte)0x9A,(byte)0x10,(byte)0xBD,(byte)0xBA,(byte)0x5B,(byte)0x26,
 | 
			
		||||
(byte)0x99,(byte)0xC3,(byte)0x27,(byte)0x18,(byte)0x6A,(byte)0xF4,(byte)0xE2,(byte)0x3C,
 | 
			
		||||
(byte)0x1A,(byte)0x94,(byte)0x68,(byte)0x34,(byte)0xB6,(byte)0x15,(byte)0x0B,(byte)0xDA,
 | 
			
		||||
(byte)0x25,(byte)0x83,(byte)0xE9,(byte)0xCA,(byte)0x2A,(byte)0xD4,(byte)0x4C,(byte)0xE8,
 | 
			
		||||
(byte)0xDB,(byte)0xBB,(byte)0xC2,(byte)0xDB,(byte)0x04,(byte)0xDE,(byte)0x8E,(byte)0xF9,
 | 
			
		||||
(byte)0x2E,(byte)0x8E,(byte)0xFC,(byte)0x14,(byte)0x1F,(byte)0xBE,(byte)0xCA,(byte)0xA6,
 | 
			
		||||
(byte)0x28,(byte)0x7C,(byte)0x59,(byte)0x47,(byte)0x4E,(byte)0x6B,(byte)0xC0,(byte)0x5D,
 | 
			
		||||
(byte)0x99,(byte)0xB2,(byte)0x96,(byte)0x4F,(byte)0xA0,(byte)0x90,(byte)0xC3,(byte)0xA2,
 | 
			
		||||
(byte)0x23,(byte)0x3B,(byte)0xA1,(byte)0x86,(byte)0x51,(byte)0x5B,(byte)0xE7,(byte)0xED,
 | 
			
		||||
(byte)0x1F,(byte)0x61,(byte)0x29,(byte)0x70,(byte)0xCE,(byte)0xE2,(byte)0xD7,(byte)0xAF,
 | 
			
		||||
(byte)0xB8,(byte)0x1B,(byte)0xDD,(byte)0x76,(byte)0x21,(byte)0x70,(byte)0x48,(byte)0x1C,
 | 
			
		||||
(byte)0xD0,(byte)0x06,(byte)0x91,(byte)0x27,(byte)0xD5,(byte)0xB0,(byte)0x5A,(byte)0xA9,
 | 
			
		||||
(byte)0x93,(byte)0xB4,(byte)0xEA,(byte)0x98,(byte)0x8D,(byte)0x8F,(byte)0xDD,(byte)0xC1,
 | 
			
		||||
(byte)0x86,(byte)0xFF,(byte)0xB7,(byte)0xDC,(byte)0x90,(byte)0xA6,(byte)0xC0,(byte)0x8F,
 | 
			
		||||
(byte)0x4D,(byte)0xF4,(byte)0x35,(byte)0xC9,(byte)0x34,(byte)0x02,(byte)0x84,(byte)0x92,
 | 
			
		||||
(byte)0x36,(byte)0xC3,(byte)0xFA,(byte)0xB4,(byte)0xD2,(byte)0x7C,(byte)0x70,(byte)0x26,
 | 
			
		||||
(byte)0xC1,(byte)0xD4,(byte)0xDC,(byte)0xB2,(byte)0x60,(byte)0x26,(byte)0x46,(byte)0xDE,
 | 
			
		||||
(byte)0xC9,(byte)0x75,(byte)0x1E,(byte)0x76,(byte)0x3D,(byte)0xBA,(byte)0x37,(byte)0xBD,
 | 
			
		||||
(byte)0xF8,(byte)0xFF,(byte)0x94,(byte)0x06,(byte)0xAD,(byte)0x9E,(byte)0x53,(byte)0x0E,
 | 
			
		||||
(byte)0xE5,(byte)0xDB,(byte)0x38,(byte)0x2F,(byte)0x41,(byte)0x30,(byte)0x01,(byte)0xAE,
 | 
			
		||||
(byte)0xB0,(byte)0x6A,(byte)0x53,(byte)0xED,(byte)0x90,(byte)0x27,(byte)0xD8,(byte)0x31,
 | 
			
		||||
(byte)0x17,(byte)0x97,(byte)0x27,(byte)0xB0,(byte)0x86,(byte)0x5A,(byte)0x89,(byte)0x18,
 | 
			
		||||
(byte)0xDA,(byte)0x3E,(byte)0xDB,(byte)0xEB,(byte)0xCF,(byte)0x9B,(byte)0x14,(byte)0xED,
 | 
			
		||||
(byte)0x44,(byte)0xCE,(byte)0x6C,(byte)0xBA,(byte)0xCE,(byte)0xD4,(byte)0xBB,(byte)0x1B,
 | 
			
		||||
(byte)0xDB,(byte)0x7F,(byte)0x14,(byte)0x47,(byte)0xE6,(byte)0xCC,(byte)0x25,(byte)0x4B,
 | 
			
		||||
(byte)0x33,(byte)0x20,(byte)0x51,(byte)0x51,(byte)0x2B,(byte)0xD7,(byte)0xAF,(byte)0x42,
 | 
			
		||||
(byte)0x6F,(byte)0xB8,(byte)0xF4,(byte)0x01,(byte)0x37,(byte)0x8C,(byte)0xD2,(byte)0xBF,
 | 
			
		||||
(byte)0x59,(byte)0x83,(byte)0xCA,(byte)0x01,(byte)0xC6,(byte)0x4B,(byte)0x92,(byte)0xEC,
 | 
			
		||||
(byte)0xF0,(byte)0x32,(byte)0xEA,(byte)0x15,(byte)0xD1,(byte)0x72,(byte)0x1D,(byte)0x03,
 | 
			
		||||
(byte)0xF4,(byte)0x82,(byte)0xD7,(byte)0xCE,(byte)0x6E,(byte)0x74,(byte)0xFE,(byte)0xF6,
 | 
			
		||||
(byte)0xD5,(byte)0x5E,(byte)0x70,(byte)0x2F,(byte)0x46,(byte)0x98,(byte)0x0C,(byte)0x82,
 | 
			
		||||
(byte)0xB5,(byte)0xA8,(byte)0x40,(byte)0x31,(byte)0x90,(byte)0x0B,(byte)0x1C,(byte)0x9E,
 | 
			
		||||
(byte)0x59,(byte)0xE7,(byte)0xC9,(byte)0x7F,(byte)0xBE,(byte)0xC7,(byte)0xE8,(byte)0xF3,
 | 
			
		||||
(byte)0x23,(byte)0xA9,(byte)0x7A,(byte)0x7E,(byte)0x36,(byte)0xCC,(byte)0x88,(byte)0xBE,
 | 
			
		||||
(byte)0x0F,(byte)0x1D,(byte)0x45,(byte)0xB7,(byte)0xFF,(byte)0x58,(byte)0x5A,(byte)0xC5,
 | 
			
		||||
(byte)0x4B,(byte)0xD4,(byte)0x07,(byte)0xB2,(byte)0x2B,(byte)0x41,(byte)0x54,(byte)0xAA,
 | 
			
		||||
(byte)0xCC,(byte)0x8F,(byte)0x6D,(byte)0x7E,(byte)0xBF,(byte)0x48,(byte)0xE1,(byte)0xD8,
 | 
			
		||||
(byte)0x14,(byte)0xCC,(byte)0x5E,(byte)0xD2,(byte)0x0F,(byte)0x80,(byte)0x37,(byte)0xE0,
 | 
			
		||||
(byte)0xA7,(byte)0x97,(byte)0x15,(byte)0xEE,(byte)0xF2,(byte)0x9B,(byte)0xE3,(byte)0x28,
 | 
			
		||||
(byte)0x06,(byte)0xA1,(byte)0xD5,(byte)0x8B,(byte)0xB7,(byte)0xC5,(byte)0xDA,(byte)0x76,
 | 
			
		||||
(byte)0xF5,(byte)0x50,(byte)0xAA,(byte)0x3D,(byte)0x8A,(byte)0x1F,(byte)0xBF,(byte)0xF0,
 | 
			
		||||
(byte)0xEB,(byte)0x19,(byte)0xCC,(byte)0xB1,(byte)0xA3,(byte)0x13,(byte)0xD5,(byte)0x5C,
 | 
			
		||||
(byte)0xDA,(byte)0x56,(byte)0xC9,(byte)0xEC,(byte)0x2E,(byte)0xF2,(byte)0x96,(byte)0x32,
 | 
			
		||||
(byte)0x38,(byte)0x7F,(byte)0xE8,(byte)0xD7,(byte)0x6E,(byte)0x3C,(byte)0x04,(byte)0x68,
 | 
			
		||||
(byte)0x04,(byte)0x3E,(byte)0x8F,(byte)0x66,(byte)0x3F,(byte)0x48,(byte)0x60,(byte)0xEE,
 | 
			
		||||
(byte)0x12,(byte)0xBF,(byte)0x2D,(byte)0x5B,(byte)0x0B,(byte)0x74,(byte)0x74,(byte)0xD6,
 | 
			
		||||
(byte)0xE6,(byte)0x94,(byte)0xF9,(byte)0x1E,(byte)0x6D,(byte)0xBE,(byte)0x11,(byte)0x59,
 | 
			
		||||
(byte)0x74,(byte)0xA3,(byte)0x92,(byte)0x6F,(byte)0x12,(byte)0xFE,(byte)0xE5,(byte)0xE4,
 | 
			
		||||
(byte)0x38,(byte)0x77,(byte)0x7C,(byte)0xB6,(byte)0xA9,(byte)0x32,(byte)0xDF,(byte)0x8C,
 | 
			
		||||
(byte)0xD8,(byte)0xBE,(byte)0xC4,(byte)0xD0,(byte)0x73,(byte)0xB9,(byte)0x31,(byte)0xBA,
 | 
			
		||||
(byte)0x3B,(byte)0xC8,(byte)0x32,(byte)0xB6,(byte)0x8D,(byte)0x9D,(byte)0xD3,(byte)0x00,
 | 
			
		||||
(byte)0x74,(byte)0x1F,(byte)0xA7,(byte)0xBF,(byte)0x8A,(byte)0xFC,(byte)0x47,(byte)0xED,
 | 
			
		||||
(byte)0x25,(byte)0x76,(byte)0xF6,(byte)0x93,(byte)0x6B,(byte)0xA4,(byte)0x24,(byte)0x66,
 | 
			
		||||
(byte)0x3A,(byte)0xAB,(byte)0x63,(byte)0x9C,(byte)0x5A,(byte)0xE4,(byte)0xF5,(byte)0x68,
 | 
			
		||||
(byte)0x34,(byte)0x23,(byte)0xB4,(byte)0x74,(byte)0x2B,(byte)0xF1,(byte)0xC9,(byte)0x78,
 | 
			
		||||
(byte)0x23,(byte)0x8F,(byte)0x16,(byte)0xCB,(byte)0xE3,(byte)0x9D,(byte)0x65,(byte)0x2D,
 | 
			
		||||
(byte)0xE3,(byte)0xFD,(byte)0xB8,(byte)0xBE,(byte)0xFC,(byte)0x84,(byte)0x8A,(byte)0xD9,
 | 
			
		||||
(byte)0x22,(byte)0x22,(byte)0x2E,(byte)0x04,(byte)0xA4,(byte)0x03,(byte)0x7C,(byte)0x07,
 | 
			
		||||
(byte)0x13,(byte)0xEB,(byte)0x57,(byte)0xA8,(byte)0x1A,(byte)0x23,(byte)0xF0,(byte)0xC7,
 | 
			
		||||
(byte)0x34,(byte)0x73,(byte)0xFC,(byte)0x64,(byte)0x6C,(byte)0xEA,(byte)0x30,(byte)0x6B,
 | 
			
		||||
(byte)0x4B,(byte)0xCB,(byte)0xC8,(byte)0x86,(byte)0x2F,(byte)0x83,(byte)0x85,(byte)0xDD,
 | 
			
		||||
(byte)0xFA,(byte)0x9D,(byte)0x4B,(byte)0x7F,(byte)0xA2,(byte)0xC0,(byte)0x87,(byte)0xE8,
 | 
			
		||||
(byte)0x79,(byte)0x68,(byte)0x33,(byte)0x03,(byte)0xED,(byte)0x5B,(byte)0xDD,(byte)0x3A,
 | 
			
		||||
(byte)0x06,(byte)0x2B,(byte)0x3C,(byte)0xF5,(byte)0xB3,(byte)0xA2,(byte)0x78,(byte)0xA6,
 | 
			
		||||
(byte)0x6D,(byte)0x2A,(byte)0x13,(byte)0xF8,(byte)0x3F,(byte)0x44,(byte)0xF8,(byte)0x2D,
 | 
			
		||||
(byte)0xDF,(byte)0x31,(byte)0x0E,(byte)0xE0,(byte)0x74,(byte)0xAB,(byte)0x6A,(byte)0x36,
 | 
			
		||||
(byte)0x45,(byte)0x97,(byte)0xE8,(byte)0x99,(byte)0xA0,(byte)0x25,(byte)0x5D,(byte)0xC1,
 | 
			
		||||
(byte)0x64,(byte)0xF3,(byte)0x1C,(byte)0xC5,(byte)0x08,(byte)0x46,(byte)0x85,(byte)0x1D,
 | 
			
		||||
(byte)0xF9,(byte)0xAB,(byte)0x48,(byte)0x19,(byte)0x5D,(byte)0xED,(byte)0x7E,(byte)0xA1,
 | 
			
		||||
(byte)0xB1,(byte)0xD5,(byte)0x10,(byte)0xBD,(byte)0x7E,(byte)0xE7,(byte)0x4D,(byte)0x73,
 | 
			
		||||
(byte)0xFA,(byte)0xF3,(byte)0x6B,(byte)0xC3,(byte)0x1E,(byte)0xCF,(byte)0xA2,(byte)0x68,
 | 
			
		||||
(byte)0x35,(byte)0x90,(byte)0x46,(byte)0xF4,(byte)0xEB,(byte)0x87,(byte)0x9F,(byte)0x92,
 | 
			
		||||
(byte)0x40,(byte)0x09,(byte)0x43,(byte)0x8B,(byte)0x48,(byte)0x1C,(byte)0x6C,(byte)0xD7,
 | 
			
		||||
(byte)0x88,(byte)0x9A,(byte)0x00,(byte)0x2E,(byte)0xD5,(byte)0xEE,(byte)0x38,(byte)0x2B,
 | 
			
		||||
(byte)0xC9,(byte)0x19,(byte)0x0D,(byte)0xA6,(byte)0xFC,(byte)0x02,(byte)0x6E,(byte)0x47,
 | 
			
		||||
(byte)0x95,(byte)0x58,(byte)0xE4,(byte)0x47,(byte)0x56,(byte)0x77,(byte)0xE9,(byte)0xAA,
 | 
			
		||||
(byte)0x9E,(byte)0x30,(byte)0x50,(byte)0xE2,(byte)0x76,(byte)0x56,(byte)0x94,(byte)0xDF,
 | 
			
		||||
(byte)0xC8,(byte)0x1F,(byte)0x56,(byte)0xE8,(byte)0x80,(byte)0xB9,(byte)0x6E,(byte)0x71,
 | 
			
		||||
(byte)0x60,(byte)0xC9,(byte)0x80,(byte)0xDD,(byte)0x98,(byte)0xED,(byte)0xD3,(byte)0xDF,
 | 
			
		||||
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] G(){ return g; }
 | 
			
		||||
  @Override
 | 
			
		||||
  byte[] P(){ return p; }
 | 
			
		||||
  @Override
 | 
			
		||||
  String sha_name(){ return "sha-512"; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,237 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHGEX extends KeyExchange{
 | 
			
		||||
 | 
			
		||||
  private static final int SSH_MSG_KEX_DH_GEX_GROUP=               31;
 | 
			
		||||
  private static final int SSH_MSG_KEX_DH_GEX_INIT=                32;
 | 
			
		||||
  private static final int SSH_MSG_KEX_DH_GEX_REPLY=               33;
 | 
			
		||||
  private static final int SSH_MSG_KEX_DH_GEX_REQUEST=             34;
 | 
			
		||||
 | 
			
		||||
  int min;
 | 
			
		||||
  int preferred;
 | 
			
		||||
  int max;
 | 
			
		||||
 | 
			
		||||
  private int state;
 | 
			
		||||
 | 
			
		||||
  DH dh;
 | 
			
		||||
 | 
			
		||||
  byte[] V_S;
 | 
			
		||||
  byte[] V_C;
 | 
			
		||||
  byte[] I_S;
 | 
			
		||||
  byte[] I_C;
 | 
			
		||||
 | 
			
		||||
  private Buffer buf;
 | 
			
		||||
  private Packet packet;
 | 
			
		||||
 | 
			
		||||
  private byte[] p;
 | 
			
		||||
  private byte[] g;
 | 
			
		||||
  private byte[] e;
 | 
			
		||||
 | 
			
		||||
  protected String hash;
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void init(Session session,
 | 
			
		||||
                   byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
 | 
			
		||||
    this.V_S=V_S;      
 | 
			
		||||
    this.V_C=V_C;      
 | 
			
		||||
    this.I_S=I_S;      
 | 
			
		||||
    this.I_C=I_C;      
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(session.getConfig(hash)).asSubclass(HASH.class);
 | 
			
		||||
      sha=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      sha.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    buf=new Buffer();
 | 
			
		||||
    packet=new Packet(buf);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends DH> c=Class.forName(session.getConfig("dh")).asSubclass(DH.class);
 | 
			
		||||
      min=Integer.parseInt(session.getConfig("dhgex_min"));
 | 
			
		||||
      max=Integer.parseInt(session.getConfig("dhgex_max"));
 | 
			
		||||
      preferred=Integer.parseInt(session.getConfig("dhgex_preferred"));
 | 
			
		||||
      if(checkInvalidSize(min) || checkInvalidSize(max) || checkInvalidSize(preferred) || preferred < min || max < preferred){
 | 
			
		||||
        throw new JSchException("Invalid DHGEX sizes: min=" + min + " max=" + max + " preferred=" + preferred);
 | 
			
		||||
      }
 | 
			
		||||
      dh=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      dh.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)SSH_MSG_KEX_DH_GEX_REQUEST);
 | 
			
		||||
    buf.putInt(min);
 | 
			
		||||
    buf.putInt(preferred);
 | 
			
		||||
    buf.putInt(max);
 | 
			
		||||
    session.write(packet); 
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "SSH_MSG_KEX_DH_GEX_REQUEST("+min+"<"+preferred+"<"+max+") sent");
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "expecting SSH_MSG_KEX_DH_GEX_GROUP");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    state=SSH_MSG_KEX_DH_GEX_GROUP;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean next(Buffer _buf) throws Exception{
 | 
			
		||||
    int i,j;
 | 
			
		||||
    switch(state){
 | 
			
		||||
    case SSH_MSG_KEX_DH_GEX_GROUP:
 | 
			
		||||
      // byte  SSH_MSG_KEX_DH_GEX_GROUP(31)
 | 
			
		||||
      // mpint p, safe prime
 | 
			
		||||
      // mpint g, generator for subgroup in GF (p)
 | 
			
		||||
      _buf.getInt();
 | 
			
		||||
      _buf.getByte();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      if(j!=SSH_MSG_KEX_DH_GEX_GROUP){
 | 
			
		||||
        System.err.println("type: must be SSH_MSG_KEX_DH_GEX_GROUP "+j);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      p=_buf.getMPInt();
 | 
			
		||||
      g=_buf.getMPInt();
 | 
			
		||||
 | 
			
		||||
      dh.setP(p);
 | 
			
		||||
      dh.setG(g);
 | 
			
		||||
      // The client responds with:
 | 
			
		||||
      // byte  SSH_MSG_KEX_DH_GEX_INIT(32)
 | 
			
		||||
      // mpint e <- g^x mod p
 | 
			
		||||
      //         x is a random number (1 < x < (p-1)/2)
 | 
			
		||||
 | 
			
		||||
      e=dh.getE();
 | 
			
		||||
 | 
			
		||||
      packet.reset();
 | 
			
		||||
      buf.putByte((byte)SSH_MSG_KEX_DH_GEX_INIT);
 | 
			
		||||
      buf.putMPInt(e);
 | 
			
		||||
      session.write(packet);
 | 
			
		||||
 | 
			
		||||
      if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                             "SSH_MSG_KEX_DH_GEX_INIT sent");
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                             "expecting SSH_MSG_KEX_DH_GEX_REPLY");
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      state=SSH_MSG_KEX_DH_GEX_REPLY;
 | 
			
		||||
      return true;
 | 
			
		||||
      //break;
 | 
			
		||||
 | 
			
		||||
    case SSH_MSG_KEX_DH_GEX_REPLY:
 | 
			
		||||
      // The server responds with:
 | 
			
		||||
      // byte      SSH_MSG_KEX_DH_GEX_REPLY(33)
 | 
			
		||||
      // string    server public host key and certificates (K_S)
 | 
			
		||||
      // mpint     f
 | 
			
		||||
      // string    signature of H
 | 
			
		||||
      j=_buf.getInt();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      if(j!=SSH_MSG_KEX_DH_GEX_REPLY){
 | 
			
		||||
        System.err.println("type: must be SSH_MSG_KEX_DH_GEX_REPLY "+j);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      byte[] f=_buf.getMPInt();
 | 
			
		||||
      byte[] sig_of_H=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      dh.setF(f);
 | 
			
		||||
 | 
			
		||||
      dh.checkRange();
 | 
			
		||||
 | 
			
		||||
      K=normalize(dh.getK());
 | 
			
		||||
 | 
			
		||||
      //The hash H is computed as the HASH hash of the concatenation of the
 | 
			
		||||
      //following:
 | 
			
		||||
      // string    V_C, the client's version string (CR and NL excluded)
 | 
			
		||||
      // string    V_S, the server's version string (CR and NL excluded)
 | 
			
		||||
      // string    I_C, the payload of the client's SSH_MSG_KEXINIT
 | 
			
		||||
      // string    I_S, the payload of the server's SSH_MSG_KEXINIT
 | 
			
		||||
      // string    K_S, the host key
 | 
			
		||||
      // uint32    min, minimal size in bits of an acceptable group
 | 
			
		||||
      // uint32   n, preferred size in bits of the group the server should send
 | 
			
		||||
      // uint32    max, maximal size in bits of an acceptable group
 | 
			
		||||
      // mpint     p, safe prime
 | 
			
		||||
      // mpint     g, generator for subgroup
 | 
			
		||||
      // mpint     e, exchange value sent by the client
 | 
			
		||||
      // mpint     f, exchange value sent by the server
 | 
			
		||||
      // mpint     K, the shared secret
 | 
			
		||||
      // This value is called the exchange hash, and it is used to authenti-
 | 
			
		||||
      // cate the key exchange.
 | 
			
		||||
 | 
			
		||||
      buf.reset();
 | 
			
		||||
      buf.putString(V_C); buf.putString(V_S);
 | 
			
		||||
      buf.putString(I_C); buf.putString(I_S);
 | 
			
		||||
      buf.putString(K_S);
 | 
			
		||||
      buf.putInt(min); buf.putInt(preferred); buf.putInt(max);
 | 
			
		||||
      buf.putMPInt(p); buf.putMPInt(g); buf.putMPInt(e); buf.putMPInt(f);
 | 
			
		||||
      buf.putMPInt(K);
 | 
			
		||||
 | 
			
		||||
      byte[] foo=new byte[buf.getLength()];
 | 
			
		||||
      buf.getByte(foo);
 | 
			
		||||
      sha.update(foo, 0, foo.length);
 | 
			
		||||
 | 
			
		||||
      H=sha.digest();
 | 
			
		||||
 | 
			
		||||
      // System.err.print("H -> "); dump(H, 0, H.length);
 | 
			
		||||
 | 
			
		||||
      i=0;
 | 
			
		||||
      j=0;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      String alg=Util.byte2str(K_S, i, j);
 | 
			
		||||
      i+=j;
 | 
			
		||||
 | 
			
		||||
      boolean result = verify(alg, K_S, i, sig_of_H);
 | 
			
		||||
 | 
			
		||||
      state=STATE_END;
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getState(){return state; }
 | 
			
		||||
 | 
			
		||||
  static boolean checkInvalidSize(int size) {
 | 
			
		||||
    return (size < 1024 || size > 8192 || size % 1024 != 0);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHGEX1 extends DHGEX {
 | 
			
		||||
  DHGEX1(){
 | 
			
		||||
    hash="sha-1";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHGEX224 extends DHGEX {
 | 
			
		||||
  DHGEX224(){
 | 
			
		||||
    hash="sha-224";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHGEX256 extends DHGEX {
 | 
			
		||||
  DHGEX256(){
 | 
			
		||||
    hash="sha-256";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHGEX384 extends DHGEX {
 | 
			
		||||
  DHGEX384(){
 | 
			
		||||
    hash="sha-384";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class DHGEX512 extends DHGEX {
 | 
			
		||||
  DHGEX512(){
 | 
			
		||||
    hash="sha-512";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,184 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHGN extends KeyExchange{
 | 
			
		||||
 | 
			
		||||
  private static final int SSH_MSG_KEXDH_INIT=                     30;
 | 
			
		||||
  private static final int SSH_MSG_KEXDH_REPLY=                    31;
 | 
			
		||||
 | 
			
		||||
  private int state;
 | 
			
		||||
 | 
			
		||||
  DH dh;
 | 
			
		||||
 | 
			
		||||
  byte[] V_S;
 | 
			
		||||
  byte[] V_C;
 | 
			
		||||
  byte[] I_S;
 | 
			
		||||
  byte[] I_C;
 | 
			
		||||
 | 
			
		||||
  byte[] e;
 | 
			
		||||
 | 
			
		||||
  private Buffer buf;
 | 
			
		||||
  private Packet packet;
 | 
			
		||||
 | 
			
		||||
  abstract byte[] G();
 | 
			
		||||
  abstract byte[] P();
 | 
			
		||||
  abstract String sha_name();
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void init(Session session,
 | 
			
		||||
                   byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
 | 
			
		||||
    this.V_S=V_S;      
 | 
			
		||||
    this.V_C=V_C;      
 | 
			
		||||
    this.I_S=I_S;      
 | 
			
		||||
    this.I_C=I_C;      
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(session.getConfig(sha_name())).asSubclass(HASH.class);
 | 
			
		||||
      sha=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      sha.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    buf=new Buffer();
 | 
			
		||||
    packet=new Packet(buf);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends DH> c=Class.forName(session.getConfig("dh")).asSubclass(DH.class);
 | 
			
		||||
      dh=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      dh.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      //System.err.println(e);
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    dh.setP(P());
 | 
			
		||||
    dh.setG(G());
 | 
			
		||||
    // The client responds with:
 | 
			
		||||
    // byte  SSH_MSG_KEXDH_INIT(30)
 | 
			
		||||
    // mpint e <- g^x mod p
 | 
			
		||||
    //         x is a random number (1 < x < (p-1)/2)
 | 
			
		||||
 | 
			
		||||
    e=dh.getE();
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)SSH_MSG_KEXDH_INIT);
 | 
			
		||||
    buf.putMPInt(e);
 | 
			
		||||
 | 
			
		||||
    if(V_S==null){  // This is a really ugly hack for Session.checkKexes ;-(
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    session.write(packet);
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "SSH_MSG_KEXDH_INIT sent");
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "expecting SSH_MSG_KEXDH_REPLY");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    state=SSH_MSG_KEXDH_REPLY;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean next(Buffer _buf) throws Exception{
 | 
			
		||||
    int i,j;
 | 
			
		||||
 | 
			
		||||
    switch(state){
 | 
			
		||||
    case SSH_MSG_KEXDH_REPLY:
 | 
			
		||||
      // The server responds with:
 | 
			
		||||
      // byte      SSH_MSG_KEXDH_REPLY(31)
 | 
			
		||||
      // string    server public host key and certificates (K_S)
 | 
			
		||||
      // mpint     f
 | 
			
		||||
      // string    signature of H
 | 
			
		||||
      j=_buf.getInt();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      if(j!=31){
 | 
			
		||||
        System.err.println("type: must be 31 "+j);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      byte[] f=_buf.getMPInt();
 | 
			
		||||
      byte[] sig_of_H=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      dh.setF(f);
 | 
			
		||||
 | 
			
		||||
      dh.checkRange();
 | 
			
		||||
 | 
			
		||||
      K=normalize(dh.getK());
 | 
			
		||||
 | 
			
		||||
      //The hash H is computed as the HASH hash of the concatenation of the
 | 
			
		||||
      //following:
 | 
			
		||||
      // string    V_C, the client's version string (CR and NL excluded)
 | 
			
		||||
      // string    V_S, the server's version string (CR and NL excluded)
 | 
			
		||||
      // string    I_C, the payload of the client's SSH_MSG_KEXINIT
 | 
			
		||||
      // string    I_S, the payload of the server's SSH_MSG_KEXINIT
 | 
			
		||||
      // string    K_S, the host key
 | 
			
		||||
      // mpint     e, exchange value sent by the client
 | 
			
		||||
      // mpint     f, exchange value sent by the server
 | 
			
		||||
      // mpint     K, the shared secret
 | 
			
		||||
      // This value is called the exchange hash, and it is used to authenti-
 | 
			
		||||
      // cate the key exchange.
 | 
			
		||||
      buf.reset();
 | 
			
		||||
      buf.putString(V_C); buf.putString(V_S);
 | 
			
		||||
      buf.putString(I_C); buf.putString(I_S);
 | 
			
		||||
      buf.putString(K_S);
 | 
			
		||||
      buf.putMPInt(e); buf.putMPInt(f);
 | 
			
		||||
      buf.putMPInt(K);
 | 
			
		||||
      byte[] foo=new byte[buf.getLength()];
 | 
			
		||||
      buf.getByte(foo);
 | 
			
		||||
      sha.update(foo, 0, foo.length);
 | 
			
		||||
      H=sha.digest();
 | 
			
		||||
      //System.err.print("H -> "); //dump(H, 0, H.length);
 | 
			
		||||
 | 
			
		||||
      i=0;
 | 
			
		||||
      j=0;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      String alg=Util.byte2str(K_S, i, j);
 | 
			
		||||
      i+=j;
 | 
			
		||||
 | 
			
		||||
      boolean result = verify(alg, K_S, i, sig_of_H);
 | 
			
		||||
 | 
			
		||||
      state=STATE_END;
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getState(){return state; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,200 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
abstract class DHXEC extends KeyExchange{
 | 
			
		||||
 | 
			
		||||
  private static final int SSH_MSG_KEX_ECDH_INIT =                 30;
 | 
			
		||||
  private static final int SSH_MSG_KEX_ECDH_REPLY=                 31;
 | 
			
		||||
  private int state;
 | 
			
		||||
 | 
			
		||||
  byte[] Q_C;
 | 
			
		||||
 | 
			
		||||
  byte[] V_S;
 | 
			
		||||
  byte[] V_C;
 | 
			
		||||
  byte[] I_S;
 | 
			
		||||
  byte[] I_C;
 | 
			
		||||
 | 
			
		||||
  byte[] e;
 | 
			
		||||
 | 
			
		||||
  private Buffer buf;
 | 
			
		||||
  private Packet packet;
 | 
			
		||||
 | 
			
		||||
  private XDH xdh;
 | 
			
		||||
 | 
			
		||||
  protected String sha_name;
 | 
			
		||||
  protected String curve_name;
 | 
			
		||||
  protected int key_len;
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void init(Session session,
 | 
			
		||||
                   byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
 | 
			
		||||
    this.V_S=V_S;      
 | 
			
		||||
    this.V_C=V_C;      
 | 
			
		||||
    this.I_S=I_S;      
 | 
			
		||||
    this.I_C=I_C;      
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
 | 
			
		||||
      sha=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      sha.init();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){
 | 
			
		||||
      System.err.println(e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    buf=new Buffer();
 | 
			
		||||
    packet=new Packet(buf);
 | 
			
		||||
 | 
			
		||||
    packet.reset();
 | 
			
		||||
    buf.putByte((byte)SSH_MSG_KEX_ECDH_INIT);
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends XDH> c=Class.forName(session.getConfig("xdh")).asSubclass(XDH.class);
 | 
			
		||||
      xdh=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
      xdh.init(curve_name, key_len);
 | 
			
		||||
 | 
			
		||||
      Q_C = xdh.getQ();
 | 
			
		||||
      buf.putString(Q_C);
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception | NoClassDefFoundError e){
 | 
			
		||||
      throw new JSchException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(V_S==null){  // This is a really ugly hack for Session.checkKexes ;-(
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    session.write(packet);
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "SSH_MSG_KEX_ECDH_INIT sent");
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "expecting SSH_MSG_KEX_ECDH_REPLY");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    state=SSH_MSG_KEX_ECDH_REPLY;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean next(Buffer _buf) throws Exception{
 | 
			
		||||
    int i,j;
 | 
			
		||||
    switch(state){
 | 
			
		||||
    case SSH_MSG_KEX_ECDH_REPLY:
 | 
			
		||||
      // The server responds with:
 | 
			
		||||
      // byte     SSH_MSG_KEX_ECDH_REPLY
 | 
			
		||||
      // string   K_S, server's public host key
 | 
			
		||||
      // string   Q_S, server's ephemeral public key octet string
 | 
			
		||||
      // string   the signature on the exchange hash
 | 
			
		||||
      j=_buf.getInt();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      j=_buf.getByte();
 | 
			
		||||
      if(j!=SSH_MSG_KEX_ECDH_REPLY){
 | 
			
		||||
        System.err.println("type: must be SSH_MSG_KEX_ECDH_REPLY "+j);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      byte[] Q_S=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      // RFC 5656,
 | 
			
		||||
      // 4. ECDH Key Exchange
 | 
			
		||||
      //   All elliptic curve public keys MUST be validated after they are
 | 
			
		||||
      //   received.  An example of a validation algorithm can be found in
 | 
			
		||||
      //   Section 3.2.2 of [SEC1].  If a key fails validation,
 | 
			
		||||
      //   the key exchange MUST fail.
 | 
			
		||||
      if(!xdh.validate(Q_S)){
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      K = xdh.getSecret(Q_S);
 | 
			
		||||
      K=normalize(K);
 | 
			
		||||
 | 
			
		||||
      byte[] sig_of_H=_buf.getString();
 | 
			
		||||
 | 
			
		||||
      //The hash H is computed as the HASH hash of the concatenation of the
 | 
			
		||||
      //following:
 | 
			
		||||
      // string   V_C, client's identification string (CR and LF excluded)
 | 
			
		||||
      // string   V_S, server's identification string (CR and LF excluded)
 | 
			
		||||
      // string   I_C, payload of the client's SSH_MSG_KEXINIT
 | 
			
		||||
      // string   I_S, payload of the server's SSH_MSG_KEXINIT
 | 
			
		||||
      // string   K_S, server's public host key
 | 
			
		||||
      // string   Q_C, client's ephemeral public key octet string
 | 
			
		||||
      // string   Q_S, server's ephemeral public key octet string
 | 
			
		||||
      // mpint    K,   shared secret
 | 
			
		||||
 | 
			
		||||
      // This value is called the exchange hash, and it is used to authenti-
 | 
			
		||||
      // cate the key exchange.
 | 
			
		||||
      // RFC 8731,
 | 
			
		||||
      // 3.1. Shared Secret Encoding
 | 
			
		||||
      //   The shared secret, K, is defined in [RFC4253] and [RFC5656] as an
 | 
			
		||||
      //   integer encoded as a multiple precision integer (mpint).
 | 
			
		||||
      //   Curve25519/448 outputs a binary string X, which is the 32- or 56-byte
 | 
			
		||||
      //   point obtained by scalar multiplication of the other side's public
 | 
			
		||||
      //   key and the local private key scalar.  The 32 or 56 bytes of X are
 | 
			
		||||
      //   converted into K by interpreting the octets as an unsigned fixed-
 | 
			
		||||
      //   length integer encoded in network byte order.
 | 
			
		||||
      //
 | 
			
		||||
      //   The mpint K is then encoded using the process described in Section 5
 | 
			
		||||
      //   of [RFC4251], and the resulting bytes are fed as described in
 | 
			
		||||
      //   [RFC4253] to the key exchange method's hash function to generate
 | 
			
		||||
      //   encryption keys.
 | 
			
		||||
      buf.reset();
 | 
			
		||||
      buf.putString(V_C); buf.putString(V_S);
 | 
			
		||||
      buf.putString(I_C); buf.putString(I_S);
 | 
			
		||||
      buf.putString(K_S);
 | 
			
		||||
      buf.putString(Q_C); buf.putString(Q_S);
 | 
			
		||||
      buf.putMPInt(K);
 | 
			
		||||
      byte[] foo=new byte[buf.getLength()];
 | 
			
		||||
      buf.getByte(foo);
 | 
			
		||||
 | 
			
		||||
      sha.update(foo, 0, foo.length);
 | 
			
		||||
      H=sha.digest();
 | 
			
		||||
 | 
			
		||||
      i=0;
 | 
			
		||||
      j=0;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      String alg=Util.byte2str(K_S, i, j);
 | 
			
		||||
      i+=j;
 | 
			
		||||
 | 
			
		||||
      boolean result = verify(alg, K_S, i, sig_of_H);
 | 
			
		||||
 | 
			
		||||
      state=STATE_END;
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getState(){return state; }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2015-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface ECDH {
 | 
			
		||||
  void init(int size) throws Exception;
 | 
			
		||||
  byte[] getSecret(byte[] r, byte[] s) throws Exception;
 | 
			
		||||
  byte[] getQ() throws Exception;
 | 
			
		||||
  boolean validate(byte[] r, byte[] s) throws Exception;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
public interface ForwardedTCPIPDaemon extends Runnable{
 | 
			
		||||
  void setChannel(ChannelForwardedTCPIP channel, InputStream in, OutputStream out);
 | 
			
		||||
  void setArg(Object[] arg);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2004-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface GSSContext{
 | 
			
		||||
  public void create(String user, String host) throws JSchException;
 | 
			
		||||
  public boolean isEstablished();
 | 
			
		||||
  public byte[] init(byte[] token, int s, int l) throws JSchException;
 | 
			
		||||
  public byte[] getMIC(byte[] message, int s, int l);
 | 
			
		||||
  public void dispose();
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface HASH{
 | 
			
		||||
  void init() throws Exception;
 | 
			
		||||
  int getBlockSize();
 | 
			
		||||
  void update(byte[] foo, int start, int len) throws Exception;
 | 
			
		||||
  byte[] digest() throws Exception;
 | 
			
		||||
  default String name() {return "";}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,150 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public class HostKey{
 | 
			
		||||
 | 
			
		||||
  private static final byte[][] names = {
 | 
			
		||||
    Util.str2byte("ssh-dss"),
 | 
			
		||||
    Util.str2byte("ssh-rsa"),
 | 
			
		||||
    Util.str2byte("ecdsa-sha2-nistp256"),
 | 
			
		||||
    Util.str2byte("ecdsa-sha2-nistp384"),
 | 
			
		||||
    Util.str2byte("ecdsa-sha2-nistp521"),
 | 
			
		||||
    Util.str2byte("ssh-ed25519"),
 | 
			
		||||
    Util.str2byte("ssh-ed448")
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  public static final int UNKNOWN=-1;
 | 
			
		||||
  public static final int GUESS=0;
 | 
			
		||||
  public static final int SSHDSS=1;
 | 
			
		||||
  public static final int SSHRSA=2;
 | 
			
		||||
  public static final int ECDSA256=3;
 | 
			
		||||
  public static final int ECDSA384=4;
 | 
			
		||||
  public static final int ECDSA521=5;
 | 
			
		||||
  public static final int ED25519=6;
 | 
			
		||||
  public static final int ED448=7;
 | 
			
		||||
 | 
			
		||||
  protected String marker;
 | 
			
		||||
  protected String host;
 | 
			
		||||
  protected int type;
 | 
			
		||||
  protected byte[] key;
 | 
			
		||||
  protected String comment;
 | 
			
		||||
 | 
			
		||||
  public HostKey(String host, byte[] key) throws JSchException {
 | 
			
		||||
    this(host, GUESS, key);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public HostKey(String host, int type, byte[] key) throws JSchException {
 | 
			
		||||
    this(host, type, key, null);
 | 
			
		||||
  }
 | 
			
		||||
  public HostKey(String host, int type, byte[] key, String comment) throws JSchException {
 | 
			
		||||
    this("", host, type, key, comment);
 | 
			
		||||
  }
 | 
			
		||||
  public HostKey(String marker, String host, int type, byte[] key, String comment) throws JSchException {
 | 
			
		||||
    this.marker=marker;
 | 
			
		||||
    this.host=host; 
 | 
			
		||||
    if(type==GUESS){
 | 
			
		||||
      if(key[8]=='d'){ this.type=SSHDSS; }
 | 
			
		||||
      else if(key[8]=='r'){ this.type=SSHRSA; }
 | 
			
		||||
      else if(key[8]=='e' && key[10]=='2'){ this.type=ED25519; }
 | 
			
		||||
      else if(key[8]=='e' && key[10]=='4'){ this.type=ED448; }
 | 
			
		||||
      else if(key[8]=='a' && key[20]=='2'){ this.type=ECDSA256; }
 | 
			
		||||
      else if(key[8]=='a' && key[20]=='3'){ this.type=ECDSA384; }
 | 
			
		||||
      else if(key[8]=='a' && key[20]=='5'){ this.type=ECDSA521; }
 | 
			
		||||
      else { throw new JSchException("invalid key type");}
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      this.type=type; 
 | 
			
		||||
    }
 | 
			
		||||
    this.key=key;
 | 
			
		||||
    this.comment=comment;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getHost(){ return host; }
 | 
			
		||||
  public String getType(){
 | 
			
		||||
    if(type==SSHDSS ||
 | 
			
		||||
       type==SSHRSA ||
 | 
			
		||||
       type==ED25519 ||
 | 
			
		||||
       type==ED448 ||
 | 
			
		||||
       type==ECDSA256 ||
 | 
			
		||||
       type==ECDSA384 ||
 | 
			
		||||
       type==ECDSA521){
 | 
			
		||||
      return Util.byte2str(names[type-1]);
 | 
			
		||||
    }
 | 
			
		||||
    return "UNKNOWN";
 | 
			
		||||
  }
 | 
			
		||||
  protected static int name2type(String name){
 | 
			
		||||
    for(int i = 0; i < names.length; i++){
 | 
			
		||||
      if(Util.byte2str(names[i]).equals(name)){
 | 
			
		||||
        return i + 1;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return UNKNOWN;
 | 
			
		||||
  }
 | 
			
		||||
  public String getKey(){
 | 
			
		||||
    return Util.byte2str(Util.toBase64(key, 0, key.length, true));
 | 
			
		||||
  }
 | 
			
		||||
  public String getFingerPrint(JSch jsch){
 | 
			
		||||
    HASH hash=null;
 | 
			
		||||
    try{
 | 
			
		||||
      String _c=JSch.getConfig("FingerprintHash").toLowerCase();
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(JSch.getConfig(_c)).asSubclass(HASH.class);
 | 
			
		||||
      hash=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){ System.err.println("getFingerPrint: "+e); }
 | 
			
		||||
    return Util.getFingerPrint(hash, key, false, true);
 | 
			
		||||
  }
 | 
			
		||||
  public String getComment(){ return comment; }
 | 
			
		||||
  public String getMarker(){ return marker; }
 | 
			
		||||
 | 
			
		||||
  boolean isMatched(String _host){
 | 
			
		||||
    return isIncluded(_host);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean isIncluded(String _host){
 | 
			
		||||
    int i=0;
 | 
			
		||||
    String hosts=this.host; 
 | 
			
		||||
    int hostslen=hosts.length();
 | 
			
		||||
    int hostlen=_host.length();
 | 
			
		||||
    int j;
 | 
			
		||||
    while(i<hostslen){
 | 
			
		||||
      j=hosts.indexOf(',', i);
 | 
			
		||||
      if(j==-1){
 | 
			
		||||
       if(hostlen!=hostslen-i) return false;
 | 
			
		||||
       return hosts.regionMatches(true, i, _host, 0, hostlen);
 | 
			
		||||
      }
 | 
			
		||||
      if(hostlen==(j-i)){
 | 
			
		||||
        if(hosts.regionMatches(true, i, _host, 0, hostlen)) return true;
 | 
			
		||||
      }
 | 
			
		||||
      i=j+1;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,94 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2004-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface HostKeyRepository{
 | 
			
		||||
  final int OK=0;
 | 
			
		||||
  final int NOT_INCLUDED=1;
 | 
			
		||||
  final int CHANGED=2;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Checks if <code>host</code> is included with the <code>key</code>. 
 | 
			
		||||
   * 
 | 
			
		||||
   * @return #NOT_INCLUDED, #OK or #CHANGED
 | 
			
		||||
   * @see #NOT_INCLUDED
 | 
			
		||||
   * @see #OK
 | 
			
		||||
   * @see #CHANGED
 | 
			
		||||
   */
 | 
			
		||||
  int check(String host, byte[] key);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Adds a host key <code>hostkey</code>
 | 
			
		||||
   *
 | 
			
		||||
   * @param hostkey a host key to be added
 | 
			
		||||
   * @param ui a user interface for showing messages or promping inputs.
 | 
			
		||||
   * @see UserInfo
 | 
			
		||||
   */
 | 
			
		||||
  void add(HostKey hostkey, UserInfo ui);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Removes a host key if there exists mached key with
 | 
			
		||||
   * <code>host</code>, <code>type</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #remove(String host, String type, byte[] key)
 | 
			
		||||
   */
 | 
			
		||||
  void remove(String host, String type);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Removes a host key if there exists a matched key with
 | 
			
		||||
   * <code>host</code>, <code>type</code> and <code>key</code>.
 | 
			
		||||
   */
 | 
			
		||||
  void remove(String host, String type, byte[] key);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns id of this repository.
 | 
			
		||||
   *
 | 
			
		||||
   * @return identity in String
 | 
			
		||||
   */
 | 
			
		||||
  String getKnownHostsRepositoryID();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Retuns a list for host keys managed in this repository.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #getHostKey(String host, String type)
 | 
			
		||||
   */
 | 
			
		||||
  HostKey[] getHostKey();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Retuns a list for host keys managed in this repository.
 | 
			
		||||
   *
 | 
			
		||||
   * @param host a hostname used in searching host keys.
 | 
			
		||||
   *        If <code>null</code> is given, every host key will be listed.
 | 
			
		||||
   * @param type a key type used in searching host keys,
 | 
			
		||||
   *        and it should be "ssh-dss" or "ssh-rsa".
 | 
			
		||||
   *        If <code>null</code> is given, a key type type will not be ignored.
 | 
			
		||||
   */
 | 
			
		||||
  HostKey[] getHostKey(String host, String type);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,133 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.net.SocketException;
 | 
			
		||||
 | 
			
		||||
class IO{
 | 
			
		||||
  InputStream in;
 | 
			
		||||
  OutputStream out;
 | 
			
		||||
  OutputStream out_ext;
 | 
			
		||||
 | 
			
		||||
  private boolean in_dontclose=false;
 | 
			
		||||
  private boolean out_dontclose=false;
 | 
			
		||||
  private boolean out_ext_dontclose=false;
 | 
			
		||||
 | 
			
		||||
  void setOutputStream(OutputStream out){ this.out=out; }
 | 
			
		||||
  void setOutputStream(OutputStream out, boolean dontclose){
 | 
			
		||||
    this.out_dontclose=dontclose;
 | 
			
		||||
    setOutputStream(out);
 | 
			
		||||
  }
 | 
			
		||||
  void setExtOutputStream(OutputStream out){ this.out_ext=out; }
 | 
			
		||||
  void setExtOutputStream(OutputStream out, boolean dontclose){
 | 
			
		||||
    this.out_ext_dontclose=dontclose;
 | 
			
		||||
    setExtOutputStream(out);
 | 
			
		||||
  }
 | 
			
		||||
  void setInputStream(InputStream in){ this.in=in; }
 | 
			
		||||
  void setInputStream(InputStream in, boolean dontclose){
 | 
			
		||||
    this.in_dontclose=dontclose;
 | 
			
		||||
    setInputStream(in);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void put(Packet p) throws IOException, SocketException {
 | 
			
		||||
    out.write(p.buffer.buffer, 0, p.buffer.index);
 | 
			
		||||
    out.flush();
 | 
			
		||||
  }
 | 
			
		||||
  void put(byte[] array, int begin, int length) throws IOException {
 | 
			
		||||
    out.write(array, begin, length);
 | 
			
		||||
    out.flush();
 | 
			
		||||
  }
 | 
			
		||||
  void put_ext(byte[] array, int begin, int length) throws IOException {
 | 
			
		||||
    out_ext.write(array, begin, length);
 | 
			
		||||
    out_ext.flush();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int getByte() throws IOException {
 | 
			
		||||
    return in.read();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void getByte(byte[] array) throws IOException {
 | 
			
		||||
    getByte(array, 0, array.length);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void getByte(byte[] array, int begin, int length) throws IOException {
 | 
			
		||||
    do{
 | 
			
		||||
      int completed = in.read(array, begin, length);
 | 
			
		||||
      if(completed<0){
 | 
			
		||||
        throw new IOException("End of IO Stream Read");
 | 
			
		||||
      }
 | 
			
		||||
      begin+=completed;
 | 
			
		||||
      length-=completed;
 | 
			
		||||
    }
 | 
			
		||||
    while (length>0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void out_close(){
 | 
			
		||||
    try{
 | 
			
		||||
      if(out!=null && !out_dontclose) out.close();
 | 
			
		||||
      out=null;
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void close(){
 | 
			
		||||
    try{
 | 
			
		||||
      if(in!=null && !in_dontclose) in.close();
 | 
			
		||||
      in=null;
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
 | 
			
		||||
    out_close();
 | 
			
		||||
 | 
			
		||||
    try{
 | 
			
		||||
      if(out_ext!=null && !out_ext_dontclose) out_ext.close();
 | 
			
		||||
      out_ext=null;
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
  void finalize() throws Throwable{
 | 
			
		||||
    try{
 | 
			
		||||
      if(in!=null) in.close();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
    try{
 | 
			
		||||
      if(out!=null) out.close();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
    try{
 | 
			
		||||
      if(out_ext!=null) out_ext.close();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception ee){}
 | 
			
		||||
  }
 | 
			
		||||
  */
 | 
			
		||||
}
 | 
			
		||||
@@ -1,117 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public interface Identity{
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Decrypts this identity with the specified pass-phrase.
 | 
			
		||||
   * @param passphrase the pass-phrase for this identity.
 | 
			
		||||
   * @return <code>true</code> if the decryption is succeeded
 | 
			
		||||
   * or this identity is not cyphered.
 | 
			
		||||
   */
 | 
			
		||||
  public boolean setPassphrase(byte[] passphrase) throws JSchException;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the public-key blob.
 | 
			
		||||
   * @return the public-key blob
 | 
			
		||||
   */
 | 
			
		||||
  public byte[] getPublicKeyBlob();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Signs on data with this identity, and returns the result.
 | 
			
		||||
   * <p>
 | 
			
		||||
   * <em>IMPORTANT NOTE:</em>
 | 
			
		||||
   * <br>
 | 
			
		||||
   * The {@link #getSignature(byte[], String)} method should be overridden
 | 
			
		||||
   * to ensure {@code ssh-rsa} type public keys function with the
 | 
			
		||||
   * {@code rsa-sha2-256} or {@code rsa-sha2-512} signature algorithms.
 | 
			
		||||
   * </p>
 | 
			
		||||
   * @param data data to be signed
 | 
			
		||||
   * @return the signature
 | 
			
		||||
   * @see #getSignature(byte[], String)
 | 
			
		||||
   */
 | 
			
		||||
  public byte[] getSignature(byte[] data);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Signs on data with this identity, and returns the result.
 | 
			
		||||
   * <p>
 | 
			
		||||
   * <em>IMPORTANT NOTE:</em>
 | 
			
		||||
   * <br>
 | 
			
		||||
   * The default implementation of this method simply calls
 | 
			
		||||
   * {@link #getSignature(byte[])}, which will fail with {@code ssh-rsa}
 | 
			
		||||
   * type public keys when utilized with the {@code rsa-sha2-256} or
 | 
			
		||||
   * {@code rsa-sha2-512} signature algorithms:
 | 
			
		||||
   * <br>
 | 
			
		||||
   * it exists only to maintain backwards compatibility of this interface.
 | 
			
		||||
   * </p>
 | 
			
		||||
   * <p>
 | 
			
		||||
   * This default method should be overridden by implementations to
 | 
			
		||||
   * ensure the {@code rsa-sha2-256} and {@code rsa-sha2-512} signature
 | 
			
		||||
   * algorithms function correctly.
 | 
			
		||||
   * </p>
 | 
			
		||||
   * @param data data to be signed
 | 
			
		||||
   * @param alg signature algorithm to use
 | 
			
		||||
   * @return the signature
 | 
			
		||||
   * @since 0.1.57
 | 
			
		||||
   * @see #getSignature(byte[])
 | 
			
		||||
   */
 | 
			
		||||
  public default byte[] getSignature(byte[] data, String alg) {return getSignature(data);}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @deprecated The decryption should be done automatically in {@link #setPassphrase(byte[])}
 | 
			
		||||
   * @see #setPassphrase(byte[])
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated
 | 
			
		||||
  public boolean decrypt();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the name of the key algorithm.
 | 
			
		||||
   * @return "ssh-rsa" or "ssh-dss"
 | 
			
		||||
   */
 | 
			
		||||
  public String getAlgName();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the name of this identity. 
 | 
			
		||||
   * It will be useful to identify this object in the {@link IdentityRepository}.
 | 
			
		||||
   */
 | 
			
		||||
  public String getName();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns <code>true</code> if this identity is cyphered.
 | 
			
		||||
   * @return <code>true</code> if this identity is cyphered.
 | 
			
		||||
   */
 | 
			
		||||
  public boolean isEncrypted();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Disposes internally allocated data, like byte array for the private key.
 | 
			
		||||
   */
 | 
			
		||||
  public void clear();
 | 
			
		||||
}
 | 
			
		||||
@@ -1,151 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
class IdentityFile implements Identity{
 | 
			
		||||
  private JSch jsch;
 | 
			
		||||
  private KeyPair kpair;
 | 
			
		||||
  private String identity;
 | 
			
		||||
 | 
			
		||||
  static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException{
 | 
			
		||||
    KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile);
 | 
			
		||||
    return new IdentityFile(jsch, prvfile, kpair);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{
 | 
			
		||||
 | 
			
		||||
    KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey);
 | 
			
		||||
    return new IdentityFile(jsch, name, kpair);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private IdentityFile(JSch jsch, String name, KeyPair kpair) throws JSchException{
 | 
			
		||||
    this.jsch = jsch;
 | 
			
		||||
    this.identity = name;
 | 
			
		||||
    this.kpair = kpair;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Decrypts this identity with the specified pass-phrase.
 | 
			
		||||
   * @param passphrase the pass-phrase for this identity.
 | 
			
		||||
   * @return <code>true</code> if the decryption is succeeded
 | 
			
		||||
   * or this identity is not cyphered.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean setPassphrase(byte[] passphrase) throws JSchException{
 | 
			
		||||
    return kpair.decrypt(passphrase);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the public-key blob.
 | 
			
		||||
   * @return the public-key blob
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getPublicKeyBlob(){
 | 
			
		||||
    return kpair.getPublicKeyBlob();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Signs on data with this identity, and returns the result.
 | 
			
		||||
   * @param data data to be signed
 | 
			
		||||
   * @return the signature
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getSignature(byte[] data){
 | 
			
		||||
    return kpair.getSignature(data);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Signs on data with this identity, and returns the result.
 | 
			
		||||
   * @param data data to be signed
 | 
			
		||||
   * @param alg signature algorithm to use
 | 
			
		||||
   * @return the signature
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public byte[] getSignature(byte[] data, String alg){
 | 
			
		||||
    return kpair.getSignature(data, alg);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @deprecated This method should not be invoked.
 | 
			
		||||
   * @see #setPassphrase(byte[] passphrase)
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  @Deprecated
 | 
			
		||||
  public boolean decrypt(){
 | 
			
		||||
    throw new RuntimeException("not implemented");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the name of the key algorithm.
 | 
			
		||||
   * @return "ssh-rsa" or "ssh-dss"
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getAlgName(){
 | 
			
		||||
    byte[] name = kpair.getKeyTypeName();
 | 
			
		||||
    return Util.byte2str(name);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the name of this identity. 
 | 
			
		||||
   * It will be useful to identify this object in the {@link IdentityRepository}.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getName(){
 | 
			
		||||
    return identity;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns <code>true</code> if this identity is cyphered.
 | 
			
		||||
   * @return <code>true</code> if this identity is cyphered.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isEncrypted(){
 | 
			
		||||
    return kpair.isEncrypted();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Disposes internally allocated data, like byte array for the private key.
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public void clear(){
 | 
			
		||||
    kpair.dispose();
 | 
			
		||||
    kpair = null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns an instance of {@link KeyPair} used in this {@link Identity}.
 | 
			
		||||
   * @return an instance of {@link KeyPair} used in this {@link Identity}.
 | 
			
		||||
   */
 | 
			
		||||
  public KeyPair getKeyPair(){
 | 
			
		||||
    return kpair;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,44 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2012-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public interface IdentityRepository {
 | 
			
		||||
  public static final int UNAVAILABLE=0;
 | 
			
		||||
  public static final int NOTRUNNING=1;
 | 
			
		||||
  public static final int RUNNING=2;
 | 
			
		||||
  public String getName();
 | 
			
		||||
  public int getStatus();
 | 
			
		||||
  public Vector<Identity> getIdentities();
 | 
			
		||||
  public boolean add(byte[] identity);
 | 
			
		||||
  public boolean remove(byte[] blob);
 | 
			
		||||
  public void removeAll();
 | 
			
		||||
}
 | 
			
		||||
@@ -1,109 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2012-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * JSch will accept ciphered keys, but some implementations of
 | 
			
		||||
 * IdentityRepository can not.  For example, IdentityRepository for
 | 
			
		||||
 * ssh-agent and pageant only accept plain keys.  The following class has
 | 
			
		||||
 * been introduced to cache ciphered keys for them, and pass them
 | 
			
		||||
 * whenever they are de-ciphered.
 | 
			
		||||
 */
 | 
			
		||||
class IdentityRepositoryWrapper implements IdentityRepository {
 | 
			
		||||
  private IdentityRepository ir;
 | 
			
		||||
  private Vector<Identity> cache = new Vector<>();
 | 
			
		||||
  private boolean keep_in_cache = false;
 | 
			
		||||
  IdentityRepositoryWrapper(IdentityRepository ir){
 | 
			
		||||
    this(ir, false);
 | 
			
		||||
  }
 | 
			
		||||
  IdentityRepositoryWrapper(IdentityRepository ir, boolean keep_in_cache){
 | 
			
		||||
    this.ir = ir;
 | 
			
		||||
    this.keep_in_cache = keep_in_cache;
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getName() {
 | 
			
		||||
    return ir.getName();
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public int getStatus() {
 | 
			
		||||
    return ir.getStatus();
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean add(byte[] identity) {
 | 
			
		||||
    return ir.add(identity);
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean remove(byte[] blob) {
 | 
			
		||||
    return ir.remove(blob);
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public void removeAll() {
 | 
			
		||||
    cache.removeAllElements();
 | 
			
		||||
    ir.removeAll();
 | 
			
		||||
  }
 | 
			
		||||
  @Override
 | 
			
		||||
  public Vector<Identity> getIdentities() {
 | 
			
		||||
    Vector<Identity> result = new Vector<>();
 | 
			
		||||
    for(int i = 0; i< cache.size(); i++){
 | 
			
		||||
      Identity identity = cache.elementAt(i);
 | 
			
		||||
      result.add(identity);
 | 
			
		||||
    }
 | 
			
		||||
    Vector<Identity> tmp = ir.getIdentities();
 | 
			
		||||
    for(int i = 0; i< tmp.size(); i++){
 | 
			
		||||
      result.add(tmp.elementAt(i));
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
  void add(Identity identity) {
 | 
			
		||||
    if(!keep_in_cache && 
 | 
			
		||||
       !identity.isEncrypted() && (identity instanceof IdentityFile)) {
 | 
			
		||||
      try {
 | 
			
		||||
        ir.add(((IdentityFile)identity).getKeyPair().forSSHAgent());
 | 
			
		||||
      }
 | 
			
		||||
      catch(JSchException e){
 | 
			
		||||
        // an exception will not be thrown.
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      cache.addElement(identity);
 | 
			
		||||
  }
 | 
			
		||||
  void check() {
 | 
			
		||||
    if(cache.size() > 0){
 | 
			
		||||
      Object[] identities = cache.toArray();
 | 
			
		||||
      for(int i = 0; i < identities.length; i++){
 | 
			
		||||
        Identity identity = (Identity)(identities[i]);
 | 
			
		||||
        cache.removeElement(identity);
 | 
			
		||||
        add(identity);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,716 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.util.Enumeration;
 | 
			
		||||
import java.util.Hashtable;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public class JSch{
 | 
			
		||||
  /**
 | 
			
		||||
   * The version number.
 | 
			
		||||
   */
 | 
			
		||||
  public static final String VERSION  = Version.getVersion();
 | 
			
		||||
 | 
			
		||||
  static Hashtable<String, String> config=new Hashtable<>();
 | 
			
		||||
  static{
 | 
			
		||||
    config.put("kex", Util.getSystemProperty("jsch.kex", "curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256"));
 | 
			
		||||
    config.put("server_host_key", Util.getSystemProperty("jsch.server_host_key", "ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256"));
 | 
			
		||||
    config.put("prefer_known_host_key_types", Util.getSystemProperty("jsch.prefer_known_host_key_types", "yes"));
 | 
			
		||||
    config.put("enable_server_sig_algs", Util.getSystemProperty("jsch.enable_server_sig_algs", "yes"));
 | 
			
		||||
    config.put("cipher.s2c", Util.getSystemProperty("jsch.cipher", "aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com"));
 | 
			
		||||
    config.put("cipher.c2s", Util.getSystemProperty("jsch.cipher", "aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com"));
 | 
			
		||||
    config.put("mac.s2c", Util.getSystemProperty("jsch.mac", "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1"));
 | 
			
		||||
    config.put("mac.c2s", Util.getSystemProperty("jsch.mac", "hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1"));
 | 
			
		||||
    config.put("compression.s2c", Util.getSystemProperty("jsch.compression", "none"));
 | 
			
		||||
    config.put("compression.c2s", Util.getSystemProperty("jsch.compression", "none"));
 | 
			
		||||
 | 
			
		||||
    config.put("lang.s2c", Util.getSystemProperty("jsch.lang", ""));
 | 
			
		||||
    config.put("lang.c2s", Util.getSystemProperty("jsch.lang", ""));
 | 
			
		||||
 | 
			
		||||
    config.put("dhgex_min", Util.getSystemProperty("jsch.dhgex_min", "2048"));
 | 
			
		||||
    config.put("dhgex_max", Util.getSystemProperty("jsch.dhgex_max", "8192"));
 | 
			
		||||
    config.put("dhgex_preferred", Util.getSystemProperty("jsch.dhgex_preferred", "3072"));
 | 
			
		||||
 | 
			
		||||
    config.put("compression_level", Util.getSystemProperty("jsch.compression_level", "6"));
 | 
			
		||||
 | 
			
		||||
    config.put("diffie-hellman-group-exchange-sha1", 
 | 
			
		||||
                                "com.jcraft.jsch.DHGEX1");
 | 
			
		||||
    config.put("diffie-hellman-group1-sha1", 
 | 
			
		||||
                                "com.jcraft.jsch.DHG1");
 | 
			
		||||
    config.put("diffie-hellman-group14-sha1", 
 | 
			
		||||
               "com.jcraft.jsch.DHG14");
 | 
			
		||||
    config.put("diffie-hellman-group-exchange-sha256", 
 | 
			
		||||
               "com.jcraft.jsch.DHGEX256");
 | 
			
		||||
    config.put("diffie-hellman-group-exchange-sha224@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHGEX224");
 | 
			
		||||
    config.put("diffie-hellman-group-exchange-sha384@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHGEX384");
 | 
			
		||||
    config.put("diffie-hellman-group-exchange-sha512@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHGEX512");
 | 
			
		||||
    config.put("diffie-hellman-group14-sha256", 
 | 
			
		||||
               "com.jcraft.jsch.DHG14256");
 | 
			
		||||
    config.put("diffie-hellman-group15-sha512", 
 | 
			
		||||
               "com.jcraft.jsch.DHG15");
 | 
			
		||||
    config.put("diffie-hellman-group16-sha512", 
 | 
			
		||||
               "com.jcraft.jsch.DHG16");
 | 
			
		||||
    config.put("diffie-hellman-group17-sha512", 
 | 
			
		||||
               "com.jcraft.jsch.DHG17");
 | 
			
		||||
    config.put("diffie-hellman-group18-sha512", 
 | 
			
		||||
               "com.jcraft.jsch.DHG18");
 | 
			
		||||
    config.put("diffie-hellman-group14-sha256@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG14256");
 | 
			
		||||
    config.put("diffie-hellman-group14-sha224@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG14224");
 | 
			
		||||
    config.put("diffie-hellman-group15-sha256@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG15256");
 | 
			
		||||
    config.put("diffie-hellman-group15-sha384@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG15384");
 | 
			
		||||
    config.put("diffie-hellman-group16-sha512@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG16");
 | 
			
		||||
    config.put("diffie-hellman-group16-sha384@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG16384");
 | 
			
		||||
    config.put("diffie-hellman-group18-sha512@ssh.com", 
 | 
			
		||||
               "com.jcraft.jsch.DHG18");
 | 
			
		||||
    config.put("ecdsa-sha2-nistp256", "com.jcraft.jsch.jce.SignatureECDSA256");
 | 
			
		||||
    config.put("ecdsa-sha2-nistp384", "com.jcraft.jsch.jce.SignatureECDSA384");
 | 
			
		||||
    config.put("ecdsa-sha2-nistp521", "com.jcraft.jsch.jce.SignatureECDSA521");
 | 
			
		||||
 | 
			
		||||
    config.put("ecdh-sha2-nistp256", "com.jcraft.jsch.DHEC256");
 | 
			
		||||
    config.put("ecdh-sha2-nistp384", "com.jcraft.jsch.DHEC384");
 | 
			
		||||
    config.put("ecdh-sha2-nistp521", "com.jcraft.jsch.DHEC521");
 | 
			
		||||
 | 
			
		||||
    config.put("ecdh-sha2-nistp", "com.jcraft.jsch.jce.ECDHN");
 | 
			
		||||
 | 
			
		||||
    config.put("curve25519-sha256",            "com.jcraft.jsch.DH25519");
 | 
			
		||||
    config.put("curve25519-sha256@libssh.org", "com.jcraft.jsch.DH25519");
 | 
			
		||||
    config.put("curve448-sha512",              "com.jcraft.jsch.DH448");
 | 
			
		||||
 | 
			
		||||
    config.put("dh",            "com.jcraft.jsch.jce.DH");
 | 
			
		||||
    config.put("3des-cbc",      "com.jcraft.jsch.jce.TripleDESCBC");
 | 
			
		||||
    config.put("blowfish-cbc",  "com.jcraft.jsch.jce.BlowfishCBC");
 | 
			
		||||
    config.put("hmac-sha1",     "com.jcraft.jsch.jce.HMACSHA1");
 | 
			
		||||
    config.put("hmac-sha1-96",  "com.jcraft.jsch.jce.HMACSHA196");
 | 
			
		||||
    config.put("hmac-sha2-256",  "com.jcraft.jsch.jce.HMACSHA256");
 | 
			
		||||
    config.put("hmac-sha2-512",  "com.jcraft.jsch.jce.HMACSHA512");
 | 
			
		||||
    config.put("hmac-md5",      "com.jcraft.jsch.jce.HMACMD5");
 | 
			
		||||
    config.put("hmac-md5-96",   "com.jcraft.jsch.jce.HMACMD596");
 | 
			
		||||
    config.put("hmac-sha1-etm@openssh.com",     "com.jcraft.jsch.jce.HMACSHA1ETM");
 | 
			
		||||
    config.put("hmac-sha1-96-etm@openssh.com",  "com.jcraft.jsch.jce.HMACSHA196ETM");
 | 
			
		||||
    config.put("hmac-sha2-256-etm@openssh.com",  "com.jcraft.jsch.jce.HMACSHA256ETM");
 | 
			
		||||
    config.put("hmac-sha2-512-etm@openssh.com",  "com.jcraft.jsch.jce.HMACSHA512ETM");
 | 
			
		||||
    config.put("hmac-md5-etm@openssh.com",      "com.jcraft.jsch.jce.HMACMD5ETM");
 | 
			
		||||
    config.put("hmac-md5-96-etm@openssh.com",   "com.jcraft.jsch.jce.HMACMD596ETM");
 | 
			
		||||
    config.put("hmac-sha256-2@ssh.com",  "com.jcraft.jsch.jce.HMACSHA2562SSHCOM");
 | 
			
		||||
    config.put("hmac-sha224@ssh.com",  "com.jcraft.jsch.jce.HMACSHA224SSHCOM");
 | 
			
		||||
    config.put("hmac-sha256@ssh.com",  "com.jcraft.jsch.jce.HMACSHA256SSHCOM");
 | 
			
		||||
    config.put("hmac-sha384@ssh.com",  "com.jcraft.jsch.jce.HMACSHA384SSHCOM");
 | 
			
		||||
    config.put("hmac-sha512@ssh.com",  "com.jcraft.jsch.jce.HMACSHA512SSHCOM");
 | 
			
		||||
    config.put("sha-1",         "com.jcraft.jsch.jce.SHA1");
 | 
			
		||||
    config.put("sha-224",       "com.jcraft.jsch.jce.SHA224");
 | 
			
		||||
    config.put("sha-256",       "com.jcraft.jsch.jce.SHA256");
 | 
			
		||||
    config.put("sha-384",       "com.jcraft.jsch.jce.SHA384");
 | 
			
		||||
    config.put("sha-512",       "com.jcraft.jsch.jce.SHA512");
 | 
			
		||||
    config.put("md5",           "com.jcraft.jsch.jce.MD5");
 | 
			
		||||
    config.put("sha1",          "com.jcraft.jsch.jce.SHA1");
 | 
			
		||||
    config.put("sha224",        "com.jcraft.jsch.jce.SHA224");
 | 
			
		||||
    config.put("sha256",        "com.jcraft.jsch.jce.SHA256");
 | 
			
		||||
    config.put("sha384",        "com.jcraft.jsch.jce.SHA384");
 | 
			
		||||
    config.put("sha512",        "com.jcraft.jsch.jce.SHA512");
 | 
			
		||||
    config.put("signature.dss", "com.jcraft.jsch.jce.SignatureDSA");
 | 
			
		||||
    config.put("ssh-rsa",       "com.jcraft.jsch.jce.SignatureRSA");
 | 
			
		||||
    config.put("rsa-sha2-256",  "com.jcraft.jsch.jce.SignatureRSASHA256");
 | 
			
		||||
    config.put("rsa-sha2-512",  "com.jcraft.jsch.jce.SignatureRSASHA512");
 | 
			
		||||
    config.put("ssh-rsa-sha224@ssh.com",  "com.jcraft.jsch.jce.SignatureRSASHA224SSHCOM");
 | 
			
		||||
    config.put("ssh-rsa-sha256@ssh.com",  "com.jcraft.jsch.jce.SignatureRSASHA256SSHCOM");
 | 
			
		||||
    config.put("ssh-rsa-sha384@ssh.com",  "com.jcraft.jsch.jce.SignatureRSASHA384SSHCOM");
 | 
			
		||||
    config.put("ssh-rsa-sha512@ssh.com",  "com.jcraft.jsch.jce.SignatureRSASHA512SSHCOM");
 | 
			
		||||
    config.put("keypairgen.dsa",   "com.jcraft.jsch.jce.KeyPairGenDSA");
 | 
			
		||||
    config.put("keypairgen.rsa",   "com.jcraft.jsch.jce.KeyPairGenRSA");
 | 
			
		||||
    config.put("keypairgen.ecdsa", "com.jcraft.jsch.jce.KeyPairGenECDSA");
 | 
			
		||||
    config.put("random",        "com.jcraft.jsch.jce.Random");
 | 
			
		||||
 | 
			
		||||
    config.put("hmac-ripemd160", "com.jcraft.jsch.bc.HMACRIPEMD160");
 | 
			
		||||
    config.put("hmac-ripemd160@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160OpenSSH");
 | 
			
		||||
    config.put("hmac-ripemd160-etm@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160ETM");
 | 
			
		||||
 | 
			
		||||
    config.put("none",           "com.jcraft.jsch.CipherNone");
 | 
			
		||||
 | 
			
		||||
    config.put("aes128-gcm@openssh.com",    "com.jcraft.jsch.jce.AES128GCM");
 | 
			
		||||
    config.put("aes256-gcm@openssh.com",    "com.jcraft.jsch.jce.AES256GCM");
 | 
			
		||||
 | 
			
		||||
    config.put("aes128-cbc",    "com.jcraft.jsch.jce.AES128CBC");
 | 
			
		||||
    config.put("aes192-cbc",    "com.jcraft.jsch.jce.AES192CBC");
 | 
			
		||||
    config.put("aes256-cbc",    "com.jcraft.jsch.jce.AES256CBC");
 | 
			
		||||
    config.put("rijndael-cbc@lysator.liu.se",    "com.jcraft.jsch.jce.AES256CBC");
 | 
			
		||||
 | 
			
		||||
    config.put("chacha20-poly1305@openssh.com", "com.jcraft.jsch.bc.ChaCha20Poly1305");
 | 
			
		||||
    config.put("cast128-cbc",    "com.jcraft.jsch.bc.CAST128CBC");
 | 
			
		||||
    config.put("cast128-ctr",    "com.jcraft.jsch.bc.CAST128CTR");
 | 
			
		||||
    config.put("twofish128-cbc",    "com.jcraft.jsch.bc.Twofish128CBC");
 | 
			
		||||
    config.put("twofish192-cbc",    "com.jcraft.jsch.bc.Twofish192CBC");
 | 
			
		||||
    config.put("twofish256-cbc",    "com.jcraft.jsch.bc.Twofish256CBC");
 | 
			
		||||
    config.put("twofish-cbc",    "com.jcraft.jsch.bc.Twofish256CBC");
 | 
			
		||||
    config.put("twofish128-ctr",    "com.jcraft.jsch.bc.Twofish128CTR");
 | 
			
		||||
    config.put("twofish192-ctr",    "com.jcraft.jsch.bc.Twofish192CTR");
 | 
			
		||||
    config.put("twofish256-ctr",    "com.jcraft.jsch.bc.Twofish256CTR");
 | 
			
		||||
    config.put("seed-cbc@ssh.com",    "com.jcraft.jsch.bc.SEEDCBC");
 | 
			
		||||
 | 
			
		||||
    config.put("aes128-ctr",    "com.jcraft.jsch.jce.AES128CTR");
 | 
			
		||||
    config.put("aes192-ctr",    "com.jcraft.jsch.jce.AES192CTR");
 | 
			
		||||
    config.put("aes256-ctr",    "com.jcraft.jsch.jce.AES256CTR");
 | 
			
		||||
    config.put("3des-ctr",      "com.jcraft.jsch.jce.TripleDESCTR");
 | 
			
		||||
    config.put("blowfish-ctr",  "com.jcraft.jsch.jce.BlowfishCTR");
 | 
			
		||||
    config.put("arcfour",      "com.jcraft.jsch.jce.ARCFOUR");
 | 
			
		||||
    config.put("arcfour128",      "com.jcraft.jsch.jce.ARCFOUR128");
 | 
			
		||||
    config.put("arcfour256",      "com.jcraft.jsch.jce.ARCFOUR256");
 | 
			
		||||
 | 
			
		||||
    config.put("userauth.none",    "com.jcraft.jsch.UserAuthNone");
 | 
			
		||||
    config.put("userauth.password",    "com.jcraft.jsch.UserAuthPassword");
 | 
			
		||||
    config.put("userauth.keyboard-interactive",    "com.jcraft.jsch.UserAuthKeyboardInteractive");
 | 
			
		||||
    config.put("userauth.publickey",    "com.jcraft.jsch.UserAuthPublicKey");
 | 
			
		||||
    config.put("userauth.gssapi-with-mic",    "com.jcraft.jsch.UserAuthGSSAPIWithMIC");
 | 
			
		||||
    config.put("gssapi-with-mic.krb5",    "com.jcraft.jsch.jgss.GSSContextKrb5");
 | 
			
		||||
 | 
			
		||||
    config.put("zlib",             "com.jcraft.jsch.jzlib.Compression");
 | 
			
		||||
    config.put("zlib@openssh.com", "com.jcraft.jsch.jzlib.Compression");
 | 
			
		||||
 | 
			
		||||
    config.put("pbkdf", "com.jcraft.jsch.jce.PBKDF");
 | 
			
		||||
 | 
			
		||||
    if(JavaVersion.getVersion()>=11){
 | 
			
		||||
      config.put("xdh", "com.jcraft.jsch.jce.XDH");
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      config.put("xdh", "com.jcraft.jsch.bc.XDH");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(JavaVersion.getVersion()>=15){
 | 
			
		||||
      config.put("keypairgen.eddsa", "com.jcraft.jsch.jce.KeyPairGenEdDSA");
 | 
			
		||||
      config.put("ssh-ed25519", "com.jcraft.jsch.jce.SignatureEd25519");
 | 
			
		||||
      config.put("ssh-ed448", "com.jcraft.jsch.jce.SignatureEd448");
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      config.put("keypairgen.eddsa", "com.jcraft.jsch.bc.KeyPairGenEdDSA");
 | 
			
		||||
      config.put("ssh-ed25519", "com.jcraft.jsch.bc.SignatureEd25519");
 | 
			
		||||
      config.put("ssh-ed448", "com.jcraft.jsch.bc.SignatureEd448");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    config.put("StrictHostKeyChecking",  "ask");
 | 
			
		||||
    config.put("HashKnownHosts",  "no");
 | 
			
		||||
 | 
			
		||||
    config.put("PreferredAuthentications", Util.getSystemProperty("jsch.preferred_authentications", "gssapi-with-mic,publickey,keyboard-interactive,password"));
 | 
			
		||||
    config.put("PubkeyAcceptedAlgorithms", Util.getSystemProperty("jsch.client_pubkey", "ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256"));
 | 
			
		||||
 | 
			
		||||
    config.put("CheckCiphers", Util.getSystemProperty("jsch.check_ciphers", "chacha20-poly1305@openssh.com"));
 | 
			
		||||
    config.put("CheckMacs", Util.getSystemProperty("jsch.check_macs", ""));
 | 
			
		||||
    config.put("CheckKexes", Util.getSystemProperty("jsch.check_kexes", "curve25519-sha256,curve25519-sha256@libssh.org,curve448-sha512"));
 | 
			
		||||
    config.put("CheckSignatures", Util.getSystemProperty("jsch.check_signatures", "ssh-ed25519,ssh-ed448"));
 | 
			
		||||
    config.put("FingerprintHash", Util.getSystemProperty("jsch.fingerprint_hash", "sha256"));
 | 
			
		||||
 | 
			
		||||
    config.put("MaxAuthTries", Util.getSystemProperty("jsch.max_auth_tries", "6"));
 | 
			
		||||
    config.put("ClearAllForwardings", "no");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private Vector<Session> sessionPool = new Vector<>();
 | 
			
		||||
 | 
			
		||||
  private IdentityRepository defaultIdentityRepository =
 | 
			
		||||
    new LocalIdentityRepository(this);
 | 
			
		||||
 | 
			
		||||
  private IdentityRepository identityRepository = defaultIdentityRepository;
 | 
			
		||||
 | 
			
		||||
  private ConfigRepository configRepository = null;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the <code>identityRepository</code>, which will be referred
 | 
			
		||||
   * in the public key authentication.
 | 
			
		||||
   *
 | 
			
		||||
   * @param identityRepository if <code>null</code> is given,
 | 
			
		||||
   * the default repository, which usually refers to ~/.ssh/, will be used.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #getIdentityRepository()
 | 
			
		||||
   */
 | 
			
		||||
  public synchronized void setIdentityRepository(IdentityRepository identityRepository){
 | 
			
		||||
    if(identityRepository == null){
 | 
			
		||||
      this.identityRepository = defaultIdentityRepository;
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      this.identityRepository = identityRepository;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public synchronized IdentityRepository getIdentityRepository(){
 | 
			
		||||
    return this.identityRepository;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public ConfigRepository getConfigRepository() {
 | 
			
		||||
    return this.configRepository;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setConfigRepository(ConfigRepository configRepository) {
 | 
			
		||||
    this.configRepository = configRepository;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private HostKeyRepository known_hosts=null;
 | 
			
		||||
 | 
			
		||||
  static final Logger DEVNULL=new Logger(){
 | 
			
		||||
      @Override
 | 
			
		||||
      public boolean isEnabled(int level){return false;}
 | 
			
		||||
      @Override
 | 
			
		||||
      public void log(int level, String message){}
 | 
			
		||||
    };
 | 
			
		||||
  static Logger logger=DEVNULL;
 | 
			
		||||
  private Logger instLogger;
 | 
			
		||||
 | 
			
		||||
  public JSch(){
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Instantiates the <code>Session</code> object with
 | 
			
		||||
   * <code>host</code>.  The user name and port number will be retrieved from
 | 
			
		||||
   * ConfigRepository.  If user name is not given,
 | 
			
		||||
   * the system property "user.name" will be referred. 
 | 
			
		||||
   *
 | 
			
		||||
   * @param host hostname
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException
 | 
			
		||||
   *         if <code>username</code> or <code>host</code> are invalid.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the instance of <code>Session</code> class.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #getSession(String username, String host, int port)
 | 
			
		||||
   * @see com.jcraft.jsch.Session
 | 
			
		||||
   * @see com.jcraft.jsch.ConfigRepository
 | 
			
		||||
   */
 | 
			
		||||
  public Session getSession(String host)
 | 
			
		||||
     throws JSchException {
 | 
			
		||||
    return getSession(null, host, 22);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Instantiates the <code>Session</code> object with
 | 
			
		||||
   * <code>username</code> and <code>host</code>.
 | 
			
		||||
   * The TCP port 22 will be used in making the connection.
 | 
			
		||||
   * Note that the TCP connection must not be established
 | 
			
		||||
   * until Session#connect().
 | 
			
		||||
   *
 | 
			
		||||
   * @param username user name
 | 
			
		||||
   * @param host hostname
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException
 | 
			
		||||
   *         if <code>username</code> or <code>host</code> are invalid.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the instance of <code>Session</code> class.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #getSession(String username, String host, int port)
 | 
			
		||||
   * @see com.jcraft.jsch.Session
 | 
			
		||||
   */
 | 
			
		||||
  public Session getSession(String username, String host)
 | 
			
		||||
     throws JSchException {
 | 
			
		||||
    return getSession(username, host, 22);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Instantiates the <code>Session</code> object with given
 | 
			
		||||
   * <code>username</code>, <code>host</code> and <code>port</code>.
 | 
			
		||||
   * Note that the TCP connection must not be established
 | 
			
		||||
   * until Session#connect().
 | 
			
		||||
   *
 | 
			
		||||
   * @param username user name
 | 
			
		||||
   * @param host hostname
 | 
			
		||||
   * @param port port number
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException
 | 
			
		||||
   *         if <code>username</code> or <code>host</code> are invalid.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the instance of <code>Session</code> class.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #getSession(String username, String host, int port)
 | 
			
		||||
   * @see com.jcraft.jsch.Session
 | 
			
		||||
   */
 | 
			
		||||
  public Session getSession(String username, String host, int port) throws JSchException {
 | 
			
		||||
    if(host==null){
 | 
			
		||||
      throw new JSchException("host must not be null.");
 | 
			
		||||
    }
 | 
			
		||||
    Session s = new Session(this, username, host, port); 
 | 
			
		||||
    return s;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void addSession(Session session){
 | 
			
		||||
    synchronized(sessionPool){
 | 
			
		||||
      sessionPool.addElement(session);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected boolean removeSession(Session session){
 | 
			
		||||
    synchronized(sessionPool){
 | 
			
		||||
      return sessionPool.remove(session);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the hostkey repository.
 | 
			
		||||
   *
 | 
			
		||||
   * @param hkrepo
 | 
			
		||||
   *
 | 
			
		||||
   * @see com.jcraft.jsch.HostKeyRepository
 | 
			
		||||
   * @see com.jcraft.jsch.KnownHosts
 | 
			
		||||
   */
 | 
			
		||||
  public void setHostKeyRepository(HostKeyRepository hkrepo){
 | 
			
		||||
    known_hosts=hkrepo;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the instance of <code>KnownHosts</code>, which refers
 | 
			
		||||
   * to <code>filename</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param filename filename of known_hosts file.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException
 | 
			
		||||
   *         if the given filename is invalid.
 | 
			
		||||
   *
 | 
			
		||||
   * @see com.jcraft.jsch.KnownHosts
 | 
			
		||||
   */
 | 
			
		||||
  public void setKnownHosts(String filename) throws JSchException{
 | 
			
		||||
    if(known_hosts==null) known_hosts=new KnownHosts(this);
 | 
			
		||||
    if(known_hosts instanceof KnownHosts){
 | 
			
		||||
      synchronized(known_hosts){
 | 
			
		||||
        ((KnownHosts)known_hosts).setKnownHosts(filename); 
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the instance of <code>KnownHosts</code> generated with
 | 
			
		||||
   * <code>stream</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param stream the instance of InputStream from known_hosts file.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException
 | 
			
		||||
   *         if an I/O error occurs.
 | 
			
		||||
   *
 | 
			
		||||
   * @see com.jcraft.jsch.KnownHosts
 | 
			
		||||
   */
 | 
			
		||||
  public void setKnownHosts(InputStream stream) throws JSchException{ 
 | 
			
		||||
    if(known_hosts==null) known_hosts=new KnownHosts(this);
 | 
			
		||||
    if(known_hosts instanceof KnownHosts){
 | 
			
		||||
      synchronized(known_hosts){
 | 
			
		||||
        ((KnownHosts)known_hosts).setKnownHosts(stream); 
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the current hostkey repository.
 | 
			
		||||
   * By the default, this method will the instance of <code>KnownHosts</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @return current hostkey repository.
 | 
			
		||||
   *
 | 
			
		||||
   * @see com.jcraft.jsch.HostKeyRepository
 | 
			
		||||
   * @see com.jcraft.jsch.KnownHosts
 | 
			
		||||
   */
 | 
			
		||||
  public HostKeyRepository getHostKeyRepository(){ 
 | 
			
		||||
    if(known_hosts==null) known_hosts=new KnownHosts(this);
 | 
			
		||||
    return known_hosts; 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   *
 | 
			
		||||
   * @param prvkey filename of the private key.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>prvkey</code> is invalid.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #addIdentity(String prvkey, String passphrase)
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(String prvkey) throws JSchException{
 | 
			
		||||
    addIdentity(prvkey, (byte[])null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   * Before registering it into identityRepository,
 | 
			
		||||
   * it will be deciphered with <code>passphrase</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param prvkey filename of the private key.
 | 
			
		||||
   * @param passphrase passphrase for <code>prvkey</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>passphrase</code> is not right.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #addIdentity(String prvkey, byte[] passphrase)
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(String prvkey, String passphrase) throws JSchException{
 | 
			
		||||
    byte[] _passphrase=null;
 | 
			
		||||
    if(passphrase!=null){
 | 
			
		||||
      _passphrase=Util.str2byte(passphrase);
 | 
			
		||||
    }
 | 
			
		||||
    addIdentity(prvkey, _passphrase);
 | 
			
		||||
    if(_passphrase!=null)
 | 
			
		||||
      Util.bzero(_passphrase);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   * Before registering it into identityRepository,
 | 
			
		||||
   * it will be deciphered with <code>passphrase</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param prvkey filename of the private key.
 | 
			
		||||
   * @param passphrase passphrase for <code>prvkey</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>passphrase</code> is not right.
 | 
			
		||||
   *
 | 
			
		||||
   * @see #addIdentity(String prvkey, String pubkey, byte[] passphrase)
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(String prvkey, byte[] passphrase) throws JSchException{
 | 
			
		||||
    Identity identity=IdentityFile.newInstance(prvkey, null, this);
 | 
			
		||||
    addIdentity(identity, passphrase);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   * Before registering it into identityRepository,
 | 
			
		||||
   * it will be deciphered with <code>passphrase</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param prvkey filename of the private key.
 | 
			
		||||
   * @param pubkey filename of the public key.
 | 
			
		||||
   * @param passphrase passphrase for <code>prvkey</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>passphrase</code> is not right.
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException{
 | 
			
		||||
    Identity identity=IdentityFile.newInstance(prvkey, pubkey, this);
 | 
			
		||||
    addIdentity(identity, passphrase);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   * Before registering it into identityRepository,
 | 
			
		||||
   * it will be deciphered with <code>passphrase</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param name name of the identity to be used to
 | 
			
		||||
                 retrieve it in the identityRepository.
 | 
			
		||||
   * @param prvkey private key in byte array.
 | 
			
		||||
   * @param pubkey public key in byte array.
 | 
			
		||||
   * @param passphrase passphrase for <code>prvkey</code>.
 | 
			
		||||
   *
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase) throws JSchException{
 | 
			
		||||
    Identity identity=IdentityFile.newInstance(name, prvkey, pubkey, this);
 | 
			
		||||
    addIdentity(identity, passphrase);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the private key, which will be referred in
 | 
			
		||||
   * the public key authentication.
 | 
			
		||||
   * Before registering it into identityRepository,
 | 
			
		||||
   * it will be deciphered with <code>passphrase</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @param identity private key.
 | 
			
		||||
   * @param passphrase passphrase for <code>identity</code>.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>passphrase</code> is not right.
 | 
			
		||||
   */
 | 
			
		||||
  public void addIdentity(Identity identity, byte[] passphrase) throws JSchException{
 | 
			
		||||
    if(passphrase!=null){
 | 
			
		||||
      try{ 
 | 
			
		||||
        byte[] goo=new byte[passphrase.length];
 | 
			
		||||
        System.arraycopy(passphrase, 0, goo, 0, passphrase.length);
 | 
			
		||||
        passphrase=goo;
 | 
			
		||||
        identity.setPassphrase(passphrase); 
 | 
			
		||||
      }
 | 
			
		||||
      finally{
 | 
			
		||||
        Util.bzero(passphrase);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(identityRepository instanceof LocalIdentityRepository){
 | 
			
		||||
      ((LocalIdentityRepository)identityRepository).add(identity);
 | 
			
		||||
    }
 | 
			
		||||
    else if(identity instanceof IdentityFile && !identity.isEncrypted()) {
 | 
			
		||||
      identityRepository.add(((IdentityFile)identity).getKeyPair().forSSHAgent());
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      synchronized(this){
 | 
			
		||||
        if(!(identityRepository instanceof IdentityRepositoryWrapper)){
 | 
			
		||||
          setIdentityRepository(new IdentityRepositoryWrapper(identityRepository));
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      ((IdentityRepositoryWrapper)identityRepository).add(identity);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @deprecated use #removeIdentity(Identity identity)
 | 
			
		||||
   */
 | 
			
		||||
  @Deprecated
 | 
			
		||||
  public void removeIdentity(String name) throws JSchException{
 | 
			
		||||
    Vector<Identity> identities = identityRepository.getIdentities();
 | 
			
		||||
    for(int i=0; i<identities.size(); i++){
 | 
			
		||||
      Identity identity=identities.elementAt(i);
 | 
			
		||||
      if(!identity.getName().equals(name))
 | 
			
		||||
        continue;
 | 
			
		||||
      if(identityRepository instanceof LocalIdentityRepository){
 | 
			
		||||
        ((LocalIdentityRepository)identityRepository).remove(identity);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
        identityRepository.remove(identity.getPublicKeyBlob());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Removes the identity from identityRepository.
 | 
			
		||||
   *
 | 
			
		||||
   * @param identity the indentity to be removed.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if <code>identity</code> is invalid.
 | 
			
		||||
   */
 | 
			
		||||
  public void removeIdentity(Identity identity) throws JSchException{
 | 
			
		||||
    identityRepository.remove(identity.getPublicKeyBlob());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Lists names of identities included in the identityRepository.
 | 
			
		||||
   *
 | 
			
		||||
   * @return names of identities
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if identityReposory has problems.
 | 
			
		||||
   */
 | 
			
		||||
  public Vector<String> getIdentityNames() throws JSchException{
 | 
			
		||||
    Vector<String> foo=new Vector<>();
 | 
			
		||||
    Vector<Identity> identities = identityRepository.getIdentities();
 | 
			
		||||
    for(int i=0; i<identities.size(); i++){
 | 
			
		||||
      Identity identity=identities.elementAt(i);
 | 
			
		||||
      foo.addElement(identity.getName());
 | 
			
		||||
    }
 | 
			
		||||
    return foo;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Removes all identities from identityRepository.
 | 
			
		||||
   *
 | 
			
		||||
   * @throws JSchException if identityReposory has problems.
 | 
			
		||||
   */
 | 
			
		||||
  public void removeAllIdentity() throws JSchException{
 | 
			
		||||
    identityRepository.removeAll();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the config value for the specified key.
 | 
			
		||||
   *
 | 
			
		||||
   * @param key key for the configuration.
 | 
			
		||||
   * @return config value
 | 
			
		||||
   */
 | 
			
		||||
  public static String getConfig(String key){ 
 | 
			
		||||
    synchronized(config){
 | 
			
		||||
      if(key.equals("PubkeyAcceptedKeyTypes")){
 | 
			
		||||
        key="PubkeyAcceptedAlgorithms";
 | 
			
		||||
      }
 | 
			
		||||
      return config.get(key);
 | 
			
		||||
    } 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets or Overrides the configuration.
 | 
			
		||||
   *
 | 
			
		||||
   * @param newconf configurations
 | 
			
		||||
   */
 | 
			
		||||
  public static void setConfig(Hashtable<String, String> newconf){
 | 
			
		||||
    synchronized(config){
 | 
			
		||||
      for(Enumeration<String> e=newconf.keys() ; e.hasMoreElements() ;) {
 | 
			
		||||
        String newkey=e.nextElement();
 | 
			
		||||
        String key=(newkey.equals("PubkeyAcceptedKeyTypes") ? "PubkeyAcceptedAlgorithms" : newkey);
 | 
			
		||||
        config.put(key, newconf.get(newkey));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets or Overrides the configuration.
 | 
			
		||||
   *
 | 
			
		||||
   * @param key key for the configuration
 | 
			
		||||
   * @param value value for the configuration
 | 
			
		||||
   */
 | 
			
		||||
  public static void setConfig(String key, String value){
 | 
			
		||||
    if(key.equals("PubkeyAcceptedKeyTypes")){
 | 
			
		||||
      config.put("PubkeyAcceptedAlgorithms", value);
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      config.put(key, value);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the logger
 | 
			
		||||
   *
 | 
			
		||||
   * @param logger logger or <code>null</code> if no logging
 | 
			
		||||
   * should take place
 | 
			
		||||
   *
 | 
			
		||||
   * @see com.jcraft.jsch.Logger
 | 
			
		||||
   */
 | 
			
		||||
  public static void setLogger(Logger logger){
 | 
			
		||||
    if(logger==null) logger=DEVNULL;
 | 
			
		||||
    JSch.logger=logger;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns  a logger to be used for this particular instance of JSch
 | 
			
		||||
   * @return The logger that is used by this instance. If no particular
 | 
			
		||||
   * logger has been set, the statically set logger is returned.
 | 
			
		||||
   */
 | 
			
		||||
  public Logger getInstanceLogger() {
 | 
			
		||||
      if (this.instLogger == null) {
 | 
			
		||||
          return logger;
 | 
			
		||||
      }
 | 
			
		||||
      return instLogger;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets a logger to be used for this particular instance of JSch
 | 
			
		||||
   * @param logger The logger to be used or <code>null</code> if
 | 
			
		||||
   * the statically set logger should be used
 | 
			
		||||
   */
 | 
			
		||||
  public void setInstanceLogger(Logger logger) {
 | 
			
		||||
      this.instLogger = logger;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the statically set logger, i.e. the logger being
 | 
			
		||||
   * used by all JSch instances without explicitly set logger.
 | 
			
		||||
   * @return The logger
 | 
			
		||||
   */
 | 
			
		||||
  public static Logger getLogger(){
 | 
			
		||||
    return logger;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,69 +0,0 @@
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Extension of {@link JSchException} to indicate when a connection fails during algorithm
 | 
			
		||||
 * negotiation.
 | 
			
		||||
 */
 | 
			
		||||
public class JSchAlgoNegoFailException extends JSchException {
 | 
			
		||||
 | 
			
		||||
  private static final long serialVersionUID = -1L;
 | 
			
		||||
 | 
			
		||||
  private final String algorithmName;
 | 
			
		||||
  private final String jschProposal;
 | 
			
		||||
  private final String serverProposal;
 | 
			
		||||
 | 
			
		||||
  JSchAlgoNegoFailException(int algorithmIndex, String jschProposal, String serverProposal) {
 | 
			
		||||
    super(failString(algorithmIndex, jschProposal, serverProposal));
 | 
			
		||||
    algorithmName = algorithmNameFromIndex(algorithmIndex);
 | 
			
		||||
    this.jschProposal = jschProposal;
 | 
			
		||||
    this.serverProposal = serverProposal;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get the algorithm name. */
 | 
			
		||||
  public String getAlgorithmName() {
 | 
			
		||||
    return algorithmName;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get the JSch algorithm proposal. */
 | 
			
		||||
  public String getJSchProposal() {
 | 
			
		||||
    return jschProposal;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get the server algorithm proposal. */
 | 
			
		||||
  public String getServerProposal() {
 | 
			
		||||
    return serverProposal;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static String failString(int algorithmIndex, String jschProposal, String serverProposal) {
 | 
			
		||||
    return String.format(
 | 
			
		||||
        "Algorithm negotiation fail: algorithmName=\"%s\" jschProposal=\"%s\" serverProposal=\"%s\"",
 | 
			
		||||
        algorithmNameFromIndex(algorithmIndex), jschProposal, serverProposal);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static String algorithmNameFromIndex(int algorithmIndex) {
 | 
			
		||||
    switch (algorithmIndex) {
 | 
			
		||||
      case KeyExchange.PROPOSAL_KEX_ALGS:
 | 
			
		||||
        return "kex";
 | 
			
		||||
      case KeyExchange.PROPOSAL_SERVER_HOST_KEY_ALGS:
 | 
			
		||||
        return "server_host_key";
 | 
			
		||||
      case KeyExchange.PROPOSAL_ENC_ALGS_CTOS:
 | 
			
		||||
        return "cipher.c2s";
 | 
			
		||||
      case KeyExchange.PROPOSAL_ENC_ALGS_STOC:
 | 
			
		||||
        return "cipher.s2c";
 | 
			
		||||
      case KeyExchange.PROPOSAL_MAC_ALGS_CTOS:
 | 
			
		||||
        return "mac.c2s";
 | 
			
		||||
      case KeyExchange.PROPOSAL_MAC_ALGS_STOC:
 | 
			
		||||
        return "mac.s2c";
 | 
			
		||||
      case KeyExchange.PROPOSAL_COMP_ALGS_CTOS:
 | 
			
		||||
        return "compression.c2s";
 | 
			
		||||
      case KeyExchange.PROPOSAL_COMP_ALGS_STOC:
 | 
			
		||||
        return "compression.s2c";
 | 
			
		||||
      case KeyExchange.PROPOSAL_LANG_CTOS:
 | 
			
		||||
        return "lang.c2s";
 | 
			
		||||
      case KeyExchange.PROPOSAL_LANG_STOC:
 | 
			
		||||
        return "lang.s2c";
 | 
			
		||||
      default:
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class JSchAuthCancelException extends JSchException{
 | 
			
		||||
  private static final long serialVersionUID=-1L;
 | 
			
		||||
  String method;
 | 
			
		||||
  JSchAuthCancelException () {
 | 
			
		||||
    super();
 | 
			
		||||
  }
 | 
			
		||||
  JSchAuthCancelException (String s) {
 | 
			
		||||
    super(s);
 | 
			
		||||
    this.method=s;
 | 
			
		||||
  }
 | 
			
		||||
  public String getMethod(){
 | 
			
		||||
    return method;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,43 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public class JSchException extends Exception{
 | 
			
		||||
  private static final long serialVersionUID=-1L;
 | 
			
		||||
  public JSchException () {
 | 
			
		||||
    super();
 | 
			
		||||
  }
 | 
			
		||||
  public JSchException (String s) {
 | 
			
		||||
    super(s);
 | 
			
		||||
  }
 | 
			
		||||
  public JSchException (String s, Throwable e) {
 | 
			
		||||
    super(s, e);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
class JSchPartialAuthException extends JSchException{
 | 
			
		||||
  private static final long serialVersionUID=-1L;
 | 
			
		||||
  String methods;
 | 
			
		||||
  public JSchPartialAuthException () {
 | 
			
		||||
    super();
 | 
			
		||||
  }
 | 
			
		||||
  public JSchPartialAuthException (String s) {
 | 
			
		||||
    super(s);
 | 
			
		||||
    this.methods=s;
 | 
			
		||||
  }
 | 
			
		||||
  public String getMethods(){
 | 
			
		||||
    return methods;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
final class JavaVersion {
 | 
			
		||||
 | 
			
		||||
  static int getVersion() {
 | 
			
		||||
    return 8;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,53 +0,0 @@
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
import java.util.logging.Level;
 | 
			
		||||
import java.util.logging.Logger;
 | 
			
		||||
 | 
			
		||||
public class JulLogger implements com.jcraft.jsch.Logger {
 | 
			
		||||
 | 
			
		||||
  private static final Logger stlogger = Logger.getLogger(JSch.class.getName());
 | 
			
		||||
  private final Logger logger;
 | 
			
		||||
  
 | 
			
		||||
  public JulLogger() {
 | 
			
		||||
    this(stlogger);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  JulLogger(Logger logger) {
 | 
			
		||||
    this.logger = logger;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean isEnabled(int level) {
 | 
			
		||||
    return logger.isLoggable(getLevel(level));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void log(int level, String message) {
 | 
			
		||||
    log(level, message, null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void log(int level, String message, Throwable cause) {
 | 
			
		||||
    if (cause == null) {
 | 
			
		||||
      logger.log(getLevel(level), message);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    logger.log(getLevel(level), message, cause);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static Level getLevel(int level) {
 | 
			
		||||
    switch (level) {
 | 
			
		||||
      case com.jcraft.jsch.Logger.DEBUG:
 | 
			
		||||
        return Level.FINE;
 | 
			
		||||
      case com.jcraft.jsch.Logger.INFO:
 | 
			
		||||
        return Level.INFO;
 | 
			
		||||
      case com.jcraft.jsch.Logger.WARN:
 | 
			
		||||
        return Level.WARNING;
 | 
			
		||||
      case com.jcraft.jsch.Logger.ERROR:
 | 
			
		||||
      case com.jcraft.jsch.Logger.FATAL:
 | 
			
		||||
        return Level.SEVERE;
 | 
			
		||||
      default:
 | 
			
		||||
        return Level.FINER;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,398 +0,0 @@
 | 
			
		||||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
 | 
			
		||||
/*
 | 
			
		||||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. 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.
 | 
			
		||||
 | 
			
		||||
  3. The names of the authors may not be used to endorse or promote products
 | 
			
		||||
     derived from this software without specific prior written permission.
 | 
			
		||||
 | 
			
		||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
 | 
			
		||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package com.jcraft.jsch;
 | 
			
		||||
 | 
			
		||||
public abstract class KeyExchange{
 | 
			
		||||
 | 
			
		||||
  static final int PROPOSAL_KEX_ALGS=0;
 | 
			
		||||
  static final int PROPOSAL_SERVER_HOST_KEY_ALGS=1;
 | 
			
		||||
  static final int PROPOSAL_ENC_ALGS_CTOS=2;
 | 
			
		||||
  static final int PROPOSAL_ENC_ALGS_STOC=3;
 | 
			
		||||
  static final int PROPOSAL_MAC_ALGS_CTOS=4;
 | 
			
		||||
  static final int PROPOSAL_MAC_ALGS_STOC=5;
 | 
			
		||||
  static final int PROPOSAL_COMP_ALGS_CTOS=6;
 | 
			
		||||
  static final int PROPOSAL_COMP_ALGS_STOC=7;
 | 
			
		||||
  static final int PROPOSAL_LANG_CTOS=8;
 | 
			
		||||
  static final int PROPOSAL_LANG_STOC=9;
 | 
			
		||||
  static final int PROPOSAL_MAX=10;
 | 
			
		||||
 | 
			
		||||
  //static String kex_algs="diffie-hellman-group-exchange-sha1"+
 | 
			
		||||
  //                       ",diffie-hellman-group1-sha1";
 | 
			
		||||
 | 
			
		||||
//static String kex="diffie-hellman-group-exchange-sha1";
 | 
			
		||||
  static String kex="diffie-hellman-group1-sha1";
 | 
			
		||||
  static String server_host_key="ssh-rsa,ssh-dss";
 | 
			
		||||
  static String enc_c2s="blowfish-cbc";
 | 
			
		||||
  static String enc_s2c="blowfish-cbc";
 | 
			
		||||
  static String mac_c2s="hmac-md5";     // hmac-md5,hmac-sha1,hmac-ripemd160,
 | 
			
		||||
                                        // hmac-sha1-96,hmac-md5-96
 | 
			
		||||
  static String mac_s2c="hmac-md5";
 | 
			
		||||
//static String comp_c2s="none";        // zlib
 | 
			
		||||
//static String comp_s2c="none";
 | 
			
		||||
  static String lang_c2s="";
 | 
			
		||||
  static String lang_s2c="";
 | 
			
		||||
 | 
			
		||||
  public static final int STATE_END=0;
 | 
			
		||||
 | 
			
		||||
  protected Session session=null;
 | 
			
		||||
  protected HASH sha=null;
 | 
			
		||||
  protected byte[] K=null;
 | 
			
		||||
  protected byte[] H=null;
 | 
			
		||||
  protected byte[] K_S=null;
 | 
			
		||||
 | 
			
		||||
  public abstract void init(Session session, 
 | 
			
		||||
                            byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception;
 | 
			
		||||
  void doInit(Session session, 
 | 
			
		||||
                            byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
 | 
			
		||||
    this.session = session;
 | 
			
		||||
    init(session, V_S, V_C, I_S, I_C);
 | 
			
		||||
  }
 | 
			
		||||
  public abstract boolean next(Buffer buf) throws Exception;
 | 
			
		||||
 | 
			
		||||
  public abstract int getState();
 | 
			
		||||
 | 
			
		||||
  protected final int RSA=0;
 | 
			
		||||
  protected final int DSS=1;
 | 
			
		||||
  protected final int ECDSA=2;
 | 
			
		||||
  protected final int EDDSA=3;
 | 
			
		||||
  private int type=0;
 | 
			
		||||
  private String key_alg_name = "";
 | 
			
		||||
 | 
			
		||||
  public String getKeyType() {
 | 
			
		||||
    if(type==DSS) return "DSA";
 | 
			
		||||
    if(type==RSA) return "RSA";
 | 
			
		||||
    if(type==EDDSA) return "EDDSA";
 | 
			
		||||
    return "ECDSA";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getKeyAlgorithName() {
 | 
			
		||||
    return key_alg_name;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected static String[] guess(Session session, byte[]I_S, byte[]I_C) throws Exception{
 | 
			
		||||
    String[] guess=new String[PROPOSAL_MAX];
 | 
			
		||||
    Buffer sb=new Buffer(I_S); sb.setOffSet(17);
 | 
			
		||||
    Buffer cb=new Buffer(I_C); cb.setOffSet(17);
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
      for(int i=0; i<PROPOSAL_MAX; i++){
 | 
			
		||||
        session.getLogger().log(Logger.INFO,
 | 
			
		||||
                             "kex: server: "+Util.byte2str(sb.getString()));
 | 
			
		||||
      }
 | 
			
		||||
      for(int i=0; i<PROPOSAL_MAX; i++){
 | 
			
		||||
        session.getLogger().log(Logger.INFO,
 | 
			
		||||
                             "kex: client: "+Util.byte2str(cb.getString()));
 | 
			
		||||
      }
 | 
			
		||||
      sb.setOffSet(17);
 | 
			
		||||
      cb.setOffSet(17);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for(int i=0; i<PROPOSAL_MAX; i++){
 | 
			
		||||
      byte[] sp=sb.getString();  // server proposal
 | 
			
		||||
      byte[] cp=cb.getString();  // client proposal
 | 
			
		||||
      int j=0;
 | 
			
		||||
      int k=0;
 | 
			
		||||
 | 
			
		||||
      loop:
 | 
			
		||||
      while(j<cp.length){
 | 
			
		||||
        while(j<cp.length && cp[j]!=',')j++; 
 | 
			
		||||
        if(k==j) throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
 | 
			
		||||
        String algorithm=Util.byte2str(cp, k, j-k);
 | 
			
		||||
        int l=0;
 | 
			
		||||
        int m=0;
 | 
			
		||||
        while(l<sp.length){
 | 
			
		||||
          while(l<sp.length && sp[l]!=',')l++; 
 | 
			
		||||
          if(m==l) throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
 | 
			
		||||
          if(algorithm.equals(Util.byte2str(sp, m, l-m))){
 | 
			
		||||
            guess[i]=algorithm;
 | 
			
		||||
            break loop;
 | 
			
		||||
          }
 | 
			
		||||
          l++;
 | 
			
		||||
          m=l;
 | 
			
		||||
        }
 | 
			
		||||
        j++;
 | 
			
		||||
        k=j;
 | 
			
		||||
      }
 | 
			
		||||
      if(j==0){
 | 
			
		||||
        guess[i]="";
 | 
			
		||||
      }
 | 
			
		||||
      else if(guess[i]==null){
 | 
			
		||||
        throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    boolean _s2cAEAD=false;
 | 
			
		||||
    boolean _c2sAEAD=false;
 | 
			
		||||
    try{
 | 
			
		||||
      Class<? extends Cipher> _s2cclazz=Class.forName(session.getConfig(guess[PROPOSAL_ENC_ALGS_STOC])).asSubclass(Cipher.class);
 | 
			
		||||
      Cipher _s2ccipher=_s2cclazz.getDeclaredConstructor().newInstance();
 | 
			
		||||
      _s2cAEAD=_s2ccipher.isAEAD();
 | 
			
		||||
      if(_s2cAEAD){
 | 
			
		||||
        guess[PROPOSAL_MAC_ALGS_STOC]=null;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      Class<? extends Cipher> _c2sclazz=Class.forName(session.getConfig(guess[PROPOSAL_ENC_ALGS_CTOS])).asSubclass(Cipher.class);
 | 
			
		||||
      Cipher _c2scipher=_c2sclazz.getDeclaredConstructor().newInstance();
 | 
			
		||||
      _c2sAEAD=_c2scipher.isAEAD();
 | 
			
		||||
      if(_c2sAEAD){
 | 
			
		||||
        guess[PROPOSAL_MAC_ALGS_CTOS]=null;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception | NoClassDefFoundError e){
 | 
			
		||||
      throw new JSchException(e.toString(), e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "kex: algorithm: "+guess[PROPOSAL_KEX_ALGS]);
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "kex: host key algorithm: "+guess[PROPOSAL_SERVER_HOST_KEY_ALGS]);
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "kex: server->client"+
 | 
			
		||||
                           " cipher: "+guess[PROPOSAL_ENC_ALGS_STOC]+
 | 
			
		||||
                           " MAC: "+(_s2cAEAD?("<implicit>"):(guess[PROPOSAL_MAC_ALGS_STOC]))+
 | 
			
		||||
                           " compression: "+guess[PROPOSAL_COMP_ALGS_STOC]);
 | 
			
		||||
      session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                           "kex: client->server"+
 | 
			
		||||
                           " cipher: "+guess[PROPOSAL_ENC_ALGS_CTOS]+
 | 
			
		||||
                           " MAC: "+(_c2sAEAD?("<implicit>"):(guess[PROPOSAL_MAC_ALGS_CTOS]))+
 | 
			
		||||
                           " compression: "+guess[PROPOSAL_COMP_ALGS_CTOS]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return guess;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getFingerPrint(){
 | 
			
		||||
    HASH hash=null;
 | 
			
		||||
    try{
 | 
			
		||||
      String _c=session.getConfig("FingerprintHash").toLowerCase();
 | 
			
		||||
      Class<? extends HASH> c=Class.forName(session.getConfig(_c)).asSubclass(HASH.class);
 | 
			
		||||
      hash=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
    }
 | 
			
		||||
    catch(Exception e){ System.err.println("getFingerPrint: "+e); }
 | 
			
		||||
    return Util.getFingerPrint(hash, getHostKey(), true, false);
 | 
			
		||||
  }
 | 
			
		||||
  byte[] getK(){ return K; }
 | 
			
		||||
  byte[] getH(){ return H; }
 | 
			
		||||
  HASH getHash(){ return sha; }
 | 
			
		||||
  byte[] getHostKey(){ return K_S; }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * It seems JCE included in Oracle's Java7u6(and later) has suddenly changed
 | 
			
		||||
   * its behavior.  The secrete generated by KeyAgreement#generateSecret()
 | 
			
		||||
   * may start with 0, even if it is a positive value.
 | 
			
		||||
   */
 | 
			
		||||
  protected byte[] normalize(byte[] secret) {
 | 
			
		||||
    if(secret.length > 1 &&
 | 
			
		||||
       secret[0] == 0 && (secret[1]&0x80) == 0) {
 | 
			
		||||
      byte[] tmp=new byte[secret.length-1];
 | 
			
		||||
      System.arraycopy(secret, 1, tmp, 0, tmp.length);
 | 
			
		||||
      return normalize(tmp);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      return secret;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected boolean verify(String alg, byte[] K_S, int index,
 | 
			
		||||
                           byte[] sig_of_H) throws Exception {
 | 
			
		||||
    int i,j;
 | 
			
		||||
 | 
			
		||||
    i=index;
 | 
			
		||||
    boolean result=false;
 | 
			
		||||
 | 
			
		||||
    if(alg.equals("ssh-rsa")){
 | 
			
		||||
      byte[] tmp;
 | 
			
		||||
      byte[] ee;
 | 
			
		||||
      byte[] n;
 | 
			
		||||
 | 
			
		||||
      type=RSA;
 | 
			
		||||
      key_alg_name=alg;
 | 
			
		||||
      
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      ee=tmp;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      n=tmp;
 | 
			
		||||
 | 
			
		||||
      SignatureRSA sig=null;
 | 
			
		||||
      Buffer buf=new Buffer(sig_of_H);
 | 
			
		||||
      String foo=Util.byte2str(buf.getString());
 | 
			
		||||
      try{
 | 
			
		||||
        Class<? extends SignatureRSA> c=Class.forName(session.getConfig(foo)).asSubclass(SignatureRSA.class);
 | 
			
		||||
        sig=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
        sig.init();
 | 
			
		||||
      }
 | 
			
		||||
      catch(Exception e){
 | 
			
		||||
        System.err.println(e);
 | 
			
		||||
      }
 | 
			
		||||
      sig.setPubKey(ee, n);   
 | 
			
		||||
      sig.update(H);
 | 
			
		||||
      result=sig.verify(sig_of_H);
 | 
			
		||||
 | 
			
		||||
      if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                             "ssh_rsa_verify: "+foo+" signature "+result);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(alg.equals("ssh-dss")){
 | 
			
		||||
      byte[] q=null;
 | 
			
		||||
      byte[] tmp;
 | 
			
		||||
      byte[] p;
 | 
			
		||||
      byte[] g;
 | 
			
		||||
      byte[] f;
 | 
			
		||||
      
 | 
			
		||||
      type=DSS;
 | 
			
		||||
      key_alg_name=alg;
 | 
			
		||||
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
          ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      p=tmp;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      q=tmp;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
          ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      g=tmp;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      f=tmp;
 | 
			
		||||
 | 
			
		||||
      SignatureDSA sig=null;
 | 
			
		||||
      try{
 | 
			
		||||
        Class<? extends SignatureDSA> c=Class.forName(session.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
 | 
			
		||||
        sig=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
        sig.init();
 | 
			
		||||
      }
 | 
			
		||||
      catch(Exception e){
 | 
			
		||||
        System.err.println(e);
 | 
			
		||||
      }
 | 
			
		||||
      sig.setPubKey(f, p, q, g);   
 | 
			
		||||
      sig.update(H);
 | 
			
		||||
      result=sig.verify(sig_of_H);
 | 
			
		||||
 | 
			
		||||
      if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                             "ssh_dss_verify: signature "+result);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(alg.equals("ecdsa-sha2-nistp256") ||
 | 
			
		||||
            alg.equals("ecdsa-sha2-nistp384") ||
 | 
			
		||||
            alg.equals("ecdsa-sha2-nistp521")) {
 | 
			
		||||
      byte[] tmp;
 | 
			
		||||
      byte[] r;
 | 
			
		||||
      byte[] s;
 | 
			
		||||
 | 
			
		||||
      // RFC 5656, 
 | 
			
		||||
      type=ECDSA;
 | 
			
		||||
      key_alg_name=alg;
 | 
			
		||||
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      i++;
 | 
			
		||||
      tmp=new byte[(j-1)/2];
 | 
			
		||||
      System.arraycopy(K_S, i, tmp, 0, tmp.length); i+=(j-1)/2;
 | 
			
		||||
      r=tmp;
 | 
			
		||||
      tmp=new byte[(j-1)/2];
 | 
			
		||||
      System.arraycopy(K_S, i, tmp, 0, tmp.length); i+=(j-1)/2;
 | 
			
		||||
      s=tmp;
 | 
			
		||||
 | 
			
		||||
      SignatureECDSA sig=null;
 | 
			
		||||
      try{
 | 
			
		||||
        Class<? extends SignatureECDSA> c=Class.forName(session.getConfig(alg)).asSubclass(SignatureECDSA.class);
 | 
			
		||||
        sig=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
        sig.init();
 | 
			
		||||
      }
 | 
			
		||||
      catch(Exception e){
 | 
			
		||||
        System.err.println(e);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      sig.setPubKey(r, s);
 | 
			
		||||
 | 
			
		||||
      sig.update(H);
 | 
			
		||||
 | 
			
		||||
      result=sig.verify(sig_of_H);
 | 
			
		||||
 | 
			
		||||
      if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO, 
 | 
			
		||||
                             "ssh_ecdsa_verify: "+alg+" signature "+result);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(alg.equals("ssh-ed25519") ||
 | 
			
		||||
            alg.equals("ssh-ed448")) {
 | 
			
		||||
      byte[] tmp;
 | 
			
		||||
 | 
			
		||||
      // RFC 8709,
 | 
			
		||||
      type=EDDSA;
 | 
			
		||||
      key_alg_name=alg;
 | 
			
		||||
 | 
			
		||||
      j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
 | 
			
		||||
        ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
 | 
			
		||||
      tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
 | 
			
		||||
 | 
			
		||||
      SignatureEdDSA sig=null;
 | 
			
		||||
      try{
 | 
			
		||||
        Class<? extends SignatureEdDSA> c=Class.forName(session.getConfig(alg)).asSubclass(SignatureEdDSA.class);
 | 
			
		||||
        sig=c.getDeclaredConstructor().newInstance();
 | 
			
		||||
        sig.init();
 | 
			
		||||
      }
 | 
			
		||||
      catch(Exception | NoClassDefFoundError e){
 | 
			
		||||
        System.err.println(e);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      sig.setPubKey(tmp);
 | 
			
		||||
 | 
			
		||||
      sig.update(H);
 | 
			
		||||
 | 
			
		||||
      result=sig.verify(sig_of_H);
 | 
			
		||||
 | 
			
		||||
      if(session.getLogger().isEnabled(Logger.INFO)){
 | 
			
		||||
        session.getLogger().log(Logger.INFO,
 | 
			
		||||
                             "ssh_eddsa_verify: "+alg+" signature "+result);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      System.err.println("unknown alg");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user