public void _01_BasicInitTokenAndPinTest() { using (IPkcs11Library pkcs11Library = Settings.Factories.Pkcs11LibraryFactory.LoadPkcs11Library(Settings.Factories, Settings.Pkcs11LibraryPath, Settings.AppType)) { // Find first slot with token present ISlot slot = Helpers.GetUsableSlot(pkcs11Library); ITokenInfo tokenInfo = slot.GetTokenInfo(); // Check if token needs to be initialized if (!tokenInfo.TokenFlags.TokenInitialized) { // Initialize token and SO (security officer) pin slot.InitToken(Settings.SecurityOfficerPin, Settings.ApplicationName); // Open RW session using (ISession session = slot.OpenSession(SessionType.ReadWrite)) { // Login as SO (security officer) session.Login(CKU.CKU_SO, Settings.SecurityOfficerPin); // Initialize user pin session.InitPin(Settings.NormalUserPin); session.Logout(); } } } }
private static void InitializeToken(ISlot slot, string label, string soPin, string userPin) { if (slot.GetTokenInfo().TokenFlags.TokenInitialized) { throw new Exception("Token already initialized"); } slot.InitToken(soPin, label); using (ISession session = slot.OpenSession(SessionType.ReadWrite)) { session.Login(CKU.CKU_SO, soPin); session.InitPin(userPin); } }
public void InitToken(string soPin, string label) { if (this._disposed) { throw new ObjectDisposedException(this.GetType().FullName); } if (_authenticatedSession != null) { throw new Exception("Authenticated session exists"); } _slot.InitToken(soPin, label); }
public void _HL_09_01_BasicInitTokenAndPinTest() { using (var pkcs11 = Settings.Factories.RutokenPkcs11LibraryFactory.LoadRutokenPkcs11Library(Settings.Factories, Settings.Pkcs11LibraryPath, Settings.AppType)) { // Установление соединения с Рутокен в первом доступном слоте ISlot slot = Helpers.GetUsableSlot(pkcs11); // Инициализация токена slot.InitToken(Settings.SecurityOfficerPin, Settings.TokenStdLabel); // Открытие RW сессии using (ISession session = slot.OpenSession(SessionType.ReadWrite)) { // Аутентификация администратора session.Login(CKU.CKU_SO, Settings.SecurityOfficerPin); // Инициализация ПИН-кода пользователя session.InitPin(Settings.NormalUserPin); // Завершение сессии session.Logout(); } } }