summary refs log tree commit diff
path: root/src/util/entities
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-01-29 21:30:42 -0500
committerGitHub <noreply@github.com>2023-01-30 13:30:42 +1100
commit709dc7280e8b4aab2b173c3897b418f6e1759ae7 (patch)
tree5a8ed3e144a8032649d1c2f7c72f9c0c01e7742c /src/util/entities
parentMerge branch 'master' of github.com:fosscord/fosscord-server (diff)
downloadserver-709dc7280e8b4aab2b173c3897b418f6e1759ae7.tar.xz
Implement WebAuthn (#967)
* implement webauthn

* code review

---------

Co-authored-by: Madeline <46743919+MaddyUnderStars@users.noreply.github.com>
Diffstat (limited to 'src/util/entities')
-rw-r--r--src/util/entities/SecurityKey.ts46
-rw-r--r--src/util/entities/User.ts7
-rw-r--r--src/util/entities/index.ts3
3 files changed, 55 insertions, 1 deletions
diff --git a/src/util/entities/SecurityKey.ts b/src/util/entities/SecurityKey.ts
new file mode 100644
index 00000000..8f377d9d
--- /dev/null
+++ b/src/util/entities/SecurityKey.ts
@@ -0,0 +1,46 @@
+/*
+	Fosscord: A FOSS re-implementation and extension of the Discord.com backend.
+	Copyright (C) 2023 Fosscord and Fosscord Contributors
+	
+	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, either version 3 of the License, or
+	(at your option) any later version.
+	
+	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 { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { BaseClass } from "./BaseClass";
+import { User } from "./User";
+
+@Entity("security_keys")
+export class SecurityKey extends BaseClass {
+	@Column({ nullable: true })
+	@RelationId((key: SecurityKey) => key.user)
+	user_id: string;
+
+	@JoinColumn({ name: "user_id" })
+	@ManyToOne(() => User, {
+		onDelete: "CASCADE",
+	})
+	user: User;
+
+	@Column()
+	key_id: string;
+
+	@Column()
+	public_key: string;
+
+	@Column()
+	counter: number;
+
+	@Column()
+	name: string;
+}
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index 658584c3..fa8c7aa7 100644
--- a/src/util/entities/User.ts
+++ b/src/util/entities/User.ts
@@ -33,6 +33,7 @@ import { UserSettings } from "./UserSettings";
 import { Session } from "./Session";
 import { Config, FieldErrors, Snowflake, trimSpecial, adjustEmail } from "..";
 import { Request } from "express";
+import { SecurityKey } from "./SecurityKey";
 
 export enum PublicUserEnum {
 	username,
@@ -138,6 +139,9 @@ export class User extends BaseClass {
 	@Column({ select: false })
 	mfa_enabled: boolean = false; // if multi factor authentication is enabled
 
+	@Column({ select: false, default: false })
+	webauthn_enabled: boolean = false; // if webauthn multi factor authentication is enabled
+
 	@Column({ select: false, nullable: true })
 	totp_secret?: string = "";
 
@@ -223,6 +227,9 @@ export class User extends BaseClass {
 	@Column({ type: "simple-json", select: false })
 	extended_settings: string = "{}";
 
+	@OneToMany(() => SecurityKey, (key: SecurityKey) => key.user)
+	security_keys: SecurityKey[];
+
 	// TODO: I don't like this method?
 	validate() {
 		if (this.email) {
diff --git a/src/util/entities/index.ts b/src/util/entities/index.ts
index d856c41b..6dfbd822 100644
--- a/src/util/entities/index.ts
+++ b/src/util/entities/index.ts
@@ -23,8 +23,8 @@ export * from "./BackupCodes";
 export * from "./Ban";
 export * from "./BaseClass";
 export * from "./Categories";
-export * from "./ClientRelease";
 export * from "./Channel";
+export * from "./ClientRelease";
 export * from "./Config";
 export * from "./ConnectedAccount";
 export * from "./EmbedCache";
@@ -41,6 +41,7 @@ export * from "./ReadState";
 export * from "./Recipient";
 export * from "./Relationship";
 export * from "./Role";
+export * from "./SecurityKey";
 export * from "./Session";
 export * from "./Sticker";
 export * from "./StickerPack";