Skip to content

Allow to set CA list for SSLContext via BIO - #211

Closed
normanmaurer wants to merge 1 commit into
1.1.33from
trusted_ca
Closed

normanmaurer wants to merge 1 commit into
1.1.33from
trusted_ca

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

To correct announce CA list we need to allow setting it via a BIO so we can hook it up with the X509TrustManager.
This is needed to fix netty/netty#6141 .

Modifications:

Add new SSLContext.setCACertifcateBio(...) method

Result:

Be able to set the to be announced CA list.

Comment thread openssl-dynamic/src/main/c/sslcontext.c Outdated
return rv;
}

TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCACertificateBio)(TCN_STDARGS,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesn't look like the return value is used ... should we just make this method void and throw if something goes wrong?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think we should return jboolean and use it :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

jboolean sgtm

Comment thread openssl-dynamic/src/main/c/sslcontext.c Outdated
TCN_ASSERT(ctx != 0);

if (b == NULL) {
return JNI_FALSE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we want to keep this method as boolean then we could change to this:

return b != NULL && c->mode != SSL_MODE_CLIENT && SSL_CTX_use_client_CA_bio(c->ctx, b) > 0 ? JNI_TRUE : JNI_FALSE;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1

Comment thread openssl-dynamic/src/main/c/sslutils.c Outdated
if (SSL_CTX_add_extra_chain_cert(ctx, x509) != 1) {
X509_free(x509);
return -1;
if (ca == 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make this data type jboolean and/or treat it as a boolean if (ca) { .. }?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1

Comment thread openssl-dynamic/src/main/c/sslutils.c Outdated
}

int SSL_CTX_use_certificate_chain_bio(SSL_CTX *ctx, BIO *bio,
int skipfirst)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

move this argument to the previous line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1

* <br>
* @param ctx Server context to use.
* @param certBio Directory of PEM-encoded CA Certificates for Client Auth.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make this void or add a @returns describing the return value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1

Comment thread openssl-dynamic/src/main/c/sslcontext.c Outdated
BIO *b = J2P(certs, BIO *);

UNREFERENCED(o);
TCN_ASSERT(ctx != 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ctx != 0 -> c != NULL

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure we can do... just made it consistent with the rest of the methods .

Comment thread openssl-dynamic/src/main/c/sslutils.c Outdated

int SSL_CTX_use_certificate_chain_bio(SSL_CTX *ctx, BIO *bio,
int skipfirst)
static int SSL_CTX_setup_certs(SSL_CTX *ctx, BIO *bio, int skipfirst, int ca)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what c standard do we target, c99? If so consider using #include <stdbool.h> and bool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good question. I just used what we used in other methods. So keep it for now as it is ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer to be explicit about types when possible in typed languages. If its an int then compare it to an explicit value, if its a bool then use it like a boolean. For example below we use the int like a boolean and there is nothing that describes this assumption ... making it a bool removes the ambiguity.

@normanmaurer normanmaurer Dec 21, 2016 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Scottmitch I think I would like to keep it as it is and cleanup all the methods in a followup PR as this should be done for all the methods in all classes where we use an int as bool. Ok ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@normanmaurer - Do you have other examples where we do this? As long as we clean it up that is fine with me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually its the same method or methods that call it... skipfirst is also just a boolean.

Motivation:

To correct announce CA list we need to allow setting it via a BIO so we can hook it up with the X509TrustManager.
This is needed to fix netty/netty#6141 .

Modifications:

Add new SSLContext.setCACertifcateBio(...) method

Result:

Be able to set the to be announced CA list.

@Scottmitch Scottmitch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yay stdbool !

@normanmaurer

Copy link
Copy Markdown
Member Author

Cherry-picked into 1.1.33 (9d9a37c) and master (cbd38f3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants