package/network/services/ead/src/tinysrp/tinysrp.c
/* This is called by the server with a connected socket. */
This is called by the server with a connected socket.
This is called by the server with a connected socket .
int tsrp_server_authenticate(int s, TSRP_SESSION *tsrp)
{
	int i, j;
	unsigned char username[MAXUSERLEN], *skey;
	unsigned char msgbuf[MAXPARAMLEN + 1], abuf[MAXPARAMLEN];
	struct t_server *ts;
	struct t_num A, *B;
	i = recv(s, msgbuf, 1, 0);
	if (i <= 0) {
		return 0;
	}
	j = msgbuf[0];
	i = recv(s, username, j, MSG_WAITALL);
	if (i <= 0) {
		return 0;
	}
	username[j] = '\0';
	ts = t_serveropen(username);
	if (ts == NULL) {
		return 0;
	}
	msgbuf[0] = ts->index;                  
	i = ts->s.len;
	msgbuf[1] = i;
	memcpy(msgbuf + 2, ts->s.data, i);
	if (send(s, msgbuf, i + 2, 0) < 0) {
		return 0;
	}
	B = t_servergenexp(ts);
	i = recv(s, msgbuf, 1, 0);
	if (i <= 0) {
		return 0;
	}
	A.len = msgbuf[0] + 1;
	A.data = abuf;
	i = recv(s, abuf, A.len, MSG_WAITALL);
	if (i <= 0) {
		return 0;
	}
	msgbuf[0] = B->len - 1;
	memcpy(msgbuf + 1, B->data, B->len);
	if (send(s, msgbuf, B->len + 1, 0) < 0) {
		return 0;
	}
	skey = t_servergetkey(ts, &A);
	if (skey == NULL) {
		return 0;
	}
	i = recv(s, msgbuf, RESPONSE_LEN, MSG_WAITALL);
	if (i <= 0) {
		return 0;
	}
	if (t_serververify(ts, msgbuf) != 0) {
		return 0;
	}
	if (send(s, t_serverresponse(ts), RESPONSE_LEN, 0) < 0) {
		return 0;
	}
	if (tsrp) {
		memcpy(tsrp->username, username, strlen(username) + 1);
		memcpy(tsrp->key, skey, SESSION_KEY_LEN);
	}
	t_serverclose(ts);
	return 1;
}
int tsrp_server_authenticate ( int s , TSRP_SESSION * tsrp ) { int i , j ; unsigned char username [ MAXUSERLEN ] , * skey ; unsigned char msgbuf [ MAXPARAMLEN + 1 ] , abuf [ MAXPARAMLEN ] ; struct t_server * ts ; struct t_num A , * B ; i = recv ( s , msgbuf , 1 , 0 ) ; if ( i <= 0 ) { return 0 ; } j = msgbuf [ 0 ] ; i = recv ( s , username , j , MSG_WAITALL ) ; if ( i <= 0 ) { return 0 ; } username [ j ] = ' \0 ' ; ts = t_serveropen ( username ) ; if ( ts == NULL ) { return 0 ; } msgbuf [ 0 ] = ts -> index ; i = ts -> s . len ; msgbuf [ 1 ] = i ; memcpy ( msgbuf + 2 , ts -> s . data , i ) ; if ( send ( s , msgbuf , i + 2 , 0 ) < 0 ) { return 0 ; } B = t_servergenexp ( ts ) ; i = recv ( s , msgbuf , 1 , 0 ) ; if ( i <= 0 ) { return 0 ; } A . len = msgbuf [ 0 ] + 1 ; A . data = abuf ; i = recv ( s , abuf , A . len , MSG_WAITALL ) ; if ( i <= 0 ) { return 0 ; } msgbuf [ 0 ] = B -> len - 1 ; memcpy ( msgbuf + 1 , B -> data , B -> len ) ; if ( send ( s , msgbuf , B -> len + 1 , 0 ) < 0 ) { return 0 ; } skey = t_servergetkey ( ts , & A ) ; if ( skey == NULL ) { return 0 ; } i = recv ( s , msgbuf , RESPONSE_LEN , MSG_WAITALL ) ; if ( i <= 0 ) { return 0 ; } if ( t_serververify ( ts , msgbuf ) != 0 ) { return 0 ; } if ( send ( s , t_serverresponse ( ts ) , RESPONSE_LEN , 0 ) < 0 ) { return 0 ; } if ( tsrp ) { memcpy ( tsrp -> username , username , strlen ( username ) + 1 ) ; memcpy ( tsrp -> key , skey , SESSION_KEY_LEN ) ; } t_serverclose ( ts ) ; return 1 ; }
This is called by the server with a connected socket.
This is called by the server with a connected socket .
/* Get the username. */ /* Send the prime index and the salt. */ /* max 256 primes... */ /* Calculate B while we're waiting. */ /* Get A from the client. */ /* Now send B. */ /* Calculate the session key while we're waiting. */ /* Get the response from the client. */ /* Client authenticated.  Now authenticate ourselves to the client. */ /* Copy the key and clean up. */