Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: |
LOWER_JDK="${{ matrix.java }}"
UPPER_JDK=$((LOWER_JDK+1))
./mvnw -B -V -e -Pcoverage verify -Dtoolchain.jdk.version="[$LOWER_JDK,$UPPER_JDK)" -Dmaven.resources.skip=true -Dflatten.skip=true -Dmaven.main.skip=true -Dbnd.skip=true -Dassembly.skipAssembly=true -Dmaven.javadoc.skip=true -Dcyclonedx.skip=true -Dspdx.skip=true -Dformatter.skip=true -Dforbiddenapis.skip=true -DskipTests=false -DskipITs=false
./mvnw -B -V -e -Pcoverage verify -Dtoolchain.jdk.version="[$LOWER_JDK,$UPPER_JDK)" -Dwindowsapi.skip=true -Dmaven.resources.skip=true -Dflatten.skip=true -Dmaven.main.skip=true -Dbnd.skip=true -Dassembly.skipAssembly=true -Dmaven.javadoc.skip=true -Dcyclonedx.skip=true -Dspdx.skip=true -Dformatter.skip=true -Dforbiddenapis.skip=true -DskipTests=false -DskipITs=false
- name: Upload test results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
Expand Down
152 changes: 150 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,58 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.codecrete.windows-api</groupId>
<artifactId>windowsapi-maven-plugin</artifactId>
<version>0.8.4</version>
<configuration>
<sourceDirectory>.</sourceDirectory>
<basePackage>com.jcraft.jsch.windowsapi</basePackage>
<addAsSourceRoot>false</addAsSourceRoot>
<functions>
<function>CloseHandle</function>
<function>CopySid</function>
<function>CreateFileMappingA</function>
<function>FindWindowA</function>
<function>GetCurrentProcessId</function>
<function>GetCurrentThreadId</function>
<function>GetLengthSid</function>
<function>GetTokenInformation</function>
<function>InitializeSecurityDescriptor</function>
<function>IsValidSid</function>
<function>MapViewOfFile</function>
<function>OpenProcess</function>
<function>OpenProcessToken</function>
<function>SendMessageA</function>
<function>SetSecurityDescriptorOwner</function>
<function>UnmapViewOfFile</function>
</functions>
<structs>
<struct>COPYDATASTRUCT</struct>
<struct>SECURITY_ATTRIBUTES</struct>
<struct>SECURITY_DESCRIPTOR</struct>
<struct>SID_AND_ATTRIBUTES</struct>
<struct>TOKEN_USER</struct>
</structs>
<enumerations>
<enumeration>FILE_MAP</enumeration>
<enumeration>PAGE_PROTECTION_FLAGS</enumeration>
<enumeration>TOKEN_ACCESS_MASK</enumeration>
<enumeration>TOKEN_INFORMATION_CLASS</enumeration>
</enumerations>
<constants>
<constant>INVALID_HANDLE_VALUE</constant>
<constant>MAXIMUM_ALLOWED</constant>
<constant>SECURITY_DESCRIPTOR_REVISION</constant>
<constant>WM_COPYDATA</constant>
</constants>
</configuration>
</plugin>
<plugin>
<groupId>software.xdev</groupId>
<artifactId>find-and-replace-maven-plugin</artifactId>
<version>1.0.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
Expand Down Expand Up @@ -418,6 +470,36 @@
<release>16</release>
</configuration>
</execution>
<execution>
<id>default-compile-19</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java19</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
<release>19</release>
</configuration>
</execution>
<execution>
<id>default-compile-23</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java23</compileSourceRoot>
<compileSourceRoot>${project.build.directory}/generated-sources/windows-api</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
<release>23</release>
<compilerArgs>
<arg>-Xlint:all,-processing,-classfile,-options,-restricted</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-compile-24</id>
<goals>
Expand Down Expand Up @@ -559,8 +641,8 @@
<quiet>true</quiet>
<doclint>none</doclint>
<subpackages>com.jcraft.jsch</subpackages>
<excludePackageNames>com.jcraft.jsch.*</excludePackageNames>
<sourcepath>${project.build.sourceDirectory}:${project.build.directory}/generated-sources/java-templates:${project.basedir}/src/main/java9:${project.basedir}/src/main/java10:${project.basedir}/src/main/java11:${project.basedir}/src/main/java15:${project.basedir}/src/main/java16:${project.basedir}/src/main/java24</sourcepath>
<excludePackageNames>com.jcraft.jsch.*,com.jcraft.jsch.windowsapi.windows.win32.*,com.jcraft.jsch.windowsapi.windows.win32.system.*,com.jcraft.jsch.windowsapi.windows.win32.ui.*</excludePackageNames>
<sourcepath>${project.build.sourceDirectory}:${project.build.directory}/generated-sources/java-templates:${project.basedir}/src/main/java9:${project.basedir}/src/main/java10:${project.basedir}/src/main/java11:${project.basedir}/src/main/java15:${project.basedir}/src/main/java16:${project.basedir}/src/main/java19:${project.basedir}/src/main/java23:${project.build.directory}/generated-sources/windows-api:${project.basedir}/src/main/java24</sourcepath>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -658,6 +740,8 @@
<sourceDirectory>${project.basedir}/src/main/java11</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java15</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java16</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java19</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java23</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java24</sourceDirectory>
<sourceDirectory>${project.basedir}/src/main/java-templates</sourceDirectory>
</sourceDirectories>
Expand All @@ -679,6 +763,8 @@
<directory>${project.basedir}/src/main/java11</directory>
<directory>${project.basedir}/src/main/java15</directory>
<directory>${project.basedir}/src/main/java16</directory>
<directory>${project.basedir}/src/main/java19</directory>
<directory>${project.basedir}/src/main/java23</directory>
<directory>${project.basedir}/src/main/java24</directory>
<directory>${project.basedir}/src/main/java-templates</directory>
</directories>
Expand All @@ -690,8 +776,10 @@
<version>0.8.14</version>
<configuration>
<excludes>
<exclude>com/jcraft/jsch/JavaThreadId.class</exclude>
<exclude>com/jcraft/jsch/JavaVersion.class</exclude>
<exclude>com/jcraft/jsch/JplLogger.class</exclude>
<exclude>com/jcraft/jsch/PageantFFMConnector.class</exclude>
<exclude>com/jcraft/jsch/UnixDomainSocketFactory.class</exclude>
<exclude>com/jcraft/jsch/jce/KeyPairGenEdDSA.class</exclude>
<exclude>com/jcraft/jsch/jce/MLKEM.class</exclude>
Expand All @@ -703,6 +791,7 @@
<exclude>com/jcraft/jsch/jce/XDH.class</exclude>
<exclude>META-INF/versions/9/com/jcraft/jsch/JavaVersion.class</exclude>
<exclude>META-INF/versions/10/com/jcraft/jsch/JavaVersion.class</exclude>
<exclude>META-INF/versions/19/com/jcraft/jsch/JavaThreadId.class</exclude>
</excludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -987,5 +1076,64 @@
</plugins>
</build>
</profile>
<profile>
<id>windowsapi</id>
<activation>
<property>
<name>windowsapi.skip</name>
<value>!true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.codecrete.windows-api</groupId>
<artifactId>windowsapi-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>windows-api</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- see https://github.com/manuelbl/WindowsApiGenerator/issues/7 -->
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround for manuelbl/WindowsApiGenerator#7 that I opened.
I also opened manuelbl/WindowsApiGenerator#9 with a possible solution.
Once this issue is resolved upstream, we should be able to remove this find-and-replace-maven-plugin.

<plugin>
<groupId>software.xdev</groupId>
<artifactId>find-and-replace-maven-plugin</artifactId>
<executions>
<execution>
<id>fix-mapviewoffile-signature</id>
<phase>process-sources</phase>
<goals>
<goal>file-contents</goal>
</goals>
<configuration>
<baseDir>${project.build.directory}/generated-sources/windows-api/com/jcraft/jsch/windowsapi/windows/win32/system/memory/</baseDir>
<fileMask>Apis.java</fileMask>
<encoding>UTF-8</encoding>
<findRegex>MapViewOfFile\(MemorySegment lastErrorState</findRegex>
<replaceValue>MapViewOfFile(SegmentAllocator allocator, MemorySegment lastErrorState</replaceValue>
</configuration>
</execution>
<execution>
<id>fix-mapviewoffile-downcall</id>
<phase>process-sources</phase>
<goals>
<goal>file-contents</goal>
</goals>
<configuration>
<baseDir>${project.build.directory}/generated-sources/windows-api/com/jcraft/jsch/windowsapi/windows/win32/system/memory/</baseDir>
<fileMask>Apis.java</fileMask>
<encoding>UTF-8</encoding>
<findRegex>MapViewOfFile\$IMPL\.HANDLE\.invokeExact\(lastErrorState</findRegex>
<replaceValue>MapViewOfFile\$IMPL.HANDLE.invokeExact(allocator, lastErrorState</replaceValue>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
21 changes: 21 additions & 0 deletions src/assembly/sources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/java19</directory>
<outputDirectory>META-INF/versions/19</outputDirectory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/java23</directory>
<outputDirectory>META-INF/versions/23</outputDirectory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/generated-sources/windows-api</directory>
<outputDirectory>META-INF/versions/23</outputDirectory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/java24</directory>
<outputDirectory>META-INF/versions/24</outputDirectory>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/jcraft/jsch/JavaThreadId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jcraft.jsch;

import com.jcraft.jsch.annotations.SuppressForbiddenApi;

final class JavaThreadId {

Check warning on line 5 in src/main/java/com/jcraft/jsch/JavaThreadId.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=mwiede_jsch&issues=AZx7mek9XBSQSTe5DPn5&open=AZx7mek9XBSQSTe5DPn5&pullRequest=1001

@SuppressForbiddenApi("jdk-deprecated")
static long get() {
return Thread.currentThread().getId();
}
}
36 changes: 25 additions & 11 deletions src/main/java/com/jcraft/jsch/PageantConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinError;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinUser;
Expand Down Expand Up @@ -85,8 +86,10 @@ public void query(Buffer buffer) throws AgentProxyException {
throw new AgentProxyException("Pageant is not runnning.");
}

String mapname =
String.format(Locale.ROOT, "PageantRequest%08x", kernel32.GetCurrentThreadId());
String threadId = JavaVersion.getVersion() >= 19
? String.format(Locale.ROOT, "%08x%08x", kernel32.GetCurrentProcessId(), JavaThreadId.get())
: String.format(Locale.ROOT, "%08x", kernel32.GetCurrentThreadId());
String mapname = "JSchPageantRequest" + threadId;

HANDLE sharedFile = null;
Pointer sharedMemory = null;
Expand All @@ -96,13 +99,19 @@ public void query(Buffer buffer) throws AgentProxyException {

sharedFile = kernel32.CreateFileMapping(WinBase.INVALID_HANDLE_VALUE, psa,
WinNT.PAGE_READWRITE, 0, AGENT_MAX_MSGLEN, mapname);
if (sharedFile == null || sharedFile == WinBase.INVALID_HANDLE_VALUE) {
throw new AgentProxyException("Unable to create shared file mapping.");
int lastError = kernel32.GetLastError();
if (sharedFile == null) {
throw new AgentProxyException(
"Unable to CreateFileMapping(): GetLastError() = " + lastError);
}
if (lastError == WinError.ERROR_ALREADY_EXISTS) {
throw new AgentProxyException("Shared file mapping already exists");
}

sharedMemory = kernel32.MapViewOfFile(sharedFile, WinNT.SECTION_MAP_WRITE, 0, 0, 0);
sharedMemory = kernel32.MapViewOfFile(sharedFile, WinBase.FILE_MAP_WRITE, 0, 0, 0);
if (sharedMemory == null) {
throw new AgentProxyException("Unable to create shared file mapping.");
throw new AgentProxyException(
"Unable to MapViewOfFile(): GetLastError() = " + kernel32.GetLastError());
}

sharedMemory.write(0, buffer.buffer, 0, buffer.getLength());
Expand All @@ -124,13 +133,18 @@ public void query(Buffer buffer) throws AgentProxyException {
sharedMemory.read(4, buffer.buffer, 0, i);
} else {
throw new AgentProxyException(
"User32.SendMessage() returned 0 with cds.dwData: " + Long.toHexString(foo));
"SendMessage() returned 0 with cds.dwData: " + Long.toHexString(foo));
}
} finally {
if (sharedMemory != null)
kernel32.UnmapViewOfFile(sharedMemory);
if (sharedFile != null)
kernel32.CloseHandle(sharedFile);
try {
if (sharedMemory != null) {
kernel32.UnmapViewOfFile(sharedMemory);
}
} finally {
if (sharedFile != null) {
kernel32.CloseHandle(sharedFile);
}
}
}
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/jcraft/jsch/PageantFFMConnector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 PageantFFMConnector implements AgentConnector {

public PageantFFMConnector() throws AgentProxyException {
throw new AgentProxyException("PageantFFMConnector requires Java23+.");
}

@Override
public String getName() {
throw new UnsupportedOperationException("PageantFFMConnector requires Java23+.");
}

@Override
public boolean isAvailable() {
throw new UnsupportedOperationException("PageantFFMConnector requires Java23+.");
}

@Override
public void query(Buffer buffer) throws AgentProxyException {
throw new UnsupportedOperationException("PageantFFMConnector requires Java23+.");
}
}
8 changes: 8 additions & 0 deletions src/main/java19/com/jcraft/jsch/JavaThreadId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.jcraft.jsch;

final class JavaThreadId {

Check warning on line 3 in src/main/java19/com/jcraft/jsch/JavaThreadId.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=mwiede_jsch&issues=AZx7men0XBSQSTe5DPn7&open=AZx7men0XBSQSTe5DPn7&pullRequest=1001

static long get() {
return Thread.currentThread().threadId();
}
}
Loading