Skip to content

Instantly share code, notes, and snippets.

@eliezio
Created January 25, 2013 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliezio/4634277 to your computer and use it in GitHub Desktop.
Save eliezio/4634277 to your computer and use it in GitHub Desktop.
/**
* Artifício para evitar que o CLA do comando seja adulterado pela ChannelImpl.setChannel().
* Thanks Bruno Jesus!
* <p/>
* Vide: http://www.java2s.com/Open-Source/Java/6.0-JDK-Modules-sun/security/sun/security/smartcardio/ChannelImpl.java.htm
*
* @param channel Canal
* @param cla CLA do comando
*/
private static void preventCLACorruption(CardChannel channel, int cla) {
final int newChannelNumber = (((cla >= 0) && (cla <= 3)) ? cla : 0);
if (channel.getChannelNumber() != newChannelNumber) {
try {
Field f = channel.getClass().getDeclaredField("channel");
f.setAccessible(true);
f.set(channel, newChannelNumber);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment