int main(int argc, char**argv) { int n; char sendline[10000]; char recvline[10000]; char key[32]; memset(key,'\0',32); unsigned char decrypted[10000]; FILE *file; //memset(recvline,'\0',10000); //char user_input[1000]; file=fopen(argv[1],"r"); char *split=strtok(argv[1],"."); split=strtok(NULL,"."); if(file==0 || strcmp(split,"bank")) { printf("Error opening ATM initialization file\n"); return 64; } fread(key,sizeof(key),32,file); key[32]='\0'; //printf("bank file contents: %s\n",key); HashTable *users = hash_table_create(100); HashTable *balance = hash_table_create(100); Bank *bank = bank_create(); //bank->users = list_create(); //bank->usr_key = hash_table_create(100); //bank->usr_bal = hash_table_create(100); printf("%s", prompt); fflush(stdout); while(1) { memset(decrypted,'\0',10000); memset(recvline,'\0',10000); //memset(sendline,'\0',10000); fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(bank->sockfd, &fds); select(bank->sockfd+1, &fds, NULL, NULL, NULL); if(FD_ISSET(0, &fds)) { fgets(sendline, 10000,stdin); bank_process_local_command(bank, sendline, strlen(sendline),users,balance); printf("%s", prompt); fflush(stdout); } else if(FD_ISSET(bank->sockfd, &fds)) { ; //int flag = 0; n = bank_recv(bank, recvline, 10000); //int flag=decrypt(recvline,key,decrypted,n); if(!decrypt(recvline,key,decrypted,n)) { //this means that it has not been decrypted correctly so it will return a null packet unsigned char encrypted[10000]; char packet[10000]; sprintf(packet,"<%s>",NULL); int out_size =0; encrypt(packet,key,encrypted,&out_size); bank_send(bank, encrypted, out_size); printf("%s", prompt); fflush(stdout); continue; } //printf("%s\n",decrypted); char * message=strtok(decrypted,"\n"); bank_process_remote_command(bank, message, n, users,key,balance); } } hash_table_free(balance); hash_table_free(users); //never executes bank_free(bank); //fclose(file); return EXIT_SUCCESS; }
int main(int argc, char**argv) { char* filename = argv[1]; FILE* fp; fp = fopen(filename,"r"); if(fp == NULL){ puts("ERROR OPENING FILE"); return 64; } int n; char sendline[1000]; char recvline[1000]; Bank *bank = bank_create(); bank->bank_pub_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL); if(bank->bank_pub_key == NULL) { printf("\n%s\n", "Error Reading bank public key"); RSA_free(bank->bank_pub_key); return 0; } bank->bank_priv_key = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL); if(bank->bank_priv_key == NULL) { printf("\n%s\n", "Error Reading bank private key"); RSA_free(bank->bank_priv_key); return 0; } bank->atm_pub_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL); if(bank->atm_pub_key == NULL) { printf("\n%s\n", "Error Reading atm public key"); RSA_free(bank->atm_pub_key); return 0; } fclose(fp); printf("%s", prompt); fflush(stdout); while(1) { fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(bank->sockfd, &fds); select(bank->sockfd+1, &fds, NULL, NULL, NULL); if(FD_ISSET(0, &fds)) { fgets(sendline, 10000,stdin); bank_process_local_command(bank, sendline, strlen(sendline)); printf("%s", prompt); fflush(stdout); } else if(FD_ISSET(bank->sockfd, &fds)) { n = bank_recv(bank, recvline, 10000); bank_process_remote_command(bank, recvline, n); } } RSA_free(bank->bank_priv_key); return EXIT_SUCCESS; }
int main(int argc, char**argv) { int n; char sendline[1000]; char recvline[1000]; char *bankPath; FILE *bankFile; char *second; int filenamelen = 0; Bank *bank = bank_create(); if(argc == 1) { printf("Usage: Bank <filename>\n"); return 62; } //user fails to provide exactly one argument second = argv[1]; filenamelen = strlen(second); bankPath = malloc(1 + filenamelen + 5); strncpy(bankPath, second, strlen(second)); bankPath[filenamelen] = '.'; bankPath[filenamelen+1] = 'b'; bankPath[filenamelen+2] = 'a'; bankPath[filenamelen+3] = 'n'; bankPath[filenamelen+4] = 'k'; bankPath[filenamelen+5] = 0; bankFile = fopen(bankPath, "r"); if(bankFile == NULL){ printf("Error opening bank initialization file\n"); return 64; } fclose(bankFile); printf("%s", prompt); fflush(stdout); while(1) { fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(bank->sockfd, &fds); select(bank->sockfd+1, &fds, NULL, NULL, NULL); if(FD_ISSET(0, &fds)) { fgets(sendline, 10000,stdin); bank_process_local_command(bank, sendline, strlen(sendline)); printf("%s", prompt); fflush(stdout); } else if(FD_ISSET(bank->sockfd, &fds)) { n = bank_recv(bank, recvline, 10000); bank_process_remote_command(bank, recvline, n); } } return EXIT_SUCCESS; }
bool bbruntime_create(){ if( blitz_create() ){ if( hook_create() ){ if( event_create() ){ if( math_create() ){ if( string_create() ){ if( stdio_create() ){ if( stream_create() ){ if( sockets_create() ){ if( enet_create() ){ if( runtime_create() ){ if( system_create() ){ if( bank_create() ){ if( system_windows_create() ){ if( filesystem_create() ){ if( filesystem_windows_create() ){ if( timer_windows_create() ){ if( input_create() ){ if( input_directinput8_create() ){ if( audio_create() ){ if( audio_fmod_create() ){ if( userlibs_create() ){ if( pixmap_create() ){ if( blitz2d_create() ){ if( graphics_create() ){ if( runtime_glfw3_create() ){ return true; }else sue( "runtime_glfw3_create failed" ); graphics_destroy(); }else sue( "graphics_create failed" ); blitz2d_destroy(); }else sue( "blitz2d_create failed" ); pixmap_destroy(); }else sue( "pixmap_create failed" ); userlibs_destroy(); }else sue( "userlibs_create failed" ); audio_fmod_destroy(); }else sue( "audio_fmod_create failed" ); audio_destroy(); }else sue( "audio_create failed" ); input_directinput8_destroy(); }else sue( "input_directinput8_create failed" ); input_destroy(); }else sue( "input_create failed" ); timer_windows_destroy(); }else sue( "timer_windows_create failed" ); filesystem_windows_destroy(); }else sue( "filesystem_windows_create failed" ); filesystem_destroy(); }else sue( "filesystem_create failed" ); system_windows_destroy(); }else sue( "system_windows_create failed" ); bank_destroy(); }else sue( "bank_create failed" ); system_destroy(); }else sue( "system_create failed" ); runtime_destroy(); }else sue( "runtime_create failed" ); enet_destroy(); }else sue( "enet_create failed" ); sockets_destroy(); }else sue( "sockets_create failed" ); stream_destroy(); }else sue( "stream_create failed" ); stdio_destroy(); }else sue( "stdio_create failed" ); string_destroy(); }else sue( "string_create failed" ); math_destroy(); }else sue( "math_create failed" ); event_destroy(); }else sue( "event_create failed" ); hook_destroy(); }else sue( "hook_create failed" ); blitz_destroy(); }else sue( "blitz_create failed" ); return false; }
int main(int argc, char**argv) { int n; char sendline[1000]; char recvline[1000]; if (argc != 2) { printf("Error opening bank initialization file\n"); return 64; } char *token; char argv_cp[1024]; strcpy(argv_cp, argv[1]); strtok(argv_cp, "."); token = strtok(NULL, "."); if (strcmp(token, "bank") != 0) { printf("Error opening bank initialization file\n"); return 64; } Bank *bank = bank_create(); //Check for command line arguements FILE *init_file; strcpy(bank->symm_key, argv[1]); init_file = fopen(argv[1],"r"); if (init_file == NULL) { printf("Error opening bank initialization file\n"); return 64; } fclose(init_file); printf("%s", prompt); fflush(stdout); while(1) { fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(bank->sockfd, &fds); select(bank->sockfd+1, &fds, NULL, NULL, NULL); if(FD_ISSET(0, &fds)) { fgets(sendline, 10000,stdin); bank_process_local_command(bank, sendline, strlen(sendline)); printf("%s", prompt); fflush(stdout); } else if(FD_ISSET(bank->sockfd, &fds)) { n = bank_recv(bank, recvline, 10000); bank_process_remote_command(bank, recvline, n); } } return EXIT_SUCCESS; }