Dump valid JSON file and minor correction for opensshforwindows keys #354
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
this PR addresses two issues that I detected when running LaZagne:
First, the JSON dump outputs an invalid JSON when special characters are in the result (for example, newline characters or quotes). In this case, if you try to load the content of the output file with
json.loads
(for instance) you will get an exception. This is what is described in issue JSON format stores multi-line string for SSH keys #226 regarding multi-line strings for SSH keys in the JSON output. This is due to thedecode('unicode-escape')
instruction when the JSON file is written:This will decode the special characters (\n for newline or " for quotes) that need to be encoded for the JSON to be valid according to its specification (see the answer to this stackoverflow thread). Substituting the previous line by:
solves this issue.
Second, the password key for opensshforwindows credentials is spelled as
PrivateKey
(note the capital K). However, when writing the output, the code will convert the key to lowercase (see here). Later, the code will check that the password is not empty capitalizing only the first letter (see here). That is, it will look for the value stored under the keyPrivatekey
which will not exist. Thus, the output will not contain the SSH key that was actually found. Changing the key fromPrivateKey
toPrivatekey
solves the issue.I hope this is helpful. Please, let me know if you need any clarification or if you have any comment!