]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 't/crypt_cleanups'
authorAndre Noll <maan@systemlinux.org>
Sat, 23 Apr 2011 13:54:59 +0000 (15:54 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 23 Apr 2011 13:58:22 +0000 (15:58 +0200)
Conflicts:
Makefile.in

56 files changed:
Makefile.in
NEWS
afh.c
afh_common.c
afs.c
afs.cmd
afs.h
aft.c
alsa_write.c
attribute.c
audioc.c
audiod.c
audiod_command.c
blob.c
client.c
client.h
client_common.c
command.c
command.h
command_util.sh
configure.ac
crypt.c
crypt.h
dccp_recv.c
dccp_send.c
error.h
exec.c
fade.c
fecdec_filter.c
file_write.c
filter_common.c
grab_client.c
gui.c
hash.h [deleted file]
http_recv.c
http_send.c
net.c
oss_write.c
osx_write.c
rc4.h [deleted file]
recv.c
sched.c
send_common.c
server.c
server.cmd
sha1.c [deleted file]
sha1.h [deleted file]
signal.c
stdin.c
stdout.c
udp_recv.c
udp_send.c
user_list.c
user_list.h
vss.c
write.c

index 8b33aaac0c9fe58bab3b20c61cee25476af90965..8ecc1b8f6d606497aff2e9291e9b962d698cd28e 100644 (file)
@@ -56,7 +56,6 @@ CPPFLAGS += -Wunused-macros
 CPPFLAGS += -Wbad-function-cast
 CPPFLAGS += -fno-strict-aliasing
 CPPFLAGS += -DMAIN_INPUT_FILE_IS_$(*F)
-CPPFLAGS += @SSL_CPPFLAGS@
 CPPFLAGS += @arch_cppflags@
 CPPFLAGS += -I/usr/local/include
 CPPFLAGS += -I$(cmdline_dir)
@@ -150,6 +149,9 @@ $(object_dir):
 $(man_dir):
        mkdir -p $@
 
+$(object_dir)/crypt.o: crypt.c | $(object_dir)
+       @[ -z "$(Q)" ] || echo 'CC $<'
+       $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(DEBUG_CPPFLAGS) @openssl_cppflags@ $<
 $(object_dir)/spx_common.o: spx_common.c | $(object_dir)
        @[ -z "$(Q)" ] || echo 'CC $<'
        $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(DEBUG_CPPFLAGS) @ogg_cppflags@ $<
diff --git a/NEWS b/NEWS
index c08197f522011aaceb409c542ad1ca6e75a160d0..3295738632ef423ca4b36f68f3bcdc533d873e38 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@
        - The git version reported by --version always matches HEAD.
        - The autogen script detects the number of processors and
          runs a parallel make if possible.
+       - Major cleanup of the crypto API.
 
 ------------------------------------------
 0.4.6 (2011-03-31) "deterministic entropy"
diff --git a/afh.c b/afh.c
index 37d71224ba5631cc24f79c194810c20f9d9eb95e..66c4d1ca0f41a9c0b09ff2f70bc3ce566007bca8 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -7,7 +7,6 @@
 /** \file afh.c Paraslash's standalone audio format handler tool. */
 
 #include <regex.h>
-#include <dirent.h>
 #include <sys/time.h>
 
 #include "para.h"
index 7ecab4e47a9bd7e47bcc7e378043d62d663cf343..769674134b0f16d88bbe856d2daf972e54ed4c1b 100644 (file)
@@ -9,7 +9,6 @@
 #include <sys/mman.h> /* mmap */
 #include <sys/time.h> /* gettimeofday */
 #include <sys/types.h>
-#include <dirent.h>
 #include <regex.h>
 
 #include "para.h"
diff --git a/afs.c b/afs.c
index 0464eb77de8918f8b38d5a41c5a792212a271c5f..ac75164c0291f955c80857876fa8af48607e2814 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <signal.h>
 #include <fnmatch.h>
-#include <openssl/rc4.h>
 #include <osl.h>
 
 #include "server.cmdline.h"
@@ -20,9 +19,6 @@
 #include "afh.h"
 #include "afs.h"
 #include "server.h"
-#include <dirent.h> /* readdir() */
-#include <sys/mman.h>
-#include <sys/time.h>
 #include "net.h"
 #include "ipc.h"
 #include "list.h"
@@ -581,22 +577,22 @@ out:
  * Result handler for sending data to the para_client process.
  *
  * \param result The data to be sent.
- * \param private Pointer to rc4 context.
+ * \param private Pointer to the context.
  *
- * \return The return value of the underlying call to rc4_send_bin_buffer().
+ * \return The return value of the underlying call to sc_send_bin_buffer().
  *
- * \sa \ref callback_result_handler, \ref rc4_send_bin_buffer().
+ * \sa \ref callback_result_handler, \ref sc_send_bin_buffer().
  */
-int rc4_send_result(struct osl_object *result, void *private)
+int sc_send_result(struct osl_object *result, void *private)
 {
-       struct rc4_context *rc4c = private;
+       struct stream_cipher_context *scc = private;
 
        if (!result->size)
                return 1;
-       return rc4_send_bin_buffer(rc4c, result->data, result->size);
+       return sc_send_bin_buffer(scc, result->data, result->size);
 }
 
-int com_select(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_select(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        struct osl_object query;
 
@@ -605,7 +601,7 @@ int com_select(struct rc4_context *rc4c, int argc, char * const * const argv)
        query.data = argv[1];
        query.size = strlen(argv[1]) + 1;
        return send_callback_request(com_select_callback, &query,
-               &rc4_send_result, rc4c);
+               &sc_send_result, scc);
 }
 
 static void init_admissible_files(char *arg)
@@ -1019,7 +1015,7 @@ out:
        free(pb.buf);
 }
 
-int com_init(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_init(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int i, j, ret;
        uint32_t table_mask = (1 << (NUM_AFS_TABLES + 1)) - 1;
@@ -1045,9 +1041,9 @@ int com_init(struct rc4_context *rc4c, int argc, char * const * const argv)
                }
        }
        ret = send_callback_request(create_tables_callback, &query,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
        if (ret < 0)
-               return rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               return sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -1065,7 +1061,7 @@ enum com_check_flags {
        CHECK_PLAYLISTS = 4
 };
 
-int com_check(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_check(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        unsigned flags = 0;
        int i, ret;
@@ -1098,19 +1094,19 @@ int com_check(struct rc4_context *rc4c, int argc, char * const * const argv)
                flags = ~0U;
        if (flags & CHECK_AFT) {
                ret = send_callback_request(aft_check_callback, NULL,
-                       rc4_send_result, rc4c);
+                       sc_send_result, scc);
                if (ret < 0)
                        return ret;
        }
        if (flags & CHECK_PLAYLISTS) {
                ret = send_callback_request(playlist_check_callback,
-                       NULL, rc4_send_result, rc4c);
+                       NULL, sc_send_result, scc);
                if (ret < 0)
                        return ret;
        }
        if (flags & CHECK_MOODS) {
                ret = send_callback_request(mood_check_callback, NULL,
-                       rc4_send_result, rc4c);
+                       sc_send_result, scc);
                if (ret < 0)
                        return ret;
        }
diff --git a/afs.cmd b/afs.cmd
index f05519989c9bd20ec4c9b7f5aa952b983efb39c2..22a0786bc8d17731b242c9dc32c13d6d547e5635 100644 (file)
--- a/afs.cmd
+++ b/afs.cmd
@@ -3,7 +3,7 @@ SF: afs.c aft.c attribute.c
 HC: Prototypes for the commands of the audio file selector.
 CC: Array of commands for the audio file selector.
 AT: server_command
-SI: openssl/rc4 osl regex
+SI: osl regex
 IN: para error crypt command string afh afs server list user_list
 SN: list of afs commands
 TM: mood lyr img pl
@@ -260,7 +260,7 @@ H: loads the mood named 'foo'.
 ---
 T: add
 N: add@member@
-O: int com_add@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_add@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
 P: AFS_READ | AFS_WRITE
 D: Read data from stdin and add it as a blob to the @member@ table.
 U: add@member@ @member@_name
@@ -273,7 +273,7 @@ H: given name already exists, its contents are replaced by the new data.
 ---
 T: cat
 N: cat@member@
-O: int com_cat@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_cat@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
 P: AFS_READ
 D: Dump the contents of a blob of type @member@ to stdout.
 U: cat@member@ @member@_name
@@ -283,7 +283,7 @@ H: they were previously added.
 ---
 T: ls
 N: ls@member@
-O: int com_ls@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_ls@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
 P: AFS_READ
 D: List blobs of type @member@ matching a pattern.
 U: ls@member@ [-i] [-l] [-r] [pattern]
@@ -303,7 +303,7 @@ H: -r       Reverse sort order.
 ---
 T: rm
 N: rm@member@
-O: int com_rm@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_rm@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
 P: AFS_READ | AFS_WRITE
 D: Remove blob(s) of type @member@ from the @member@ table.
 U: rm@member@ pattern...
@@ -312,7 +312,7 @@ H: any given pattern.
 ---
 T: mv
 N: mv@member@
-O: int com_mv@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_mv@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
 P: AFS_READ | AFS_WRITE
 D: Rename a blob of type @member@.
 U: mv@member@ old_@member@_name new_@member@_name
diff --git a/afs.h b/afs.h
index 96da2da027cf27268c7b5ad1b4af6755b593f7e6..f54aa87ccbc3c2ad0a3ab44b054f22a6560aaa85 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -7,7 +7,6 @@
 /** \file afs.h Exported symbols of the audio file selector. */
 
 #include <regex.h>
-#include "hash.h"
 
 /** Audio file selector data stored in the audio file table. */
 struct afs_info {
@@ -119,8 +118,8 @@ struct ls_data {
        char *path;
        /** The score value (if -a was given). */
        long score;
-       /** The sha1 hash of audio file. */
-       HASH_TYPE *hash;
+       /** The hash value of audio file data. */
+       unsigned char *hash;
 };
 
 /** Data about the current audio file, passed from afs to server. */
@@ -205,7 +204,7 @@ typedef void callback_function(int fd, const struct osl_object *);
  * \sa \ref send_callback_request().
  */
 typedef int callback_result_handler(struct osl_object *result, void *private);
-int rc4_send_result(struct osl_object *result, void *private);
+int sc_send_result(struct osl_object *result, void *private);
 int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr);
 
 __noreturn void afs_init(uint32_t cookie, int socket_fd);
diff --git a/aft.c b/aft.c
index b3dde1379997bb6f69647255d0ac53fb703fce09..157b5a626b58306647fd3a09502efe992ed44bdc 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -7,8 +7,6 @@
 /** \file aft.c Audio file table functions. */
 
 #include <regex.h>
-#include <dirent.h> /* readdir() */
-#include <openssl/rc4.h>
 #include <sys/mman.h>
 #include <fnmatch.h>
 #include <sys/shm.h>
@@ -239,7 +237,7 @@ enum audio_file_table_columns {
  */
 static int aft_hash_compare(const struct osl_object *obj1, const struct osl_object *obj2)
 {
-       return hash_compare((HASH_TYPE *)obj1->data, (HASH_TYPE *)obj2->data);
+       return hash_compare((unsigned char *)obj1->data, (unsigned char *)obj2->data);
 }
 
 static struct osl_column_description aft_cols[] = {
@@ -486,7 +484,7 @@ int aft_get_row_of_path(const char *path, struct osl_row **row)
  *
  * \return Standard.
  */
-static int aft_get_row_of_hash(HASH_TYPE *hash, struct osl_row **row)
+static int aft_get_row_of_hash(unsigned char *hash, struct osl_row **row)
 {
        const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
        return osl(osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row));
@@ -606,7 +604,7 @@ static int get_hash_object_of_aft_row(const struct osl_row *row,
  * \return The return value of the underlying call to
  * get_hash_object_of_aft_row().
  */
-static int get_hash_of_row(const struct osl_row *row, HASH_TYPE **hash)
+static int get_hash_of_row(const struct osl_row *row, unsigned char **hash)
 {
        struct osl_object obj;
        int ret = get_hash_object_of_aft_row(row, &obj);
@@ -1027,7 +1025,7 @@ out:
 
 static int make_status_items(struct audio_file_data *afd,
                struct afs_info *afsi, char *path, long score,
-               HASH_TYPE *hash)
+               unsigned char *hash)
 {
        struct ls_data d = {
                .afhi = afd->afhi,
@@ -1080,7 +1078,7 @@ static int make_status_items(struct audio_file_data *afd,
 int open_and_update_audio_file(struct osl_row *aft_row, long score,
        struct audio_file_data *afd)
 {
-       HASH_TYPE *aft_hash, file_hash[HASH_SIZE];
+       unsigned char *aft_hash, file_hash[HASH_SIZE];
        struct osl_object afsi_obj;
        struct afs_info old_afsi, new_afsi;
        int ret = get_hash_of_row(aft_row, &aft_hash);
@@ -1397,7 +1395,7 @@ out:
 /*
  * TODO: flags -h (sort by hash)
  */
-int com_ls(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_ls(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int i, ret;
        unsigned flags = 0;
@@ -1509,7 +1507,7 @@ int com_ls(struct rc4_context *rc4c, int argc, char * const * const argv)
        opts.mode = mode;
        opts.num_patterns = argc - i;
        ret = send_option_arg_callback_request(&query, opts.num_patterns,
-               argv + i, com_ls_callback, rc4_send_result, rc4c);
+               argv + i, com_ls_callback, sc_send_result, scc);
        return ret;
 }
 
@@ -1527,7 +1525,7 @@ int audio_file_loop(void *private_data, osl_rbtree_loop_func *func)
                func));
 }
 
-static struct osl_row *find_hash_sister(HASH_TYPE *hash)
+static struct osl_row *find_hash_sister(unsigned char *hash)
 {
        const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
        struct osl_row *row;
@@ -1559,7 +1557,7 @@ enum com_add_buffer_offsets {
  * It's OK to call this with afhi == NULL. In this case, the audio format
  * handler info won't be stored in the buffer.
  */
-static void save_add_callback_buffer(HASH_TYPE *hash, const char *path,
+static void save_add_callback_buffer(unsigned char *hash, const char *path,
                struct afh_info *afhi, uint32_t flags,
                uint8_t audio_format_num, struct osl_object *obj)
 {
@@ -1662,7 +1660,7 @@ static void com_add_callback(int fd, const struct osl_object *query)
        struct osl_row *pb, *aft_row;
        struct osl_row *hs;
        struct osl_object objs[NUM_AFT_COLUMNS];
-       HASH_TYPE *hash;
+       unsigned char *hash;
        char asc[2 * HASH_SIZE + 1];
        int ret;
        char afsi_buf[AFSI_SIZE];
@@ -1672,7 +1670,7 @@ static void com_add_callback(int fd, const struct osl_object *query)
                .max_size_handler = pass_buffer_as_shm, .private_data = &fd};
        uint16_t afhi_offset, chunks_offset;
 
-       hash = (HASH_TYPE *)buf + CAB_HASH_OFFSET;
+       hash = (unsigned char *)buf + CAB_HASH_OFFSET;
        hash_to_asc(hash, asc);;
        objs[AFTCOL_HASH].data = buf + CAB_HASH_OFFSET;
        objs[AFTCOL_HASH].size = HASH_SIZE;
@@ -1737,7 +1735,7 @@ static void com_add_callback(int fd, const struct osl_object *query)
        objs[AFTCOL_CHUNKS].size = query->size - chunks_offset;
        if (pb && !hs) { /* update pb's hash */
                char old_asc[2 * HASH_SIZE + 1];
-               HASH_TYPE *old_hash;
+               unsigned char *old_hash;
                ret = get_hash_of_row(pb, &old_hash);
                if (ret < 0)
                        goto out;
@@ -1796,8 +1794,8 @@ out:
 
 /** Used by com_add(). */
 struct private_add_data {
-       /** The socket file descriptor, including rc4 keys. */
-       struct rc4_context *rc4c;
+       /** The socket file descriptor, including stream cipher keys. */
+       struct stream_cipher_context *scc;
        /** The given add flags. */
        uint32_t flags;
 };
@@ -1814,7 +1812,7 @@ static void path_brother_callback(int fd, const struct osl_object *query)
 
 static void hash_sister_callback(int fd, const struct osl_object *query)
 {
-       HASH_TYPE *hash = query->data;
+       unsigned char *hash = query->data;
        struct osl_row *hash_sister;
 
        hash_sister = find_hash_sister(hash);
@@ -1838,7 +1836,7 @@ static int add_one_audio_file(const char *path, void *private_data)
        struct afh_info afhi, *afhi_ptr = NULL;
        struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */
        struct osl_object map, obj = {.data = NULL}, query;
-       HASH_TYPE hash[HASH_SIZE];
+       unsigned char hash[HASH_SIZE];
 
        ret = guess_audio_format(path);
        if (ret < 0 && !(pad->flags & ADD_FLAG_ALL))
@@ -1852,7 +1850,7 @@ static int add_one_audio_file(const char *path, void *private_data)
        ret = 1;
        if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
                if (pad->flags & ADD_FLAG_VERBOSE)
-                       send_ret = rc4_send_va_buffer(pad->rc4c,
+                       send_ret = sc_send_va_buffer(pad->scc,
                                "lazy-ignore: %s\n", path);
                goto out_free;
        }
@@ -1873,7 +1871,7 @@ static int add_one_audio_file(const char *path, void *private_data)
        ret = 1;
        if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) {
                if (pad->flags & ADD_FLAG_VERBOSE)
-                       send_ret = rc4_send_va_buffer(pad->rc4c,
+                       send_ret = sc_send_va_buffer(pad->scc,
                                "%s exists, not forcing update\n", path);
                goto out_unmap;
        }
@@ -1891,13 +1889,13 @@ static int add_one_audio_file(const char *path, void *private_data)
        munmap(map.data, map.size);
        close(fd);
        if (pad->flags & ADD_FLAG_VERBOSE) {
-               send_ret = rc4_send_va_buffer(pad->rc4c, "adding %s\n", path);
+               send_ret = sc_send_va_buffer(pad->scc, "adding %s\n", path);
                if (send_ret < 0)
                        goto out_free;
        }
        save_add_callback_buffer(hash, path, afhi_ptr, pad->flags, format_num, &obj);
        /* Ask afs to consider this entry for adding. */
-       ret = send_callback_request(com_add_callback, &obj, rc4_send_result, pad->rc4c);
+       ret = send_callback_request(com_add_callback, &obj, sc_send_result, pad->scc);
        goto out_free;
 
 out_unmap:
@@ -1905,7 +1903,7 @@ out_unmap:
        munmap(map.data, map.size);
 out_free:
        if (ret < 0 && send_ret >= 0)
-               send_ret = rc4_send_va_buffer(pad->rc4c,
+               send_ret = sc_send_va_buffer(pad->scc,
                        "failed to add %s (%s)\n", path, para_strerror(-ret));
        free(obj.data);
        if (afhi_ptr) {
@@ -1921,10 +1919,10 @@ out_free:
        return send_ret;
 }
 
-int com_add(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_add(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int i, ret;
-       struct private_add_data pad = {.rc4c = rc4c, .flags = 0};
+       struct private_add_data pad = {.scc = scc, .flags = 0};
        struct stat statbuf;
 
        for (i = 1; i < argc; i++) {
@@ -1958,7 +1956,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv)
                char *path;
                ret = verify_path(argv[i], &path);
                if (ret < 0) {
-                       ret = rc4_send_va_buffer(rc4c, "%s: %s\n", argv[i],
+                       ret = sc_send_va_buffer(scc, "%s: %s\n", argv[i],
                                para_strerror(-ret));
                        if (ret < 0)
                                return ret;
@@ -1966,7 +1964,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv)
                }
                ret = stat(path, &statbuf);
                if (ret < 0) {
-                       ret = rc4_send_va_buffer(rc4c, "failed to stat %s (%s)\n", path,
+                       ret = sc_send_va_buffer(scc, "failed to stat %s (%s)\n", path,
                                strerror(errno));
                        free(path);
                        if (ret < 0)
@@ -1979,7 +1977,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv)
                else
                        ret = add_one_audio_file(path, &pad);
                if (ret < 0) {
-                       rc4_send_va_buffer(rc4c, "%s: %s\n", path, para_strerror(-ret));
+                       sc_send_va_buffer(scc, "%s: %s\n", path, para_strerror(-ret));
                        free(path);
                        return ret;
                }
@@ -2111,7 +2109,7 @@ static void com_touch_callback(int fd, const struct osl_object *query)
        free(tad.pb.buf);
 }
 
-int com_touch(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_touch(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        struct com_touch_options cto = {
                .num_played = -1,
@@ -2179,9 +2177,9 @@ int com_touch(struct rc4_context *rc4c, int argc, char * const * const argv)
        if (i >= argc)
                return -E_AFT_SYNTAX;
        ret = send_option_arg_callback_request(&query, argc - i,
-               argv + i, com_touch_callback, rc4_send_result, rc4c);
+               argv + i, com_touch_callback, sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -2263,7 +2261,7 @@ static void com_rm_callback(int fd, const struct osl_object *query)
 }
 
 /* TODO options: -r (recursive) */
-int com_rm(struct rc4_context *rc4c, int argc,  char * const * const argv)
+int com_rm(struct stream_cipher_context *scc, int argc,  char * const * const argv)
 {
        uint32_t flags = 0;
        struct osl_object query = {.data = &flags, .size = sizeof(flags)};
@@ -2294,9 +2292,9 @@ int com_rm(struct rc4_context *rc4c, int argc,  char * const * const argv)
        if (i >= argc)
                return -E_AFT_SYNTAX;
        ret = send_option_arg_callback_request(&query, argc - i, argv + i,
-               com_rm_callback, rc4_send_result, rc4c);
+               com_rm_callback, sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -2411,7 +2409,7 @@ out:
        free(cad.pb.buf);
 }
 
-int com_cpsi(struct rc4_context *rc4c, int argc,  char * const * const argv)
+int com_cpsi(struct stream_cipher_context *scc, int argc,  char * const * const argv)
 {
        unsigned flags = 0;
        int i, ret;
@@ -2456,9 +2454,9 @@ int com_cpsi(struct rc4_context *rc4c, int argc,  char * const * const argv)
        if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */
                flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags;
        ret = send_option_arg_callback_request(&options, argc - i, argv + i,
-               com_cpsi_callback, rc4_send_result, rc4c);
+               com_cpsi_callback, sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -2474,9 +2472,9 @@ static void afs_stat_callback(int fd, const struct osl_object *query)
 }
 
 /**
- * Get the current afs status items from the afs process and send it using RC4.
+ * Get the current afs status items from the afs process and send it.
  *
- * \param rc4c The rc4 context for data encryption.
+ * \param scc The stream cipher context for data encryption.
  * \param parser_friendly Whether parser-friendly output format should be used.
  *
  * As the contents of the afs status items change in time and the command
@@ -2485,12 +2483,12 @@ static void afs_stat_callback(int fd, const struct osl_object *query)
  * is used to pass the status items from the afs process to the command handler
  * via a shared memory area and a pipe.
  */
-int send_afs_status(struct rc4_context *rc4c, int parser_friendly)
+int send_afs_status(struct stream_cipher_context *scc, int parser_friendly)
 {
        struct osl_object query = {.data = &parser_friendly,
                .size = sizeof(parser_friendly)};
 
-       return send_callback_request(afs_stat_callback, &query, rc4_send_result, rc4c);
+       return send_callback_request(afs_stat_callback, &query, sc_send_result, scc);
 }
 
 /* TODO: optionally fix problems by removing offending rows */
index 8cf5cfd25bf3909e0f4d338d2397ca0e017c29ab..c2a4cc1e94f47d9cf9717334059e6cf57df4970a 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <alsa/asoundlib.h>
 #include <sys/time.h>
 #include <stdbool.h>
index 24536911affeceffb029f806de4aa6d4b03d362a..4c664996bea7dc869d30ed12e41b4f538fdd5d58 100644 (file)
@@ -7,7 +7,6 @@
 /** \file attribute.c Attribute handling functions. */
 
 #include <regex.h>
-#include <openssl/rc4.h>
 #include <osl.h>
 
 #include "para.h"
@@ -177,7 +176,7 @@ static void com_lsatt_callback(int fd, const struct osl_object *query)
        free(laad.pb.buf);
 }
 
-int com_lsatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_lsatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        unsigned flags = 0;
        struct osl_object options = {.data = &flags, .size = sizeof(flags)};
@@ -205,12 +204,12 @@ int com_lsatt(struct rc4_context *rc4c, int argc, char * const * const argv)
                }
        }
        ret = send_option_arg_callback_request(&options, argc - i, argv + i,
-               com_lsatt_callback, rc4_send_result, rc4c);
+               com_lsatt_callback, sc_send_result, scc);
        if (!ret) {
                if (argc > 1)
-                       ret = rc4_send_va_buffer(rc4c, "no matches\n");
+                       ret = sc_send_va_buffer(scc, "no matches\n");
        } else if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -278,7 +277,7 @@ out:
                PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 }
 
-int com_setatt(__a_unused struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_setatt(__a_unused struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        if (argc < 3)
                return -E_ATTR_SYNTAX;
@@ -359,16 +358,16 @@ out:
        free(pb.buf);
 }
 
-int com_addatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_addatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int ret;
 
        if (argc < 2)
                return -E_ATTR_SYNTAX;
        ret = send_standard_callback_request(argc - 1, argv + 1, com_addatt_callback,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -402,16 +401,16 @@ out:
        free(pb.buf);
 }
 
-int com_mvatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_mvatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int ret;
 
        if (argc != 3)
                return -E_ATTR_SYNTAX;
        ret = send_standard_callback_request(argc - 1, argv + 1, com_mvatt_callback,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -474,16 +473,16 @@ static void com_rmatt_callback(int fd, const struct osl_object *query)
        free(raad.pb.buf);
 }
 
-int com_rmatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_rmatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        int ret;
 
        if (argc < 2)
                return -E_ATTR_SYNTAX;
        ret = send_standard_callback_request(argc - 1, argv + 1, com_rmatt_callback,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
        if (ret < 0)
-               rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+               sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
        return ret;
 }
 
index adcae715e28d29c48da934a16360dab8b5ecc476..8c46b46f7d19864dbbd0c0074d399cb12ea696f2 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 
 #include "audioc.cmdline.h"
 #include "para.h"
index 5bc22c816896d22b7c1269dc7ceb3fa234efd7b0..9f664e178309c39e70a64d7ea55f6a29f0c5f6cf 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -7,9 +7,7 @@
 /** \file audiod.c the paraslash's audio daemon */
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <signal.h>
-#include <openssl/rc4.h>
 #include <stdbool.h>
 
 #include "para.h"
index bfd7c4aa5df170235f24961813bc4cc2e69790fa..05059ac06d2ff7f23a9648e14e54c71c904bfa9d 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"
diff --git a/blob.c b/blob.c
index cbf2af49395f09b00aa322774ec79118d181daa4..dfe4e37431226bb80b298b7b676928897e645413 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <fnmatch.h>
-#include <openssl/rc4.h>
 #include <osl.h>
 
 #include "para.h"
@@ -162,7 +161,7 @@ static void com_lsblob_callback(struct osl_table *table,
        free(lbad.pb.buf);
 }
 
-static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc, char * const * const argv)
+static int com_lsblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv)
 {
        uint32_t flags = 0;
        struct osl_object options = {.data = &flags, .size = sizeof(flags)};
@@ -193,7 +192,7 @@ static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc,
 //     if (argc > i)
 //             return -E_BLOB_SYNTAX;
        return send_option_arg_callback_request(&options, argc - i,
-               argv + i, f, rc4_send_result, rc4c);
+               argv + i, f, sc_send_result, scc);
 }
 
 static int cat_blob(struct osl_table *table, struct osl_row *row,
@@ -226,13 +225,13 @@ static void com_catblob_callback(struct osl_table *table, int fd,
        for_each_matching_row(&pmd);
 }
 
-static int com_catblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_catblob(callback_function *f, struct stream_cipher_context *scc, int argc,
                char * const * const argv)
 {
        if (argc < 2)
                return -E_BLOB_SYNTAX;
        return send_standard_callback_request(argc - 1, argv + 1, f,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
 }
 
 /** Used for removing rows from a blob table. */
@@ -295,13 +294,13 @@ out:
        free(rmbd.pb.buf);
 }
 
-static int com_rmblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_rmblob(callback_function *f, struct stream_cipher_context *scc, int argc,
                char * const * const argv)
 {
        if (argc < 2)
                return -E_MOOD_SYNTAX;
        return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f,
-               rc4_send_result, rc4c);
+               sc_send_result, scc);
 }
 
 static void com_addblob_callback(struct osl_table *table, __a_unused int fd,
@@ -377,7 +376,7 @@ out:
  * write input from fd to dynamically allocated buffer,
  * but maximal max_size byte.
  */
-static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object *obj)
+static int fd2buf(struct stream_cipher_context *scc, unsigned max_size, struct osl_object *obj)
 {
        const size_t chunk_size = 1024;
        size_t size = 2048, received = 0;
@@ -385,7 +384,7 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object
        char *buf = para_malloc(size);
 
        for (;;) {
-               ret = rc4_recv_bin_buffer(rc4c, buf + received, chunk_size);
+               ret = sc_recv_bin_buffer(scc, buf + received, chunk_size);
                if (ret <= 0)
                        break;
                received += ret;
@@ -407,7 +406,7 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object
 /*
  * Read data from a file descriptor, and send it to the afs process.
  *
- * \param rc4c crypt context containing the file descriptor to read data from.
+ * \param scc crypt context containing the file descriptor to read data from.
  * \param arg_obj Pointer to the arguments to \a f.
  * \param f The callback function.
  * \param max_len Don't read more than that many bytes from stdin.
@@ -417,14 +416,14 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object
  * This function is used by commands that wish to let para_server store
  * arbitrary data specified by the user (for instance the add_blob family of
  * commands). First, at most \a max_len bytes are read and decrypted from the
- * file descriptor given by \a rc4c. The result is concatenated with the buffer
+ * file descriptor given by \a scc. The result is concatenated with the buffer
  * given by \a arg_obj, and the combined buffer is made available to the afs
  * process via the callback method. See \ref send_callback_request for details.
  *
  * \return Negative on errors, the return value of the underlying call to
  * send_callback_request() otherwise.
  */
-static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj,
+static int stdin_command(struct stream_cipher_context *scc, struct osl_object *arg_obj,
                callback_function *f, unsigned max_len,
                callback_result_handler *result_handler,
                void *private_result_data)
@@ -432,10 +431,10 @@ static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj,
        struct osl_object query, stdin_obj;
        int ret;
 
-       ret = rc4_send_buffer(rc4c, AWAITING_DATA_MSG);
+       ret = sc_send_buffer(scc, AWAITING_DATA_MSG);
        if (ret < 0)
                return ret;
-       ret = fd2buf(rc4c, max_len, &stdin_obj);
+       ret = fd2buf(scc, max_len, &stdin_obj);
        if (ret < 0)
                return ret;
        query.size = arg_obj->size + stdin_obj.size;
@@ -448,7 +447,7 @@ static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj,
        return ret;
 }
 
-static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_addblob(callback_function *f, struct stream_cipher_context *scc, int argc,
                char * const * const argv)
 {
        struct osl_object arg_obj;
@@ -459,7 +458,7 @@ static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc,
                return -E_BLOB_SYNTAX;
        arg_obj.size = strlen(argv[1]) + 1;
        arg_obj.data = (char *)argv[1];
-       return stdin_command(rc4c, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL);
+       return stdin_command(scc, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL);
 }
 
 /* FIXME: Print output to client, not to log file */
@@ -485,7 +484,7 @@ out:
                PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 }
 
-static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c,
+static int com_mvblob(callback_function *f, __a_unused struct stream_cipher_context *scc,
                int argc, char * const * const argv)
 {
        if (argc != 3)
@@ -499,9 +498,9 @@ static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c,
        { \
                return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \
        } \
-       int com_ ## cmd_name ## cmd_prefix(struct rc4_context *rc4c, int argc, char * const * const argv) \
+       int com_ ## cmd_name ## cmd_prefix(struct stream_cipher_context *scc, int argc, char * const * const argv) \
        { \
-               return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, rc4c, argc, argv); \
+               return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, scc, argc, argv); \
        }
 
 static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
index ec32cd414e31df10dd5c7dbecbdef60c5134a5a2..b6a2f24157b7a01a63f9bbb13418c2c2326559dc 100644 (file)
--- a/client.c
+++ b/client.c
@@ -7,7 +7,6 @@
 /** \file client.c the client program used to connect to para_server */
 
 #include <regex.h>
-#include <openssl/rc4.h>
 #include <stdbool.h>
 
 #include "para.h"
index 667607e23cf554e7598006d8f0d19268afe6c11d..2d63c4109460764d4fa5e3a6aa9c694044775afb 100644 (file)
--- a/client.h
+++ b/client.h
@@ -6,8 +6,6 @@
 
 /** \file client.h Common client functions and exported symbols from client_common.c. */
 
-#include <openssl/rc4.h>
-
 /** The different states of a connection from the view of the client. */
 enum {
        /** TCP connection is established. */
@@ -32,8 +30,8 @@ enum {
 struct client_task {
        /** The state of the connection. */
        int status;
-       /** The file descriptor and the rc4 keys. */
-       struct rc4_context rc4c;
+       /** The file descriptor and the session keys. */
+       struct stream_cipher_context scc;
        /** The configuration (including the command). */
        struct client_args_info conf;
        /** The config file for client options. */
index 54bb9433e34cbd0a5bbfed50d07a7d536e0f8b65..d3a9ede1f0e1d5b7238a387f0f3aa03650deed55 100644 (file)
@@ -8,8 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
-#include <openssl/rc4.h>
 
 #include "para.h"
 #include "error.h"
 #include "sched.h"
 #include "client.cmdline.h"
 #include "crypt.h"
-#include "rc4.h"
 #include "net.h"
 #include "fd.h"
 #include "string.h"
 #include "client.cmdline.h"
 #include "client.h"
-#include "hash.h"
 #include "buffer_tree.h"
 #include "version.h"
 
@@ -41,8 +37,10 @@ void client_close(struct client_task *ct)
 {
        if (!ct)
                return;
-       if (ct->rc4c.fd >= 0)
-               close(ct->rc4c.fd);
+       if (ct->scc.fd >= 0)
+               close(ct->scc.fd);
+       sc_free(ct->scc.recv);
+       sc_free(ct->scc.send);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
@@ -70,19 +68,19 @@ static void client_pre_select(struct sched *s, struct task *t)
        struct client_task *ct = container_of(t, struct client_task, task);
        struct btr_node *btrn = ct->btrn;
 
-       if (ct->rc4c.fd < 0)
+       if (ct->scc.fd < 0)
                return;
        switch (ct->status) {
        case CL_CONNECTED:
        case CL_SENT_AUTH:
        case CL_SENT_CH_RESPONSE:
        case CL_SENT_COMMAND:
-               para_fd_set(ct->rc4c.fd, &s->rfds, &s->max_fileno);
+               para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno);
                return;
 
        case CL_RECEIVED_WELCOME:
        case CL_RECEIVED_PROCEED:
-               para_fd_set(ct->rc4c.fd, &s->wfds, &s->max_fileno);
+               para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno);
                return;
 
        case CL_RECEIVING:
@@ -91,7 +89,7 @@ static void client_pre_select(struct sched *s, struct task *t)
                        if (ret < 0)
                                sched_min_delay(s);
                        else
-                               para_fd_set(ct->rc4c.fd, &s->rfds,
+                               para_fd_set(ct->scc.fd, &s->rfds,
                                        &s->max_fileno);
                }
                return;
@@ -101,7 +99,7 @@ static void client_pre_select(struct sched *s, struct task *t)
                        if (ret < 0)
                                sched_min_delay(s);
                        else
-                               para_fd_set(ct->rc4c.fd, &s->wfds,
+                               para_fd_set(ct->scc.fd, &s->wfds,
                                        &s->max_fileno);
                }
                return;
@@ -114,12 +112,12 @@ static int client_recv_buffer(struct client_task *ct, fd_set *rfds,
        int ret;
 
        if (ct->status < CL_SENT_CH_RESPONSE)
-               return read_nonblock(ct->rc4c.fd, buf, sz, rfds, n);
+               return read_nonblock(ct->scc.fd, buf, sz, rfds, n);
 
        *n = 0;
-       ret = rc4_recv_buffer(&ct->rc4c, buf, sz);
+       ret = sc_recv_buffer(&ct->scc, buf, sz);
        /*
-        * rc4_recv_buffer is used with blocking fds elsewhere, so it
+        * sc_recv_buffer is used with blocking fds elsewhere, so it
         * does not use the nonblock-API. Therefore we need to
         * check for EOF and EAGAIN.
         */
@@ -155,7 +153,7 @@ static void client_post_select(struct sched *s, struct task *t)
        char buf[CLIENT_BUFSIZE];
 
        t->error = 0;
-       if (ct->rc4c.fd < 0)
+       if (ct->scc.fd < 0)
                return;
        switch (ct->status) {
        case CL_CONNECTED: /* receive welcome message */
@@ -167,40 +165,39 @@ static void client_post_select(struct sched *s, struct task *t)
        case CL_RECEIVED_WELCOME: /* send auth command */
                sprintf(buf, AUTH_REQUEST_MSG "%s", ct->user);
                PARA_INFO_LOG("--> %s\n", buf);
-               if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+               if (!FD_ISSET(ct->scc.fd, &s->wfds))
                        return;
-               ret = send_buffer(ct->rc4c.fd, buf);
+               ret = send_buffer(ct->scc.fd, buf);
                if (ret < 0)
                        goto out;
                ct->status = CL_SENT_AUTH;
                return;
        case CL_SENT_AUTH:
                /*
-                * Receive challenge and rc4 keys, decrypt the challenge and
+                * Receive challenge and session keys, decrypt the challenge and
                 * send back the hash of the decrypted challenge.
                 */
                {
-               /* decrypted challenge/rc4 buffer */
+               /* decrypted challenge/session key buffer */
                unsigned char crypt_buf[1024];
                /* the SHA1 of the decrypted challenge */
-               unsigned char challenge_sha1[HASH_SIZE];
+               unsigned char challenge_hash[HASH_SIZE];
 
                ret = client_recv_buffer(ct, &s->rfds, buf, sizeof(buf), &n);
                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 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);
-               hash_to_asc(challenge_sha1, buf);
+               hash_function((char *)crypt_buf, CHALLENGE_SIZE, challenge_hash);
+               ct->scc.send = sc_new(crypt_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
+               ct->scc.recv = sc_new(crypt_buf + CHALLENGE_SIZE + SESSION_KEY_LEN,
+                       SESSION_KEY_LEN);
+               hash_to_asc(challenge_hash, buf);
                PARA_INFO_LOG("--> %s\n", buf);
-               ret = send_bin_buffer(ct->rc4c.fd, (char *)challenge_sha1,
+               ret = send_bin_buffer(ct->scc.fd, (char *)challenge_hash,
                        HASH_SIZE);
                if (ret < 0)
                        goto out;
@@ -225,7 +222,7 @@ static void client_post_select(struct sched *s, struct task *t)
                {
                int i;
                char *command = NULL;
-               if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+               if (!FD_ISSET(ct->scc.fd, &s->wfds))
                        return;
                for (i = 0; i < ct->conf.inputs_num; i++) {
                        char *tmp = command;
@@ -235,7 +232,7 @@ static void client_post_select(struct sched *s, struct task *t)
                }
                command = para_strcat(command, EOC_MSG "\n");
                PARA_DEBUG_LOG("--> %s\n", command);
-               ret = rc4_send_buffer(&ct->rc4c, command);
+               ret = sc_send_buffer(&ct->scc, command);
                free(command);
                if (ret < 0)
                        goto out;
@@ -269,10 +266,10 @@ static void client_post_select(struct sched *s, struct task *t)
                        goto out;
                if (ret == 0)
                        return;
-               if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+               if (!FD_ISSET(ct->scc.fd, &s->wfds))
                        return;
                sz = btr_next_buffer(btrn, &buf2);
-               ret = rc4_send_bin_buffer(&ct->rc4c, buf2, sz);
+               ret = sc_send_bin_buffer(&ct->scc, buf2, sz);
                if (ret < 0)
                        goto out;
                btr_consume(btrn, sz);
@@ -290,7 +287,7 @@ static void client_post_select(struct sched *s, struct task *t)
                 * The FD_ISSET() is not strictly necessary, but is allows us
                 * to skip the malloc below if there is nothing to read anyway.
                 */
-               if (!FD_ISSET(ct->rc4c.fd, &s->rfds))
+               if (!FD_ISSET(ct->scc.fd, &s->rfds))
                        return;
                buf2 = para_malloc(CLIENT_BUFSIZE);
                ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
@@ -316,14 +313,14 @@ static int client_connect(struct client_task *ct)
 {
        int ret;
 
-       ct->rc4c.fd = -1;
+       ct->scc.fd = -1;
        ret = para_connect_simple(IPPROTO_TCP, ct->conf.hostname_arg,
                                               ct->conf.server_port_arg);
        if (ret < 0)
                return ret;
-       ct->rc4c.fd = ret;
+       ct->scc.fd = ret;
        ct->status = CL_CONNECTED;
-       ret = mark_fd_nonblocking(ct->rc4c.fd);
+       ret = mark_fd_nonblocking(ct->scc.fd);
        if (ret < 0)
                goto err_out;
        ct->task.pre_select = client_pre_select;
@@ -332,8 +329,8 @@ static int client_connect(struct client_task *ct)
        register_task(&ct->task);
        return 1;
 err_out:
-       close(ct->rc4c.fd);
-       ct->rc4c.fd = -1;
+       close(ct->scc.fd);
+       ct->scc.fd = -1;
        return ret;
 }
 
@@ -364,7 +361,7 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr,
        ct->btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "client", .parent = parent, .child = child));
        *ct_ptr = ct;
-       ct->rc4c.fd = -1;
+       ct->scc.fd = -1;
        ret = -E_CLIENT_SYNTAX;
        if (client_cmdline_parser(argc, argv, &ct->conf))
                goto out;
index 24ddf7897d81e3b27c6f1777f975da49ca31ee52..d82bd5d71ca3ed6bf2fa40777c5a5b1231fd897f 100644 (file)
--- a/command.c
+++ b/command.c
@@ -10,8 +10,6 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#include <dirent.h>
-#include <openssl/rc4.h>
 #include <osl.h>
 #include <stdbool.h>
 
@@ -27,7 +25,6 @@
 #include "list.h"
 #include "send.h"
 #include "vss.h"
-#include "rc4.h"
 #include "net.h"
 #include "daemon.h"
 #include "fd.h"
@@ -45,7 +42,7 @@
 extern int mmd_mutex;
 extern struct misc_meta_data *mmd;
 extern struct sender senders[];
-int send_afs_status(struct rc4_context *rc4c, int parser_friendly);
+int send_afs_status(struct stream_cipher_context *scc, int parser_friendly);
 
 const char *status_item_list[] = {STATUS_ITEM_ARRAY};
 
@@ -190,7 +187,7 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman
        return 1;
 }
 
-int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_sender(struct stream_cipher_context *scc, int argc, char * const * argv)
 {
        int i, ret;
        char *msg = NULL;
@@ -203,7 +200,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
                        free(msg);
                        msg = tmp;
                }
-               ret = rc4_send_buffer(rc4c, msg);
+               ret = sc_send_buffer(scc, msg);
                free(msg);
                return ret;
        }
@@ -212,7 +209,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
                if (scd.sender_num < 0)
                        return ret;
                msg = senders[scd.sender_num].help();
-               ret = rc4_send_buffer(rc4c, msg);
+               ret = sc_send_buffer(scc, msg);
                free(msg);
                return ret;
        }
@@ -241,7 +238,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
 }
 
 /* server info */
-int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_si(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        int i, ret;
        char *ut;
@@ -256,7 +253,7 @@ int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
                free(info);
        }
        ut = uptime_str();
-       ret = rc4_send_va_buffer(rc4c, "version: " GIT_VERSION "\n"
+       ret = sc_send_va_buffer(scc, "version: " GIT_VERSION "\n"
                "up: %s\nplayed: %u\n"
                "server_pid: %d\n"
                "afs_pid: %d\n"
@@ -281,11 +278,11 @@ int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
 }
 
 /* version */
-int com_version(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_version(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
-       return rc4_send_buffer(rc4c, VERSION_TEXT("server")
+       return sc_send_buffer(scc, VERSION_TEXT("server")
                "built: " BUILD_DATE "\n"
                UNAME_RS ", " CC_VERSION "\n"
        );
@@ -347,7 +344,7 @@ static char *empty_status_items(int parser_friendly)
 #undef EMPTY_STATUS_ITEMS
 
 /* stat */
-int com_stat(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_stat(struct stream_cipher_context *scc, int argc, char * const * argv)
 {
        int i, ret;
        struct misc_meta_data tmp, *nmmd = &tmp;
@@ -382,7 +379,7 @@ int com_stat(struct rc4_context *rc4c, int argc, char * const * argv)
        for (;;) {
                mmd_dup(nmmd);
                s = get_status(nmmd, parser_friendly);
-               ret = rc4_send_buffer(rc4c, s);
+               ret = sc_send_buffer(scc, s);
                free(s);
                if (ret < 0)
                        goto out;
@@ -390,11 +387,11 @@ int com_stat(struct rc4_context *rc4c, int argc, char * const * argv)
                        static char *esi;
                        if (!esi)
                                esi = empty_status_items(parser_friendly);
-                       ret = rc4_send_buffer(rc4c, esi);
+                       ret = sc_send_buffer(scc, esi);
                        if (ret < 0)
                                goto out;
                } else
-                       send_afs_status(rc4c, parser_friendly);
+                       send_afs_status(scc, parser_friendly);
                ret = 1;
                if (num > 0 && !--num)
                        goto out;
@@ -406,14 +403,14 @@ out:
        return ret;
 }
 
-static int send_list_of_commands(struct rc4_context *rc4c, struct server_command *cmd,
+static int send_list_of_commands(struct stream_cipher_context *scc, struct server_command *cmd,
                const char *handler)
 {
        int ret, i;
 
        for (i = 1; cmd->name; cmd++, i++) {
                char *perms = cmd_perms_itohuman(cmd->perms);
-               ret = rc4_send_va_buffer(rc4c, "%s\t%s\t%s\t%s\n", cmd->name,
+               ret = sc_send_va_buffer(scc, "%s\t%s\t%s\t%s\n", cmd->name,
                        handler,
                        perms,
                        cmd->description);
@@ -446,7 +443,7 @@ static struct server_command *get_cmd_ptr(const char *name, char **handler)
 }
 
 /* help */
-int com_help(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_help(struct stream_cipher_context *scc, int argc, char * const * argv)
 {
        struct server_command *cmd;
        char *perms, *handler;
@@ -454,16 +451,16 @@ int com_help(struct rc4_context *rc4c, int argc, char * const * argv)
 
        if (argc < 2) {
                /* no argument given, print list of commands */
-               if ((ret = send_list_of_commands(rc4c, server_cmds, "server")) < 0)
+               if ((ret = send_list_of_commands(scc, server_cmds, "server")) < 0)
                        return ret;
-               return send_list_of_commands(rc4c, afs_cmds, "afs");
+               return send_list_of_commands(scc, afs_cmds, "afs");
        }
        /* argument given for help */
        cmd = get_cmd_ptr(argv[1], &handler);
        if (!cmd)
                return -E_BAD_CMD;
        perms = cmd_perms_itohuman(cmd->perms);
-       ret = rc4_send_va_buffer(rc4c,
+       ret = sc_send_va_buffer(scc,
                "%s - %s\n\n"
                "handler: %s\n"
                "permissions: %s\n"
@@ -482,7 +479,7 @@ int com_help(struct rc4_context *rc4c, int argc, char * const * argv)
 }
 
 /* hup */
-int com_hup(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_hup(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -491,7 +488,7 @@ int com_hup(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * con
 }
 
 /* term */
-int com_term(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_term(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -499,7 +496,7 @@ int com_term(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co
        return 1;
 }
 
-int com_play(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_play(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -512,7 +509,7 @@ int com_play(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co
 }
 
 /* stop */
-int com_stop(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_stop(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -525,7 +522,7 @@ int com_stop(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co
 }
 
 /* pause */
-int com_pause(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_pause(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -540,7 +537,7 @@ int com_pause(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * c
 }
 
 /* next */
-int com_next(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_next(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -552,7 +549,7 @@ int com_next(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co
 }
 
 /* nomore */
-int com_nomore(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_nomore(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
@@ -564,7 +561,7 @@ int com_nomore(__a_unused struct rc4_context *rc4c, int argc, __a_unused char *
 }
 
 /* ff */
-int com_ff(__a_unused struct rc4_context *rc4c, int argc, char * const * argv)
+int com_ff(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv)
 {
        long promille;
        int ret, backwards = 0;
@@ -603,7 +600,7 @@ out:
 }
 
 /* jmp */
-int com_jmp(__a_unused struct rc4_context *rc4c, int argc, char * const * argv)
+int com_jmp(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv)
 {
        long unsigned int i;
        int ret;
@@ -657,7 +654,7 @@ static struct server_command *parse_cmd(const char *cmdstr)
        return get_cmd_ptr(buf, NULL);
 }
 
-static int read_command(struct rc4_context *rc4c, char **result)
+static int read_command(struct stream_cipher_context *scc, char **result)
 {
        int ret;
        char buf[4096];
@@ -667,7 +664,7 @@ static int read_command(struct rc4_context *rc4c, char **result)
                size_t numbytes;
                char *p;
 
-               ret = rc4_recv_buffer(rc4c, buf, sizeof(buf));
+               ret = sc_recv_buffer(scc, buf, sizeof(buf));
                if (ret < 0)
                        goto out;
                if (!ret)
@@ -712,7 +709,7 @@ static void reset_signals(void)
  * calls this function.
  *
  * An RSA-based challenge/response is used to authenticate
- * the peer. It that authentication succeeds, a random RC4
+ * the peer. It that authentication succeeds, a random
  * session key is generated and sent back to the peer,
  * encrypted with its RSA public key.  From this point on,
  * all transfers are crypted with this session key.
@@ -726,20 +723,20 @@ static void reset_signals(void)
  * which terminates the function if the connection was not
  * authenticated when the timeout expires.
  *
- * \sa alarm(2), rc4(3), crypt.c, crypt.h
+ * \sa alarm(2), crypt.c, crypt.h
  */
 __noreturn void handle_connect(int fd, const char *peername)
 {
        int ret, argc;
        char buf[4096];
-       unsigned char rand_buf[CHALLENGE_SIZE + 2 * RC4_KEY_LEN];
-       unsigned char challenge_sha1[HASH_SIZE];
+       unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
+       unsigned char challenge_hash[HASH_SIZE];
        struct user *u;
        struct server_command *cmd = NULL;
        char **argv = NULL;
        char *p, *command = NULL;
        size_t numbytes;
-       struct rc4_context rc4c = {.fd = fd};
+       struct stream_cipher_context scc = {.fd = fd};
 
        reset_signals();
        /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
@@ -769,7 +766,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        u = lookup_user(p);
        if (u) {
                get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
-               ret = para_encrypt_buffer(u->rsa, rand_buf, sizeof(rand_buf),
+               ret = pub_encrypt(u->pubkey, rand_buf, sizeof(rand_buf),
                        (unsigned char *)buf);
                if (ret < 0)
                        goto net_err;
@@ -798,26 +795,25 @@ __noreturn void handle_connect(int fd, const char *peername)
        if (!u)
                goto net_err;
        /*
-        * The correct response is the sha1 of the first CHALLENGE_SIZE bytes
+        * The correct response is the hash of the first CHALLENGE_SIZE bytes
         * of the random data.
         */
        ret = -E_BAD_AUTH;
        if (numbytes != HASH_SIZE)
                goto net_err;
-       sha1_hash((char *)rand_buf, CHALLENGE_SIZE, challenge_sha1);
-       if (memcmp(challenge_sha1, buf, HASH_SIZE))
+       hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
+       if (memcmp(challenge_hash, buf, HASH_SIZE))
                goto net_err;
        /* auth successful */
        alarm(0);
        PARA_INFO_LOG("good auth for %s\n", u->name);
-       /* init rc4 keys with the second part of the random buffer */
-       RC4_set_key(&rc4c.recv_key, RC4_KEY_LEN, rand_buf + CHALLENGE_SIZE);
-       RC4_set_key(&rc4c.send_key, RC4_KEY_LEN, rand_buf + CHALLENGE_SIZE
-               + RC4_KEY_LEN);
-       ret = rc4_send_buffer(&rc4c, PROCEED_MSG);
+       /* init stream cipher keys with the second part of the random buffer */
+       scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
+       scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN);
+       ret = sc_send_buffer(&scc, PROCEED_MSG);
        if (ret < 0)
                goto net_err;
-       ret = read_command(&rc4c, &command);
+       ret = read_command(&scc, &command);
        if (ret == -E_COMMAND_SYNTAX)
                goto err_out;
        if (ret < 0)
@@ -837,7 +833,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        argc = ret;
        PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name,
                        peername);
-       ret = cmd->handler(&rc4c, argc, argv);
+       ret = cmd->handler(&scc, argc, argv);
        free_argv(argv);
        mutex_lock(mmd_mutex);
        mmd->num_commands++;
@@ -845,11 +841,13 @@ __noreturn void handle_connect(int fd, const char *peername)
        if (ret >= 0)
                goto out;
 err_out:
-       rc4_send_va_buffer(&rc4c, "%s\n", para_strerror(-ret));
+       sc_send_va_buffer(&scc, "%s\n", para_strerror(-ret));
 net_err:
        PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 out:
        free(command);
+       sc_free(scc.recv);
+       sc_free(scc.send);
        mutex_lock(mmd_mutex);
        if (cmd && (cmd->perms & AFS_WRITE) && ret >= 0)
                mmd->events++;
index 347dd81ceedc753eb7f89a204ae5372ddb079dc7..fd879829de5683c1adeefe9b7a957df62d247a43 100644 (file)
--- a/command.h
+++ b/command.h
@@ -7,7 +7,7 @@ struct server_command {
        /** The name of the command. */
        const char *name;
        /** Pointer to the function that handles the command. */
-       int (*handler)(struct rc4_context *, int, char * const * const);
+       int (*handler)(struct stream_cipher_context *, int, char * const * const);
        /** The privileges a user must have to execute this command. */
        unsigned int perms;
        /** One-line description of the command. */
index 847f87e4ccdd379330c36ed27dc65db4ecc96edb..8f82b39318103dd73b44315ddaa3548912320bbc 100755 (executable)
@@ -200,14 +200,6 @@ dump_proto()
        echo '/**'
        echo " * $desc_txt"
        echo ' *'
-       if [[ "$system_includes" =~ openssl/rc4.h ]]; then
-               echo ' * \param rc4c The rc4 crypt context.'
-       else
-               echo ' * \param fd The file descriptor to send output to.'
-       fi
-       echo ' * \param argc The number of arguments.'
-       echo ' * \param argv The argument vector.'
-       echo ' * '
        echo " * Usage: $usage_txt"
        echo ' * '
        echo "$help_txt" | sed -e 's/^/ * /g'
index e5a23438dbdcb989abe8d1f4556bc4f1bd689fa5..32381c6b1ceec6dfd2586a1f73c0cdd4804ce855 100644 (file)
@@ -87,7 +87,7 @@ AC_DEFUN([add_cmdline],[$(for i in $@; do printf "${i}.cmdline "; done)])
 all_errlist_objs="server mp3_afh afh_common vss command net string signal time
 daemon stat crypt http_send close_on_fork ipc acl afh fade amp_filter
 dccp_send fd user_list chunk_queue afs aft mood score attribute blob ringbuffer
-playlist sha1 sched audiod grab_client filter_common wav_filter compress_filter
+playlist sched audiod grab_client filter_common wav_filter compress_filter
 http_recv dccp_recv recv_common write_common file_write audiod_command
 client_common recv stdout filter stdin audioc write client exec send_common ggo
 udp_recv udp_send color fec fecdec_filter prebuffer_filter mm
@@ -118,7 +118,7 @@ audiod_cmdline_objs="add_cmdline(audiod compress_filter http_recv dccp_recv file
 audiod_errlist_objs="audiod signal string daemon stat net
        time grab_client filter_common wav_filter compress_filter amp_filter http_recv dccp_recv
        recv_common fd sched write_common file_write audiod_command crypt fecdec_filter
-       client_common ggo udp_recv color fec prebuffer_filter sha1 audiod_command_list
+       client_common ggo udp_recv color fec prebuffer_filter audiod_command_list
        bitstream imdct wma_common wmadec_filter buffer_tree"
 audiod_ldflags="-lm"
 audiod_audio_formats="wma"
@@ -131,7 +131,7 @@ server_cmdline_objs="add_cmdline(server)"
 server_errlist_objs="server afh_common mp3_afh vss command net string signal
        time daemon crypt http_send close_on_fork mm
        ipc dccp_send fd user_list chunk_queue afs aft mood score attribute
-       blob playlist sha1 sched acl send_common udp_send color fec
+       blob playlist sched acl send_common udp_send color fec
        server_command_list afs_command_list wma_afh wma_common"
 server_ldflags=""
 server_audio_formats="mp3 wma"
@@ -145,7 +145,7 @@ default_writer="FILE_WRITE"
 
 client_cmdline_objs="add_cmdline(client)"
 client_errlist_objs="client net string crypt fd sched stdin stdout time
-       client_common sha1 buffer_tree"
+       client_common buffer_tree"
 client_ldflags=""
 
 gui_cmdline_objs="add_cmdline(gui)"
@@ -273,46 +273,52 @@ fi
 CPPFLAGS="$OLD_CPPFLAGS"
 LDFLAGS="$OLD_LDFLAGS"
 LIBS="$OLD_LIBS"
-########################################################################### ssl
-dnl @synopsis CHECK_SSL
-dnl
-dnl based on the follwing macro from the autoconf archive
-dnl
-dnl @category InstalledPackages
-dnl @author Mark Ethan Trostler <trostler@juniper.net>
-dnl @version 2003-01-28
-dnl @license AllPermissive
-
-AC_DEFUN([CHECK_SSL],
-[
-       for ssldir in $1 /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr; do
-               AC_MSG_CHECKING(for openssl in $ssldir)
-               if test -f "$ssldir/include/openssl/ssl.h"; then
-                       found_ssl="yes"
-                       AC_MSG_RESULT(yes)
-                       SSL_CFLAGS="-I$ssldir/include"
-                       SSL_CPPFLAGS="-I$ssldir/include"
-                       break
-               fi
-               AC_MSG_RESULT(no)
-       done
-       if test x_$found_ssl != x_yes; then
-               AC_MSG_ERROR(Cannot find ssl libraries)
-       else
-               SSL_LIBS="-lssl -lcrypto";
-               SSL_LDFLAGS="-L$ssldir/lib";
+###################################################################### openssl
+OLD_CPPFLAGS="$CPPFLAGS"
+OLD_LD_FLAGS="$LDFLAGS"
+OLD_LIBS="$LIBS"
+have_openssl="yes"
+AC_ARG_WITH(openssl_headers, [AC_HELP_STRING(--with-openssl-headers=dir,
+       [look for openssl headers also in dir])])
+if test -n "$with_openssl_headers"; then
+       openssl_cppflags="-I$with_openssl_headers"
+       CPPFLAGS="$CPPFLAGS $openssl_cppflags"
+fi
+AC_ARG_WITH(openssl_libs, [AC_HELP_STRING(--with-openssl-libs=dir,
+       [look for openssl libraries also in dir])])
+if test -n "$with_openssl_libs"; then
+       openssl_libs="-L$with_openssl_libs"
+       LDFLAGS="$LDFLAGS $openssl_libs"
+fi
+AC_CHECK_HEADER(openssl/ssl.h, [], [have_openssl="no"])
+AC_CHECK_LIB([crypto], [RAND_bytes], [], [have_openssl="no"])
+if test "$have_openssl" = "no" -a -z "$with_openssl_headers$with_openssl_libs"; then
+       # try harder: openssl is sometimes installed in /usr/local/ssl
+       openssl_cppflags="-I/usr/local/ssl/include"
+       CPPFLAGS="$CPPFLAGS $openssl_cppflags"
+       openssl_libs="-L/usr/local/ssl/lib"
+       LDFLAGS="$LDFLAGS $openssl_libs"
+       # clear cache
+       unset ac_cv_header_openssl_ssl_h 2> /dev/null
+       unset ac_cv_lib_crypto_RAND_bytes 2> /dev/null
+       AC_CHECK_HEADER(openssl/ssl.h, [have_openssl="yes"], [])
+       if test "$have_openssl" = "yes"; then
+               AC_CHECK_LIB([crypto], [RAND_bytes], [], [have_openssl="no"])
        fi
-       AC_SUBST(SSL_CPPFLAGS)
-])dnl
-
-AC_ARG_ENABLE(ssldir, [AS_HELP_STRING(--enable-ssldir=path,
-       [Search for openssl also in path.])])
-if test "$enable_ssldir" = "yes"; then enable_ssldir=""; fi
-CHECK_SSL($enable_ssldir)
-server_ldflags="$server_ldflags $SSL_LDFLAGS $SSL_LIBS"
-client_ldflags="$client_ldflags $SSL_LDFLAGS $SSL_LIBS"
-audiod_ldflags="$audiod_ldflags $SSL_LDFLAGS $SSL_LIBS"
-
+fi
+if test "$have_openssl" = "yes"; then
+       AC_DEFINE(HAVE_OPENSSL, 1, [define to 1 to turn on openssl support])
+       AC_SUBST(openssl_cppflags)
+       openssl_libs="$openssl_libs -lssl -lcrypto"
+       server_ldflags="$server_ldflags $openssl_libs"
+       client_ldflags="$client_ldflags $openssl_libs"
+       audiod_ldflags="$audiod_ldflags $openssl_libs"
+else
+       AC_MSG_ERROR([openssl libraries not found])
+fi
+CPPFLAGS="$OLD_CPPFLAGS"
+LDFLAGS="$OLD_LDFLAGS"
+LIBS="$OLD_LIBS"
 ########################################################################### libsocket
 AC_CHECK_LIB([c], [socket],
        [socket_lib=],
diff --git a/crypt.c b/crypt.c
index cdcb6149d04254a0def3bcc903823f71ae3a89e5..8e1814dd3d82e5fd1d50301402faea6b0d9a9934 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -4,21 +4,27 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file crypt.c openssl-based RSA encryption/decryption routines */
+/** \file crypt.c Openssl-based encryption/decryption routines. */
 
 #include <regex.h>
-#include <dirent.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <openssl/rand.h>
 #include <openssl/err.h>
 #include <openssl/rc4.h>
+#include <openssl/pem.h>
+#include <openssl/sha.h>
 
 #include "para.h"
 #include "error.h"
 #include "string.h"
 #include "crypt.h"
 #include "fd.h"
+
+struct asymmetric_key {
+       RSA *rsa;
+};
+
 /**
  * Fill a buffer with random content.
  *
@@ -102,50 +108,58 @@ static EVP_PKEY *load_key(const char *file, int private)
 }
 
 /**
- * read an RSA key from a file
+ * Read an asymmetric key from a file.
  *
- * \param key_file the file containing the key
- * \param rsa RSA structure is returned here
- * \param private if non-zero, read the private key, otherwise the public key
+ * \param key_file The file containing the key.
+ * \param private if non-zero, read the private key, otherwise the public key.
+ * \param result The key structure is returned here.
  *
- * \return The size of the RSA key on success, negative on errors.
+ * \return The size of the key on success, negative on errors.
  *
  * \sa openssl(1), rsa(1).
  */
-int get_rsa_key(char *key_file, RSA **rsa, int private)
+int get_asymmetric_key(const char *key_file, int private,
+               struct asymmetric_key **result)
 {
-       EVP_PKEY *key = load_key(key_file, private);
+       struct asymmetric_key *key;
+       RSA *rsa;
+       EVP_PKEY *pkey = load_key(key_file, private);
 
-       if (!key)
+       if (!pkey)
                return (private == LOAD_PRIVATE_KEY)? -E_PRIVATE_KEY
                        : -E_PUBLIC_KEY;
-       *rsa = EVP_PKEY_get1_RSA(key);
-       EVP_PKEY_free(key);
-       if (!*rsa)
+       rsa = EVP_PKEY_get1_RSA(pkey);
+       EVP_PKEY_free(pkey);
+       if (!rsa)
                return -E_RSA;
-       return RSA_size(*rsa);
+       key = para_malloc(sizeof(*key));
+       key->rsa = rsa;
+       *result = key;
+       return RSA_size(rsa);
 }
 
 /**
- * free an RSA structure
+ * Deallocate an asymmetric key structure.
  *
- * \param rsa pointer to the RSA struct to free
+ * \param key Pointer to the key structure to free.
  *
- * This must be called for any key obtained by get_rsa_key().
+ * This must be called for any key obtained by get_asymmetric_key().
  */
-void rsa_free(RSA *rsa)
+void free_asymmetric_key(struct asymmetric_key *key)
 {
-       if (rsa)
-               RSA_free(rsa);
+       if (!key)
+               return;
+       RSA_free(key->rsa);
+       free(key);
 }
 
 /**
- * decrypt a buffer using an RSA key
+ * Decrypt a buffer using a private key.
  *
- * \param key_file full path of the rsa key
- * \param outbuf the output buffer
- * \param inbuf the encrypted input buffer
- * \param rsa_inlen the length of \a inbuf
+ * \param key_file Full path of the key.
+ * \param outbuf The output buffer.
+ * \param inbuf The encrypted input buffer.
+ * \param inlen The length of \a inbuf in bytes.
  *
  * The \a outbuf must be large enough to hold at least \a rsa_inlen bytes.
  *
@@ -153,15 +167,15 @@ void rsa_free(RSA *rsa)
  *
  * \sa RSA_private_decrypt(3)
  **/
-int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *inbuf,
-                       unsigned rsa_inlen)
+int priv_decrypt(const char *key_file, unsigned char *outbuf,
+               unsigned char *inbuf, int inlen)
 {
-       RSA *rsa;
-       int ret, inlen = rsa_inlen;
+       struct asymmetric_key *priv;
+       int ret;
 
        if (inlen < 0)
                return -E_RSA;
-       ret = get_rsa_key(key_file, &rsa, LOAD_PRIVATE_KEY);
+       ret = get_asymmetric_key(key_file, LOAD_PRIVATE_KEY, &priv);
        if (ret < 0)
                return ret;
        /*
@@ -169,46 +183,82 @@ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *in
         * factor to protect against this kind of attack.
         */
        ret = -E_BLINDING;
-       if (RSA_blinding_on(rsa, NULL) == 0)
+       if (RSA_blinding_on(priv->rsa, NULL) == 0)
                goto out;
-       ret = RSA_private_decrypt(inlen, inbuf, outbuf, rsa, RSA_PKCS1_OAEP_PADDING);
-       RSA_blinding_off(rsa);
+       ret = RSA_private_decrypt(inlen, inbuf, outbuf, priv->rsa,
+               RSA_PKCS1_OAEP_PADDING);
+       RSA_blinding_off(priv->rsa);
        if (ret <= 0)
                ret = -E_DECRYPT;
 out:
-       rsa_free(rsa);
+       free_asymmetric_key(priv);
        return ret;
 }
 
 /**
- * encrypt a buffer using an RSA key
+ * Encrypt a buffer using an RSA key
  *
- * \param rsa: public rsa key
- * \param inbuf the input buffer
- * \param len the length of \a inbuf
- * \param outbuf the output buffer
+ * \param pub: The public key.
+ * \param inbuf The input buffer.
+ * \param len The length of \a inbuf.
+ * \param outbuf The output buffer.
  *
- * \return The size of the encrypted data on success, negative on errors
+ * \return The size of the encrypted data on success, negative on errors.
  *
  * \sa RSA_public_encrypt(3)
  */
-int para_encrypt_buffer(RSA *rsa, unsigned char *inbuf,
+int pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf,
                unsigned len, unsigned char *outbuf)
 {
        int ret, flen = len; /* RSA_public_encrypt expects a signed int */
 
        if (flen < 0)
                return -E_ENCRYPT;
-       ret = RSA_public_encrypt(flen, inbuf, outbuf, rsa, RSA_PKCS1_OAEP_PADDING);
+       ret = RSA_public_encrypt(flen, inbuf, outbuf, pub->rsa,
+               RSA_PKCS1_OAEP_PADDING);
        return ret < 0? -E_ENCRYPT : ret;
 }
 
+struct stream_cipher {
+       RC4_KEY key;
+};
+
+/**
+ * Allocate and initialize a stream cipher structure.
+ *
+ * \param data The key.
+ * \param len The size of the key.
+ *
+ * \return A new stream cipher structure.
+ */
+struct stream_cipher *sc_new(const unsigned char *data, int len)
+{
+       struct stream_cipher *sc = para_malloc(sizeof(*sc));
+       RC4_set_key(&sc->key, len, data);
+       return sc;
+}
+
+/**
+ * Deallocate a stream cipher structure.
+ *
+ * \param sc A stream cipher previously obtained by sc_new().
+ */
+void sc_free(struct stream_cipher *sc)
+{
+       free(sc);
+}
+
+/**
+ * The RC4() implementation of openssl apparently reads and writes data in
+ * blocks of 8 bytes. So we have to make sure our buffer sizes are a multiple
+ * of this.
+ */
 #define RC4_ALIGN 8
 
 /**
  * Encrypt and send a buffer.
  *
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
  * \param buf The buffer to send.
  * \param len The size of \a buf in bytes.
  *
@@ -216,7 +266,8 @@ int para_encrypt_buffer(RSA *rsa, unsigned char *inbuf,
  *
  * \sa \ref write_all(), RC4(3).
  */
-int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len)
+int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf,
+               size_t len)
 {
        int ret;
        unsigned char *tmp;
@@ -225,12 +276,12 @@ int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len)
 
        assert(len);
        tmp = para_malloc(l2);
-       RC4(&rc4c->send_key, l1, (const unsigned char *)buf, tmp);
+       RC4(&scc->send->key, l1, (const unsigned char *)buf, tmp);
        if (len > l1) {
                memcpy(remainder, buf + l1, len - l1);
-               RC4(&rc4c->send_key, len - l1, remainder, tmp + l1);
+               RC4(&scc->send->key, len - l1, remainder, tmp + l1);
        }
-       ret = write_all(rc4c->fd, (char *)tmp, &len);
+       ret = write_all(scc->fd, (char *)tmp, &len);
        free(tmp);
        return ret;
 }
@@ -238,31 +289,32 @@ int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len)
 /**
  * Encrypt and send a \p NULL-terminated buffer.
  *
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
  * \param buf The buffer to send.
  *
- * \return The return value of the underyling call to rc4_send_bin_buffer().
+ * \return The return value of the underyling call to sc_send_bin_buffer().
  */
-int rc4_send_buffer(struct rc4_context *rc4c, const char *buf)
+int sc_send_buffer(struct stream_cipher_context *scc, const char *buf)
 {
-       return rc4_send_bin_buffer(rc4c, buf, strlen(buf));
+       return sc_send_bin_buffer(scc, buf, strlen(buf));
 }
 
 /**
  * Format, encrypt and send a buffer.
  *
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
  * \param fmt A format string.
  *
- * \return The return value of the underyling call to rc4_send_buffer().
+ * \return The return value of the underyling call to sc_send_buffer().
  */
-__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...)
+__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
+               const char *fmt, ...)
 {
        char *msg;
        int ret;
 
        PARA_VSPRINTF(fmt, msg);
-       ret = rc4_send_buffer(rc4c, msg);
+       ret = sc_send_buffer(scc, msg);
        free(msg);
        return ret;
 }
@@ -270,7 +322,7 @@ __printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, .
 /**
  * Receive a buffer and decrypt it.
  *
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
  * \param buf The buffer to write the decrypted data to.
  * \param size The size of \a buf.
  *
@@ -279,13 +331,14 @@ __printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, .
  *
  * \sa recv(2), RC4(3).
  */
-int rc4_recv_bin_buffer(struct rc4_context *rc4c, char *buf, size_t size)
+int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
+               size_t size)
 {
        unsigned char *tmp = para_malloc(size);
-       ssize_t ret = recv(rc4c->fd, tmp, size, 0);
+       ssize_t ret = recv(scc->fd, tmp, size, 0);
 
        if (ret > 0)
-               RC4(&rc4c->recv_key, ret, tmp, (unsigned char *)buf);
+               RC4(&scc->recv->key, ret, tmp, (unsigned char *)buf);
        else if (ret < 0)
                ret = -ERRNO_TO_PARA_ERROR(errno);
        free(tmp);
@@ -295,26 +348,44 @@ int rc4_recv_bin_buffer(struct rc4_context *rc4c, char *buf, size_t size)
 /**
  * Receive a buffer, decrypt it and write terminating NULL byte.
  *
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
  * \param buf The buffer to write the decrypted data to.
  * \param size The size of \a buf.
  *
- * Read at most \a size - 1 bytes from file descriptor given by \a rc4c,
- * decrypt the received data and write a NULL byte at the end of the decrypted
- * data.
+ * Read at most \a size - 1 bytes from file descriptor given by \a scc, decrypt
+ * the received data and write a NULL byte at the end of the decrypted data.
  *
  * \return The return value of the underlying call to \ref
- * rc4_recv_bin_buffer().
+ * sc_recv_bin_buffer().
  */
-int rc4_recv_buffer(struct rc4_context *rc4c, char *buf, size_t size)
+int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size)
 {
        int n;
 
        assert(size);
-       n = rc4_recv_bin_buffer(rc4c, buf, size - 1);
+       n = sc_recv_bin_buffer(scc, buf, size - 1);
        if (n >= 0)
                buf[n] = '\0';
        else
                *buf = '\0';
        return n;
 }
+
+/**
+ * Compute the hash of the given input data.
+ *
+ * \param data Pointer to the data to compute the hash value from.
+ * \param len The length of \a data in bytes.
+ * \param hash Result pointer.
+ *
+ * \a hash must point to an area at least \p HASH_SIZE bytes large.
+ *
+ * \sa sha(3), openssl(1).
+ * */
+void hash_function(const char *data, unsigned long len, unsigned char *hash)
+{
+       SHA_CTX c;
+       SHA1_Init(&c);
+       SHA1_Update(&c, data, len);
+       SHA1_Final(hash, &c);
+}
diff --git a/crypt.h b/crypt.h
index 6bd8179bbe90b8162bcc7d3a9af5736cd21d2677..21abe41f68cd8c5b335cc133b5c6f3050869c4ee 100644 (file)
--- a/crypt.h
+++ b/crypt.h
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file crypt.h prototypes for the RSA crypt functions */
+/** \file crypt.h Prototypes for paraslash crypto functions. */
 
-#include <openssl/pem.h>
-int para_encrypt_buffer(RSA* rsa, unsigned char *inbuf, unsigned len,
-       unsigned char *outbuf);
-int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *inbuf,
-       unsigned rsa_inlen);
-int get_rsa_key(char *key_file, RSA **rsa, int private);
+/** Opaque structure for public and private keys. */
+struct asymmetric_key;
+
+int pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf,
+               unsigned len, unsigned char *outbuf);
+int priv_decrypt(const char *key_file, unsigned char *outbuf,
+               unsigned char *inbuf, int inlen);
+int get_asymmetric_key(const char *key_file, int private,
+               struct asymmetric_key **result);
+void free_asymmetric_key(struct asymmetric_key *key);
 
-void rsa_free(RSA *rsa);
 void get_random_bytes_or_die(unsigned char *buf, int num);
 void init_random_seed_or_die(void);
 
+/** Opaque structure for stream cipher crypto. */
+struct stream_cipher;
+
+/** Number of bytes of the session key. */
+#define SESSION_KEY_LEN 32
+
 /**
  * Used on the server-side for client-server communication encryption.
  *
- * The traffic between (the forked child of) para_server and the remote
- * client process is crypted by a RC4 session key. This structure contains
- * the RC4 keys and the file descriptor for which these keys should be used.
+ * The traffic between (the forked child of) para_server and the remote client
+ * process is crypted by a symmetric session key. This structure contains the
+ * keys for the stream cipher and the file descriptor for which these keys
+ * should be used.
  */
-struct rc4_context {
+struct stream_cipher_context {
        /** The socket file descriptor. */
        int fd;
-       /** Key used for sending data. */
-       RC4_KEY recv_key;
        /** Key used for receiving data. */
-       RC4_KEY send_key;
+       struct stream_cipher *recv;
+       /** Key used for sending data. */
+       struct stream_cipher *send;
 };
-int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len);
-int rc4_send_buffer(struct rc4_context *rc4c, const char *buf);
-__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...);
-int rc4_recv_bin_buffer(struct rc4_context *rcc, char *buf, size_t size);
-int rc4_recv_buffer(struct rc4_context *rcc, char *buf, size_t size);
+
+struct stream_cipher *sc_new(const unsigned char *data, int len);
+void sc_free(struct stream_cipher *sc);
+
+int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf,
+               size_t len);
+int sc_send_buffer(struct stream_cipher_context *scc, const char *buf);
+__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
+               const char *fmt, ...);
+int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
+               size_t size);
+int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size);
 
 /** \cond used to distinguish between loading of private/public key */
 #define LOAD_PUBLIC_KEY 0
 #define LOAD_PRIVATE_KEY 1
 #define CHALLENGE_SIZE 64
 /** \endcond **/
+
+/** Size of the hash value in bytes. */
+#define HASH_SIZE 20
+
+void hash_function(const char *data, unsigned long len, unsigned char *hash);
+
+/**
+ * Compare two hashes.
+ *
+ * \param h1 Pointer to the first hash value.
+ * \param h2 Pointer to the second hash value.
+ *
+ * \return 1, -1, or zero, depending on whether \a h1 is greater than,
+ * less than or equal to h2, respectively.
+ */
+_static_inline_ int hash_compare(unsigned char *h1, unsigned char *h2)
+{
+       int i;
+
+       for (i = 0; i < HASH_SIZE; i++) {
+               if (h1[i] < h2[i])
+                       return -1;
+               if (h1[i] > h2[i])
+                       return 1;
+       }
+       return 0;
+}
+
+/**
+ * Convert a hash value to ascii format.
+ *
+ * \param hash the hash value.
+ * \param asc Result pointer.
+ *
+ * \a asc must point to an area of at least 2 * \p HASH_SIZE + 1 bytes which
+ * will be filled by the function with the ascii representation of the hash
+ * value given by \a hash, and a terminating \p NULL byte.
+ */
+_static_inline_ void hash_to_asc(unsigned char *hash, char *asc)
+{
+       int i;
+       const char hexchar[] = "0123456789abcdef";
+
+       for (i = 0; i < HASH_SIZE; i++) {
+               asc[2 * i] = hexchar[hash[i] >> 4];
+               asc[2 * i + 1] = hexchar[hash[i] & 0xf];
+       }
+       asc[2 * HASH_SIZE] = '\0';
+}
index 41c2ee1a690a82ebee2623c3f79efe21b8e364e2..af8e6b1657e86777af5f6360c573c60bcc46e93c 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 
 #include "para.h"
 #include "error.h"
@@ -39,7 +38,6 @@ struct private_dccp_recv_data {
        struct btr_pool *btrp;
 };
 
-
 static void dccp_recv_close(struct receiver_node *rn)
 {
 
@@ -52,7 +50,6 @@ static void dccp_recv_close(struct receiver_node *rn)
        rn->private_data = NULL;
 }
 
-
 static int dccp_recv_open(struct receiver_node *rn)
 {
        struct private_dccp_recv_data *pdd;
index 304a42e749a647d5d6a568ae0e9850d183907979..0484778eb593d342eaa0fd961a521e587a5ef468 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <osl.h>
 
 #include "para.h"
diff --git a/error.h b/error.h
index fdd2d3b7b9b6b06f8e7ba0d6a457dc249c314b3e..2e32c24044bd074cc9e311903adde6d85ac5a4c0 100644 (file)
--- a/error.h
+++ b/error.h
@@ -19,7 +19,6 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define GUI_ERRORS
 #define RINGBUFFER_ERRORS
 #define SCORE_ERRORS
-#define SHA1_ERRORS
 #define RBTREE_ERRORS
 #define RECV_ERRORS
 #define IPC_ERRORS
diff --git a/exec.c b/exec.c
index b11b217b963fd2359622d5f56688c7f51e80b766..e765dc4d8f0473290b309efd45e04318b21b6792 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -7,7 +7,6 @@
 /** \file exec.c Helper functions for spawning new processes. */
 
 #include <regex.h>
-#include <dirent.h>
 
 #include "para.h"
 #include "close_on_fork.h"
diff --git a/fade.c b/fade.c
index 41b4a6d78e2b40d80cb24e31a5b0030c37db4584..04ca923770ec069bda49d3a069fac795fd461ac1 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <sys/ioctl.h>
 #include <ctype.h>
 #include <stdlib.h> /* EXIT_SUCCESS */
index 4f3ba950d985b3548dfc926402bbaae5e1ad2434..fb2dba025d37806b2b70bd8f8002cae09e3e4db8 100644 (file)
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <stdbool.h>
 
-#include <dirent.h>
 #include "para.h"
 #include "error.h"
 #include "list.h"
index 8cafbb687b8498ff6b9db43a1129676363b3db20..bfade187a8b215ff74fb5baecee845149f360528 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <sys/time.h>
 #include <stdbool.h>
 
index 269c4d6d5fb516402d756906bdb57fc5c2be2275..566d97edc9ee7eca82525f7854c4b81aed93c04d 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"
index a85e42a967817d6d767a6f9bf52b95c6146d5369..9109c2f8f6c5f1978eddd356ff7f8e979d73dd8a 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"
diff --git a/gui.c b/gui.c
index 578eeed0c96d502767a57b5cb80f0cad2c9cfc07..c8721565ae86502319be0ed2e6257454b876f841 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <signal.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <curses.h>
 
 #include "gui.cmdline.h"
diff --git a/hash.h b/hash.h
deleted file mode 100644 (file)
index 6dfddbe..0000000
--- a/hash.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2007-2011 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
-
-/** \file hash.h Inline functions for hash values. */
-
-/** hash arrays are always unsigned char. */
-#define HASH_TYPE unsigned char
-
-#include "sha1.h"
-/** We use openssl's sha1 implementation. */
-#define hash_function sha1_hash
-
-/**
- * Compare two hashes.
- *
- * \param h1 Pointer to the first hash value.
- * \param h2 Pointer to the second hash value.
- *
- * \return 1, -1, or zero, depending on whether \a h1 is greater than,
- * less than or equal to h2, respectively.
- */
-_static_inline_ int hash_compare(HASH_TYPE *h1, HASH_TYPE *h2)
-{
-       int i;
-
-       for (i = 0; i < HASH_SIZE; i++) {
-               if (h1[i] < h2[i])
-                       return -1;
-               if (h1[i] > h2[i])
-                       return 1;
-       }
-       return 0;
-}
-
-/**
- * Convert a hash value to ascii format.
- *
- * \param hash the hash value.
- * \param asc Result pointer.
- *
- * \a asc must point to an area of at least 2 * \p HASH_SIZE + 1 bytes which
- * will be filled by the function with the ascii representation of the hash
- * value given by \a hash, and a terminating \p NULL byte.
- */
-_static_inline_ void hash_to_asc(HASH_TYPE *hash, char *asc)
-{
-       int i;
-       const char hexchar[] = "0123456789abcdef";
-
-       for (i = 0; i < HASH_SIZE; i++) {
-               asc[2 * i] = hexchar[hash[i] >> 4];
-               asc[2 * i + 1] = hexchar[hash[i] & 0xf];
-       }
-       asc[2 * HASH_SIZE] = '\0';
-}
index 53ef8e60d03f6d7afc4d5b9d7e3b7a2e71c97deb..5717692ce2133e548fee68552787cd89c9c69fc0 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 
 #include "para.h"
 #include "error.h"
index 086b600f0d043f928e6c2c0f71afa65104045f00..8ae2341a0351d9edc447f544c33fd66e0fb6c74a 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <osl.h>
 #include <stdbool.h>
 
diff --git a/net.c b/net.c
index 2369dc8ce99027a4bb122a9a9d3e71bb5aa10f8b..ffd4350b4b14bc32d8e270db2734cc97fee400df 100644 (file)
--- a/net.c
+++ b/net.c
 #define AI_ADDRCONFIG 0
 #endif
 
-#include <dirent.h>
 #include <regex.h>
-#include <openssl/rc4.h>
 
 #include "para.h"
 #include "error.h"
-#include "crypt.h"
 #include "net.h"
 #include "string.h"
 #include "list.h"
index e79ea6ced6c62f3fdfe1b6ce59cf7f7784cb9614..d583c2338bb1dc0dc96d274d49824d45a3b75c6e 100644 (file)
@@ -9,7 +9,6 @@
 #include <regex.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include <dirent.h>
 #include <sys/soundcard.h>
 #include <stdbool.h>
 
index f27a49b0f1183947763c6bae1ac31b2af1b92e3a..50f22be9a4939121f1573462ffdfd31037257aa0 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"
diff --git a/rc4.h b/rc4.h
deleted file mode 100644 (file)
index 1815e3b..0000000
--- a/rc4.h
+++ /dev/null
@@ -1,4 +0,0 @@
-/** \file rc4.h common symbols of command.c and client_common.c */
-
-/** Number of bytes of the rc4 session key. */
-#define RC4_KEY_LEN 32
diff --git a/recv.c b/recv.c
index ae8a1f663b725cbed40f763e0105fd04d2d4dcc9..52f457fc29b68e61ba017079511145f4e3120885 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"
diff --git a/sched.c b/sched.c
index 9be3a2e83109f0db884c5fdebf3e7e62f4f9b3c5..8baed4962d9e5dfbf2cad170b1c38d2d42b123b3 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -7,7 +7,6 @@
 /** \file sched.c Paraslash's scheduling functions. */
 
 #include <regex.h>
-#include <dirent.h> /* readdir() */
 #include <assert.h>
 #include <sys/time.h>
 
index 6a85644d734d6c2f7fd748edf688c6cc21b18651..e786f996ad3b85218d9953a01fee6a86f34b6de4 100644 (file)
@@ -7,7 +7,6 @@
 /** \file send_common.c Functions used by more than one paraslash sender. */
 
 #include <regex.h>
-#include <dirent.h>
 #include <osl.h>
 
 #include "para.h"
index 4d54f74b63d47e52fee508a899bc3b8970d1e1b6..e8dddf5bc27a80238436811b7d2b46680cddb3d7 100644 (file)
--- a/server.c
+++ b/server.c
  *
  *     - Doubly linked lists: \ref list.h,
  *     - Ring buffer: \ref ringbuffer.c, \ref ringbuffer.h,
- *     - Hashing: \ref hash.h, \ref sha1.h, \ref sha1.c,
- *     - Crypto: \ref crypt.c.
+ *     - Crypto: \ref crypt.c, \ref crypt.h.
  *     - Forward error correction: \ref fec.c.
  */
 
 #include <signal.h>
-#include <dirent.h>
 #include <sys/time.h>
-#include <openssl/rc4.h>
 #include <regex.h>
 #include <osl.h>
 #include <stdbool.h>
index 73ee3417f405ab7620adb53f0f0242b8467e307d..d3fad648b6bd992e7485a48379abebf28e37be6e 100644 (file)
@@ -3,7 +3,7 @@ SF: command.c
 HC: prototypes for the server command handlers
 CC: array of server commands
 AT: server_command
-SI: openssl/rc4 osl regex
+SI: osl regex
 IN: para error crypt command string afh afs server list user_list
 SN: list of server commands
 ---
diff --git a/sha1.c b/sha1.c
deleted file mode 100644 (file)
index b0e955e..0000000
--- a/sha1.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2007-2011 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
-
-/** \file sha1.c Secure Hash Algorithm, provided by openssl. */
-
-#include "para.h"
-#include <openssl/sha.h>
-
-/**
- * Compute the sha1 hash.
- *
- * \param data Pointer to the data to compute the hash value from.
- * \param len The length of \a data in bytes.
- * \param sha1 Result pointer.
- *
- * \a sha1 must point to an area at least 20 bytes large.
- *
- * \sa sha(3), openssl(1).
- * */
-void sha1_hash(const char *data, unsigned long len, unsigned char *sha1)
-{
-       SHA_CTX c;
-       SHA1_Init(&c);
-       SHA1_Update(&c, data, len);
-       SHA1_Final(sha1, &c);
-}
diff --git a/sha1.h b/sha1.h
deleted file mode 100644 (file)
index 4d21733..0000000
--- a/sha1.h
+++ /dev/null
@@ -1,5 +0,0 @@
-/** \file sha1.h Secure Hash Algorithm prototype */
-
-/** Size of the hash value in bytes. */
-#define HASH_SIZE 20
-void sha1_hash(const char *data, unsigned long len, unsigned char *sha1);
index 4726571c40da9a166fcef51655b2d20d87fd59b0..f02c453a04a02e5d3e1c8a9c791aba8275a60671 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -7,7 +7,6 @@
 
 #include <signal.h>
 #include <sys/types.h>
-#include <dirent.h>
 
 #include "para.h"
 #include "error.h"
diff --git a/stdin.c b/stdin.c
index e625f3726789972386de10c8af86d68b206e82c4..14dd9d40f4d56e2cb5845fa95546db7a7baa8581 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -6,7 +6,6 @@
 
 /** \file stdin.c Functions that deal with reading from stdin. */
 
-#include <dirent.h> /* readdir() */
 #include <assert.h>
 #include <stdbool.h>
 #include <regex.h>
index 5604fced075f5c2b24b8df622c6e0ad5c3a320dc..a2ee2aca6af8114eadf92539092bcca9bb7d0e09 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -6,7 +6,6 @@
 
 /** \file stdout.c Functions that deal with writing to stdout. */
 
-#include <dirent.h> /* readdir() */
 #include <assert.h>
 #include <stdbool.h>
 
index e276343ea1aae1b2a750389c4c691170b9c3aa6e..45d24eae2cd40e9ee4b53106b92ccb85c779dc85 100644 (file)
@@ -6,7 +6,6 @@
 /** \file udp_recv.c Paraslash's udp receiver */
 
 #include <regex.h>
-#include <dirent.h>
 #include <sys/socket.h>
 #include <net/if.h>
 
index b4494eb7edb9e9fd26c1f4d20e9b81b06472c625..7a1a89f73e1ab79d91fa2e0978072eaf9e10fc46 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <regex.h>
 #include <sys/time.h>
-#include <dirent.h>
 #include <sys/socket.h>
 #include <netinet/udp.h>
 #include <net/if.h>
index fe1b946b1e96596ce6cd8c7949407bf7a341cfb6..9de54f43b415e53600da0caef967dcf92164c8f1 100644 (file)
@@ -8,8 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
-#include <openssl/rc4.h>
 
 #include "para.h"
 #include "error.h"
@@ -18,7 +16,6 @@
 #include "string.h"
 #include "list.h"
 #include "user_list.h"
-#include "rc4.h"
 
 static struct list_head user_list;
 
@@ -41,7 +38,7 @@ static void populate_user_list(char *user_list_file)
                /* keyword, name, key, perms */
                char w[255], n[255], k[255], p[255], tmp[4][255];
                struct user *u;
-               RSA *rsa;
+               struct asymmetric_key *pubkey;
 
                ret = para_fgets(line, sizeof(line), file_ptr);
                if (ret <= 0)
@@ -51,27 +48,27 @@ static void populate_user_list(char *user_list_file)
                if (strcmp(w, "user"))
                        continue;
                PARA_DEBUG_LOG("found entry for user %s\n", n);
-               ret = get_rsa_key(k, &rsa, LOAD_PUBLIC_KEY);
+               ret = get_asymmetric_key(k, LOAD_PUBLIC_KEY, &pubkey);
                if (ret < 0) {
                        PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n,
                                para_strerror(-ret));
                        continue;
                }
                /*
-                * In order to encrypt len := CHALLENGE_SIZE + 2 * RC4_KEY_LEN
+                * In order to encrypt len := CHALLENGE_SIZE + 2 * SESSION_KEY_LEN
                 * bytes using RSA_public_encrypt() with EME-OAEP padding mode,
                 * RSA_size(rsa) must be greater than len + 41. So ignore keys
                 * which are too short. For details see RSA_public_encrypt(3).
                 */
-               if (ret <= CHALLENGE_SIZE + 2 * RC4_KEY_LEN + 41) {
-                       PARA_WARNING_LOG("rsa key %s too short (%d)\n",
+               if (ret <= CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) {
+                       PARA_WARNING_LOG("public key %s too short (%d)\n",
                                k, ret);
-                       rsa_free(rsa);
+                       free_asymmetric_key(pubkey);
                        continue;
                }
                u = para_malloc(sizeof(*u));
                u->name = para_strdup(n);
-               u->rsa = rsa;
+               u->pubkey = pubkey;
                u->perms = 0;
                num = sscanf(p, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
                        tmp[0], tmp[1], tmp[2], tmp[3]);
@@ -117,7 +114,7 @@ void init_user_list(char *user_list_file)
                list_for_each_entry_safe(u, tmp, &user_list, node) {
                        list_del(&u->node);
                        free(u->name);
-                       rsa_free(u->rsa);
+                       free_asymmetric_key(u->pubkey);
                        free(u);
                }
        } else
index cce577a60331ae955a21a774f016d2dc032dc623..68fa21b2a0185a79bcabc0136d2152595711756c 100644 (file)
@@ -20,13 +20,13 @@ enum {AFS_READ = 1, AFS_WRITE = 2, VSS_READ = 4, VSS_WRITE = 8};
  * data needed to authenticate the user
  */
 struct user {
-       /** the position of this user in the list of users */
+       /** The position of this user in the list of users. */
        struct list_head node;
-       /** the username */
+       /** The username. */
        char *name;
-       /**  the public RSA key */
-       RSA *rsa;
-       /** the privileges that this user has */
+       /** The public key. */
+       struct asymmetric_key *pubkey;
+       /** The privileges of this user. */
        unsigned int perms;
 };
 
diff --git a/vss.c b/vss.c
index ba6f7c4c655134d11d79e6411ab92d63b4efd160..dfd80ebcb817526c6e0c5c4f62eeb07ae6fc9375 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -12,7 +12,6 @@
  */
 
 #include <regex.h>
-#include <dirent.h>
 #include <osl.h>
 
 #include "para.h"
diff --git a/write.c b/write.c
index 571dc4ed8e4c0d35e253f277205975d5eac8758c..6b574414b6b13c227c98b008addd28f4b2302b33 100644 (file)
--- a/write.c
+++ b/write.c
@@ -8,7 +8,6 @@
 
 #include <regex.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <stdbool.h>
 
 #include "para.h"