Compare commits
	
		
			24 Commits
		
	
	
		
			feature/82
			...
			feature/no
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 9c43136e18 | ||
|   | 38da94e6dd | ||
|   | da245f3f88 | ||
|   | 1e18763f8d | ||
|   | 82c3b0546c | ||
|   | f246726ab7 | ||
|   | 331daa7e12 | ||
|   | 9be215c295 | ||
|   | bb97a023de | ||
|   | edb4907bf5 | ||
|   | a718c7ed7e | ||
|   | 4f11789f26 | ||
|   | eb15861b13 | ||
|   | 8c2c8049c8 | ||
|   | 2f3761b0a7 | ||
|   | 260bc8adb2 | ||
|   | 87e979635b | ||
|   | 0c9c163755 | ||
|   | 74ceea562b | ||
|   | c6a5362ecb | ||
|   | f655a89be0 | ||
|   | 0d6f837578 | ||
|   | 8c61b028b7 | ||
|   | 93cf4f790c | 
							
								
								
									
										4
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							| @@ -339,7 +339,7 @@ jobs: | |||||||
|       with: |       with: | ||||||
|         name: archive APK ('net' built on ${{ github.job }}) |         name: archive APK ('net' built on ${{ github.job }}) | ||||||
|         path: | |         path: | | ||||||
|           src/keepass2android-app/bin/Release/net8.0-android/publish/*.apk |           src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk | ||||||
|  |  | ||||||
|     - name: Select the manifest |     - name: Select the manifest | ||||||
|       run: | |       run: | | ||||||
| @@ -365,5 +365,5 @@ jobs: | |||||||
|       with: |       with: | ||||||
|         name: archive APK ('nonet' built on ${{ github.job }}) |         name: archive APK ('nonet' built on ${{ github.job }}) | ||||||
|         path: | |         path: | | ||||||
|           src/keepass2android-app/bin/Release/net8.0-android/publish/*.apk |           src/keepass2android-app/bin/Release/net9.0-android/publish/*.apk | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							| @@ -3,10 +3,9 @@ env: | |||||||
|   NAME: 'Release' |   NAME: 'Release' | ||||||
|  |  | ||||||
| on: | on: | ||||||
|   push: |   # the workflow is always triggered manually. This allows to test the apks | ||||||
|     tags: |   # before publishing the release and not having a broken tag in the repo if that test fails. | ||||||
|       - "v1.*" |   workflow_dispatch:  | ||||||
|   workflow_dispatch: # Allows manual triggering of the workflow |  | ||||||
| jobs: | jobs: | ||||||
|  |  | ||||||
|   build-release: |   build-release: | ||||||
| @@ -131,8 +130,8 @@ jobs: | |||||||
|         name: keepass2android_${{ matrix.target }}_${{ matrix.flavor }} |         name: keepass2android_${{ matrix.target }}_${{ matrix.flavor }} | ||||||
|         # the first line is for "apk" target, the second line is for "apk_split" target |         # the first line is for "apk" target, the second line is for "apk_split" target | ||||||
|         path: | |         path: | | ||||||
|           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/net8.0-android/*/publish/*.apk |           src/keepass2android-app/bin/Release/net9.0-android/*/publish/*.apk | ||||||
|      |      | ||||||
|     - name: List apks |     - name: List apks | ||||||
|       run:  find . -type f -name "*.apk" |       run:  find . -type f -name "*.apk" | ||||||
| @@ -143,5 +142,5 @@ jobs: | |||||||
|       with: |       with: | ||||||
|         draft: true |         draft: true | ||||||
|         files: | |         files: | | ||||||
|           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/net8.0-android/*/publish/*.apk |           src/keepass2android-app/bin/Release/net9.0-android/*/publish/*.apk | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
| @@ -34,5 +34,6 @@ | |||||||
|     <AndroidLibrary Bind="False" Update="okhttp-digest-3.1.0.jar" /> |     <AndroidLibrary Bind="False" Update="okhttp-digest-3.1.0.jar" /> | ||||||
|     <AndroidLibrary Bind="False" Update="okio-3.6.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="okio-jvm-3.6.0.jar" /> | ||||||
|  |     <AndroidLibrary Bind="False" Update="jsch-2.27.2.jar" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| </Project> | </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"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <TargetFramework>net8.0-android</TargetFramework> |     <TargetFramework>net9.0-android</TargetFramework> | ||||||
|     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> |     <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||||||
|     <Nullable>enable</Nullable> |     <Nullable>enable</Nullable> | ||||||
|     <ImplicitUsings>enable</ImplicitUsings> |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|   | |||||||
| @@ -51,4 +51,6 @@ dependencies { | |||||||
|     implementation 'com.pcloud.sdk:android:1.9.1' |     implementation 'com.pcloud.sdk:android:1.9.1' | ||||||
|     implementation 'com.google.code.gson:gson:2.8.6' |     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; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
| } |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,378 +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.math.BigInteger; |  | ||||||
|  |  | ||||||
| class KeyPairDSA extends KeyPair{ |  | ||||||
|   private byte[] P_array; |  | ||||||
|   private byte[] Q_array; |  | ||||||
|   private byte[] G_array; |  | ||||||
|   private byte[] pub_array; |  | ||||||
|   private byte[] prv_array; |  | ||||||
|  |  | ||||||
|   //private int key_size=0; |  | ||||||
|   private int key_size=1024; |  | ||||||
|  |  | ||||||
|   KeyPairDSA(JSch jsch){ |  | ||||||
|     this(jsch, null, null, null, null, null); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairDSA(JSch jsch, |  | ||||||
|                     byte[] P_array, |  | ||||||
|                     byte[] Q_array, |  | ||||||
|                     byte[] G_array, |  | ||||||
|                     byte[] pub_array, |  | ||||||
|                     byte[] prv_array){ |  | ||||||
|     super(jsch); |  | ||||||
|     this.P_array = P_array; |  | ||||||
|     this.Q_array = Q_array; |  | ||||||
|     this.G_array = G_array; |  | ||||||
|     this.pub_array = pub_array; |  | ||||||
|     this.prv_array = prv_array; |  | ||||||
|     if(P_array!=null) |  | ||||||
|       key_size = (new BigInteger(P_array)).bitLength(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   void generate(int key_size) throws JSchException{ |  | ||||||
|     this.key_size=key_size; |  | ||||||
|     try{ |  | ||||||
|       Class<? extends KeyPairGenDSA> c=Class.forName(JSch.getConfig("keypairgen.dsa")).asSubclass(KeyPairGenDSA.class); |  | ||||||
|       KeyPairGenDSA keypairgen=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       keypairgen.init(key_size); |  | ||||||
|       P_array=keypairgen.getP(); |  | ||||||
|       Q_array=keypairgen.getQ(); |  | ||||||
|       G_array=keypairgen.getG(); |  | ||||||
|       pub_array=keypairgen.getY(); |  | ||||||
|       prv_array=keypairgen.getX(); |  | ||||||
|  |  | ||||||
|       keypairgen=null; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("KeyPairDSA: "+e); |  | ||||||
|       throw new JSchException(e.toString(), e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] begin=Util.str2byte("-----BEGIN DSA PRIVATE KEY-----"); |  | ||||||
|   private static final byte[] end=Util.str2byte("-----END DSA PRIVATE KEY-----"); |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getBegin(){ return begin; } |  | ||||||
|   @Override |  | ||||||
|   byte[] getEnd(){ return end; } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getPrivateKey(){ |  | ||||||
|     int content= |  | ||||||
|       1+countLength(1) + 1 +                           // INTEGER |  | ||||||
|       1+countLength(P_array.length) + P_array.length + // INTEGER  P |  | ||||||
|       1+countLength(Q_array.length) + Q_array.length + // INTEGER  Q |  | ||||||
|       1+countLength(G_array.length) + G_array.length + // INTEGER  G |  | ||||||
|       1+countLength(pub_array.length) + pub_array.length + // INTEGER  pub |  | ||||||
|       1+countLength(prv_array.length) + prv_array.length;  // INTEGER  prv |  | ||||||
|  |  | ||||||
|     int total= |  | ||||||
|       1+countLength(content)+content;   // SEQUENCE |  | ||||||
|  |  | ||||||
|     byte[] plain=new byte[total]; |  | ||||||
|     int index=0; |  | ||||||
|     index=writeSEQUENCE(plain, index, content); |  | ||||||
|     index=writeINTEGER(plain, index, new byte[1]);  // 0 |  | ||||||
|     index=writeINTEGER(plain, index, P_array); |  | ||||||
|     index=writeINTEGER(plain, index, Q_array); |  | ||||||
|     index=writeINTEGER(plain, index, G_array); |  | ||||||
|     index=writeINTEGER(plain, index, pub_array); |  | ||||||
|     index=writeINTEGER(plain, index, prv_array); |  | ||||||
|     return plain; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   boolean parse(byte[] plain){ |  | ||||||
|     try{ |  | ||||||
|  |  | ||||||
|       if(vendor==VENDOR_FSECURE){ |  | ||||||
|         if(plain[0]!=0x30){              // FSecure |  | ||||||
|           Buffer buf=new Buffer(plain); |  | ||||||
|           buf.getInt(); |  | ||||||
|           P_array=buf.getMPIntBits(); |  | ||||||
|           G_array=buf.getMPIntBits(); |  | ||||||
|           Q_array=buf.getMPIntBits(); |  | ||||||
|           pub_array=buf.getMPIntBits(); |  | ||||||
|           prv_array=buf.getMPIntBits(); |  | ||||||
|           if(P_array!=null) |  | ||||||
|             key_size = (new BigInteger(P_array)).bitLength(); |  | ||||||
|           return true; |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|       else if(vendor==VENDOR_PUTTY){ |  | ||||||
|         Buffer buf=new Buffer(plain); |  | ||||||
|         buf.skip(plain.length); |  | ||||||
|  |  | ||||||
|         try { |  | ||||||
|           byte[][] tmp = buf.getBytes(1, ""); |  | ||||||
|           prv_array = tmp[0]; |  | ||||||
|         } |  | ||||||
|         catch(JSchException e){ |  | ||||||
|           return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       // OPENSSH Key v1 Format |  | ||||||
|       else if (vendor == VENDOR_OPENSSH_V1) { |  | ||||||
|  |  | ||||||
|         final Buffer prvKEyBuffer = new Buffer(plain); |  | ||||||
|         int checkInt1 = prvKEyBuffer.getInt(); // uint32 checkint1 |  | ||||||
|         int checkInt2 = prvKEyBuffer.getInt(); // uint32 checkint2 |  | ||||||
|         if (checkInt1 != checkInt2) { |  | ||||||
|           throw new JSchException("check failed"); |  | ||||||
|         } |  | ||||||
|         // The private key section contains both the public key and the private key |  | ||||||
|         String keyType = Util.byte2str(prvKEyBuffer.getString()); // string keytype |  | ||||||
|  |  | ||||||
|         P_array=prvKEyBuffer.getMPInt(); |  | ||||||
|         Q_array=prvKEyBuffer.getMPInt(); |  | ||||||
|         G_array= prvKEyBuffer.getMPInt(); |  | ||||||
|         pub_array=prvKEyBuffer.getMPInt(); |  | ||||||
|         prv_array=prvKEyBuffer.getMPInt(); |  | ||||||
|         publicKeyComment=Util.byte2str(prvKEyBuffer.getString()); |  | ||||||
|         //if(P_array!=null) key_size = (new BigInteger(P_array)).bitLength(); |  | ||||||
|         return true; |  | ||||||
|  |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       int index=0; |  | ||||||
|       int length=0; |  | ||||||
|  |  | ||||||
|       if(plain[index]!=0x30)return false; |  | ||||||
|       index++; // SEQUENCE |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if(plain[index]!=0x02)return false; |  | ||||||
|       index++; // INTEGER |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       P_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, P_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       Q_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, Q_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       G_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, G_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       pub_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, pub_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       prv_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, prv_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       if(P_array!=null) |  | ||||||
|         key_size = (new BigInteger(P_array)).bitLength(); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println(e); |  | ||||||
|       //e.printStackTrace(); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getPublicKeyBlob(){ |  | ||||||
|     byte[] foo=super.getPublicKeyBlob(); |  | ||||||
|     if(foo!=null) return foo; |  | ||||||
|  |  | ||||||
|     if(P_array==null) return null; |  | ||||||
|     byte[][] tmp = new byte[5][]; |  | ||||||
|     tmp[0] = sshdss; |  | ||||||
|     tmp[1] = P_array; |  | ||||||
|     tmp[2] = Q_array; |  | ||||||
|     tmp[3] = G_array; |  | ||||||
|     tmp[4] = pub_array; |  | ||||||
|     return Buffer.fromBytes(tmp).buffer; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] sshdss=Util.str2byte("ssh-dss"); |  | ||||||
|   @Override |  | ||||||
|   byte[] getKeyTypeName(){return sshdss;} |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){return DSA;} |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ |  | ||||||
|     return key_size; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureDSA> c=Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class); |  | ||||||
|       SignatureDSA dsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       dsa.init(); |  | ||||||
|       dsa.setPrvKey(prv_array, P_array, Q_array, G_array); |  | ||||||
|  |  | ||||||
|       dsa.update(data); |  | ||||||
|       byte[] sig = dsa.sign(); |  | ||||||
|       byte[][] tmp = new byte[2][]; |  | ||||||
|       tmp[0] = sshdss; |  | ||||||
|       tmp[1] = sig; |  | ||||||
|       return Buffer.fromBytes(tmp).buffer; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("e "+e); |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data, String alg){ |  | ||||||
|     return getSignature(data); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureDSA> c=Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class); |  | ||||||
|       SignatureDSA dsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       dsa.init(); |  | ||||||
|  |  | ||||||
|       if(pub_array == null && P_array == null && getPublicKeyBlob()!=null){ |  | ||||||
|         Buffer buf = new Buffer(getPublicKeyBlob()); |  | ||||||
|         buf.getString(); |  | ||||||
|         P_array = buf.getString(); |  | ||||||
|         Q_array = buf.getString(); |  | ||||||
|         G_array = buf.getString(); |  | ||||||
|         pub_array = buf.getString(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       dsa.setPubKey(pub_array, P_array, Q_array, G_array); |  | ||||||
|       return dsa; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("e "+e); |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(String alg){ |  | ||||||
|     return getVerifier(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException { |  | ||||||
|  |  | ||||||
|     byte[][] tmp = buf.getBytes(7, "invalid key format"); |  | ||||||
|  |  | ||||||
|     byte[] P_array = tmp[1]; |  | ||||||
|     byte[] Q_array = tmp[2]; |  | ||||||
|     byte[] G_array = tmp[3]; |  | ||||||
|     byte[] pub_array = tmp[4]; |  | ||||||
|     byte[] prv_array = tmp[5]; |  | ||||||
|     KeyPairDSA kpair = new KeyPairDSA(jsch, |  | ||||||
|                                       P_array, Q_array, G_array, |  | ||||||
|                                       pub_array, prv_array); |  | ||||||
|     kpair.publicKeyComment = Util.byte2str(tmp[6]); |  | ||||||
|     kpair.vendor=VENDOR_OPENSSH; |  | ||||||
|     return kpair; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] forSSHAgent() throws JSchException { |  | ||||||
|     if(isEncrypted()){ |  | ||||||
|       throw new JSchException("key is encrypted."); |  | ||||||
|     } |  | ||||||
|     Buffer buf = new Buffer(); |  | ||||||
|     buf.putString(sshdss); |  | ||||||
|     buf.putString(P_array); |  | ||||||
|     buf.putString(Q_array); |  | ||||||
|     buf.putString(G_array); |  | ||||||
|     buf.putString(pub_array); |  | ||||||
|     buf.putString(prv_array); |  | ||||||
|     buf.putString(Util.str2byte(publicKeyComment)); |  | ||||||
|     byte[] result = new byte[buf.getLength()]; |  | ||||||
|     buf.getByte(result, 0, result.length); |  | ||||||
|     return result; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void dispose(){ |  | ||||||
|     super.dispose(); |  | ||||||
|     Util.bzero(prv_array); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,163 +0,0 @@ | |||||||
| package com.jcraft.jsch; |  | ||||||
|  |  | ||||||
| import com.jcraft.jsch.jbcrypt.BCrypt; |  | ||||||
|  |  | ||||||
| import java.util.Arrays; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * A {@link KeyPair} which can only reveal its type and content after it was decrypted using {@link com.jcraft.jsch.KeyPairDeferred#decrypt(byte[])}. |  | ||||||
|  * This is needed for openssh-v1-private-key format. |  | ||||||
|  */ |  | ||||||
| class KeyPairDeferred extends KeyPair { |  | ||||||
|  |  | ||||||
|     private KeyPair delegate; |  | ||||||
|  |  | ||||||
|     KeyPairDeferred(JSch jsch) { |  | ||||||
|         super(jsch); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public boolean decrypt(String _passphrase) { |  | ||||||
|         return decrypt(Util.str2byte(_passphrase)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public boolean decrypt(byte[] _passphrase) { |  | ||||||
|         try { |  | ||||||
|             if (!isEncrypted()) { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|             if (_passphrase == null) { |  | ||||||
|                 jsch.getInstanceLogger().log(Logger.ERROR, "no passphrase set."); |  | ||||||
|                 return false; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             initCipher(_passphrase); |  | ||||||
|  |  | ||||||
|             byte[] plain = new byte[data.length]; |  | ||||||
|             cipher.update(data, 0, data.length, plain, 0); |  | ||||||
|  |  | ||||||
|             // now we have decrypted key and can determine type |  | ||||||
|             int type = readOpenSSHKeyv1(plain); |  | ||||||
|  |  | ||||||
|             delegate = getKeyPair(jsch, null, null, null, false, plain, getPublicKeyBlob(), type, VENDOR_OPENSSH_V1, publicKeyComment, cipher, null, null); |  | ||||||
|  |  | ||||||
|             return delegate != null; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         } catch (Exception e) { |  | ||||||
|             throw new IllegalArgumentException("Could not sucessfully decrypt openssh v1 key", e); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private void initCipher(byte[] _passphrase) throws Exception { |  | ||||||
|  |  | ||||||
|         // the encrypted private key is here: |  | ||||||
|         if ("bcrypt".equals(kdfName)) { |  | ||||||
|             Buffer opts = new Buffer(kdfOptions); |  | ||||||
|  |  | ||||||
|             byte[] keyiv = new byte[48]; |  | ||||||
|  |  | ||||||
|             new BCrypt().pbkdf(_passphrase, opts.getString(), opts.getInt(), keyiv); |  | ||||||
|  |  | ||||||
|             Arrays.fill(_passphrase, (byte) 0); |  | ||||||
|             byte[] key = Arrays.copyOfRange(keyiv, 0, 32); |  | ||||||
|             byte[] iv = Arrays.copyOfRange(keyiv, 32, 48); |  | ||||||
|             cipher.init(Cipher.DECRYPT_MODE, key, iv); |  | ||||||
|         } else { |  | ||||||
|             throw new IllegalStateException("No support for KDF '" + kdfName + "'."); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     void generate(int key_size) throws JSchException { |  | ||||||
|         throw new UnsupportedOperationException(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     byte[] getBegin() { |  | ||||||
|         return requireDecrypted(delegate).getBegin(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     byte[] getEnd() { |  | ||||||
|         return requireDecrypted(delegate).getEnd(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public int getKeySize() { |  | ||||||
|         return requireDecrypted(delegate).getKeySize(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public byte[] getSignature(byte[] data) { |  | ||||||
|         return requireDecrypted(delegate).getSignature(data); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public byte[] getSignature(byte[] data, String alg) { |  | ||||||
|         return requireDecrypted(delegate).getSignature(data, alg); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public Signature getVerifier() { |  | ||||||
|         return requireDecrypted(delegate).getVerifier(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public Signature getVerifier(String alg) { |  | ||||||
|         return requireDecrypted(delegate).getVerifier(alg); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public byte[] forSSHAgent() throws JSchException { |  | ||||||
|         return requireDecrypted(delegate).forSSHAgent(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     byte[] getPrivateKey() { |  | ||||||
|         return requireDecrypted(delegate).getPrivateKey(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     byte[] getKeyTypeName() { |  | ||||||
|         return requireDecrypted(delegate).getKeyTypeName(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public int getKeyType() { |  | ||||||
|         return requireDecrypted(delegate).getKeyType(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     boolean parse(byte[] data) { |  | ||||||
|         return requireDecrypted(delegate).parse(data); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public byte[] getPublicKeyBlob() { |  | ||||||
|         return delegate != null ? delegate.getPublicKeyBlob() : null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public String getPublicKeyComment() { |  | ||||||
|         return requireDecrypted(delegate).getPublicKeyComment(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public String getFingerPrint() { |  | ||||||
|         return requireDecrypted(delegate).getFingerPrint(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public boolean isEncrypted() { |  | ||||||
|         return delegate != null ? delegate.isEncrypted() : super.isEncrypted(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private <T> T requireDecrypted(T obj) { |  | ||||||
|         if (obj == null) |  | ||||||
|             throw new IllegalStateException("encrypted key has not been decrypted yet."); |  | ||||||
|         return obj; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,467 +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; |  | ||||||
|  |  | ||||||
| import java.util.Arrays; |  | ||||||
|  |  | ||||||
| class KeyPairECDSA extends KeyPair{ |  | ||||||
|  |  | ||||||
|   private static byte[][] oids = { |  | ||||||
|     {(byte)0x06, (byte)0x08, (byte)0x2a, (byte)0x86, (byte)0x48, // 256 |  | ||||||
|      (byte)0xce, (byte)0x3d, (byte)0x03, (byte)0x01, (byte)0x07}, |  | ||||||
|     {(byte)0x06, (byte)0x05, (byte)0x2b, (byte)0x81, (byte)0x04, // 384 |  | ||||||
|      (byte)0x00, (byte)0x22}, |  | ||||||
|     {(byte)0x06, (byte)0x05, (byte)0x2b, (byte)0x81, (byte)0x04, //521 |  | ||||||
|      (byte)0x00, (byte)0x23}, |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static String[] names = { |  | ||||||
|     "nistp256", "nistp384", "nistp521" |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private byte[] name=Util.str2byte(names[0]); |  | ||||||
|   private byte[] r_array; |  | ||||||
|   private byte[] s_array; |  | ||||||
|   private byte[] prv_array; |  | ||||||
|  |  | ||||||
|   private int key_size=256; |  | ||||||
|  |  | ||||||
|   KeyPairECDSA(JSch jsch){ |  | ||||||
|     this(jsch, null, null, null, null); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairECDSA(JSch jsch , byte[] pubkey){ |  | ||||||
|     this(jsch, null, null, null, null); |  | ||||||
|  |  | ||||||
|     if(pubkey!=null){ |  | ||||||
|       byte[] name = new byte[8]; |  | ||||||
|       System.arraycopy(pubkey, 11, name, 0, 8); |  | ||||||
|       if(Util.array_equals(name, Util.str2byte("nistp384"))){ |  | ||||||
|         key_size=384; |  | ||||||
|         this.name=name; |  | ||||||
|       } |  | ||||||
|       if(Util.array_equals(name, Util.str2byte("nistp521"))){ |  | ||||||
|         key_size=521; |  | ||||||
|         this.name=name; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairECDSA(JSch jsch, |  | ||||||
|                       byte[] name, |  | ||||||
|                       byte[] r_array, |  | ||||||
|                       byte[] s_array, |  | ||||||
|                       byte[] prv_array){ |  | ||||||
|     super(jsch); |  | ||||||
|     if(name!=null) |  | ||||||
|       this.name = name; |  | ||||||
|     this.r_array = r_array; |  | ||||||
|     this.s_array = s_array; |  | ||||||
|     this.prv_array = prv_array; |  | ||||||
|     if(prv_array!=null) |  | ||||||
|       key_size = prv_array.length>=64 ? 521 : |  | ||||||
|                   (prv_array.length>=48 ? 384 : 256); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   void generate(int key_size) throws JSchException{ |  | ||||||
|     this.key_size=key_size; |  | ||||||
|     try{ |  | ||||||
|       Class<? extends KeyPairGenECDSA> c=Class.forName(JSch.getConfig("keypairgen.ecdsa")).asSubclass(KeyPairGenECDSA.class); |  | ||||||
|       KeyPairGenECDSA keypairgen=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       keypairgen.init(key_size); |  | ||||||
|       prv_array=keypairgen.getD(); |  | ||||||
|       r_array=keypairgen.getR(); |  | ||||||
|       s_array=keypairgen.getS(); |  | ||||||
|       name=Util.str2byte(names[prv_array.length>=64 ? 2 : |  | ||||||
|                                (prv_array.length>=48 ? 1 : 0)]); |  | ||||||
|       keypairgen=null; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       throw new JSchException(e.toString(), e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] begin = |  | ||||||
|     Util.str2byte("-----BEGIN EC PRIVATE KEY-----"); |  | ||||||
|   private static final byte[] end = |  | ||||||
|     Util.str2byte("-----END EC PRIVATE KEY-----"); |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getBegin(){ return begin; } |  | ||||||
|   @Override |  | ||||||
|   byte[] getEnd(){ return end; } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getPrivateKey(){ |  | ||||||
|  |  | ||||||
|     byte[] tmp = new byte[1]; tmp[0]=1; |  | ||||||
|  |  | ||||||
|     byte[] oid = oids[ |  | ||||||
|                       (r_array.length>=64) ? 2 : |  | ||||||
|                        ((r_array.length>=48) ? 1 : 0) |  | ||||||
|                      ]; |  | ||||||
|  |  | ||||||
|     byte[] point = toPoint(r_array, s_array); |  | ||||||
|  |  | ||||||
|     int bar = ((point.length+1)&0x80)==0 ? 3 : 4; |  | ||||||
|     byte[] foo = new byte[point.length+bar]; |  | ||||||
|     System.arraycopy(point, 0, foo, bar, point.length); |  | ||||||
|     foo[0]=0x03;                     // BITSTRING |  | ||||||
|     if(bar==3){ |  | ||||||
|       foo[1]=(byte)(point.length+1); |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|       foo[1]=(byte)0x81; |  | ||||||
|       foo[2]=(byte)(point.length+1); |  | ||||||
|     } |  | ||||||
|     point = foo; |  | ||||||
|  |  | ||||||
|     int content= |  | ||||||
|       1+countLength(tmp.length) + tmp.length + |  | ||||||
|       1+countLength(prv_array.length) + prv_array.length + |  | ||||||
|       1+countLength(oid.length) + oid.length + |  | ||||||
|       1+countLength(point.length) + point.length; |  | ||||||
|  |  | ||||||
|     int total= |  | ||||||
|       1+countLength(content)+content;   // SEQUENCE |  | ||||||
|  |  | ||||||
|     byte[] plain=new byte[total]; |  | ||||||
|     int index=0; |  | ||||||
|     index=writeSEQUENCE(plain, index, content); |  | ||||||
|     index=writeINTEGER(plain, index, tmp); |  | ||||||
|     index=writeOCTETSTRING(plain, index, prv_array); |  | ||||||
|     index=writeDATA(plain, (byte)0xa0, index, oid); |  | ||||||
|     index=writeDATA(plain, (byte)0xa1, index, point); |  | ||||||
|  |  | ||||||
|     return plain; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   boolean parse(byte[] plain){ |  | ||||||
|     try{ |  | ||||||
|  |  | ||||||
|       if(vendor==VENDOR_FSECURE){ |  | ||||||
|         /* |  | ||||||
|         if(plain[0]!=0x30){              // FSecure |  | ||||||
|           return true; |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|         */ |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|       else if(vendor==VENDOR_PUTTY){ |  | ||||||
|         /* |  | ||||||
|         Buffer buf=new Buffer(plain); |  | ||||||
|         buf.skip(plain.length); |  | ||||||
|  |  | ||||||
|         try { |  | ||||||
|           byte[][] tmp = buf.getBytes(1, ""); |  | ||||||
|           prv_array = tmp[0]; |  | ||||||
|         } |  | ||||||
|         catch(JSchException e){ |  | ||||||
|           return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|         */ |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       // OPENSSH Key v1 Format |  | ||||||
|       if (vendor == VENDOR_OPENSSH_V1) { |  | ||||||
|  |  | ||||||
|         final Buffer prvKeyBuffer = new Buffer(plain); |  | ||||||
|         int checkInt1 = prvKeyBuffer.getInt(); // uint32 checkint1 |  | ||||||
|         int checkInt2 = prvKeyBuffer.getInt(); // uint32 checkint2 |  | ||||||
|         if (checkInt1 != checkInt2) { |  | ||||||
|           throw new JSchException("check failed"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         String keyType = Util.byte2str(prvKeyBuffer.getString()); // string keytype |  | ||||||
|  |  | ||||||
|         name = prvKeyBuffer.getString(); |  | ||||||
|         if(!Arrays.asList(names).contains(Util.byte2str(name))){ |  | ||||||
|           throw new IllegalArgumentException("unknown curve name "+Util.byte2str(name)); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         final int keyLen = prvKeyBuffer.getInt(); |  | ||||||
|         final int x04 = prvKeyBuffer.getByte(); // in case of x04 it is uncompressed https://tools.ietf.org/html/rfc5480#page-7 |  | ||||||
|         final byte[] x = new byte[(keyLen - 1) / 2]; |  | ||||||
|         final byte[] y = new byte[(keyLen - 1) / 2]; |  | ||||||
|         prvKeyBuffer.getByte(x); |  | ||||||
|         prvKeyBuffer.getByte(y); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         prv_array=prvKeyBuffer.getString(); |  | ||||||
|         publicKeyComment=Util.byte2str(prvKeyBuffer.getString()); |  | ||||||
|         r_array = x; |  | ||||||
|         s_array = y; |  | ||||||
|         key_size = x.length>=64 ? 521 : |  | ||||||
|                 (x.length>=48 ? 384 : 256); |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|  |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       int index=0; |  | ||||||
|       int length=0; |  | ||||||
|  |  | ||||||
|       if(plain[index]!=0x30)return false; |  | ||||||
|       index++; // SEQUENCE |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if(plain[index]!=0x02)return false; |  | ||||||
|       index++; // INTEGER |  | ||||||
|  |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       index+=length; |  | ||||||
|       index++;   // 0x04 |  | ||||||
|  |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       prv_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, prv_array, 0, length); |  | ||||||
|  |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++;  // 0xa0 |  | ||||||
|  |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       byte[] oid_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, oid_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       for(int i = 0; i<oids.length; i++){ |  | ||||||
|         if(Util.array_equals(oids[i], oid_array)){ |  | ||||||
|           name = Util.str2byte(names[i]); |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       index++;  // 0xa1 |  | ||||||
|  |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       byte[] Q_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, Q_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       byte[][] tmp = fromPoint(Q_array); |  | ||||||
|       r_array = tmp[0]; |  | ||||||
|       s_array = tmp[1]; |  | ||||||
|  |  | ||||||
|       if(prv_array!=null) |  | ||||||
|         key_size = prv_array.length>=64 ? 521 : |  | ||||||
|                     (prv_array.length>=48 ? 384 : 256); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println(e); |  | ||||||
|       //e.printStackTrace(); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getPublicKeyBlob(){ |  | ||||||
|     byte[] foo = super.getPublicKeyBlob(); |  | ||||||
|  |  | ||||||
|     if(foo!=null) return foo; |  | ||||||
|  |  | ||||||
|     if(r_array==null) return null; |  | ||||||
|  |  | ||||||
|     byte[][] tmp = new byte[3][]; |  | ||||||
|     tmp[0] = Util.str2byte("ecdsa-sha2-"+Util.byte2str(name)); |  | ||||||
|     tmp[1] = name; |  | ||||||
|     tmp[2] = new byte[1+r_array.length+s_array.length]; |  | ||||||
|     tmp[2][0] = 4;   // POINT_CONVERSION_UNCOMPRESSED |  | ||||||
|     System.arraycopy(r_array, 0, tmp[2], 1, r_array.length); |  | ||||||
|     System.arraycopy(s_array, 0, tmp[2], 1+r_array.length, s_array.length); |  | ||||||
|  |  | ||||||
|     return Buffer.fromBytes(tmp).buffer; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getKeyTypeName(){ |  | ||||||
|     return Util.str2byte("ecdsa-sha2-"+Util.byte2str(name)); |  | ||||||
|   } |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){ |  | ||||||
|     return ECDSA; |  | ||||||
|   } |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ |  | ||||||
|     return key_size; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureECDSA> c=Class.forName(JSch.getConfig("ecdsa-sha2-"+Util.byte2str(name))).asSubclass(SignatureECDSA.class); |  | ||||||
|       SignatureECDSA ecdsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       ecdsa.init(); |  | ||||||
|       ecdsa.setPrvKey(prv_array); |  | ||||||
|  |  | ||||||
|       ecdsa.update(data); |  | ||||||
|       byte[] sig = ecdsa.sign(); |  | ||||||
|  |  | ||||||
|       byte[][] tmp = new byte[2][]; |  | ||||||
|       tmp[0] = Util.str2byte("ecdsa-sha2-"+Util.byte2str(name)); |  | ||||||
|       tmp[1] = sig; |  | ||||||
|       return Buffer.fromBytes(tmp).buffer; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("e "+e); |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data, String al){ |  | ||||||
|     return getSignature(data); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureECDSA> c=Class.forName(JSch.getConfig("ecdsa-sha2-"+Util.byte2str(name))).asSubclass(SignatureECDSA.class); |  | ||||||
|       final SignatureECDSA ecdsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       ecdsa.init(); |  | ||||||
|  |  | ||||||
|       if(r_array == null && s_array == null && getPublicKeyBlob()!=null){ |  | ||||||
|         Buffer buf = new Buffer(getPublicKeyBlob()); |  | ||||||
|         buf.getString();    // ecdsa-sha2-nistp256 |  | ||||||
|         buf.getString();    // nistp256 |  | ||||||
|         byte[][] tmp = fromPoint(buf.getString()); |  | ||||||
|         r_array = tmp[0]; |  | ||||||
|         s_array = tmp[1]; |  | ||||||
|       } |  | ||||||
|       ecdsa.setPubKey(r_array, s_array); |  | ||||||
|       return ecdsa; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("e "+e); |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(String alg){ |  | ||||||
|     return getVerifier(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException { |  | ||||||
|  |  | ||||||
|     byte[][] tmp = buf.getBytes(5, "invalid key format"); |  | ||||||
|  |  | ||||||
|     byte[] name = tmp[1];       // nistp256 |  | ||||||
|     byte[][] foo = fromPoint(tmp[2]); |  | ||||||
|     byte[] r_array = foo[0]; |  | ||||||
|     byte[] s_array = foo[1]; |  | ||||||
|  |  | ||||||
|     byte[] prv_array = tmp[3]; |  | ||||||
|     KeyPairECDSA kpair = new KeyPairECDSA(jsch, |  | ||||||
|                                           name, |  | ||||||
|                                           r_array, s_array, |  | ||||||
|                                           prv_array); |  | ||||||
|     kpair.publicKeyComment = Util.byte2str(tmp[4]); |  | ||||||
|     kpair.vendor=VENDOR_OPENSSH; |  | ||||||
|     return kpair; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] forSSHAgent() throws JSchException { |  | ||||||
|     if(isEncrypted()){ |  | ||||||
|       throw new JSchException("key is encrypted."); |  | ||||||
|     } |  | ||||||
|     Buffer buf = new Buffer(); |  | ||||||
|     buf.putString(Util.str2byte("ecdsa-sha2-"+Util.byte2str(name))); |  | ||||||
|     buf.putString(name); |  | ||||||
|     buf.putString(toPoint(r_array, s_array)); |  | ||||||
|     buf.putString(prv_array); |  | ||||||
|     buf.putString(Util.str2byte(publicKeyComment)); |  | ||||||
|     byte[] result = new byte[buf.getLength()]; |  | ||||||
|     buf.getByte(result, 0, result.length); |  | ||||||
|     return result; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static byte[] toPoint(byte[] r_array, byte[] s_array) { |  | ||||||
|     byte[] tmp = new byte[1+r_array.length+s_array.length]; |  | ||||||
|     tmp[0]=0x04; |  | ||||||
|     System.arraycopy(r_array, 0, tmp, 1, r_array.length); |  | ||||||
|     System.arraycopy(s_array, 0, tmp, 1+r_array.length, s_array.length); |  | ||||||
|     return tmp; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static byte[][] fromPoint(byte[] point) { |  | ||||||
|     int i = 0; |  | ||||||
|     while(point[i]!=4) i++; |  | ||||||
|     i++; |  | ||||||
|     byte[][] tmp = new byte[2][]; |  | ||||||
|     byte[] r_array = new byte[(point.length-i)/2]; |  | ||||||
|     byte[] s_array = new byte[(point.length-i)/2]; |  | ||||||
|     // point[0] == 0x04 == POINT_CONVERSION_UNCOMPRESSED |  | ||||||
|     System.arraycopy(point, i, r_array, 0, r_array.length); |  | ||||||
|     System.arraycopy(point, i+r_array.length, s_array, 0, s_array.length); |  | ||||||
|     tmp[0] = r_array; |  | ||||||
|     tmp[1] = s_array; |  | ||||||
|  |  | ||||||
|     return tmp; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void dispose(){ |  | ||||||
|     super.dispose(); |  | ||||||
|     Util.bzero(prv_array); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,68 +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.Arrays; |  | ||||||
|  |  | ||||||
| class KeyPairEd25519 extends KeyPairEdDSA{ |  | ||||||
|  |  | ||||||
|   private static int keySize = 32; |  | ||||||
|  |  | ||||||
|   KeyPairEd25519(JSch jsch){ |  | ||||||
|     this(jsch, null, null); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairEd25519(JSch jsch, |  | ||||||
|                     byte[] pub_array, |  | ||||||
|                     byte[] prv_array){ |  | ||||||
|     super(jsch, pub_array, prv_array); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){ return ED25519; } |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ return keySize; } |  | ||||||
|   @Override |  | ||||||
|   String getSshName(){ return "ssh-ed25519"; } |  | ||||||
|   @Override |  | ||||||
|   String getJceName(){ return "Ed25519"; } |  | ||||||
|  |  | ||||||
|   static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException { |  | ||||||
|  |  | ||||||
|     byte[][] tmp = buf.getBytes(4, "invalid key format"); |  | ||||||
|  |  | ||||||
|     byte[] pub_array = tmp[1]; |  | ||||||
|     byte[] prv_array = Arrays.copyOf(tmp[2], keySize); |  | ||||||
|     KeyPairEd25519 kpair = new KeyPairEd25519(jsch, pub_array, prv_array); |  | ||||||
|     kpair.publicKeyComment = Util.byte2str(tmp[3]); |  | ||||||
|     kpair.vendor=VENDOR_OPENSSH; |  | ||||||
|     return kpair; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,68 +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.Arrays; |  | ||||||
|  |  | ||||||
| class KeyPairEd448 extends KeyPairEdDSA{ |  | ||||||
|  |  | ||||||
|   private static int keySize = 57; |  | ||||||
|  |  | ||||||
|   KeyPairEd448(JSch jsch){ |  | ||||||
|     this(jsch, null, null); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairEd448(JSch jsch, |  | ||||||
|                     byte[] pub_array, |  | ||||||
|                     byte[] prv_array){ |  | ||||||
|     super(jsch, pub_array, prv_array); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){ return ED448; } |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ return keySize; } |  | ||||||
|   @Override |  | ||||||
|   String getSshName(){ return "ssh-ed448"; } |  | ||||||
|   @Override |  | ||||||
|   String getJceName(){ return "Ed448"; } |  | ||||||
|  |  | ||||||
|   static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException { |  | ||||||
|  |  | ||||||
|     byte[][] tmp = buf.getBytes(4, "invalid key format"); |  | ||||||
|  |  | ||||||
|     byte[] pub_array = tmp[1]; |  | ||||||
|     byte[] prv_array = Arrays.copyOf(tmp[2], keySize); |  | ||||||
|     KeyPairEd448 kpair = new KeyPairEd448(jsch, pub_array, prv_array); |  | ||||||
|     kpair.publicKeyComment = Util.byte2str(tmp[3]); |  | ||||||
|     kpair.vendor=VENDOR_OPENSSH; |  | ||||||
|     return kpair; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,191 +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.Arrays; |  | ||||||
|  |  | ||||||
| abstract class KeyPairEdDSA extends KeyPair{ |  | ||||||
|   private byte[] pub_array; |  | ||||||
|   private byte[] prv_array; |  | ||||||
|  |  | ||||||
|   KeyPairEdDSA(JSch jsch, |  | ||||||
|                     byte[] pub_array, |  | ||||||
|                     byte[] prv_array){ |  | ||||||
|     super(jsch); |  | ||||||
|     this.pub_array = pub_array; |  | ||||||
|     this.prv_array = prv_array; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   abstract String getSshName(); |  | ||||||
|   abstract String getJceName(); |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   void generate(int key_size) throws JSchException{ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends KeyPairGenEdDSA> c=Class.forName(JSch.getConfig("keypairgen.eddsa")).asSubclass(KeyPairGenEdDSA.class); |  | ||||||
|       KeyPairGenEdDSA keypairgen=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       keypairgen.init(getJceName(), getKeySize()); |  | ||||||
|       pub_array=keypairgen.getPub(); |  | ||||||
|       prv_array=keypairgen.getPrv(); |  | ||||||
|  |  | ||||||
|       keypairgen=null; |  | ||||||
|     } |  | ||||||
|     catch(Exception | NoClassDefFoundError e){ |  | ||||||
|       //System.err.println("KeyPairEdDSA: "+e); |  | ||||||
|       throw new JSchException(e.toString(), e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   // These methods appear to be for writing keys to a file. |  | ||||||
|   // And since writing VENDOR_OPENSSH_V1 isn't supported yet, have these methods fail. |  | ||||||
|   @Override |  | ||||||
|   byte[] getBegin(){ throw new UnsupportedOperationException(); } |  | ||||||
|   @Override |  | ||||||
|   byte[] getEnd(){ throw new UnsupportedOperationException(); } |  | ||||||
|   @Override |  | ||||||
|   byte[] getPrivateKey(){ throw new UnsupportedOperationException(); } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   boolean parse(byte [] plain){ |  | ||||||
|  |  | ||||||
|     // Only OPENSSH Key v1 Format supported for EdDSA keys |  | ||||||
|     if(vendor != VENDOR_OPENSSH_V1) return false; |  | ||||||
|     try{ |  | ||||||
|       // OPENSSH Key v1 Format |  | ||||||
|       final Buffer buf = new Buffer(plain); |  | ||||||
|       int checkInt1 = buf.getInt(); // uint32 checkint1 |  | ||||||
|       int checkInt2 = buf.getInt(); // uint32 checkint2 |  | ||||||
|       if (checkInt1 != checkInt2) { |  | ||||||
|         throw new JSchException("check failed"); |  | ||||||
|       } |  | ||||||
|       String keyType = Util.byte2str(buf.getString()); // string keytype |  | ||||||
|       pub_array = buf.getString(); // public key |  | ||||||
|       // OpenSSH stores private key in first half of string and duplicate copy of public key in second half of string |  | ||||||
|       byte[] tmp = buf.getString(); // secret key (private key + public key) |  | ||||||
|       prv_array = Arrays.copyOf(tmp, getKeySize()); |  | ||||||
|       publicKeyComment = Util.byte2str(buf.getString()); |  | ||||||
|       return true; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println(e); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getPublicKeyBlob(){ |  | ||||||
|     byte[] foo=super.getPublicKeyBlob(); |  | ||||||
|     if(foo!=null) return foo; |  | ||||||
|  |  | ||||||
|     if(pub_array==null) return null; |  | ||||||
|     byte[][] tmp = new byte[2][]; |  | ||||||
|     tmp[0] = getKeyTypeName(); |  | ||||||
|     tmp[1] = pub_array; |  | ||||||
|     return Buffer.fromBytes(tmp).buffer; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getKeyTypeName(){ return Util.str2byte(getSshName()); } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data){ |  | ||||||
|     return getSignature(data, getSshName()); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data, String alg){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureEdDSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureEdDSA.class); |  | ||||||
|       SignatureEdDSA eddsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       eddsa.init(); |  | ||||||
|       eddsa.setPrvKey(prv_array); |  | ||||||
|  |  | ||||||
|       eddsa.update(data); |  | ||||||
|       byte[] sig = eddsa.sign(); |  | ||||||
|       byte[][] tmp = new byte[2][]; |  | ||||||
|       tmp[0] = Util.str2byte(alg); |  | ||||||
|       tmp[1] = sig; |  | ||||||
|       return Buffer.fromBytes(tmp).buffer; |  | ||||||
|     } |  | ||||||
|     catch(Exception | NoClassDefFoundError e){ |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(){ |  | ||||||
|     return getVerifier(getSshName()); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(String alg){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureEdDSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureEdDSA.class); |  | ||||||
|       SignatureEdDSA eddsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       eddsa.init(); |  | ||||||
|  |  | ||||||
|       if(pub_array == null && getPublicKeyBlob()!=null){ |  | ||||||
|         Buffer buf = new Buffer(getPublicKeyBlob()); |  | ||||||
|         buf.getString(); |  | ||||||
|         pub_array = buf.getString(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       eddsa.setPubKey(pub_array); |  | ||||||
|       return eddsa; |  | ||||||
|     } |  | ||||||
|     catch(Exception | NoClassDefFoundError e){ |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] forSSHAgent() throws JSchException { |  | ||||||
|     if(isEncrypted()){ |  | ||||||
|       throw new JSchException("key is encrypted."); |  | ||||||
|     } |  | ||||||
|     Buffer buf = new Buffer(); |  | ||||||
|     buf.putString(getKeyTypeName()); |  | ||||||
|     buf.putString(pub_array); |  | ||||||
|     byte[] tmp = new byte[prv_array.length + pub_array.length]; |  | ||||||
|     System.arraycopy(prv_array, 0, tmp, 0, prv_array.length); |  | ||||||
|     System.arraycopy(pub_array, 0, tmp, prv_array.length, pub_array.length); |  | ||||||
|     buf.putString(tmp); |  | ||||||
|     buf.putString(Util.str2byte(publicKeyComment)); |  | ||||||
|     byte[] result = new byte[buf.getLength()]; |  | ||||||
|     buf.getByte(result, 0, result.length); |  | ||||||
|     return result; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void dispose(){ |  | ||||||
|     super.dispose(); |  | ||||||
|     Util.bzero(prv_array); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,39 +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 KeyPairGenDSA{ |  | ||||||
|   void init(int key_size) throws Exception; |  | ||||||
|   byte[] getX(); |  | ||||||
|   byte[] getY(); |  | ||||||
|   byte[] getP(); |  | ||||||
|   byte[] getQ(); |  | ||||||
|   byte[] getG(); |  | ||||||
| } |  | ||||||
| @@ -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 KeyPairGenECDSA{ |  | ||||||
|   void init(int key_size) throws Exception; |  | ||||||
|   byte[] getD(); |  | ||||||
|   byte[] getR(); |  | ||||||
|   byte[] getS(); |  | ||||||
| } |  | ||||||
| @@ -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; |  | ||||||
|  |  | ||||||
| public interface KeyPairGenEdDSA{ |  | ||||||
|   void init(String Name, int keylen) throws Exception; |  | ||||||
|   byte[] getPub(); |  | ||||||
|   byte[] getPrv(); |  | ||||||
| } |  | ||||||
| @@ -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 KeyPairGenRSA{ |  | ||||||
|   void init(int key_size) throws Exception; |  | ||||||
|   byte[] getD(); |  | ||||||
|   byte[] getE(); |  | ||||||
|   byte[] getN(); |  | ||||||
|  |  | ||||||
|   byte[] getC(); |  | ||||||
|   byte[] getEP(); |  | ||||||
|   byte[] getEQ(); |  | ||||||
|   byte[] getP(); |  | ||||||
|   byte[] getQ(); |  | ||||||
| } |  | ||||||
| @@ -1,34 +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 KeyPairGenXEC{ |  | ||||||
|   void init(String name) throws Exception; |  | ||||||
| } |  | ||||||
| @@ -1,386 +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; |  | ||||||
|  |  | ||||||
| import java.util.Vector; |  | ||||||
| import java.math.BigInteger; |  | ||||||
|  |  | ||||||
| class KeyPairPKCS8 extends KeyPair { |  | ||||||
|   private static final byte[] rsaEncryption = { |  | ||||||
|     (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, |  | ||||||
|     (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01 |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] dsaEncryption = { |  | ||||||
|     (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0xce, |  | ||||||
|     (byte)0x38, (byte)0x04, (byte)0x1 |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] pbes2 = { |  | ||||||
|     (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, |  | ||||||
|     (byte)0x0d, (byte)0x01, (byte)0x05, (byte)0x0d  |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] pbkdf2 = { |  | ||||||
|     (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, |  | ||||||
|     (byte)0x0d, (byte)0x01, (byte)0x05, (byte)0x0c  |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] aes128cbc = { |  | ||||||
|     (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, |  | ||||||
|     (byte)0x03, (byte)0x04, (byte)0x01, (byte)0x02  |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] aes192cbc = { |  | ||||||
|     (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, |  | ||||||
|     (byte)0x03, (byte)0x04, (byte)0x01, (byte)0x16  |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] aes256cbc = { |  | ||||||
|     (byte)0x60, (byte)0x86, (byte)0x48, (byte)0x01, (byte)0x65, |  | ||||||
|     (byte)0x03, (byte)0x04, (byte)0x01, (byte)0x2a  |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private static final byte[] pbeWithMD5AndDESCBC = { |  | ||||||
|     (byte)0x2a, (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, |  | ||||||
|     (byte)0x0d, (byte)0x01, (byte)0x05, (byte)0x03 |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   private KeyPair kpair = null; |  | ||||||
|  |  | ||||||
|   KeyPairPKCS8(JSch jsch){ |  | ||||||
|     super(jsch); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   void generate(int key_size) throws JSchException{ |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] begin=Util.str2byte("-----BEGIN DSA PRIVATE KEY-----"); |  | ||||||
|   private static final byte[] end=Util.str2byte("-----END DSA PRIVATE KEY-----"); |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getBegin(){ return begin; } |  | ||||||
|   @Override |  | ||||||
|   byte[] getEnd(){ return end; } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getPrivateKey(){ |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   boolean parse(byte[] plain){ |  | ||||||
|  |  | ||||||
|     /* from RFC5208 |  | ||||||
|       PrivateKeyInfo ::= SEQUENCE { |  | ||||||
|         version                   Version, |  | ||||||
|         privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier, |  | ||||||
|         privateKey                PrivateKey, |  | ||||||
|         attributes           [0]  IMPLICIT Attributes OPTIONAL  |  | ||||||
|       } |  | ||||||
|       Version ::= INTEGER |  | ||||||
|       PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier |  | ||||||
|       PrivateKey ::= OCTET STRING |  | ||||||
|       Attributes ::= SET OF Attribute |  | ||||||
|     } |  | ||||||
|     */ |  | ||||||
|  |  | ||||||
|     try{ |  | ||||||
|       Vector<byte[]> values = new Vector<>(); |  | ||||||
|  |  | ||||||
|       ASN1[] contents = null; |  | ||||||
|       ASN1 asn1 = new ASN1(plain); |  | ||||||
|       contents = asn1.getContents(); |  | ||||||
|  |  | ||||||
|       ASN1 privateKeyAlgorithm = contents[1]; |  | ||||||
|       ASN1 privateKey = contents[2]; |  | ||||||
|  |  | ||||||
|       contents = privateKeyAlgorithm.getContents(); |  | ||||||
|       byte[] privateKeyAlgorithmID = contents[0].getContent(); |  | ||||||
|       contents = contents[1].getContents(); |  | ||||||
|       if(contents.length>0){ |  | ||||||
|         for(int i = 0; i < contents.length; i++){ |  | ||||||
|           values.addElement(contents[i].getContent()); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       byte[] _data = privateKey.getContent(); |  | ||||||
|  |  | ||||||
|       KeyPair _kpair = null; |  | ||||||
|       if(Util.array_equals(privateKeyAlgorithmID, rsaEncryption)){ |  | ||||||
|         _kpair = new KeyPairRSA(jsch); |  | ||||||
|         _kpair.copy(this); |  | ||||||
|         if(_kpair.parse(_data)){ |  | ||||||
|           kpair = _kpair; |  | ||||||
|         }  |  | ||||||
|       } |  | ||||||
|       else if(Util.array_equals(privateKeyAlgorithmID, dsaEncryption)){ |  | ||||||
|         asn1 = new ASN1(_data); |  | ||||||
|         if(values.size() == 0) {  // embedded DSA parameters format |  | ||||||
|           /* |  | ||||||
|              SEQUENCE |  | ||||||
|                SEQUENCE |  | ||||||
|                  INTEGER    // P_array |  | ||||||
|                  INTEGER    // Q_array |  | ||||||
|                  INTEGER    // G_array |  | ||||||
|                INTEGER      // prv_array |  | ||||||
|           */ |  | ||||||
|           contents = asn1.getContents(); |  | ||||||
|           byte[] bar = contents[1].getContent(); |  | ||||||
|           contents = contents[0].getContents(); |  | ||||||
|           for(int i = 0; i < contents.length; i++){ |  | ||||||
|             values.addElement(contents[i].getContent()); |  | ||||||
|           } |  | ||||||
|           values.addElement(bar); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|           /* |  | ||||||
|              INTEGER      // prv_array |  | ||||||
|           */ |  | ||||||
|           values.addElement(asn1.getContent()); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         byte[] P_array = values.elementAt(0); |  | ||||||
|         byte[] Q_array = values.elementAt(1); |  | ||||||
|         byte[] G_array = values.elementAt(2); |  | ||||||
|         byte[] prv_array = values.elementAt(3); |  | ||||||
|         // Y = g^X mode p |  | ||||||
|         byte[] pub_array = |  | ||||||
|           (new BigInteger(G_array)). |  | ||||||
|             modPow(new BigInteger(prv_array), new BigInteger(P_array)). |  | ||||||
|             toByteArray(); |  | ||||||
|  |  | ||||||
|         KeyPairDSA _key = new KeyPairDSA(jsch, |  | ||||||
|                                          P_array, Q_array, G_array, |  | ||||||
|                                          pub_array, prv_array); |  | ||||||
|         plain = _key.getPrivateKey(); |  | ||||||
|  |  | ||||||
|         _kpair = new KeyPairDSA(jsch); |  | ||||||
|         _kpair.copy(this); |  | ||||||
|         if(_kpair.parse(plain)){ |  | ||||||
|           kpair = _kpair; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     catch(ASN1Exception e){ |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println(e); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     return kpair != null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getPublicKeyBlob(){ |  | ||||||
|     return kpair.getPublicKeyBlob(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getKeyTypeName(){ return kpair.getKeyTypeName();} |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){return kpair.getKeyType();} |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ |  | ||||||
|     return kpair.getKeySize(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data){ |  | ||||||
|     return kpair.getSignature(data); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data, String alg){ |  | ||||||
|     return kpair.getSignature(data, alg); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(){ |  | ||||||
|     return kpair.getVerifier(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(String alg){ |  | ||||||
|     return kpair.getVerifier(alg); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] forSSHAgent() throws JSchException { |  | ||||||
|     return kpair.forSSHAgent(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public boolean decrypt(byte[] _passphrase){ |  | ||||||
|     if(!isEncrypted()){ |  | ||||||
|       return true; |  | ||||||
|     } |  | ||||||
|     if(_passphrase==null){ |  | ||||||
|       return !isEncrypted(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /* |  | ||||||
|       SEQUENCE |  | ||||||
|         SEQUENCE |  | ||||||
|           OBJECT            :PBES2 |  | ||||||
|           SEQUENCE |  | ||||||
|             SEQUENCE |  | ||||||
|               OBJECT            :PBKDF2 |  | ||||||
|               SEQUENCE |  | ||||||
|                 OCTET STRING      [HEX DUMP]:E4E24ADC9C00BD4D |  | ||||||
|                 INTEGER           :0800 |  | ||||||
|             SEQUENCE |  | ||||||
|               OBJECT            :aes-128-cbc |  | ||||||
|               OCTET STRING      [HEX DUMP]:5B66E6B3BF03944C92317BC370CC3AD0 |  | ||||||
|         OCTET STRING      [HEX DUMP]: |  | ||||||
|  |  | ||||||
| or |  | ||||||
|  |  | ||||||
|       SEQUENCE |  | ||||||
|         SEQUENCE |  | ||||||
|           OBJECT            :pbeWithMD5AndDES-CBC |  | ||||||
|           SEQUENCE |  | ||||||
|             OCTET STRING      [HEX DUMP]:DBF75ECB69E3C0FC |  | ||||||
|             INTEGER           :0800 |  | ||||||
|         OCTET STRING      [HEX DUMP] |  | ||||||
|     */ |  | ||||||
|  |  | ||||||
|     try{ |  | ||||||
|  |  | ||||||
|       ASN1[] contents = null; |  | ||||||
|       ASN1 asn1 = new ASN1(data); |  | ||||||
|  |  | ||||||
|       contents =  asn1.getContents(); |  | ||||||
|  |  | ||||||
|       byte[] _data = contents[1].getContent(); |  | ||||||
|  |  | ||||||
|       ASN1 pbes = contents[0]; |  | ||||||
|       contents = pbes.getContents(); |  | ||||||
|       byte[] pbesid = contents[0].getContent(); |  | ||||||
|       ASN1 pbesparam = contents[1]; |  | ||||||
|  |  | ||||||
|       byte[] salt = null; |  | ||||||
|       int iterations = 0; |  | ||||||
|       byte[] iv = null; |  | ||||||
|       byte[] encryptfuncid = null; |  | ||||||
|  |  | ||||||
|       if(Util.array_equals(pbesid, pbes2)){ |  | ||||||
|         contents = pbesparam.getContents(); |  | ||||||
|         ASN1 pbkdf = contents[0]; |  | ||||||
|         ASN1 encryptfunc = contents[1]; |  | ||||||
|         contents = pbkdf.getContents(); |  | ||||||
|         byte[] pbkdfid = contents[0].getContent(); |  | ||||||
|         ASN1 pbkdffunc = contents[1]; |  | ||||||
|         contents = pbkdffunc.getContents(); |  | ||||||
|         salt = contents[0].getContent(); |  | ||||||
|         iterations =  |  | ||||||
|           Integer.parseInt((new BigInteger(contents[1].getContent())).toString()); |  | ||||||
|  |  | ||||||
|         contents = encryptfunc.getContents(); |  | ||||||
|         encryptfuncid = contents[0].getContent(); |  | ||||||
|         iv = contents[1].getContent(); |  | ||||||
|       } |  | ||||||
|       else if(Util.array_equals(pbesid, pbeWithMD5AndDESCBC)){ |  | ||||||
|         // not supported |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|       else { |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       Cipher cipher=getCipher(encryptfuncid); |  | ||||||
|       if(cipher==null) return false; |  | ||||||
|  |  | ||||||
|       byte[] key=null; |  | ||||||
|       try{ |  | ||||||
|         Class<? extends PBKDF> c=Class.forName(JSch.getConfig("pbkdf")).asSubclass(PBKDF.class); |  | ||||||
|         PBKDF tmp=c.getDeclaredConstructor().newInstance(); |  | ||||||
|         key = tmp.getKey(_passphrase, salt, iterations, cipher.getBlockSize()); |  | ||||||
|       } |  | ||||||
|       catch(Exception ee){ |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if(key==null){ |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       cipher.init(Cipher.DECRYPT_MODE, key, iv); |  | ||||||
|       Util.bzero(key); |  | ||||||
|       byte[] plain=new byte[_data.length]; |  | ||||||
|       cipher.update(_data, 0, _data.length, plain, 0); |  | ||||||
|       if(parse(plain)){ |  | ||||||
|         encrypted=false; |  | ||||||
|         return true; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     catch(ASN1Exception e){ |  | ||||||
|       // System.err.println(e); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       // System.err.println(e); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return false; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   Cipher getCipher(byte[] id){ |  | ||||||
|     Cipher cipher=null; |  | ||||||
|     String name = null; |  | ||||||
|     try{ |  | ||||||
|       if(Util.array_equals(id, aes128cbc)){ |  | ||||||
|         name="aes128-cbc"; |  | ||||||
|       } |  | ||||||
|       else if(Util.array_equals(id, aes192cbc)){ |  | ||||||
|         name="aes192-cbc"; |  | ||||||
|       } |  | ||||||
|       else if(Util.array_equals(id, aes256cbc)){ |  | ||||||
|         name="aes256-cbc"; |  | ||||||
|       } |  | ||||||
|       Class<? extends Cipher> c=Class.forName(JSch.getConfig(name)).asSubclass(Cipher.class); |  | ||||||
|       cipher=c.getDeclaredConstructor().newInstance(); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       if(jsch.getInstanceLogger().isEnabled(Logger.FATAL)){ |  | ||||||
|         String message=""; |  | ||||||
|         if(name==null){ |  | ||||||
|           message="unknown oid: "+Util.toHex(id); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|           message="function "+name+" is not supported"; |  | ||||||
|         } |  | ||||||
|         jsch.getInstanceLogger().log(Logger.FATAL, "PKCS8: "+message); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     return cipher; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,461 +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.math.BigInteger; |  | ||||||
|  |  | ||||||
| class KeyPairRSA extends KeyPair{ |  | ||||||
|   private byte[] n_array;   // modulus   p multiply q |  | ||||||
|   private byte[] pub_array; // e |  | ||||||
|   private byte[] prv_array; // d         e^-1 mod (p-1)(q-1) |  | ||||||
|  |  | ||||||
|   private byte[] p_array;  // prime p |  | ||||||
|   private byte[] q_array;  // prime q |  | ||||||
|   private byte[] ep_array; // prime exponent p  dmp1 == prv mod (p-1) |  | ||||||
|   private byte[] eq_array; // prime exponent q  dmq1 == prv mod (q-1) |  | ||||||
|   private byte[] c_array;  // coefficient  iqmp == modinv(q, p) == q^-1 mod p |  | ||||||
|  |  | ||||||
|   private int key_size=1024; |  | ||||||
|  |  | ||||||
|   KeyPairRSA(JSch jsch){ |  | ||||||
|     this(jsch, null, null, null); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   KeyPairRSA(JSch jsch, |  | ||||||
|                     byte[] n_array, |  | ||||||
|                     byte[] pub_array, |  | ||||||
|                     byte[] prv_array){ |  | ||||||
|     super(jsch); |  | ||||||
|     this.n_array = n_array; |  | ||||||
|     this.pub_array = pub_array; |  | ||||||
|     this.prv_array = prv_array; |  | ||||||
|     if(n_array!=null){ |  | ||||||
|       key_size = (new BigInteger(n_array)).bitLength(); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   void generate(int key_size) throws JSchException{ |  | ||||||
|     this.key_size=key_size; |  | ||||||
|     try{ |  | ||||||
|       Class<? extends KeyPairGenRSA> c=Class.forName(JSch.getConfig("keypairgen.rsa")).asSubclass(KeyPairGenRSA.class); |  | ||||||
|       KeyPairGenRSA keypairgen=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       keypairgen.init(key_size); |  | ||||||
|       pub_array=keypairgen.getE(); |  | ||||||
|       prv_array=keypairgen.getD(); |  | ||||||
|       n_array=keypairgen.getN(); |  | ||||||
|  |  | ||||||
|       p_array=keypairgen.getP(); |  | ||||||
|       q_array=keypairgen.getQ(); |  | ||||||
|       ep_array=keypairgen.getEP(); |  | ||||||
|       eq_array=keypairgen.getEQ(); |  | ||||||
|       c_array=keypairgen.getC(); |  | ||||||
|  |  | ||||||
|       keypairgen=null; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println("KeyPairRSA: "+e); |  | ||||||
|       throw new JSchException(e.toString(), e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] begin=Util.str2byte("-----BEGIN RSA PRIVATE KEY-----"); |  | ||||||
|   private static final byte[] end=Util.str2byte("-----END RSA PRIVATE KEY-----"); |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getBegin(){ return begin; } |  | ||||||
|   @Override |  | ||||||
|   byte[] getEnd(){ return end; } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   byte[] getPrivateKey(){ |  | ||||||
|     int content= |  | ||||||
|       1+countLength(1) + 1 +                           // INTEGER |  | ||||||
|       1+countLength(n_array.length) + n_array.length + // INTEGER  N |  | ||||||
|       1+countLength(pub_array.length) + pub_array.length + // INTEGER  pub |  | ||||||
|       1+countLength(prv_array.length) + prv_array.length+  // INTEGER  prv |  | ||||||
|       1+countLength(p_array.length) + p_array.length+      // INTEGER  p |  | ||||||
|       1+countLength(q_array.length) + q_array.length+      // INTEGER  q |  | ||||||
|       1+countLength(ep_array.length) + ep_array.length+    // INTEGER  ep |  | ||||||
|       1+countLength(eq_array.length) + eq_array.length+    // INTEGER  eq |  | ||||||
|       1+countLength(c_array.length) + c_array.length;      // INTEGER  c |  | ||||||
|  |  | ||||||
|     int total= |  | ||||||
|       1+countLength(content)+content;   // SEQUENCE |  | ||||||
|  |  | ||||||
|     byte[] plain=new byte[total]; |  | ||||||
|     int index=0; |  | ||||||
|     index=writeSEQUENCE(plain, index, content); |  | ||||||
|     index=writeINTEGER(plain, index, new byte[1]);  // 0 |  | ||||||
|     index=writeINTEGER(plain, index, n_array); |  | ||||||
|     index=writeINTEGER(plain, index, pub_array); |  | ||||||
|     index=writeINTEGER(plain, index, prv_array); |  | ||||||
|     index=writeINTEGER(plain, index, p_array); |  | ||||||
|     index=writeINTEGER(plain, index, q_array); |  | ||||||
|     index=writeINTEGER(plain, index, ep_array); |  | ||||||
|     index=writeINTEGER(plain, index, eq_array); |  | ||||||
|     index=writeINTEGER(plain, index, c_array); |  | ||||||
|     return plain; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   boolean parse(byte [] plain){ |  | ||||||
|  |  | ||||||
|     try{ |  | ||||||
|       int index=0; |  | ||||||
|       int length=0; |  | ||||||
|  |  | ||||||
|       if(vendor==VENDOR_PUTTY){ |  | ||||||
|         Buffer buf = new Buffer(plain); |  | ||||||
|         buf.skip(plain.length); |  | ||||||
|  |  | ||||||
|         try { |  | ||||||
|           byte[][] tmp = buf.getBytes(4, ""); |  | ||||||
|           prv_array = tmp[0]; |  | ||||||
|           p_array = tmp[1]; |  | ||||||
|           q_array = tmp[2]; |  | ||||||
|           c_array = tmp[3]; |  | ||||||
|         } |  | ||||||
|         catch(JSchException e){ |  | ||||||
|           return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         getEPArray(); |  | ||||||
|         getEQArray(); |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if(vendor==VENDOR_FSECURE){ |  | ||||||
|         if(plain[index]!=0x30){                  // FSecure |  | ||||||
|           Buffer buf=new Buffer(plain); |  | ||||||
|           pub_array=buf.getMPIntBits(); |  | ||||||
|           prv_array=buf.getMPIntBits(); |  | ||||||
|           n_array=buf.getMPIntBits(); |  | ||||||
|           byte[] u_array=buf.getMPIntBits(); |  | ||||||
|           p_array=buf.getMPIntBits(); |  | ||||||
|           q_array=buf.getMPIntBits(); |  | ||||||
|           if(n_array!=null){ |  | ||||||
|             key_size = (new BigInteger(n_array)).bitLength(); |  | ||||||
|           } |  | ||||||
|  |  | ||||||
|           getEPArray(); |  | ||||||
|           getEQArray(); |  | ||||||
|           getCArray(); |  | ||||||
|  |  | ||||||
|           return true; |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|             // OPENSSH Key v1 Format |  | ||||||
|             if (vendor == VENDOR_OPENSSH_V1) { |  | ||||||
|                 final Buffer prvKEyBuffer = new Buffer(plain); |  | ||||||
|                 int checkInt1 = prvKEyBuffer.getInt(); // uint32 checkint1 |  | ||||||
|                 int checkInt2 = prvKEyBuffer.getInt(); // uint32 checkint2 |  | ||||||
|                 if (checkInt1 != checkInt2) { |  | ||||||
|                     throw new JSchException("check failed"); |  | ||||||
|                 } |  | ||||||
|                 String keyType = Util.byte2str(prvKEyBuffer.getString()); // string keytype |  | ||||||
|                 n_array = prvKEyBuffer.getMPInt(); // Modulus |  | ||||||
|                 pub_array=prvKEyBuffer.getMPInt(); // Public Exponent |  | ||||||
|                 prv_array = prvKEyBuffer.getMPInt(); // Private Exponent |  | ||||||
|                 c_array= prvKEyBuffer.getMPInt(); // iqmp (q^-1 mod p) |  | ||||||
|                 p_array=prvKEyBuffer.getMPInt(); // p (Prime 1) |  | ||||||
|                 q_array=prvKEyBuffer.getMPInt(); // q (Prime 2) |  | ||||||
|  |  | ||||||
|                 getEPArray(); |  | ||||||
|                 getEQArray(); |  | ||||||
|  |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|       /* |  | ||||||
|         Key must be in the following ASN.1 DER encoding, |  | ||||||
|         RSAPrivateKey ::= SEQUENCE { |  | ||||||
|           version           Version, |  | ||||||
|           modulus           INTEGER,  -- n |  | ||||||
|           publicExponent    INTEGER,  -- e |  | ||||||
|           privateExponent   INTEGER,  -- d |  | ||||||
|           prime1            INTEGER,  -- p |  | ||||||
|           prime2            INTEGER,  -- q |  | ||||||
|           exponent1         INTEGER,  -- d mod (p-1) |  | ||||||
|           exponent2         INTEGER,  -- d mod (q-1) |  | ||||||
|           coefficient       INTEGER,  -- (inverse of q) mod p |  | ||||||
|           otherPrimeInfos   OtherPrimeInfos OPTIONAL |  | ||||||
|         } |  | ||||||
|       */ |  | ||||||
|  |  | ||||||
|       index++; // SEQUENCE |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if(plain[index]!=0x02)return false; |  | ||||||
|       index++; // INTEGER |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       n_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, n_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       pub_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, pub_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       prv_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, prv_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       p_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, p_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       q_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, q_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       ep_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, ep_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       eq_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, eq_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       index++; |  | ||||||
|       length=plain[index++]&0xff; |  | ||||||
|       if((length&0x80)!=0){ |  | ||||||
|         int foo=length&0x7f; length=0; |  | ||||||
|         while(foo-->0){ length=(length<<8)+(plain[index++]&0xff); } |  | ||||||
|       } |  | ||||||
|       c_array=new byte[length]; |  | ||||||
|       System.arraycopy(plain, index, c_array, 0, length); |  | ||||||
|       index+=length; |  | ||||||
|  |  | ||||||
|       if(n_array!=null){ |  | ||||||
|         key_size = (new BigInteger(n_array)).bitLength(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       //System.err.println(e); |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getPublicKeyBlob(){ |  | ||||||
|     byte[] foo=super.getPublicKeyBlob(); |  | ||||||
|     if(foo!=null) return foo; |  | ||||||
|  |  | ||||||
|     if(pub_array==null) return null; |  | ||||||
|     byte[][] tmp = new byte[3][]; |  | ||||||
|     tmp[0] = sshrsa; |  | ||||||
|     tmp[1] = pub_array; |  | ||||||
|     tmp[2] = n_array; |  | ||||||
|     return Buffer.fromBytes(tmp).buffer; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] sshrsa=Util.str2byte("ssh-rsa"); |  | ||||||
|   @Override |  | ||||||
|   byte[] getKeyTypeName(){return sshrsa;} |  | ||||||
|   @Override |  | ||||||
|   public int getKeyType(){return RSA;} |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getKeySize(){ |  | ||||||
|     return key_size; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data){ |  | ||||||
|     return getSignature(data, "ssh-rsa"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] getSignature(byte[] data, String alg){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureRSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class); |  | ||||||
|       SignatureRSA rsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       rsa.init(); |  | ||||||
|       rsa.setPrvKey(prv_array, n_array); |  | ||||||
|  |  | ||||||
|       rsa.update(data); |  | ||||||
|       byte[] sig = rsa.sign(); |  | ||||||
|       byte[][] tmp = new byte[2][]; |  | ||||||
|       tmp[0] = Util.str2byte(alg); |  | ||||||
|       tmp[1] = sig; |  | ||||||
|       return Buffer.fromBytes(tmp).buffer; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(){ |  | ||||||
|     return getVerifier("ssh-rsa"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public Signature getVerifier(String alg){ |  | ||||||
|     try{ |  | ||||||
|       Class<? extends SignatureRSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class); |  | ||||||
|       SignatureRSA rsa=c.getDeclaredConstructor().newInstance(); |  | ||||||
|       rsa.init(); |  | ||||||
|  |  | ||||||
|       if(pub_array == null && n_array == null && getPublicKeyBlob()!=null){ |  | ||||||
|         Buffer buf = new Buffer(getPublicKeyBlob()); |  | ||||||
|         buf.getString(); |  | ||||||
|         pub_array = buf.getString(); |  | ||||||
|         n_array = buf.getString(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       rsa.setPubKey(pub_array, n_array); |  | ||||||
|       return rsa; |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException { |  | ||||||
|  |  | ||||||
|     byte[][] tmp = buf.getBytes(8, "invalid key format"); |  | ||||||
|  |  | ||||||
|     byte[] n_array = tmp[1]; |  | ||||||
|     byte[] pub_array = tmp[2]; |  | ||||||
|     byte[] prv_array = tmp[3]; |  | ||||||
|     KeyPairRSA kpair = new KeyPairRSA(jsch, n_array, pub_array, prv_array); |  | ||||||
|     kpair.c_array = tmp[4];     // iqmp |  | ||||||
|     kpair.p_array = tmp[5]; |  | ||||||
|     kpair.q_array = tmp[6]; |  | ||||||
|     kpair.publicKeyComment = Util.byte2str(tmp[7]); |  | ||||||
|     kpair.vendor=VENDOR_OPENSSH; |  | ||||||
|     return kpair; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public byte[] forSSHAgent() throws JSchException { |  | ||||||
|     if(isEncrypted()){ |  | ||||||
|       throw new JSchException("key is encrypted."); |  | ||||||
|     } |  | ||||||
|     Buffer buf = new Buffer(); |  | ||||||
|     buf.putString(sshrsa); |  | ||||||
|     buf.putString(n_array); |  | ||||||
|     buf.putString(pub_array); |  | ||||||
|     buf.putString(prv_array); |  | ||||||
|     buf.putString(getCArray()); |  | ||||||
|     buf.putString(p_array); |  | ||||||
|     buf.putString(q_array); |  | ||||||
|     buf.putString(Util.str2byte(publicKeyComment)); |  | ||||||
|     byte[] result = new byte[buf.getLength()]; |  | ||||||
|     buf.getByte(result, 0, result.length); |  | ||||||
|     return result; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private byte[] getEPArray(){ |  | ||||||
|     if(ep_array==null){ |  | ||||||
|       ep_array=(new BigInteger(prv_array)).mod(new BigInteger(p_array).subtract(BigInteger.ONE)).toByteArray(); |  | ||||||
|     } |  | ||||||
|     return ep_array; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private byte[] getEQArray(){ |  | ||||||
|     if(eq_array==null){ |  | ||||||
|       eq_array=(new BigInteger(prv_array)).mod(new BigInteger(q_array).subtract(BigInteger.ONE)).toByteArray(); |  | ||||||
|     } |  | ||||||
|     return eq_array; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private byte[] getCArray(){ |  | ||||||
|     if(c_array==null){ |  | ||||||
|       c_array=(new BigInteger(q_array)).modInverse(new BigInteger(p_array)).toByteArray(); |  | ||||||
|     } |  | ||||||
|     return c_array; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void dispose(){ |  | ||||||
|     super.dispose(); |  | ||||||
|     Util.bzero(prv_array); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,622 +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.File; |  | ||||||
| import java.io.FileInputStream; |  | ||||||
| import java.io.FileNotFoundException; |  | ||||||
| import java.io.FileOutputStream; |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.io.InputStream; |  | ||||||
| import java.io.OutputStream; |  | ||||||
| import java.util.ArrayList; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Vector; |  | ||||||
|  |  | ||||||
| class KnownHosts implements HostKeyRepository{ |  | ||||||
|   private JSch jsch=null; |  | ||||||
|   private String known_hosts=null; |  | ||||||
|   private Vector<HostKey> pool=null; |  | ||||||
|  |  | ||||||
|   MAC hmacsha1; |  | ||||||
|  |  | ||||||
|   KnownHosts(JSch jsch) { |  | ||||||
|     super(); |  | ||||||
|     this.jsch=jsch; |  | ||||||
|     getHMACSHA1(); |  | ||||||
|     pool=new Vector<>(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void setKnownHosts(String filename) throws JSchException{ |  | ||||||
|     try{ |  | ||||||
|       known_hosts = filename; |  | ||||||
|       FileInputStream fis=new FileInputStream(Util.checkTilde(filename)); |  | ||||||
|       setKnownHosts(fis); |  | ||||||
|     } |  | ||||||
|     catch(FileNotFoundException e){ |  | ||||||
|       // The non-existing file should be allowed. |  | ||||||
|     }  |  | ||||||
|   } |  | ||||||
|   void setKnownHosts(InputStream input) throws JSchException{ |  | ||||||
|     pool.removeAllElements(); |  | ||||||
|     StringBuilder sb=new StringBuilder(); |  | ||||||
|     byte i; |  | ||||||
|     int j; |  | ||||||
|     boolean error=false; |  | ||||||
|     try{ |  | ||||||
|       InputStream fis=input; |  | ||||||
|       String host; |  | ||||||
|       String key=null; |  | ||||||
|       int type; |  | ||||||
|       byte[] buf=new byte[1024]; |  | ||||||
|       int bufl=0; |  | ||||||
| loop: |  | ||||||
|       while(true){ |  | ||||||
|         bufl=0; |  | ||||||
|         while(true){ |  | ||||||
|           j=fis.read(); |  | ||||||
|           if(j==-1){ |  | ||||||
|             if(bufl==0){ break loop; } |  | ||||||
|             break; |  | ||||||
|           } |  | ||||||
|           if(j==0x0d){ continue; } |  | ||||||
|           if(j==0x0a){ break; } |  | ||||||
|           if(buf.length<=bufl){ |  | ||||||
|             if(bufl>1024*10) break;   // too long... |  | ||||||
|             byte[] newbuf=new byte[buf.length*2]; |  | ||||||
|             System.arraycopy(buf, 0, newbuf, 0, buf.length); |  | ||||||
|             buf=newbuf; |  | ||||||
|           } |  | ||||||
|           buf[bufl++]=(byte)j; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         j=0; |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j]; |  | ||||||
|           if(i==' '||i=='\t'){ j++; continue; } |  | ||||||
|           if(i=='#'){ |  | ||||||
|             addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|             continue loop; |  | ||||||
|           } |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|         if(j>=bufl){  |  | ||||||
|           addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|           continue loop;  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         sb.setLength(0); |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j++]; |  | ||||||
|           if(i==0x20 || i=='\t'){ break; } |  | ||||||
|           sb.append((char)i); |  | ||||||
|         } |  | ||||||
|         host=sb.toString(); |  | ||||||
|         if(j>=bufl || host.length()==0){ |  | ||||||
|           addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|           continue loop;  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j]; |  | ||||||
|           if(i==' '||i=='\t'){ j++; continue; } |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         String marker=""; |  | ||||||
|         if(host.charAt(0) == '@'){ |  | ||||||
|           marker = host; |  | ||||||
|  |  | ||||||
|           sb.setLength(0); |  | ||||||
|           while(j<bufl){ |  | ||||||
|             i=buf[j++]; |  | ||||||
|             if(i==0x20 || i=='\t'){ break; } |  | ||||||
|             sb.append((char)i); |  | ||||||
|           } |  | ||||||
|           host=sb.toString(); |  | ||||||
|           if(j>=bufl || host.length()==0){ |  | ||||||
|             addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|             continue loop;  |  | ||||||
|           } |  | ||||||
|  |  | ||||||
|           while(j<bufl){ |  | ||||||
|             i=buf[j]; |  | ||||||
|             if(i==' '||i=='\t'){ j++; continue; } |  | ||||||
|             break; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         sb.setLength(0); |  | ||||||
|         type=-1; |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j++]; |  | ||||||
|           if(i==0x20 || i=='\t'){ break; } |  | ||||||
|           sb.append((char)i); |  | ||||||
|         } |  | ||||||
|         String tmp = sb.toString(); |  | ||||||
|         if(HostKey.name2type(tmp)!=HostKey.UNKNOWN){ |  | ||||||
|           type=HostKey.name2type(tmp); |  | ||||||
|         } |  | ||||||
|         else { j=bufl; } |  | ||||||
|         if(j>=bufl){ |  | ||||||
|           addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|           continue loop;  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j]; |  | ||||||
|           if(i==' '||i=='\t'){ j++; continue; } |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         sb.setLength(0); |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j++]; |  | ||||||
|           if(i==0x0d){ continue; } |  | ||||||
|           if(i==0x0a){ break; } |  | ||||||
|           if(i==0x20 || i=='\t'){ break; } |  | ||||||
|           sb.append((char)i); |  | ||||||
|         } |  | ||||||
|         key=sb.toString(); |  | ||||||
|         if(key.length()==0){ |  | ||||||
|           addInvalidLine(Util.byte2str(buf, 0, bufl)); |  | ||||||
|           continue loop;  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         while(j<bufl){ |  | ||||||
|           i=buf[j]; |  | ||||||
|           if(i==' '||i=='\t'){ j++; continue; } |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /** |  | ||||||
|           "man sshd" has following descriptions, |  | ||||||
|             Note that the lines in these files are typically hundreds |  | ||||||
|             of characters long, and you definitely don't want to type |  | ||||||
|             in the host keys by hand.  Rather, generate them by a script, |  | ||||||
|             ssh-keyscan(1) or by taking /usr/local/etc/ssh_host_key.pub and |  | ||||||
|             adding the host names at the front. |  | ||||||
|           This means that a comment is allowed to appear at the end of each |  | ||||||
|           key entry. |  | ||||||
|         */ |  | ||||||
|         String comment=null; |  | ||||||
|         if(j<bufl){ |  | ||||||
|           sb.setLength(0); |  | ||||||
|           while(j<bufl){ |  | ||||||
|             i=buf[j++]; |  | ||||||
|             if(i==0x0d){ continue; } |  | ||||||
|             if(i==0x0a){ break; } |  | ||||||
|             sb.append((char)i); |  | ||||||
|           } |  | ||||||
|           comment=sb.toString(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         //System.err.println(host); |  | ||||||
|         //System.err.println("|"+key+"|"); |  | ||||||
|  |  | ||||||
|         HostKey hk = null; |  | ||||||
|         hk = new HashedHostKey(marker, host, type,  |  | ||||||
|                                Util.fromBase64(Util.str2byte(key), 0,  |  | ||||||
|                                                key.length()), comment); |  | ||||||
|         pool.addElement(hk); |  | ||||||
|       } |  | ||||||
|       if(error){ |  | ||||||
|         throw new JSchException("KnownHosts: invalid format"); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       if(e instanceof JSchException) |  | ||||||
|         throw (JSchException)e;          |  | ||||||
|       throw new JSchException(e.toString(), e); |  | ||||||
|     } |  | ||||||
|     finally { |  | ||||||
|       try{ input.close(); } |  | ||||||
|       catch(IOException e){ |  | ||||||
|         throw new JSchException(e.toString(), e); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   private void addInvalidLine(String line) throws JSchException { |  | ||||||
|     HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); |  | ||||||
|     pool.addElement(hk); |  | ||||||
|   } |  | ||||||
|   String getKnownHostsFile(){ return known_hosts; } |  | ||||||
|   @Override |  | ||||||
|   public String getKnownHostsRepositoryID(){ return known_hosts; } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int check(String host, byte[] key){ |  | ||||||
|     int result=NOT_INCLUDED; |  | ||||||
|     if(host==null){ |  | ||||||
|       return result; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     HostKey hk = null; |  | ||||||
|     try { |  | ||||||
|       hk = new HostKey(host, HostKey.GUESS, key); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){  // unsupported key |  | ||||||
|       jsch.getInstanceLogger().log(Logger.DEBUG, "exception while trying to read key while checking host '" + host + "'", e); |  | ||||||
|       return result; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     synchronized(pool){ |  | ||||||
|       for(int i=0; i<pool.size(); i++){ |  | ||||||
|         HostKey _hk=pool.elementAt(i); |  | ||||||
|         if(_hk.isMatched(host) && _hk.type==hk.type){ |  | ||||||
|           if(Util.array_equals(_hk.key, key)){ |  | ||||||
|             return OK; |  | ||||||
|           } |  | ||||||
|           result=CHANGED; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if(result==NOT_INCLUDED && |  | ||||||
|        host.startsWith("[") && |  | ||||||
|        host.indexOf("]:")>1 |  | ||||||
|        ){ |  | ||||||
|       return check(host.substring(1, host.indexOf("]:")), key); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return result; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public void add(HostKey hostkey, UserInfo userinfo){ |  | ||||||
|     int type=hostkey.type; |  | ||||||
|     String host=hostkey.getHost(); |  | ||||||
| //    byte[] key=hostkey.key; |  | ||||||
|  |  | ||||||
|     HostKey hk=null; |  | ||||||
|     synchronized(pool){ |  | ||||||
|       for(int i=0; i<pool.size(); i++){ |  | ||||||
|         hk=pool.elementAt(i); |  | ||||||
|         if(hk.isMatched(host) && hk.type==type){ |  | ||||||
| /* |  | ||||||
|           if(Util.array_equals(hk.key, key)){ return; } |  | ||||||
|           if(hk.host.equals(host)){ |  | ||||||
|             hk.key=key; |  | ||||||
|             return; |  | ||||||
|           } |  | ||||||
|           else{ |  | ||||||
|             hk.host=deleteSubString(hk.host, host); |  | ||||||
|             break; |  | ||||||
|           } |  | ||||||
| */ |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     hk=hostkey; |  | ||||||
|  |  | ||||||
|     pool.addElement(hk); |  | ||||||
|  |  | ||||||
|     syncKnownHostsFile(userinfo); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void syncKnownHostsFile(UserInfo userinfo) { |  | ||||||
|     String khFilename = getKnownHostsRepositoryID(); |  | ||||||
|     if (khFilename == null) { |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     boolean doSync=true; |  | ||||||
|     File goo=new File(Util.checkTilde(khFilename )); |  | ||||||
|     if(!goo.exists()){ |  | ||||||
|       doSync = false; |  | ||||||
|       if (userinfo!=null) { |  | ||||||
|         doSync = userinfo.promptYesNo(khFilename +" does not exist.\n"+ |  | ||||||
|                                  "Are you sure you want to create it?" |  | ||||||
|                                  ); |  | ||||||
|         goo=goo.getParentFile(); |  | ||||||
|         if(doSync && goo!=null && !goo.exists()){ |  | ||||||
|           doSync=userinfo.promptYesNo("The parent directory "+goo+" does not exist.\n"+ |  | ||||||
|                                    "Are you sure you want to create it?" |  | ||||||
|                                    ); |  | ||||||
|           if(doSync){ |  | ||||||
|             if(!goo.mkdirs()){ |  | ||||||
|               userinfo.showMessage(goo+" has not been created."); |  | ||||||
|               doSync=false; |  | ||||||
|             } |  | ||||||
|             else{ |  | ||||||
|               userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission."); |  | ||||||
|             } |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|         if(goo==null)doSync=false; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     if(!doSync){ |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     try{  |  | ||||||
|       sync(khFilename);  |  | ||||||
|     } |  | ||||||
|     catch(Exception e) { |  | ||||||
|       jsch.getInstanceLogger().log(Logger.ERROR, "unable to sync known host file " + goo.getPath(), e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public HostKey[] getHostKey(){ |  | ||||||
|     return getHostKey(null, (String)null); |  | ||||||
|   } |  | ||||||
|   @Override |  | ||||||
|   public HostKey[] getHostKey(String host, String type){ |  | ||||||
|     synchronized(pool){ |  | ||||||
|       List<HostKey> v = new ArrayList<>(); |  | ||||||
|       for(int i=0; i<pool.size(); i++){ |  | ||||||
|         HostKey hk=pool.elementAt(i); |  | ||||||
|         if(hk.type==HostKey.UNKNOWN) continue; |  | ||||||
|         if(host==null ||  |  | ||||||
|            (hk.isMatched(host) &&  |  | ||||||
|             (type==null || hk.getType().equals(type)))){ |  | ||||||
|           v.add(hk); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       HostKey[] foo = new HostKey[v.size()]; |  | ||||||
|       for(int i=0; i<v.size(); i++){ |  | ||||||
|         foo[i] = v.get(i); |  | ||||||
|       } |  | ||||||
|       if(host != null && host.startsWith("[") && host.indexOf("]:")>1){ |  | ||||||
|         HostKey[] tmp = |  | ||||||
|           getHostKey(host.substring(1, host.indexOf("]:")), type); |  | ||||||
|         if(tmp.length > 0){ |  | ||||||
|           HostKey[] bar = new HostKey[foo.length + tmp.length]; |  | ||||||
|           System.arraycopy(foo, 0, bar, 0, foo.length); |  | ||||||
|           System.arraycopy(tmp, 0, bar, foo.length, tmp.length); |  | ||||||
|           foo = bar; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       return foo; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   @Override |  | ||||||
|   public void remove(String host, String type){ |  | ||||||
|     remove(host, type, null); |  | ||||||
|   } |  | ||||||
|   @Override |  | ||||||
|   public void remove(String host, String type, byte[] key){ |  | ||||||
|     boolean sync=false; |  | ||||||
|     synchronized(pool){ |  | ||||||
|     for(int i=0; i<pool.size(); i++){ |  | ||||||
|       HostKey hk=pool.elementAt(i); |  | ||||||
|       if(host==null || |  | ||||||
|          (hk.isMatched(host) &&  |  | ||||||
|           (type==null || (hk.getType().equals(type) && |  | ||||||
|                           (key==null || Util.array_equals(key, hk.key)))))){ |  | ||||||
|         String hosts=hk.getHost(); |  | ||||||
|         if(host == null || hosts.equals(host) ||  |  | ||||||
|            ((hk instanceof HashedHostKey) && |  | ||||||
|             ((HashedHostKey)hk).isHashed())){ |  | ||||||
|           pool.removeElement(hk); |  | ||||||
|           i--; |  | ||||||
|         } |  | ||||||
|         else{ |  | ||||||
|           hk.host=deleteSubString(hosts, host); |  | ||||||
|         } |  | ||||||
|         sync=true; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     } |  | ||||||
|     if(sync){ |  | ||||||
|       try{sync();}catch(Exception e){}; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void sync() throws IOException {  |  | ||||||
|     if(known_hosts!=null) |  | ||||||
|       sync(known_hosts);  |  | ||||||
|   } |  | ||||||
|   synchronized void sync(String foo) throws IOException { |  | ||||||
|     if(foo==null) return; |  | ||||||
|     try (FileOutputStream fos = new FileOutputStream(Util.checkTilde(foo))) { |  | ||||||
|       dump(fos); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private static final byte[] space={(byte)0x20}; |  | ||||||
|   private static final byte[] lf=Util.str2byte("\n"); |  | ||||||
|    |  | ||||||
|   void dump(OutputStream out) { |  | ||||||
|     try{ |  | ||||||
|       HostKey hk; |  | ||||||
|       synchronized(pool){ |  | ||||||
|       for(int i=0; i<pool.size(); i++){ |  | ||||||
|         hk=pool.elementAt(i); |  | ||||||
|         dumpHostKey(out, hk); |  | ||||||
|       } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       jsch.getInstanceLogger().log(Logger.ERROR, "unable to dump known hosts", e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void dumpHostKey(OutputStream out, HostKey hk) throws IOException { |  | ||||||
|     String marker=hk.getMarker(); |  | ||||||
|     String host=hk.getHost(); |  | ||||||
|     String type=hk.getType(); |  | ||||||
|     String comment = hk.getComment(); |  | ||||||
|     if (type.equals("UNKNOWN")) { |  | ||||||
|       out.write(Util.str2byte(host)); |  | ||||||
|       out.write(lf); |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     if (marker.length() != 0) { |  | ||||||
|       out.write(Util.str2byte(marker)); |  | ||||||
|       out.write(space); |  | ||||||
|     } |  | ||||||
|     out.write(Util.str2byte(host)); |  | ||||||
|     out.write(space); |  | ||||||
|     out.write(Util.str2byte(type)); |  | ||||||
|     out.write(space); |  | ||||||
|     out.write(Util.str2byte(hk.getKey())); |  | ||||||
|      |  | ||||||
|     if (comment != null) { |  | ||||||
|       out.write(space); |  | ||||||
|       out.write(Util.str2byte(comment)); |  | ||||||
|     } |  | ||||||
|     out.write(lf); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   String deleteSubString(String hosts, String host){ |  | ||||||
|     int i=0; |  | ||||||
|     int hostlen=host.length(); |  | ||||||
|     int hostslen=hosts.length(); |  | ||||||
|     int j; |  | ||||||
|     while(i<hostslen){ |  | ||||||
|       j=hosts.indexOf(',', i); |  | ||||||
|       if(j==-1) break; |  | ||||||
|       if(!host.equals(hosts.substring(i, j))){ |  | ||||||
|         i=j+1; |  | ||||||
|         continue; |  | ||||||
|       } |  | ||||||
|       return hosts.substring(0, i)+hosts.substring(j+1); |  | ||||||
|     } |  | ||||||
|     if(hosts.endsWith(host) && hostslen-i==hostlen){ |  | ||||||
|       return hosts.substring(0, (hostlen==hostslen) ? 0 :hostslen-hostlen-1); |  | ||||||
|     } |  | ||||||
|     return hosts; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   MAC getHMACSHA1() throws IllegalArgumentException { |  | ||||||
|     if (hmacsha1 == null){ |  | ||||||
|       hmacsha1 = createHMAC(JSch.getConfig("hmac-sha1")); |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     return hmacsha1; |  | ||||||
|   } |  | ||||||
|    |  | ||||||
|   MAC createHMAC(String hmacClassname) throws IllegalArgumentException { |  | ||||||
|     try{ |  | ||||||
|       Class<? extends MAC> c=Class.forName(hmacClassname).asSubclass(MAC.class); |  | ||||||
|       return c.getDeclaredConstructor().newInstance(); |  | ||||||
|     } |  | ||||||
|     catch(Exception e){ |  | ||||||
|       jsch.getInstanceLogger().log(Logger.ERROR, "unable to instantiate HMAC-class " + hmacClassname, e); |  | ||||||
|       throw new IllegalArgumentException("instantiation of " + hmacClassname + " lead to an error", e); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   HostKey createHashedHostKey(String host, byte[]key) throws JSchException { |  | ||||||
|     HashedHostKey hhk=new HashedHostKey(host, key); |  | ||||||
|     hhk.hash(); |  | ||||||
|     return hhk; |  | ||||||
|   }  |  | ||||||
|   class HashedHostKey extends HostKey{ |  | ||||||
|     private static final String HASH_MAGIC="|1|"; |  | ||||||
|     private static final String HASH_DELIM="|"; |  | ||||||
|  |  | ||||||
|     private boolean hashed=false; |  | ||||||
|     byte[] salt=null; |  | ||||||
|     byte[] hash=null; |  | ||||||
|  |  | ||||||
|     HashedHostKey(String host, byte[] key) throws JSchException { |  | ||||||
|       this(host, GUESS, key); |  | ||||||
|     } |  | ||||||
|     HashedHostKey(String host, int type, byte[] key) throws JSchException { |  | ||||||
|       this("", host, type, key, null); |  | ||||||
|     } |  | ||||||
|     HashedHostKey(String marker, String host, int type, byte[] key, String comment) throws JSchException { |  | ||||||
|       super(marker, host, type, key, comment); |  | ||||||
|       if(this.host.startsWith(HASH_MAGIC) && |  | ||||||
|          this.host.substring(HASH_MAGIC.length()).indexOf(HASH_DELIM)>0){ |  | ||||||
|         String data=this.host.substring(HASH_MAGIC.length()); |  | ||||||
|         String _salt=data.substring(0, data.indexOf(HASH_DELIM)); |  | ||||||
|         String _hash=data.substring(data.indexOf(HASH_DELIM)+1); |  | ||||||
|         salt=Util.fromBase64(Util.str2byte(_salt), 0, _salt.length()); |  | ||||||
|         hash=Util.fromBase64(Util.str2byte(_hash), 0, _hash.length()); |  | ||||||
|         int blockSize = hmacsha1.getBlockSize(); |  | ||||||
|         if (salt.length!=blockSize || hash.length!=blockSize) { |  | ||||||
|           salt=null; |  | ||||||
|           hash=null; |  | ||||||
|           return; |  | ||||||
|         } |  | ||||||
|         hashed=true; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     boolean isMatched(String _host){ |  | ||||||
|       if(!hashed){ |  | ||||||
|         return super.isMatched(_host); |  | ||||||
|       } |  | ||||||
|       try{ |  | ||||||
|         synchronized(hmacsha1){ |  | ||||||
|           hmacsha1.init(salt); |  | ||||||
|           byte[] foo=Util.str2byte(_host); |  | ||||||
|           hmacsha1.update(foo, 0, foo.length); |  | ||||||
|           byte[] bar=new byte[hmacsha1.getBlockSize()]; |  | ||||||
|           hmacsha1.doFinal(bar, 0); |  | ||||||
|           return Util.array_equals(hash, bar); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       catch(Exception e){ |  | ||||||
|         jsch.getInstanceLogger().log(Logger.ERROR, "an error occurred while trying to check hash for host " + _host, e); |  | ||||||
|       } |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     boolean isHashed(){ |  | ||||||
|       return hashed; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     void hash(){ |  | ||||||
|       if(hashed) |  | ||||||
|         return; |  | ||||||
|       if(salt==null){ |  | ||||||
|         Random random=Session.random; |  | ||||||
|         synchronized(random){ |  | ||||||
|           salt=new byte[hmacsha1.getBlockSize()]; |  | ||||||
|           random.fill(salt, 0, salt.length); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       try{ |  | ||||||
|         synchronized(hmacsha1){ |  | ||||||
|           hmacsha1.init(salt); |  | ||||||
|           byte[] foo=Util.str2byte(host); |  | ||||||
|           hmacsha1.update(foo, 0, foo.length); |  | ||||||
|           hash=new byte[hmacsha1.getBlockSize()]; |  | ||||||
|           hmacsha1.doFinal(hash, 0); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       catch(Exception e){ |  | ||||||
|         jsch.getInstanceLogger().log(Logger.ERROR, "an error occurred while trying to calculate the hash for host " + host, e); |  | ||||||
|         salt = null; |  | ||||||
|         hash = null; |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|       host=HASH_MAGIC+Util.byte2str(Util.toBase64(salt, 0, salt.length, true))+ |  | ||||||
|         HASH_DELIM+Util.byte2str(Util.toBase64(hash, 0, hash.length, true)); |  | ||||||
|       hashed=true; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,157 +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; |  | ||||||
|  |  | ||||||
| class LocalIdentityRepository implements IdentityRepository { |  | ||||||
|   private static final String name = "Local Identity Repository"; |  | ||||||
|  |  | ||||||
|   private Vector<Identity> identities = new Vector<>(); |  | ||||||
|   private JSch jsch; |  | ||||||
|  |  | ||||||
|   LocalIdentityRepository(JSch jsch){ |  | ||||||
|     this.jsch = jsch; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public String getName(){ |  | ||||||
|     return name; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public int getStatus(){ |  | ||||||
|     return RUNNING; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized Vector<Identity> getIdentities() { |  | ||||||
|     removeDupulicates(); |  | ||||||
|     Vector<Identity> v = new Vector<>(); |  | ||||||
|     for(int i=0; i<identities.size(); i++){ |  | ||||||
|       v.addElement(identities.elementAt(i)); |  | ||||||
|     } |  | ||||||
|     return v; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   public synchronized void add(Identity identity) { |  | ||||||
|     if(!identities.contains(identity)) { |  | ||||||
|       byte[] blob1 = identity.getPublicKeyBlob(); |  | ||||||
|       if(blob1 == null) { |  | ||||||
|         identities.addElement(identity); |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|       for(int i = 0; i<identities.size(); i++){ |  | ||||||
|         byte[] blob2 = identities.elementAt(i).getPublicKeyBlob(); |  | ||||||
|         if(blob2 != null && Util.array_equals(blob1, blob2)){ |  | ||||||
|           if(!identity.isEncrypted() &&  |  | ||||||
|              identities.elementAt(i).isEncrypted()){ |  | ||||||
|             remove(blob2); |  | ||||||
|           } |  | ||||||
|           else {   |  | ||||||
|             return; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       identities.addElement(identity); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized boolean add(byte[] identity) { |  | ||||||
|     try{ |  | ||||||
|       Identity _identity = |  | ||||||
|         IdentityFile.newInstance("from remote:", identity, null, jsch); |  | ||||||
|       add(_identity); |  | ||||||
|       return true; |  | ||||||
|     } |  | ||||||
|     catch(JSchException e){ |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   synchronized void remove(Identity identity) { |  | ||||||
|     if(identities.contains(identity)) { |  | ||||||
|       identities.removeElement(identity); |  | ||||||
|       identity.clear(); |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|       remove(identity.getPublicKeyBlob()); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized boolean remove(byte[] blob) { |  | ||||||
|     if(blob == null) return false; |  | ||||||
|     for(int i=0; i<identities.size(); i++) { |  | ||||||
|       Identity _identity = identities.elementAt(i); |  | ||||||
|       byte[] _blob = _identity.getPublicKeyBlob(); |  | ||||||
|       if(_blob == null || !Util.array_equals(blob, _blob)) |  | ||||||
|         continue; |  | ||||||
|       identities.removeElement(_identity); |  | ||||||
|       _identity.clear(); |  | ||||||
|       return true; |  | ||||||
|     } |  | ||||||
|     return false; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Override |  | ||||||
|   public synchronized void removeAll() { |  | ||||||
|     for(int i=0; i<identities.size(); i++) { |  | ||||||
|       Identity identity=identities.elementAt(i); |  | ||||||
|       identity.clear(); |  | ||||||
|     } |  | ||||||
|     identities.removeAllElements(); |  | ||||||
|   }  |  | ||||||
|  |  | ||||||
|   private void removeDupulicates(){ |  | ||||||
|     Vector<byte[]> v = new Vector<>(); |  | ||||||
|     int len = identities.size(); |  | ||||||
|     if(len == 0) return; |  | ||||||
|     for(int i=0; i<len; i++){ |  | ||||||
|       Identity foo = identities.elementAt(i); |  | ||||||
|       byte[] foo_blob = foo.getPublicKeyBlob(); |  | ||||||
|       if(foo_blob == null) continue; |  | ||||||
|       for(int j=i+1; j<len; j++){ |  | ||||||
|         Identity bar = identities.elementAt(j); |  | ||||||
|         byte[] bar_blob = bar.getPublicKeyBlob(); |  | ||||||
|         if(bar_blob == null) continue; |  | ||||||
|         if(Util.array_equals(foo_blob, bar_blob) && |  | ||||||
|            foo.isEncrypted() == bar.isEncrypted()){ |  | ||||||
|           v.addElement(foo_blob); |  | ||||||
|           break; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     for(int i=0; i<v.size(); i++){ |  | ||||||
|       remove(v.elementAt(i)); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user