Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.

Initial commit - #2

Merged
divegeek merged 4 commits into
divegeek:masterfrom
cpathak:master
Mar 25, 2020
Merged

Initial commit#2
divegeek merged 4 commits into
divegeek:masterfrom
cpathak:master

Conversation

@cpathak

Copy link
Copy Markdown
Contributor
  • Framework code.
  • dummy provision cmd
  • getHWInfo cmd
    This is tested on jcardsim and simulator.

This commit is not tested.
- fixed security exception due to apdu.
- changed build.xml and removed build_common.xml
- fixed some bugs related to KMByteBlob and KMEnum.
- Added getHardwareInfo

@divegeekdivegeek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the binary files? And can we redistribute them all?


public KMType get(short index) {
if (index >= length) {
throw new KMException(ISO7816.SW_WRONG_LENGTH);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bad idea to new exceptions, isn't it? As I recall I preallocated them, the same way ISOException works. Does JavaCard now have reliable garbage collection?

@Override
public void init() {
key = 0;
val = 1; // always 1.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother allocating space? If getVal() just returns 1, you can omit this, I think.

return repository.newByteBlob();
}

// copy the blob

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an init-by-reference ctor might be useful as well. For example, you can point the array at the APDU buffer, with appropriate start and length.


import javacard.framework.ISO7816;

public class KMByteTag extends KMTag {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KMBytesTag or KMByteBlobTag. The name should indicate that this is a value containing more than one byte.

}

// validate the tag key
private static boolean validateKey(short key) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factor the bulk of this into a helper method, since you repeat it?

*
* @param keymasterState represents current applet state.
*/
public void setKeymasterState(byte keymasterState) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if these getters and setters are actually better than just making the fields public.

} else if (len == UINT32_LENGTH) {
inst = exp.instance(buffer, startOff, (short) 4);
incrementStartOff((short) 4);
} else if (len == UINT64_LENGTH) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might just want to throw in this case. Maybe even in the UINT32 case.

while (index < payloadLength) {
short tagInd = 0;
short tagType = peekTagType();
while (tagInd < allowedTags.length()) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this is a likely area for optimization. This will be executed enough that it may be a hot spot, and if allowedTags is sorted a binary search would not be much more code or complexity.

- Fixed transaction buffer overflow bug.
- Added new AddRngEntropy command
@divegeek
divegeek merged commit 5eeda37 into divegeek:masterMar 25, 2020
divegeek pushed a commit that referenced this pull request Jul 28, 2020
divegeek pushed a commit that referenced this pull request Feb 16, 2021
subrahmanyaman referenced this pull request in subrahmanyaman/JavaCardKeymaster Aug 26, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@cpathak@divegeek