* Generate self-signed certificate if keys/citadel.cer is not present.
authorArt Cancro <ajc@citadel.org>
Sun, 22 Feb 2004 05:31:00 +0000 (05:31 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 22 Feb 2004 05:31:00 +0000 (05:31 +0000)
* Cleaned up some log messages.

citadel/.cvsignore
citadel/citserver.c
citadel/serv_crypto.c
citadel/serv_crypto.h
citadel/user_ops.c

index 7ffbd80a982b51eafe50ed1f9d5847e0b5b9d634..2088cc38a4363709763cb988ab3b6caf45271a69 100644 (file)
@@ -61,3 +61,4 @@ configure.lineno
 config.sub
 config.guess
 openldap-data
+keys
index 327659b779b40141235f71149254fd5ebbbd2234..826e00d2b314dbb7c29dc5757f880c8578fdcf0d 100644 (file)
@@ -510,8 +510,7 @@ void cmd_iden(char *argbuf)
                }
        }
 
-       lprintf(3,"Session %d: Client %d/%d/%01d.%02d (%s) from %s\n",
-               CC->cs_pid,
+       lprintf(3,"Client %d/%d/%01d.%02d (%s) from %s\n",
                dev_code,
                cli_code,
                (rev_level / 100),
@@ -903,7 +902,7 @@ void begin_session(struct CitContext *con)
        if ((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions))
                con->nologin = 1;
 
-       lprintf(3, "Session %d: started.\n", con->cs_pid);
+       lprintf(3, "Session started.\n");
 
        /* Run any session startup routines registered by loadable modules */
        PerformSessionHooks(EVT_START);
index d757141568f2d3e2365eeb698b5aaf962481e861..fdfffc5a3f3802fc2f7937474c184adafe03d22e 100644 (file)
@@ -92,8 +92,10 @@ void init_ssl(void)
        SSL_METHOD *ssl_method;
        DH *dh;
        RSA *rsa=NULL;
-       X509_REQ *x = NULL;
+       X509_REQ *req = NULL;
+       X509 *cer = NULL;
        EVP_PKEY *pk = NULL;
+       EVP_PKEY *req_pkey = NULL;
        X509_NAME *name = NULL;
        FILE *fp;
 
@@ -243,13 +245,13 @@ void init_ssl(void)
                        /* Create a public key from the private key */
                        if (pk=EVP_PKEY_new(), pk != NULL) {
                                EVP_PKEY_assign_RSA(pk, rsa);
-                               if (x = X509_REQ_new(), x != NULL) {
+                               if (req = X509_REQ_new(), req != NULL) {
 
                                        /* Set the public key */
-                                       X509_REQ_set_pubkey(x, pk);
-                                       X509_REQ_set_version(x, 0L);
+                                       X509_REQ_set_pubkey(req, pk);
+                                       X509_REQ_set_version(req, 0L);
 
-                                       name = X509_REQ_get_subject_name(x);
+                                       name = X509_REQ_get_subject_name(req);
 
                                        /* Tell it who we are */
 
@@ -273,10 +275,10 @@ void init_ssl(void)
                                        X509_NAME_add_entry_by_txt(name, "CN",
                                                MBSTRING_ASC, config.c_fqdn, -1, -1, 0);
                                
-                                       X509_REQ_set_subject_name(x, name);
+                                       X509_REQ_set_subject_name(req, name);
 
                                        /* Sign the CSR */
-                                       if (!X509_REQ_sign(x, pk, EVP_md5())) {
+                                       if (!X509_REQ_sign(req, pk, EVP_md5())) {
                                                lprintf(3, "X509_REQ_sign(): error\n");
                                        }
                                        else {
@@ -284,12 +286,12 @@ void init_ssl(void)
                                                fp = fopen(CTDL_CSR_PATH, "w");
                                                if (fp != NULL) {
                                                        chmod(CTDL_CSR_PATH, 0600);
-                                                       PEM_write_X509_REQ(fp, x);
+                                                       PEM_write_X509_REQ(fp, req);
                                                        fclose(fp);
                                                }
                                        }
 
-                                       X509_REQ_free(x);
+                                       X509_REQ_free(req);
                                }
                        }
 
@@ -309,8 +311,60 @@ void init_ssl(void)
        if (access(CTDL_CER_PATH, R_OK) != 0) {
                lprintf(3, "Generating a self-signed certificate.\n");
 
+               /* Same deal as before: always read the key from disk because
+                * it may or may not have just been generated.
+                */
+               fp = fopen(CTDL_KEY_PATH, "r");
+               if (fp) {
+                       rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
+                       fclose(fp);
+               }
+
+               /* This also holds true for the CSR. */
+               req = NULL;
+               cer = NULL;
+               pk = NULL;
+               if (rsa) {
+                       if (pk=EVP_PKEY_new(), pk != NULL) {
+                               EVP_PKEY_assign_RSA(pk, rsa);
+                       }
+
+                       fp = fopen(CTDL_CSR_PATH, "r");
+                       if (fp) {
+                               req = PEM_read_X509_REQ(fp, NULL, NULL, NULL);
+                               fclose(fp);
+                       }
 
-               /* FIXME ... do it */
+                       if (req) {
+                               if (cer = X509_new(), cer != NULL) {
+
+                                       X509_set_issuer_name(cer, req->req_info->subject);
+                                       X509_set_subject_name(cer, req->req_info->subject);
+                                       X509_gmtime_adj(X509_get_notBefore(cer),0);
+                                       X509_gmtime_adj(X509_get_notAfter(cer),(long)60*60*24*SIGN_DAYS);
+                                       req_pkey = X509_REQ_get_pubkey(req);
+                                       X509_set_pubkey(cer, req_pkey);
+                                       EVP_PKEY_free(req_pkey);
+                                       
+                                       /* Sign the cert */
+                                       if (!X509_sign(cer, pk, EVP_md5())) {
+                                               lprintf(3, "X509_sign(): error\n");
+                                       }
+                                       else {
+                                               /* Write it to disk. */ 
+                                               fp = fopen(CTDL_CER_PATH, "w");
+                                               if (fp != NULL) {
+                                                       chmod(CTDL_CER_PATH, 0600);
+                                                       PEM_write_X509(fp, cer);
+                                                       fclose(fp);
+                                               }
+                                       }
+                                       X509_free(cer);
+                               }
+                       }
+
+                       RSA_free(rsa);
+               }
        }
 
 
index d833d40d1612451c8bf543ccdbb9bc52b0c63e46..d273611c19caa2695a0ba3c6d1fd0e74de3b75b3 100644 (file)
@@ -1,5 +1,10 @@
 /* $Id$ */
 
+/*
+ * Number of days for which self-signed certs are valid.
+ */
+#define SIGN_DAYS      3650    /* Ten years */
+
 /* Shared Diffie-Hellman parameters */
 #define DH_P           "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
 #define DH_G           "2"
index d512db3c67d5e09d64316df39f0a38f047130213..7da967bc5730a9af9f7256d5927f9520568a485d 100644 (file)
@@ -436,8 +436,7 @@ void session_startup(void)
 {
        int i;
 
-       lprintf(3, "Session %d: %s logged in",
-              CC->cs_pid, CC->curr_user);
+       lprintf(3, "<%s> logged in\n", CC->curr_user);
 
        lgetuser(&CC->user, CC->curr_user);
        ++(CC->user.timescalled);