示例#1
0
        /// <summary>
        /// Update the current APDU with selected parameters
        /// </summary>
        /// <param name="apduParam">APDU parameters</param>
        public void    Update(APDUParam apduParam)
        {
            if (apduParam.UseData)
            {
                m_baData = apduParam.Data;
            }

            if (apduParam.UseLe)
            {
                m_bLe = apduParam.Le;
            }

            if (apduParam.UseP1)
            {
                m_bP1 = apduParam.P1;
            }

            if (apduParam.UseP2)
            {
                m_bP2 = apduParam.P2;
            }

            if (apduParam.UseChannel)
            {
                m_bCla += apduParam.Channel;
            }
        }
示例#2
0
        /// <summary>
        /// Copy constructor (used for cloning)
        /// </summary>
        /// <param name="param"></param>
        public APDUParam(APDUParam param)
        {
            // Copy field
            if (param.m_baData != null)
                param.m_baData.CopyTo(m_baData, 0);
            m_bClass = param.m_bClass;
            m_bChannel = param.m_bChannel;
            m_bP1 = param.m_bP1;
            m_bP2 = param.m_bP2;
            m_nLe = param.m_nLe;

            // Copy flags field
            m_fChannel = param.m_fChannel;
            m_fClass = param.m_fClass;
            m_fData = param.m_fData;
            m_fLe = param.m_fLe;
            m_fUseP1 = param.m_fUseP1;
            m_fUseP2 = param.m_fUseP2;
        }
示例#3
0
        /// <summary>
        /// Copy constructor (used for cloning)
        /// </summary>
        /// <param name="param"></param>
        public APDUParam(APDUParam param)
        {
            // Copy field
            if (param.m_baData != null)
            {
                param.m_baData.CopyTo(m_baData, 0);
            }
            m_bClass   = param.m_bClass;
            m_bChannel = param.m_bChannel;
            m_bP1      = param.m_bP1;
            m_bP2      = param.m_bP2;
            m_nLe      = param.m_nLe;

            // Copy flags field
            m_fChannel = param.m_fChannel;
            m_fClass   = param.m_fClass;
            m_fData    = param.m_fData;
            m_fLe      = param.m_fLe;
            m_fUseP1   = param.m_fUseP1;
            m_fUseP2   = param.m_fUseP2;
        }
示例#4
0
        public bool A38(byte[] Rand, byte[] Result)
        {
            Debug.Assert(Rand.Length == 16);
            try
            {
                if (!DFgsm_selected) SelectDFGsm();

                APDUResponse apduResp;
                APDUParam apduParam = new APDUParam();

                //Execute A38 Algorithm
                apduParam.Data = (byte[])Rand.Clone();
                apduRunGSM.Update(apduParam);
                apduResp = iCard.Transmit(apduRunGSM);
                if (apduResp.SW1 != SC_PENDING)
                    throw new Exception("RunGSM: " + apduResp.ToString());

                apduParam.Reset();
                apduParam.Le = apduResp.SW2;
                apduParam.Data = null;
                apduGetResponse.Update(apduParam);
                apduResp = iCard.Transmit(apduGetResponse);
                if (apduResp.Status != SC_OK)
                    throw new Exception("Get GSM result failed: " + apduResp.ToString());
                //Console.Write("GSM Result: ");
                //for (int i = 0; i < apduResp.Data.Length; i++)
                //    Console.Write(String.Format("{0:X2}", apduResp.Data[i]));
                //Console.WriteLine();
                apduResp.Data.CopyTo(Result, 0);
                return true;
                }
            catch (System.Exception ex)
            {
                Console.WriteLine("SIM Run_GSM exception: " + ex.ToString());
                return false;
            }
        }
示例#5
0
        /// <summary>
        /// This program tests the API with a SIM card. 
        /// If your PIN is activated be careful when presenting the PIN to your card! 
        /// </summary>
        public void Test()
        {
            try
            {
                DFgsm_selected = false;
                APDUResponse apduResp;
                APDUParam apduParam = new APDUParam();

                // Verify the PIN (if necessary)
                byte[] pin = new byte[] { 0x31, 0x32, 0x33, 0x34, 0xFF, 0xFF, 0xFF, 0xFF };
                apduParam.Data = pin;
                apduVerifyCHV.Update(apduParam);
                apduResp = iCard.Transmit(apduVerifyCHV);
                // Select the MF (3F00)
                apduParam.Data = new byte[] { 0x3F, 0x00 };
                apduSelectFile.Update(apduParam);
                apduResp = iCard.Transmit(apduSelectFile);
                if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING)
                    throw new Exception("Select command failed: " + apduResp.ToString());
                Console.WriteLine("MF selected");

                // Select the EFtelecom (7F10)
                apduParam.Data = new byte[] { 0x7F, 0x10 };
                apduSelectFile.Update(apduParam);
                apduResp = iCard.Transmit(apduSelectFile);
                if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING)
                    throw new Exception("Select command failed: " + apduResp.ToString());
                Console.WriteLine("DFtelecom selected");

                // Select the EFadn (6F3A)
                apduParam.Data = new byte[] { 0x6F, 0x3A };
                apduSelectFile.Update(apduParam);
                apduResp = iCard.Transmit(apduSelectFile);
                if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING)
                    throw new Exception("Select command failed: " + apduResp.ToString());
                Console.WriteLine("EFadn (Phone numbers) selected");

                // Read the response
                if (apduResp.SW1 == SC_PENDING)
                {
                    apduParam.Reset();
                    apduParam.Le = apduResp.SW2;
                    apduParam.Data = null;
                    apduGetResponse.Update(apduParam);
                    apduResp = iCard.Transmit(apduGetResponse);
                    if (apduResp.Status != SC_OK)
                        throw new Exception("Select command failed: " + apduResp.ToString());
                }

                // Get the length of the record
                int recordLength = apduResp.Data[14];

                Console.WriteLine("Reading the Phone number 10 first entries");
                // Read the 10 first record of the file
                for (int nI = 0; nI < 10; nI++)
                {
                    apduParam.Reset();
                    apduParam.Le = (byte) recordLength;
                    apduParam.P1 = (byte) (nI + 1);
                    apduReadRecord.Update(apduParam);
                    apduResp = iCard.Transmit(apduReadRecord);

                    if (apduResp.Status != SC_OK)
                        throw new Exception("ReadRecord command failed: " + apduResp.ToString());

                    Console.WriteLine("Record #" + ((int) (nI + 1)).ToString());
                    Console.WriteLine(apduResp.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#6
0
        public void SelectDFGsm()
        {
            APDUResponse apduResp;
            APDUParam apduParam = new APDUParam();

            // Select the DF_GSM (7F20)
            apduParam.Data = new byte[] { 0x7F, 0x20 };
            apduSelectFile.Update(apduParam);
            apduResp = iCard.Transmit(apduSelectFile);
            if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING)
                throw new Exception("Select command failed: " + apduResp.ToString());
            Console.WriteLine("DFgsm selected");
            DFgsm_selected = true;
        }
        /// <summary>
        /// Update the current APDU with selected parameters
        /// </summary>
        /// <param name="apduParam">APDU parameters</param>
        public void Update(APDUParam apduParam)
        {
            if (apduParam.UseData)
                m_baData = apduParam.Data;

            if (apduParam.UseLe)
                m_bLe = apduParam.Le;

            if (apduParam.UseP1)
                m_bP1 = apduParam.P1;

            if (apduParam.UseP2)
                m_bP2 = apduParam.P2;

            if (apduParam.UseChannel)
                m_bCla += apduParam.Channel;
        }