*/
/********************************************************/
/* */
-/* Procedure to purge incoming plain text channel */
-/* before going to TLS mode. */
+/* Procedure to purge incoming TLS channel */
+/* After crypted link is established but before */
+/* to use it. */
/* */
/* See VE-2011-0411, "plaintext command injection" */
/* */
/********************************************************/
-static void socpurge(SOCTYP *soc)
+static void socpurge(SOCTYP *soc,const char *peerip)
{
-_Bool needpurge;
+#define OPEP "devsoc.c:socpurge"
+
+int max;
int count;
-needpurge=true;
+max=1000; //purgin for one seconde max;
count=0;
-while (needpurge==true) {
- TIMESPEC attend;
-
- (void) printf("JMPDBG purge\n");
- needpurge=false;
+for (;count<max;count++) {
soc->carin=0;
soc->carpile[0]='\000';
- attend.tv_sec=0;
- attend.tv_nsec=1000000; //waiting one milli sec
- if (soc_waitforchar(soc,&attend)>0) {
- (void) printf("JMPDBG need purge count='%d'\n",count);
- needpurge=true;
- (void) soc_receive(soc);
- count++;
- if (count>10)
- (void) exit(-1);
- }
+ (void) usleep(1000); //1 millisec
+ (void) soc_receive(soc);
+ if (soc->carin==0) //got no character
+ break;
+ (void) rou_alert(0,"JMPDBG reading soc count='%d' carin='%d'",count,soc->carin);
}
+if (count>=max) //one second max!
+ (void) rou_alert(0,"%s purge is too long with peer [%s]",OPEP,peerip);
+#undef OPEP
}
/*
\f
if (soc!=(SOCTYP *)0) {
struct pollfd polling[1];
- polling[0].events=POLLIN;
+ polling[0].events=POLLIN|POLLPRI;
polling[0].revents=(short)0;
switch (soc->modtls) {
case true :
/* crypted channel, return true is successful. */
/* */
/********************************************************/
-_Bool soc_starttls(SOCPTR *socptr)
+_Bool soc_starttls(SOCPTR *socptr,const char *peerip)
{
_Bool ok;
int tosend;
char buffer[100];
+ (void) socpurge(soc,peerip);
tosend=snprintf(buffer,sizeof(buffer),"%d 2.0.0 Ready to start TLS%s",
SIGNON,CRLF);
(void) soc_writebuffer(soc,buffer,tosend);
if ((soc->tls=tls_opentls(soc->handle,true))!=(TLSTYP *)0) {
soc->proto=pro_smtps;
soc->modtls=true;
- (void) socpurge(soc);
+ (void) socpurge(soc,peerip);
ok=true;
}
}
case SSL_ERROR_WANT_READ : //"wanted" error
case SSL_ERROR_WANT_WRITE :
(void) printf("JMPDBG SSL_get_error='%d'\n",status);
- (void) usleep(1000000);
+ (void) usleep(1000);
count++;
proceed=true;
break;
got=-1;
if (tls!=(TLSTYP *)0) {
- if ((got=SSL_read(tls->ssl,buffer,maxread))<=0) {
+ if ((got=SSL_read(tls->ssl,buffer,maxread))<0) {
(void) showtlserror(tls,got,"Trouble to read data");
got=-1;
}