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