
API In CPP
122
char cNull[1] = {0};
//Send login message
WriteWord("/login");
WriteWord(cNull);
ReadSentence(readSentence);
DEBUG ? readSentence.Print() : 0;
if (readSentence.GetReturnType() != DONE) {
printf("Error.\n");
} else {
// extract md5 string from the challenge sentence
char *strWord = new char [readSentence[1].size() + 1];
strcpy(strWord, readSentence[1].c_str());
char *md5Challenge = strtok(strWord, "=");
md5Challenge = strtok(NULL, "=");
DEBUG ? printf("MD5 of challenge = %s\n", md5Challenge) : 0;
////Place of interest: Check to see if this md5Challenge string works as as string.
// It may not because it needs to be binary.
// convert szMD5Challenge to binary
string md5ChallengeBinary = MD5ToBinary(md5Challenge);
delete[] strWord;
// get md5 of the password + challenge concatenation
md5_init(&state);
md5_append(&state, (const md5_byte_t *)cNull, 1);
md5_append(&state, (const md5_byte_t *)strPassword.c_str(),
strlen(strPassword.c_str()));
md5_append(&state, (const md5_byte_t *)md5ChallengeBinary.c_str(), 16);
md5_finish(&state, digest);
// convert this digest to a string representation of the hex values
// digest is the binary format of what we want to send
// szMD5PasswordToSend is the "string" hex format
string md5PasswordToSend = MD5DigestToHexString(digest);
DEBUG ? printf("MD5 Password To Send = %s\n", md5PasswordToSend.c_str()) : 0;
// put together the login sentence
writeSentence.AddWord("/login");
writeSentence.AddWord("=name=" + strUsername);
writeSentence.AddWord("=response=00" + md5PasswordToSend);
Komentáře k této Příručce