示例#1
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>
 protected 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);
 }
        public void _01_BasicMechanismListAndInfoTest()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 1)
            {
                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.InitArgs81);
                if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED))
                {
                    Assert.Fail(rv.ToString());
                }

                // Find first slot with token present
                ulong slotId = Helpers.GetUsableSlot(pkcs11);

                // Get number of supported mechanisms in first call
                ulong 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());
                }
            }
        }
        public void _01_BasicMechanismListAndInfoTest()
        {
            Helpers.CheckPlatform();

            CKR rv = CKR.CKR_OK;

            using (Pkcs11Library pkcs11Library = new Pkcs11Library(Settings.Pkcs11LibraryPath))
            {
                rv = pkcs11Library.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
                NativeULong slotId = Helpers.GetUsableSlot(pkcs11Library);

                // Get number of supported mechanisms in first call
                NativeULong mechanismCount = 0;
                rv = pkcs11Library.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 = pkcs11Library.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 = pkcs11Library.C_GetMechanismInfo(slotId, mechanismList[0], ref mechanismInfo);
                if (rv != CKR.CKR_OK)
                {
                    Assert.Fail(rv.ToString());
                }

                // Do something interesting with mechanism info

                rv = pkcs11Library.C_Finalize(IntPtr.Zero);
                if (rv != CKR.CKR_OK)
                {
                    Assert.Fail(rv.ToString());
                }
            }
        }
示例#4
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));
        }
示例#5
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 IMechanismInfo GetMechanismInfo(CKM mechanism)
        {
            _logger.Debug("Slot({0})::GetMechanismInfo", _slotId);

            CK_MECHANISM_INFO mechanismInfo = new CK_MECHANISM_INFO();
            CKR rv = _pkcs11Library.C_GetMechanismInfo(_slotId, mechanism, ref mechanismInfo);

            if (rv != CKR.CKR_OK)
            {
                throw new Pkcs11Exception("C_GetMechanismInfo", rv);
            }

            return(new MechanismInfo(mechanism, mechanismInfo));
        }
示例#6
0
 internal MechanismInfo(CK_MECHANISM_INFO mi)
 {
     this.mi = mi;
 }