Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/socket/session-utils.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import t from 'tcomb'; | import t from 'tcomb'; | ||||
import type { TUnion, TInterface } from 'tcomb'; | import type { TUnion, TInterface } from 'tcomb'; | ||||
import { | import { | ||||
usersInRawEntryInfos, | usersInRawEntryInfos, | ||||
serverEntryInfo, | serverEntryInfo, | ||||
serverEntryInfosObject, | serverEntryInfosObject, | ||||
} from 'lib/shared/entry-utils.js'; | } from 'lib/shared/entry-utils.js'; | ||||
import { usersInThreadInfo } from 'lib/shared/thread-utils.js'; | import { usersInThreadInfo } from 'lib/shared/thread-utils.js'; | ||||
import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | ||||
import type { UpdateActivityResult } from 'lib/types/activity-types.js'; | import type { UpdateActivityResult } from 'lib/types/activity-types.js'; | ||||
import type { IdentityKeysBlob } from 'lib/types/crypto-types.js'; | |||||
import { isDeviceType } from 'lib/types/device-types.js'; | import { isDeviceType } from 'lib/types/device-types.js'; | ||||
import type { | import type { | ||||
CalendarQuery, | CalendarQuery, | ||||
DeltaEntryInfosResponse, | DeltaEntryInfosResponse, | ||||
} from 'lib/types/entry-types.js'; | } from 'lib/types/entry-types.js'; | ||||
import { | import { | ||||
reportTypes, | reportTypes, | ||||
type ThreadInconsistencyReportCreationRequest, | type ThreadInconsistencyReportCreationRequest, | ||||
Show All 37 Lines | |||||
import { | import { | ||||
threadInconsistencyReportValidatorShape, | threadInconsistencyReportValidatorShape, | ||||
entryInconsistencyReportValidatorShape, | entryInconsistencyReportValidatorShape, | ||||
} from '../responders/report-responders.js'; | } from '../responders/report-responders.js'; | ||||
import { | import { | ||||
setNewSession, | setNewSession, | ||||
setCookiePlatform, | setCookiePlatform, | ||||
setCookiePlatformDetails, | setCookiePlatformDetails, | ||||
setCookieSignedIdentityKeysBlob, | |||||
} from '../session/cookies.js'; | } from '../session/cookies.js'; | ||||
import type { Viewer } from '../session/viewer.js'; | import type { Viewer } from '../session/viewer.js'; | ||||
import { activityUpdater } from '../updaters/activity-updaters.js'; | import { activityUpdater } from '../updaters/activity-updaters.js'; | ||||
import { compareNewCalendarQuery } from '../updaters/entry-updaters.js'; | import { compareNewCalendarQuery } from '../updaters/entry-updaters.js'; | ||||
import type { SessionUpdate } from '../updaters/session-updaters.js'; | import type { SessionUpdate } from '../updaters/session-updaters.js'; | ||||
import { getOlmUtility } from '../utils/olm-utils.js'; | |||||
const clientResponseInputValidator: TUnion<TInterface> = t.union([ | const clientResponseInputValidator: TUnion<TInterface> = t.union([ | ||||
tShape({ | tShape({ | ||||
type: t.irreducible( | type: t.irreducible( | ||||
'serverRequestTypes.PLATFORM', | 'serverRequestTypes.PLATFORM', | ||||
x => x === serverRequestTypes.PLATFORM, | x => x === serverRequestTypes.PLATFORM, | ||||
), | ), | ||||
platform: tPlatform, | platform: tPlatform, | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | ) { | ||||
} | } | ||||
stateCheckStatus = | stateCheckStatus = | ||||
invalidKeys.length > 0 | invalidKeys.length > 0 | ||||
? { status: 'state_invalid', invalidKeys } | ? { status: 'state_invalid', invalidKeys } | ||||
: { status: 'state_validated' }; | : { status: 'state_validated' }; | ||||
} else if (clientResponse.type === serverRequestTypes.MORE_ONE_TIME_KEYS) { | } else if (clientResponse.type === serverRequestTypes.MORE_ONE_TIME_KEYS) { | ||||
invariant(clientResponse.keys, 'keys expected in client response'); | invariant(clientResponse.keys, 'keys expected in client response'); | ||||
handleAsyncPromise(saveOneTimeKeys(viewer, clientResponse.keys)); | handleAsyncPromise(saveOneTimeKeys(viewer, clientResponse.keys)); | ||||
} else if ( | |||||
clientResponse.type === serverRequestTypes.SIGNED_IDENTITY_KEYS_BLOB | |||||
) { | |||||
invariant( | |||||
clientResponse.signedIdentityKeysBlob, | |||||
'signedIdentityKeysBlob expected in client response', | |||||
); | |||||
const { signedIdentityKeysBlob } = clientResponse; | |||||
const identityKeys: IdentityKeysBlob = JSON.parse( | |||||
signedIdentityKeysBlob.payload, | |||||
); | |||||
const olmUtil = getOlmUtility(); | |||||
try { | |||||
olmUtil.ed25519_verify( | |||||
identityKeys.primaryIdentityPublicKeys.ed25519, | |||||
signedIdentityKeysBlob.payload, | |||||
signedIdentityKeysBlob.signature, | |||||
); | |||||
handleAsyncPromise( | |||||
setCookieSignedIdentityKeysBlob( | |||||
viewer.cookieID, | |||||
signedIdentityKeysBlob, | |||||
), | |||||
); | |||||
} catch (e) { | |||||
continue; | |||||
} | |||||
} | } | ||||
} | } | ||||
const activityUpdatePromise = (async () => { | const activityUpdatePromise = (async () => { | ||||
if (activityUpdates.length === 0) { | if (activityUpdates.length === 0) { | ||||
return; | return; | ||||
} | } | ||||
return await activityUpdater(viewer, { updates: activityUpdates }); | return await activityUpdater(viewer, { updates: activityUpdates }); | ||||
▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines |