Skip to content

Encryption and authentication #29

Open

Description

@vascanera

Please consider adding some form of full file encryption (e.g.: Mcrypt?) for the stored JSON files.
Also, please consider adding some form of user authentication (a nice to have).
Keep up the good work!

Activity

  1. changed the title [-]Encrpytion and authentication[/-] [+]Encryption and authentication[/+] on Feb 20, 2020
  2. added
    enhancement
    on Feb 21, 2020
  3. rakibtg commented on Feb 22, 2020

    @rakibtg
    Member

    @adrianvoica It seems like Mcrypt is removed in in PHP 7.2 and introduced Sodium. Sodium is not available in old versions of PHP including 7.1!
    Do you have any thoughts/opinion on this?

  4. vascanera commented on Feb 23, 2020

    @vascanera
    Author

    @rakibtg Well, I am not talking about an actual implementation of a certain algorithm, I am just saying there could be placeholder method (custom hook) that, when present, will encode / decode the data right before writing / after reading from the actual files (based on the user's preference of an algorithm, either an established one or a custom built one). Same goes for authentication. If these 2 "issues" are tackled, I think SleekDB could really take off, since it will have everything required for building rapid JSON-based RESTful APIs. Cheers!

  5. rakibtg commented on Feb 26, 2020

    @rakibtg
    Member

    @684102 Sure! Send a PR I will check your implementation.. Any contributions are always welcome :)

  6. added this to the Version 2.1 milestone on Jan 18, 2021
  7. modified the milestones: Version 2.2, on Feb 7, 2021
  8. REDAL commented on Feb 19, 2021

    @REDAL

    @adrianvoica It seems like Mcrypt is removed in in PHP 7.2 and introduced Sodium. Sodium is not available in old versions of PHP including 7.1!
    Do you have any thoughts/opinion on this?

    we can make it only for the supported version of PHP

  9. Timu57 commented on Feb 22, 2021

    @Timu57
    Member

    We could use the following project to implement encryption instead of reinventing the wheel:

    https://github.com/defuse/php-encryption

    The dependency graph does not look bad too.

    https://github.com/defuse/php-encryption/network/dependencies

    But we would need to add the following to composer.json:

    {
      "require": {
        "ext-openssl": "*",
        "defuse/php-encryption": "^2.0"
      },
      "suggest": {
        "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
      },
    }
  10. TheSyedKazmi commented on Feb 24, 2021

    @TheSyedKazmi

    this is just a thought since we are talking about flat file system and thus given would be tables would be the files or table wold be individual folder with files as entry points. either ways. just encrypt with openssl with key provided by user. us the key to read write individual files, which ever the case may be. I am taking hint from how larvel uses key to encrypt session and cookies and becomes very handy use case on shared hosting.

  11. Timu57 commented on Feb 25, 2021

    @Timu57
    Member

    @sk-pro-cloud I am sorry but I did not understand what you meant? What would be handy?

  12. Timu57 commented on Feb 25, 2021

    @Timu57
    Member

    https://github.com/illuminate/encryption
    The implementation of encryption in laravel is very interesting and simple.. Could that be something for us?

  13. rakibtg commented on Feb 25, 2021

    @rakibtg
    Member
  14. Timu57 commented on Feb 26, 2021

    @Timu57
    Member

    Encryption modes

    I think when implementing encryption we should implement it with 3 modes.

    1. No encryption
    2. Encrypt whole store
    3. Encrypt parts of documents

    How will SleekDB know which mode to use?

    Solution ideas:

    1. SleekDB creates and uses a new store called _encryptionSettings or something where all settings regarding encryption is stored
    2. Every store include one new file that holds the settings.

    New Store method

    To retrieve the Encrypter object we could implement one new method to the Store class.

    function getEncrypter(): Encrypter

    Encrypter methods

    Probably we could implement two new methods for the users to work with encryption:

    1. Encryper->setSettings(...): Encrypter
    2. Encrypter->getSettings(): bool|array

    setSettings()

    function setSettings(bool|array $encryptionSetting): Encrypter

    Parameters

    • $encryptionSetting

      • If it is false no encryption will be used (and the settings will be deleted if exist)
      • If it is true the whole document will be encrypted (except the _id)
      • If it is an array it has to contain all the fields to encrypt (all fields not included will not be encrypted)

    Encrypt/Decrypt all documents

    For the use case that someone wants to use that feature on an existing database we could / should also provide the following two methods:

    encryptAllDocuments()

    Uses the current settings to encrypt all documents.

    decryptAllDocuments()

    Uses the current settings to decrypt all documents.

    Other Solutions?!

    I am sure we can come up with a more convenient solution than my quick idea. Let us discuss and let us hear your ideas!

  15. added and removed
    enhancement
    on Feb 26, 2021
  16. TheSyedKazmi commented on Mar 11, 2021

    @TheSyedKazmi

    @Timu57 you caught my gist very nicely and was precisely the larvel repo I had in mind. you are on a right track there is encryption on normal. there is normal+salt+key.

    Now there might be cases were one does not need to the whole razmataz of encryption just that file is tinkered with e.g. how Opis if signing files https://opis.io/closure/3.x/security.html. One could adopt the idea of https://opis.io/closure/3.x/security.html#custom-security-providers concept into mix.

    I had in my project used something of similar i.e. suppose json is flat file with bunch of strings (eventually this what it really is). bin-dex it in to alphanumeric characters, Then hash_hmac with secret and then prepend has_hmac and length of charters to the string in following format.

    hash_hmac:charaterlength of bin-hex:bin-hex e.g. asdasd23423sda34:10:2sds2545ss
    do keep in mind hash_mac would come in fixed string length based on what ever encryption base you choose.
    when getting explode : so we get

    [ 0 => asdasd23423sda34,
    1 =>10
    2 =>2sds2545ss
    ]
    quick logic
    if (strlen(a[2]) !==a[1] ) run exception;
    if (!decryt) run exception;
    else do what ever you want.
    so given from above suppose we use false as default aka no encryption we can still use the character count mechanism to keep a bay wandering fid bits who may tinker with code a) is not straight off human readable b) it needs some form of processing to be ready for some thing to be done on it else its just bunch of characters c) third it would maintain some from security measure in file or system.
    This is my fantasised vision going forward.
    Reality is intention is not to make something bullet proof but enough strong to take the shock. if there are other mechanism watching on then system can capture on that 1-2 millisecond buffer it gets. I had custom exception played into mix. If such and such occurs custom exception triggers. you can send an email, set tracking cookie, block IP and what ever else not.
    Its two part game one is before the fact and one is after the fact with lots of what ifs in it. what happens when trigger occurs, what happens after the trigger, what happens to resources that depend on resources not offered because trigger occurred - fallback,

  17. bespired commented on Jul 12, 2021

    @bespired

    What exactly are you trying to accomplish here?
    Seems to me all the code needed to decrypt the stored files are right here where the files are ...

    Or am I missing something?

    Plus: Finding stuff in encrypted files can be very slow.

  18. mitmelon commented on May 15, 2022

    @mitmelon

    Encryption modes

    I think when implementing encryption we should implement it with 3 modes.

    1. No encryption
    2. Encrypt whole store
    3. Encrypt parts of documents

    How will SleekDB know which mode to use?

    Solution ideas:

    1. SleekDB creates and uses a new store called _encryptionSettings or something where all settings regarding encryption is stored
    2. Every store include one new file that holds the settings.

    New Store method

    To retrieve the Encrypter object we could implement one new method to the Store class.

    function getEncrypter(): Encrypter
    

    Encrypter methods

    Probably we could implement two new methods for the users to work with encryption:

    1. Encryper->setSettings(...): Encrypter
    2. Encrypter->getSettings(): bool|array

    setSettings()

    function setSettings(bool|array $encryptionSetting): Encrypter
    

    Parameters

    • $encryptionSetting

      • If it is false no encryption will be used (and the settings will be deleted if exist)
      • If it is true the whole document will be encrypted (except the _id)
      • If it is an array it has to contain all the fields to encrypt (all fields not included will not be encrypted)

    Encrypt/Decrypt all documents

    For the use case that someone wants to use that feature on an existing database we could / should also provide the following two methods:

    encryptAllDocuments()

    Uses the current settings to encrypt all documents.

    decryptAllDocuments()

    Uses the current settings to decrypt all documents.

    Other Solutions?!

    I am sure we can come up with a more convenient solution than my quick idea. Let us discuss and let us hear your ideas!

    This is the most efficient way of doing this... But this feature request has been over a year now and yet nothing has been done to implement this...

    I think it's best if developers implement this themselves...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions