Skip to content

Commit

Permalink
Merge pull request #515 from NuSkooler/bugfix/ssh_doc_updates
Browse files Browse the repository at this point in the history
Updated the SSH version, config, and documentation
  • Loading branch information
NuSkooler authored Oct 12, 2023
2 parents 1a99153 + 270c09e commit c84b3ee
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 293 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ logs/
mail/
node_modules/
docs/_site/
docs/.sass-cache/
docs/.sass-cache/

docs/.jekyll-cache/
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ npm install # or simply 'yarn'
## 0.0.13-beta to 0.0.14-beta

* Due to changes to supported algorithms in newer versions of openssl, the default list of supported algorithms for the ssh login server has changed. There are both removed ciphers as well as optional new kex algorithms available now. ***NOTE:*** Changes to supported algorithms are only needed to support keys generated with new versions of openssl, if you already have a ssl key in use you should not have to make any changes to your config.
* Removed ciphers: 'blowfish-cbc', 'arcfour256', 'arcfour128', and 'cast128-cbc'
* Added kex: 'curve25519-sha256', '[email protected]', 'curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521'

## 0.0.12-beta to 0.0.13-beta
* To enable the new Waiting for Caller (WFC) support, please see [WFC](docs/modding/wfc.md).
* :exclamation: The SSH server's `ssh2` module has gone through a major upgrade. Existing users will need to comment out two SSH KEX algorithms from their `config.hjson` if present else clients such as NetRunner will not be able to connect over SSH. Comment out `diffie-hellman-group-exchange-sha256` and `diffie-hellman-group-exchange-sha1`
Expand Down
28 changes: 10 additions & 18 deletions core/config_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,15 @@ module.exports = () => {
//
// 1 - Generate a Private Key (PK):
// Currently ENiGMA 1/2 requires a PKCS#1 PEM formatted PK.
// To generate a secure PK, issue the following command:
//
// > openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 \
// -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa \
// -out ./config/security/ssh_private_key.pem -aes128
//
// (The above is a more modern equivalent of the following):
// > openssl genrsa -aes128 -out ./config/security/ssh_private_key.pem 2048
// For information on generating a key, see:
// https://nuskooler.github.io/enigma-bbs/servers/loginservers/ssh.html#generate-a-ssh-private-key
//
// 2 - Set 'privateKeyPass' to the password you used in step #1
//
// 3 - Finally, set 'enabled' to 'true'
//
// Additional reading:
// - https://blog.sleeplessbeastie.eu/2017/12/28/how-to-generate-private-key/
// - https://gist.github.com/briansmith/2ee42439923d8e65a266994d0f70180b
// - https://nuskooler.github.io/enigma-bbs/servers/loginservers/ssh.html
//
privateKeyPem: paths.join(
__dirname,
Expand All @@ -222,14 +215,18 @@ module.exports = () => {
//
algorithms: {
kex: [
'curve25519-sha256',
'[email protected]',
'ecdh-sha2-nistp256',
'ecdh-sha2-nistp384',
'ecdh-sha2-nistp521',
'diffie-hellman-group14-sha1',
'diffie-hellman-group1-sha1',
// Group exchange not currnetly supported
// 'diffie-hellman-group-exchange-sha256',
// 'diffie-hellman-group-exchange-sha1',
'curve25519-sha256',
'[email protected]',
'ecdh-sha2-nistp256',
'ecdh-sha2-nistp384',
'ecdh-sha2-nistp521',
],
cipher: [
'aes128-ctr',
Expand All @@ -242,12 +239,7 @@ module.exports = () => {
'aes256-cbc',
'aes192-cbc',
'aes128-cbc',
'blowfish-cbc',
'3des-cbc',
'arcfour256',
'arcfour128',
'cast128-cbc',
'arcfour',
],
hmac: [
'hmac-sha2-256',
Expand Down
3 changes: 3 additions & 0 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ GEM
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
minitest (5.19.0)
nokogiri (1.15.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
pathutil (0.16.2)
Expand All @@ -101,6 +103,7 @@ GEM
webrick (1.8.1)

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ collections:
- admin/oputil.md
- admin/updating.md
- troubleshooting/monitoring-logs.md
- troubleshooting/ssh-troubleshooting.md

81 changes: 67 additions & 14 deletions docs/_docs/servers/loginservers/ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ layout: page
title: SSH Server
---
## SSH Login Server

The ENiGMA½ SSH *login server* allows secure user logins over SSH (ssh://).

*Note:* If you run into any troubles during SSH setup, please see [Troubleshooting SSH](../../troubleshooting/ssh-troubleshooting.md)

## Configuration

Entries available under `config.loginServers.ssh`:

| Item | Required | Description |
Expand All @@ -20,10 +24,8 @@ Entries available under `config.loginServers.ssh`:
| `algorithms` | :-1: | Configuration block for SSH algorithms. Includes keys of `kex`, `cipher`, `hmac`, and `compress`. See the algorithms section in the [ssh2-streams](https://github.com/mscdex/ssh2-streams#ssh2stream-methods) documentation for details. For defaults set by ENiGMA½, see `core/config_default.js`.
| `traceConnections` | :-1: | Set to `true` to enable full trace-level information on SSH connections.


* *IMPORTANT* With the `privateKeyPass` option set, make sure that you verify that the config file is not readable by other users!


### Example Configuration

```hjson
Expand All @@ -40,43 +42,94 @@ Entries available under `config.loginServers.ssh`:
```

## Generate a SSH Private Key

To utilize the SSH server, an SSH Private Key (PK) will need generated. OpenSSH or (with some versions) OpenSSL can be used for this task:

### OpenSSH
### OpenSSH (Preferred)

#### OpenSSH Install - Linux / Mac

If it is not already available, install OpenSSH using the package manager of your choice (should be pre-installed on most distributions.)

#### Running OpenSSH - Linux / Mac

From the root directory of the Enigma BBS, run the following:

```shell
mkdir -p config/security
ssh-keygen -t rsa -m PEM -h -f config/security/ssh_private_key.pem
```

#### Windows Install - OpenSSH

OpenSSH may already be installed, try running `ssh-keygen.exe`. If not, see this page: [Install OpenSSH for Windows](https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui)

#### Running OpenSSH - Windows

After installation, go to the root directory of your enigma project and run:

```bash
ssh-keygen -m PEM -h -f config/ssh_private_key.pem
```powershell
mkdir .\config\security -ErrorAction SilentlyContinue
ssh-keygen.exe -t rsa -m PEM -h -f .\config\security\ssh_private_key.pem
```

#### ssh-keygen options

Option descriptions:

| Option | Description |
|------|-------------|
| `-t rsa` | Use the RSA algorithm needed for the `ssh2` library |
| `-m PEM` | Set the output format to `PEM`, compatible with the `ssh2` library |
| `-h` | Generate a host key |
| `-f config/ssh_private_key.pem` | Filename for the private key. Used in the `privateKeyPem` option in the configuration |

When you execute the `ssh-keygen` command it will ask for a passphrase (and a confirmation.) This should then be used as the value for `privateKeyPass` in the configuration.


### OpenSSL

If you do not have OpenSSH installed or if you have trouble with the above OpenSSH commands, using some versions for OpenSSL (before version 3) the following commands may work as well:
#### Open SSL Install - Linux / Mac

If not already installed, install via the `openssl` package on most package managers.

```bash
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./config/ssh_private_key.pem -aes128
#### Open SSL Install - Windows

```powershell
winget install -e --id ShiningLight.OpenSSL
```

Or for even older OpenSSL versions:
#### Running OpenSSL

```bash
openssl genrsa -aes128 -out ./config/ssh_private_key.pem 2048
*Note:* Using `ssh-keygen` from OpenSSL is recommended where possible. If you have trouble with the above OpenSSH commands, using some versions for OpenSSL (before version 3) the following commands may work as well:

#### Running OpenSSL - Linux / Mac

Run the following from the root directory of Enigma

```shell
mkdir -p config/security
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./config/security/ssh_private_key.pem -aes128
```

Note that you may need `-3des` for very old implementations or SSH clients!
#### Running OpenSSL - Windows

Run the following from the root directory of Enigma (note: you may need to specify the full path to openssl.exe if it isn't in your system path, on my system it was `C:\Program Files\OpenSSL-Win64\bin\openssl.exe`):

```powershell
mkdir .\config\security -ErrorAction SilentlyContinue
openssl.exe genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl.exe rsa -out ./config/security/ssh_private_key.pem -aes128
```

#### Running Older OpenSSL

For older OpenSSL versions, the following command has been known to work:

```shell
openssl genrsa -aes128 -out ./config/ssh_private_key.pem 2048
```

*Note:* that you may need `-3des` for very old implementations or SSH clients!

## Prompt

The keyboard interactive prompt can be customized using a `SSHPMPT.ASC` art file. See [art](../../art/general.md) for more information on configuring. This prompt includes a `newUserNames` variable to show the list of allowed new user names (see `firstMenuNewUser` above.) See [mci](../../art/mci.md) for information about formatting this string. Note: Regardless of the content of the `SSHPMPT.ASC` file, the prompt is surrounded by "Access denied", a newline, the prompt, another newline, and then the string "\[username]'s password: ". This normally occurs after the first password prompt (no art is shown before the first password attempt is made.)
The keyboard interactive prompt can be customized using a `SSHPMPT.ASC` art file. See [art](../../art/general.md) for more information on configuring. This prompt includes a `newUserNames` variable to show the list of allowed new user names (see `firstMenuNewUser` above.) See [mci](../../art/mci.md) for information about formatting this string. Note: Regardless of the content of the `SSHPMPT.ASC` file, the prompt is surrounded by "Access denied", a newline, the prompt, another newline, and then the string "\[username]'s password: ". This normally occurs after the first password prompt (no art is shown before the first password attempt is made.)
45 changes: 45 additions & 0 deletions docs/_docs/troubleshooting/ssh-troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: page
title: Troubleshooting SSH
---

Stuck with errors trying to get your SSH setup configured? See below for some common problems. Or as always, reach out to us by creating an [Issue](https://github.com/NuSkooler/enigma-bbs/issues) or start a [Discussion](https://github.com/NuSkooler/enigma-bbs/discussions)

## No Such File or Directory

***Symptom:***
BBS not starting with an error similar to the following:

```shell
Error initializing: Error: ENOENT: no such file or directory, open '<path>/config/security/ssh_private_key.pem'
```

***Solution:***
Several things can cause this:

1. `ssh_private_key.pem` was installed to the wrong location. Make sure that it is in the `config/security` directory and has the name matching the error message. You can also change your `config.hjson` if you prefer to point to the location of the key file.
2. `ssh_private_key.pem` has the wrong file permissions. Verify that the file will be readable by the user that the BBS is running as. Because it is a cryptographic key however, we do recommend that access is restricted only to that user.

## Error With Netrunner

***Symptom:***
Some ssh clients connect, but Netrunner (and other older clients) get a connection failed message and the following is in the log:

```shell
"level":40,"error":"Handshake failed","code":2,"msg":"SSH connection error"
```

***Solution:***

The key was most likely not generated with the `-t rsa` option, and is using a newer algorithm that is not supported by Netrunner and similar clients. Regenerate the certificate with the `-t rsa` option.

***Symptom:***
Some ssh clients connect, but Netrunner (and other older clients) get a connection failed message and the following is in the log:

```shell
"level":40,"error":"Group exchange not implemented for server","msg":"SSH connection error"
```

***Solution:***

Remove the following encryption protocols from your `config.hjson`: `diffie-hellman-group-exchange-sha256` and `diffie-hellman-group-exchange-sha1`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"sanitize-filename": "^1.6.3",
"sqlite3": "5.1.6",
"sqlite3-trans": "1.3.0",
"ssh2": "1.11.0",
"ssh2": "1.14.0",
"systeminformation": "5.21.7",
"telnet-socket": "0.2.4",
"temptmp": "^1.1.0",
Expand Down
Loading

0 comments on commit c84b3ee

Please sign in to comment.