Ejemplo n.º 1
0
        public override ProtobufPacket Handle(EncryptionRequestPacket packet)
        {
            var generator = new CipherKeyGenerator();

            generator.Init(new KeyGenerationParameters(new SecureRandom(), 16 * 8));
            var sharedKey = generator.GenerateKey();

            var hash = GetServerIDHash(packet.PublicKey, sharedKey, packet.ServerID);

            if (!Yggdrasil.JoinSession(Context.AccessToken, Context.SelectedProfile, hash).Result.Response)
            {
                throw new Exception("Yggdrasil error: Not authenticated.");
            }

            var signer = new PKCS1Signer(packet.PublicKey);

            Context.SendPacket(new EncryptionResponsePacket
            {
                SharedSecret = signer.SignData(sharedKey),
                VerifyToken  = signer.SignData(packet.VerifyToken)
            });

            Context.Stream.InitializeEncryption(sharedKey);

            return(null);
        }
Ejemplo n.º 2
0
        private void HandleEncryptionResponse(EncryptionResponsePacket packet)
        {
            if (Authorized)
                return;

            if (AuthorizationStatus.HasFlag(AuthorizationStatus.EncryprionEnabled))
            {
                var pkcs = new PKCS1Signer(Module.RsaKeyPair);

                var decryptedToken = pkcs.DeSignData(packet.VerificationToken);
                for (int i = 0; i < VerificationToken.Length; i++)
                    if (decryptedToken[i] != VerificationToken[i])
                    {
                        SendPacket(new AuthorizationDisconnectPacket { Reason = "Unable to authenticate." });
                        return;
                    }
                Array.Clear(VerificationToken, 0, VerificationToken.Length);

                var sharedKey = pkcs.DeSignData(packet.SharedSecret);

                Stream.InitializeEncryption(sharedKey);
            }
            else
                SendPacket(new AuthorizationDisconnectPacket { Reason = "Encryption not enabled!" });
        }
Ejemplo n.º 3
0
        private void HandleEncryptionResponse(EncryptionResponsePacket packet)
        {
            if (Authorized)
            {
                return;
            }

            if (AuthorizationStatus.HasFlag(AuthorizationStatus.EncryprionEnabled))
            {
                var pkcs = new PKCS1Signer(Module.Security.RSAKeyPair);

                var decryptedToken = pkcs.DeSignData(packet.VerificationToken);
                for (var i = 0; i < VerificationToken.Length; i++)
                {
                    if (decryptedToken[i] != VerificationToken[i])
                    {
                        SendPacket(new AuthorizationDisconnectPacket {
                            Reason = "Unable to authenticate."
                        });
                        return;
                    }
                }
                Array.Clear(VerificationToken, 0, VerificationToken.Length);

                var sharedKey = pkcs.DeSignData(packet.SharedSecret);

                Stream = new ProtobufTransmission <SCONPacket>(Socket, new BouncyCastleAesStream(Socket, sharedKey));
            }
            else
            {
                SendPacket(new AuthorizationDisconnectPacket {
                    Reason = "Encryption not enabled!"
                });
            }
        }
Ejemplo n.º 4
0
        public void Test()
        {
            var length = 256;

            var expected = new byte[length];
            var actual = new byte[length];

            new Random().NextBytes(expected);

            var signer = new PKCS1Signer(GenerateKeyPair());
            actual = signer.SignData(expected);
            actual = signer.DeSignData(actual);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        private void HandleEncryptionRequest(EncryptionRequestPacket packet)
        {
            if(Authorized)
                return;

            if (AuthorizationStatus.HasFlag(AuthorizationStatus.EncryprionEnabled))
            {
                var generator = new CipherKeyGenerator();
                generator.Init(new KeyGenerationParameters(new SecureRandom(), 16 * 8));
                var sharedKey = generator.GenerateKey();

                var pkcs = new PKCS1Signer(packet.PublicKey);
                var signedSecret = pkcs.SignData(sharedKey);
                var signedVerify = pkcs.SignData(packet.VerificationToken);

                SendPacket(new EncryptionResponsePacket { SharedSecret = signedSecret, VerificationToken = signedVerify });

                Stream.InitializeEncryption(sharedKey);

                SendPacket(new AuthorizationPasswordPacket { PasswordHash = Password.Hash });
            }
            else
                throw new SCONException("Encryption was not enabled!");
        }
Ejemplo n.º 6
0
        private void HandleEncryptionRequest(EncryptionRequestPacket packet)
        {
            var generator = new CipherKeyGenerator();
            generator.Init(new KeyGenerationParameters(new SecureRandom(), 16 * 8));
            var sharedKey = generator.GenerateKey();

            var pkcs = new PKCS1Signer(packet.PublicKey);
            var signedSecret = pkcs.SignData(sharedKey);
            var signedVerify = pkcs.SignData(packet.VerificationToken);

            SendPacketDirect(new EncryptionResponsePacket { SharedSecret = signedSecret, VerificationToken = signedVerify });

            Stream.InitializeEncryption(sharedKey);

            State |= JoinState.JoinedGame;
        }