Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(keystone): DOMA-10642 custom field for encrypted text #5450

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

YEgorLu
Copy link
Contributor

@YEgorLu YEgorLu commented Nov 9, 2024

Simplify work with encrypted data, remove 'keyField's, support different algorithms and secrets on same table
See README.md

@YEgorLu YEgorLu added ✋🙂 Review please Comments are resolved, take a look, please 😎 Cool 📦 Packages labels Nov 9, 2024
packages/keystone/cipher.js Outdated Show resolved Hide resolved
packages/keystone/cipher.js Outdated Show resolved Hide resolved
packages/keystone/cipher.js Outdated Show resolved Hide resolved
packages/keystone/cipher.js Outdated Show resolved Hide resolved
packages/keystone/cipher.js Outdated Show resolved Hide resolved
…ypted by manager; Do not encrypt field before database, if it is encrypted; Enhance script; Rename field;
Comment on lines +42 to +44
const errorStart = _getErrorStart(listKey, path)
const encryptionManager = _getEncryptionManager(errorStart, options)
set(options, 'encryptionManager', encryptionManager)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's hard to understand whats going on here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to provide EncryptionManager for fieldAdapter. FieldAdapter parses options before we can do something in constructor here, so must update "options" before super()

Copy link

sonarcloud bot commented Nov 25, 2024


const compressors = {
'noop': noop,
'open-condo_brotli': require('./brotli'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An imports should be at the top

/** @type {Record<string, KeyDeriver>} */
const keyDerivers = {
'noop': noop,
'open-condo_pbkdf2-sha512': require('./pbkdf2'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be at the top

throw new Error(`Algorithm ${algorithm} is not supported right now at ${versionId}.algorithm`)
}
if (SUGGESTIONS[cipherInfo.mode]) {
console.warn(`${SUGGESTIONS[cipherInfo.mode]} at ${versionId}.algorithm`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s better to throw an error …


const keyLength = cipherInfo.keyLength

if ((typeof secret !== 'string' && !(secret instanceof Buffer)) || isEmpty(secret)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also check the length of the secret … And check it by bad password list (same as password).


const conf = require('@open-condo/config')

const { compressors } = require('./compressors')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a global const {[name]: function} it’s better to use consts like naming.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s better to use this global cost for EncryptionVersion. I know too many cases and usually I need to write own EncryptionVersion …


const { compressors } = require('./compressors')
const { EncryptionVersion } = require('./EncryptionVersion')
const { keyDerivers } = require('./keyDerivers')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, looks like global consts mapping (like MESSAGE_META or any other)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 Packages ✋🙂 Review please Comments are resolved, take a look, please
Development

Successfully merging this pull request may close these issues.

4 participants