Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/socket/session-utils.js
Show All 35 Lines | |||||
import { hash } from 'lib/utils/objects.js'; | import { hash } from 'lib/utils/objects.js'; | ||||
import { promiseAll } from 'lib/utils/promises.js'; | import { promiseAll } from 'lib/utils/promises.js'; | ||||
import { | import { | ||||
tShape, | tShape, | ||||
tPlatform, | tPlatform, | ||||
tPlatformDetails, | tPlatformDetails, | ||||
} from 'lib/utils/validation-utils.js'; | } from 'lib/utils/validation-utils.js'; | ||||
import { createOlmSession } from '../creators/olm-session-creator.js'; | |||||
import { saveOneTimeKeys } from '../creators/one-time-keys-creator.js'; | import { saveOneTimeKeys } from '../creators/one-time-keys-creator.js'; | ||||
import createReport from '../creators/report-creator.js'; | import createReport from '../creators/report-creator.js'; | ||||
import { SQL } from '../database/database.js'; | import { SQL } from '../database/database.js'; | ||||
import { | import { | ||||
fetchEntryInfos, | fetchEntryInfos, | ||||
fetchEntryInfosByID, | fetchEntryInfosByID, | ||||
fetchEntriesForSession, | fetchEntriesForSession, | ||||
} from '../fetchers/entry-fetchers.js'; | } from '../fetchers/entry-fetchers.js'; | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | const clientResponseInputValidator: TUnion<ClientResponse> = t.union([ | ||||
}), | }), | ||||
tShape({ | tShape({ | ||||
type: t.irreducible( | type: t.irreducible( | ||||
'serverRequestTypes.SIGNED_IDENTITY_KEYS_BLOB', | 'serverRequestTypes.SIGNED_IDENTITY_KEYS_BLOB', | ||||
x => x === serverRequestTypes.SIGNED_IDENTITY_KEYS_BLOB, | x => x === serverRequestTypes.SIGNED_IDENTITY_KEYS_BLOB, | ||||
), | ), | ||||
signedIdentityKeysBlob: signedIdentityKeysBlobValidator, | signedIdentityKeysBlob: signedIdentityKeysBlobValidator, | ||||
}), | }), | ||||
tShape({ | |||||
type: t.irreducible( | |||||
'serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE', | |||||
x => x === serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE, | |||||
), | |||||
initialNotificationsEncryptedMessage: t.String, | |||||
}), | |||||
]); | ]); | ||||
type StateCheckStatus = | type StateCheckStatus = | ||||
| { status: 'state_validated' } | | { status: 'state_validated' } | ||||
| { status: 'state_invalid', invalidKeys: $ReadOnlyArray<string> } | | { status: 'state_invalid', invalidKeys: $ReadOnlyArray<string> } | ||||
| { status: 'state_check' }; | | { status: 'state_check' }; | ||||
type ProcessClientResponsesResult = { | type ProcessClientResponsesResult = { | ||||
serverRequests: ServerServerRequest[], | serverRequests: ServerServerRequest[], | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | ) { | ||||
setCookieSignedIdentityKeysBlob( | setCookieSignedIdentityKeysBlob( | ||||
viewer.cookieID, | viewer.cookieID, | ||||
signedIdentityKeysBlob, | signedIdentityKeysBlob, | ||||
), | ), | ||||
); | ); | ||||
} catch (e) { | } catch (e) { | ||||
continue; | continue; | ||||
} | } | ||||
} else if ( | |||||
clientResponse.type === | |||||
serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE | |||||
) { | |||||
invariant( | |||||
t.String.is(clientResponse.initialNotificationsEncryptedMessage), | |||||
'initialNotificationsEncryptedMessage expected in client response', | |||||
); | |||||
const { initialNotificationsEncryptedMessage } = clientResponse; | |||||
try { | |||||
await createOlmSession( | |||||
initialNotificationsEncryptedMessage, | |||||
'notifications', | |||||
viewer.cookieID, | |||||
); | |||||
} catch (e) { | |||||
continue; | |||||
} | |||||
} | } | ||||
} | } | ||||
const activityUpdatePromise = (async () => { | const activityUpdatePromise = (async () => { | ||||
if (activityUpdates.length === 0) { | if (activityUpdates.length === 0) { | ||||
return undefined; | return undefined; | ||||
} | } | ||||
return await activityUpdater(viewer, { updates: activityUpdates }); | return await activityUpdater(viewer, { updates: activityUpdates }); | ||||
▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines |