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

ELY-5 - Implemented Unix SHA Crypt #5

Conversation

jpkrohling
Copy link
Contributor

This is a first refactored version of the first implementation jpkrohling/wildfly-elytron/ELY-5-UnixSHACrypt, and is not meant to be merged, as I'm mostly looking for feedback.

Things that I'd particularly like to get reviewed are:

  • Dependency on JUnit
  • Overall coding style (including javadocs)
  • Possible performance issues
  • I'm not sure I quite understood the architecture, so, would be nice to check if the code is where it's expected to be.

But of course, any kind of comment is welcomed. As I mentioned on the IRC, I found this JIRA and decided to give it a try, just for fun. I'm not sure if you already have a specific implementation in mind for this, but if not, this could be a good candidate.

private Charset charset;

/**
* Accepts a formatted string with the specifications plus the password. Examples for the specification are:
Copy link
Contributor

Choose a reason for hiding this comment

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

This implementation is not meant to accept the raw string; that is the role of CryptStringPasswordSpec. This implementation should only consist of the salt, iteration count, and hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Will remove it, and work on the Spec.

@jpkrohling
Copy link
Contributor Author

So, I'm sending another commit, just to check if this is going on the right direction. I'll add more javadoc and change a bit how the encode is organized, but I've shuffled things a bit to see if it fits better the architecture.

@jpkrohling
Copy link
Contributor Author

By the way: for the "real" PR, I'd be squashing the commits.

@dmlloyd
Copy link
Contributor

dmlloyd commented Jun 6, 2014

At this point I think it needs a rebase in order to understand the changes.

@jpkrohling
Copy link
Contributor Author

Rebased, I hope it looks better :-)

this.salt = password.getSalt();
this.iterationCount = password.getIterationCount();
this.id = password.getId();
this.encoded = password.getEncoded();
Copy link
Contributor

Choose a reason for hiding this comment

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

The "encoded" field should remain null. There should be a "byte[] hash" field instead. Also, charset encoding should not be used for hash password types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, forgot to make a note somewhere that I wasn't sure if "encoded" was what I thought it was. It seems it isn't :-) Will change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About the charset: I haven't given much thought to this, but my first intuition would be that it would be sensible to set a default charset to a common value. A byte is a byte no matter the charset, but when working on the hash for a given password, it might make a difference. I haven't tested, but wouldn't it cause problems when a password is hashed on one machine with ISO-8859-5, and read/verified on a machine whose default charset is UTF-8?

Copy link
Contributor

Choose a reason for hiding this comment

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

This password class should only deal with the decoded material. Since it only deals in bytes, the encoded field should be null, as should the reported charset/encoding.

When we do the CryptStringPasswordSpec handling, after all the various crypt types have been implemented, that will be a different story. The key material will be a string (like what you'd find in a /etc/shadow file or similar) and will be translatable to/from various algorithms' "raw" form.

@jpkrohling
Copy link
Contributor Author

Take 3 is ready for review. As seen on the SCRAM example, I'm throwing the InvalidKeySpec when facing exceptions at the PasswordFactorySpiImpl level.

@jpkrohling
Copy link
Contributor Author

Any further feedback on this one?

@@ -48,6 +69,20 @@ protected Password engineGeneratePassword(final String algorithm, final KeySpec
return abstractPassword.getKeySpec(keySpecType);
}
}

switch (algorithm) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This bit shouldn't be required. If UnixSHACryptPassword extends AbstractPasswordImpl (as it should), then the method to convert it to a key spec should be right on that class.

@jpkrohling
Copy link
Contributor Author

I've sent a few more commits, that should be addressing the comments. The only think I didn't work on yet is on converting the tests into a higher level usage of the API, as it's not very clear to me how they should be used from the outside.

@dmlloyd dmlloyd mentioned this pull request Jul 11, 2014
@dmlloyd
Copy link
Contributor

dmlloyd commented Jul 11, 2014

This PR should be closed if #10 is merged, because that PR incorporates this one.

@darranl
Copy link
Contributor

darranl commented Jul 15, 2014

Being merged under #10

Thank you very much for the work on this.

@darranl darranl closed this Jul 15, 2014
darranl added a commit to darranl-archive/2020-wildfly-elytron that referenced this pull request Dec 11, 2018
[ELY-1711] Create new `wildfly-elytron-sasl-digest` module
darranl pushed a commit to darranl-archive/2020-wildfly-elytron that referenced this pull request Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants