示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aSim"></param>

        private void _DisposeSim(SIMAuthDaemon aSim)
        {
            if (aSim == null)
            {
                return;
            }
            aSim.Card.Disconnect(SCardDisposition.UnpowerCard);
            aSim.Card.Dispose();
        }
示例#2
0
        internal byte[] RunGsmAlgo(byte[] rand)
        {
            if (!aSim.SelectDFTelecom())
            {
                MessageBox.Show("Error reading GSM SIM card!");
                _DisposeSim(aSim);
                aSim = null;
                return(null);
            }

            CardResponseAPDU sres = aSim.RunGsmAlgo(rand);

            if (sres != null && sres.GetData() != null)
            {
                txtLog.AppendText("SRES resp " + CardHex.FromByteArray(rand) + "[" + rand.Length + "] -> " + CardHex.FromByteArray(sres.GetData()) + Environment.NewLine);
                return(sres.GetData());
            }

            txtLog.AppendText("SRES fail " + CardHex.FromByteArray(rand) + "[" + rand.Length + "] -> <failed> " + CardHex.FromByte(sres.SW1) + " " + CardHex.FromByte(sres.SW2) + Environment.NewLine);
            return(null);
        }
示例#3
0
        private void btnReadDetails_Click(object sender, System.EventArgs e)
        {
            if (aSim == null)
            {
                aSim = _ObtainSim();
                if (aSim == null)
                {
                    return;
                }
            }

            try
            {
                byte[] data = aSim.ReadIccIdentification();
                if (data == null)
                {
                    MessageBox.Show("Error reading GSM SIM card!");
                    _DisposeSim(aSim);
                    aSim = null;
                    return;
                }
                txtLog.AppendText("ICCID: " + CardHex.FromByteArray(data) + Environment.NewLine);


                /* check access to SIM card. fails if CHV required */
                if (aSim.ReadImsi() == null)
                {
                    CardResponseAPDU aRespAPDU = aSim.VerifyChv(this, m_aCardForm,
                                                                "PIN Verification", "In order to access your SIM the PIN is required.");

                    if (aRespAPDU == null)
                    {
                        // The PIN entry has been cancelled by the user.
                        _DisposeSim(aSim);
                        aSim = null;
                        return;
                    }

                    if (!aRespAPDU.IsSuccessful)
                    {
                        string sHeading = "Failed to verify PIN!";
                        switch (aRespAPDU.SW)
                        {
                        case 0x9804:
                            m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading,
                                               "Wrong PIN!");
                            break;

                        case 0x9840:
                            m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading,
                                               "Wrong PIN! The SIM has been blocked.");
                            break;

                        case 0x9808:
                            m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading,
                                               "The SIM is blocked. Please use mobile phone " +
                                               "in order to unblock the SIM with the PUK.");
                            break;

                        default:
                            m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading,
                                               "Unknown reason: (" + aRespAPDU.SW + ")");
                            break;
                        }
                        _DisposeSim(aSim);
                        aSim = null;
                        return;
                    }
                }

                data = aSim.ReadImsi();
                if (data == null)
                {
                    MessageBox.Show("Error reading IMSI!");
                    _DisposeSim(aSim);
                    aSim = null;
                    return;
                }
                txtLog.AppendText("IMSI:  " + CardHex.FromByteArray(data) + Environment.NewLine);

                if (!aSim.SelectDFTelecom())
                {
                    MessageBox.Show("Error selecting GSM file!");
                    _DisposeSim(aSim);
                    aSim = null;
                    return;
                }

                byte[] rand = CardHex.ToByteArray(txtRand.Text);
                byte[] resp = RunGsmAlgo(rand);

                /**/
            }
            catch (Exception)
            {
                _DisposeSim(aSim);
                aSim = null;
            }
        }