Пример #1
0
        public Session(int clientOS, int clientRevision)
        {
            /* Initialize protocol with this session. */
            this._protocol = new Protocol(this);

            /* Set client properties. */
            this._clientId       = CLIENT_ID;
            this._clientOs       = clientOS;
            this._clientRevision = clientRevision;

            /* Client and server generate 16 random bytes each. */
            this._clientRandom = new byte[16];
            this._serverRandom = new byte[16];

            RandomBytes.GetRandomBytes(ref this._clientRandom);

            /* Allocate buffer for server RSA key. */
            this._serverBlob = new byte[256];

            /* Allocate buffer for salt and auth hash. */
            this._username = null;
            this._password = null;
            this._salt     = new byte[10];
            this._authHash = new byte[20];

            /*
             * Create a private and public DH key and allocate buffer
             * for shared key. This, along with key signing, is used
             * to securely agree on a session key for the Shannon stream
             * cipher.
             */
            this._dhClientKeyPair = DH.GenerateKeyPair(768);
            this._dhSharedKey     = new byte[96];

            /* Generate RSA key pair. */
            this._rsaClientKeyPair = Sharpotify.Crypto.RSA.GenerateKeyPair(1024);

            /* Allocate buffers for HMAC and Shannon stream cipher keys. */
            this._keyHmac   = new byte[20];
            this._authHmac  = new byte[20];
            this._keyRecv   = new byte[32];
            this._keySend   = new byte[32];
            this._keyRecvIv = 0;
            this._keySendIv = 0;

            /* Stream cipher instances. */
            this._shannonRecv = new Shannon();
            this._shannonSend = new Shannon();

            /* Allocate buffer for puzzle solution. */
            this._puzzleDenominator = 0;
            this._puzzleMagic       = 0;
            this._puzzleSolution    = new byte[8];

            /* Found in Storage.dat (cache) at offset 16. Modify first byte of cache hash. */
            this._cacheHash = new byte[] {
                (byte)0xf4, (byte)0xc2, (byte)0xaa, (byte)0x05,
                (byte)0xe8, (byte)0x25, (byte)0xa7, (byte)0xb5,
                (byte)0xe4, (byte)0xe6, (byte)0x59, (byte)0x0f,
                (byte)0x3d, (byte)0xd0, (byte)0xbe, (byte)0x0a,
                (byte)0xef, (byte)0x20, (byte)0x51, (byte)0x95
            };
            this._cacheHash[0] = (byte)new Random().Next();

            /* Not initialized. */
            this._initialClientPacket = null;
            this._initialServerPacket = null;
        }