-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jo/updated-shell
- Loading branch information
Showing
15 changed files
with
197 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: test | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
on: | ||
pull_request: { types: [opened, reopened, synchronize, ready_for_review] } | ||
push: { branches: [main] } | ||
|
||
env: | ||
LOG_LEVEL: info | ||
SWIFT_DETERMINISTIC_HASHING: 1 | ||
jobs: | ||
test: | ||
services: | ||
ssh-server: | ||
image: lscr.io/linuxserver/openssh-server:latest | ||
ports: | ||
- 2222:2222 | ||
env: | ||
USER_NAME: citadel | ||
USER_PASSWORD: hunter2 | ||
PASSWORD_ACCESS: true | ||
runs-on: ubuntu-latest | ||
container: | ||
image: swift:5.10-jammy | ||
env: | ||
SWIFT_DETERMINISTIC_HASHING: 1 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Resolve | ||
run: swift package resolve | ||
- name: Run tests | ||
run: swift test | ||
env: | ||
SWIFT_DETERMINISTIC_HASHING: 1 | ||
SSH_HOST: ssh-server | ||
SSH_PORT: 2222 | ||
SSH_USERNAME: citadel | ||
SSH_PASSWORD: hunter2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
xcuserdata/ | ||
Package.resolved | ||
citadel_host_key_ed25519 | ||
.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
FROM ubuntu:latest | ||
|
||
RUN apt update && apt install openssh-server sudo -y | ||
|
||
RUN echo "ubuntu:test" | chpasswd | ||
|
||
RUN service ssh start | ||
|
||
EXPOSE 22 | ||
|
||
CMD ["/usr/sbin/sshd","-D"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import NIO | ||
import CryptoKit | ||
import Crypto | ||
import Logging | ||
import NIOSSH | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
Sources/Citadel/DirectTCPIP/Server/DirectTCPIP+Server.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import NIO | ||
import NIOSSH | ||
|
||
fileprivate final class ProxyChannelHandler: ChannelOutboundHandler { | ||
typealias OutboundIn = ByteBuffer | ||
|
||
private let write: (ByteBuffer, EventLoopPromise<Void>?) -> Void | ||
|
||
init(write: @escaping (ByteBuffer, EventLoopPromise<Void>?) -> Void) { | ||
self.write = write | ||
} | ||
|
||
func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) { | ||
let data = self.unwrapOutboundIn(data) | ||
write(data, promise) | ||
} | ||
} | ||
|
||
public protocol DirectTCPIPDelegate { | ||
func initializeDirectTCPIPChannel(_ channel: Channel, request: SSHChannelType.DirectTCPIP, context: SSHContext) -> EventLoopFuture<Void> | ||
} | ||
|
||
public struct DirectTCPIPForwardingDelegate: DirectTCPIPDelegate { | ||
internal enum Error: Swift.Error { | ||
case forbidden | ||
} | ||
|
||
public var whitelistedHosts: [String]? | ||
public var whitelistedPorts: [Int]? | ||
|
||
public init() {} | ||
|
||
public func initializeDirectTCPIPChannel(_ channel: Channel, request: SSHChannelType.DirectTCPIP, context: SSHContext) -> EventLoopFuture<Void> { | ||
if let whitelistedHosts, !whitelistedHosts.contains(request.targetHost) { | ||
return channel.eventLoop.makeFailedFuture(Error.forbidden) | ||
} | ||
|
||
if let whitelistedPorts, !whitelistedPorts.contains(request.targetPort) { | ||
return channel.eventLoop.makeFailedFuture(Error.forbidden) | ||
} | ||
|
||
return ClientBootstrap(group: channel.eventLoop) | ||
.connect(host: request.targetHost, port: request.targetPort) | ||
.flatMap { remote in | ||
channel.pipeline.addHandlers([ | ||
DataToBufferCodec() | ||
]).flatMap { | ||
channel.pipeline.addHandler(ProxyChannelHandler { data, promise in | ||
remote.writeAndFlush(data, promise: promise) | ||
}) | ||
}.flatMap { | ||
remote.pipeline.addHandler(ProxyChannelHandler { [weak channel] data, promise in | ||
guard let channel else { | ||
promise?.fail(ChannelError.ioOnClosedChannel) | ||
return | ||
} | ||
channel.writeAndFlush(data, promise: promise) | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters