GithubHelp home page GithubHelp logo

adobels / citadel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from orlandos-nl/citadel

0.0 0.0 0.0 179 KB

SSH Client & Server in Swift

License: MIT License

C 21.55% Swift 78.20% Dockerfile 0.25%

citadel's Introduction

Citadel

Citadel is a high level API around NIOSSH. It aims to add what's out of scope for NIOSSH, lending code from my private tools.

It features the following helpers:

  • TCP-IP forwarding child channels
  • Basic SFTP Client
  • TTY support
  • SSH Key format parsing

Read the docs

Usage

If you have any questions, join the Discord

Supporting Older Cryptography

If you need deprecated crypto support, you can enable Citadel's (or custom) algorithms like so. This is a global setting and needs to happen before connecting.

NIOSSHAlgorithms.register(
    publicKey: Insecure.RSA.PublicKey.self,
    signature: Insecure.RSA.Signature.self
)

NIOSSHAlgorithms.register(transportProtectionScheme: AES128CTR.self)
NIOSSHAlgorithms.register(keyExchangeAlgorithm: DiffieHellmanGroup14Sha1.self)

SSH Proxy for MongoKitten

// - MARK: Fill these in:
let eventloop: EventLoop

// E.G. example.com
let sshHost: String

// Password or public key
let sshCredentials: SSHAuthenticationMethod

// Accept anything, custom validator or predefined keys
let hostKeyValidator: SSHHostKeyValidator

// Use a custom Mongo Connection builder
let pool = MongoSingleConnectionPool(
    eventLoop: eventLoop, 
    // Provide an authenticationSource, as defined by MongoDB. If unknown, likely `admin`
    authenticationSource: settings.authenticationSource ?? "admin",
    // Provide MongoKitten credentials
    credentials: settings.authentication
) { eventLoop in
    // Create a connection boot
    SSHClient.connect(
        sshHost: sshHost,
        authenticationMethod: sshAuthenticationMethod,
        hostKeyValidator: hostKeyValidator
    ).flatMap { sshClient in
        // The address that is presented as the locally exposed interface
        // This is purely communicated to the SSH server
        let address: SocketAddress
        
        do {
            address = try SocketAddress(ipAddress: "fe80::1", port: 27017)
        } catch {
            return sshChannel.eventLoop.makeFailedFuture(SSHClientError.invalidOriginAddress)
        }
        
        return sshClient.createDirectTCPIPChannel(
            using: SSHChannelType.DirectTCPIP(
                targetHost: "localhost", // MongoDB host 
                targetPort: 27017, // MongoDB port
                originatorAddress: address
            )
        )
    }.flatMap { childChannel in
        MongoConnection.addHandlers(to: childChannel, context: context)
    }
}

TODO

A couple of code is held back until further work in SwiftNIO SSH is completed.

Contributing

I'm happy to accept ideas and PRs for new API's.

citadel's People

Contributors

gwynne avatar jaapwijnen avatar jdmcd avatar joannis avatar michalbencur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.