-/** \todo dirify */
-/** where to find the keys */
-#define CTDL_CRYPTO_DIR "./keys"
-#define CTDL_KEY_PATH CTDL_CRYPTO_DIR "/citadel.key" /**< the key */
-#define CTDL_CSR_PATH CTDL_CRYPTO_DIR "/citadel.csr" /**< the csr file */
-#define CTDL_CER_PATH CTDL_CRYPTO_DIR "/citadel.cer" /**< the cer file */
-#define SIGN_DAYS 365 /**< how long our certificate should live */
-
-SSL_CTX *ssl_ctx; /**< SSL context */
-pthread_mutex_t **SSLCritters; /**< Things needing locking */
-
-pthread_key_t ThreadSSL; /**< Per-thread SSL context */
-
-/**
- * \brief what?????
- * \return thread id???
- */
-static unsigned long id_callback(void)
-{
- return (unsigned long) pthread_self();
+
+/* where to find the keys */
+#define CTDL_CRYPTO_DIR ctdl_key_dir
+#define CTDL_KEY_PATH file_crpt_file_key
+#define CTDL_CSR_PATH file_crpt_file_csr
+#define CTDL_CER_PATH file_crpt_file_cer
+#define SIGN_DAYS 3650 /* how long our certificate should live */
+
+SSL_CTX *ssl_ctx; /* SSL context */
+char *ssl_cipher_list = DEFAULT_SSL_CIPHER_LIST;
+
+pthread_key_t ThreadSSL; /* Per-thread SSL context */
+
+void shutdown_ssl(void) {
+ ERR_free_strings();
+}
+
+
+void generate_key(char *keyfilename) {
+ int ret = 0;
+ RSA *rsa = NULL;
+ BIGNUM *bne = NULL;
+ int bits = 2048;
+ unsigned long e = RSA_F4;
+ FILE *fp;
+
+ if (access(keyfilename, R_OK) == 0) {
+ return;
+ }
+
+ syslog(LOG_INFO, "crypto: generating RSA key pair");
+
+ // generate rsa key
+ bne = BN_new();
+ ret = BN_set_word(bne,e);
+ if (ret != 1) {
+ goto free_all;
+ }
+
+ rsa = RSA_new();
+ ret = RSA_generate_key_ex(rsa, bits, bne, NULL);
+ if (ret != 1) {
+ goto free_all;
+ }
+
+ // write the key file
+ fp = fopen(keyfilename, "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, "crypto: cannot write key: %s", ERR_reason_error_string(ERR_get_error()));
+ unlink(keyfilename);
+ }
+ fclose(fp);
+ }
+
+ // 4. free
+free_all:
+ RSA_free(rsa);
+ BN_free(bne);