Add U2F support

This commit is contained in:
Jonas Lochmann
2022-09-22 08:47:06 +02:00
parent 04aa2ce517
commit 613776cbf9
64 changed files with 2501 additions and 134 deletions
+52
View File
@@ -0,0 +1,52 @@
/*
* 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 { ParentAction } from './basetypes'
import { throwOutOfRange } from './meta/util'
const actionType = 'AddParentU2fKey'
export class AddParentU2fKeyAction extends ParentAction {
readonly keyHandle: Buffer
readonly publicKey: Buffer
constructor ({ keyHandle, publicKey }: {
keyHandle: Buffer
publicKey: Buffer
}) {
super()
if (keyHandle.length > 2048) throwOutOfRange({ actionType, field: 'keyHandle', value: keyHandle.length })
if (publicKey.length > 2048) throwOutOfRange({ actionType, field: 'publicKey', value: publicKey.length })
this.keyHandle = keyHandle
this.publicKey = publicKey
}
static parse = ({ keyHandle, publicKey }: SerializedAddParentU2fKeyAction) => (
new AddParentU2fKeyAction({
keyHandle: Buffer.from(keyHandle, 'base64'),
publicKey: Buffer.from(publicKey, 'base64')
})
)
}
export interface SerializedAddParentU2fKeyAction {
type: 'ADD_PARENT_U2F'
keyHandle: string
publicKey: string
}
+3
View File
@@ -21,6 +21,7 @@ export { AddCategoryAppsAction } from './addcategoryapps'
export { AddCategoryNetworkIdAction } from './addcategorynetworkid'
export { AddUserAction } from './adduser'
export { AddInstalledAppsAction } from './addinstalledapps'
export { AddParentU2fKeyAction } from './addu2fkey'
export { AddUsedTimeAction } from './addusedtime'
export { AddUsedTimeActionVersion2 } from './addusedtime2'
export { ChangeParentPasswordAction } from './changeparentpassword'
@@ -36,10 +37,12 @@ export { IgnoreManipulationAction } from './ignoremanipulation'
export { IncrementCategoryExtraTimeAction } from './incrementcategoryextratime'
export { RemoveCategoryAppsAction } from './removecategoryapps'
export { RemoveInstalledAppsAction } from './removeinstalledapps'
export { RemoveParentU2fKeyAction } from './removeu2fkey'
export { RemoveUserAction } from './removeuser'
export { ResetCategoryNetworkIdsAction } from './resetcategorynetworkids'
export { RenameChildAction } from './renamechild'
export { ReplyToKeyRequestAction } from './replytokeyrequest'
export { ReportU2fLoginAction } from './reportu2flogin'
export { SetCategoryExtraTimeAction } from './setcategoryextratime'
export { SetCategoryForUnassignedAppsAction } from './setcategoryforunassignedapps'
export { SetChildPasswordAction } from './setchildpassword'
+52
View File
@@ -0,0 +1,52 @@
/*
* 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 { ParentAction } from './basetypes'
import { throwOutOfRange } from './meta/util'
const actionType = 'RemoveParentU2FKey'
export class RemoveParentU2fKeyAction extends ParentAction {
readonly keyHandle: Buffer
readonly publicKey: Buffer
constructor ({ keyHandle, publicKey }: {
keyHandle: Buffer
publicKey: Buffer
}) {
super()
if (keyHandle.length > 2048) throwOutOfRange({ actionType, field: 'keyHandle', value: keyHandle.length })
if (publicKey.length > 2048) throwOutOfRange({ actionType, field: 'publicKey', value: publicKey.length })
this.keyHandle = keyHandle
this.publicKey = publicKey
}
static parse = ({ keyHandle, publicKey }: SerializedRemoveParentU2fKeyAction) => (
new RemoveParentU2fKeyAction({
keyHandle: Buffer.from(keyHandle, 'base64'),
publicKey: Buffer.from(publicKey, 'base64')
})
)
}
export interface SerializedRemoveParentU2fKeyAction {
type: 'REMOVE_PARENT_U2F'
keyHandle: string
publicKey: string
}
+30
View File
@@ -0,0 +1,30 @@
/*
* 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 { ParentAction } from './basetypes'
export class ReportU2fLoginAction extends ParentAction {
static instance = new ReportU2fLoginAction()
private constructor () {
super()
}
}
export interface SerializedReportU2fLoginAction {
type: 'REPORT_U2F_LOGIN'
}
+13 -1
View File
@@ -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
@@ -17,6 +17,7 @@
import { AddCategoryAppsAction, SerializedAddCategoryAppsAction } from '../addcategoryapps'
import { AddCategoryNetworkIdAction, SerializedAddCategoryNetworkIdAction } from '../addcategorynetworkid'
import { AddParentU2fKeyAction, SerializedAddParentU2fKeyAction } from '../addu2fkey'
import { AddUserAction, SerializedAddUserAction } from '../adduser'
import { ParentAction } from '../basetypes'
import { ChangeParentPasswordAction, SerializedChangeParentPasswordAction } from '../changeparentpassword'
@@ -27,8 +28,10 @@ import { DeleteChildTaskAction, SerializedDeleteChildTaskAction } from '../delet
import { DeleteTimeLimitRuleAction, SerializedDeleteTimeLimitRuleAction } from '../deletetimelimitrule'
import { IgnoreManipulationAction, SerializedIgnoreManipulationAction } from '../ignoremanipulation'
import { IncrementCategoryExtraTimeAction, SerializedIncrementCategoryExtraTimeAction } from '../incrementcategoryextratime'
import { ReportU2fLoginAction, SerializedReportU2fLoginAction } from '../reportu2flogin'
import { UnknownActionTypeException } from '../meta/exception'
import { RemoveCategoryAppsAction, SerializedRemoveCategoryAppsAction } from '../removecategoryapps'
import { RemoveParentU2fKeyAction, SerializedRemoveParentU2fKeyAction } from '../removeu2fkey'
import { RemoveUserAction, SerializedRemoveUserAction } from '../removeuser'
import { RenameChildAction, SerializedRenameChildAction } from '../renamechild'
import { ResetCategoryNetworkIdsAction, SerializeResetCategoryNetworkIdsAction } from '../resetcategorynetworkids'
@@ -68,6 +71,7 @@ import { SerializedUpdateUserLimitLoginPreBlockDuration, UpdateUserLimitLoginPre
export type SerializedParentAction =
SerializedAddCategoryAppsAction |
SerializedAddCategoryNetworkIdAction |
SerializedAddParentU2fKeyAction |
SerializedAddUserAction |
SerializedChangeParentPasswordAction |
SerializedCreateCategoryAction |
@@ -77,7 +81,9 @@ export type SerializedParentAction =
SerializedDeleteTimeLimitRuleAction |
SerializedIgnoreManipulationAction |
SerializedIncrementCategoryExtraTimeAction |
SerializedReportU2fLoginAction |
SerializedRemoveCategoryAppsAction |
SerializedRemoveParentU2fKeyAction |
SerializedRemoveUserAction |
SerializedRenameChildAction |
SerializeResetCategoryNetworkIdsAction |
@@ -119,6 +125,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return AddCategoryAppsAction.parse(action)
} else if (action.type === 'ADD_CATEGORY_NETWORK_ID') {
return AddCategoryNetworkIdAction.parse(action)
} else if (action.type === 'ADD_PARENT_U2F') {
return AddParentU2fKeyAction.parse(action)
} else if (action.type === 'ADD_USER') {
return AddUserAction.parse(action)
} else if (action.type === 'CHANGE_PARENT_PASSWORD') {
@@ -137,8 +145,12 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return IgnoreManipulationAction.parse(action)
} else if (action.type === 'INCREMENT_CATEGORY_EXTRATIME') {
return IncrementCategoryExtraTimeAction.parse(action)
} else if (action.type === 'REPORT_U2F_LOGIN') {
return ReportU2fLoginAction.instance
} else if (action.type === 'REMOVE_CATEGORY_APPS') {
return RemoveCategoryAppsAction.parse(action)
} else if (action.type === 'REMOVE_PARENT_U2F') {
return RemoveParentU2fKeyAction.parse(action)
} else if (action.type === 'REMOVE_USER') {
return RemoveUserAction.parse(action)
} else if (action.type === 'RENAME_CHILD') {