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:
+28
-2
@@ -111,11 +111,19 @@ export interface DeviceAttributesVersion12 {
|
||||
manipulationFlags: number
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion13 {
|
||||
publicKey: Buffer | null
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion14 {
|
||||
nextKeyReplySequenceNumber: string
|
||||
}
|
||||
|
||||
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
|
||||
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
|
||||
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11 &
|
||||
DeviceAttributesVersion12
|
||||
DeviceAttributesVersion12 & DeviceAttributesVersion13 & DeviceAttributesVersion14
|
||||
|
||||
export type DeviceModel = Sequelize.Model<DeviceAttributes> & DeviceAttributes
|
||||
export type DeviceModelStatic = typeof Sequelize.Model & {
|
||||
@@ -281,6 +289,22 @@ export const attributesVersion12: SequelizeAttributes<DeviceAttributesVersion12>
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion13: SequelizeAttributes<DeviceAttributesVersion13> = {
|
||||
publicKey: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: true,
|
||||
defaultValue: null
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion14: SequelizeAttributes<DeviceAttributesVersion14> = {
|
||||
nextKeyReplySequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 1
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
@@ -293,7 +317,9 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion9,
|
||||
...attributesVersion10,
|
||||
...attributesVersion11,
|
||||
...attributesVersion12
|
||||
...attributesVersion12,
|
||||
...attributesVersion13,
|
||||
...attributesVersion14
|
||||
}
|
||||
|
||||
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModelStatic => sequelize.define('Device', attributes) as DeviceModelStatic
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn, versionColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface EncryptedAppListAttributes {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
type: number
|
||||
version: string
|
||||
data: Buffer
|
||||
}
|
||||
|
||||
export const types = {
|
||||
base: 1,
|
||||
diff: 2
|
||||
}
|
||||
|
||||
export type EncryptedAppListModel = Sequelize.Model<EncryptedAppListAttributes> & EncryptedAppListAttributes
|
||||
export type EncryptedAppListModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): EncryptedAppListModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<EncryptedAppListAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
deviceId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
validate: {
|
||||
min: 1,
|
||||
max: 2
|
||||
}
|
||||
},
|
||||
version: {
|
||||
...versionColumn
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
}
|
||||
}
|
||||
|
||||
export const createEncryptedAppListModel = (sequelize: Sequelize.Sequelize): EncryptedAppListModelStatic => sequelize.define('EncryptedAppList', attributes) as EncryptedAppListModelStatic
|
||||
+25
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 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
|
||||
@@ -19,7 +19,7 @@ import * as Sequelize from 'sequelize'
|
||||
import { booleanColumn, familyIdColumn, optionalLabelColumn, timestampColumn, versionColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface FamilyAttributes {
|
||||
export interface FamilyAttributesVersion1 {
|
||||
familyId: string
|
||||
name: string
|
||||
createdAt: string
|
||||
@@ -29,12 +29,18 @@ export interface FamilyAttributes {
|
||||
hasFullVersion: boolean
|
||||
}
|
||||
|
||||
export interface FamilyAttributesVersion2 {
|
||||
nextServerKeyRequestSeq: string
|
||||
}
|
||||
|
||||
export type FamilyAttributes = FamilyAttributesVersion1 & FamilyAttributesVersion2
|
||||
|
||||
export type FamilyModel = Sequelize.Model<FamilyAttributes> & FamilyAttributes
|
||||
export type FamilyModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): FamilyModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<FamilyAttributes> = {
|
||||
export const attributesVersion1: SequelizeAttributes<FamilyAttributesVersion1> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
@@ -47,4 +53,20 @@ export const attributes: SequelizeAttributes<FamilyAttributes> = {
|
||||
hasFullVersion: { ...booleanColumn }
|
||||
}
|
||||
|
||||
export const attributesVersion2: SequelizeAttributes<FamilyAttributesVersion2> = {
|
||||
nextServerKeyRequestSeq: {
|
||||
type: Sequelize.BIGINT,
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
validate: {
|
||||
min: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<FamilyAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2
|
||||
}
|
||||
|
||||
export const createFamilyModel = (sequelize: Sequelize.Sequelize): FamilyModelStatic => sequelize.define('Family', attributes) as FamilyModelStatic
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface KeyRequestAttributes {
|
||||
familyId: string
|
||||
serverSequenceNumber: string
|
||||
senderDeviceId: string
|
||||
senderSequenceNumber: string
|
||||
deviceId: string | null
|
||||
categoryId: string | null
|
||||
type: number
|
||||
tempKey: Buffer
|
||||
signature: Buffer
|
||||
}
|
||||
|
||||
export const types = {
|
||||
appListBase: 1,
|
||||
appListDiff: 2,
|
||||
all: [1, 2]
|
||||
}
|
||||
|
||||
export type KeyRequestModel = Sequelize.Model<KeyRequestAttributes> & KeyRequestAttributes
|
||||
export type KeyRequestModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): KeyRequestModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<KeyRequestAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
serverSequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
primaryKey: true,
|
||||
allowNull: false
|
||||
},
|
||||
senderDeviceId: {
|
||||
...idWithinFamilyColumn
|
||||
},
|
||||
senderSequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
allowNull: false
|
||||
},
|
||||
deviceId: {
|
||||
...idWithinFamilyColumn,
|
||||
allowNull: true
|
||||
},
|
||||
categoryId: {
|
||||
...idWithinFamilyColumn,
|
||||
allowNull: true
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isIn: [types.all]
|
||||
}
|
||||
},
|
||||
tempKey: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
},
|
||||
signature: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
}
|
||||
}
|
||||
|
||||
export const createKeyRequestModel = (sequelize: Sequelize.Sequelize): KeyRequestModelStatic => sequelize.define('KeyRequest', attributes) as KeyRequestModelStatic
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface KeyResponseAttributes {
|
||||
familyId: string
|
||||
receiverDeviceId: string
|
||||
requestServerSequenceNumber: string // fk to request table with familyId
|
||||
senderDeviceId: string // pk up to this
|
||||
replyServerSequenceNumber: string // unique with familyId, receiverDeviceId
|
||||
requestClientSequenceNumber: string
|
||||
tempKey: Buffer
|
||||
encryptedKey: Buffer
|
||||
signature: Buffer
|
||||
}
|
||||
|
||||
export type KeyResponseModel = Sequelize.Model<KeyResponseAttributes> & KeyResponseAttributes
|
||||
export type KeyResponseModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): KeyResponseModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<KeyResponseAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
receiverDeviceId: {
|
||||
...idWithinFamilyColumn
|
||||
},
|
||||
requestServerSequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
primaryKey: true,
|
||||
allowNull: false
|
||||
},
|
||||
senderDeviceId: {
|
||||
...idWithinFamilyColumn
|
||||
},
|
||||
replyServerSequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
allowNull: false
|
||||
},
|
||||
requestClientSequenceNumber: {
|
||||
type: Sequelize.BIGINT,
|
||||
allowNull: false
|
||||
},
|
||||
tempKey: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
},
|
||||
encryptedKey: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
},
|
||||
signature: {
|
||||
type: Sequelize.BLOB,
|
||||
allowNull: false
|
||||
}
|
||||
}
|
||||
|
||||
export const createKeyResponseModel = (sequelize: Sequelize.Sequelize): KeyResponseModelStatic => sequelize.define('KeyResponse', attributes) as KeyResponseModelStatic
|
||||
@@ -27,7 +27,10 @@ import { CategoryTimeWarningModelStatic, createCategoryTimeWarningModel } from '
|
||||
import { ChildTaskModelStatic, createChildTaskModel } from './childtask'
|
||||
import { ConfigModelStatic, createConfigModel } from './config'
|
||||
import { createDeviceModel, DeviceModelStatic } from './device'
|
||||
import { createEncryptedAppListModel, EncryptedAppListModelStatic } from './encryptedapplist'
|
||||
import { createFamilyModel, FamilyModelStatic } from './family'
|
||||
import { createKeyRequestModel, KeyRequestModelStatic } from './keyrequest'
|
||||
import { createKeyResponseModel, KeyResponseModelStatic } from './keyresponse'
|
||||
import { createMailLoginTokenModel, MailLoginTokenModelStatic } from './maillogintoken'
|
||||
import { createUmzug } from './migration/umzug'
|
||||
import { createOldDeviceModel, OldDeviceModelStatic } from './olddevice'
|
||||
@@ -52,7 +55,10 @@ export interface Database {
|
||||
childTask: ChildTaskModelStatic
|
||||
config: ConfigModelStatic
|
||||
device: DeviceModelStatic
|
||||
encryptedAppList: EncryptedAppListModelStatic
|
||||
family: FamilyModelStatic
|
||||
keyRequest: KeyRequestModelStatic
|
||||
keyResponse: KeyResponseModelStatic
|
||||
mailLoginToken: MailLoginTokenModelStatic
|
||||
oldDevice: OldDeviceModelStatic
|
||||
purchase: PurchaseModelStatic
|
||||
@@ -77,7 +83,10 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
|
||||
categoryTimeWarning: createCategoryTimeWarningModel(sequelize),
|
||||
config: createConfigModel(sequelize),
|
||||
device: createDeviceModel(sequelize),
|
||||
encryptedAppList: createEncryptedAppListModel(sequelize),
|
||||
family: createFamilyModel(sequelize),
|
||||
keyRequest: createKeyRequestModel(sequelize),
|
||||
keyResponse: createKeyResponseModel(sequelize),
|
||||
mailLoginToken: createMailLoginTokenModel(sequelize),
|
||||
oldDevice: createOldDeviceModel(sequelize),
|
||||
purchase: createPurchaseModel(sequelize),
|
||||
|
||||
@@ -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
|
||||
@@ -22,7 +22,7 @@ import { attributesVersion1 as authTokenAttributes } from '../../authtoken'
|
||||
import { attributesVersion1 as categoryAttributes } from '../../category'
|
||||
import { attributes as categoryAppAttributes } from '../../categoryapp'
|
||||
import { attributesVersion1 as deviceAttributes } from '../../device'
|
||||
import { attributes as familyAttributes } from '../../family'
|
||||
import { attributesVersion1 as familyAttributes } from '../../family'
|
||||
import { attributes as purchaseAttributes } from '../../purchase'
|
||||
import { attributesVersion1 as timelimitruleAttributes } from '../../timelimitrule'
|
||||
import { attributesVersion1 as usedTimeAttribute } from '../../usedtime'
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
const dialect = sequelize.getDialect()
|
||||
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
||||
const isPosgresql = dialect === 'postgres'
|
||||
|
||||
if (isMysql) {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `EncryptedAppLists` ' +
|
||||
'(`familyId` VARCHAR(10) NOT NULL, `deviceId` VARCHAR(6) NOT NULL,' +
|
||||
'`type` INTEGER NOT NULL, `version` VARCHAR(4) NOT NULL,' +
|
||||
'`data` BLOB NOT NULL, ' +
|
||||
'PRIMARY KEY (`familyId`, `deviceId`, `type`),' +
|
||||
'FOREIGN KEY (`familyId`, `deviceId`) REFERENCES `Devices` (`familyId`, `deviceId`) ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
} else {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE "EncryptedAppLists" ' +
|
||||
'("familyId" VARCHAR(10) NOT NULL, "deviceId" VARCHAR(6) NOT NULL,' +
|
||||
'"type" INTEGER NOT NULL, "version" VARCHAR(4) NOT NULL,' +
|
||||
'"data" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'PRIMARY KEY ("familyId", "deviceId", "type"),' +
|
||||
'FOREIGN KEY ("familyId", "deviceId") REFERENCES "Devices" ("familyId", "deviceId") ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
await queryInterface.addIndex('EncryptedAppLists', ['familyId', 'deviceId', 'type', 'version'], { transaction })
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('EncryptedAppLists', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion13 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Devices', 'publicKey', {
|
||||
...deviceAttributes.publicKey
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Devices', 'publicKey', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion2 as familyAttributes } from '../../family'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Families', 'nextServerKeyRequestSeq', {
|
||||
...familyAttributes.nextServerKeyRequestSeq
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Families', 'nextServerKeyRequestSeq', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
const dialect = sequelize.getDialect()
|
||||
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
||||
const isPosgresql = dialect === 'postgres'
|
||||
|
||||
if (isMysql) {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `KeyRequests` (' +
|
||||
'`familyId` VARCHAR(10) NOT NULL, ' +
|
||||
'`serverSequenceNumber` BIGINT NOT NULL, ' +
|
||||
'`senderDeviceId` VARCHAR(6) NOT NULL, ' +
|
||||
'`senderSequenceNumber` BIGINT NOT NULL, ' +
|
||||
'`deviceId` VARCHAR(6) NULL, ' +
|
||||
'`categoryId` VARCHAR(6) NULL, ' +
|
||||
'`type` INTEGER NOT NULL, ' +
|
||||
'`tempKey` BLOB NOT NULL, ' +
|
||||
'`signature` BLOB NOT NULL, ' +
|
||||
'PRIMARY KEY (`familyId`, `serverSequenceNumber`), ' +
|
||||
'FOREIGN KEY (`familyId`, `senderDeviceId`) REFERENCES `Devices` (`familyId`, `deviceId`) ON UPDATE CASCADE ON DELETE CASCADE, ' +
|
||||
'FOREIGN KEY (`familyId`, `deviceId`) REFERENCES `Devices` (`familyId`, `deviceId`) ON UPDATE CASCADE ON DELETE CASCADE, ' +
|
||||
'FOREIGN KEY (`familyId`, `categoryId`) REFERENCES `Categories` (`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
} else {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE "KeyRequests" (' +
|
||||
'"familyId" VARCHAR(10) NOT NULL, ' +
|
||||
'"serverSequenceNumber" ' + (isPosgresql ? 'BIGINT' : 'LONG') + ' NOT NULL, ' +
|
||||
'"senderDeviceId" VARCHAR(6) NOT NULL, ' +
|
||||
'"senderSequenceNumber" ' + (isPosgresql ? 'BIGINT' : 'LONG') + ' NOT NULL, ' +
|
||||
'"deviceId" VARCHAR(6) NULL, ' +
|
||||
'"categoryId" VARCHAR(6) NULL, ' +
|
||||
'"type" INTEGER NOT NULL, ' +
|
||||
'"tempKey" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'"signature" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'PRIMARY KEY ("familyId", "serverSequenceNumber"), ' +
|
||||
'FOREIGN KEY ("familyId", "senderDeviceId") REFERENCES "Devices" ("familyId", "deviceId") ON UPDATE CASCADE ON DELETE CASCADE, ' +
|
||||
'FOREIGN KEY ("familyId", "deviceId") REFERENCES "Devices" ("familyId", "deviceId") ON UPDATE CASCADE ON DELETE CASCADE, ' +
|
||||
'FOREIGN KEY ("familyId", "categoryId") REFERENCES "Categories" ("familyId", "categoryId") ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
await queryInterface.addIndex('KeyRequests', ['familyId', 'senderDeviceId', 'senderSequenceNumber'], { transaction })
|
||||
await queryInterface.addIndex('KeyRequests', ['familyId', 'deviceId'], { transaction })
|
||||
await queryInterface.addIndex('KeyRequests', ['familyId', 'categoryId'], { transaction })
|
||||
await queryInterface.addIndex('KeyRequests', ['familyId', 'senderDeviceId', 'deviceId', 'categoryId'], { transaction, unique: true })
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('KeyRequests', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
const dialect = sequelize.getDialect()
|
||||
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
||||
const isPosgresql = dialect === 'postgres'
|
||||
|
||||
if (isMysql) {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `KeyResponses` (' +
|
||||
'`familyId` VARCHAR(10) NOT NULL, ' +
|
||||
'`receiverDeviceId` VARCHAR(6) NOT NULL, ' +
|
||||
'`requestServerSequenceNumber` BIGINT NOT NULL, ' +
|
||||
'`senderDeviceId` VARCHAR(6) NOT NULL, ' +
|
||||
'`replyServerSequenceNumber` BIGINT NOT NULL, ' +
|
||||
'`requestClientSequenceNumber` BIGINT NOT NULL, ' +
|
||||
'`tempKey` BLOB NOT NULL, ' +
|
||||
'`encryptedKey` BLOB NOT NULL, ' +
|
||||
'`signature` BLOB NOT NULL, ' +
|
||||
'PRIMARY KEY (`familyId`, `receiverDeviceId`, `requestServerSequenceNumber`, `senderDeviceId`), ' +
|
||||
'FOREIGN KEY (`familyId`, `requestServerSequenceNumber`) REFERENCES `KeyRequests` (`familyId`, `serverSequenceNumber`) ON UPDATE CASCADE ON DELETE CASCADE ' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
} else {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE "KeyResponses" (' +
|
||||
'"familyId" VARCHAR(10) NOT NULL, ' +
|
||||
'"receiverDeviceId" VARCHAR(6) NOT NULL, ' +
|
||||
'"requestServerSequenceNumber" ' + (isPosgresql ? 'BIGINT' : 'LONG') + ' NOT NULL, ' +
|
||||
'"senderDeviceId" VARCHAR(6) NOT NULL, ' +
|
||||
'"replyServerSequenceNumber" ' + (isPosgresql ? 'BIGINT' : 'LONG') + ' NOT NULL, ' +
|
||||
'"requestClientSequenceNumber" ' + (isPosgresql ? 'BIGINT' : 'LONG') + ' NOT NULL, ' +
|
||||
'"tempKey" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'"encryptedKey" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'"signature" ' + (isPosgresql ? 'BYTEA' : 'BLOB') + ' NOT NULL, ' +
|
||||
'PRIMARY KEY ("familyId", "receiverDeviceId", "requestServerSequenceNumber", "senderDeviceId"), ' +
|
||||
'FOREIGN KEY ("familyId", "requestServerSequenceNumber") REFERENCES "KeyRequests" ("familyId", "serverSequenceNumber") ON UPDATE CASCADE ON DELETE CASCADE ' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
}
|
||||
|
||||
await queryInterface.addIndex('KeyResponses', ['familyId', 'requestServerSequenceNumber'], { transaction })
|
||||
await queryInterface.addIndex(
|
||||
'KeyResponses',
|
||||
['familyId', 'receiverDeviceId', 'replyServerSequenceNumber'],
|
||||
{
|
||||
transaction,
|
||||
unique: true,
|
||||
name: 'key_response_index_fid_rdid_rssn'
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('KeyResponses', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion14 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Devices', 'nextKeyReplySequenceNumber', {
|
||||
...deviceAttributes.nextKeyReplySequenceNumber
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Devices', 'nextKeyReplySequenceNumber', { transaction })
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user