Skip to content

Handle key generation when key is not present in .env - #6839

Merged
samsonasik merged 2 commits into
codeigniter4:developfrom
paulbalandan:fix-key-generate
Nov 10, 2022
Merged

Handle key generation when key is not present in .env#6839
samsonasik merged 2 commits into
codeigniter4:developfrom
paulbalandan:fix-key-generate

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Fixes #6838

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@totoprayogo1916

Copy link
Copy Markdown
Contributor

A new problem arises if the encryption.key is already filled and then marked with a hash.
The new key cannot be made active.

# encryption.key = hex2bin:ac14ecef198655f6f465e6bbd0715f2b0eb107c7efb9663d75e7df7574f9757c

@paulbalandan

Copy link
Copy Markdown
Member Author

key:generate relies on env() to get the replaceable key. If the key is commented out, env() will return ''.

$currentKey = env('encryption.key', '');

@totoprayogo1916

totoprayogo1916 commented Nov 10, 2022

Copy link
Copy Markdown
Contributor

What I mean is,
encryption.key that has been filled in and marked with the hash

when run spark key:generate,
The .env file does not make the encryption.key active.
And the encryption.key still remains with the hash mark.

@paulbalandan

Copy link
Copy Markdown
Member Author

Okay. I got what you mean. This is because preg_replace() did not find the old key in the file because it thinks it is an empty string.

@paulbalandan

Copy link
Copy Markdown
Member Author

@totoprayogo1916 Kindly check new code

@totoprayogo1916 totoprayogo1916 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It works

@samsonasik
samsonasik merged commit e86ef99 into codeigniter4:develop Nov 10, 2022
@samsonasik

Copy link
Copy Markdown
Member

Thank you @paulbalandan

@paulbalandan
paulbalandan deleted the fix-key-generate branch November 10, 2022 06:21
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: spark key:generate doesn't generate encryption.key if no template

5 participants