]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - client_common.c
Replace direct use of RC4 by stream cipher abstraction.
[paraslash.git] / client_common.c
index 593cb2c044c37995d76fa58f4abcb0a6ab198668..c55db47bf457ffbf1c40b79d098116a33d5e8a83 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2010 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2011 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <openssl/rc4.h>
 
 #include "para.h"
 #include "error.h"
@@ -42,6 +41,8 @@ void client_close(struct client_task *ct)
                return;
        if (ct->rc4c.fd >= 0)
                close(ct->rc4c.fd);
+       stream_cipher_free(ct->rc4c.recv);
+       stream_cipher_free(ct->rc4c.send);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
@@ -170,7 +171,7 @@ static void client_post_select(struct sched *s, struct task *t)
                        return;
                ret = send_buffer(ct->rc4c.fd, buf);
                if (ret < 0)
-                       goto err;
+                       goto out;
                ct->status = CL_SENT_AUTH;
                return;
        case CL_SENT_AUTH:
@@ -188,21 +189,21 @@ static void client_post_select(struct sched *s, struct task *t)
                if (ret < 0 || n == 0)
                        goto out;
                PARA_INFO_LOG("<-- [challenge] (%zu bytes)\n", n);
-               ret = para_decrypt_buffer(ct->key_file, crypt_buf,
+               ret = priv_decrypt(ct->key_file, crypt_buf,
                        (unsigned char *)buf, n);
                if (ret < 0)
-                       goto err;
+                       goto out;
                sha1_hash((char *)crypt_buf, CHALLENGE_SIZE, challenge_sha1);
-               RC4_set_key(&ct->rc4c.send_key, RC4_KEY_LEN,
-                       crypt_buf + CHALLENGE_SIZE);
-               RC4_set_key(&ct->rc4c.recv_key, RC4_KEY_LEN,
-                       crypt_buf + CHALLENGE_SIZE + RC4_KEY_LEN);
+               ct->rc4c.send = stream_cipher_new(crypt_buf + CHALLENGE_SIZE,
+                       RC4_KEY_LEN);
+               ct->rc4c.recv = stream_cipher_new(crypt_buf + CHALLENGE_SIZE
+                       + RC4_KEY_LEN, RC4_KEY_LEN);
                hash_to_asc(challenge_sha1, buf);
                PARA_INFO_LOG("--> %s\n", buf);
                ret = send_bin_buffer(ct->rc4c.fd, (char *)challenge_sha1,
                        HASH_SIZE);
                if (ret < 0)
-                       goto err;
+                       goto out;
                ct->status = CL_SENT_CH_RESPONSE;
                return;
                }
@@ -237,7 +238,7 @@ static void client_post_select(struct sched *s, struct task *t)
                ret = rc4_send_buffer(&ct->rc4c, command);
                free(command);
                if (ret < 0)
-                       goto err;
+                       goto out;
                ct->status = CL_SENT_COMMAND;
                return;
                }
@@ -265,7 +266,7 @@ static void client_post_select(struct sched *s, struct task *t)
                size_t sz;
                ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
                if (ret < 0)
-                       goto err;
+                       goto out;
                if (ret == 0)
                        return;
                if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
@@ -273,7 +274,7 @@ static void client_post_select(struct sched *s, struct task *t)
                sz = btr_next_buffer(btrn, &buf2);
                ret = rc4_send_bin_buffer(&ct->rc4c, buf2, sz);
                if (ret < 0)
-                       goto err;
+                       goto out;
                btr_consume(btrn, sz);
                return;
                }
@@ -282,7 +283,7 @@ static void client_post_select(struct sched *s, struct task *t)
                char *buf2;
                ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
                if (ret < 0)
-                       goto err;
+                       goto out;
                if (ret == 0)
                        return;
                /*
@@ -301,7 +302,6 @@ static void client_post_select(struct sched *s, struct task *t)
                goto out;
                }
        }
-err:
 out:
        t->error = ret;
        if (ret < 0) {