Skip to content

Commit

Permalink
Add generate_ephemeral_key that allows a random ephermal key
Browse files Browse the repository at this point in the history
This is useful for features that can use enither a persistent
or an ephemeral key.

Patch V2: Move the functionality of generating a random key into a
          separate function that acts as wrapper for pem_read_key_file
Patch V4: Move wrapper functionality to caller and leave only generate
          epehermal key functionality in the new function
Acked-by: David Sommerseth <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg18527.html

Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
schwabe authored and cron2 committed Jul 5, 2019
1 parent 0d80b56 commit fb4e8ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/openvpn/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,20 @@ write_pem_key_file(const char *filename, const char *pem_name)
return;
}

bool
generate_ephemeral_key(struct buffer *key, const char *key_name)
{
msg(M_INFO, "Using random %s.", key_name);
uint8_t rand[BCAP(key)];
if (!rand_bytes(rand, BCAP(key)))
{
msg(M_WARN, "ERROR: could not generate random key");
return false;
}
buf_write(key, rand, BCAP(key));
return true;
}

bool
read_pem_key_file(struct buffer *key, const char *pem_name,
const char *key_file, const char *key_inline)
Expand Down
12 changes: 11 additions & 1 deletion src/openvpn/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,17 @@ unsigned int crypto_max_overhead(void);
* @param pem_name The name to use in the PEM header/footer.
*/
void
write_pem_key_file(const char *filename, const char *pem_name);
write_pem_key_file(const char *filename, const char *key_name);

/**
* Generate ephermal key material into the key structure
*
* @param key the key structure that will hold the key material
* @param pem_name the name used for logging
* @return true if key generation was successful
*/
bool
generate_ephemeral_key(struct buffer *key, const char *pem_name);

/**
* Read key material from a PEM encoded files into the key structure
Expand Down

0 comments on commit fb4e8ab

Please sign in to comment.