Ejemplo n.º 1
0
        /// <summary>
        /// Opens a session between an application and a token in a particular slot
        /// </summary>
        /// <param name="sessionType">Type of session to be opened</param>
        /// <returns>Session</returns>
        public ISession OpenSession(SessionType sessionType)
        {
            _logger.Debug("Slot({0})::OpenSession", _slotId);

            NativeULong flags = CKF.CKF_SERIAL_SESSION;

            if (sessionType == SessionType.ReadWrite)
            {
                flags = flags | CKF.CKF_RW_SESSION;
            }

            NativeULong sessionId = CK.CK_INVALID_HANDLE;
            CKR         rv        = _p11.C_OpenSession(_slotId, flags, IntPtr.Zero, IntPtr.Zero, ref sessionId);

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

            if (_logger.IsEnabled(Pkcs11InteropLogLevel.Info))
            {
                _logger.Info("Opened {0} session {1} with token in slot {2}", Pkcs11InteropLogUtils.ToString(sessionType), sessionId, _slotId);
            }

            return(_factories.SessionFactory.CreateSession(_factories, _p11, sessionId));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens a session between an application and a token in a particular slot
        /// </summary>
        /// <param name="sessionType">Type of session to be opened</param>
        /// <returns>Session</returns>
        public Session OpenSession(SessionType sessionType)
        {
            uint flags = CKF.CKF_SERIAL_SESSION;

            if (sessionType == SessionType.ReadWrite)
            {
                flags = flags | CKF.CKF_RW_SESSION;
            }

            uint sessionId = CK.CK_INVALID_HANDLE;
            CKR  rv        = _p11.C_OpenSession(_slotId, flags, IntPtr.Zero, IntPtr.Zero, ref sessionId);

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

            return(new Session(_p11, sessionId));
        }