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

[#832] fix the issue when private key was never used #833

Closed
wants to merge 1 commit into from

Conversation

dmitriim
Copy link
Member

No description provided.

Comment on lines +297 to +301
$config = $this->stepdef->get('config');

if (empty($config)) {
return $password;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is config itself ever empty for this step? I think it's not possible given it's validation.

Copy link
Member Author

@dmitriim dmitriim Aug 31, 2023

Choose a reason for hiding this comment

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

well, it's a trait so we can't be 100% sure how it could be used... for me it makes sense to add this check.

Comment on lines +303 to +306
if (!empty($config->password)) {
// Because variables use redacted values by default, we evaluate the secret explicitly.
$password = $this->get_variables()->evaluate($config->password);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this would miss cases where the password is an empty string or zero(es). It might be too edgy of a case to care though, and it's probably something that shouldn't be set so I'm okay with this.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point. Changing to isset


// Use key authorisation if privkeyfile is set.
if (!empty($config->privkeyfile)) {
$privkeycontents = file_get_contents($this->resolve_path($config->privkeyfile));
$privkeypassphrase = $config->password ?: false;
$privkeypassphrase = $password ?: false;
Copy link
Contributor

Choose a reason for hiding this comment

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

By this stage, password would have already been set. It's safe to use the password variable as-is and you do not have to assign it to a new variable (or default it back to false)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is annoying, but it's not very clear what will be returned by $this->get_variables()->evaluate($config->password); Ideally we should add more validation here to make sure it's a string.

@@ -293,13 +293,22 @@ public function execute($input = null) {
* @return AsymmetricKey|string
*/
private function load_key() {
// Because variables use redacted values by default, we evaluate the secret explicitly.
$password = $this->get_variables()->evaluate($this->stepdef->config->password);
$password = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also concerned whether or not the current user:pass and user:nopassword will work, if false is returned. If it's OK, that's great. We should update the phpdoc to support AsymmetricKey|string|false

@dmitriim
Copy link
Member Author

dmitriim commented Aug 31, 2023

All those good points that need to be sorted. For now we re moving on with minimum changes #834

@dmitriim dmitriim closed this Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants