Skip to content

Commit e94bf80

Browse files
author
stskeeps
committed
SSL support for UnrealIRCD!
1 parent 5b3b137 commit e94bf80

22 files changed

+345
-66
lines changed

.RELEASE.NOTES

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Unreal3.1-Silverheart Release Notes
1515
Where 20 is the numeric. Numerics are 1-255, 0 means no numeric (bad),
1616
and no server must have same numeric
1717

18-
* We have introduced encrypted irc connections, and we will soon have a
19-
client out for it (this is not SSL). Stay tuned in #UnrealIRCd for more
20-
information
18+
* We have introduced encrypted irc connections, using SSL
19+
2120

2221
* NOTE, in #UnrealIRCD we don't help with Services etc.
2322

Config

+29-30
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ else
504504
echo 'not found (good!)'
505505
fi
506506

507-
echo $n "...Looking for /usr/include/openssl/blowfish.h...$c"
508-
if [ -r /usr/include/openssl/blowfish.h ] ; then
507+
echo $n "...Looking for /usr/include/openssl/ssl.h...$c"
508+
if [ -r /usr/include/openssl/ssl.h ] ; then
509509
OPENSSL=define
510510
echo 'found!'
511511
else
@@ -793,28 +793,6 @@ else
793793
fi
794794
fi
795795
$RM -f $EXEC $TMP
796-
797-
echo $n "Do we have an broken /usr/include/string.h ... $c"
798-
cat > $TMP <<__EOF__
799-
#include <string.h>
800-
main()
801-
{
802-
char *s = "moocows";
803-
char *p = "moocows";
804-
805-
if (strcasecmp(s, p))
806-
exit(0);
807-
exit(0);
808-
}
809-
__EOF__
810-
$COMP >/dev/null 2>&1
811-
if [ $? -ne 0 ] ; then
812-
echo " no$c"
813-
STRCASECMP=undef
814-
else
815-
echo "yes"
816-
STRCASECMP=define
817-
fi
818796
#
819797
# what do we need that isn't here already ?
820798
#
@@ -1015,8 +993,25 @@ if [ $? -ne 0 ] ; then
1015993
echo $n " inet_netof$c"
1016994
NINETNETOF=define
1017995
fi
1018-
$RM -f $EXEC $TMP
1019996
echo " "
997+
$RM -f $EXEC $TMP
998+
cat > $TMP << __EOF__
999+
#include <string.h>
1000+
main()
1001+
{
1002+
strcasecmp("moo", "moo");
1003+
}
1004+
__EOF__
1005+
$COMP
1006+
# >/dev/null 2>&1
1007+
if [ $? -ne 0 ] ; then
1008+
echo $n " strcasecmp $c "
1009+
STRCASECMP=undef
1010+
else
1011+
STRCASECMP=define
1012+
fi
1013+
$RM -f $EXEC $TMP
1014+
10201015
#
10211016
#
10221017
#
@@ -1096,7 +1091,7 @@ cat > $SETUP <<__EOF__
10961091
#$NINETNETOF NEED_INET_NETOF
10971092
#$GETTIMEOFDAY GETTIMEOFDAY
10981093
#$LRAND48 LRAND48
1099-
#$STRCASECMP GOT_STRCASECMP
1094+
#$STRCASECMP GOT_STRCASECMP
11001095
__EOF__
11011096
if [ "$MALLOCH" = "undef" ] ; then
11021097
echo "#undef MALLOCH" >> $SETUP
@@ -1304,7 +1299,7 @@ while [ -z "$FOO" ] ; do
13041299
FOO="No"
13051300
fi
13061301
echo ""
1307-
echo "Do you want to support encrypted connections"
1302+
echo "Do you want to support SSL (Secure Sockets Layer) connections"
13081303
echo $n "[$FOO] -> $c"
13091304
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
13101305
read cc
@@ -1318,7 +1313,7 @@ while [ -z "$FOO" ] ; do
13181313
case "$cc" in
13191314
[Yy]*)
13201315
CRYPTOIRCD="1"
1321-
CRYPTOLIB="-lcrypto"
1316+
CRYPTOLIB="-lssl -lcrypto"
13221317
;;
13231318
[Nn]*)
13241319
CRYPTOIRCD=""
@@ -1779,9 +1774,9 @@ else
17791774
echo "#undef CRYPT_OPER_PASSWORD" >> $OPTIONS_H
17801775
fi
17811776
if [ -n "$CRYPTOIRCD" ] ; then
1782-
echo "#define CRYPTOIRCD 1" >> $OPTIONS_H
1777+
echo "#define USE_SSL 1" >> $OPTIONS_H
17831778
else
1784-
echo "#undef CRYPTOIRCD" >> $OPTIONS_H
1779+
echo "#undef USE_SSL" >> $OPTIONS_H
17851780
fi
17861781
if [ -n "$CRYPT_LINK_PASSWORD" ] ; then
17871782
echo "#define CRYPT_LINK_PASSWORD 1" >> $OPTIONS_H
@@ -1857,6 +1852,10 @@ if [ "$OSNAME" = "Linux (with GLIBC 2.x or greater)" ]; then
18571852
echo ""
18581853
fi
18591854

1855+
if [ -n "$CRYPTOIRCD" ] ; then
1856+
make pem
1857+
fi
1858+
18601859
cat << __EOF__
18611860
18621861
_____________________________________________________________________

Makefile.dist

+5
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,8 @@ depend:
210210
install: all
211211
@echo "Now install by hand; make install is broken."
212212

213+
pem: src/ssl.cnf
214+
/usr/local/ssl/bin/openssl req -new -x509 -days 365 -nodes \
215+
-config src/ssl.cnf -out server.pem -keyout server.pem
216+
/usr/local/ssl/bin/openssl x509 -subject -dates -fingerprint -noout \
217+
-in server.pem

TODO

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ Assigned to DrBin:
5252
* Make a is_chan_op, is_chanprot, is_chanowner all-in-one function
5353
* Split up Link (SLink)
5454
* Add Dlink (DSLink)
55+
56+
57+
58+
-----------------------------------------------------

include/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
* Would you like all clients to see the progress of their connections?
423423
*/
424424

425-
#define SHOWCONNECTINFO
425+
#undef SHOWCONNECTINFO
426426

427427
/*
428428
* SOCKS proxy checker

include/ssl.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Make these what you want for cert & key files */
2+
#define CERTF "server.pem"
3+
#define KEYF "server.pem"
4+
5+
6+
extern SSL_CTX * ctx;
7+
extern SSL_METHOD *meth;
8+
extern void init_ssl();
9+
extern int ssl_handshake(aClient *); /* Handshake the accpeted con.*/
10+
extern int ssl_client_handshake(aClient *); /* and the initiated con.*/

include/struct.h

+29-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
#ifdef CRYPTOIRCD
5050
#include <openssl/blowfish.h>
5151
#endif
52-
52+
#ifdef USE_SSL
53+
#include <openssl/rsa.h> /* SSL stuff */
54+
#include <openssl/crypto.h>
55+
#include <openssl/x509.h>
56+
#include <openssl/pem.h>
57+
#include <openssl/ssl.h>
58+
#include <openssl/err.h>
59+
#endif
5360
typedef struct t_fline aFline;
5461
typedef struct t_crline aCRline;
5562
typedef struct t_vhline aVHline;
@@ -217,9 +224,12 @@ typedef unsigned int u_int32_t; /* XXX Hope this works! */
217224
#ifdef CRYPTOIRCD
218225
#define FLAGS_SECURE 0x8000000
219226
#endif
227+
#ifdef USE_SSL
228+
#define FLAGS_SSL 0x10000000
229+
#define FLAGS_SSL_HSHAKE 0x20000000
230+
#endif
220231

221232
#define FLAGS_MAP 0x80000000 /* Show this entry in /map */
222-
223233
/* Dec 26th, 1997 - added flags2 when I ran out of room in flags -DuffJ */
224234

225235
/* Dec 26th, 1997 - having a go at
@@ -250,7 +260,7 @@ typedef unsigned int u_int32_t; /* XXX Hope this works! */
250260
#define UMODE_WHOIS 0x100000 /* gets notice on /whois */
251261
#define UMODE_KIX 0x200000 /* usermode +q */
252262
#define UMODE_BOT 0x400000 /* User is a bot */
253-
#define UMODE_CODER 0x800000 /* User is a network coder */
263+
#define UMODE_SECURE 0x800000 /* User is a secure connect */
254264
#define UMODE_FCLIENT 0x1000000 /* recieve client on far connects.. */
255265
#define UMODE_HIDING 0x2000000 /* Totally invisible .. */
256266
#define UMODE_VICTIM 0x8000000 /* Intentional Victim */
@@ -259,7 +269,7 @@ typedef unsigned int u_int32_t; /* XXX Hope this works! */
259269
#define UMODE_SETHOST 0x40000000 /* used sethost */
260270
#define UMODE_STRIPBADWORDS 0x80000000 /* */
261271

262-
#define SEND_UMODES (UMODE_INVISIBLE|UMODE_OPER|UMODE_WALLOP|UMODE_FAILOP|UMODE_HELPOP|UMODE_REGNICK|UMODE_SADMIN|UMODE_NETADMIN|UMODE_TECHADMIN|UMODE_COADMIN|UMODE_ADMIN|UMODE_SERVICES|UMODE_HIDE|UMODE_EYES|UMODE_WHOIS|UMODE_KIX|UMODE_BOT|UMODE_CODER|UMODE_FCLIENT|UMODE_HIDING|UMODE_DEAF|UMODE_VICTIM|UMODE_HIDEOPER|UMODE_SETHOST|UMODE_STRIPBADWORDS)
272+
#define SEND_UMODES (UMODE_INVISIBLE|UMODE_OPER|UMODE_WALLOP|UMODE_FAILOP|UMODE_HELPOP|UMODE_REGNICK|UMODE_SADMIN|UMODE_NETADMIN|UMODE_TECHADMIN|UMODE_COADMIN|UMODE_ADMIN|UMODE_SERVICES|UMODE_HIDE|UMODE_EYES|UMODE_WHOIS|UMODE_KIX|UMODE_BOT|UMODE_SECURE|UMODE_FCLIENT|UMODE_HIDING|UMODE_DEAF|UMODE_VICTIM|UMODE_HIDEOPER|UMODE_SETHOST|UMODE_STRIPBADWORDS)
263273
#define ALL_UMODES (SEND_UMODES|UMODE_SERVNOTICE|UMODE_LOCOP|UMODE_KILLS|UMODE_CLIENT|UMODE_FLOOD|UMODE_CHATOP|UMODE_SERVICES|UMODE_EYES)
264274
#define FLAGS_ID (FLAGS_DOID|FLAGS_GOTID)
265275

@@ -329,8 +339,13 @@ typedef unsigned int u_int32_t; /* XXX Hope this works! */
329339
#define IsSecure(x) ((x)->flags & FLAGS_SECURE)
330340
#define SetSecure(x) ((x)->flags |= FLAGS_SECURE)
331341
#define ClearSecure(x) ((x)->flags &= ~FLAGS_SECURE)
342+
#else
343+
#ifdef USE_SSL
344+
#define IsSecure(x) ((x)->flags & FLAGS_SSL)
345+
#else
346+
#define IsSecure(x) (0)
347+
#endif
332348
#endif
333-
334349

335350
#define IsHybNotice(x) ((x)->flags & FLAGS_HYBNOTICE)
336351
#define SetHybNotice(x) ((x)->flags |= FLAGS_HYBNOTICE)
@@ -792,6 +807,7 @@ struct t_vhline {
792807
#define LISTENER_REMOTEADMIN 0x000008
793808
#define LISTENER_JAVACLIENT 0x000010
794809
#define LISTENER_MASK 0x000020
810+
#define LISTENER_SSL 0x000040
795811

796812
struct Client {
797813
struct Client *next, *prev, *hnext;
@@ -842,6 +858,10 @@ struct Client {
842858
#ifdef CRYPTOIRCD
843859
aCryptInfo *cryptinfo; /* crypt */
844860
#endif
861+
#ifdef USE_SSL
862+
struct SSL *ssl;
863+
struct X509 *client_cert;
864+
#endif
845865
#ifndef NO_FDLIST
846866
long lastrecvM; /* to check for activity --Mika */
847867
int priority;
@@ -1073,6 +1093,7 @@ struct Channel {
10731093
#endif
10741094
#define MODE_NOCTCP 0x10000000
10751095
#define MODE_AUDITORIUM 0x20000000
1096+
#define MODE_ONLYSECURE 0x40000000
10761097

10771098
#define is_halfop is_half_op
10781099
/*
@@ -1164,5 +1185,8 @@ extern char *gnulicense[];
11641185

11651186
#define FLUSH_BUFFER -2
11661187
#define COMMA ","
1188+
#ifdef USE_SSL
1189+
#include "ssl.h"
1190+
#endif
11671191

11681192
#endif /* __struct_include__ */

include/sys.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
# include <string.h>
5454
# endif
5555
#endif
56-
56+
#ifdef SSL
57+
#include <openssl/ssl.h>
58+
#endif
5759
#ifndef GOT_STRCASECMP
5860
#define strcasecmp mycmp
5961
#define strncasecmp myncmp

networks/unrealircd.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Exp $
88
#
99
# change the filename to what network header file you use
1010
# relative to DPATH
11-
Include .................: networks/unreal-test.network
11+
Include .................: networks/roxnet.network
1212

1313
#
1414
# What K:Line address can K:lined users mail at?

src/Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OBJS=agent.o aln.o badwords.o bsd.o channel.o class.o cloak.o crule.o dbuf.o dyn
2727
fdlist.o hash.o help.o ircd.o ircsprintf.o list.o lusers.o \
2828
match.o packet.o parse.o $(REGEX) res.o $(RES) s_auth.o \
2929
s_bsd.o s_conf.o s_debug.o s_err.o s_extra.o s_kline.o \
30-
s_misc.o s_numeric.o s_serv.o s_socks.o $(STRTOUL) s_unreal.o \
30+
s_misc.o s_numeric.o s_serv.o s_socks.o $(STRTOUL) ssl.o s_unreal.o \
3131
s_user.o scache.o send.o support.o userload.o version.o webtv.o \
3232
whowas.o zip.o
3333

@@ -59,7 +59,8 @@ version.o: version.c ../include/version.h
5959
$(CC) $(CFLAGS) -c version.c
6060

6161
ircd: $(OBJS)
62-
$(CC) $(CFLAGS) -o ircd $(OBJS) $(LDFLAGS) $(IRCDLIBS) $(CRYPTOLIB)
62+
# $(CC) $(CFLAGS) $(CRYPTOLIB) -o ircd $(OBJS) $(LDFLAGS) $(IRCDLIBS) -lssl
63+
$(CC) $(CFLAGS) -o ircd $(CRYPTOLIB) $(OBJS) $(LDFLAGS) $(IRCDLIBS) $(CRYPTOLIB)
6364
chmod $(IRCDMODE) ircd
6465

6566
chkconf: ../include/struct.h ../include/config.h ../include/settings.h ../include/sys.h \
@@ -102,6 +103,9 @@ send.o: send.c $(INCLUDES)
102103
webtv.o: webtv.c $(INCLUDES)
103104
$(CC) $(CFLAGS) -c webtv.c
104105

106+
ssl.o: ssl.c $(INCLUDES)
107+
$(CC) $(CFLAGS) -c ssl.c
108+
105109
match.o: match.c $(INCLUDES)
106110
$(CC) $(CFLAGS) -c match.c
107111

src/bsd.c

+8
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,18 @@ int deliver_it(cptr, str, len)
118118
cptr->name, cptr->status, IsDead(cptr) ? "DEAD" : "", str);
119119
return -1;
120120
}
121+
122+
#ifdef USE_SSL
123+
if (cptr->flags & FLAGS_SSL)
124+
retval = SSL_write((SSL *)cptr->ssl, str, len);
125+
else
126+
retval = send(cptr->fd, str, len, 0);
127+
#else
121128
#ifndef INET6
122129
retval = send(cptr->fd, str, len, 0);
123130
#else
124131
retval = sendto(cptr->fd, str, len, 0, 0, 0);
132+
#endif
125133
#endif
126134
/*
127135
** Convert WOULDBLOCK to a return of "0 bytes moved". This

src/channel.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ aCtab cFlagTab[] = {
148148
#endif
149149
{MODE_NOCTCP, 'C', 0, 0}, /* no CTCPs */
150150
{MODE_AUDITORIUM, 'u', 0, 0},
151+
{MODE_ONLYSECURE, 'z', 0, 0},
151152
{0x0, 0x0, 0x0}
152153
};
153154
#endif
@@ -1583,6 +1584,7 @@ int do_mode_char(chptr, modetype, modechar, param, what, cptr, pcount, pvar,
15831584
case MODE_STRIPBADWORDS:
15841585
#endif
15851586
case MODE_NOCTCP:
1587+
case MODE_ONLYSECURE:
15861588
case MODE_NOINVITE:
15871589
setthephuckingmode:
15881590
/* +sp bugfix.. */
@@ -2246,6 +2248,11 @@ static int can_join(cptr, sptr, chptr, key, link, parv)
22462248
/* if ((chptr->mode.mode & MODE_OPERONLY) && IsOper(sptr)) {
22472249
goto admok;
22482250
} */
2251+
if ((chptr->mode.mode & MODE_ONLYSECURE) &&
2252+
!(sptr->umodes & UMODE_SECURE))
2253+
{
2254+
return (ERR_BANNEDFROMCHAN);
2255+
}
22492256
if ((chptr->mode.mode & MODE_OPERONLY) && !IsOper(sptr))
22502257
{
22512258
return (ERR_OPERONLY);
@@ -2259,7 +2266,7 @@ static int can_join(cptr, sptr, chptr, key, link, parv)
22592266
if ((chptr->mode.mode & MODE_NOHIDING) && IsHiding(sptr))
22602267
return (ERR_NOHIDING);
22612268

2262-
if ((IsOper(sptr) && !(chptr->mode.mode & MODE_ADMONLY)))
2269+
if ((IsOper(sptr) && !((chptr->mode.mode & MODE_ADMONLY))))
22632270
{
22642271
return 0; /* may override */
22652272
}

src/ircd.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,9 @@ int InitwIRCD(argc, argv)
11251125
#endif
11261126
check_class();
11271127
write_pidfile();
1128-
1128+
#ifdef USE_SSL
1129+
init_ssl();
1130+
#endif
11291131
Debug((DEBUG_NOTICE, "Server ready..."));
11301132
#ifdef USE_SYSLOG
11311133
syslog(LOG_NOTICE, "Server Ready");

0 commit comments

Comments
 (0)