Information about the random data of a client and a server in an SSL context
Inheritance: IMechanismParams, IDisposable
コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the CkTlsKdfParams class.
        /// </summary>
        /// <param name="prfMechanism">Hash mechanism used in the TLS 1.2 PRF construct or CKM_TLS_PRF to use with the TLS 1.0 and 1.1 PRF construct (CKM)</param>
        /// <param name="label">Label for this key derivation</param>
        /// <param name="randomInfo">Random data for the key derivation</param>
        /// <param name="contextData">Context data for this key derivation</param>
        public CkTlsKdfParams(ulong prfMechanism, byte[] label, CkSsl3RandomData randomInfo, byte[] contextData)
        {
            if (randomInfo == null)
            {
                throw new ArgumentNullException("randomInfo");
            }

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params40 = new HighLevelAPI40.MechanismParams.CkTlsKdfParams(Convert.ToUInt32(prfMechanism), label, _randomInfo._params40, contextData);
                }
                else
                {
                    _params41 = new HighLevelAPI41.MechanismParams.CkTlsKdfParams(Convert.ToUInt32(prfMechanism), label, _randomInfo._params41, contextData);
                }
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params80 = new HighLevelAPI80.MechanismParams.CkTlsKdfParams(prfMechanism, label, _randomInfo._params80, contextData);
                }
                else
                {
                    _params81 = new HighLevelAPI81.MechanismParams.CkTlsKdfParams(prfMechanism, label, _randomInfo._params81, contextData);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the CkTls12MasterKeyDeriveParams class.
        /// </summary>
        /// <param name="randomInfo">Client's and server's random data information</param>
        /// <param name="prfHashMechanism">Base hash used in the underlying TLS 1.2 PRF operation used to derive the master key (CKM)</param>
        public CkTls12MasterKeyDeriveParams(CkSsl3RandomData randomInfo, ulong prfHashMechanism)
        {
            if (randomInfo == null)
            {
                throw new ArgumentNullException("randomInfo");
            }

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params40 = new HighLevelAPI40.MechanismParams.CkTls12MasterKeyDeriveParams(_randomInfo._params40, Convert.ToUInt32(prfHashMechanism));
                }
                else
                {
                    _params41 = new HighLevelAPI41.MechanismParams.CkTls12MasterKeyDeriveParams(_randomInfo._params41, Convert.ToUInt32(prfHashMechanism));
                }
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params80 = new HighLevelAPI80.MechanismParams.CkTls12MasterKeyDeriveParams(_randomInfo._params80, prfHashMechanism);
                }
                else
                {
                    _params81 = new HighLevelAPI81.MechanismParams.CkTls12MasterKeyDeriveParams(_randomInfo._params81, prfHashMechanism);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the CkSsl3KeyMatParams class.
        /// </summary>
        /// <param name='macSizeInBits'>The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param>
        /// <param name='keySizeInBits'>The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param>
        /// <param name='ivSizeInBits'>The length (in bits) of the IV agreed upon during the protocol handshake phase or if no IV is required, the length should be set to 0</param>
        /// <param name='isExport'>Flag indicating whether the keys have to be derived for an export version of the protocol</param>
        /// <param name='randomInfo'>Client's and server's random data information</param>
        public CkSsl3KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, CkSsl3RandomData randomInfo)
        {
            if (randomInfo == null)
            {
                throw new ArgumentNullException("randomInfo");
            }

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params40 = new HighLevelAPI40.MechanismParams.CkSsl3KeyMatParams(Convert.ToUInt32(macSizeInBits), Convert.ToUInt32(keySizeInBits), Convert.ToUInt32(ivSizeInBits), isExport, _randomInfo._params40);
                }
                else
                {
                    _params41 = new HighLevelAPI41.MechanismParams.CkSsl3KeyMatParams(Convert.ToUInt32(macSizeInBits), Convert.ToUInt32(keySizeInBits), Convert.ToUInt32(ivSizeInBits), isExport, _randomInfo._params41);
                }
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                {
                    _params80 = new HighLevelAPI80.MechanismParams.CkSsl3KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, _randomInfo._params80);
                }
                else
                {
                    _params81 = new HighLevelAPI81.MechanismParams.CkSsl3KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, _randomInfo._params81);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the CkSsl3KeyMatParams class.
        /// </summary>
        /// <param name='macSizeInBits'>The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param>
        /// <param name='keySizeInBits'>The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param>
        /// <param name='ivSizeInBits'>The length (in bits) of the IV agreed upon during the protocol handshake phase or if no IV is required, the length should be set to 0</param>
        /// <param name='isExport'>Flag indicating whether the keys have to be derived for an export version of the protocol</param>
        /// <param name='randomInfo'>Client's and server's random data information</param>
        public CkSsl3KeyMatParams(uint macSizeInBits, uint keySizeInBits, uint ivSizeInBits, bool isExport, CkSsl3RandomData randomInfo)
        {
            if (randomInfo == null)
            {
                throw new ArgumentNullException("randomInfo");
            }

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (ivSizeInBits % 8 != 0)
            {
                throw new ArgumentException("Value has to be a multiple of 8", "ivSizeInBits");
            }

            // GC will not free ReturnedKeyMaterial while this object exists
            _returnedKeyMaterial = new CkSsl3KeyMatOut(ivSizeInBits / 8);

            _lowLevelStruct.MacSizeInBits = macSizeInBits;
            _lowLevelStruct.KeySizeInBits = keySizeInBits;
            _lowLevelStruct.IVSizeInBits  = ivSizeInBits;
            _lowLevelStruct.IsExport      = isExport;
            _lowLevelStruct.RandomInfo    = (CK_SSL3_RANDOM_DATA)_randomInfo.ToLowLevelParams();

            // Abrakadabra :)
            _lowLevelStruct.ReturnedKeyMaterial = UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_SSL3_KEY_MAT_OUT)));
            UnmanagedMemory.Write(_lowLevelStruct.ReturnedKeyMaterial, _returnedKeyMaterial._lowLevelStruct);
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the CkSsl3MasterKeyDeriveParams class.
        /// </summary>
        /// <param name='randomInfo'>Client's and server's random data information</param>
        /// <param name='dh'>Set to false for CKM_SSL3_MASTER_KEY_DERIVE mechanism and to true for CKM_SSL3_MASTER_KEY_DERIVE_DH mechanism</param>
        public CkSsl3MasterKeyDeriveParams(CkSsl3RandomData randomInfo, bool dh)
        {
            if (randomInfo == null)
            {
                throw new ArgumentNullException("randomInfo");
            }

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToLowLevelParams();
            _lowLevelStruct.Version    = (dh) ? IntPtr.Zero : UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_VERSION)));
        }
コード例 #6
0
        /// <summary>
        /// Disposes object
        /// </summary>
        /// <param name="disposing">Flag indicating whether managed resources should be disposed</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    // Dispose managed objects
                    if (_params40 != null)
                    {
                        _params40.Dispose();
                        _params40 = null;
                    }

                    if (_params41 != null)
                    {
                        _params41.Dispose();
                        _params41 = null;
                    }

                    if (_params80 != null)
                    {
                        _params80.Dispose();
                        _params80 = null;
                    }

                    if (_params81 != null)
                    {
                        _params81.Dispose();
                        _params81 = null;
                    }

                    if (_returnedKeyMaterialLeftInstance == false)
                    {
                        if (_returnedKeyMaterial != null)
                        {
                            _returnedKeyMaterial.Dispose();
                            _returnedKeyMaterial = null;
                        }
                    }

                    // Release the reference to randomInfo so GC knows this object doesn't need it anymore
                    _randomInfo = null;
                }

                // Dispose unmanaged objects

                _disposed = true;
            }
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the CkSsl3KeyMatParams class.
        /// </summary>
        /// <param name='macSizeInBits'>The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param>
        /// <param name='keySizeInBits'>The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param>
        /// <param name='ivSizeInBits'>The length (in bits) of the IV agreed upon during the protocol handshake phase or if no IV is required, the length should be set to 0</param>
        /// <param name='isExport'>Flag indicating whether the keys have to be derived for an export version of the protocol</param>
        /// <param name='randomInfo'>Client's and server's random data information</param>
        public CkSsl3KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, CkSsl3RandomData randomInfo)
        {
            if (randomInfo == null)
                throw new ArgumentNullException("randomInfo");

            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                    _params40 = new HighLevelAPI40.MechanismParams.CkSsl3KeyMatParams(Convert.ToUInt32(macSizeInBits), Convert.ToUInt32(keySizeInBits), Convert.ToUInt32(ivSizeInBits), isExport, _randomInfo._params40);
                else
                    _params41 = new HighLevelAPI41.MechanismParams.CkSsl3KeyMatParams(Convert.ToUInt32(macSizeInBits), Convert.ToUInt32(keySizeInBits), Convert.ToUInt32(ivSizeInBits), isExport, _randomInfo._params41);
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                    _params80 = new HighLevelAPI80.MechanismParams.CkSsl3KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, _randomInfo._params80);
                else
                    _params81 = new HighLevelAPI81.MechanismParams.CkSsl3KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, _randomInfo._params81);
            }
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the CkSsl3MasterKeyDeriveParams class.
        /// </summary>
        /// <param name='randomInfo'>Client's and server's random data information</param>
        /// <param name='dh'>Set to false for CKM_SSL3_MASTER_KEY_DERIVE mechanism and to true for CKM_SSL3_MASTER_KEY_DERIVE_DH mechanism</param>
        public CkSsl3MasterKeyDeriveParams(CkSsl3RandomData randomInfo, bool dh)
        {
            if (randomInfo == null)
                throw new ArgumentNullException("randomInfo");
            
            // Keep reference to randomInfo so GC will not free it while this object exists
            _randomInfo = randomInfo;

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                    _params40 = new HighLevelAPI40.MechanismParams.CkSsl3MasterKeyDeriveParams(_randomInfo._params40, dh);
                else
                    _params41 = new HighLevelAPI41.MechanismParams.CkSsl3MasterKeyDeriveParams(_randomInfo._params41, dh);
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                    _params80 = new HighLevelAPI80.MechanismParams.CkSsl3MasterKeyDeriveParams(_randomInfo._params80, dh);
                else
                    _params81 = new HighLevelAPI81.MechanismParams.CkSsl3MasterKeyDeriveParams(_randomInfo._params81, dh);
            }
        }