Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ecsec Public
reqesidta-prototype
client-signer
Commits
9781639b
Commit
9781639b
authored
Oct 23, 2019
by
Michael Rauh
Browse files
Gracefully handle the case if there are no terminals
parent
a223625d
Changes
1
Show whitespace changes
Inline
Side-by-side
ifd/scio-backend/pcsc/src/main/java/org/openecard/scio/PCSCTerminals.java
View file @
9781639b
...
...
@@ -33,6 +33,7 @@ import javax.annotation.Nonnull;
import
javax.smartcardio.CardException
;
import
javax.smartcardio.CardTerminal
;
import
javax.smartcardio.CardTerminals
;
import
jnasmartcardio.Smartcardio
;
import
org.openecard.common.ifd.scio.NoSuchTerminal
;
import
org.openecard.common.ifd.scio.SCIOErrorCode
;
import
org.openecard.common.ifd.scio.SCIOException
;
...
...
@@ -62,15 +63,36 @@ public class PCSCTerminals implements SCIOTerminals {
PCSCTerminals
(
@Nonnull
PCSCFactory
terminalFactory
)
{
this
.
terminalFactory
=
terminalFactory
;
loadTerminals
();
terminals
=
new
CardTerminals
()
{
@Override
public
List
<
CardTerminal
>
list
(
CardTerminals
.
State
arg0
)
throws
CardException
{
if
(
loadTerminals
())
{
return
terminals
.
list
(
arg0
);
}
else
{
throw
new
Smartcardio
.
JnaPCSCException
(
SCIOErrorCode
.
getLong
(
SCIOErrorCode
.
SCARD_E_NO_SERVICE
),
"Error loading PCSC subsystem."
);
}
}
private
void
reloadFactory
()
{
loadTerminals
();
@Override
public
boolean
waitForChange
(
long
arg0
)
throws
CardException
{
if
(
loadTerminals
())
{
return
terminals
.
waitForChange
(
arg0
);
}
else
{
throw
new
Smartcardio
.
JnaPCSCException
(
SCIOErrorCode
.
getLong
(
SCIOErrorCode
.
SCARD_E_NO_SERVICE
),
"Error loading PCSC subsystem."
);
}
}
};
}
private
void
loadTerminals
()
{
private
boolean
loadTerminals
()
{
try
{
terminals
=
terminalFactory
.
getRawFactory
().
terminals
();
return
true
;
}
catch
(
Smartcardio
.
EstablishContextException
ex
)
{
LOG
.
debug
(
"Failed to load PCSC terminals."
,
ex
);
return
false
;
}
}
@Override
...
...
@@ -100,7 +122,7 @@ public class PCSCTerminals implements SCIOTerminals {
}
else
if
(
code
==
SCIOErrorCode
.
SCARD_E_NO_SERVICE
||
code
==
SCIOErrorCode
.
SCARD_E_SERVICE_STOPPED
)
{
if
(
firstTry
)
{
LOG
.
debug
(
"No service available exception, reloading PCSC and trying again."
);
re
load
Factory
();
load
Terminals
();
return
list
(
state
,
false
);
}
else
{
LOG
.
debug
(
"No service available exception, returning empty list."
);
...
...
@@ -221,11 +243,9 @@ public class PCSCTerminals implements SCIOTerminals {
return
Collections
.
emptyList
();
}
else
if
(
code
==
SCIOErrorCode
.
SCARD_E_NO_SERVICE
||
code
==
SCIOErrorCode
.
SCARD_E_SERVICE_STOPPED
||
code
==
SCIOErrorCode
.
SCARD_E_INVALID_HANDLE
)
{
LOG
.
debug
(
"No service available exception, reloading PCSC and returning empty list."
);
parent
.
re
load
Factory
();
parent
.
load
Terminals
();
own
.
loadTerminals
();
return
Collections
.
emptyList
();
}
else
if
(
code
==
SCIOErrorCode
.
SCARD_E_INVALID_HANDLE
)
{
// don't log in order to prevent flooding
}
else
{
LOG
.
error
(
msg
,
ex
);
}
...
...
@@ -404,7 +424,7 @@ public class PCSCTerminals implements SCIOTerminals {
case
SCARD_E_NO_SERVICE:
case
SCARD_E_SERVICE_STOPPED:
LOG
.
debug
(
"No service available exception, reloading PCSC."
);
parent
.
re
load
Factory
();
parent
.
load
Terminals
();
own
.
loadTerminals
();
case
SCARD_E_NO_READERS_AVAILABLE:
// send events that everything is removed if there are any terminals connected right now
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment