コード例 #1
0
        public virtual byte[] ExportKeyingMaterial(string asciiLabel, byte[] context_value, int length)
        {
            if (context_value != null && !TlsUtilities.IsValidUint16(context_value.Length))
            {
                throw new ArgumentException("must have length less than 2^16 (or be null)", "context_value");
            }

            SecurityParameters sp = SecurityParameters;

            if (!sp.IsExtendedMasterSecret)
            {
                /*
                 * RFC 7627 5.4. If a client or server chooses to continue with a full handshake without
                 * the extended master secret extension, [..] the client or server MUST NOT export any
                 * key material based on the new master secret for any subsequent application-level
                 * authentication. In particular, it MUST disable [RFC5705] [..].
                 */
                throw new InvalidOperationException("cannot export keying material without extended_master_secret");
            }

            byte[] cr = sp.ClientRandom, sr = sp.ServerRandom;

            int seedLength = cr.Length + sr.Length;

            if (context_value != null)
            {
                seedLength += (2 + context_value.Length);
            }

            byte[] seed    = new byte[seedLength];
            int    seedPos = 0;

            Array.Copy(cr, 0, seed, seedPos, cr.Length);
            seedPos += cr.Length;
            Array.Copy(sr, 0, seed, seedPos, sr.Length);
            seedPos += sr.Length;
            if (context_value != null)
            {
                TlsUtilities.WriteUint16(context_value.Length, seed, seedPos);
                seedPos += 2;
                Array.Copy(context_value, 0, seed, seedPos, context_value.Length);
                seedPos += context_value.Length;
            }

            if (seedPos != seedLength)
            {
                throw new InvalidOperationException("error in calculation of seed for export");
            }

            return(TlsUtilities.PRF(this, sp.MasterSecret, asciiLabel, seed, length));
        }
コード例 #2
0
        public byte[] ExportKeyingMaterial(string asciiLabel, byte[] context_value, int length)
        {
            if (context_value != null && !TlsUtilities.IsValidUint16(context_value.Length))
            {
                throw new ArgumentException("'context_value' must have length less than 2^16 (or be null)");
            }

            SecurityParameters sp = this.securityParameters;

            byte[] cr = sp.ClientRandom, sr = sp.ServerRandom;

            int seedLength = cr.Length + sr.Length;

            if (context_value != null)
            {
                seedLength += (2 + context_value.Length);
            }

            byte[] seed    = new byte[seedLength];
            int    seedPos = 0;

            Array.Copy(cr, 0, seed, seedPos, cr.Length);
            seedPos += cr.Length;
            Array.Copy(sr, 0, seed, seedPos, sr.Length);
            seedPos += sr.Length;
            if (context_value != null)
            {
                TlsUtilities.WriteUint16(context_value.Length, seed, seedPos);
                seedPos += 2;
                Array.Copy(context_value, 0, seed, seedPos, context_value.Length);
                seedPos += context_value.Length;
            }

            if (seedPos != seedLength)
            {
                throw new InvalidOperationException("error in calculation of seed for export");
            }

            return(TlsUtilities.PRF(this, sp.MasterSecret, asciiLabel, seed, length));
        }
コード例 #3
0
    public virtual byte[] ExportKeyingMaterial(string asciiLabel, byte[] context_value, int length)
    {
        if (context_value != null && !TlsUtilities.IsValidUint16(context_value.Length))
        {
            throw new ArgumentException("must have length less than 2^16 (or be null)", "context_value");
        }
        SecurityParameters securityParameters = SecurityParameters;

        byte[] clientRandom = securityParameters.ClientRandom;
        byte[] serverRandom = securityParameters.ServerRandom;
        int    num          = clientRandom.Length + serverRandom.Length;

        if (context_value != null)
        {
            num += 2 + context_value.Length;
        }
        byte[] array = new byte[num];
        int    num2  = 0;

        Array.Copy(clientRandom, 0, array, num2, clientRandom.Length);
        num2 += clientRandom.Length;
        Array.Copy(serverRandom, 0, array, num2, serverRandom.Length);
        num2 += serverRandom.Length;
        if (context_value != null)
        {
            TlsUtilities.WriteUint16(context_value.Length, array, num2);
            num2 += 2;
            Array.Copy(context_value, 0, array, num2, context_value.Length);
            num2 += context_value.Length;
        }
        if (num2 != num)
        {
            throw new InvalidOperationException("error in calculation of seed for export");
        }
        return(TlsUtilities.PRF(this, securityParameters.MasterSecret, asciiLabel, array, length));
    }