[crypto,key] add function to export PEM and create a key

* freerdp_key_generate creates a new key
* freerdp_key_get_pem exports the key as PEM
This commit is contained in:
akallabeth
2025-04-22 10:56:13 +02:00
parent 0eefdbdb40
commit 2fb2e5f9c5
10 changed files with 192 additions and 19 deletions

View File

@@ -35,16 +35,62 @@ extern "C"
WINPR_ATTR_MALLOC(freerdp_key_free, 1)
FREERDP_API rdpPrivateKey* freerdp_key_new(void);
WINPR_ATTR_MALLOC(freerdp_key_free, 1)
FREERDP_API rdpPrivateKey* freerdp_key_new_from_file(const char* keyfile);
WINPR_DEPRECATED_VAR(
"[since 3.16.0] use freerdp_key_new_from_file_enc",
WINPR_ATTR_MALLOC(freerdp_key_free, 1)
FREERDP_API rdpPrivateKey* freerdp_key_new_from_file(const char* keyfile));
WINPR_DEPRECATED_VAR("[since 3.16.0] use freerdp_key_new_from_pem_enc",
WINPR_ATTR_MALLOC(freerdp_key_free, 1)
FREERDP_API rdpPrivateKey* freerdp_key_new_from_pem(const char* pem));
/** @brief Create a private key from file \b keyfile with optional password \b password
*
* @param keyfile The file to read the key from
* @param password The optional password the key is enecrypted with, \b NULL for unencrypted
* @return An allocated private key, \b NULL in case of failure.
* @since version 3.16.0
*/
FREERDP_API rdpPrivateKey* freerdp_key_new_from_file_enc(const char* keyfile,
const char* password);
/** @brief Create a private key from a PEM file with optional \b password
*
* @param pem The PEM string to use
* @param password The optional password, use \b NULL if no encryption is used.
* @return An allocated private key, \b NULL in case of failure.
* @since version 3.16.0
*/
WINPR_ATTR_MALLOC(freerdp_key_free, 1)
FREERDP_API rdpPrivateKey* freerdp_key_new_from_pem(const char* pem);
FREERDP_API rdpPrivateKey* freerdp_key_new_from_pem_enc(const char* pem, const char* password);
FREERDP_API BOOL freerdp_key_is_rsa(const rdpPrivateKey* key);
FREERDP_API size_t freerdp_key_get_bits(const rdpPrivateKey* key);
/** @brief Create a PEM from a private key
*
* @param key The key to convert
* @param plen Optional pointer, value set to strlen of the PEM
* @param password Optional password string. If \b NULL an unencrypted PEM is written.
* @return A PEM string or \b NULL in case of errors
*
* @since version 3.16.0
*/
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_key_get_pem(const rdpPrivateKey* key, size_t* plen,
const char* password);
/** @brief Create a new private key
*
* @param key The key to initialize
* @param type The key type (RSA, ...)
* @param count The number of arguments following, depends on type
* @return \b TRUE for success, \b FALSE otherwise
* @since version 3.16.0
*/
FREERDP_API BOOL freerdp_key_generate(rdpPrivateKey* key, const char* type, size_t count, ...);
#ifdef __cplusplus
}
#endif