Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/session/cookies.js
// @flow | // @flow | ||||
import crypto from 'crypto'; | import crypto from 'crypto'; | ||||
import type { $Response, $Request } from 'express'; | import type { $Response, $Request } from 'express'; | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import bcrypt from 'twin-bcrypt'; | import bcrypt from 'twin-bcrypt'; | ||||
import url from 'url'; | import url from 'url'; | ||||
import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | import { | ||||
hasMinCodeVersion, | |||||
FUTURE_CODE_VERSION, | |||||
} from 'lib/shared/version-utils.js'; | |||||
import type { Shape } from 'lib/types/core.js'; | import type { Shape } from 'lib/types/core.js'; | ||||
import type { SignedIdentityKeysBlob } from 'lib/types/crypto-types.js'; | import type { SignedIdentityKeysBlob } from 'lib/types/crypto-types.js'; | ||||
import { isWebPlatform } from 'lib/types/device-types.js'; | import { isWebPlatform } from 'lib/types/device-types.js'; | ||||
import type { Platform, PlatformDetails } from 'lib/types/device-types.js'; | import type { Platform, PlatformDetails } from 'lib/types/device-types.js'; | ||||
import type { CalendarQuery } from 'lib/types/entry-types.js'; | import type { CalendarQuery } from 'lib/types/entry-types.js'; | ||||
import { | import { | ||||
type ServerSessionChange, | type ServerSessionChange, | ||||
cookieLifetime, | cookieLifetime, | ||||
▲ Show 20 Lines • Show All 800 Lines • ▼ Show 20 Lines | const query = SQL` | ||||
WHERE id = ${cookieID} | WHERE id = ${cookieID} | ||||
`; | `; | ||||
const [queryResult] = await dbQuery(query); | const [queryResult] = await dbQuery(query); | ||||
return ( | return ( | ||||
queryResult.length === 1 && queryResult[0].signed_identity_keys === null | queryResult.length === 1 && queryResult[0].signed_identity_keys === null | ||||
); | ); | ||||
} | } | ||||
async function isCookieMissingOlmNotificationsSession( | |||||
viewer: Viewer, | |||||
): Promise<boolean> { | |||||
if ( | |||||
!viewer.platformDetails || | |||||
viewer.platformDetails.platform !== 'ios' || | |||||
!viewer.platformDetails.codeVersion || | |||||
viewer.platformDetails.codeVersion < FUTURE_CODE_VERSION | |||||
) { | |||||
return false; | |||||
} | |||||
const query = SQL` | |||||
SELECT COUNT(*) AS count | |||||
ashoat: There's a trailing space here. Please remove before landing! | |||||
FROM olm_sessions | |||||
WHERE cookie_id = ${viewer.cookieID} AND is_content = FALSE | |||||
`; | |||||
const [queryResult] = await dbQuery(query); | |||||
return queryResult[0].count === 0; | |||||
} | |||||
async function setCookiePlatform( | async function setCookiePlatform( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
platform: Platform, | platform: Platform, | ||||
): Promise<void> { | ): Promise<void> { | ||||
const newPlatformDetails = { ...viewer.platformDetails, platform }; | const newPlatformDetails = { ...viewer.platformDetails, platform }; | ||||
viewer.setPlatformDetails(newPlatformDetails); | viewer.setPlatformDetails(newPlatformDetails); | ||||
const query = SQL` | const query = SQL` | ||||
UPDATE cookies | UPDATE cookies | ||||
Show All 35 Lines | export { | ||||
setNewSession, | setNewSession, | ||||
extendCookieLifespan, | extendCookieLifespan, | ||||
addCookieToJSONResponse, | addCookieToJSONResponse, | ||||
addCookieToHomeResponse, | addCookieToHomeResponse, | ||||
setCookieSignedIdentityKeysBlob, | setCookieSignedIdentityKeysBlob, | ||||
isCookieMissingSignedIdentityKeysBlob, | isCookieMissingSignedIdentityKeysBlob, | ||||
setCookiePlatform, | setCookiePlatform, | ||||
setCookiePlatformDetails, | setCookiePlatformDetails, | ||||
isCookieMissingOlmNotificationsSession, | |||||
}; | }; |
There's a trailing space here. Please remove before landing!