Exemplo n.º 1
0
 /// <summary>
 /// Creates mechanism of given type with structure as parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameterStructure">Structure with mechanism parameters</param>
 /// <returns>Mechanism of given type with structure as parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, object parameterStructure)
 {
     if (parameterStructure == null)
         throw new ArgumentNullException("parameterStructure");
     
     return CreateMechanism(Convert.ToUInt64((uint)mechanism), parameterStructure);
 }
        public void _01_BasicMechanismListAndInfoTest()
        {
            if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
                Assert.Inconclusive("Test cannot be executed on this platform");

            CKR rv = CKR.CKR_OK;
            
            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath))
            {
                rv = pkcs11.C_Initialize(Settings.InitArgs40);
                if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED))
                    Assert.Fail(rv.ToString());
                
                // Find first slot with token present
                uint slotId = Helpers.GetUsableSlot(pkcs11);
                
                // Get number of supported mechanisms in first call
                uint mechanismCount = 0;
                rv = pkcs11.C_GetMechanismList(slotId, null, ref mechanismCount);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                Assert.IsTrue(mechanismCount > 0);
                
                // Allocate array for supported mechanisms
                CKM[] mechanismList = new CKM[mechanismCount];
                
                // Get supported mechanisms in second call
                rv = pkcs11.C_GetMechanismList(slotId, mechanismList, ref mechanismCount);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                // Analyze first supported mechanism
                CK_MECHANISM_INFO mechanismInfo = new CK_MECHANISM_INFO();
                rv = pkcs11.C_GetMechanismInfo(slotId, mechanismList[0], ref mechanismInfo);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                // Do something interesting with mechanism info
                
                rv = pkcs11.C_Finalize(IntPtr.Zero);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates attribute of given type with mechanism array value
        /// </summary>
        /// <param name="type">Attribute type</param>
        /// <param name="value">Attribute value</param>
        /// <returns>Attribute of given type with mechanism array value</returns>
        public static CK_ATTRIBUTE CreateAttribute(uint type, CKM[] value)
        {
            uint[] uintArray = null;
            if (value != null)
            {
                uintArray = new uint[value.Length];
                for (int i = 0; i < value.Length; i++)
                    uintArray[i] = (uint)value[i];
            }

            return CreateAttribute(type, uintArray);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Obtains a list of mechanism types supported by a token
        /// </summary>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <param name="mechanismList">
        /// If set to null then the number of mechanisms is returned in "count" parameter, without actually returning a list of mechanisms.
        /// If not set to null then "count" parameter must contain the lenght of mechanismList array and mechanism list is returned in "mechanismList" parameter.
        /// </param>
        /// <param name="count">Location that receives the number of mechanisms</param>
        /// <returns>CKR_BUFFER_TOO_SMALL, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetMechanismList(uint slotId, CKM[] mechanismList, ref uint count)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            uint[] uintList = null;
            if (mechanismList != null)
                uintList = new uint[mechanismList.Length];

            uint rv = _delegates.C_GetMechanismList(slotId, uintList, ref count);

            if (mechanismList != null)
            {
                for (int i = 0; i < mechanismList.Length; i++)
                    mechanismList[i] = (CKM)uintList[i];
            }

            return (CKR)rv;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates attribute of given type with mechanism array value
        /// </summary>
        /// <param name="type">Attribute type</param>
        /// <param name="value">Attribute value</param>
        /// <returns>Attribute of given type with mechanism array value</returns>
        public static CK_ATTRIBUTE CreateAttribute(ulong type, CKM[] value)
        {
            ulong[] ulongArray = null;
            if (value != null)
            {
                ulongArray = new ulong[value.Length];
                for (int i = 0; i < value.Length; i++)
                    ulongArray[i] = Convert.ToUInt64((uint)value[i]);
            }

            return CreateAttribute(type, ulongArray);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 public Mechanism(CKM type, byte[] parameter)
 {
     if (Platform.UnmanagedLongSize == 4)
     {
         if (Platform.StructPackingSize == 0)
             _mechanism40 = new HighLevelAPI40.Mechanism(Convert.ToUInt32(type), parameter);
         else
             _mechanism41 = new HighLevelAPI41.Mechanism(Convert.ToUInt32(type), parameter);
     }
     else
     {
         if (Platform.StructPackingSize == 0)
             _mechanism80 = new HighLevelAPI80.Mechanism(type, parameter);
         else
             _mechanism81 = new HighLevelAPI81.Mechanism(type, parameter);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return CreateMechanism((uint)mechanism);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return CreateMechanism(Convert.ToUInt64((uint)mechanism), parameter);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Converts CKM to NativeULong
 /// </summary>
 /// <param name="value">CKM that should be converted</param>
 /// <returns>NativeULong with value from CKM</returns>
 public static NativeULong ConvertFromCKM(CKM value)
 {
     return(Convert.ToUInt64(value));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return(CreateMechanism((uint)mechanism));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return(CreateMechanism((uint)mechanism, parameter));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return(CreateMechanism(NativeLongUtils.ConvertFromCKM(mechanism)));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return(CreateMechanism(NativeLongUtils.ConvertFromCKM(mechanism), parameter));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return(CreateMechanism(Convert.ToUInt64((uint)mechanism), parameter));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return(CreateMechanism(Convert.ToUInt64((uint)mechanism)));
 }
Exemplo n.º 16
0
 public MechanismTypeAttribute(CKA type, CKM mechanismType) : base((uint)type)
 {
     MechanismType = mechanismType;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 public Mechanism(CKM type, byte[] parameter)
 {
     _ckMechanism = CkmUtils.CreateMechanism(type, parameter);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Obtains information about a particular mechanism possibly supported by a token
 /// </summary>
 /// <param name="mechanism">Mechanism</param>
 /// <returns>Information about mechanism</returns>
 public MechanismInfo GetMechanismInfo(CKM mechanism)
 {
     CK_MECHANISM_INFO mechanismInfo = new CK_MECHANISM_INFO();
     CKR rv = _p11.C_GetMechanismInfo(_slotId, mechanism, ref mechanismInfo);
     if (rv != CKR.CKR_OK)
         throw new Pkcs11Exception("C_GetMechanismInfo", rv);
     
     return new MechanismInfo(mechanism, mechanismInfo);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 public Mechanism(CKM type)
 {
     _ckMechanism = CkmUtils.CreateMechanism(type);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Obtains a list of mechanism types supported by a token
        /// </summary>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <param name="mechanismList">
        /// If set to null then the number of mechanisms is returned in "count" parameter, without actually returning a list of mechanisms.
        /// If not set to null then "count" parameter must contain the lenght of mechanismList array and mechanism list is returned in "mechanismList" parameter.
        /// </param>
        /// <param name="count">Location that receives the number of mechanisms</param>
        /// <returns>CKR_BUFFER_TOO_SMALL, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetMechanismList(ulong slotId, CKM[] mechanismList, ref ulong count)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            ulong[] ulongList = null;
            if (mechanismList != null)
                ulongList = new ulong[mechanismList.Length];

            ulong rv = _delegates.C_GetMechanismList(slotId, ulongList, ref count);

            if (mechanismList != null)
            {
                for (int i = 0; i < mechanismList.Length; i++)
                    mechanismList[i] = (CKM)Convert.ToUInt32(ulongList[i]);
            }

            return (CKR)Convert.ToUInt32(rv);
        }
 /// <summary>
 /// Creates mechanism of given type with object parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism and its parameter</returns>
 public IMechanism Create(CKM type, IMechanismParams parameter)
 {
     return(new Mechanism(type, parameter));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Obtain a parameter class here.
        /// </summary>
        /// <param name="ckm"></param>
        /// <returns></returns>
        public static Parameters GetParameters(CKM ckm)
        {
            Parameters lParameters = new Parameters();

            return(lParameters);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Obtains information about a particular mechanism possibly supported by a token
 /// </summary>
 /// <param name="mechanism">Mechanism</param>
 /// <returns>Information about mechanism</returns>
 public MechanismInfo GetMechanismInfo(CKM mechanism)
 {
     if (Platform.UnmanagedLongSize == 4)
         return (Platform.StructPackingSize == 0) ? new MechanismInfo(_slot40.GetMechanismInfo(mechanism)) : new MechanismInfo(_slot41.GetMechanismInfo(mechanism));
     else
         return (Platform.StructPackingSize == 0) ? new MechanismInfo(_slot80.GetMechanismInfo(mechanism)) : new MechanismInfo(_slot81.GetMechanismInfo(mechanism));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism and its parameter</returns>
 public IMechanism Create(CKM type, byte[] parameter)
 {
     return(_factory.Create(type, parameter));
 }
Exemplo n.º 25
0
        /// <summary>
        /// Obtains information about a particular mechanism possibly supported by a token
        /// </summary>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <param name="type">The type of mechanism</param>
        /// <param name="info">Structure that receives the mechanism information</param>
        /// <returns>CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_MECHANISM_INVALID, CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetMechanismInfo(ulong slotId, CKM type, ref CK_MECHANISM_INFO info)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            ulong rv = _delegates.C_GetMechanismInfo(slotId, Convert.ToUInt64(type), ref info);
            return (CKR)Convert.ToUInt32(rv);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Creates mechanism of given type with object parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism and its parameter</returns>
 public IMechanism Create(CKM type, IMechanismParams parameter)
 {
     return(_factory.Create(type, parameter));
 }
Exemplo n.º 27
0
        /// <summary>
        /// Creates mechanism of given type with object parameter
        /// </summary>
        /// <param name="type">Mechanism type</param>
        /// <param name="parameter">Mechanism parameter</param>
        public Mechanism(CKM type, IMechanismParams parameter)
        {
            if (parameter == null)
                throw new ArgumentNullException("parameter");

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                    _mechanism40 = new HighLevelAPI40.Mechanism(Convert.ToUInt32(type), parameter);
                else
                    _mechanism41 = new HighLevelAPI41.Mechanism(Convert.ToUInt32(type), parameter);
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                    _mechanism80 = new HighLevelAPI80.Mechanism(type, parameter);
                else
                    _mechanism81 = new HighLevelAPI81.Mechanism(type, parameter);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <returns>Mechanism with no parameter</returns>
 public IMechanism Create(CKM type)
 {
     return(_factory.Create(type));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return CreateMechanism((uint)mechanism, parameter);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 public Mechanism(CKM type, byte[] parameter)
 {
     _ckMechanism = CkmUtils.CreateMechanism(type, parameter);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Obtains information about a particular mechanism possibly supported by a token
        /// </summary>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <param name="type">The type of mechanism</param>
        /// <param name="info">Structure that receives the mechanism information</param>
        /// <returns>CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_MECHANISM_INVALID, CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetMechanismInfo(uint slotId, CKM type, ref CK_MECHANISM_INFO info)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            uint rv = _delegates.C_GetMechanismInfo(slotId, (uint)type, ref info);
            return (CKR)rv;
        }
Exemplo n.º 32
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 public Mechanism(CKM type)
 {
     _ckMechanism = CkmUtils.CreateMechanism(type);
 }
Exemplo n.º 33
0
        /// <summary>
        /// Reads value of attribute and returns it as mechanism array
        /// </summary>
        /// <param name="attribute">Attribute whose value should be read</param>
        /// <param name="value">Location that receives attribute value</param>
        public static void ConvertValue(ref CK_ATTRIBUTE attribute, out CKM[] value)
        {
            ulong[] ulongArray = null;
            ConvertValue(ref attribute, out ulongArray);

            CKM[] ckmArray = null;
            if (ulongArray != null)
            {
                ckmArray = new CKM[ulongArray.Length];
                for (int i = 0; i < ulongArray.Length; i++)
                    ckmArray[i] = (CKM)Convert.ToUInt32(ulongArray[i]);
            }
            value = ckmArray;
        }
Exemplo n.º 34
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return(CreateMechanism(ConvertUtils.UInt64FromCKM(mechanism)));
 }
Exemplo n.º 35
0
        /// <summary>
        /// Reads value of attribute and returns it as mechanism array
        /// </summary>
        /// <param name="attribute">Attribute whose value should be read</param>
        /// <param name="value">Location that receives attribute value</param>
        public static void ConvertValue(ref CK_ATTRIBUTE attribute, out CKM[] value)
        {
            uint[] uintArray = null;
            ConvertValue(ref attribute, out uintArray);

            CKM[] ckmArray = null;
            if (uintArray != null)
            {
                ckmArray = new CKM[uintArray.Length];
                for (int i = 0; i < uintArray.Length; i++)
                    ckmArray[i] = (CKM)uintArray[i];
            }
            value = ckmArray;
        }
Exemplo n.º 36
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism of given type with byte array parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism, byte[] parameter)
 {
     return(CreateMechanism(ConvertUtils.UInt64FromCKM(mechanism), parameter));
 }
Exemplo n.º 37
0
        /// <summary>
        /// Creates mechanism of given type with object parameter
        /// </summary>
        /// <param name="type">Mechanism type</param>
        /// <param name="parameter">Mechanism parameter</param>
        public Mechanism(CKM type, IMechanismParams parameter)
        {
            if (parameter == null)
                throw new ArgumentNullException("parameter");

            // Keep reference to parameter so GC will not free it while mechanism exists
            _mechanismParams = parameter;

            object lowLevelParams = _mechanismParams.ToMarshalableStructure();
            _ckMechanism = CkmUtils.CreateMechanism(type, lowLevelParams);
        }
        public void _09_MechanismArrayAttributeTest()
        {
            if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 1)
                Assert.Inconclusive("Test cannot be executed on this platform");

            CKM[] originalValue = new CKM[2];
            originalValue[0] = CKM.CKM_RSA_PKCS;
            originalValue[1] = CKM.CKM_AES_CBC;
            // Create attribute with mechanism array value
            CK_ATTRIBUTE attr = CkaUtils.CreateAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue);
            Assert.IsTrue(attr.type == (uint)CKA.CKA_ALLOWED_MECHANISMS);
            Assert.IsTrue(attr.value != IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == (UnmanagedMemory.SizeOf(typeof(uint)) * originalValue.Length));
            
            CKM[] recoveredValue = null;
            // Read the value of attribute
            CkaUtils.ConvertValue(ref attr, out recoveredValue);
            Assert.IsTrue(originalValue.Length == recoveredValue.Length);
            for (int i = 0; i < recoveredValue.Length; i++)
            {
                Assert.IsTrue(originalValue[i] == recoveredValue[i]);
            }

            // Free attribute value
            UnmanagedMemory.Free(ref attr.value);
            attr.valueLen = 0;
            Assert.IsTrue(attr.type == (uint)CKA.CKA_ALLOWED_MECHANISMS);
            Assert.IsTrue(attr.value == IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == 0);

            // Create attribute with null mechanism array value
            attr = CkaUtils.CreateAttribute(CKA.CKA_ALLOWED_MECHANISMS, (CKM[])null);
            Assert.IsTrue(attr.type == (uint)CKA.CKA_ALLOWED_MECHANISMS);
            Assert.IsTrue(attr.value == IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == 0);
            
            // Create attribute with empty mechanism array value
            attr = CkaUtils.CreateAttribute(CKA.CKA_ALLOWED_MECHANISMS, new CKM[0]);
            Assert.IsTrue(attr.type == (uint)CKA.CKA_ALLOWED_MECHANISMS);
            Assert.IsTrue(attr.value == IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == 0);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="mechanism">Mechanism type</param>
 /// <returns>Mechanism of given type with no parameter</returns>
 public static CK_MECHANISM CreateMechanism(CKM mechanism)
 {
     return CreateMechanism(Convert.ToUInt64((uint)mechanism));
 }
Exemplo n.º 40
0
 /// <summary>
 /// Converts CKM to UInt32
 /// </summary>
 /// <param name="value">CKM that should be converted</param>
 /// <returns>UInt32 with value from CKM</returns>
 public static UInt32 UInt32FromCKM(CKM value)
 {
     return(Convert.ToUInt32(value));
 }
Exemplo n.º 41
0
 /// <summary>
 /// Converts CKM to UInt64
 /// </summary>
 /// <param name="value">CKM that should be converted</param>
 /// <returns>UInt64 with value from CKM</returns>
 public static UInt64 UInt64FromCKM(CKM value)
 {
     return(Convert.ToUInt64(value));
 }
Exemplo n.º 42
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <returns>Mechanism with no parameter</returns>
 public IMechanism CreateMechanism(CKM type)
 {
     return(new Mechanism(type));
 }
Exemplo n.º 43
0
        /// <summary>
        /// Obtains a list of mechanism types supported by a token
        /// </summary>
        /// <returns>List of mechanism types supported by a token</returns>
        public List<CKM> GetMechanismList()
        {
            ulong mechanismCount = 0;
            CKR rv = _p11.C_GetMechanismList(_slotId, null, ref mechanismCount);
            if (rv != CKR.CKR_OK)
                throw new Pkcs11Exception("C_GetMechanismList", rv);

            if (mechanismCount < 1)
                return new List<CKM>();

            CKM[] mechanismList = new CKM[mechanismCount];
            rv = _p11.C_GetMechanismList(_slotId, mechanismList, ref mechanismCount);
            if (rv != CKR.CKR_OK)
                throw new Pkcs11Exception("C_GetMechanismList", rv);

            if (mechanismList.Length != Convert.ToInt32(mechanismCount))
                Array.Resize(ref mechanismList, Convert.ToInt32(mechanismCount));

            return new List<CKM>(mechanismList);
        }
Exemplo n.º 44
0
 /// <summary>
 /// Creates mechanism of given type with byte array parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 /// <param name="parameter">Mechanism parameter</param>
 /// <returns>Mechanism and its parameter</returns>
 public IMechanism CreateMechanism(CKM type, byte[] parameter)
 {
     return(new Mechanism(type, parameter));
 }
Exemplo n.º 45
0
 /// <summary>
 /// Converts low level CK_MECHANISM_INFO structure to high level MechanismInfo class
 /// </summary>
 /// <param name="mechanism">Mechanism</param>
 /// <param name="ck_mechanism_info">Low level CK_MECHANISM_INFO structure</param>
 internal MechanismInfo(CKM mechanism, CK_MECHANISM_INFO ck_mechanism_info)
 {
     _mechanism = mechanism;
     _minKeySize = ck_mechanism_info.MinKeySize;
     _maxKeySize = ck_mechanism_info.MaxKeySize;
     _mechanismFlags = new MechanismFlags(ck_mechanism_info.Flags);
 }
Exemplo n.º 46
0
 /// <summary>
 /// Creates mechanism of given type with no parameter
 /// </summary>
 /// <param name="type">Mechanism type</param>
 public Mechanism(CKM type)
 {
     _ckMechanism = LowLevelAPI.CkmUtils.CreateMechanism(type);
 }