Skip to content

Commit

Permalink
update project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ElNiak committed Dec 22, 2023
1 parent bac4339 commit 513a9d0
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 40 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ env:

install:
. ssh3_env/bin/activate && python3 -m pip install wheel && python3 -m pip install .

run-server:
. ssh3_env/bin/activate && python3 py-ssh3/cli/server/main.py

run-client:
. ssh3_env/bin/activate && python3 py-ssh3/cli/client/main.py
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ make env; make install;
## Usage

### PySSH3 server

```bash
# TODO add arguments
make run-server
./ssh3_env/bin/activate && python3 py-ssh3/server_cli.py
```

#### Authorized keys and authorized identities
TODO

### PySSH3 client
```bash
make run-client
./ssh3_env/bin/activate && python3 py-ssh3/client_cli.py
```

#### Private-key authentication
Expand All @@ -45,4 +46,5 @@ TODO
- [ ] Add documentation
- [ ] Add examples
- [ ] Add more features
- [ ] Add threading support
- [ ] Add threading support
- [ ] Inspire more from [paramiko]
Empty file removed py-ssh3/cli/client/__init__.py
Empty file.
Empty file.
Empty file removed py-ssh3/cli/server/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions py-ssh3/linux_server/auth.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from flask import Flask, request, Response
import base64
import logging
from functools import wraps

app = Flask(__name__)

def handle_auths(enable_password_login, default_max_packet_size, authenticated_handler_func):
def auth_decorator(f):
@wraps(f)
Expand Down Expand Up @@ -42,12 +39,3 @@ def decorated_function(*args, **kwargs):
def check_credentials(username, password):
# Placeholder for checking username and password
return True # Assuming credentials are valid

@app.route('/your-endpoint', methods=['GET', 'POST'])
@handle_auths(enable_password_login=True, default_max_packet_size=30000, authenticated_handler_func=None)
def your_endpoint():
# Implement the logic for the specific endpoint
return "Endpoint logic"

if __name__ == '__main__':
app.run(host='0.0.0.0', port=443)
33 changes: 15 additions & 18 deletions py-ssh3/cli/server/main.py → py-ssh3/server_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import signal
import subprocess
import asyncio
import socket
import contextlib
import signal
import fcntl
import struct
Expand Down Expand Up @@ -55,7 +52,7 @@
"SIGVTALRM": signal.SIGVTALRM,
"SIGWINCH": signal.SIGWINCH,
"SIGXCPU": signal.SIGXCPU,
"SIGXFSZ": signal.SIGXFSZ,
"SIGXFSZ": signal.SIGXFSZ
}

class ChannelType:
Expand Down Expand Up @@ -250,52 +247,52 @@ async def main():
if not certPathExists:
logging.error(f"the \"{args.certPath}\" certificate file does not exist")
if not keyPathExists:
logging.error(f"the \"{args.keyPath}\" certificate private key file does not exist")
log.error(f"the \"{args.keyPath}\" certificate private key file does not exist")
if not certPathExists or not keyPathExists:
logging.error("If you have no certificate and want a security comparable to traditional SSH host keys, you can generate a self-signed certificate using the -generate-selfsigned-cert arg or using the following script:")
logging.error("https://github.com/francoismichel/ssh3/blob/main/generate_openssl_selfsigned_certificate.sh")
log.error("If you have no certificate and want a security comparable to traditional SSH host keys, you can generate a self-signed certificate using the -generate-selfsigned-cert arg or using the following script:")
log.error("https://github.com/ElNiak/py-ssh3/blob/main/generate_openssl_selfsigned_certificate.sh")
os.Exit(-1)
else:
if certPathExists:
logging.error(f"asked for generating a certificate but the \"{args.certPath}\" file already exists")
log.error(f"asked for generating a certificate but the \"{args.certPath}\" file already exists")
if keyPathExists:
logging.error(f"asked for generating a private key but the \"{args.keyPath}\" file already exists")
log.error(f"asked for generating a private key but the \"{args.keyPath}\" file already exists")
if certPathExists or keyPathExists:
os.Exit(-1)
pubkey, privkey, err = util.generate_key()
if err != None:
logging.error(f"could not generate private key: {err}")
log.error(f"could not generate private key: {err}")
os.Exit(-1)
cert, err = util.GenerateCert(privkey)
if err != None:
logging.error(f"could not generate certificate: {err}")
log.error(f"could not generate certificate: {err}")
os.Exit(-1)

err = util.DumpCertAndKeyToFiles(cert, pubkey, privkey, args.certPath, args.keyPath)
if err != None:
logging.error(f"could not save certificate and key to files: {err}")
log.error(f"could not save certificate and key to files: {err}")
os.Exit(-1)

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
log.basicConfig(level=log.DEBUG)
else:
log_level = os.getenv("SSH3_LOG_LEVEL")
if log_level:
numeric_level = getattr(logging, log_level.upper(), None)
numeric_level = getattr(log, log_level.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError(f"Invalid log level: {log_level}")
logging.basicConfig(level=numeric_level)
log.basicConfig(level=numeric_level)

logFileName = os.getenv("SSH3_LOG_FILE")
if logFileName == "":
logFileName = "/var/log/ssh3.log"
logFile = open(logFileName, "a")
logging.basicConfig(filename=logFile, level=logging.INFO)
log.basicConfig(filename=logFile, level=log.INFO)

# quicConf = &quic.Config{
# Allow0RTT: True,
# }


if __name__ == "__main__":
asyncio.run(main())
if __name__ == "__main__":
asyncio.run(main())
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 513a9d0

Please sign in to comment.