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