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

SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 #356

Merged
merged 7 commits into from
Aug 7, 2017

Conversation

Alameyo
Copy link
Member

@Alameyo Alameyo commented Jul 24, 2017

Generally trust managers, checking CRL and some minor things. Still TO-DO: accepting self signed certificates, make use of blacklist keystore and do OCSP.

@Alameyo Alameyo requested a review from guusdk July 24, 2017 17:46
@akrherz
Copy link
Member

akrherz commented Jul 24, 2017

@Alameyo It would be good for your commit message to actually have the SPARK-???? nomenclature for each issue so that the Jira auto-linking works / this commit gets associated with the proper Jira issue.

@Alameyo Alameyo changed the title SPARK-1966, 1952, 1969, 1970, 1971 and partially 1968 SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 Jul 24, 2017
@Alameyo
Copy link
Member Author

Alameyo commented Jul 24, 2017

@akrherz Ok, title was generated from commit comment and I forgot to add SPARK

@Alameyo Alameyo changed the title SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 SPARK-1960, SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 Jul 24, 2017
@Alameyo Alameyo force-pushed the SSLContext branch 7 times, most recently from 81e4228 to 81ba4c9 Compare July 27, 2017 13:12
@Alameyo Alameyo changed the title SPARK-1960, SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 SPARK-1966, SPARK-1952, SPARK-1969, SPARK-1970, SPARK-1971 and partially SPARK-1968 Jul 27, 2017
@Alameyo
Copy link
Member Author

Alameyo commented Jul 27, 2017

Now also SPARK-1975 as Self Signed certificates can be accepted.

@guusdk
Copy link
Member

guusdk commented Jul 27, 2017

That last commit did not have SPARK-1975 in it either. :)

You can (and should!) rewrite those commit messages. There are a couple of options, see: https://help.github.com/articles/changing-a-commit-message/


// check if certificate isn't self signed, self signed certificate still have to be in TrustStore to be
// accepted
if (chain.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Chain length is not a safe way to determine if the certificate in the chain is self-signed. The chain could be incomplete (it might depend on certificates that are in the truststore, without including those certificates), and chains might contain certificates that are not part of the chain at all (and are unused). You should find a better way to identify "self-signed"

@Alameyo
Copy link
Member Author

Alameyo commented Jul 29, 2017

Added support for SPARK-1977 OCSP.

* Return true if the certificate chain contain only one Self Signed certificate
*/
private boolean isSelfSigned(X509Certificate[] chain) {
if(chain[0].getIssuerX500Principal().getName().equals(chain[0].getSubjectX500Principal().getName())){
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps replace by: return chain[0].getIssuerX500Principal().getName().equals(chain[0].getSubjectX500Principal().getName()) (there's no need for the if/else)?

@@ -187,6 +188,17 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
}

/**
* Return true if the certificate chain contain only one Self Signed certificate
*/
private boolean isSelfSigned(X509Certificate[] chain) {
Copy link
Member

Choose a reason for hiding this comment

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

This code assumes that the first certificate is the self-signed one, which could lead to several problems. For example, a certificate chain should, but is not always ordered (and if it is, I think it's typically the last certificate that's self-signed).

Perhaps you should consider changing the argument to this method: instead of passing a chain, you might want to pass a single certificate. That way, this method's responsibility is very well defined. If needed, you could add additional methods that check if the entire chain represents a self-signed certificate (by checking if the chain size is equal to 1, and by passing that certificate to this method).

Copy link
Member Author

Choose a reason for hiding this comment

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

I added check if chain length equals 1. If it is true together as well as same subject issuer requirement then certificate is self signed. This way in case when chain would be reversed there will be no problems about that.
One note: I don't worry here about standard root CA at the end of certificate path but about situation when server send only one self signed certificate for it's identification. If chain is longer than 1 then it is standard path building.

PKIXRevocationChecker checker = (PKIXRevocationChecker) certPathBuilder.getRevocationChecker();
// soft fail option mean that OCSP or CRL must pass validation, in case when OCSP cannot be
// validated it will validate CRL and then if both cannot be checked it will fail
checker.setOptions(EnumSet.of(PKIXRevocationChecker.Option.SOFT_FAIL));
Copy link
Member

Choose a reason for hiding this comment

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

Should this be configurable? Perhaps the end-user should control if SOFT_FAIL should apply.



if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
builder.setPort(5222);
Copy link
Member

Choose a reason for hiding this comment

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

Does this take into account that the user can also set another port than 5222? If that's done, we should not hard-code to 5222.

Copy link
Member Author

@Alameyo Alameyo Aug 4, 2017

Choose a reason for hiding this comment

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

Changed. I digged into that a bit more and while 5222 is recommended because other ports might be blocked by firewalls, there is no general prohibition against using other ports. Though so far I cannot connect without using "automatically discover host and port".

@@ -277,6 +284,22 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
builder.setProxyInfo( proxyInfo );
}

if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
Copy link
Member

Choose a reason for hiding this comment

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

(same as before - can you get rid of this code duplication?) Does this take into account that the user can also set another port than 5222? If that's done, we should not hard-code to 5222.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed this two classes share a bunch of the similar code, tomorrow I will try to reduce some of its redundancy.

ResourceUtils.resButton(acceptSelfSigned, Res.getString("checkbox.accept.self.signed"));
ResourceUtils.resButton(checkCRL, Res.getString("checkbox.check.crl"));
ResourceUtils.resButton(checkOCSP, Res.getString("checkbox.check.ocsp"));
ResourceUtils.resButton(showCert, Res.getString("button.show.certificate"));
ResourceUtils.resButton(fileButton, Res.getString("label.choose.file"));


Copy link
Member

Choose a reason for hiding this comment

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

Small bug: when I open the "certificates" tab and the "accept all" option is already checked, then the others are not disabled. It works when I unselect and reselect again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@Alameyo Alameyo force-pushed the SSLContext branch 2 times, most recently from c6edac8 to 034cb63 Compare August 5, 2017 18:52
Added setUp method to SPARKSSLContext, removed acceptAll from Security
tab as there is already Accept All checkbox in certificates tab.
@guusdk guusdk merged commit 29f89bd into igniterealtime:master Aug 7, 2017
@Alameyo Alameyo deleted the SSLContext branch December 9, 2018 21:37
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.

3 participants