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

WIP: sphincs+ support, for post-quantum crypto #160

Closed
wants to merge 12 commits into from

Conversation

awwad
Copy link
Contributor

@awwad awwad commented Nov 20, 2018

This PR is to create a place to discuss the changes that @cryptojedi and @joostrijneveld have recommended for adding sphincs+ post-quantum crypto support to secure-systems-lib as a means to allow TUF and in-toto to make use of it.

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@awwad
Copy link
Contributor Author

awwad commented Nov 20, 2018

I think that it's important that sphincs support and the use of pyspx (which is a bit new and could use more testing) be optional (not a requirement for ssl installation). What do you think, @SantiagoTorres?

@@ -900,6 +900,260 @@ def import_ecdsa_privatekey_from_file(filepath, password=None):
return key_object


def generate_and_write_spx_keypair(filepath=None, password=None):
Copy link
Contributor Author

@awwad awwad Nov 20, 2018

Choose a reason for hiding this comment

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

Sidenote (doesn't have to be done for this PR): much of the code in this function is duplicated in multiple places: generate_and_write_..._keypair. This makes it clear that we should modularize the generate functions and do things like argument checking, password prompting and format validation, temp file creation, writing, etc. in one place used by all the generate_... functions.

The same goes for import_..._privatekey_....




def import_spx_publickey_from_file(filepath):
Copy link
Contributor Author

@awwad awwad Nov 20, 2018

Choose a reason for hiding this comment

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

Comment requiring no change to this PR: this function can be generalized across all keytypes.

@SantiagoTorres
Copy link
Collaborator

SantiagoTorres commented Nov 20, 2018 via email

@awwad
Copy link
Contributor Author

awwad commented Nov 20, 2018

Just wanted to know if you have thoughts on optional-vs-required. No rush on that question.

@awwad
Copy link
Contributor Author

awwad commented Nov 20, 2018

@cryptojedi and @joostrijneveld: This looks good. I'll make more comments later, but I very much appreciate the effort to make this fit the style of the code and include good docstrings.

If you don't mind, I think I have to make a few edits to make the use of the sphincs+ implementation and pyspx optional before I can merge this. That'll entail a few edits after Thanksgiving (back on Monday). The thinking there is that pyspx is still pretty fresh and not heavily tested, and I don't think I should require folks using TUF to include it -- just allow them to use it optionally.

# Generate the keyid of the Ed25519 key. 'key_value' corresponds to the
# 'keyval' entry of the 'Ed25519KEY_SCHEMA' dictionary. The private key
# Generate the keyid of the ECDSA key. 'key_value' corresponds to the
# 'keyval' entry of the 'ECDSAKEY_SCHEMA' dictionary. The private key
Copy link
Contributor Author

Choose a reason for hiding this comment

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

^_^ Thanks for the typo fix.

@awwad awwad changed the title WIP: sphincs support, for post-quantum crypto WIP: sphincs+ support, for post-quantum crypto Nov 20, 2018
@joostrijneveld
Copy link

@awwad Sounds great, thanks! We didn’t really give making the dependency optional much thought (other than checking for potentially unsuccessful imports), but that definitely sounds like a good idea.

I completely agree w.r.t the status of pyspx; I’ll make sure to add some more comprehensive tests.

Copy link

@alyptik alyptik left a comment

Choose a reason for hiding this comment

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

I think a lot of the lines broken due to length could be refactored into multiple statements instead. A lot of the multiline string literals could be made a bit neater by using \n escapes instead of literal new lines.

@@ -227,7 +235,7 @@
# Supported TUF key types.
KEYTYPE_SCHEMA = SCHEMA.OneOf(
[SCHEMA.String('rsa'), SCHEMA.String('ed25519'),
SCHEMA.String('ecdsa-sha2-nistp256')])
SCHEMA.String('ecdsa-sha2-nistp256'),SCHEMA.String('spx')])
Copy link

Choose a reason for hiding this comment

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

Shouldn't there be a space after the "," to be consistent with the previous line?

Choose a reason for hiding this comment

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

You're right; fixed!

# worry about leaking sensitive information about the key's location.
# However, care should be taken when including the full path in exceptions
# and log files.
password = get_password('Enter a password for the SPX'
Copy link

Choose a reason for hiding this comment

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

Multi-line strings like this are kind of confusing to mentally parse when combined with string concatenation. Is there maybe a more compact way to write these?

Choose a reason for hiding this comment

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

This addition is an artifact of code duplication, which seems out of scope for this pull request.

# to a programmer who can call the function with or without a 'password'.
# Hence, we treat an empty password here, as if no 'password' was passed.
password = get_password('Enter a password for an encrypted RSA'
' file \'' + Fore.RED + filepath + Fore.RESET + '\': ',
Copy link

Choose a reason for hiding this comment

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

What's the reason you chose single quotes for these literals instead of using double quotes such as in " file '" + ... vs. 'file \''?

Choose a reason for hiding this comment

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

This addition is an artifact of code duplication, which seems out of scope for this pull request.

# If the JSON could not be decoded, it is very likely, but not necessarily,
# due to a non-empty password.
except securesystemslib.exceptions.Error:
raise securesystemslib.exceptions\
Copy link

Choose a reason for hiding this comment

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

How come you broke the line before the "." instead of after like in previous statements?

Choose a reason for hiding this comment

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

This addition is an artifact of code duplication, which seems out of scope for this pull request.


signature = None

# An if-clause is not strictly needed here, since 'spx' is the only
Copy link

Choose a reason for hiding this comment

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

Since we are bothering to handle the error with an else: clause, wouldn't you agree that the if check actually does matter? Maybe the comment could be reworded to reflect this if so.

Choose a reason for hiding this comment

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

This addition is an artifact of code duplication, which seems out of scope for this pull request.

@JustinCappos
Copy link

Looks like the remaining issues are very minor code changes. @lukpueh would you kindly take a look? If it's very minor edits, please just make them and we can merge...

@lukpueh
Copy link
Member

lukpueh commented Aug 14, 2019

Continued in #169. Closing here.

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.

None yet

7 participants