diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c b/src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c
index bb9cc7a..5c4b6ff 100644
--- a/src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c
+++ b/src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c
@@ -581,9 +581,10 @@ static public_key_t* find_pubkey_in_certs(private_pkcs11_private_key_t *this,
 	CK_CERTIFICATE_TYPE type = CKC_X_509;
 	CK_ATTRIBUTE tmpl[] = {
 		{CKA_CLASS, &class, sizeof(class)},
-		{CKA_CERTIFICATE_TYPE, &type, sizeof(type)},
 		{CKA_ID, keyid.ptr, keyid.len},
+		{CKA_CERTIFICATE_TYPE, &type, sizeof(type)},
 	};
+    int     tmpl_len = countof(tmpl) ;
 	CK_OBJECT_HANDLE object;
 	CK_ATTRIBUTE attr[] = {
 		{CKA_VALUE, NULL, 0},
@@ -592,9 +593,14 @@ static public_key_t* find_pubkey_in_certs(private_pkcs11_private_key_t *this,
 	chunk_t data = chunk_empty;
 	public_key_t *key = NULL;
 	certificate_t *cert;
-
+    
+	if (!lib->settings->get_bool(lib->settings,
+					"libstrongswan.plugins.pkcs11.modules.%s.require_x509",
+					TRUE, this->lib->get_name(this->lib)))
+        tmpl_len-- ;
+    
 	enumerator = this->lib->create_object_enumerator(this->lib, this->session,
-									tmpl, countof(tmpl), attr, countof(attr));
+									tmpl, tmpl_len, attr, countof(attr));
 	if (enumerator->enumerate(enumerator, &object))
 	{
 		data = chunk_clone(chunk_create(attr[0].pValue, attr[0].ulValueLen));
@@ -721,7 +727,17 @@ pkcs11_private_key_t *pkcs11_private_key_connect(key_type_t type, va_list args)
 		return NULL;
 	}
 
-	this->pubkey = pkcs11_public_key_connect(this->lib, slot, this->type, keyid);
+	if (lib->settings->get_bool(lib->settings,
+					"libstrongswan.plugins.pkcs11.modules.%s.use_x509",
+					FALSE, this->lib->get_name(this->lib)))
+    {
+        this->pubkey = NULL ; 
+    }    
+    else
+    {
+        this->pubkey = pkcs11_public_key_connect(this->lib, slot, this->type, keyid);
+    }
+    
 	if (!this->pubkey)
 	{
 		this->pubkey = find_pubkey_in_certs(this, keyid);
