git-svn-id: svn://db.shs.com.ru/pip@608 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -52,7 +52,7 @@ PIByteArray PIAuth::startServer() {
|
||||
PIByteArray ba;
|
||||
crypt.generateKeypair(my_pk, box_sk);
|
||||
PIByteArray noise = crypt.generateRandomBuff(randomi()%256+128);
|
||||
ba << (int)state << info << sign_pk << my_pk << noise;
|
||||
ba << (int)state << server_info << sign_pk << my_pk << noise;
|
||||
PIByteArray sign = crypt.signMessage(ba, sign_sk);
|
||||
ba << sign;
|
||||
return ba;
|
||||
@@ -134,8 +134,30 @@ PIAuth::State PIAuth::receive(PIByteArray & ba) {
|
||||
ba << rsign;
|
||||
return state;
|
||||
}
|
||||
if (state == AuthReply && rstate == KeyExchange) {
|
||||
|
||||
if ((state == AuthReply && rstate == KeyExchange) || (state == PassRequest && rstate == KeyExchange)) {
|
||||
PIByteArray tba, ctba;
|
||||
PIByteArray rsign;
|
||||
ba >> ctba >> rsign;
|
||||
bool ok = false;
|
||||
tba = crypt.decrypt(ctba, box_pk, box_sk, &ok);
|
||||
if (tba.isEmpty() || !ok) return disconnect(ba, "Message corrupted");
|
||||
ba.clear();
|
||||
ba << (int)rstate << ctba;
|
||||
if (!crypt.verifySign(ba, rsign, auth_sign)) return disconnect(ba, "Incorrect sign");
|
||||
tba >> secret_key;
|
||||
if (secret_key.size() != crypt.sizeKey()) return disconnect(ba, "Invalid key");
|
||||
ba.clear();
|
||||
state = Connected;
|
||||
connected();
|
||||
ba << (int)state << crypt.generateRandomBuff(randomi()%256);
|
||||
return state;
|
||||
}
|
||||
if (state == Connected && rstate == Connected) {
|
||||
ba.clear();
|
||||
state = Connected;
|
||||
connected();
|
||||
ba << (int)state << crypt.generateRandomBuff(randomi()%256);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +224,13 @@ PIAuth::State PIAuth::receive(PIByteArray & ba) {
|
||||
ba = createSKMessage();
|
||||
return state;
|
||||
}
|
||||
if ((state == KeyExchange && rstate == Connected) || (state == Connected && rstate == Connected)) {
|
||||
ba.clear();
|
||||
state = Connected;
|
||||
connected();
|
||||
ba << (int)state << crypt.generateRandomBuff(randomi()%256);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
return disconnect(ba, "invalid state " + PIString::fromNumber((int)state));
|
||||
@@ -247,7 +276,7 @@ PIByteArray PIAuth::createSKMessage() {
|
||||
secret_key = crypt.generateKey();
|
||||
PIByteArray tba;
|
||||
PIByteArray noise = crypt.generateRandomBuff(randomi()%256);
|
||||
tba << secret_key << noise << box_pk;
|
||||
tba << secret_key << noise;
|
||||
tba = crypt.crypt(tba, box_pk, box_sk);
|
||||
PIByteArray ret;
|
||||
ret << (int)state << tba;
|
||||
|
||||
Reference in New Issue
Block a user