refactor: remove PGP encryption usage for user email and secrets
Eliminated PGP encryption for `email` and `twoFactorSecret` fields in `users` schema to simplify handling of sensitive data. Since abstraction in schemas.
This commit is contained in:
@@ -36,7 +36,6 @@ export class MediaService {
|
|||||||
|
|
||||||
private async initClamScan() {
|
private async initClamScan() {
|
||||||
try {
|
try {
|
||||||
// @ts-expect-error
|
|
||||||
const scanner = await new NodeClam().init({
|
const scanner = await new NodeClam().init({
|
||||||
clamdscan: {
|
clamdscan: {
|
||||||
host: this.configService.get<string>("CLAMAV_HOST", "localhost"),
|
host: this.configService.get<string>("CLAMAV_HOST", "localhost"),
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { Injectable } from "@nestjs/common";
|
|||||||
import { eq, sql } from "drizzle-orm";
|
import { eq, sql } from "drizzle-orm";
|
||||||
import { CryptoService } from "../crypto/crypto.service";
|
import { CryptoService } from "../crypto/crypto.service";
|
||||||
import { DatabaseService } from "../database/database.service";
|
import { DatabaseService } from "../database/database.service";
|
||||||
import { contents, favorites, users } from "../database/schemas";
|
import {
|
||||||
|
contents,
|
||||||
|
favorites,
|
||||||
|
users,
|
||||||
|
} from "../database/schemas";
|
||||||
import { UpdateUserDto } from "./dto/update-user.dto";
|
import { UpdateUserDto } from "./dto/update-user.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -18,13 +22,11 @@ export class UsersService {
|
|||||||
passwordHash: string;
|
passwordHash: string;
|
||||||
emailHash: string;
|
emailHash: string;
|
||||||
}) {
|
}) {
|
||||||
const pgpKey = this.cryptoService.getPgpEncryptionKey();
|
|
||||||
|
|
||||||
const [newUser] = await this.databaseService.db
|
const [newUser] = await this.databaseService.db
|
||||||
.insert(users)
|
.insert(users)
|
||||||
.values({
|
.values({
|
||||||
username: data.username,
|
username: data.username,
|
||||||
email: sql`pgp_sym_encrypt(${data.email}, ${pgpKey})`,
|
email: data.email,
|
||||||
emailHash: data.emailHash,
|
emailHash: data.emailHash,
|
||||||
passwordHash: data.passwordHash,
|
passwordHash: data.passwordHash,
|
||||||
})
|
})
|
||||||
@@ -34,13 +36,11 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByEmailHash(emailHash: string) {
|
async findByEmailHash(emailHash: string) {
|
||||||
const pgpKey = this.cryptoService.getPgpEncryptionKey();
|
|
||||||
|
|
||||||
const result = await this.databaseService.db
|
const result = await this.databaseService.db
|
||||||
.select({
|
.select({
|
||||||
uuid: users.uuid,
|
uuid: users.uuid,
|
||||||
username: users.username,
|
username: users.username,
|
||||||
email: sql<string>`pgp_sym_decrypt(${users.email}, ${pgpKey})`,
|
email: users.email,
|
||||||
passwordHash: users.passwordHash,
|
passwordHash: users.passwordHash,
|
||||||
status: users.status,
|
status: users.status,
|
||||||
isTwoFactorEnabled: users.isTwoFactorEnabled,
|
isTwoFactorEnabled: users.isTwoFactorEnabled,
|
||||||
@@ -53,13 +53,11 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOneWithPrivateData(uuid: string) {
|
async findOneWithPrivateData(uuid: string) {
|
||||||
const pgpKey = this.cryptoService.getPgpEncryptionKey();
|
|
||||||
|
|
||||||
const result = await this.databaseService.db
|
const result = await this.databaseService.db
|
||||||
.select({
|
.select({
|
||||||
uuid: users.uuid,
|
uuid: users.uuid,
|
||||||
username: users.username,
|
username: users.username,
|
||||||
email: sql<string>`pgp_sym_decrypt(${users.email}, ${pgpKey})`,
|
email: users.email,
|
||||||
displayName: users.displayName,
|
displayName: users.displayName,
|
||||||
status: users.status,
|
status: users.status,
|
||||||
isTwoFactorEnabled: users.isTwoFactorEnabled,
|
isTwoFactorEnabled: users.isTwoFactorEnabled,
|
||||||
@@ -146,11 +144,10 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setTwoFactorSecret(uuid: string, secret: string) {
|
async setTwoFactorSecret(uuid: string, secret: string) {
|
||||||
const pgpKey = this.cryptoService.getPgpEncryptionKey();
|
|
||||||
return await this.databaseService.db
|
return await this.databaseService.db
|
||||||
.update(users)
|
.update(users)
|
||||||
.set({
|
.set({
|
||||||
twoFactorSecret: sql`pgp_sym_encrypt(${secret}, ${pgpKey})`,
|
twoFactorSecret: secret,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(users.uuid, uuid))
|
.where(eq(users.uuid, uuid))
|
||||||
@@ -169,10 +166,9 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getTwoFactorSecret(uuid: string): Promise<string | null> {
|
async getTwoFactorSecret(uuid: string): Promise<string | null> {
|
||||||
const pgpKey = this.cryptoService.getPgpEncryptionKey();
|
|
||||||
const result = await this.databaseService.db
|
const result = await this.databaseService.db
|
||||||
.select({
|
.select({
|
||||||
secret: sql<string>`pgp_sym_decrypt(${users.twoFactorSecret}, ${pgpKey})`,
|
secret: users.twoFactorSecret,
|
||||||
})
|
})
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(eq(users.uuid, uuid))
|
.where(eq(users.uuid, uuid))
|
||||||
|
|||||||
Reference in New Issue
Block a user