…lines 1–9 unchanged (9 lines)
10
11
12#define NGX_SSL_CACHE_PATH 0
13#define NGX_SSL_CACHE_DATA 1
14#define NGX_SSL_CACHE_ENGINE 2
15
16#define NGX_SSL_CACHE_DISABLED (ngx_array_t *) (uintptr_t) -1
17
18
19#define ngx_ssl_cache_get_conf(cycle) \
20 (ngx_ssl_cache_t *) ngx_get_conf(cycle->conf_ctx, ngx_openssl_cache_module)
21
22#define ngx_ssl_cache_get_old_conf(cycle) \
…lines 23–59 unchanged (37 lines)
60 ngx_rbtree_node_t sentinel;
61
62 ngx_flag_t inheritable;
63} ngx_ssl_cache_t;
64
65
66typedef struct {
67 ngx_str_t *pwd;
68 unsigned encrypted:1;
69} ngx_ssl_cache_pwd_t;
70
71
72static ngx_int_t ngx_ssl_cache_init_key(ngx_pool_t *pool, ngx_uint_t index,
73 ngx_str_t *path, ngx_ssl_cache_key_t *id);
74static ngx_ssl_cache_node_t *ngx_ssl_cache_lookup(ngx_ssl_cache_t *cache,
75 ngx_ssl_cache_type_t *type, ngx_ssl_cache_key_t *id, uint32_t hash);
…lines 76–232 unchanged (157 lines)
233 break;
234 }
235 }
236 }
237
238 if (value == NULL) {
239 value = type->create(&id, err, &data);
240
241 if (value == NULL || data == NGX_SSL_CACHE_DISABLED) {
242 return value;
243 }
244 }
245
246 cn = ngx_palloc(cf->pool, sizeof(ngx_ssl_cache_node_t) + id.len + 1);
247 if (cn == NULL) {
248 type->free(value);
…lines 249–274 unchanged (26 lines)
275 *err = NULL;
276
277 if (ngx_ssl_cache_init_key(pool, index, path, &id) != NGX_OK) {
278 return NULL;
279 }
280
281 return ngx_ssl_cache_types[index].create(&id, err, &data);
282}
283
284
285static ngx_int_t
286ngx_ssl_cache_init_key(ngx_pool_t *pool, ngx_uint_t index, ngx_str_t *path,
287 ngx_ssl_cache_key_t *id)
…lines 288–477 unchanged (190 lines)
478}
479
480
481static void *
482ngx_ssl_cache_pkey_create(ngx_ssl_cache_key_t *id, char **err, void *data)
483{
484 ngx_array_t **passwords = data;
485
486 BIO *bio;
487 EVP_PKEY *pkey;
488 ngx_uint_t tries;
489 pem_password_cb *cb;
490 ngx_ssl_cache_pwd_t cb_data, *pwd;
491
492 if (id->type == NGX_SSL_CACHE_ENGINE) {
493
494#ifndef OPENSSL_NO_ENGINE
495
496 u_char *p, *last;
…lines 497–536 unchanged (40 lines)
537
538 bio = ngx_ssl_cache_create_bio(id, err);
539 if (bio == NULL) {
540 return NULL;
541 }
542
543 cb_data.encrypted = 0;
544
545 if (*passwords) {
546 cb_data.pwd = (*passwords)->elts;
547 tries = (*passwords)->nelts;
548 pwd = &cb_data;
549 cb = ngx_ssl_cache_pkey_password_callback;
550
551 } else {
552 cb_data.pwd = NULL;
553 tries = 1;
554 pwd = NULL;
555 cb = NULL;
556 }
557
558 for ( ;; ) {
559
560 pkey = PEM_read_bio_PrivateKey(bio, NULL, cb, pwd);
561 if (pkey != NULL) {
562 break;
563 }
564
565 if (tries-- > 1) {
566 ERR_clear_error();
567 (void) BIO_reset(bio);
568 cb_data.pwd++;
569 continue;
570 }
571
572 *err = "PEM_read_bio_PrivateKey() failed";
573 BIO_free(bio);
574 return NULL;
575 }
576
577 if (cb_data.encrypted) {
578 *passwords = NGX_SSL_CACHE_DISABLED;
579 }
580
581 BIO_free(bio);
582
583 return pkey;
584}
585
586
587static int
588ngx_ssl_cache_pkey_password_callback(char *buf, int size, int rwflag,
589 void *userdata)
590{
591 ngx_ssl_cache_pwd_t *data = userdata;
592
593 ngx_str_t *pwd;
594
595 if (rwflag) {
596 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
597 "ngx_ssl_cache_pkey_password_callback() is called "
598 "for encryption");
599 return 0;
600 }
601
602 data->encrypted = 1;
603
604 pwd = data->pwd;
605
606 if (pwd == NULL) {
607 return 0;
608 }
609
610 if (pwd->len > (size_t) size) {
…lines 611–925 unchanged (315 lines)