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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions classes/local/step/sftp_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

$config = $this->stepdef->get('config');

if (empty($config)) {
return $password;
}
Comment on lines +297 to +301
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.


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

return PublicKeyLoader::load($privkeycontents, $privkeypassphrase);
}

Expand Down
Loading