コード例 #1
0
ファイル: TLSUtils.cs プロジェクト: kdurkin77/DTLS2.Net
        public static byte[] GetVerifyData(Version version, HandshakeInfo handshakeInfo, bool client, bool isClientFinished,
                                           byte[] handshakeHash)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (handshakeInfo == null)
            {
                throw new ArgumentNullException(nameof(handshakeInfo));
            }

            if (handshakeHash == null)
            {
                throw new ArgumentNullException(nameof(handshakeHash));
            }

            TlsContext context    = new DTLSContext(client, version, handshakeInfo);
            var        asciiLabel = isClientFinished ? ExporterLabel.client_finished : ExporterLabel.server_finished;

            return(TlsUtilities.IsTlsV11(context) ?
                   TlsUtilities.PRF_legacy(handshakeInfo.MasterSecret, asciiLabel, handshakeHash, 12)
                : TlsUtilities.PRF(context, handshakeInfo.MasterSecret, asciiLabel, handshakeHash, 12));
        }
コード例 #2
0
ファイル: TLSUtils.cs プロジェクト: kdurkin77/DTLS2.Net
        public static TlsCipher AssignCipher(byte[] preMasterSecret, bool client, Version version, HandshakeInfo handshakeInfo)
        {
            if (preMasterSecret == null)
            {
                throw new ArgumentNullException(nameof(preMasterSecret));
            }

            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (handshakeInfo == null)
            {
                throw new ArgumentNullException(nameof(handshakeInfo));
            }

            TlsContext context            = new DTLSContext(client, version, handshakeInfo);
            var        securityParameters = context.SecurityParameters;
            var        seed       = securityParameters.ClientRandom.Concat(securityParameters.ServerRandom).ToArray();
            var        asciiLabel = ExporterLabel.master_secret;

            handshakeInfo.MasterSecret = TlsUtilities.IsTlsV11(context) ?
                                         TlsUtilities.PRF_legacy(preMasterSecret, asciiLabel, seed, 48)
                : TlsUtilities.PRF(context, preMasterSecret, asciiLabel, seed, 48);

            seed = securityParameters.ServerRandom.Concat(securityParameters.ClientRandom).ToArray();
            var key_block = TlsUtilities.IsTlsV11(context) ?
                            TlsUtilities.PRF_legacy(handshakeInfo.MasterSecret, ExporterLabel.key_expansion, seed, 96)
                : TlsUtilities.PRF(context, handshakeInfo.MasterSecret, ExporterLabel.key_expansion, seed, 96);

            return(_CipherFactory
                   .CreateCipher(context, _GetEncryptionAlgorithm(handshakeInfo.CipherSuite), _GetMACAlgorithm(handshakeInfo.CipherSuite)));
        }
コード例 #3
0
ファイル: TLSUtils.cs プロジェクト: kdurkin77/DTLS2.Net
        public static byte[] CalculateKeyBlock(TlsContext context, int size)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }

            var securityParameters = context.SecurityParameters;
            var master_secret      = securityParameters.MasterSecret;
            var seed = securityParameters.ServerRandom.Concat(securityParameters.ClientRandom).ToArray();

            return(TlsUtilities.IsTlsV11(context)
                ? TlsUtilities.PRF_legacy(master_secret, ExporterLabel.key_expansion, seed, size)
                : TlsUtilities.PRF(context, master_secret, ExporterLabel.key_expansion, seed, size));
        }