Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live renewal of the TLS options #331

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ A [bunyan logger](https://github.com/trentm/node-bunyan) instance. Created by de
Sets the timeout (in ms) after that an idle connection is closed by the server
__Default:__ `0`

## Renew TLS options
[`renewTlsOptions(tlsOptions)`](src/index.js#L172) is used to read and use a new set of TLS certificates without restarting the server.
Receives the same options as the [tls parameter](#tls) parameter in the constructor.
```js
let originalOptions = {};
originalOptions.tls = {
key: fs.readFileSync("\path\to\old\key.pem"),
cert: fs.readFileSync("\path\to\old\cert.pem")
}
let ftpServer = new FtpServer(originalOptions);

// Afterwards when the certificate is going to expire, it will need to be renewed
let newTlsOptions = {
key: fs.readFileSync("\path\to\new\key.pem"),
cert: fs.readFileSync("\path\to\new\cert.pem")
}
ftpServer.renewTlsOptions(newTlsOptions);
```

## CLI

`ftp-srv` also comes with a builtin CLI.
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,9 @@ class FtpServer extends EventEmitter {
});
}

renewTlsOptions(tlsOptions) {
this.server.setSecureContext(tlsOptions);
this.log.debug('Updating TLS options');
}
}
module.exports = FtpServer;