Skip to content

Commit

Permalink
Merge pull request #97 from crocs-muni/devel
Browse files Browse the repository at this point in the history
Synchronizing devel to master v1.6
  • Loading branch information
petrs committed Sep 7, 2015
2 parents 4e87eeb + f5478ca commit e4aff46
Show file tree
Hide file tree
Showing 199 changed files with 54,309 additions and 4,668 deletions.
13 changes: 0 additions & 13 deletions !notes.txt

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/AlgTest_Process/nbproject/private/
/AlgTest_JavaCard/build/
/AlgTest_JClient/build/
/AlgTest_JClient/test/*.jar
/AlgTest_Process/build/
/AlgTest_JClient/dist/README.TXT
/AlgTest_Process/dist/README.TXT
*.class
*.class
/AlgTest_JavaCard/nbproject/project.properties
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java

jdk:
- oraclejdk7

Expand Down
Binary file removed AlgTestProcess.jar
Binary file not shown.
23 changes: 0 additions & 23 deletions AlgTest_JClient/AlgTest_supported_parameters.txt

This file was deleted.

32 changes: 18 additions & 14 deletions AlgTest_JClient/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
<description>Builds, tests, and runs the project AlgTestJClient.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
Expand All @@ -29,24 +27,17 @@
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
Expand All @@ -55,19 +46,32 @@
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="AlgTestJClient-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

<target name="-post-jar">
<!-- Copy newly build jar into test directory for simulator of smart cards-->
<copy file="${basedir}/dist/AlgTestJClient.jar" tofile="${basedir}/test/AlgTestJClient.jar"/>
<copy file="${basedir}/dist/lib/jcardsim-2.2.2-all.jar" tofile="${basedir}/test/jcardsim-2.2.2-all.jar"/>

<!-- Copy files necessary for compilation of JC applet-->
<copy file="${basedir}/src/algtest/AlgKeyHarvest.java" tofile="../AlgTest_JavaCard/src/AlgTest/AlgKeyHarvest.java"/>
<copy file="${basedir}/src/algtest/AlgPerformanceTest.java" tofile="../AlgTest_JavaCard/src/AlgTest/AlgPerformanceTest.java"/>
<copy file="${basedir}/src/algtest/AlgSupportTest.java" tofile="../AlgTest_JavaCard/src/AlgTest/AlgSupportTest.java"/>
<copy file="${basedir}/src/algtest/JCAlgTestApplet.java" tofile="../AlgTest_JavaCard/src/AlgTest/JCAlgTestApplet.java"/>
<copy file="${basedir}/src/algtest/Consts.java" tofile="../AlgTest_JavaCard/src/AlgTest/Consts.java"/>
<copy file="${basedir}/src/algtest/JCConsts.java" tofile="../AlgTest_JavaCard/src/AlgTest/JCConsts.java"/>
<copy file="${basedir}/src/algtest/TestSettings.java" tofile="../AlgTest_JavaCard/src/AlgTest/TestSettings.java"/>
<copy file="${basedir}/src/algtest/JavaCardAES.java" tofile="../AlgTest_JavaCard/src/AlgTest/JavaCardAES.java"/>
<copy file="${basedir}/src/algtest/AlgStorageTest.java" tofile="../AlgTest_JavaCard/src/AlgTest/AlgStorageTest.java"/>
</target>
</project>
Binary file modified AlgTest_JClient/dist/AlgTestJClient.jar
Binary file not shown.
32 changes: 0 additions & 32 deletions AlgTest_JClient/dist/README.TXT

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions AlgTest_JClient/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=
javac.classpath=\
${libs.JCardSim2.2.2.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand All @@ -42,7 +43,8 @@ javac.target=1.7
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.testng.classpath}
${libs.testng.classpath}:\
${libs.JCardSim222.classpath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
Expand Down
2 changes: 0 additions & 2 deletions AlgTest_JClient/src/Manifest.txt

This file was deleted.

150 changes: 150 additions & 0 deletions AlgTest_JClient/src/algtest/AlgKeyHarvest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
Copyright (c) 2004-2014 Petr Svenda <[email protected]>
LICENSE TERMS
The free distribution and use of this software in both source and binary
form is allowed (with or without changes) provided that:
1. distributions of this source code include the above copyright
notice, this list of conditions and the following disclaimer;
2. distributions in binary form include the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other associated materials;
3. the copyright holder's name is not used to endorse products
built using this software without specific written permission.
ALTERNATIVELY, provided that this notice is retained in full, this product
may be distributed under the terms of the GNU General Public License (GPL),
in which case the provisions of the GPL apply INSTEAD OF those given above.
DISCLAIMER
This software is provided 'as is' with no explicit or implied warranties
in respect of its properties, including, but not limited to, correctness
and/or fitness for purpose.
Please, report any bugs to author <[email protected]>
*/

/**
*
* @author Petr Svenda, Lenka Kunikova, Lukas Srom
*/
package AlgTest;


import javacard.framework.*;
import javacard.security.*;


public class AlgKeyHarvest {
private KeyPair m_keyPair = null;
private AlgTest.TestSettings m_testSettings = null;
private RSAPublicKey m_rsaPublicKey = null;
private RSAPrivateCrtKey m_rsaPrivateCrtKey = null;
private RSAPrivateKey m_rsaPrivateKey = null;

private static final byte KeyPair_ALG_RSA = 1;
private static final byte KeyPair_ALG_RSA_CRT = 2;
private static final byte KeyBuilder_ALG_TYPE_RSA_PUBLIC = 11;
private static final byte KeyBuilder_ALG_TYPE_RSA_PRIVATE = 12;
private static final byte KeyBuilder_ALG_TYPE_RSA_CRT_PRIVATE = 13;


AlgKeyHarvest() {
m_testSettings = new AlgTest.TestSettings();
}

public byte process(APDU apdu) throws ISOException {
byte bProcessed = 0;
byte[] apduBuffer = apdu.getBuffer();

if (apduBuffer[ISO7816.OFFSET_CLA] == AlgTest.Consts.CLA_CARD_ALGTEST) {
bProcessed = 1;
switch ( apduBuffer[ISO7816.OFFSET_INS]) {
case AlgTest.Consts.INS_CARD_GETRSAKEY: GetRSAKey(apdu); break;
default : {
bProcessed = 0;
break;
}
}
}

return bProcessed;
}

/**
* Method for on-card generation of RSA keypair and export of result outside (in two apdu)
* @param apdu
*/
void GetRSAKey(APDU apdu) {
byte[] apdubuf = apdu.getBuffer();
m_testSettings.parse(apdu);

// Generate new object if not before yet
if (m_keyPair == null) {
m_keyPair = new KeyPair((byte)m_testSettings.keyClass, m_testSettings.keyLength);
// m_keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_512);
}

switch (m_testSettings.keyType) {
case KeyBuilder_ALG_TYPE_RSA_PUBLIC: {
m_keyPair.genKeyPair();
m_rsaPublicKey = (RSAPublicKey) m_keyPair.getPublic();

short offset = 0;
apdubuf[offset] = (byte)0x82; offset++;
short len = m_rsaPublicKey.getExponent(apdubuf, (short)(offset + 2));
Util.setShort(apdubuf, offset, len);
offset += 2; // length
offset += len; // value

apdubuf[offset] = (byte)0x82; offset++;
len = m_rsaPublicKey.getModulus(apdubuf, (short) (offset + 2));
Util.setShort(apdubuf, offset, len);
offset += 2; // length
offset += len; // value

apdu.setOutgoingAndSend((short) 0, offset);

break;
}
case KeyBuilder_ALG_TYPE_RSA_PRIVATE: {
short offset = 0;
if(m_testSettings.keyClass == KeyPair_ALG_RSA_CRT) {
m_rsaPrivateCrtKey = (RSAPrivateCrtKey) m_keyPair.getPrivate();

short len = m_rsaPrivateCrtKey.getP(apdubuf, (short)(offset + 3));
apdubuf[offset] = (byte)0x82; offset++;
Util.setShort(apdubuf, offset, len); offset += 2;
offset += len;

len = m_rsaPrivateCrtKey.getQ(apdubuf, (short)(offset + 3));
apdubuf[offset] = (byte)0x82; offset++;
Util.setShort(apdubuf, offset, len); offset += 2;
offset += len;
}
else if(m_testSettings.keyClass == KeyPair_ALG_RSA) {
m_rsaPrivateKey = (RSAPrivateKey) m_keyPair.getPrivate();

short len = m_rsaPrivateKey.getExponent(apdubuf, (short)(offset + 3));
apdubuf[offset] = (byte)0x82; offset++;
Util.setShort(apdubuf, offset, len); offset += 2;
offset += len;

len = m_rsaPrivateKey.getModulus(apdubuf, (short)(offset + 3));
apdubuf[offset] = (byte)0x82; offset++;
Util.setShort(apdubuf, offset, len); offset += 2;
offset += len;
}
else ISOException.throwIt( ISO7816.SW_COMMAND_NOT_ALLOWED) ;

apdu.setOutgoingAndSend((short) 0, offset);
break;
}
}
}
}
Loading

0 comments on commit e4aff46

Please sign in to comment.