Podpis elektroniczny KIR/SZAFIR

0

Witam,
próbuję podpisać dokument z wykorzystaniem karty kryptograficznej KIR. Niestety podczas pobierania listy certyfikatów napotykam na błąd.

String libPath = "C:\\CryptoTech\\CryptoCard\\CCPkiP11.dll";
String pin = "125521";
String pkcs11Config = "name = CryptoTech\nlibrary = " + libPath;
ByteArrayInputStream confStream = new ByteArrayInputStream(pkcs11Config.getBytes());
Provider prov = new sun.security.pkcs11.SunPKCS11(confStream);
Security.addProvider(prov);
KeyStore keyStore = KeyStore.getInstance("PKCS11", prov);
keyStore.load(null, pin.toCharArray());
Enumeration<String> alias = keyStore.aliases();

Logi

xades4j.verification.UnexpectedJCAException: The keystore couldn't be initialized
                at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:179)
                at xades4j.providers.impl.KeyStoreKeyingDataProvider.getSigningCertificateChain(KeyStoreKeyingDataProvider.java:189)
                at xades4j.production.SignerBES.sign(SignerBES.java:151)
                at xades4j.production.SignerBES.sign(SignerBES.java:122)
                at my.testapp.signer.SignerHelper.signXadesBES(SignerHelper.java:67)
                at my.testapp.signer.applet.SignerApplet$2.run(SignerApplet.java:212)
                at java.lang.Thread.run(Unknown Source)
Caused by: java.security.KeyStoreException: KeyStore instantiation failed
                at java.security.KeyStore$Builder$2.getKeyStore(Unknown Source)
                at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:175)
                ... 6 more
Caused by: java.io.IOException: load failed
                at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:843)
                at java.security.KeyStore.load(Unknown Source)
                at java.security.KeyStore$Builder$2$1.run(Unknown Source)
                at java.security.KeyStore$Builder$2$1.run(Unknown Source)
                at java.security.AccessController.doPrivileged(Native Method)
                ... 8 more
Caused by: javax.security.auth.login.LoginException
                at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1238)
                at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:849)
                at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:834)
                ... 12 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_LOCKED
                at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
                at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)
                ... 14 more

PIN jest ok, po podaniu tego PINu np. podczas podpisywania Word'a wszystko kończy się sukcesem.

Podając zły pin otrzymałam komunikat

Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_INCORRECT
                at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
                at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)
                ... 14 more
0

Google mówi że to oznacza że twój token (karta) jest zablokowany.

0

Tylko dlaczego udało mi się podpisać Word'a... Niepokojący jest również fakt, że identyczna sytuacja występuje na 3ch różnych kartach KIR'u.
@Shalom, wiesz może jak odblokować token? Spróbowałabym, może jakoś udało by mi się wtedy pobrać listę certyfikatów.

0

Pojęcia nie mam, ale sugerowałbym po prostu przedebugować ten kod z biblioteki żeby zobaczyć co sie dzieje pod spodem. Możliwe że błąd jest zupełnie inny/głupi a komunikat i wyjątek są nieprecyzyjne.

0

Z jakiej biblioteki korzystasz? Bezpośrednio z szafirowej czy z jakiejś niezależnej implementacji?

0

Bezpośrednio z Szafirowej po instalacji CryptoCard Suite.

1

Pakiet jest walnięty, bywa zdarza się :) Dzwoń na infolinię KIR-u i niech się pomęczą :)

Generalnie problem polega na tym, że SZAFIR czasami uwidacznia pewne błędy w Crypto-API. Zazwyczaj są na to robione obejścia. Tu jak widać czegoś nie wyłapali.

0

A zainicjowaliście karty pinami? Można to zrobić np. przy oprogramowaniu CryptoCard Suite.

0

@DevKate: udało ci sie rozwiązać ten problem?

Piszę aplikację podpisującą różnymi podpisami kwalifikowanymi. Wykorzystuję bibliotekę xades4j https://github.com/luisgoncalves/xades4j
Nie ma problemu z podpisywaniem kartami certum i cencert, aż do dzisiaj kiedy okazało się ze trzeba coś podpisać KIRem...
Po podaniu prawidłowego pinu rzuca mi czymś takim:

 xades4j.verification.UnexpectedJCAException: The keystore couldn't be initialized
        at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:179)
        at xades4j.providers.impl.KeyStoreKeyingDataProvider.getSigningCertificateChain(KeyStoreKeyingDataProvider.java:189)
        at xades4j.production.SignerBES.sign(SignerBES.java:151)
        at xades4j.production.SignerBES.sign(SignerBES.java:122)
        at com.riv.jpk.security.XadesHelper.sign(XadesHelper.java:127)
        at com.riv.jpk.RaportGenerators.BaseGen.signXml(BaseGen.java:192)
        at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM.signXml(JpkGeneratorVM.java:417)
        at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM.lambda$validateMetaXML$44(JpkGeneratorVM.java:403)
        at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM$$Lambda$361/32216595.handle(Unknown Source)
        at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.concurrent.EventHelper.fireEvent(EventHelper.java:219)
        at javafx.concurrent.Task.fireEvent(Task.java:1356)
        at javafx.concurrent.Task.setState(Task.java:723)
        at javafx.concurrent.Task$TaskCallable.lambda$call$496(Task.java:1434)
        at javafx.concurrent.Task$TaskCallable$$Lambda$347/3131345.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
        at com.sun.javafx.application.PlatformImpl$$Lambda$51/6271097.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
        at com.sun.javafx.application.PlatformImpl$$Lambda$49/19468568.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
        at com.sun.glass.ui.win.WinApplication$$Lambda$39/443957.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745) Caused by: java.security.KeyStoreException: KeyStore instantiation failed
        at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1967)
        at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:175)
        ... 32 more 
Caused by: java.io.IOException: load failed
        at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:843)
        at java.security.KeyStore.load(KeyStore.java:1479)
        at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1937)
        at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1918)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1964)
        ... 33 more
Caused by: javax.security.auth.login.LoginException
        at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1238)
        at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:849)
        at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:834)
        ... 38 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_LEN_RANGE
        at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
        at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)
        ... 40 more

Gdzie jak wygoglałam CKR_PIN_LEN_RANGE:
The specified PIN is too long or too short. This return code only applies to functions which attempt to set a PIN.

Co już się całkiem kupy nie trzyma...

1 użytkowników online, w tym zalogowanych: 0, gości: 1