roster-server 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -754,8 +754,18 @@ class Roster {
|
|
|
754
754
|
const dispatcher = createDispatcher(portData);
|
|
755
755
|
const upgradeHandler = createUpgradeHandler(portData);
|
|
756
756
|
const greenlockStorePath = this.greenlockStorePath;
|
|
757
|
+
const normalizeHostInput = (value) => {
|
|
758
|
+
if (typeof value === 'string') return value;
|
|
759
|
+
if (!value || typeof value !== 'object') return '';
|
|
760
|
+
if (typeof value.servername === 'string') return value.servername;
|
|
761
|
+
if (typeof value.hostname === 'string') return value.hostname;
|
|
762
|
+
if (typeof value.subject === 'string') return value.subject;
|
|
763
|
+
return '';
|
|
764
|
+
};
|
|
757
765
|
const loadCert = (subjectDir) => {
|
|
758
|
-
const
|
|
766
|
+
const normalizedSubject = normalizeHostInput(subjectDir).trim().toLowerCase();
|
|
767
|
+
if (!normalizedSubject) return null;
|
|
768
|
+
const certPath = path.join(greenlockStorePath, 'live', normalizedSubject);
|
|
759
769
|
const keyPath = path.join(certPath, 'privkey.pem');
|
|
760
770
|
const certFilePath = path.join(certPath, 'cert.pem');
|
|
761
771
|
const chainPath = path.join(certPath, 'chain.pem');
|
|
@@ -768,13 +778,15 @@ class Roster {
|
|
|
768
778
|
return null;
|
|
769
779
|
};
|
|
770
780
|
const zoneSubjectForHost = (servername) => {
|
|
771
|
-
const
|
|
781
|
+
const host = normalizeHostInput(servername).trim().toLowerCase();
|
|
782
|
+
const labels = host.split('.').filter(Boolean);
|
|
772
783
|
if (labels.length < 3) return null;
|
|
773
784
|
return labels.slice(1).join('.');
|
|
774
785
|
};
|
|
775
786
|
const resolvePemsForServername = (servername) => {
|
|
776
|
-
|
|
777
|
-
|
|
787
|
+
const host = normalizeHostInput(servername).trim().toLowerCase();
|
|
788
|
+
if (!host) return null;
|
|
789
|
+
return loadCert(host) || loadCert(zoneSubjectForHost(host));
|
|
778
790
|
};
|
|
779
791
|
|
|
780
792
|
if (portNum === this.defaultPort) {
|