Example #1
0
        public byte[] GetScopeExclusivePseudonym(byte[] scopeURI, bool raw = false)
        {
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    C;
                ErrorCode err = this.device.GetScopeExlusivePseudonym(this.pin, scopeURI, out C);

                if (!err.IsOK)
                {
                    err.Command = "GetScopeExlusivePseudonym";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
                if (!raw)
                {
                    byte[] data    = new byte[C.Length + 1];
                    byte[] tmpData = C;
                    // ensure that we add 0x00 to data to force it to be signed.
                    data[0] = 0x00;
                    Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
                    Array.Reverse(data, 0, data.Length);
                    return(data);
                }
                else
                {
                    return(C);
                }
            }
        }
Example #2
0
        public byte[] ReadGroupComponent(int groupID, int compType, bool raw = false)
        {
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    c;
                ErrorCode err = this.device.ReadGroupComponent(this.pin, (byte)groupID, compType, out c);

                if (!err.IsOK)
                {
                    err.Command = "ReadGroupComponent";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }

                if (!raw)
                {
                    byte[] data    = new byte[c.Length + 1];
                    byte[] tmpData = c;
                    // ensure that we add 0x00 to data to force it to be signed.
                    data[0] = 0x00;
                    Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
                    //Data from the card is in big-endian. need to reverse it.
                    Array.Reverse(data, 0, data.Length);
                    return(data);
                }
                return(c);
            }
        }
Example #3
0
        public byte[] GetDevicePublicKey(bool raw = false)
        {
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    pubKey;
                ErrorCode err = this.device.GetDevicePublicKey(this.pin, out pubKey);

                if (!err.IsOK)
                {
                    err.Command = "GetDevicePublicKey";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }

                if (!raw)
                {
                    byte[] data    = new byte[pubKey.Length + 1];
                    byte[] tmpData = pubKey;
                    // ensure that we add 0x00 to data to force it to be signed.
                    data[0] = 0x00;
                    Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
                    //Data from the card is in big-endian. need to reverse it.
                    Array.Reverse(data, 0, data.Length);
                    return(data);
                }
                else
                {
                    return(pubKey);
                }
            }
        }
Example #4
0
 public void ResetDevice()
 {
     DebugUtils.DebugPrintBegin(null);
     using (SmartCardTransaction scT = new SmartCardTransaction(this.device, SCardReaderDisposition.Leave))
     {
         // do nothing.
     }
     DebugUtils.DebugPrintEnd(null);
 }
Example #5
0
        public byte[] BeginCommitment(int proverID)
        {
            byte pID = (byte)proverID;

            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[] pSession;
                this.device.BeginCommitments(pin, pID, out pSession);
                return(pSession);
            }
        }
Example #6
0
        public void SetCardInRootMode()
        {
            /* byte[] accMac = new byte[] { 0xE6, 0x63, 0x6D, 0x90, 0x49, 0x84, 0x02, 0xDF }; */
            byte[] accMac = new byte[] { 0xDD, 0xE8, 0x90, 0x96, 0x3E, 0xF8, 0x09, 0x0E };

            /*
             * Old root access macs:
             * { 0xE6, 0x63, 0x6D, 0x90, 0x49, 0x84, 0x02, 0xDF };
             */
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                device.SetRootMode(accMac);
            }
        }
Example #7
0
        public void GetIssuanceResponse(byte credID)
        {
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    c;
                ErrorCode err = this.device.GetIssuanceResponse(this.pin, credID, out c);

                if (!err.IsOK)
                {
                    err.Command = "GetIssuanceResponse";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
            }
        }
Example #8
0
        public void BeginResponse(int proverID, byte[] input)
        {
            byte pID = (byte)proverID;

            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                ErrorCode err = this.device.BeginResponse(pin, pID, input);
                if (!err.IsOK)
                {
                    err.Command = "BeginResponse";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
            }
        }
Example #9
0
 public byte[] GetDeviceResponse(bool raw = false)
 {
     using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
     {
         byte[]    R;
         ErrorCode err = this.device.GetDeviceResponse(this.pin, out R);
         if (!err.IsOK)
         {
             err.Command = "GetDeviceResponse";
             DebugUtils.DebugPrintErrorCodes(err);
             throw err;
         }
         if (!raw)
         {
             Array.Reverse(R, 0, R.Length);
         }
         return(R);
     }
 }
 private void initCardButton_Click(object sender, RoutedEventArgs e)
 {
   using (SmartCardTransaction scT = new SmartCardTransaction(this.smartCard.device))
   {
     string puk;
     try
     {
       String pin = "1234";
       KeyPair pq = new KeyPair(p, q);
       puk = this.smartCard.InitDevice(pq, pin);
     }
     catch (ErrorCode ex)
     {
       String msg = String.Format("Could not INITIALIZE DEVICE. error code: {0} {1}", ex.SW1, ex.SW2);
       System.Windows.MessageBox.Show(msg);
     }
   }
   this.CleanAndClose();
 }
Example #11
0
        public int GetCreadentialStatus(byte credID)
        {
            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte      issuerID;
                byte[]    vSize;
                byte[]    kSize;
                int       status;
                byte      prescount;
                ErrorCode err = this.device.ReadCredential(this.pin, credID, out issuerID, out vSize, out kSize, out status, out prescount);

                if (!err.IsOK)
                {
                    err.Command = "ReadCredential";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
                return(status);
            }
        }
Example #12
0
        public bool IsGeneratorSet(int groupID)
        {
            byte gID = (byte)groupID;

            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    sizeOfM;
                byte[]    sizeOfQ;
                byte[]    sizeOfF;
                int       t;
                ErrorCode err = this.device.ReadGroup(this.pin, gID, out sizeOfM, out sizeOfQ, out sizeOfF, out t);
                if (!err.IsOK)
                {
                    err.Command = "ReadGroup";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
                return(t > 0);
            }
        }
Example #13
0
        public byte[] GetCredentialPublicKey(int credID, bool raw = false)
        {
            byte cID = (byte)credID;

            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    pubKey;
                ErrorCode err = this.device.GetCredentialPublicKey(pin, cID, out pubKey);
                if (!err.IsOK)
                {
                    err.Command = "GetCredentialPublicKey";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
                if (!raw)
                {
                    Array.Reverse(pubKey, 0, pubKey.Length);
                }
                return(pubKey);
            }
        }
Example #14
0
        public byte[] GetPresCommitment(int proverID, int credID, bool raw = false)
        {
            byte pID = (byte)proverID;
            byte cID = (byte)credID;

            using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
            {
                byte[]    C;
                ErrorCode err = this.device.GetPresentationCommitment(pin, cID, out C);
                if (!err.IsOK)
                {
                    err.Command = "GetPresentationCommitment";
                    DebugUtils.DebugPrintErrorCodes(err);
                    throw err;
                }
                if (!raw)
                {
                    Array.Reverse(C, 0, C.Length);
                }
                return(C);
            }
        }
    private void virginMode_Click(object sender, RoutedEventArgs e)
    {
      using (SmartCardTransaction scT = new SmartCardTransaction(this.device.device))
      {
        try
        {
          device.SetVirginMode();
        }
        catch (ErrorCode ex)
        {
          String msg = String.Format("Could not set card in virgin mode: {0}{X2} {1}{X2} in commando {3}", ex.SW1, ex.SW2, ex.Command);
          System.Windows.MessageBox.Show(msg);
        }
        catch (Exception ex)
        {
          String msg = String.Format("Could not set card in virgin mode: {0}", ex.Message);
          System.Windows.MessageBox.Show(msg);
        }

        this.Close();
      }
    }
Example #16
0
 public void SetGroupOfUnknownOrder(BigInteger modulus)
 {
     byte[] mod = modulus.ToByteArray();
     // need to convert it to big-endian.
     Array.Reverse(mod, 0, mod.Length);
     using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
     {
         ErrorCode err = this.device.PutData(mod);
         if (!err.IsOK)
         {
             err.Command = "PutData";
             DebugUtils.DebugPrintErrorCodes(err);
             throw err;
         }
         err = this.device.SetGroupComponent(0x00, 0);
         if (!err.IsOK)
         {
             err.Command = "SetGroupComponent";
             DebugUtils.DebugPrintErrorCodes(err);
             throw err;
         }
     }
 }
Example #17
0
 public void ResetDevice()
 {
   
   DebugUtils.DebugPrintBegin(null);
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device, SCardReaderDisposition.Leave))
   {
     // do nothing.
   }
   DebugUtils.DebugPrintEnd(null);
 }
Example #18
0
    public int GetCreadentialStatus(byte credID)
    {
      using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
      {
        byte issuerID;
        byte[] vSize;
        byte[] kSize;
        int status;
        byte prescount;
        ErrorCode err = this.device.ReadCredential(this.pin, credID, out issuerID, out vSize, out kSize, out status, out prescount);

        if (!err.IsOK)
        {
          err.Command = "ReadCredential";
          DebugUtils.DebugPrintErrorCodes(err);
          throw err;
        }
        return status;
      }

    }
Example #19
0
    public byte[] ReadGroupComponent(int groupID, int compType, bool raw = false)
    {
      using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
      {
        byte[] c;
        ErrorCode err = this.device.ReadGroupComponent(this.pin, (byte)groupID, compType, out c);

        if (!err.IsOK)
        {
          err.Command = "ReadGroupComponent";
          DebugUtils.DebugPrintErrorCodes(err);
          throw err;
        }

        if (!raw)
        {
          byte[] data = new byte[c.Length + 1];
          byte[] tmpData = c;
          // ensure that we add 0x00 to data to force it to be signed.
          data[0] = 0x00;
          Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
          //Data from the card is in big-endian. need to reverse it.
          Array.Reverse(data, 0, data.Length);
          return data;
        }
        return c;

      }
    }
Example #20
0
    public void GetIssuanceResponse(byte credID) {

      using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
      {
        byte[] c;
        ErrorCode err = this.device.GetIssuanceResponse(this.pin, credID, out c);

        if (!err.IsOK)
        {
          err.Command = "GetIssuanceResponse";
          DebugUtils.DebugPrintErrorCodes(err);
          throw err;
        }
      }
    }
Example #21
0
    public byte[] GetDevicePublicKey(bool raw = false)
    {
      using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
      {
        byte[] pubKey;
        ErrorCode err = this.device.GetDevicePublicKey(this.pin, out pubKey);

        if (!err.IsOK)
        {
          err.Command = "GetDevicePublicKey";
          DebugUtils.DebugPrintErrorCodes(err);
          throw err;
        }

        if (!raw)
        {
          byte[] data = new byte[pubKey.Length + 1];
          byte[] tmpData = pubKey;
          // ensure that we add 0x00 to data to force it to be signed.
          data[0] = 0x00;
          Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
          //Data from the card is in big-endian. need to reverse it.
          Array.Reverse(data, 0, data.Length);
          return data;
        }
        else
        {
          return pubKey;
        }
      }
    }
Example #22
0
    public byte[] GetScopeExclusivePseudonym(byte[] scopeURI, bool raw = false)
    {
      using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
      {
        byte[] C;
        ErrorCode err = this.device.GetScopeExlusivePseudonym(this.pin, scopeURI, out C);

        if (!err.IsOK)
        {
          err.Command = "GetScopeExlusivePseudonym";
          DebugUtils.DebugPrintErrorCodes(err);
          throw err;
        }
        if (!raw)
        {
          byte[] data = new byte[C.Length + 1];
          byte[] tmpData = C;
          // ensure that we add 0x00 to data to force it to be signed.
          data[0] = 0x00;
          Buffer.BlockCopy(tmpData, 0, data, 1, tmpData.Length);
          Array.Reverse(data, 0, data.Length);
          return data;
        }
        else
        {
          return C;
        }
      }
    }
Example #23
0
 public byte[] GetDeviceResponse(bool raw = false)
 {
   
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     byte[] R;
     ErrorCode err = this.device.GetDeviceResponse(this.pin, out R);
     if (!err.IsOK)
     {
       err.Command = "GetDeviceResponse";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
     if (!raw)
     {
       Array.Reverse(R, 0, R.Length);
     }
     return R;
   }
 }
Example #24
0
 public void BeginResponse(int proverID, byte[] input)
 {
   byte pID = (byte)proverID;
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     ErrorCode err = this.device.BeginResponse(pin, pID, input);
     if (!err.IsOK)
     {
       err.Command = "BeginResponse";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
   }
 }
Example #25
0
 public byte[] BeginCommitment(int proverID)
 {
   byte pID = (byte)proverID;
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     byte[] pSession;
     this.device.BeginCommitments(pin, pID, out pSession);
     return pSession;
   }
 }
Example #26
0
 public byte[] GetPresCommitment(int proverID, int credID, bool raw = false)
 {
   byte pID = (byte)proverID;
   byte cID = (byte)credID;
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     byte[] C;
     ErrorCode err = this.device.GetPresentationCommitment(pin, cID, out C);
     if (!err.IsOK)
     {
       err.Command = "GetPresentationCommitment";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
     if (!raw)
     {
       Array.Reverse(C, 0, C.Length);
     }
     return C;
   }
 }
Example #27
0
 public byte[] GetCredentialPublicKey(int credID, bool raw = false)
 {
   byte cID = (byte)credID;
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     byte[] pubKey;
     ErrorCode err = this.device.GetCredentialPublicKey(pin, cID, out pubKey);
     if (!err.IsOK)
     {
       err.Command = "GetCredentialPublicKey";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
     if (!raw)
     {
       Array.Reverse(pubKey, 0, pubKey.Length);
     }
     return pubKey;
   }
 }
Example #28
0
 public bool IsGeneratorSet(int groupID)
 {
   byte gID = (byte)groupID;
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     byte[] sizeOfM;
     byte[] sizeOfQ;
     byte[] sizeOfF;
     int t;
     ErrorCode err = this.device.ReadGroup(this.pin, gID, out sizeOfM, out sizeOfQ, out sizeOfF, out t);
     if (!err.IsOK)
     {
       err.Command = "ReadGroup";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
     return t > 0;
   }
 }
Example #29
0
 public void SetGroupOfUnknownOrder(BigInteger modulus)
 {
   byte[] mod = modulus.ToByteArray();
   // need to convert it to big-endian.
   Array.Reverse(mod, 0, mod.Length);
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     ErrorCode err = this.device.PutData(mod);
     if (!err.IsOK)
     {
       err.Command = "PutData";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
     err = this.device.SetGroupComponent(0x00, 0);
     if (!err.IsOK)
     {
       err.Command = "SetGroupComponent";
       DebugUtils.DebugPrintErrorCodes(err);
       throw err;
     }
   } 
 }
Example #30
0
 public void SetCardInRootMode()
 {
   
   /* byte[] accMac = new byte[] { 0xE6, 0x63, 0x6D, 0x90, 0x49, 0x84, 0x02, 0xDF }; */
   byte[] accMac = new byte[] { 0xDD, 0xE8, 0x90, 0x96, 0x3E, 0xF8, 0x09, 0x0E };
   /*
    * Old root access macs:
    * { 0xE6, 0x63, 0x6D, 0x90, 0x49, 0x84, 0x02, 0xDF };
    */
   using (SmartCardTransaction scT = new SmartCardTransaction(this.device))
   {
     device.SetRootMode(accMac);
   }
 }