Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3295877
D11282.id38021.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11282.id38021.diff
View Options
diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -41,6 +41,7 @@
multimediaUploadResponder,
uploadDownloadResponder,
} from './uploads/uploads.js';
+import { createAuthoritativeKeyserverConfigFiles } from './user/create-configs.js';
import { verifyUserLoggedIn } from './user/login.js';
import { initENSCache } from './utils/ens-cache.js';
import { getContentSigningKey } from './utils/olm-utils.js';
@@ -106,6 +107,9 @@
ignorePromiseRejections(
createAndMaintainTunnelbrokerWebsocket(identityInfo),
);
+ if (process.env.NODE_ENV === 'development') {
+ await createAuthoritativeKeyserverConfigFiles(identityInfo.userId);
+ }
} catch (e) {
console.warn(
'Failed identity login. Login optional until staging environment is available',
diff --git a/keyserver/src/user/create-configs.js b/keyserver/src/user/create-configs.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/user/create-configs.js
@@ -0,0 +1,72 @@
+// @flow
+
+import fs from 'fs';
+
+import { getCommConfig } from 'lib/utils/comm-config.js';
+
+import type { UserCredentials } from './checks.js';
+
+async function createFile(path: string, name: string, data: string) {
+ const filePath = `${path}/${name}`;
+
+ try {
+ await fs.promises.mkdir(path);
+ } catch (e) {
+ if (e.code !== 'EEXIST') {
+ throw e;
+ }
+ }
+ await fs.promises.writeFile(filePath, data);
+}
+
+async function createAuthoritativeKeyserverConfigFiles(userID: string) {
+ const userInfo = await getCommConfig<UserCredentials>({
+ folder: 'secrets',
+ name: 'user_credentials',
+ });
+
+ if (!userInfo?.usingIdentityCredentials) {
+ // If the keyserver is not set up to use its identity id,
+ // we will also not set up the clients to use the keyservers real id
+ return;
+ }
+
+ try {
+ const authoritativeKeyserver = {
+ authoritativeKeyserverID: userID,
+ };
+ const authoritativeKeyserverJSON = JSON.stringify(
+ authoritativeKeyserver,
+ null,
+ 2,
+ );
+ const authoritativeKeyserverFile = 'authoritative_keyserver.json';
+
+ const nativeFactsFolder = '../native/facts';
+ const nativePromise = createFile(
+ nativeFactsFolder,
+ authoritativeKeyserverFile,
+ authoritativeKeyserverJSON,
+ );
+
+ const keyserverFactsFolder = 'facts';
+ const keyserverPromise = createFile(
+ keyserverFactsFolder,
+ authoritativeKeyserverFile,
+ authoritativeKeyserverJSON,
+ );
+
+ await Promise.all([nativePromise, keyserverPromise]);
+ } catch (e) {
+ // This means that the clients will not be configured to use
+ // the real keyserver id, and will use the default 256.
+ // Try restarting the keyserver or create the files manually
+ console.error(
+ 'Failure creating configuration files: ' +
+ 'admin data could not be correctly written',
+ e,
+ );
+ }
+}
+
+export { createAuthoritativeKeyserverConfigFiles };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 11:35 PM (22 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531658
Default Alt Text
D11282.id38021.diff (2 KB)
Attached To
Mode
D11282: [keyserver] Create json files with authoritative keyserver id
Attached
Detach File
Event Timeline
Log In to Comment