XrdSecProtocolsslTest.cc

Go to the documentation of this file.
00001 
00002 #include <XrdSys/XrdSysLogger.hh>
00003 #include <XrdSec/XrdSecTLayer.hh>
00004 #include <XrdNet/XrdNetSocket.hh>
00005 #include <XrdNet/XrdNetOpts.hh>
00006 #include <XrdSecssl/XrdSecProtocolssl.hh>
00007 #include <sys/types.h>
00008 #include <sys/stat.h>
00009 #include <fcntl.h>
00010 #include <sys/time.h>
00011 
00012 #define TESTLOOP 100
00013 
00014 int main(int argc, char* argv[]) {
00015   if (argc < 2) {
00016     fprintf(stderr,"Error: you have to define if we are server or client!\n");
00017     fprintf(stderr,"usage: xrdsslprotocoltest server|client [args]\n");
00018     exit(-1);
00019   }
00020 
00021   // To silence a warning
00022   EPNAME("main");
00023   PRINT("dummy");
00024 
00025   setenv("XrdSecDEBUG","10",1);
00026   XrdSysLogger logger;
00027   XrdSysError eDest(&logger,"ssltest");
00028   
00029   if (!strcmp("server",argv[1])) {
00030     // server
00031     const char* args="-d:10 -cadir:/etc/grid-security/certificates/";
00032     if (argv[2]) {
00033       args = argv[2];
00034     }
00035 
00036     struct sockaddr  netaddr;
00037     XrdOucErrInfo error;
00038     
00039     XrdSecProtocolsslInit('s',args, &error);
00040     XrdSecProtocolssl* protocol = new XrdSecProtocolssl("localhost",(const struct sockaddr*)&netaddr);
00041     if (!protocol) {
00042       fprintf(stderr,"Error: cannot create protocol object\n");
00043       exit(-1);
00044     }
00045 
00046     XrdNetSocket* socket = new XrdNetSocket(&eDest);
00047     socket->Open(0,12345,XRDNET_SERVER);
00048 
00049     while(1) {
00050       // do an infinite handshake loop
00051       int theFd = socket->Accept();
00052       if (theFd<=0) {
00053         fprintf(stderr,"Accept failed on socket!\n");
00054         exit(-1);
00055       }
00056       protocol->secServer(theFd, &error);
00057       
00058       fprintf(stderr,"Authentication done: [%d : %s]\n", error.getErrInfo(),error.getErrText());
00059       close(theFd);
00060     }
00061 
00062     exit(0);
00063   }  else {
00064     if (!strcmp("client",argv[1])) {
00065       // client
00066       struct sockaddr  netaddr;
00067       XrdOucErrInfo error;
00068 
00069       XrdSecProtocolsslInit('c',"", &error);
00070       XrdSecProtocolssl* protocol = new XrdSecProtocolssl("localhost",(const struct sockaddr*)&netaddr);
00071       if (!protocol) {
00072         fprintf(stderr,"Error: cannot create protocol object\n");
00073         exit(-1);
00074       }
00075       XrdSecProtocolssl::allowSessions = false;
00076       struct timeval tv1, tv2, tv3;
00077       struct timezone tz;
00078 
00079       gettimeofday(&tv1,&tz);
00080       for (int i=0; i< TESTLOOP; i++) {
00081         XrdNetSocket* socket = new XrdNetSocket(&eDest);
00082         
00083         socket->Open(0,12345);
00084         
00085         int theFd = socket->Detach();
00086         if (theFd<=0) {
00087           fprintf(stderr,"unable to connect to socket\n");
00088           fprintf(stdout,"Client aborted: unable to connect to socket\n");
00089           exit(-1);
00090         }
00091         protocol->secClient(theFd, &error);
00092         if (error.getErrInfo()) {
00093           fprintf(stderr,"Authentication done: [%d : %s]\n", error.getErrInfo(),error.getErrText());
00094           fprintf(stdout,"Client aborted: authentication failure: [%d : %s]\n", error.getErrInfo(),error.getErrText());
00095           exit(-1);
00096         }
00097 
00098         delete socket;
00099       }
00100       gettimeofday(&tv2,&tz);
00101       XrdSecProtocolssl::allowSessions = true;
00102       for (int i=0; i< TESTLOOP; i++) {
00103         XrdNetSocket* socket = new XrdNetSocket(&eDest);
00104         
00105         socket->Open(0,12345);
00106         
00107         int theFd = socket->Detach();
00108         
00109         protocol->secClient(theFd, &error);
00110         if (error.getErrInfo()) {
00111           fprintf(stderr,"Authentication done: [%d : %s]\n", error.getErrInfo(),error.getErrText());
00112           exit(-1);
00113         }
00114         delete socket;
00115       }
00116       gettimeofday(&tv3,&tz);
00117 
00118       float inta = (((tv2.tv_sec-tv1.tv_sec) * 1000) + (tv2.tv_usec-tv1.tv_usec)/1000.0)/1000.0;
00119       float intb = (((tv3.tv_sec-tv2.tv_sec) * 1000) + (tv3.tv_usec-tv2.tv_usec)/1000.0)/1000.0;
00120       fprintf(stdout,"-----------------------------------------------------------------\n");
00121       fprintf(stdout,"Tested %d iterations without and with sessions...\n",TESTLOOP);
00122       fprintf(stdout,"-----------------------------------------------------------------\n");
00123       fprintf(stdout,"Performance without Sessions: %.02f authentications/s\n",TESTLOOP/inta);
00124       fprintf(stdout,"Performance with    Sessions: %.02f authentications/s\n",TESTLOOP/intb);
00125       fprintf(stdout,"-----------------------------------------------------------------\n");
00126       exit(0);
00127     }
00128   }
00129   fprintf(stderr,"Error: you have to define if we are server or client!\n");
00130   fprintf(stderr,"usage: xrdsslprotocoltest server|client\n");
00131   exit(-1);
00132 }
00133 
00134 
00135 

Generated on Tue Jul 5 14:47:01 2011 for ROOT_528-00b_version by  doxygen 1.5.1