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