Skip to content

Commit 707eb36

Browse files
committed
Tarpit added
Tarpit added and rebranded source tree to com.vivokey.otp - 600ms delay on failed authentication
1 parent 71b8eba commit 707eb36

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
File renamed without changes.

applet/src/pkgYkneoOath/YkneoOath.java applet/src/com/vivokey/otp/YkneoOath.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgYkneoOath;
1+
package com.vivokey.otp;
22

33
/*
44
* Copyright (c) 2013-2015 Yubico AB
@@ -23,6 +23,7 @@
2323
import javacard.framework.ISOException;
2424
import javacard.framework.JCSystem;
2525
import javacard.framework.Util;
26+
import javacard.security.MessageDigest;
2627
import javacard.security.RandomData;
2728

2829
public class YkneoOath extends Applet {
@@ -60,6 +61,10 @@ public class YkneoOath extends Applet {
6061
private OathObj scratchAuth;
6162
private byte[] propBuf;
6263

64+
private byte[] tar1;
65+
private byte[] tar2;
66+
private MessageDigest sha224;
67+
6368
private static final byte PROP_AUTH_OFFS = 0;
6469
private static final byte PROP_SENT_DATA_OFFS = 1;
6570
private static final byte PROP_REMAINING_DATA_LEN = 3;
@@ -79,6 +84,10 @@ public YkneoOath() {
7984
sendBuffer = JCSystem.makeTransientByteArray(BUFSIZE, JCSystem.CLEAR_ON_DESELECT);
8085
propBuf = JCSystem.makeTransientByteArray(PROP_BUF_SIZE, JCSystem.CLEAR_ON_DESELECT);
8186
rng = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM);
87+
88+
sha224 = MessageDigest.getInstance(MessageDigest.ALG_SHA_224, false);
89+
tar1 = JCSystem.makeTransientByteArray((short) 28, JCSystem.CLEAR_ON_RESET);
90+
tar2 = JCSystem.makeTransientByteArray((short)28, JCSystem.CLEAR_ON_RESET);
8291

8392
identity = new byte[CHALLENGE_LENGTH];
8493
rng.generateData(identity, _0, CHALLENGE_LENGTH);
@@ -231,6 +240,10 @@ private short handleValidate(byte[] input, byte[] output) {
231240
if(Util.arrayCompare(input, offs, tempBuf, _0, len) == 0) {
232241
propBuf[PROP_AUTH_OFFS] = 1;
233242
} else {
243+
rng.generateData(tar1, (short)0, (short)28);
244+
sha224.doFinal(tar1, (short)0, (short)28, tar2, (short)0);
245+
sha224.doFinal(tar2, (short)0, (short)28, tar1, (short)0);
246+
sha224.doFinal(tar1, (short)0, (short)28, tar2, (short)0);
234247
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
235248
}
236249
offs += len;
@@ -440,6 +453,7 @@ private void handlePut(byte[] buf) {
440453
byte digits = buf[offs++];
441454

442455
// protect against tearing (we want to do this as late as possible)
456+
443457
object.setActive(false);
444458
object.setDigits(digits);
445459

@@ -464,6 +478,7 @@ private void handlePut(byte[] buf) {
464478
object.clearImf();
465479
}
466480
object.setActive(true);
481+
467482
}
468483

469484
private short getLength(byte[] buf, short offs) {

build.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<target name="build" depends="test,ant-javacard">
1111
<javacard>
1212
<cap jckit="oracle_javacard_sdks/jc222_kit" aid="A0:00:00:06:17:00:61:FC:54:D5:01" output="vivokey-otp.cap" sources="applet/src">
13-
<applet class="pkgYkneoOath.YkneoOath"/>
13+
<applet class="com.vivokey.otp.YkneoOath"/>
1414
</cap>
1515
</javacard>
1616
</target>

0 commit comments

Comments
 (0)