public byte[] ProcessApdu(byte[] apdu)
 {
     try
     {
         Apdu Apdu = new Apdu(apdu);
         card.Log(Apdu);
         Apdu   initialApdu = Apdu;
         ushort key         = Util.ToUShort((byte)(Apdu.CLA & 0xf0), Apdu.INS);
         if (commandMap.ContainsKey(key))
         {
             BSO sigIn, encIn, sigOut, encOut;
             commandMap[key].getSMKeys(Apdu, out sigIn, out encIn, out sigOut, out encOut);
             var challenge = context.Challenge;
             if (sigIn != null || encIn != null || sigOut != null || encOut != null)
             {
                 if (!Apdu.IsSM)
                 {
                     return(Error.SMObjectMissing);
                 }
                 if (sigIn != null)
                 {
                     context.Challenge = null;
                 }
                 Apdu = Apdu.GetClearApdu(Apdu, encIn, sigIn, encOut, sigOut, challenge);
             }
             else
             {
                 if (Apdu.IsSM)
                 {
                     return(Error.ConditionsOfUseNotSatisfied);
                 }
             }
             var resp = commandMap[key].processCommand(Apdu);
             card.Log(resp);
             var random = context.Random;
             if (encOut != null || sigOut != null || sigIn != null || encIn != null)
             {
                 if (sigOut != null)
                 {
                     context.Challenge = null;
                 }
                 context.Random = null;
                 return(Apdu.GetSMResponse(initialApdu, resp, encOut, sigOut, random));
             }
             else
             {
                 return(resp);
             }
         }
         card.Log("Comando non riconosciuto");
         card.Log(Error.InsNotValid);
         return(Error.InsNotValid);
     }
     catch (ISO7816Exception cex)
     {
         card.Log((byte[])cex.CardError);
         return(cex.CardError);
     }
     catch (Exception ex)
     {
         card.Log(ex.ToString());
         return(Error.InternalError);
     }
 }
Exemplo n.º 2
0
 public byte[] ProcessApdu(byte[] apdu)
 {
     try
     {
         Apdu Apdu = new Apdu(apdu);
         card.Log(Apdu);
         Apdu initialApdu = Apdu;
         ushort key = Util.ToUShort((byte)(Apdu.CLA & 0xf0),Apdu.INS);
         if (commandMap.ContainsKey(key))
         {
             BSO sigIn, encIn, sigOut, encOut;
             commandMap[key].getSMKeys(Apdu, out sigIn, out encIn, out sigOut, out encOut);
             var challenge = context.Challenge;
             if (sigIn != null || encIn != null || sigOut != null || encOut != null)
             {
                 if (!Apdu.IsSM)
                     return Error.SMObjectMissing;
                 if (sigIn != null)
                     context.Challenge = null;
                 Apdu = Apdu.GetClearApdu(Apdu, encIn, sigIn, encOut, sigOut, challenge);
             }
             else
             {
                 if (Apdu.IsSM)
                     return Error.ConditionsOfUseNotSatisfied;
             }
             var resp=commandMap[key].processCommand(Apdu);
             card.Log(resp);
             var random = context.Random;
             if (encOut != null || sigOut != null || sigIn != null || encIn != null)
             {
                 if (sigOut != null)
                     context.Challenge = null;
                 context.Random = null;
                 return Apdu.GetSMResponse(initialApdu, resp, encOut, sigOut, random);
             }
             else
             {
                 return resp;
             }
         }
         card.Log("Comando non riconosciuto");
         card.Log(Error.InsNotValid);
         return Error.InsNotValid;
     }
     catch (ISO7816Exception cex)
     {
         card.Log((byte[])cex.CardError);
         return cex.CardError;
     }
     catch (Exception ex)
     {
         card.Log(ex.ToString());
         return Error.InternalError;
     }
 }