Skip to content

Commit

Permalink
Rename applet and add LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Jul 21, 2021
1 parent f3d97b3 commit f808c6e
Show file tree
Hide file tree
Showing 10 changed files with 798 additions and 69 deletions.
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions LICENSE-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Dusan Klinec, Martin Paljak, Petr Svenda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14 changes: 7 additions & 7 deletions applet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final def JC310b43 = libsSdk + '/jc310b43_kit'
//
// JC310b43 supports building also for lower versions (cap.targetsdk).
// If another SDK is selected, please comment the cap.targetsdk setting.
final def JC_SELECTED = JC310b43
final def JC_SELECTED = JC303

javacard {

Expand All @@ -121,24 +121,24 @@ javacard {

//noinspection GroovyAssignabilityCheck
cap {
packageName 'applet'
packageName 'jced25519'
version '0.1'
aid '01:ff:ff:04:05:06:07:08:09'
output 'applet.cap'
aid '6a:63:65:64:32:35:35:31:39'
output 'jced25519.cap'

// JC310b43 supports compilation targeting for lower API versions.
// Here you can specify path to the SDK you want to use.
// Only JC304 and higher are supported for targeting.
// If JC310b43 is not used, targetsdk cannot be set.
targetsdk JC304
// targetsdk JC304

// Override java bytecode version if needed.
// javaversion '1.7'

//noinspection GroovyAssignabilityCheck
applet {
className 'applet.MainApplet'
aid '01:ff:ff:04:05:06:07:08:09:01:02'
className 'jced25519.JCEd25519'
aid '6a:63:65:64:32:35:35:31:39:61:70:70'
}

//noinspection GroovyAssignabilityCheck
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package applet;
/*
JCEd25519 is an applet for creating Ed25519 signatures using JC API.
Copyright (C) 2021 Antonín Dufka
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package jced25519;

public class Consts {
public static final byte CLA_ED25519 = (byte) 0x00;
Expand Down Expand Up @@ -48,4 +66,4 @@ public class Consts {
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08
};
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package applet;
/*
JCEd25519 is an applet for creating Ed25519 signatures using JC API.
Copyright (C) 2021 Antonín Dufka
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


package jced25519;

import javacard.framework.*;
import javacard.security.*;
import applet.jcmathlib.*;
import applet.swalgs.*;
import jced25519.jcmathlib.*;
import jced25519.swalgs.*;

public class MainApplet extends Applet implements MultiSelectable {
public class JCEd25519 extends Applet implements MultiSelectable {
private ECConfig ecc;
private ECCurve curve;
private Bignat privateKey, privateNonce, signature;
Expand All @@ -22,10 +41,10 @@ public class MainApplet extends Applet implements MultiSelectable {
private RandomData random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);

public static void install(byte[] bArray, short bOffset, byte bLength) {
new MainApplet(bArray, bOffset, bLength);
new JCEd25519(bArray, bOffset, bLength);
}

public MainApplet(byte[] buffer, short offset, byte length) {
public JCEd25519(byte[] buffer, short offset, byte length) {
OperationSupport os = OperationSupport.getInstance();
os.setCard(OperationSupport.SIMULATOR);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
package applet;
/*
JCEd25519 is an applet for creating Ed25519 signatures using JC API.
Copyright (C) 2021 Antonín Dufka
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package jced25519;

import javacard.security.KeyAgreement;

public class OperationSupport {
private static OperationSupport instance;
Expand Down Expand Up @@ -46,6 +66,25 @@ public void setCard(short card_identifier) {
}

public void setAutomatically() {
// TODO test operations using try-catch
ECDH_XY = testECDHXY();
ECDH_X_ONLY = testECDHX();
}

private boolean testECDHXY() {
try {
KeyAgreement.getInstance(jcmathlib.ECPoint_Helper.ALG_EC_SVDP_DH_PLAIN_XY, false);
return true;
} catch (Exception e) {
return false;
}
}

private boolean testECDHX() {
try {
KeyAgreement.getInstance(jcmathlib.ECPoint_Helper.ALG_EC_SVDP_DH_PLAIN, false);
return true;
} catch (Exception e) {
return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Merged file class by JavaPresso (https://github.com/petrs/JavaPresso)

package applet;
package jced25519;

import javacard.framework.ISOException;
import javacard.framework.JCSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package applet;
package jced25519;

import javacard.framework.*;
import javacard.security.*;
Expand Down
26 changes: 1 addition & 25 deletions applet/src/test/java/tests/AppletTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tests;

import applet.Consts;
import jced25519.Consts;
import cz.muni.fi.crocs.rcard.client.CardManager;
import cz.muni.fi.crocs.rcard.client.CardType;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
Expand All @@ -17,36 +17,12 @@
import java.security.PublicKey;
import java.security.Signature;

/**
* Example test class for the applet
* Note: If simulator cannot be started try adding "-noverify" JVM parameter
*
* @author xsvenda, Dusan Klinec (ph4r05)
*/
public class AppletTest extends BaseTest {

public AppletTest() {
// Change card type here if you want to use physical card
setCardType(CardType.JCARDSIMLOCAL);
setSimulateStateful(true);
}

@BeforeAll
public static void setUpClass() throws Exception {
}

@AfterAll
public static void tearDownClass() throws Exception {
}

@BeforeEach
public void setUpMethod() throws Exception {
}

@AfterEach
public void tearDownMethod() throws Exception {
}

public byte[] keygen(CardManager cm) throws Exception {
final CommandAPDU cmd = new CommandAPDU(Consts.CLA_ED25519, Consts.INS_KEYGEN,0, 0);
final ResponseAPDU responseAPDU = cm.transmit(cmd);
Expand Down
8 changes: 5 additions & 3 deletions applet/src/test/java/tests/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tests;

import applet.MainApplet;
import jced25519.JCEd25519;
import cz.muni.fi.crocs.rcard.client.CardManager;
import cz.muni.fi.crocs.rcard.client.CardType;
import cz.muni.fi.crocs.rcard.client.RunConfig;
Expand All @@ -18,7 +18,7 @@
* @author Petr Svenda, Dusan Klinec (ph4r05)
*/
public class BaseTest {
private static String APPLET_AID = "01ffff0405060708090102";
private static String APPLET_AID = "6a6365643235353139617070";
private static byte APPLET_AID_BYTE[] = Util.hexStringToByteArray(APPLET_AID);

protected CardType cardType = CardType.JCARDSIMLOCAL;
Expand Down Expand Up @@ -64,6 +64,8 @@ public CardManager connectRaw(byte[] installData) throws Exception {
// System.setProperty("com.licel.jcardsim.randomdata.secure", "1");

runCfg.setTestCardType(cardType);
runCfg.setTargetReaderIndex(2);

if (cardType == CardType.REMOTE){
runCfg.setRemoteAddress("http:https://127.0.0.1:9901");

Expand All @@ -74,7 +76,7 @@ public CardManager connectRaw(byte[] installData) throws Exception {

} else if (cardType != CardType.PHYSICAL && cardType != CardType.PHYSICAL_JAVAX) {
// Running in the simulator
runCfg.setAppletToSimulate(MainApplet.class)
runCfg.setAppletToSimulate(JCEd25519.class)
.setTestCardType(CardType.JCARDSIMLOCAL)
.setbReuploadApplet(true)
.setInstallData(installData);
Expand Down

0 comments on commit f808c6e

Please sign in to comment.