mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add basically support for encrypted app list syncing
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AppLogicAction } from './basetypes'
|
||||
import { assertSafeInteger } from './meta/util'
|
||||
|
||||
const actionType = 'FinishKeyRequestAction'
|
||||
|
||||
export class FinishKeyRequestAction extends AppLogicAction {
|
||||
readonly deviceSequenceNumber: number
|
||||
|
||||
constructor ({ deviceSequenceNumber }: { deviceSequenceNumber: number }) {
|
||||
super()
|
||||
|
||||
assertSafeInteger({ value: deviceSequenceNumber, field: 'deviceSequenceNumber', actionType })
|
||||
|
||||
this.deviceSequenceNumber = deviceSequenceNumber
|
||||
}
|
||||
|
||||
static parse = ({ dsn }: SerializedFinishKeyRequestAction) => (
|
||||
new FinishKeyRequestAction({
|
||||
deviceSequenceNumber: dsn,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedFinishKeyRequestAction {
|
||||
type: 'FINISH_KEY_REQUEST'
|
||||
dsn: number
|
||||
}
|
||||
+6
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2021 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -30,6 +30,7 @@ export { CreateCategoryAction } from './createcategory'
|
||||
export { CreateTimeLimitRuleAction } from './createtimelimitrule'
|
||||
export { DeleteCategoryAction } from './deletecategory'
|
||||
export { DeleteTimeLimitRuleAction } from './deletetimelimitrule'
|
||||
export { FinishKeyRequestAction } from './finishkeyrequest'
|
||||
export { ForceSyncAction } from './forcesync'
|
||||
export { IgnoreManipulationAction } from './ignoremanipulation'
|
||||
export { IncrementCategoryExtraTimeAction } from './incrementcategoryextratime'
|
||||
@@ -38,6 +39,7 @@ export { RemoveInstalledAppsAction } from './removeinstalledapps'
|
||||
export { RemoveUserAction } from './removeuser'
|
||||
export { ResetCategoryNetworkIdsAction } from './resetcategorynetworkids'
|
||||
export { RenameChildAction } from './renamechild'
|
||||
export { ReplyToKeyRequestAction } from './replytokeyrequest'
|
||||
export { SetCategoryExtraTimeAction } from './setcategoryextratime'
|
||||
export { SetCategoryForUnassignedAppsAction } from './setcategoryforunassignedapps'
|
||||
export { SetChildPasswordAction } from './setchildpassword'
|
||||
@@ -66,6 +68,7 @@ export { UpdateCategoryTitleAction } from './updatecategorytitle'
|
||||
export { UpdateDeviceNameAction } from './updatedevicename'
|
||||
export { UpdateDeviceStatusAction } from './updatedevicestatus'
|
||||
export { UpdateEnableActivityLevelBlockingAction } from './updateenableactivitylevelblocking'
|
||||
export { UpdateInstalledAppsAction } from './updateinstalledapps'
|
||||
export { UpdateNetworkTimeVerificationAction } from './updatenetworktimeverification'
|
||||
export { UpdateParentNotificationFlagsAction } from './updateparentnotificationflags'
|
||||
export { UpdateTimelimitRuleAction } from './updatetimelimitrule'
|
||||
@@ -76,3 +79,5 @@ export { DeleteChildTaskAction } from './deletechildtaskaction'
|
||||
export { UpdateChildTaskAction } from './updatechildtaskaction'
|
||||
export { ReviewChildTaskAction } from './reviewchildtaskaction'
|
||||
export { UpdateUserLimitLoginPreBlockDuration } from './updateuserlimitloginpreblockduration'
|
||||
export { UploadDevicePublicKeyAction } from './uploaddevicepublickey'
|
||||
export { SendKeyRequestAction } from './sendkeyrequest'
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AppLogicAction } from './basetypes'
|
||||
import { InvalidActionParameterException } from './meta/exception'
|
||||
import { assertSafeInteger } from './meta/util'
|
||||
|
||||
const actionType = 'ReplyToKeyRequestAction'
|
||||
|
||||
export class ReplyToKeyRequestAction extends AppLogicAction {
|
||||
readonly requestServerSequenceNumber: number
|
||||
readonly tempKey: Buffer
|
||||
readonly encryptedKey: Buffer
|
||||
readonly signature: Buffer
|
||||
|
||||
constructor ({
|
||||
requestServerSequenceNumber,
|
||||
tempKey,
|
||||
encryptedKey,
|
||||
signature
|
||||
}: {
|
||||
requestServerSequenceNumber: number
|
||||
tempKey: Buffer
|
||||
encryptedKey: Buffer
|
||||
signature: Buffer
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertSafeInteger({ value: requestServerSequenceNumber, field: 'requestServerSequenceNumber', actionType })
|
||||
|
||||
if (tempKey.length !== 32 || encryptedKey.length !== 16 || signature.length !== 64) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'key/signature has wrong length'
|
||||
})
|
||||
}
|
||||
|
||||
this.requestServerSequenceNumber = requestServerSequenceNumber
|
||||
this.tempKey = tempKey
|
||||
this.encryptedKey = encryptedKey
|
||||
this.signature = signature
|
||||
}
|
||||
|
||||
static parse = ({ rsn, tempKey, encryptedKey, signature }: SerializedReplyToKeyRequestAction) => (
|
||||
new ReplyToKeyRequestAction({
|
||||
requestServerSequenceNumber: rsn,
|
||||
tempKey: Buffer.from(tempKey, 'base64'),
|
||||
encryptedKey: Buffer.from(encryptedKey, 'base64'),
|
||||
signature: Buffer.from(signature, 'base64')
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedReplyToKeyRequestAction {
|
||||
type: 'REPLY_TO_KEY_REQUEST'
|
||||
rsn: number
|
||||
tempKey: string
|
||||
encryptedKey: string
|
||||
signature: string
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AppLogicAction } from './basetypes'
|
||||
import { InvalidActionParameterException } from './meta/exception'
|
||||
import { assertIdWithinFamily, assertSafeInteger } from './meta/util'
|
||||
import { types } from '../database/keyrequest'
|
||||
|
||||
const actionType = 'SendKeyRequestAction'
|
||||
|
||||
export class SendKeyRequestAction extends AppLogicAction {
|
||||
readonly deviceSequenceNumber: number
|
||||
readonly deviceId?: string
|
||||
readonly categoryId?: string
|
||||
readonly type: number
|
||||
readonly tempKey: Buffer
|
||||
readonly signature: Buffer
|
||||
|
||||
constructor ({
|
||||
deviceSequenceNumber,
|
||||
deviceId,
|
||||
categoryId,
|
||||
type,
|
||||
tempKey,
|
||||
signature
|
||||
}: {
|
||||
deviceSequenceNumber: number
|
||||
deviceId?: string
|
||||
categoryId?: string
|
||||
type: number
|
||||
tempKey: Buffer
|
||||
signature: Buffer
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertSafeInteger({ value: deviceSequenceNumber, field: 'deviceSequenceNumber', actionType })
|
||||
assertSafeInteger({ value: type, field: 'deviceSequenceNumber', actionType })
|
||||
|
||||
if (tempKey.length != 32 || signature.length != 64) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'key/signature has wrong length'
|
||||
})
|
||||
}
|
||||
|
||||
if (deviceId !== undefined) {
|
||||
assertIdWithinFamily({ value: deviceId, actionType, field: 'deviceId' })
|
||||
}
|
||||
|
||||
if (categoryId !== undefined) {
|
||||
assertIdWithinFamily({ value: categoryId, actionType, field: 'categoryId' })
|
||||
}
|
||||
|
||||
if (deviceId !== undefined && categoryId !== undefined) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'can not specify device and category at the same time'
|
||||
})
|
||||
}
|
||||
|
||||
if (types.all.indexOf(type) === -1) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'invalid type'
|
||||
})
|
||||
}
|
||||
|
||||
this.deviceSequenceNumber = deviceSequenceNumber
|
||||
this.deviceId = deviceId
|
||||
this.categoryId = categoryId
|
||||
this.type = type
|
||||
this.tempKey = tempKey
|
||||
this.signature = signature
|
||||
}
|
||||
|
||||
static parse = ({ dsn, deviceId, categoryId, dataType, tempKey, signature }: SerializedSendKeyRequestAction) => (
|
||||
new SendKeyRequestAction({
|
||||
deviceSequenceNumber: dsn,
|
||||
deviceId,
|
||||
categoryId,
|
||||
type: dataType,
|
||||
tempKey: Buffer.from(tempKey, 'base64'),
|
||||
signature: Buffer.from(signature, 'base64')
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedSendKeyRequestAction {
|
||||
type: 'SEND_KEY_REQUEST'
|
||||
dsn: number
|
||||
deviceId?: string
|
||||
categoryId?: string
|
||||
dataType: number
|
||||
tempKey: string
|
||||
signature: string
|
||||
}
|
||||
@@ -19,26 +19,36 @@ import { AddInstalledAppsAction, SerializedAddInstalledAppsAction } from '../add
|
||||
import { AddUsedTimeAction, SerializedAddUsedTimeAction } from '../addusedtime'
|
||||
import { AddUsedTimeActionVersion2, SerializedAddUsedTimeActionVersion2 } from '../addusedtime2'
|
||||
import { AppLogicAction } from '../basetypes'
|
||||
import { FinishKeyRequestAction, SerializedFinishKeyRequestAction } from '../finishkeyrequest'
|
||||
import { ForceSyncAction, SerializedForceSyncAction } from '../forcesync'
|
||||
import { ReplyToKeyRequestAction, SerializedReplyToKeyRequestAction } from '../replytokeyrequest'
|
||||
import { MarkTaskPendingAction, SerializedMarkTaskPendingAction } from '../marktaskpendingaction'
|
||||
import { UnknownActionTypeException } from '../meta/exception'
|
||||
import { UpdateInstalledAppsAction, SerializedUpdateInstalledAppsAction } from '../updateinstalledapps'
|
||||
import { RemoveInstalledAppsAction, SerializedRemoveInstalledAppsAction } from '../removeinstalledapps'
|
||||
import { SendKeyRequestAction, SerializedSendKeyRequestAction } from '../sendkeyrequest'
|
||||
import { SerializedSignOutAtDeviceAction, SignOutAtDeviceAction } from '../signoutatdevice'
|
||||
import { SerialiezdTriedDisablingDeviceAdminAction, TriedDisablingDeviceAdminAction } from '../trieddisablingdeviceadmin'
|
||||
import { SerializedUpdateAppActivitiesAction, UpdateAppActivitiesAction } from '../updateappactivities'
|
||||
import { SerializedUpdateDeviceStatusAction, UpdateDeviceStatusAction } from '../updatedevicestatus'
|
||||
import { SerializedUploadDevicePublicKeyAction, UploadDevicePublicKeyAction } from '../uploaddevicepublickey'
|
||||
|
||||
export type SerializedAppLogicAction =
|
||||
SerializedAddInstalledAppsAction |
|
||||
SerializedAddUsedTimeAction |
|
||||
SerializedAddUsedTimeActionVersion2 |
|
||||
SerializedFinishKeyRequestAction |
|
||||
SerializedForceSyncAction |
|
||||
SerializedReplyToKeyRequestAction |
|
||||
SerializedMarkTaskPendingAction |
|
||||
SerializedUpdateInstalledAppsAction |
|
||||
SerializedRemoveInstalledAppsAction |
|
||||
SerializedSendKeyRequestAction |
|
||||
SerializedSignOutAtDeviceAction |
|
||||
SerialiezdTriedDisablingDeviceAdminAction |
|
||||
SerializedUpdateAppActivitiesAction |
|
||||
SerializedUpdateDeviceStatusAction
|
||||
SerializedUpdateDeviceStatusAction |
|
||||
SerializedUploadDevicePublicKeyAction
|
||||
|
||||
export const parseAppLogicAction = (serialized: SerializedAppLogicAction): AppLogicAction => {
|
||||
if (serialized.type === 'ADD_USED_TIME') {
|
||||
@@ -47,12 +57,20 @@ export const parseAppLogicAction = (serialized: SerializedAppLogicAction): AppLo
|
||||
return AddUsedTimeActionVersion2.parse(serialized)
|
||||
} else if (serialized.type === 'ADD_INSTALLED_APPS') {
|
||||
return AddInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'FINISH_KEY_REQUEST') {
|
||||
return FinishKeyRequestAction.parse(serialized)
|
||||
} else if (serialized.type === 'FORCE_SYNC') {
|
||||
return ForceSyncAction.instance
|
||||
} else if (serialized.type === 'REPLY_TO_KEY_REQUEST') {
|
||||
return ReplyToKeyRequestAction.parse(serialized)
|
||||
} else if (serialized.type === 'MARK_TASK_PENDING') {
|
||||
return MarkTaskPendingAction.parse(serialized)
|
||||
} else if (serialized.type === 'UPDATE_INSTALLED_APPS') {
|
||||
return UpdateInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'REMOVE_INSTALLED_APPS') {
|
||||
return RemoveInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'SEND_KEY_REQUEST') {
|
||||
return SendKeyRequestAction.parse(serialized)
|
||||
} else if (serialized.type === 'SIGN_OUT_AT_DEVICE') {
|
||||
return SignOutAtDeviceAction.instance
|
||||
} else if (serialized.type === 'TRIED_DISABLING_DEVICE_ADMIN') {
|
||||
@@ -61,6 +79,8 @@ export const parseAppLogicAction = (serialized: SerializedAppLogicAction): AppLo
|
||||
return UpdateAppActivitiesAction.parse(serialized)
|
||||
} else if (serialized.type === 'UPDATE_DEVICE_STATUS') {
|
||||
return UpdateDeviceStatusAction.parse(serialized)
|
||||
} else if (serialized.type === 'UPLOAD_DEVICE_PUBLIC_KEY') {
|
||||
return UploadDevicePublicKeyAction.parse(serialized)
|
||||
} else {
|
||||
throw new UnknownActionTypeException({ group: 'app logic' })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AppLogicAction } from './basetypes'
|
||||
import { InvalidActionParameterException } from './meta/exception'
|
||||
|
||||
const actionType = 'UpdateInstalledAppsAction'
|
||||
const SIZE_LIMIT = 1024 * 256
|
||||
|
||||
export class UpdateInstalledAppsAction extends AppLogicAction {
|
||||
readonly base?: Buffer
|
||||
readonly diff?: Buffer
|
||||
readonly wipe: boolean
|
||||
|
||||
constructor ({ base, diff, wipe }: {
|
||||
base?: Buffer,
|
||||
diff?: Buffer,
|
||||
wipe: boolean
|
||||
}) {
|
||||
super()
|
||||
|
||||
if (base && base.length > SIZE_LIMIT) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'base data too big'
|
||||
})
|
||||
}
|
||||
|
||||
if (diff && diff.length > SIZE_LIMIT) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'diff data too big'
|
||||
})
|
||||
}
|
||||
|
||||
this.base = base
|
||||
this.diff = diff
|
||||
this.wipe = wipe
|
||||
}
|
||||
|
||||
static parse = ({ b, d, w }: SerializedUpdateInstalledAppsAction) => (
|
||||
new UpdateInstalledAppsAction({
|
||||
base: b !== undefined ? Buffer.from(b, 'base64') : undefined,
|
||||
diff: d !== undefined ? Buffer.from(d, 'base64') : undefined,
|
||||
wipe: w
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedUpdateInstalledAppsAction {
|
||||
type: 'UPDATE_INSTALLED_APPS'
|
||||
b?: string
|
||||
d?: string
|
||||
w: boolean
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AppLogicAction } from './basetypes'
|
||||
import { InvalidActionParameterException } from './meta/exception'
|
||||
|
||||
const actionType = 'UploadDevicePublicKeyAction'
|
||||
|
||||
export class UploadDevicePublicKeyAction extends AppLogicAction {
|
||||
readonly key: Buffer
|
||||
|
||||
constructor ({ key }: { key: Buffer }) {
|
||||
super()
|
||||
|
||||
if (key.length !== 32) {
|
||||
throw new InvalidActionParameterException({
|
||||
actionType,
|
||||
staticMessage: 'key has wrong length'
|
||||
})
|
||||
}
|
||||
|
||||
this.key = key
|
||||
}
|
||||
|
||||
static parse = ({ key }: SerializedUploadDevicePublicKeyAction) => (
|
||||
new UploadDevicePublicKeyAction({
|
||||
key: Buffer.from(key, 'base64')
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedUploadDevicePublicKeyAction {
|
||||
type: 'UPLOAD_DEVICE_PUBLIC_KEY'
|
||||
key: string
|
||||
}
|
||||
Reference in New Issue
Block a user