SRP_CLIENT_builtin_param_verify_cb(SRP * srp, const unsigned char * mod, int modlen, const unsigned char * gen, int genlen) { struct t_preconf * tpc; int i; for(i = 0; i < t_getprecount(); ++i) { tpc = t_getpreparam(i); if(tpc->modulus.len == modlen && tpc->generator.len == genlen && memcmp(tpc->modulus.data, mod, modlen) == 0 && memcmp(tpc->generator.data, gen, genlen) == 0) { return SRP_SUCCESS; /* Match found, done */ } } return SRP_ERROR; }
int tsrp_client_authenticate(int s, char *user, char *pass, TSRP_SESSION *tsrp) { int i, index; unsigned char username[MAXUSERLEN + 1], sbuf[MAXSALTLEN]; unsigned char msgbuf[MAXPARAMLEN + 1], bbuf[MAXPARAMLEN]; unsigned char passbuf[128], *skey; struct t_client *tc; struct t_preconf *tcp; /* @@@ should go away */ struct t_num salt, *A, B; /* Send the username. */ i = strlen(user); if (i > MAXUSERLEN) { i = MAXUSERLEN; } msgbuf[0] = i; memcpy(msgbuf + 1, user, i); if (send(s, msgbuf, i + 1, 0) < 0) { return 0; } memcpy(username, user, i); username[i] = '\0'; /* Get the prime index and salt. */ i = recv(s, msgbuf, 2, MSG_WAITALL); if (i <= 0) { return 0; } index = msgbuf[0]; if (index <= 0 || index > t_getprecount()) { return 0; } tcp = t_getpreparam(index - 1); salt.len = msgbuf[1]; if (salt.len > MAXSALTLEN) { return 0; } salt.data = sbuf; i = recv(s, sbuf, salt.len, MSG_WAITALL); if (i <= 0) { return 0; } /* @@@ t_clientopen() needs a variant that takes the index */ tc = t_clientopen(username, &tcp->modulus, &tcp->generator, &salt); if (tc == NULL) { return 0; } /* Calculate A and send it to the server. */ A = t_clientgenexp(tc); msgbuf[0] = A->len - 1; /* len is max 256 */ memcpy(msgbuf + 1, A->data, A->len); if (send(s, msgbuf, A->len + 1, 0) < 0) { return 0; } /* Ask the user for the passphrase. */ if (pass == NULL) { t_getpass(passbuf, sizeof(passbuf), "Enter password:"); pass = passbuf; } t_clientpasswd(tc, pass); /* Get B from the server. */ i = recv(s, msgbuf, 1, 0); if (i <= 0) { return 0; } B.len = msgbuf[0] + 1; B.data = bbuf; i = recv(s, bbuf, B.len, MSG_WAITALL); if (i <= 0) { return 0; } /* Compute the session key. */ skey = t_clientgetkey(tc, &B); if (skey == NULL) { return 0; } /* Send the response. */ if (send(s, t_clientresponse(tc), RESPONSE_LEN, 0) < 0) { return 0; } /* Get the server's response. */ i = recv(s, msgbuf, RESPONSE_LEN, MSG_WAITALL); if (i <= 0) { return 0; } if (t_clientverify(tc, msgbuf) != 0) { return 0; } /* All done. Now copy the key and clean up. */ if (tsrp) { memcpy(tsrp->username, username, strlen(username) + 1); memcpy(tsrp->key, skey, SESSION_KEY_LEN); } t_clientclose(tc); return 1; }