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

[IMPROVE] Add an optional rocketchat-protocol DNS entry for Federation #14589

Merged
merged 3 commits into from
May 30, 2019
Merged
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
21 changes: 12 additions & 9 deletions app/federation/server/PeerDNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,23 @@ export class PeerDNS {

const [srvEntry] = srvEntries;

// Get the public key from the TXT record
const txtRecords = dnsResolveTXT(`rocketchat-public-key.${ domain }`);
// Get the protocol from the TXT record, if exists
let protocol = 'https';

// Get the first TXT record, this subdomain should have only a single record
const txtRecord = txtRecords[0];
try {
const protocolTxtRecords = dnsResolveTXT(`rocketchat-protocol.${ domain }`);

// If there is no record, skip
if (!txtRecord) {
throw new Meteor.Error('ENOTFOUND', 'Could not find public key entry on TXT records');
protocol = protocolTxtRecords[0][0].toLowerCase() === 'http' ? 'http' : 'https';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is [0][0] always guaranteed to be here? Should we check here or are we ok with this pattern of just "handling" / ignoring the exception that is thrown?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from node docs it seems to br guaranteed

} catch (err) {
// Ignore the error if the rocketchat-protocol TXT entry does not exist
}

const publicKey = txtRecord.join('');

const protocol = srvEntry.name === 'localhost' ? 'http' : 'https';
// Get the public key from the TXT record
const publicKeyTxtRecords = dnsResolveTXT(`rocketchat-public-key.${ domain }`);

// Get the first TXT record, this subdomain should have only a single record
const publicKey = publicKeyTxtRecords[0].join('');

return {
domain,
Expand Down