public CardBuffer Process(CardBuffer inBuffer) { CardBuffer outBuffer; if (UseApdus) { try { /* Transform incoming frame into an APDU */ CAPDU capdu = new CAPDU(inBuffer.GetBytes()); /* Process the APDU */ outBuffer = OnApdu(new CAPDU(inBuffer.GetBytes())); } catch (Exception) { /* Incoming frame is not a valid APDU, return 6700 */ outBuffer = new RAPDU(0x67, 0x00); } } else { /* Process the frame */ outBuffer = OnFrame(inBuffer); } IsFirstCommand = false; return(outBuffer); }
public bool ChangeKey(CardBuffer key) { _last_error = SCARD.MifUlC_ChangeKey(hCard, key.GetBytes()); if (_last_error != 0) { return(false); } return(true); }
public bool Authenticate(CardBuffer key) { _last_error = SCARD.MifUlC_Authenticate(hCard, key.GetBytes()); if (_last_error != 0) { return(false); } return(true); }
public bool Write(byte address, CardBuffer buffer) { _last_error = SCARD.MifUlC_Write4(hCard, address, buffer.GetBytes()); if (_last_error != 0) { return(false); } return(true); }
public bool Control() { byte[] r = Control(_cctrl.GetBytes()); if (r == null) { return(false); } _rctrl = null; if (r.Length > 0) { _rctrl = new CardBuffer(r); } return(true); }
private void Parse() { if (abAtr == null) { throw new NullReferenceException(); } byte[] atr = abAtr.GetBytes(); int offset = 0; byte Y1; byte K; slDescription = new List <string>(); string s = String.Format("+ TS = {0:X2} --> ", atr[0]); switch (atr[0]) { case 0x3B: s += "Direct Convention"; break; case 0x3F: s += "Inverse Convention"; break; default: s += "UNDEFINED"; break; } slDescription.Add(s); /* T0 */ /* -- */ Y1 = (byte)(atr[1] / 0x10); K = (byte)(atr[1] % 0x10); slDescription.Add(String.Format("+ T0 = {0:X02}, Y1={1}, K={2} (historical bytes)", atr[1], BINQ[Y1], K)); /* TA, TB, TC, TD */ /* -------------- */ offset = 2; if ((Y1 & 0x01) != 0) { ATR_analysis_TA(1, 0, ref offset, atr); } if ((Y1 & 0x02) != 0) { ATR_analysis_TB(1, 0, ref offset, atr); } if ((Y1 & 0x04) != 0) { ATR_analysis_TC(1, 0, ref offset, atr); } if ((Y1 & 0x08) != 0) { ATR_analysis_TD(1, ref offset, atr); } /* Historical bytes */ /* ---------------- */ if (K != 0) { int i; slDescription.Add(String.Format("+ {0} historical byte{1}:", K, K > 1 ? "s" : "")); s = String.Format(" Hex:"); for (i = 0; i < K; i++) { if (offset >= atr.Length) { slDescription.Add(String.Format("ERROR! ATR is truncated; {0} byte(s) missing", K - i)); break; } s += String.Format(" {0:X02}", atr[offset + i]); } slDescription.Add(s); s = String.Format(" Asc: "); for (i = 0; i < K; i++) { if (offset >= atr.Length) { break; } char c = (char)atr[offset + i]; if ((c <= ' ') || (c >= 0x80)) { s += "."; } else { s += c; } } slDescription.Add(s); offset += K; } /* Check TCK */ /* --------- */ if (K != 0) { int i; byte TCK = 0; for (i = 1; i < (atr.Length - 1); i++) { TCK ^= atr[i]; } s = String.Format("+ TCK = {0:X02} ", TCK); if (TCK == atr[atr.Length - 1]) { s += String.Format("(correct checksum)"); slDescription.Add(s); } else { s += String.Format("!= {0:X02}", atr[atr.Length - 1]); slDescription.Add(s); slDescription.Add(String.Format("ERROR! Checksum is invalid")); } } }
public RAPDU(CardBuffer buffer) { SetBytes(buffer.GetBytes()); }