Skip to content

Commit

Permalink
changePIN (CHANGE_CODE_MEMORY_CARD functionality) added for SLEXX42 c…
Browse files Browse the repository at this point in the history
…ards
  • Loading branch information
lewixlabs committed Feb 2, 2021
1 parent 981fb6d commit 140b0a6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "charta",
"main": "./dist/main.js",
"version": "1.0.12",
"version": "1.0.15",
"description": "Dev tool for smartcard/pos developers",
"scripts": {
"build": "tsc --build -clean && tsc",
Expand Down Expand Up @@ -68,6 +68,6 @@
"react": "^16.13.0",
"react-desktop": "^0.3.9",
"react-dom": "^16.13.0",
"tscard": "^1.0.2"
"tscard": "^1.0.3"
}
}
14 changes: 13 additions & 1 deletion src/react-engine/ApduForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CSS from "csstype";
import React from "react";
import { PINStatus } from "tscard/cards/memorycard";
import { MemoryCardTypes, PINStatus } from "tscard/cards/memorycard";
import Utilities from "tscard/utilities";
import { CardManager } from "../smartcard/cardmanager";
import { CustomButton } from "./chartaui/CustomButton";
Expand Down Expand Up @@ -73,6 +73,7 @@ export class ApduForm extends React.Component<IApduFormProps, IApduFormState> {
this.readBytes = this.readBytes.bind(this);
this.writeBytes = this.writeBytes.bind(this);
this.verifyPSC = this.verifyPSC.bind(this);
this.updatePSC = this.updatePSC.bind(this);
this.onChangeMemoryCardField = this.onChangeMemoryCardField.bind(this);
this.onBlurMemoryCardField = this.onBlurMemoryCardField.bind(this);
}
Expand Down Expand Up @@ -117,6 +118,7 @@ export class ApduForm extends React.Component<IApduFormProps, IApduFormState> {
<div hidden={!CardManager.isSupportedMemoryCard()}>
<CustomTextField label="PSC Data" text={this.state.memoryPscData} charsLength={6} maxLength={6} onChangeEvent={this.onChangeMemoryCardField} fieldName="psc" onBlurEvent={this.onBlurMemoryCardField} />
<CustomButton text="Verify PSC" clickEvent={this.verifyPSC} color="#FBC02D" />
<CustomButton text="Update PSC" clickEvent={this.updatePSC} color="#8633FF" hiddenStatus={!CardManager.isSupportedMemoryCard() || CardManager.getMemoryCardType() != MemoryCardTypes.SLE5542} />
</div>

<div style={marginTopDivStyle}>
Expand Down Expand Up @@ -357,4 +359,14 @@ export class ApduForm extends React.Component<IApduFormProps, IApduFormState> {
this.setState(apduToUpdate);
}

private async updatePSC() {

const writeOK: boolean = await CardManager.updatePSC(Utilities.hexStringToBytes(this.state.memoryPscData));

const apduToUpdate: IApduFormState = { ...this.state };
apduToUpdate.apduResult.sw = writeOK ? "9000" : "Error";
apduToUpdate.apduResult.dataOut = writeOK ? "UPDATE PSC OK" : "UPDATE PSC ERROR";

this.setState(apduToUpdate);
}
}
4 changes: 4 additions & 0 deletions src/react-engine/chartaui/CustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ interface IButtonProps {
text: string;
clickEvent: () => void;
color: string;
hiddenStatus?: boolean;
}

export const CustomButton: React.FC<IButtonProps> = (props: IButtonProps) => {
if (props.hiddenStatus)
return (<div></div>);

return (
<div style={textFieldStyle}>
<Button color={props.color} onClick={props.clickEvent}>
Expand Down
24 changes: 24 additions & 0 deletions src/smartcard/cardmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ export class CardManager {
return this.actualCard instanceof Sle;
}

public static getMemoryCardType(): MemoryCardTypes {
if (!this.actualCard)
return null;

if (!this.actualCard.isMemoryCard)
return null;

const currentSle: Sle = this.actualCard as Sle;
return currentSle.type;
}


public static async readMemoryCard(startPosition: number, bytesToRead: number): Promise<[boolean, number[]]> {

if (!this.actualCard || !this.actualCard.isMemoryCard)
Expand Down Expand Up @@ -151,6 +163,18 @@ export class CardManager {
return await currentSle.verifyPIN(pinBuffer);
}

public static async updatePSC(pinBufferToUpdate: number[]): Promise<boolean> {

if (!this.actualCard || !this.actualCard.isMemoryCard)
throw new Error("No MemoryCard Detected");

if (!(this.actualCard instanceof Sle))
throw new Error("MemoryCard Not Supported");

const sleCard = this.actualCard as Sle;
return sleCard.changePIN(pinBufferToUpdate);
}

//#endregion

private static cardManagerActive: boolean = false;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2142,10 +2142,10 @@ truncate-utf8-bytes@^1.0.0:
dependencies:
utf8-byte-length "^1.0.1"

tscard@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/tscard/-/tscard-1.0.2.tgz#39ccf8602985f4e01dc22657c8cfd21999fdea0d"
integrity sha512-jiGWTxf7f2GP0WLmckLLdh3A+1hKgy5+VPFNw5oQMWIIWToAIq4FVfC5jfkZhPo+AVuHeBG2K7tv6a0kTLx9LQ==
tscard@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tscard/-/tscard-1.0.3.tgz#276fba4a09988b7de8142cbb86c05f0aeabc8717"
integrity sha512-9Pg6R6SgDzCzEY3f9qmG0gzezGj63WVPPSfABLlnAxYfPisx+ZfRwrEWpDH4eKXWjKjAZByedlrOK4eOwnRsGA==
dependencies:
"@types/buffers" "^0.1.31"
events "^3.0.0"
Expand Down

0 comments on commit 140b0a6

Please sign in to comment.