예제 #1
0
        public void InstallForPerso(String instanceId)
        {
            AID instance             = new AID(instanceId);
            ByteArrayOutputStream bo = new ByteArrayOutputStream();

            try
            {
                bo.Write((byte)0x00);
                bo.Write((byte)0x00);

                bo.Write((byte)instance.getLength());
                bo.Write(instance.getBytes());

                bo.Write((byte)0x00);
                bo.Write((byte)0x00);
                bo.Write((byte)0x00);
            }
            catch (IOException ioe)
            {
                throw new Exception(ioe.Message);
            }

            GPInstallRequest install = new GPInstallRequest((byte)InstallRequestP1Enum.LastOrOnlyCommand | (byte)InstallRequestP1Enum.ForPersonalization)
            {
                CommandData = bo.ToByteArray()
            };
            //System.Diagnostics.Debug.WriteLine(install.ToPrintString());
            GPInstallResponse response = (GPInstallResponse)SendCommand(install);

            if (response.SW != (ushort)ISO7816ReturnCodes.SW_NO_ERROR)
            {
                throw new Exception("Install for Perso failed");
            }
        }
예제 #2
0
        private void loadCapFile(String sAID, CapFile cap, bool includeDebug, bool separateComponents, bool loadParam, bool useHash)
        {
            //if (getRegistry().allAIDs().Contains(cap.getPackageAID()))
            //{
            //    giveStrictWarning("Package with AID " + cap.getPackageAID() + " is already present on card");
            //}
            byte[] hash = useHash ? cap.getLoadFileDataHash("SHA1", includeDebug) : new byte[0];
            int    len  = cap.getCodeLength(includeDebug);

            // FIXME: parameters are optional for load
            byte[] loadParams = loadParam ? new byte[] { (byte)0xEF, 0x04, (byte)0xC6, 0x02, (byte)((len & 0xFF00) >> 8),
                                                         (byte)(len & 0xFF) } : new byte[0];

            ByteArrayOutputStream bo = new ByteArrayOutputStream();

            try
            {
                bo.Write((byte)cap.getPackageAID().getLength());
                bo.Write(cap.getPackageAID().getBytes());

                AID aid = new AID(sAID);
                bo.Write((byte)aid.getLength());
                bo.Write(aid.getBytes());

                bo.Write((byte)hash.Length);
                bo.Write(hash);

                bo.Write((byte)loadParams.Length);
                bo.Write(loadParams);

                bo.Write((byte)0x00); //no load token
            }
            catch (IOException ioe)
            {
                throw new Exception(ioe.Message);
            }

            GPInstallRequest installForLoad = new GPInstallRequest(GPInstructionEnum.Install, bo.ToByteArray(), 0x02, 0x00);
            //System.Diagnostics.Debug.WriteLine(installForLoad.ToPrintString());
            GPInstallResponse response = (GPInstallResponse)SendCommand(installForLoad);

            if (response.SW != (ushort)ISO7816ReturnCodes.SW_NO_ERROR)
            {
                throw new Exception("Install for Load failed");
            }

            List <byte[]> blocks = cap.getLoadBlocks(includeDebug, separateComponents, wrapper.getBlockSize());

            for (int i = 0; i < blocks.Count; i++)
            {
                GPInstallRequest load = new GPInstallRequest(GPInstructionEnum.Load, blocks[i], (byte)((i == (blocks.Count - 1)) ? 0x80 : 0x00), (byte)i);
                //System.Diagnostics.Debug.WriteLine(load.ToPrintString());
                response = (GPInstallResponse)SendCommand(load);
                if (response.SW != (ushort)ISO7816ReturnCodes.SW_NO_ERROR)
                {
                    throw new Exception("Load failed");
                }
            }
        }
예제 #3
0
        private void installAndMakeSelectable(AID packageAID, AID appletAID, AID instanceAID, Privileges privileges, byte[] installParams, byte[] installToken)
        {
            if (instanceAID == null)
            {
                instanceAID = appletAID;
            }
            //if (getRegistry().allAppletAIDs().Contains(instanceAID))
            //{
            //giveStrictWarning("Instance AID " + instanceAID + " is already present on card");
            //}
            if (installParams == null)
            {
                installParams = new byte[] { (byte)0xC9, 0x00 };
            }
            if (installToken == null)
            {
                installToken = new byte[0];
            }
            byte[] privs             = privileges.toBytes();
            ByteArrayOutputStream bo = new ByteArrayOutputStream();

            try
            {
                bo.Write((byte)packageAID.getLength());
                bo.Write(packageAID.getBytes());

                bo.Write((byte)appletAID.getLength());
                bo.Write(appletAID.getBytes());

                bo.Write((byte)instanceAID.getLength());
                bo.Write(instanceAID.getBytes());

                bo.Write((byte)privs.Length);
                bo.Write(privs);

                bo.Write((byte)installParams.Length);
                bo.Write(installParams);

                bo.Write((byte)installToken.Length);
                bo.Write(installToken);
            }
            catch (IOException ioe)
            {
                throw new Exception(ioe.Message);
            }
            GPInstallRequest install = new GPInstallRequest(GPInstructionEnum.Install, bo.ToByteArray(), 0x0C, 0x00);
            //System.Diagnostics.Debug.WriteLine(install.ToPrintString());
            GPInstallResponse response = (GPInstallResponse)SendCommand(install);

            if (response.SW != (ushort)ISO7816ReturnCodes.SW_NO_ERROR)
            {
                throw new Exception("Install for Install and make selectable failed");
            }
        }
예제 #4
0
        public void deleteAID(AID aid, bool deleteDeps)
        {
            ByteArrayOutputStream bo = new ByteArrayOutputStream();

            try
            {
                bo.Write((byte)0x4F);
                bo.Write((byte)aid.getLength());
                bo.Write(aid.getBytes());
            }
            catch (IOException ioe)
            {
                throw new Exception(ioe.Message);
            }
            GPInstallRequest  delete   = new GPInstallRequest(GPInstructionEnum.Delete, bo.ToByteArray(), 0x00, (byte)(deleteDeps ? 0x80 : 0x00));
            GPInstallResponse response = (GPInstallResponse)SendCommand(delete);

            if (response.SW != (ushort)ISO7816ReturnCodes.SW_NO_ERROR)
            {
                throw new Exception("Deletion failed");
            }
        }