dslinux/user/bitchx/dll/arcfour Makefile.in README arcfour.c arcfour.h asdf md5.c md5.h
stsp
stsp at user.in-berlin.de
Sun Jul 2 15:18:33 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/bitchx/dll/arcfour
In directory antilope:/tmp/cvs-serv9280/dll/arcfour
Added Files:
Makefile.in README arcfour.c arcfour.h asdf md5.c md5.h
Log Message:
Adding pristine copy of BitchX so I can branch from it.
--- NEW FILE: README ---
This module is incomplete. It's purpose was to implement a secure dcc chat
using RSA style encryption. If you feel like taking a stab at completing
this, please email me edwards at bitchx.dimension6.com as well as letting
humble at efnet know that you are interested.
Colten Edwards
--- NEW FILE: Makefile.in ---
SHELL = @SHELL@
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
topdir = @topdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = @oldincludedir@
local_dir = $(HOME)
# Where the BitchX binary will be installed.
# "make install" will compile and install the program.
INSTALL_IRC = @INSTALL_IRC@
# Where the BitchX library will be. Generally this is the place that
# you put the scripts, help pages and translation tables. It is
# very important that you set this correctly.
IRCLIB = @IRCLIB@
CC = @CC@
DEFS = @INCLUDES@
LIBS = @LIBS@
# Tcl library.
TCL_LIBS = @TCL_LIBS@
# These are for Tcl support.
TCL_OBJS = @TCL_OBJS@
# You don't have the following, so you'll want to leave this blank.
TCL_SRCS = @TCL_SRCS@
# Set this to -g if you want to be able to debug the client, otherwise
# use -O to have the compiler do some optimization instead.
CFLAGS = @CFLAGS@
# Set this to -s if you want the binary to be stripped.
LDFLAGS = @LDFLAGS@
# These are for the cd device player.
CD_SRCS = @CD_SRCS@
CD_OBJS = @CD_OBJS@
# This is the executable suffix for the target operating system.
EXEEXT = @EXEEXT@
# Extra files.
DEFAULT_CTOOLZ_DIR = @DEFAULT_CTOOLZ_DIR@
DEFAULT_MSGLOGFILE = @DEFAULT_MSGLOGFILE@
DEFAULT_BITCHX_HELP_FILE = @DEFAULT_BITCHX_HELP_FILE@
DEFAULT_SCRIPT_HELP_FILE = @DEFAULT_SCRIPT_HELP_FILE@
DEFAULT_BITCHX_KICK_FILE = @DEFAULT_BITCHX_KICK_FILE@
DEFAULT_BITCHX_QUIT_FILE = @DEFAULT_BITCHX_QUIT_FILE@
DEFAULT_BITCHX_IRCNAME_FILE = @DEFAULT_BITCHX_IRCNAME_FILE@
# Full path of the directory for BitchX help files.
HELPDIR = @HELPDIR@
# Full path of the directory for the BitchX scripts.
INSTALL_SCRIPT = @INSTALL_SCRIPT@
# Default setting for IRCPATH where BitchX will look for
# its script files if the environment variable is undefined.
# Usually, this should contain the same path as used for INSTALL_SCRIPT in
# the Makefile, but it can contain multiple path elements
# separated by colons. The path MUST lead to an existing directory,
# because the 'global' script is expected to be found there.
IRCPATH = @IRCPATH@
# Path for TRANSLATION variable.
TRANSLATION_PATH = @TRANSLATION_PATH@
# This command will be used to install the BitchX help files. If you don't
# want to install them, replace with the following:
# INSTALL_HELP_CMD = @echo The help files have not been installed.
INSTALL_HELP_CMD = @INSTALL_HELP_CMD@
# This is where the optional plugins will be copied to.
PLUGINDIR = @PLUGINDIR@
# Plugin flags.
SHLIB_LD = @SHLIB_LD@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_SUFFIX = @SHLIB_SUFFIX@
# This command will be used to install the BitchX files on Win32/OS2EMX
# systems.
WINNT_INSTALL = @WINNT_INSTALL@
# This program allows you to use screen/xterm's to put new BitchX windows
# on new screen/xterm windows.
INSTALL_WSERV = @INSTALL_WSERV@
# This program allows you to screen BitchX and reattach to it later.
INSTALL_SCRBX = @INSTALL_SCRBX@
# Set gzip and bzip2 options.
GZIP_ENV = @GZIP_ENV@
BZIP2 = @BZIP2@
# Standard programs.
RM = @RM@
LN = @LN_S@
CP = @CP@
MV = @MV@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
VERSION = @VERSION@
_VERSION_ = @_VERSION_@
MAKE_BIN = @MAKE@
MAKE = $(MAKE_BIN) $(MFLAGS)
MFLAGS = \
'local_dir=$(HOME)' \
'INSTALL_IRC=$(INSTALL_IRC)' \
'IRCLIB=$(IRCLIB)' \
'CC=$(CC)' \
'CFLAGS=$(CFLAGS)' \
'HELPDIR=$(HELPDIR)' \
'INSTALL_WSERV=$(INSTALL_WSERV)' \
'IRCPATH=$(IRCPATH)' \
'TRANSLATION_PATH=$(TRANSLATION_PATH)' \
'LDFLAGS=$(LDFLAGS)' \
'LIBS=$(LIBS)' \
'LN=$(LN)' \
'RM=$(RM)' \
'TCL_SRCS=$(TCL_SRCS)' \
'TCL_OBJS=$(TCL_OBJS)' \
'CD_PLAY=$(CD_PLAY)' \
'CD_SRCS=$(CD_SRCS)' \
'CD_OBJS=$(CD_OBJS)' \
'TCL_LIBS=$(TCL_LIBS)' \
'PLUGINDIR=$(PLUGINDIR)' \
'_VERSION_=$(_VERSION_)' \
'VERSION=$(VERSION)' \
'INSTALL_DATA=$(INSTALL_DATA)' \
'INSTALL_SCRIPT=$(INSTALL_SCRIPT)' \
'EXEEXT=$(EXEEXT)' \
'SHLIB_CFLAGS=$(SHLIB_CFLAGS)' \
'SHLIB_SUFFIX=$(SHLIB_SUFFIX)'
## Makefile starts here.
PLUGIN_NAME = arcfour
all: Makefile arcfour$(SHLIB_SUFFIX)
Makefile: Makefile.in
cd $(topdir) \
&& ./config.status
arcfour.o: $(srcdir)/arcfour.c
$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/arcfour.c
md5.o: $(srcdir)/md5.c
$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/md5.c
arcfour$(SHLIB_SUFFIX): arcfour.o md5.o ../dllinit.o
$(SHLIB_LD) arcfour.o md5.o ../dllinit.o $(SHLIB_CFLAGS) -o arcfour$(SHLIB_SUFFIX)
clean:
$(RM) *~ *.o arcfour$(SHLIB_SUFFIX) *.a *.def .#*
distclean: clean
$(RM) Makefile
install:
$(INSTALL) $(PLUGIN_NAME)$(SHLIB_SUFFIX) $(PLUGINDIR)
--- NEW FILE: md5.h ---
/* typedef a 32 bit type */
typedef unsigned long int UINT_32;
/* Data structure for MD5 (Message Digest) computation */
typedef struct {
UINT_32 i[2]; /* number of _bits_ handled mod 2^64 */
UINT_32 buf[4]; /* scratch buffer */
unsigned char in[64]; /* input buffer */
unsigned char digest[16]; /* actual digest after MD5Final call */
} MD5_CTX;
void MD5Final(MD5_CTX *);
void MD5Update(MD5_CTX *, unsigned char *, unsigned int);
void MD5Init(MD5_CTX *);
--- NEW FILE: arcfour.h ---
typedef unsigned char arcword; /* 8-bit groups */
typedef struct {
arcword state[256], i, j;
} arckey;
/* Prototypes */
static inline void arcfourInit(arckey *, char *, unsigned short);
static inline char *arcfourCrypt(arckey *, char *, int);
static int send_dcc_encrypt (int, int, char *, int);
static int get_dcc_encrypt (int, int, char *, int, int);
static int start_dcc_crypt (int, int, unsigned long, int);
static int end_dcc_crypt (int, unsigned long, int);
static int init_schat(char *, char *, char *, char *, char *, char *, unsigned long, unsigned int);
void dcc_sdcc (char *, char *);
--- NEW FILE: md5.c ---
/* MD5 Message Digest algorithm */
#include "md5.h"
/* Prototypes */
static void Transform(UINT_32 *, UINT_32 *);
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* F, G and H are basic MD5 functions: selection, majority, parity */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
/* Rotation is separate from addition to prevent recomputation */
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT_32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT_32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT_32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT_32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
void MD5Init(MD5_CTX *mdContext)
{
mdContext->i[0] = mdContext->i[1] = (UINT_32) 0;
/* Load magic initialization constants. */
mdContext->buf[0] = (UINT_32) 0x67452301;
mdContext->buf[1] = (UINT_32) 0xefcdab89;
mdContext->buf[2] = (UINT_32) 0x98badcfe;
mdContext->buf[3] = (UINT_32) 0x10325476;
}
void MD5Update(MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
{
unsigned int i, ii;
UINT_32 in[16];
int mdi;
/* compute number of bytes mod 64 */
mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
/* update number of bits */
if ((mdContext->i[0] + ((UINT_32) inLen << 3)) < mdContext->i[0])
mdContext->i[1]++;
mdContext->i[0] += ((UINT_32) inLen << 3);
mdContext->i[1] += ((UINT_32) inLen >> 29);
while (inLen--) {
/* add new character to buffer, increment mdi */
mdContext->in[mdi++] = *inBuf++;
/* transform if necessary */
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((UINT_32) mdContext->in[ii + 3]) << 24) |
(((UINT_32) mdContext->in[ii + 2]) << 16) |
(((UINT_32) mdContext->in[ii + 1]) << 8) |
((UINT_32) mdContext->in[ii]);
Transform(mdContext->buf, in);
mdi = 0;
}
}
}
void MD5Final(MD5_CTX *mdContext)
{
UINT_32 in[16];
unsigned int i, ii;
unsigned int padLen;
int mdi;
/* save number of bits */
in[14] = mdContext->i[0];
in[15] = mdContext->i[1];
/* compute number of bytes mod 64 */
mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
/* pad out to 56 mod 64 */
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
MD5Update(mdContext, PADDING, padLen);
/* append length in bits and transform */
for (i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((UINT_32) mdContext->in[ii + 3]) << 24) |
(((UINT_32) mdContext->in[ii + 2]) << 16) |
(((UINT_32) mdContext->in[ii + 1]) << 8) |
((UINT_32) mdContext->in[ii]);
Transform(mdContext->buf, in);
/* store buffer in digest */
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF);
mdContext->digest[ii + 1] =
(unsigned char) ((mdContext->buf[i] >> 8) & 0xFF);
mdContext->digest[ii + 2] =
(unsigned char) ((mdContext->buf[i] >> 16) & 0xFF);
mdContext->digest[ii + 3] =
(unsigned char) ((mdContext->buf[i] >> 24) & 0xFF);
}
}
/* Basic MD5 step. Transform buf based on in. */
static void Transform(UINT_32 *buf, UINT_32 *in)
{
UINT_32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF (a, b, c, d, in[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, in[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, in[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, in[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, in[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, in[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, in[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, in[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, in[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, in[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, in[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, in[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, in[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, in[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, in[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, in[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG (a, b, c, d, in[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, in[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, in[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, in[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, in[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, in[10], S22, 0x2441453 ); /* 22 */
GG (c, d, a, b, in[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, in[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, in[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, in[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, in[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, in[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, in[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, in[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, in[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, in[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH (a, b, c, d, in[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, in[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, in[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, in[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, in[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, in[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, in[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, in[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, in[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, in[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, in[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, in[ 6], S34, 0x4881d05 ); /* 44 */
HH (a, b, c, d, in[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, in[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, in[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, in[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II (a, b, c, d, in[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, in[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, in[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, in[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, in[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, in[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, in[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, in[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, in[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, in[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, in[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, in[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, in[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, in[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, in[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, in[ 9], S44, 0xeb86d391); /* 64 */
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
memset((void *)in, 0, sizeof(in));
}
#if 0
int main(int argc, char *argv[])
{
MD5_CTX md5Context;
unsigned int len = strlen(argv[1]);
unsigned char i;
MD5Init(&md5Context);
MD5Update(&md5Context, argv[1], len);
MD5Final(&md5Context);
printf("MD5sum: ");
for(i=0;i<16;i++)
printf("%02x", md5Context.digest[i]);
printf("\n");
}
#endif
--- NEW FILE: arcfour.c ---
/* ARCFour - a symmetric streaming cipher - Implimentation by Humble
*
* This is a variable-key-length symmetric stream cipher developed in 1987
* by Ron Rivest (the R in RSA). It used to be proprietary but was reverse
* engineered and released publicly in September 1994. The cipher is now
* freely available but the name RC4 is a trademark of RSA Data Security
* Inc. This cipher is secure, proven, easy to impliment, and quite fast.
*/
#define IN_MODULE
#include "irc.h"
#include "struct.h"
#include "ircaux.h"
#include "ctcp.h"
#include "status.h"
#include "lastlog.h"
#include "server.h"
#include "screen.h"
#include "vars.h"
#include "misc.h"
#include "output.h"
#include "module.h"
#include "hash2.h"
#include "hook.h"
#include "dcc.h"
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <unistd.h>
#include "arcfour.h"
#include "md5.h"
#define INIT_MODULE
#include "modval.h"
typedef struct {
int sock;
char ukey[16];
arckey *outbox;
arckey *inbox;
} arclist;
/* from dcc.c. Why isnt this in dcc.h? */
typedef struct _DCC_List
{
struct _DCC_List *next;
char *nick; /* do NOT free this. it's a shared pointer. */
SocketList sock;
} DCC_List;
static arclist *keyboxes[16];
static const double arc_ver = 1.0;
static unsigned int typenum = 0;
/*
* Initialize our box, and return the key used. It better be enough to hold
* 16 chars + 1 null!
*/
static char *init_box(char *ukey, arckey *key)
{
MD5_CTX md5context;
char buf[256];
int fd;
fd = open("/dev/urandom", O_RDONLY);
if (fd >= 0) {
read(fd, buf, sizeof(buf));
close(fd);
}
else
{
buf[(int)buf[69]] ^= getpid();
buf[(int)buf[226]] ^= getuid();
buf[(int)buf[119]] ^= getpid();
}
MD5Init(&md5context);
MD5Update(&md5context, buf, sizeof(buf));
MD5Final(&md5context);
memcpy(ukey, buf, 16);
ukey[16] = '\0';
arcfourInit(key, md5context.digest, 16);
return ukey;
}
static inline void arcfourInit(arckey *arc, char *userkey, unsigned short len)
{
register arcword *S = arc->state, x = 0, y = 0, pos = 0, tmp;
/* Seed the S-box linearly, then mix in the key while stiring briskly */
arc->i = arc->j = 0; /* Initialize i and j to 0 */
while((S[x] = --x)); /* Initialize S-box, backwards */
/* Note: Some of these optimizations REQUIRE arcword to be 8-bit unsigned */
do { /* Spread user key into real key */
y += S[x] + userkey[pos]; /* Keys, shaken, not stirred */
tmp = S[x]; S[x] = S[y]; S[y] = tmp; /* Swap S[i] and S[j] */
if (++pos >= len) pos = 0; /* Repeat user key to fill array */
} while(++x); /* ++x is faster than x++ */
}
static inline char *arcfourCrypt(arckey *arc, char *data, int len)
{
register arcword *S = arc->state, i = arc->i, j = arc->j, tmp;
register int c = 0;
do {
j += S[++i]; /* Shake S-box, stir well */
tmp = S[i]; S[i] = S[j]; S[j] = tmp; /* Swap S[i] and S[j] */
data[c] ^= S[(S[i] + S[j])]; /* XOR the crypto into our data */
} while (++c < len); /* Neat, ++x is faster then x++ */
arc->i = i; /* Save modified i and j counters */
arc->j = j; /* Continue where we left off */
return data; /* Return pointer to ciphertext */
}
int Arcfour_Init(IrcCommandDll **intp, Function_ptr *global_table)
{
initialize_module("arcfour");
memset(keyboxes, 0, sizeof(keyboxes));
/*
dcc_output_func = send_dcc_encrypt;
dcc_input_func = get_dcc_encrypt;
dcc_open_func = start_dcc_crypt;
dcc_close_func = end_dcc_crypt;
*/
typenum = add_dcc_bind("SCHAT", "schat", init_schat, start_dcc_crypt, get_dcc_encrypt, send_dcc_encrypt, end_dcc_crypt);
add_module_proc(DCC_PROC, "schat", "schat", "Secure DCC Chat", 0, 0, dcc_sdcc, NULL);
return 0;
}
int Arcfour_Cleanup(IrcCommandDll **intp)
{
/* remove_dcc_bind("SCHAT", typenum); */
return 1;
}
static arclist *find_box(int sock)
{
int i, tmp;
tmp = sizeof(keyboxes)/sizeof(arclist *);
for (i = 0; i < tmp; i++)
if (keyboxes[i] && (keyboxes[i]->sock == sock))
return keyboxes[i];
return (arclist *)NULL;
}
static char *dcc_crypt (int sock, char *buf, int len)
{
arclist *box;
if ((box = find_box(sock))) {
arcfourCrypt(box->outbox, buf, len-2);
return buf;
}
return NULL;
}
static int send_dcc_encrypt (int type, int sock, char *buf, int len)
{
if (type == DCC_CHAT) {
if (dcc_crypt(sock, buf, len)) {
write(sock, buf, len);
return 0;
}
}
return -1;
}
static int get_dcc_encrypt (int type, int sock, char *buf, int parm, int len)
{
if (type == DCC_CHAT) {
if ((len = dgets(buf, sock, parm, BIG_BUFFER_SIZE, NULL)) > 0) {
buf[len-1] = '\0';
dcc_crypt(sock, buf, len);
if (buf[len])
buf[len] = '\0';
}
}
return len;
}
/* Here we initialize the cryptography. Send the other end our key, and read
* in theirs. The socket "s" won't have a crypt box unless it is supposed to
* an encrypted connection.
*/
static int start_dcc_crypt (int s, int type, unsigned long d_addr, int d_port)
{
arclist *tmpbox;
put_it("start_dcc_crypt");
if ((tmpbox = find_box(s))) {
int len;
char randkey[17];
char buf[BIG_BUFFER_SIZE+1];
memset(randkey, 0, sizeof(randkey));
memset(buf, 0, sizeof(buf));
tmpbox->outbox = (arckey *)new_malloc(sizeof(arckey));
init_box(randkey, tmpbox->outbox);
snprintf(buf, BIG_BUFFER_SIZE, "SecureDCC %s\r\n%n", randkey, &len);
write(s, buf, len);
memset(buf, 0, sizeof(buf));
if ((len = dgets(buf, s, 1, BIG_BUFFER_SIZE, NULL)) > 0) {
if (!my_strnicmp("SecureDCC", buf, 9)) {
tmpbox->inbox = (arckey *)new_malloc(sizeof(arckey));
arcfourInit(tmpbox->inbox, next_arg(buf, &buf), 16);
}
}
return 0;
}
return -1;
}
static int end_dcc_crypt (int s, unsigned long d_addr, int d_port)
{
int i;
for(i = 0; i < 16; i++) {
if (keyboxes[i] && (keyboxes[i]->sock == s)) {
new_free(&(keyboxes[i]->inbox));
new_free(&(keyboxes[i]->outbox));
new_free(&keyboxes[i]);
return 0;
}
}
return -1;
}
static void start_dcc_chat(int s)
{
struct sockaddr_in remaddr;
int sra;
int type;
int new_s = -1;
char *nick = NULL;
unsigned long flags;
DCC_int *n = NULL;
SocketList *sa;
sa = get_socket(s);
flags = sa->flags;
nick = sa->server;
sra = sizeof(struct sockaddr_in);
new_s = accept(s, (struct sockaddr *) &remaddr, &sra);
type = flags & DCC_TYPES;
n = get_socketinfo(s);
if ((add_socketread(new_s, ntohs(remaddr.sin_port), flags, nick, get_dcc_encrypt, NULL)) < 0)
{
erase_dcc_info(s, 0, "%s", convert_output_format("$G %RDCC error: accept() failed. punt!!", NULL, NULL));
close_socketread(s);
return;
}
flags &= ~DCC_WAIT;
flags |= DCC_ACTIVE;
set_socketflags(new_s, flags);
set_socketinfo(new_s, n);
/*
put_it("%s", convert_output_format(fget_string_var(FORMAT_DCC_CONNECT_FSET),
"%s %s %s %s %s %d", update_clock(GET_TIME),
dcc_types[type],
nick, n->userhost?n->userhost:"u at h",
inet_ntoa(remaddr.sin_addr),ntohs(remaddr.sin_port)));
*/
get_time(&n->starttime);
close_socketread(s);
start_dcc_crypt(new_s, type, n->remote.s_addr, ntohs(remaddr.sin_port));
}
/* set up the dcc hooks */
void dcc_sdcc (char *name, char *args)
{
char *p;
int tmp, i;
DCC_int *new_sdcc;
if (!my_stricmp(name, "schat") && (strlen(args) > 0)) {
if (*args == ' ')
new_next_arg(args, &args);
else {
p = strchr(args, ' ');
if (p && *p)
*p = 0;
}
new_sdcc = dcc_create(args, "SCHAT", NULL, 0, 0, typenum, DCC_TWOCLIENTS, start_dcc_chat);
/* find_dcc_pending(new_sdcc->user, new_sdcc->filename, NULL, typenum, 1, -1); */
/* new_i = find_dcc_pending(nick, filename, NULL, type, 1, -1); */
tmp = sizeof(keyboxes)/sizeof(arclist *);
for (i = 0; i < tmp; i++)
if (!keyboxes[i])
/* keyboxes[i]->sock = new_i->sock */;
}
}
/* thanks to the new add_dcc_bind, we dont have to worry about any hooking... */
static int init_schat(char *type, char *nick, char *userhost, char *description, char *size, char *extra, unsigned long ip, unsigned int port)
{
/* new_sdcc = dcc_create(args, "SCHAT", NULL, 0, 0, typenum, DCC_TWOCLIENTS, start_dcc_chat); */
return 0;
}
--- NEW FILE: asdf ---
name, module, init func, start func, input func, output func, close func
More information about the dslinux-commit
mailing list