| 6 |
| * Copyright Nikolai Kudashov, 2015-2018. |
| 7 | */ |
| 8 |
| 9 | #ifndef HANDSHAKE_H |
| 10 | #define HANDSHAKE_H |
| 11 |
| 12 | #include <stdint.h> |
| 13 | #include "Defines.h" |
| 14 | #include <openssl/bn.h> |
| 15 |
| 16 | class Datacenter; |
| 17 | class ByteArray; |
| 18 | class TLObject; |
| 19 | class TL_future_salt; |
| 20 | class Connection; |
| 21 |
| 22 | class Handshake { |
| 23 |
| 24 | public: |
| 25 |
| 26 | Handshake(Datacenter *datacenter, HandshakeType type, HandshakeDelegate *handshakeDelegate); |
| 27 | ~Handshake(); |
| 28 | void beginHandshake(bool reconnect); |
| 29 | void cleanupHandshake(); |
| 30 | void processHandshakeResponse(TLObject *message, int64_t messageId); |
| 31 | void processHandshakeResponse_resPQ(TLObject *message, int64_t messageId); |
| 32 | void processHandshakeResponse_serverDHParams(TLObject *message, int64_t messageId); |
| 33 | void processHandshakeResponse_serverDHParamsAnswer(TLObject *message, int64_t messageId); |
| 34 | void onHandshakeConnectionConnected(); |
| 35 | void onHandshakeConnectionClosed(); |
| 36 | static void cleanupServerKeys(); |
| 37 | HandshakeType getType(); |
| 38 | ByteArray *getPendingAuthKey(); |
| 39 | int64_t getPendingAuthKeyId(); |
| 40 | TLObject *getCurrentHandshakeRequest(); |
| 41 | static bool isGoodPrime(BIGNUM *p, uint32_t g); |
| 42 |
| 43 | private: |
| 44 |
| 45 | Datacenter *currentDatacenter; |
| 46 | HandshakeType handshakeType; |
| 47 | HandshakeDelegate *delegate; |
| 48 |
| 49 | uint8_t handshakeState = 0; |
| 50 | TLObject *handshakeRequest = nullptr; |
| 51 | ByteArray *authNonce = nullptr; |
| 52 | ByteArray *authServerNonce = nullptr; |
| 53 | ByteArray *authNewNonce = nullptr; |
| 54 | ByteArray *handshakeAuthKey = nullptr; |
| 55 | TL_future_salt *handshakeServerSalt = nullptr; |
| 56 | int32_t timeDifference = 0; |
| 57 | ByteArray *authKeyTempPending = nullptr; |
| 58 | int64_t authKeyTempPendingId = 0; |
| 59 | int32_t authKeyPendingRequestId = 0; |
| 60 | int64_t authKeyPendingMessageId = 0; |
| 61 | bool needResendData = false; |
| 62 |
| 63 | void sendRequestData(TLObject *object, bool important); |
| 64 | void sendAckRequest(int64_t messageId); |
| 65 |
| 66 | static void saveCdnConfig(Datacenter *datacenter); |
| 67 | static void saveCdnConfigInternal(NativeByteBuffer *buffer); |
| 68 | static void loadCdnConfig(Datacenter *datacenter); |
| 69 |
| 70 | inline Connection *getConnection(); |
| 71 | }; |
| 72 |
| 73 | #endif |
| 74 |