/// <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); }
/// <summary> /// Constructs internal context for Pkcs11Slot class /// </summary> /// <param name="slot">High level PKCS#11 slot</param> /// <param name="storeContext">Internal context for Pkcs11X509Store class</param> /// <returns>Internal context for Pkcs11Slot class</returns> private Pkcs11SlotContext GetSlotContext(ISlot slot, Pkcs11X509StoreContext storeContext) { var slotInfo = new Pkcs11SlotInfo(slot.GetSlotInfo()); return(new Pkcs11SlotContext(slot, slotInfo, storeContext)); }
/// <summary> /// Creates new instance of Pkcs11SlotContext class /// </summary> /// <param name="slot">High level PKCS#11 slot</param> /// <param name="slotInfo">Detailed information about PKCS#11 slot</param> /// <param name="storeContext">Internal context for Pkcs11X509Store class</param> internal Pkcs11SlotContext(ISlot slot, Pkcs11SlotInfo slotInfo, Pkcs11X509StoreContext storeContext) { _slot = slot ?? throw new ArgumentNullException(nameof(slot)); _slotInfo = slotInfo ?? throw new ArgumentNullException(nameof(slotInfo)); _storeContext = storeContext ?? throw new ArgumentNullException(nameof(storeContext)); }