Ticket #456: encode_decode.patch
File encode_decode.patch, 3.8 KB (added by , at 2008-11-07T13:02:23Z) |
---|
-
bitlbee-1.2.3
diff -ur bitlbee-1.2.3/crypting.c bitlbee-1.2.3.des/crypting.c
old new 137 137 /* A little main() function for people who want a stand-alone program to 138 138 encode/decode BitlCrypted files. */ 139 139 140 int main( int argc, char *argv[] ) 140 #include "misc.h" 141 #include "base64.h" 142 #include "arc.h" 143 144 global_t global; /*ugly hack for global variable required to link*/ 145 146 /* encode: generates the md5 crypt used in the config file 147 * decode: decodes the passwords from the accounts in the xml file using the 148 * bitlbee account password 149 */ 150 int main (int argc, char *argv[]) 141 151 { 142 char *hash, *action, line[256]; 143 char* (*func)( char *, const char * ); 144 145 if( argc < 2 ) 146 { 147 fprintf( stderr, "Usage: %s <password>\n\n" 148 "Reads from stdin, writes to stdout.\n" 149 "Call as \"encode\" to encode, \"decode\" to decode.\n", argv[0] ); 150 return( 1 ); 151 } 152 153 hash = hashpass( argv[1] ); 154 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 152 char *action; 153 char *password = NULL; 154 char *pass_buf = NULL; 155 int pass_len; 156 157 /* allow binaries to be called whatever+encode and whatever+decode 158 luckily encode and decode have the same length 159 */ 160 action = argv[0] + strlen (argv[0]) - strlen ("encode"); 155 161 156 if( strcmp( action, "encode" ) == 0 ) 157 { 158 fwrite( hash, 32, 1, stdout ); 159 func = obfucrypt; 160 } 161 else if( strcmp( action, "decode" ) == 0 ) 162 { 163 char hash2[32]; 164 165 fread( hash2, 32, 1, stdin ); 166 if( memcmp( hash, hash2, 32 ) != 0 ) 167 { 168 fprintf( stderr, "Passwords don't match. Can't decode.\n" ); 169 return( 1 ); 162 if (strcmp (action, "encode") == 0) 163 { 164 password = argv[1]; 165 md5_byte_t pass_md5[21]; 166 md5_state_t md5_state; 167 168 if (argc != 2) 169 { 170 printf ("Usage: %s <password>\n", argv[0]); 171 exit (1); 170 172 } 171 func = deobfucrypt;172 }173 else174 {175 return( main( 0, NULL ) );176 }177 178 while( fscanf( stdin, "%[^\n]255s", line ) > 0 )179 {180 char *out;181 173 182 /* Flush the newline */ 183 fgetc( stdin ); 174 /* Generate a salted md5sum of the password. Use 5 bytes for the salt 175 (to prevent dictionary lookups of passwords) to end up with a 21- 176 byte password hash, more convenient for base64 encoding. */ 177 random_bytes (pass_md5 + 16, 5); 178 md5_init (&md5_state); 179 md5_append (&md5_state, (md5_byte_t*) password, strlen (password)); 180 md5_append (&md5_state, pass_md5 + 16, 5); /* Add the salt. */ 181 md5_finish (&md5_state, pass_md5); 182 /* Get the hash in base64-encoded form. */ 183 pass_buf = base64_encode (pass_md5, 21); 184 printf ("%s\n", pass_buf); 185 186 } 187 else if (strcmp (action, "decode") == 0) 188 { 189 190 if (argc != 3) 191 { 192 printf ("Usage: %s <password> <hash_from_your_xml_file>\n", argv[0]); 193 exit (1); 194 } 184 195 185 out = func( line, argv[1] ); 186 printf( "%s\n", out ); 187 g_free( out ); 196 pass_len = base64_decode (argv[2], (unsigned char**) &pass_buf); 197 arc_decode (pass_buf, pass_len, &password, argv[1]); 198 printf ("Your password is: %s\n", password); 199 188 200 } 189 190 return( 0 ); 201 else 202 { 203 fprintf (stderr, "Function not implemented, implemented functions:\n encode\n decode\n"); 204 exit (1); 205 } 206 207 /*do not free stuff, who cares?*/ 208 exit (0); 191 209 } 192 210 193 211 #endif -
bitlbee-1.2.3
diff -ur bitlbee-1.2.3/Makefile bitlbee-1.2.3.des/Makefile
old new 123 123 @-$(STRIP) $(OUTFILE) 124 124 endif 125 125 126 encode: crypting.c 127 $(CC) crypting.c lib/md5.c $(CFLAGS) -o encode -DCRYPTING_MAIN $(CFLAGS) $(EFLAGS) $(LFLAGS) 126 encode: $(objects) $(subdirobjs) crypting.c 127 $(CC) -c crypting.c $(CFLAGS) -o crypting.o -DCRYPTING_MAIN $(CFLAGS) 128 $(CC) crypting.o lib/lib.o $(CFLAGS) -o encode $(EFLAGS) $(LFLAGS) 128 129 129 130 decode: encode 130 131 cp encode decode