Skip to content

Commit 60b4a04

Browse files
committed
Added support for AWS IoT on port 443.
1 parent a1c2fbd commit 60b4a04

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ When chariotd exists due to communications failure and there are multiple certif
103103
104104
In order to easily handle certificate rotation chariotd is designed around the concept of certificate stores rather than single certificate. A certificate store is simply a base directory containing an `endpoint.txt` file listing the AWS IoT endpoint the certificates apply to, and a number of sub directories with each containing a certificate and associated private key.
105105
106+
The `endpoint.txt` may contain either just the hostname of the IoT endpoint,
107+
or hostname and port number in the form of `hostname:port`. The latter can
108+
be used to switch from the standard MQTTS port (8883) to the HTTPS port (443).
109+
This can be necessary when located behind a restrictive firewall which does
110+
not permit outbound MQTTS traffic, but does allow HTTPS. Internally, the
111+
ALPN TLS option is automatically set to `x-amzn-mqtt-ca` whenever port
112+
443 is specified.
113+
106114
Example:
107115
```
108116
/path/to/certstore/

src/certstore.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ CertStore.prototype.rotatePreferred = function() {
4141

4242
// returns [ { certId:, certPath:, caPath:, host:, clientId: }, ... ]
4343
CertStore.prototype.getCerts = function() {
44-
const endpoint =
44+
const endpoint_raw =
4545
fs.readFileSync(`${this._basedir}/endpoint.txt`, utf8).trim();
46+
const endpoint = (endpoint_raw.indexOf(':') != -1) ?
47+
endpoint_raw.split(':') : [ endpoint_raw, null ];
4648
// Get ordered list of subdirs, most recent first
4749
const dirs = fs.readdirSync(this._basedir, { withFileTypes: true })
4850
.filter(dirent => dirent.isDirectory())
@@ -58,7 +60,8 @@ CertStore.prototype.getCerts = function() {
5860
certId: x.name,
5961
certPath: `${this._basedir}/${x.name}/${x.name}-certificate.pem.crt`,
6062
keyPath: `${this._basedir}/${x.name}/${x.name}-private.pem.key`,
61-
host: endpoint,
63+
host: endpoint[0],
64+
port: endpoint[1],
6265
caPath: this._caPath,
6366
clientId: this._clientId,
6467
}));

src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ function connect() {
212212
console.info('Connecting to AWS IoT Core...');
213213

214214
const keepalive = options.keepalive != null ? +options.keepalive : 1200;
215+
const alpn = (ourcerts.preferred.port == 443) ?
216+
{ ALPNProtocols: [ 'x-amzn-mqtt-ca' ] } : undefined;
215217
const comms = awsiot.thingShadow(
216-
Object.assign({ keepalive }, ourcerts.preferred));
218+
Object.assign({ keepalive }, ourcerts.preferred, alpn));
217219
const registered = {};
218220
++comms_attempts;
219221
comms.on('connect', () => {

0 commit comments

Comments
 (0)