Maxim Dounin
August 01, 2014 01:00PM
Hello!

On Fri, Aug 01, 2014 at 09:20:02AM +0400, Dmitrii Pichulin wrote:

> On 31.07.2014 17:49, Maxim Dounin wrote:
> >> + if (engine == NULL) {
> >> + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
> >> + "ENGINE_by_id(\"%s\") failed", p);
> >> + return NGX_ERROR;
> >> + }
> >> +
> >> + p[last - p] = ':';
> >> +
> >> + if (passwords) {
> >> + pwd = passwords->elts;
> >> +
> >> + ngx_cpystrn(pwd_buf, pwd->data, pwd->len + 1);
> >> +
> >> + pwd_data.password = pwd_buf;
> >> + } else {
> >> + pwd_data.password = NULL;
> >> + }
> >> + pwd_data.prompt_info = NULL;
> >> +
> >> + last++;
> >> +
> >> + private_key = ENGINE_load_private_key(engine, last, 0,
> >> + (void *) &pwd_data);
> > I don't see how it's expected to work. You only pass private data
> > for UI callbacks, but not callbacks itself.
> >
> > Anyway, proper implementation of passing key passwords into an engine
> > seems to be rather big, and as per my reading of the code under
> > crypto/engine won't work with most of the engines anyway. It
> > might be better idea to don't try to do this for now.
>
> Maxim, our vision is based on 2 implementations of engines as previously
> noted:
> 1) gost_capi — doesn't support external passwords
> 2) opensc — with such code from get_pin function
> (https://github.com/OpenSC/engine_pkcs11/blob/master/src/engine_pkcs11.c):
>
> /* either get the pin code from the supplied callback data, or get the pin
> * via asking our self. In both cases keep a copy of the pin code in the
> * pin variable (strdup'ed copy). */
> static int get_pin(UI_METHOD * ui_method, void *callback_data)
> {
> UI *ui;
> struct {
> const void *password;
> const char *prompt_info;
> } *mycb = callback_data;
>
> /* pin in the call back data, copy and use */
> if (mycb != NULL && mycb->password) {
> pin = (char *)calloc(MAX_PIN_LENGTH, sizeof(char));
> if (!pin)
> return 0;
> strncpy(pin,mycb->password,MAX_PIN_LENGTH);
> pin_length = MAX_PIN_LENGTH;
> return 1;
> }
> ...
>
> As you can see, there's no need for ui_method if a password is present.

The code in the get_pin() function provided looks utterly wrong -
it tries to access private data of UI_METHOD, assuming some
structure. This may work if stucture match (it seems to be
copied from PW_CB_DATA used by openssl apps, see apps/apps.[ch]),
but will result in segmentation fault if it doesn't.

Proper engine behaviour would be to use provided UI_METHOD's
callbacks to ask for a password, using the
UI_INPUT_FLAG_DEFAULT_PWD flag, see engines/e_chil.c for an
example. This seems to be understood at least by openssl itself
and curl, see here:

http://curl.haxx.se/mail/lib-2013-08/0265.html

> We suggest to implement something like this:
>
> typedef struct {
> const void *password;
> const char *prompt_info;
> ngx_array_t *passwords;
> ngx_uint_t position;
> } ngx_openssl_pw_cb_data_ex;
>
> In this case, our ui_read implementation can run through all passwords,
> while supporting the basics.

There is no need to provide complex structure as there should be a
loop to call ENGINE_load_private_keyi() multiple times anyway.

> Or it would be better to pass nothing for now?

Given the fact how crappy underlying code in engines is, I
seriously doubt it worth supporting. Better to don't try for now.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 2771 July 22, 2014 07:16AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 1197 July 22, 2014 10:54AM

[PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 900 July 23, 2014 10:56AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 835 July 27, 2014 10:44PM

[PATCH 0 of 1 ] Questions about ENGINE_load_private_key

Dmitrii Pichulin 1067 July 29, 2014 11:12AM

[PATCH 1 of 1] allow to use engine keyform for server private key

Dmitrii Pichulin 804 July 29, 2014 11:12AM

Re: [PATCH 1 of 1] allow to use engine keyform for server private key

Maxim Dounin 737 July 29, 2014 11:42AM

[PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 781 July 30, 2014 11:30AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 906 July 31, 2014 09:50AM

Re: [PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 657 August 01, 2014 01:22AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 907 August 01, 2014 01:00PM

[PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 1037 August 04, 2014 03:08AM

Re: [PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 770 August 11, 2014 12:38AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 787 August 11, 2014 08:44PM

Re: [PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 4337 October 29, 2014 10:48AM

Re: [PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 739 November 21, 2014 12:22AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 924 November 21, 2014 08:10AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 985 December 03, 2014 04:26PM

Re: [PATCH] allow to use engine keyform for server private key

Dmitrii Pichulin 741 December 04, 2014 05:58AM

Re: [PATCH] allow to use engine keyform for server private key

Maxim Dounin 1073 December 04, 2014 09:42AM

Re: [PATCH 0 of 1 ] Questions about ENGINE_load_private_key

Maxim Dounin 1114 July 29, 2014 11:34AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 285
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready