Skip to content

Conversation

@ansasaki
Copy link
Owner

@ansasaki ansasaki commented Feb 9, 2018

It is necessary to call ENGINE_init() before using a
OpenSSL engine to get the engine functional reference.

Copy link

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

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

I put several comments to the code. The changes look good to me according to OpenSSL documentation.

There might be some slight differences between OpenSSL 1.1.0 and 1.0.2. Did you test with both of the versions? Are both of them supported by nginx?

}

ENGINE_free(engine);
if (!ENGINE_set_default(engine, ENGINE_METHOD_ALL)) {
Copy link

Choose a reason for hiding this comment

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

Do we need ENGINE_METHOD_ALL here? Would not be ENGINE_METHOD_PKEY_METHS enough? Or the it does not matter in this use case?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, probably setting ENGINE_METHOD_PKEY_METHS would be sufficient in this case. Unless libp11 include support to do other operations, like digests, in the hardware, what is unlikely. I'll test again and change if sufficient.

if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) {
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
"SSL_CTX_use_PrivateKey(\"%s\") failed", last);
"SSL_CTX_use_PrivateKey(ssl->ctx, pkey) failed");
Copy link

Choose a reason for hiding this comment

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

I am not sure if this is unrelated fix of copy&paste error or attempt to show messages closer to the reality. But in case there are more engines/keys being loaded, you will not be able to distinguish between the errors so I would be for leaving some identification here, even if it would not have the same arguments as the function that failed.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I did this intentionally. It is true that it does give less information, but is the explicit call made in the code. I kept the same style from the other error messages.
Putting this aside, I agree with you, the error messages should give more information, if possible.

if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) {
ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
"ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) failed",
&value[1]);
Copy link

Choose a reason for hiding this comment

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

Here, the error is reported in different way than you added in the above case. Here we print &value[1] as &V, which says us which engine failed to initialize/set_default, which might be very helpful for debugging. I would consider using the same also in the other errors.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, I agree. As I commented before, the error messages should give as more information as possible. In this case the author of this part "made a mistake" not following the style of the error messages. I can follow this and "do the mistake" too and make the error messages more informative (but out of the coding style).

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, I went through the code and it seems that the error messaging do not follow a strict rule. I think I can improve the messages in the parts I modified.

@ansasaki
Copy link
Owner Author

ansasaki commented Feb 9, 2018

I forgot to mention, but I tested with OpenSSL 1.1.0 in fedora and 1.0.2 in ubuntu. I'll try the other combinations (1.0.2 in fedora and 1.1.0 in ubuntu).

It is necessary to call ENGINE_init() before using a OpenSSL engine
to get the engine functional reference.
The previous error messages didn't specify the parameters used when
the functions failed. This uses more descriptive error messages.
This replaces the registration of the engine to be the default engine
using ENGINE_METHOD_PKEY_METHS instead of ENGINE_METHOD_ALL.
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