Hi Guys
So i have this Code i have been doing, and it giving mysterious out, anyone want to help, its been a while since i did c, so I'm a bit rusty,
basically just sending a recieving a struct to mimic the 1st stages of SSL in Linux
*Server Code*
Here Is my Client CodeCode:#include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/stat.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> typedef struct { char Version; //SSL Version char SessionID; //Session ID char Random[2]; //Nounce char CipherSuite[21][40]; //List of All the CipherSuites availabe in the SSL Client char Compression_Method; // List of All the Compression Methods Available to the client } SSL_Struct; int main(){ SSL_Struct Server_SSL; SSL_Struct Client_SSL; struct sockaddr_in client,server; int i; int j=0; int s,n,sock; int x; char y[4]; char z; char b1[100]="",b2[100]="Hi Client"; s=socket(AF_INET,SOCK_STREAM,0); server.sin_family=AF_INET; server.sin_port=2000; server.sin_addr.s_addr=inet_addr("127.0.0.1"); bind(s,(struct sockaddr *)&server,sizeof server); listen(s,1); printf("\nServer ready,waiting for client....\n"); n=sizeof client; sock=accept(s,(struct sockaddr *)&client,&n); // for(;;){ recv(sock,b1,sizeof(b1),0); //if(strcmp(b1,"end")==0) // break; printf("\n--------------Client:-----------------------\n"); printf("%s",b1); //printf("\nServer:"); send(sock,b2,sizeof(b2),0); // if(strcmp(b2,"end")==0) // break; recv(sock,(SSL_Struct*)&Client_SSL,sizeof(Client_SSL),0); printf("\n--------------Client Hello:-----------------------"); printf("\nVersion: %d",Client_SSL.Version); printf("\nSessionID: %d",Client_SSL.SessionID); printf("\nNonce: %s\n",Client_SSL.Random); for(j=1;j<21;j++){ printf("\nCiperSuite:[%s]",Client_SSL.CipherSuite[j]); } printf("\nCompression Method : %d\n",Client_SSL.Compression_Method); Server_SSL.Version=Client_SSL.Version; Server_SSL.SessionID=Client_SSL.SessionID; x = 1 + (int)(999999000.0*rand()/(RAND_MAX + 1.0)); sprintf(y,"%4d",x); strcpy(Server_SSL.Random,y); for(i=1;i<21;i++){ strncpy(Server_SSL.CipherSuite[i],Client_SSL.CipherSuite[i],40); } Server_SSL.Compression_Method=Client_SSL.Compression_Method; send(sock,(SSL_Struct*)&Server_SSL,sizeof(Server_SSL),0); //} close(sock); close(s); return 0; }
Its complied and run in the same pc, however some random characters are cropping up when i print it, any help would be kindly appreciatedCode:#include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/stat.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> typedef struct { char Version; //SSL Version char SessionID; //Session ID char Random[3]; //Nounce char CipherSuite[21][40]; //List of All the CipherSuites availabe in the SSL Client char Compression_Method; // List of All the Compression Methods Available to the client } SSL_Struct; int main(){ SSL_Struct Server_SSL; SSL_Struct Client_SSL; struct sockaddr_in client,server; int s,sock; int x; int i; char y[4]; char b1[100]="",b2[100]="Hi Server"; s=socket(AF_INET,SOCK_STREAM,0); server.sin_family=AF_INET; server.sin_port=2000; server.sin_addr.s_addr=inet_addr("127.0.0.1"); printf("\nClient ready....\n"); connect(s,(struct sockaddr *)&server,sizeof(server)); //for(;;){ // printf("\nClient:"); send(s,b2,sizeof(b2),0); // if(strcmp(b2,"end")==0) // break; recv(s,b1,sizeof(b1),0); // if(strcmp(b1,"end")==0) // break; printf("\n--------------Server:-----------------------\n"); printf("%s\n",b1); Client_SSL.Version='a'-94; Client_SSL.SessionID='a'-90; x = 1 + (int)(999999000.0*rand()/(RAND_MAX + 1.0)); sprintf(y,"%2d",x); strcpy(Client_SSL.Random,y); strcpy(Client_SSL.CipherSuite[1],"SSL_RSA_WITH_NULL_MD5"); strcpy(Client_SSL.CipherSuite[2],"SSL_RSA_WITH_NULL_SHA"); strcpy(Client_SSL.CipherSuite[3],"SSL_RSA_EXPORT_WITH_RC4_40_MD5"); strcpy(Client_SSL.CipherSuite[4],"SSL_RSA_WITH_RC4_128_MD5"); strcpy(Client_SSL.CipherSuite[5],"SSL_RSA_WITH_RC4_128_SHA"); strcpy(Client_SSL.CipherSuite[6],"SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5"); strcpy(Client_SSL.CipherSuite[7],"SSL_RSA_WITH_IDEA_CBC_SHA"); strcpy(Client_SSL.CipherSuite[8],"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA"); strcpy(Client_SSL.CipherSuite[9],"SSL_RSA_WITH_DES_CBC_SHA"); strcpy(Client_SSL.CipherSuite[10],"SSL_RSA_WITH_3DES_EDE_CBC_SHA"); strcpy(Client_SSL.CipherSuite[11],"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"); strcpy(Client_SSL.CipherSuite[12],"SSL_DHE_DSS_WITH_DES_CBC_SHA"); strcpy(Client_SSL.CipherSuite[13],"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"); strcpy(Client_SSL.CipherSuite[14],"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"); strcpy(Client_SSL.CipherSuite[15],"SSL_DHE_RSA_WITH_DES_CBC_SHA"); strcpy(Client_SSL.CipherSuite[16],"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA"); strcpy(Client_SSL.CipherSuite[17],"SSL_DH_anon_EXPORT_WITH_RC4_40_MD5"); strcpy(Client_SSL.CipherSuite[18],"SSL_DH_anon_WITH_RC4_128_MD5"); strcpy(Client_SSL.CipherSuite[19],"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA"); strcpy(Client_SSL.CipherSuite[20],"SSL_DH_anon_WITH_DES_CBC_SHA"); strcpy(Client_SSL.CipherSuite[21],"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA"); Client_SSL.Compression_Method='a'-96; printf("\n-----------------------------------Testing-------------------------------\n"); printf("\n--------------Client Hello:-----------------------"); printf("\nVersion: %d",Client_SSL.Version); printf("\nSessionID: %d",Client_SSL.SessionID); printf("\nNonce: %s\n",Client_SSL.Random); for(i=1;i<21;i++){ printf("\nCiperSuite:[%s]",Client_SSL.CipherSuite[i]); } printf("\nCompression Method : %d\n",Client_SSL.Compression_Method); send(s,(SSL_Struct*)&Client_SSL,sizeof(Client_SSL),0); recv(s,(SSL_Struct*)&Server_SSL,sizeof(Server_SSL),0); printf("\n--------------------Server Hello---------\n"); //printf("\nServer:"); printf("\nVersion: %d",Server_SSL.Version); printf("\nSessionID: %d",Server_SSL.SessionID); printf("\nNonce: %s",Server_SSL.Random); printf("\nCiperSuite :[%s]",Server_SSL.CipherSuite[3]); printf("\nCompression Method : %d\n",Server_SSL.Compression_Method); //} close(s); return 0; }
Thanks



LinkBack URL
About LinkBacks



