diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | conf.c | 3 | ||||
-rw-r--r-- | crypting.c | 60 | ||||
-rw-r--r-- | unix.c | 69 |
4 files changed, 69 insertions, 71 deletions
@@ -48,7 +48,7 @@ Makefile.settings: @echo clean: $(subdirs) - rm -f *.o $(OUTFILE) core utils/bitlbeed encode decode + rm -f *.o $(OUTFILE) core utils/bitlbeed $(MAKE) -C tests clean distclean: clean $(subdirs) @@ -123,11 +123,5 @@ ifndef DEBUG @-$(STRIP) $(OUTFILE) endif -encode: crypting.c - $(CC) crypting.c lib/md5.c $(CFLAGS) -o encode -DCRYPTING_MAIN $(CFLAGS) $(EFLAGS) $(LFLAGS) - -decode: encode - cp encode decode - ctags: ctags `find . -name "*.c"` `find . -name "*.h"` @@ -126,7 +126,7 @@ conf_t *conf_load( int argc, char *argv[] ) else if( opt == 'h' ) { printf( "Usage: bitlbee [-D/-F [-i <interface>] [-p <port>] [-n] [-v]] [-I]\n" - " [-c <file>] [-d <dir>] [-h]\n" + " [-c <file>] [-d <dir>] [-x] [-h]\n" "\n" "An IRC-to-other-chat-networks gateway\n" "\n" @@ -142,6 +142,7 @@ conf_t *conf_load( int argc, char *argv[] ) " -v Be verbose (only works in combination with -n)\n" " -c Load alternative configuration file\n" " -d Specify alternative user configuration directory\n" + " -x Command-line interface to password encryption/hashing\n" " -h Show this help page.\n" ); return NULL; } @@ -131,63 +131,3 @@ char *deobfucrypt (char *line, const char *password) return (rv); } - -#ifdef CRYPTING_MAIN - -/* A little main() function for people who want a stand-alone program to - encode/decode BitlCrypted files. */ - -int main( int argc, char *argv[] ) -{ - char *hash, *action, line[256]; - char* (*func)( char *, const char * ); - - if( argc < 2 ) - { - fprintf( stderr, "Usage: %s <password>\n\n" - "Reads from stdin, writes to stdout.\n" - "Call as \"encode\" to encode, \"decode\" to decode.\n", argv[0] ); - return( 1 ); - } - - hash = hashpass( argv[1] ); - action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); - - if( strcmp( action, "encode" ) == 0 ) - { - fwrite( hash, 32, 1, stdout ); - func = obfucrypt; - } - else if( strcmp( action, "decode" ) == 0 ) - { - char hash2[32]; - - fread( hash2, 32, 1, stdin ); - if( memcmp( hash, hash2, 32 ) != 0 ) - { - fprintf( stderr, "Passwords don't match. Can't decode.\n" ); - return( 1 ); - } - func = deobfucrypt; - } - else - { - return( main( 0, NULL ) ); - } - - while( fscanf( stdin, "%[^\n]255s", line ) > 0 ) - { - char *out; - - /* Flush the newline */ - fgetc( stdin ); - - out = func( line, argv[1] ); - printf( "%s\n", out ); - g_free( out ); - } - - return( 0 ); -} - -#endif @@ -24,11 +24,15 @@ */ #include "bitlbee.h" + +#include "arc.h" +#include "base64.h" #include "commands.h" -#include "crypting.h" #include "protocols/nogaim.h" #include "help.h" #include "ipc.h" +#include "md5.h" +#include "misc.h" #include <signal.h> #include <unistd.h> #include <sys/time.h> @@ -39,12 +43,17 @@ global_t global; /* Against global namespace pollution */ static void sighandler( int signal ); +static int crypt_main( int argc, char *argv[] ); + int main( int argc, char *argv[] ) { int i = 0; char *old_cwd = NULL; struct sigaction sig, old; + if( argc > 1 && strcmp( argv[1], "-x" ) == 0 ) + return crypt_main( argc, argv ); + log_init(); global.conf_file = g_strdup( CONF_FILE_DEF ); global.conf = conf_load( argc, argv ); @@ -158,6 +167,62 @@ int main( int argc, char *argv[] ) return( 0 ); } +static int crypt_main( int argc, char *argv[] ) +{ + int pass_len; + unsigned char *pass_cr, *pass_cl; + + if( argc < 3 ) + { + printf( "Supported:\n" + " %s -x enc <key> <cleartext password>\n" + " %s -x dec <key> <encrypted password>\n" + " %s -x hash <cleartext password>\n" + " %s -x unhash <hashed password>\n" + " %s -x chkhash <hashed password> <cleartext password>\n", + argv[0], argv[0], argv[0], argv[0], argv[0] ); + } + else if( strcmp( argv[2], "enc" ) == 0 ) + { + pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 ); + printf( "%s\n", base64_encode( pass_cr, pass_len ) ); + } + else if( strcmp( argv[2], "dec" ) == 0 ) + { + pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr ); + arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] ); + printf( "%s\n", pass_cl ); + } + else if( strcmp( argv[2], "hash" ) == 0 ) + { + md5_byte_t pass_md5[21]; + md5_state_t md5_state; + + random_bytes( pass_md5 + 16, 5 ); + md5_init( &md5_state ); + md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) ); + md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */ + md5_finish( &md5_state, pass_md5 ); + + printf( "%s\n", base64_encode( pass_md5, 21 ) ); + } + else if( strcmp( argv[2], "unhash" ) == 0 ) + { + printf( "Hash %s submitted to a massive Beowulf cluster of\n" + "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] ); + } + else if( strcmp( argv[2], "chkhash" ) == 0 ) + { + int st = md5_verify_password( argv[4], argv[3] ); + + printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" ); + + return st; + } + + return 0; +} + static void sighandler( int signal ) { /* FIXME: Calling log_message() here is not a very good idea! */ @@ -213,5 +278,3 @@ double gettime() gettimeofday( time, 0 ); return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); } - - |