- /* Get our certificates in order.
- * First, create the key/cert directory if it's not there already...
- */
- mkdir(ctdl_key_dir, 0700);
-
- /*
- * Generate a key pair if we don't have one.
- */
- if (access(file_crpt_file_key, R_OK) != 0) {
- syslog(LOG_INFO, "Generating RSA key pair.");
- rsa = RSA_generate_key(1024, /* modulus size */
- 65537, /* exponent */
- NULL, /* no callback */
- NULL); /* no callback */
- if (rsa == NULL) {
- syslog(LOG_ERR, "Key generation failed: %s", ERR_reason_error_string(ERR_get_error()));
- }
- if (rsa != NULL) {
- fp = fopen(file_crpt_file_key, "w");
- if (fp != NULL) {
- chmod(file_crpt_file_key, 0600);
- if (PEM_write_RSAPrivateKey(fp, /* the file */
- rsa, /* the key */
- NULL, /* no enc */
- NULL, /* no passphr */
- 0, /* no passphr */
- NULL, /* no callbk */
- NULL /* no callbk */
- ) != 1) {
- syslog(LOG_ERR, "Cannot write key: %s", ERR_reason_error_string(ERR_get_error()));
- unlink(file_crpt_file_key);
- }
- fclose(fp);
- }
- RSA_free(rsa);
- }
- }
+ mkdir(ctdl_key_dir, 0700); // If the keys directory does not exist, create it
+ generate_key(file_crpt_file_key); // If a private key does not exist, create it