예제 #1
0
        /// <summary>
        /// Obtains information about a session
        /// </summary>
        /// <param name="session">The session's handle</param>
        /// <param name="info">Structure that receives the session 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_OK, CKR_SESSION_CLOSED, CKR_SESSION_HANDLE_INVALID, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetSessionInfo(uint session, ref CK_SESSION_INFO info)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            uint rv = _delegates.C_GetSessionInfo(session, ref info);
            return (CKR)rv;
        }
        public void _03_SessionInfoTest()
        {
            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);
                
                // Open RO (read-only) session
                uint session = CK.CK_INVALID_HANDLE;
                rv = pkcs11.C_OpenSession(slotId, CKF.CKF_SERIAL_SESSION, IntPtr.Zero, IntPtr.Zero, ref session);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                CK_SESSION_INFO sessionInfo = new CK_SESSION_INFO();
                rv = pkcs11.C_GetSessionInfo(session, ref sessionInfo);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                // Do something interesting with session info
                Assert.IsTrue(sessionInfo.SlotId == slotId);
                
                rv = pkcs11.C_CloseAllSessions(slotId);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                rv = pkcs11.C_Finalize(IntPtr.Zero);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
            }
        }
예제 #3
0
 internal static extern uint C_GetSessionInfo(uint session, ref CK_SESSION_INFO info);
예제 #4
0
 internal static extern CKR C_GetSessionInfo(uint session, ref CK_SESSION_INFO info);
예제 #5
0
        /// <summary>
        /// Obtains information about a session
        /// </summary>
        /// <returns>Information about a session</returns>
        public SessionInfo GetSessionInfo()
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            CK_SESSION_INFO sessionInfo = new CK_SESSION_INFO();
            CKR rv = _p11.C_GetSessionInfo(_sessionId, ref sessionInfo);
            if (rv != CKR.CKR_OK)
                throw new Pkcs11Exception("C_GetSessionInfo", rv);

            return new SessionInfo(_sessionId, sessionInfo);
        }
예제 #6
0
 /// <summary>
 /// Converts low level CK_SESSION_INFO structure to high level SessionInfo class
 /// </summary>
 /// <param name="sessionId">PKCS#11 handle of session</param>
 /// <param name="ck_session_info">Low level CK_SESSION_INFO structure</param>
 internal SessionInfo(uint sessionId, CK_SESSION_INFO ck_session_info)
 {
     _sessionId = sessionId;
     _slotId = ck_session_info.SlotId;
     _state = (CKS)ck_session_info.State;
     _sessionFlags = new SessionFlags(ck_session_info.Flags);
     _deviceError = ck_session_info.DeviceError;
 }
예제 #7
0
 internal static extern NativeULong C_GetSessionInfo(NativeULong session, ref CK_SESSION_INFO info);