Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    r8b6b740 r823de9d  
    2525
    2626#include "bitlbee.h"
    27 
    28 #include "arc.h"
    29 #include "base64.h"
    3027#include "commands.h"
     28#include "crypting.h"
     29#include "otr.h"
    3130#include "protocols/nogaim.h"
    3231#include "help.h"
    3332#include "ipc.h"
    34 #include "md5.h"
    35 #include "misc.h"
     33#include "lib/ssl_client.h"
    3634#include <signal.h>
    3735#include <unistd.h>
     
    4442static void sighandler( int signal );
    4543
    46 static int crypt_main( int argc, char *argv[] );
    47 
    4844int main( int argc, char *argv[] )
    4945{
     
    5248        struct sigaction sig, old;
    5349       
    54         if( argc > 1 && strcmp( argv[1], "-x" ) == 0 )
    55                 return crypt_main( argc, argv );
    56        
    5750        log_init();
    5851        global.conf_file = g_strdup( CONF_FILE_DEF );
     
    6356        b_main_init();
    6457        nogaim_init();
     58        /* Ugly Note: libotr and gnutls both use libgcrypt. libgcrypt
     59           has a process-global config state whose initialization happpens
     60           twice if libotr and gnutls are used together. libotr installs custom
     61           memory management functions for libgcrypt while our gnutls module
     62           uses the defaults. Therefore we initialize OTR after SSL. *sigh* */
     63        ssl_init();
     64        otr_init();
    6565       
    6666        srand( time( NULL ) ^ getpid() );
     
    168168}
    169169
    170 static int crypt_main( int argc, char *argv[] )
    171 {
    172         int pass_len;
    173         unsigned char *pass_cr, *pass_cl;
    174        
    175         if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 &&
    176                           strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) )
    177         {
    178                 printf( "Supported:\n"
    179                         "  %s -x enc <key> <cleartext password>\n"
    180                         "  %s -x dec <key> <encrypted password>\n"
    181                         "  %s -x hash <cleartext password>\n"
    182                         "  %s -x unhash <hashed password>\n"
    183                         "  %s -x chkhash <hashed password> <cleartext password>\n",
    184                         argv[0], argv[0], argv[0], argv[0], argv[0] );
    185         }
    186         else if( strcmp( argv[2], "enc" ) == 0 )
    187         {
    188                 pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 );
    189                 printf( "%s\n", base64_encode( pass_cr, pass_len ) );
    190         }
    191         else if( strcmp( argv[2], "dec" ) == 0 )
    192         {
    193                 pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr );
    194                 arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] );
    195                 printf( "%s\n", pass_cl );
    196         }
    197         else if( strcmp( argv[2], "hash" ) == 0 )
    198         {
    199                 md5_byte_t pass_md5[21];
    200                 md5_state_t md5_state;
    201                
    202                 random_bytes( pass_md5 + 16, 5 );
    203                 md5_init( &md5_state );
    204                 md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) );
    205                 md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */
    206                 md5_finish( &md5_state, pass_md5 );
    207                
    208                 printf( "%s\n", base64_encode( pass_md5, 21 ) );
    209         }
    210         else if( strcmp( argv[2], "unhash" ) == 0 )
    211         {
    212                 printf( "Hash %s submitted to a massive Beowulf cluster of\n"
    213                         "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] );
    214         }
    215         else if( strcmp( argv[2], "chkhash" ) == 0 )
    216         {
    217                 char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3];
    218                 int st = md5_verify_password( argv[4], hash );
    219                
    220                 printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" );
    221                
    222                 return st;
    223         }
    224        
    225         return 0;
    226 }
    227 
    228170static void sighandler( int signal )
    229171{
Note: See TracChangeset for help on using the changeset viewer.