diff --git a/src/fr/anssi/smartpgp/SmartPGPApplet.java b/src/fr/anssi/smartpgp/SmartPGPApplet.java index 66d7916..5d8af9c 100644 --- a/src/fr/anssi/smartpgp/SmartPGPApplet.java +++ b/src/fr/anssi/smartpgp/SmartPGPApplet.java @@ -433,6 +433,12 @@ public final class SmartPGPApplet extends Applet { case Constants.TAG_CARDHOLDER_CERTIFICATE: k = currentTagOccurenceToKey(); + + if(k == null) { + ISOException.throwIt(Constants.SW_REFERENCE_DATA_NOT_FOUND); + return 0; + } + off = Util.arrayCopyNonAtomic(k.certificate, (short)0, buf, off, k.certificate_length); @@ -461,6 +467,11 @@ public final class SmartPGPApplet extends Applet { final PGPKey k = currentTagOccurenceToKey(); + if(k == null) { + ISOException.throwIt(Constants.SW_REFERENCE_DATA_NOT_FOUND); + return 0; + } + transients.setCurrentTagOccurrence((byte)(transients.currentTagOccurrence() + 1)); return Util.arrayCopyNonAtomic(k.certificate, (short)0, @@ -774,6 +785,8 @@ public final class SmartPGPApplet extends Applet { final byte[] buf = transients.buffer; + PGPKey k = null; + if(isOdd) { assertAdmin(); @@ -800,8 +813,6 @@ public final class SmartPGPApplet extends Applet { return; } - PGPKey k = null; - switch(Util.getShort(buf, off)) { case Constants.CRT_SIGNATURE_KEY: k = data.pgp_keys[Persistent.PGP_KEYS_OFFSET_SIG]; @@ -1005,7 +1016,12 @@ public final class SmartPGPApplet extends Applet { case Constants.TAG_CARDHOLDER_CERTIFICATE: assertAdmin(); - currentTagOccurenceToKey().setCertificate(buf, (short)0, lc); + k = currentTagOccurenceToKey(); + if(k == null) { + ISOException.throwIt(Constants.SW_REFERENCE_DATA_NOT_FOUND); + return; + } + k.setCertificate(buf, (short)0, lc); break; case Constants.TAG_ALGORITHM_ATTRIBUTES_SIG: