summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2008-08-01 14:07:15 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2008-08-01 14:07:15 +0000
commit23fc1c54f1ebcc170a747268f03bb591f0d22b88 (patch)
tree705ad703bc527c980cdf6f26cfb35a0ff42ae31a
parent934228a3c75afe441bc1de7db87fd4c5e700b24f (diff)
add function to load a public key from anything
-rw-r--r--lasso/xml/private.h4
-rw-r--r--lasso/xml/tools.c46
2 files changed, 49 insertions, 1 deletions
diff --git a/lasso/xml/private.h b/lasso/xml/private.h
index 7b47de44..86ccc826 100644
--- a/lasso/xml/private.h
+++ b/lasso/xml/private.h
@@ -103,7 +103,9 @@ char* lasso_build_unique_id(unsigned int size);
char* lasso_get_current_time(void);
LassoPemFileType lasso_get_pem_file_type(const char *file);
-xmlSecKey* lasso_get_public_key_from_pem_cert_file(const char *file);
+xmlSecKeyPtr lasso_get_publick_key_from_pem_file(const char *file);
+xmlSecKeyPtr lasso_load_private_key_file(const char *file);
+xmlSecKeyPtr lasso_get_public_key_from_pem_cert_file(const char *file);
xmlSecKeysMngr* lasso_load_certs_from_pem_certs_chain_file (const char *file);
char* lasso_query_sign(char *query, LassoSignatureMethod sign_method, const char *private_key_file);
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index 1c300f98..f94f7b5a 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -179,6 +179,37 @@ lasso_get_pem_file_type(const char *pem_file)
}
/**
+ * lasso_get_public_key_from_pem_file:
+ * @file: the name of a file containing a public key
+ *
+ * Load a public key from a file in the PEM format.
+ *
+ * Returns: a #xmlSecKey if one is found, NULL otherwise.
+ */
+xmlSecKeyPtr lasso_get_public_key_from_pem_file(const char *file) {
+ LassoPemFileType file_type;
+ xmlSecKeyPtr pub_key = NULL;
+
+ file_type = lasso_get_pem_file_type(file);
+ switch (file_type) {
+ case LASSO_PEM_FILE_TYPE_UNKNOWN:
+ message(G_LOG_LEVEL_WARNING, "PEM file type unknown: %s", file);
+ break; /* with a warning ? */
+ case LASSO_PEM_FILE_TYPE_CERT:
+ pub_key = lasso_get_public_key_from_pem_cert_file(file);
+ break;
+ case LASSO_PEM_FILE_TYPE_PUB_KEY:
+ pub_key = xmlSecCryptoAppKeyLoad(file,
+ xmlSecKeyDataFormatPem, NULL, NULL, NULL);
+ break;
+ case LASSO_PEM_FILE_TYPE_PRIVATE_KEY:
+ pub_key = lasso_load_private_key_file(file);
+
+ break; /* with a warning ? */
+ }
+ return pub_key;
+}
+/**
* lasso_get_public_key_from_pem_cert_file:
* @pem_cert_file: an X509 pem certificate file
*
@@ -227,6 +258,21 @@ lasso_get_public_key_from_pem_cert_file(const char *pem_cert_file)
}
/**
+ * lasso_get_public_key_from_private_key_file:
+ * @private_key_file: the name of a file containing a private key in PEM format
+ *
+ * Load a public key from a private key.
+ *
+ * Returns: a new $xmlSecKey containing the private key
+ */
+xmlSecKeyPtr
+lasso_get_public_key_from_private_key_file(const char *private_key_file)
+{
+ return XmlSecCryptoAppKeyLoad(private_key_file,
+ xmlSecKeyDataFormatPem, NULL, NULL, NULL);
+}
+
+/**
* lasso_load_certs_from_pem_certs_chain_file:
* @pem_certs_chain_file: a CA certificate chain file
*