예제 #1
0
 public virtual BigInteger CalculateSecret(BigInteger serverB)
 {
     B = Srp6Utilities.ValidatePublicValue(N, serverB);
     u = Srp6Utilities.CalculateU(digest, N, pubA, B);
     S = CalculateS();
     return(S);
 }
예제 #2
0
 public virtual BigInteger CalculateSecret(BigInteger clientA)
 {
     A = Srp6Utilities.ValidatePublicValue(N, clientA);
     u = Srp6Utilities.CalculateU(digest, N, A, pubB);
     S = CalculateS();
     return(S);
 }
예제 #3
0
 public override void ProcessClientKeyExchange(Stream input)
 {
     try
     {
         mSrpPeerCredentials = Srp6Utilities.ValidatePublicValue(mSrpGroup.N, TlsSrpUtilities.ReadSrpParameter(input));
     }
     catch (CryptoException alertCause)
     {
         throw new TlsFatalAlert(47, alertCause);
     }
     mContext.SecurityParameters.srpIdentity = Arrays.Clone(mIdentity);
 }
예제 #4
0
        public override void ProcessServerKeyExchange(Stream input)
        {
            SecurityParameters securityParameters = context.SecurityParameters;

            SignerInputBuffer buf   = null;
            Stream            teeIn = input;

            if (mTlsSigner != null)
            {
                buf   = new SignerInputBuffer();
                teeIn = new TeeInputStream(input, buf);
            }

            byte[] NBytes = TlsUtilities.ReadOpaque16(teeIn);
            byte[] gBytes = TlsUtilities.ReadOpaque16(teeIn);
            byte[] sBytes = TlsUtilities.ReadOpaque8(teeIn);
            byte[] BBytes = TlsUtilities.ReadOpaque16(teeIn);

            if (buf != null)
            {
                DigitallySigned signed_params = DigitallySigned.Parse(context, input);

                ISigner signer = InitVerifyer(mTlsSigner, signed_params.Algorithm, securityParameters);
                buf.UpdateSigner(signer);
                if (!signer.VerifySignature(signed_params.Signature))
                {
                    throw new TlsFatalAlert(AlertDescription.decrypt_error);
                }
            }

            BigInteger N = new BigInteger(1, NBytes);
            BigInteger g = new BigInteger(1, gBytes);

            // TODO Validate group parameters (see RFC 5054)
            //        throw new TlsFatalAlert(AlertDescription.insufficient_security);

            this.mS = sBytes;

            /*
             * RFC 5054 2.5.3: The client MUST abort the handshake with an "illegal_parameter" alert if
             * B % N = 0.
             */
            try
            {
                this.mB = Srp6Utilities.ValidatePublicValue(N, new BigInteger(1, BBytes));
            }
            catch (CryptoException e)
            {
                throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
            }

            this.mSrpClient.Init(N, g, TlsUtilities.CreateHash(HashAlgorithm.sha1), context.SecureRandom);
        }
        public virtual void ProcessServerKeyExchange(Stream input)
        {
            SecurityParameters securityParameters = context.SecurityParameters;

            Stream  sigIn  = input;
            ISigner signer = null;

            if (tlsSigner != null)
            {
                signer = InitSigner(tlsSigner, securityParameters);
                sigIn  = new SignerStream(input, signer, null);
            }

            byte[] NBytes = TlsUtilities.ReadOpaque16(sigIn);
            byte[] gBytes = TlsUtilities.ReadOpaque16(sigIn);
            byte[] sBytes = TlsUtilities.ReadOpaque8(sigIn);
            byte[] BBytes = TlsUtilities.ReadOpaque16(sigIn);

            if (signer != null)
            {
                byte[] sigByte = TlsUtilities.ReadOpaque16(input);

                if (!signer.VerifySignature(sigByte))
                {
                    throw new TlsFatalAlert(AlertDescription.bad_certificate);
                }
            }

            BigInteger N = new BigInteger(1, NBytes);
            BigInteger g = new BigInteger(1, gBytes);

            // TODO Validate group parameters (see RFC 5054)
            //throw new TlsFatalAlert(AlertDescription.insufficient_security);

            this.s = sBytes;

            /*
             * RFC 5054 2.5.3: The client MUST abort the handshake with an "illegal_parameter"
             * alert if B % N = 0.
             */
            try
            {
                this.B = Srp6Utilities.ValidatePublicValue(N, new BigInteger(1, BBytes));
            }
            catch (CryptoException)
            {
                throw new TlsFatalAlert(AlertDescription.illegal_parameter);
            }

            this.srpClient.Init(N, g, new Sha1Digest(), context.SecureRandom);
        }
예제 #6
0
        public override void ProcessServerKeyExchange(Stream input)
        {
            SecurityParameters securityParameters = mContext.SecurityParameters;

            SignerInputBuffer buf   = null;
            Stream            teeIn = input;

            if (mTlsSigner != null)
            {
                buf   = new SignerInputBuffer();
                teeIn = new TeeInputStream(input, buf);
            }

            ServerSrpParams srpParams = ServerSrpParams.Parse(teeIn);

            if (buf != null)
            {
                DigitallySigned signed_params = ParseSignature(input);

                ISigner signer = InitVerifyer(mTlsSigner, signed_params.Algorithm, securityParameters);
                buf.UpdateSigner(signer);
                if (!signer.VerifySignature(signed_params.Signature))
                {
                    throw new TlsFatalAlert(AlertDescription.decrypt_error);
                }
            }

            this.mSrpGroup = new Srp6GroupParameters(srpParams.N, srpParams.G);

            if (!mGroupVerifier.Accept(mSrpGroup))
            {
                throw new TlsFatalAlert(AlertDescription.insufficient_security);
            }

            this.mSrpSalt = srpParams.S;

            /*
             * RFC 5054 2.5.3: The client MUST abort the handshake with an "illegal_parameter" alert if
             * B % N = 0.
             */
            try
            {
                this.mSrpPeerCredentials = Srp6Utilities.ValidatePublicValue(mSrpGroup.N, srpParams.B);
            }
            catch (CryptoException e)
            {
                throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
            }

            this.mSrpClient.Init(mSrpGroup, TlsUtilities.CreateHash(HashAlgorithm.sha1), mContext.SecureRandom);
        }
예제 #7
0
        static public bool IsValid(LobbyClient client)
        {
            if (client.Account == null)
            {
                return(false);
            }

            return(true);

            client.serv.CalculateSecret(new BigInteger(client.A));
            BigInteger Pro   = new BigInteger(client.Proof);
            BigInteger check = Srp6Utilities.ValidatePublicValue(client.N, Pro);

            return(check.IntValue > 0);
        }
예제 #8
0
        public override void ProcessClientKeyExchange(Stream input)
        {
            /*
             * RFC 5054 2.5.4: The server MUST abort the handshake with an "illegal_parameter" alert if
             * A % N = 0.
             */
            try
            {
                this.mSrpPeerCredentials = Srp6Utilities.ValidatePublicValue(mSrpGroup.N, TlsSrpUtilities.ReadSrpParameter(input));
            }
            catch (CryptoException e)
            {
                throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
            }

            mContext.SecurityParameters.srpIdentity = Arrays.Clone(mIdentity);
        }
예제 #9
0
        public override void ProcessServerKeyExchange(Stream input)
        {
            SecurityParameters securityParameters = mContext.SecurityParameters;
            SignerInputBuffer  signerInputBuffer  = null;
            Stream             input2             = input;

            if (mTlsSigner != null)
            {
                signerInputBuffer = new SignerInputBuffer();
                input2            = (Stream)(object)new TeeInputStream(input, (Stream)(object)signerInputBuffer);
            }
            ServerSrpParams serverSrpParams = ServerSrpParams.Parse(input2);

            if (signerInputBuffer != null)
            {
                DigitallySigned digitallySigned = ParseSignature(input);
                ISigner         signer          = InitVerifyer(mTlsSigner, digitallySigned.Algorithm, securityParameters);
                signerInputBuffer.UpdateSigner(signer);
                if (!signer.VerifySignature(digitallySigned.Signature))
                {
                    throw new TlsFatalAlert(51);
                }
            }
            mSrpGroup = new Srp6GroupParameters(serverSrpParams.N, serverSrpParams.G);
            if (!mGroupVerifier.Accept(mSrpGroup))
            {
                throw new TlsFatalAlert(71);
            }
            mSrpSalt = serverSrpParams.S;
            try
            {
                mSrpPeerCredentials = Srp6Utilities.ValidatePublicValue(mSrpGroup.N, serverSrpParams.B);
            }
            catch (CryptoException alertCause)
            {
                throw new TlsFatalAlert(47, alertCause);
            }
            mSrpClient.Init(mSrpGroup, TlsUtilities.CreateHash(2), mContext.SecureRandom);
        }