ignatenkobrain / rpms / nginx

Forked from rpms/nginx 2 years ago
Clone
8f9dab
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
8f9dab
index 0a2f260..606b6e2 100644
8f9dab
--- a/src/event/ngx_event_openssl.c
8f9dab
+++ b/src/event/ngx_event_openssl.c
8f9dab
@@ -616,6 +616,71 @@ ngx_ssl_load_certificate(ngx_pool_t *pool, char **err, ngx_str_t *cert,
8f9dab
     X509    *x509, *temp;
8f9dab
     u_long   n;
8f9dab
 
8f9dab
+    if (ngx_strncmp(cert->data, "engine:", sizeof("engine:") - 1) == 0) {
8f9dab
+
8f9dab
+#ifndef OPENSSL_NO_ENGINE
8f9dab
+
8f9dab
+        u_char  *p, *last;
8f9dab
+        ENGINE  *engine;
8f9dab
+
8f9dab
+        p = cert->data + sizeof("engine:") - 1;
8f9dab
+        last = (u_char *) ngx_strchr(p, ':');
8f9dab
+
8f9dab
+        if (last == NULL) {
8f9dab
+            *err = "invalid syntax";
8f9dab
+            return NULL;
8f9dab
+        }
8f9dab
+
8f9dab
+        *last = '\0';
8f9dab
+
8f9dab
+        engine = ENGINE_by_id((char *) p);
8f9dab
+
8f9dab
+        if (engine == NULL) {
8f9dab
+            *err = "ENGINE_by_id() failed";
8f9dab
+            return NULL;
8f9dab
+        }
8f9dab
+
8f9dab
+        if (!ENGINE_init(engine)) {
8f9dab
+            *err = "ENGINE_init() failed";
8f9dab
+            ENGINE_free(engine);
8f9dab
+            return NULL;
8f9dab
+        }
8f9dab
+
8f9dab
+        *last++ = ':';
8f9dab
+
8f9dab
+        struct {
8f9dab
+            const char *cert_id;
8f9dab
+            X509 *cert;
8f9dab
+        } params = { (char *) last, NULL };
8f9dab
+
8f9dab
+        if (!ENGINE_ctrl_cmd(engine, "LOAD_CERT_CTRL", 0, &params, NULL, 1)) {
8f9dab
+            *err = "ENGINE_ctrl_cmd() failed - Unable to get the certificate";
8f9dab
+            ENGINE_free(engine);
8f9dab
+            return NULL;
8f9dab
+        }
8f9dab
+
8f9dab
+        ENGINE_finish(engine);
8f9dab
+        ENGINE_free(engine);
8f9dab
+
8f9dab
+        /* set chain to null */
8f9dab
+
8f9dab
+        *chain = sk_X509_new_null();
8f9dab
+        if (*chain == NULL) {
8f9dab
+           *err = "sk_X509_new_null() failed";
8f9dab
+           X509_free(params.cert);
8f9dab
+           return NULL;
8f9dab
+        }
8f9dab
+
8f9dab
+        return params.cert;
8f9dab
+
8f9dab
+#else
8f9dab
+
8f9dab
+        *err = "loading \"engine:...\" certificate is not supported";
8f9dab
+        return NULL;
8f9dab
+
8f9dab
+#endif
8f9dab
+    }
8f9dab
+
8f9dab
     if (ngx_strncmp(cert->data, "data:", sizeof("data:") - 1) == 0) {
8f9dab
 
8f9dab
         bio = BIO_new_mem_buf(cert->data + sizeof("data:") - 1,