public CardSigningCertificate(ISlot slot, byte[] ckaValue, IObjectHandle privateKeyHandle, IPinProvider pinProvider)
 {
     this.slot             = slot ?? throw new ArgumentNullException(nameof(slot));
     this.RawCertificate   = ckaValue ?? throw new ArgumentNullException(nameof(ckaValue));
     this.privateKeyHandle = privateKeyHandle ?? throw new ArgumentNullException(nameof(privateKeyHandle));
     this.pinProvider      = pinProvider ?? throw new ArgumentNullException(nameof(pinProvider));
 }
예제 #2
0
        public PinHub(IPinProvider pinProvider)
        {
            this.pinProvider = pinProvider;

            pinProvider.InputPinStateChange = (index, state) =>
            {
                InputPinStateChange(index, state);
            };
        }
예제 #3
0
        public PinHub(IPinProvider pinProvider)
        {
            this.pinProvider = pinProvider;

            pinProvider.InputPinStateChange = (index, state) =>
            {
                InputPinStateChange(index, state);
            };
        }
 public MediaConnector(FilterGraph filterGraph,
                       IFilterRegister filterRegister,
                       IErrorHandler errorHandler,
                       IPinProvider pinProvider)
 {
     this.filterGraph    = filterGraph;
     this.filterRegister = filterRegister;
     this.errorHandler   = errorHandler;
     this.pinProvider    = pinProvider;
 }
예제 #5
0
        /// <summary>
        /// Creates new instance of Pkcs11X509Store class.
        /// Also loads and initializes unmanaged PCKS#11 library.
        /// </summary>
        /// <param name="libraryPath">Name of or path to PKCS#11 library</param>
        /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
        public Pkcs11X509Store(string libraryPath, IPinProvider pinProvider)
        {
            if (string.IsNullOrEmpty(libraryPath))
            {
                throw new ArgumentNullException(nameof(libraryPath));
            }

            if (pinProvider == null)
            {
                throw new ArgumentNullException(nameof(pinProvider));
            }

            _storeContext = this.GetStoreContext(libraryPath, pinProvider);
            _slots        = this.GetSlots();
        }
        public CardDeviceController(string pkcs11Libpath, IPinProvider pinProvider, string zepLabel = "SIG_ZEP")
        {
            if (pkcs11Libpath == null)
            {
                throw new ArgumentNullException(nameof(pkcs11Libpath));
            }
            if (pinProvider == null)
            {
                throw new ArgumentNullException(nameof(pinProvider));
            }

            this.pinProvider = pinProvider;
            Pkcs11InteropFactories factories = new Pkcs11InteropFactories();

            this.pkcs11 = factories.Pkcs11LibraryFactory.LoadPkcs11Library(factories, pkcs11Libpath, AppType.SingleThreaded);

            try
            {
                List <ISlot> slots = this.pkcs11.GetSlotList(SlotsType.WithTokenPresent);
                this.slot = slots.SingleOrDefault(t => string.IsNullOrEmpty(zepLabel) || string.Equals(t.GetTokenInfo().Label, zepLabel, StringComparison.Ordinal));
                if (this.slot == null)
                {
                    this.pkcs11.Dispose();
                    throw new ArgumentException($"PKCS#11 lib '{pkcs11Libpath}' can not contains slot with label '{zepLabel}'.");
                }

                this.loginSession = this.slot.OpenSession(SessionType.ReadOnly);

                if (!this.SessionIsAuthenticated(this.loginSession))
                {
                    SecureString pin = pinProvider.GetBokPin();
                    try
                    {
                        this.loginSession.Login(CKU.CKU_USER, pin);
                    }
                    finally
                    {
                        pin?.Dispose();
                    }
                }
            }
            catch (Exception)
            {
                this.loginSession?.Dispose();
                this.pkcs11.Dispose();
                throw;
            }
        }
예제 #7
0
        /// <summary>
        /// Constructs internal context for Pkcs11X509Store class
        /// </summary>
        /// <param name="libraryPath">Name of or path to PKCS#11 library</param>
        /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
        /// <returns>Internal context for Pkcs11X509Store class</returns>
        private Pkcs11X509StoreContext GetStoreContext(string libraryPath, IPinProvider pinProvider)
        {
            Pkcs11 pkcs11 = null;

            try
            {
                pkcs11 = new Pkcs11(libraryPath, AppType.MultiThreaded);
                var storeInfo = new Pkcs11X509StoreInfo(libraryPath, pkcs11.GetInfo());
                return(new Pkcs11X509StoreContext(pkcs11, storeInfo, pinProvider));
            }
            catch
            {
                if (pkcs11 != null)
                {
                    pkcs11.Dispose();
                    pkcs11 = null;
                }

                throw;
            }
        }
        /// <summary>
        /// Requests PIN code for PKCS#11 token
        /// </summary>
        /// <param name="tokenContext">Internal context for Pkcs11Token class</param>
        /// <returns>PIN code</returns>
        public static byte[] GetTokenPin(Pkcs11TokenContext tokenContext)
        {
            IPinProvider pinProvider = tokenContext.SlotContext.StoreContext.PinProvider;

            Pkcs11X509StoreInfo storeInfo = tokenContext.SlotContext.StoreContext.StoreInfo;
            Pkcs11SlotInfo      slotInfo  = tokenContext.SlotContext.SlotInfo;
            Pkcs11TokenInfo     tokenInfo = tokenContext.TokenInfo;

            GetPinResult getPinResult = pinProvider.GetTokenPin(storeInfo, slotInfo, tokenInfo);

            if (getPinResult == null)
            {
                throw new Exception("Invalid response from IPinProvider");
            }

            if (getPinResult.Cancel)
            {
                throw new LoginCancelledException("Login with token pin was cancelled");
            }

            return(getPinResult.Pin);
        }
예제 #9
0
        /// <summary>
        /// Constructs internal context for Pkcs11X509Store class
        /// </summary>
        /// <param name="libraryPath">Name of or path to PKCS#11 library</param>
        /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
        /// <returns>Internal context for Pkcs11X509Store class</returns>
        private Pkcs11X509StoreContext GetStoreContext(string libraryPath, IPinProvider pinProvider)
        {
            Pkcs11InteropFactories factories = new Pkcs11InteropFactories();

            IPkcs11Library pkcs11Library = null;

            try
            {
                pkcs11Library = factories.Pkcs11LibraryFactory.LoadPkcs11Library(factories, libraryPath, AppType.MultiThreaded);
                var storeInfo = new Pkcs11X509StoreInfo(libraryPath, pkcs11Library.GetInfo());
                return(new Pkcs11X509StoreContext(pkcs11Library, storeInfo, pinProvider));
            }
            catch
            {
                if (pkcs11Library != null)
                {
                    pkcs11Library.Dispose();
                    pkcs11Library = null;
                }

                throw;
            }
        }
예제 #10
0
 /// <summary>
 /// Creates new instance of Pkcs11X509StoreContext class
 /// </summary>
 /// <param name="pkcs11">High level PKCS#11 wrapper</param>
 /// <param name="storeInfo">Detailed information about PKCS#11 based X.509 store</param>
 /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
 internal Pkcs11X509StoreContext(Pkcs11 pkcs11, Pkcs11X509StoreInfo storeInfo, IPinProvider pinProvider)
 {
     _pkcs11      = pkcs11 ?? throw new ArgumentNullException(nameof(pkcs11));
     _storeInfo   = storeInfo ?? throw new ArgumentNullException(nameof(storeInfo));
     _pinProvider = pinProvider ?? throw new ArgumentNullException(nameof(pinProvider));
 }
 /// <summary>
 /// Creates new instance of Pkcs11X509StoreContext class
 /// </summary>
 /// <param name="pkcs11Library">High level PKCS#11 wrapper</param>
 /// <param name="storeInfo">Detailed information about PKCS#11 based X.509 store</param>
 /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
 internal Pkcs11X509StoreContext(IPkcs11Library pkcs11Library, Pkcs11X509StoreInfo storeInfo, IPinProvider pinProvider)
 {
     _pkcs11Library = pkcs11Library ?? throw new ArgumentNullException(nameof(pkcs11Library));
     _storeInfo     = storeInfo ?? throw new ArgumentNullException(nameof(storeInfo));
     _pinProvider   = pinProvider ?? throw new ArgumentNullException(nameof(pinProvider));
 }