public virtual void Deserialize(byte[] input) { int pos = 0; LengthofExecutableLoadFileAID = input[pos]; pos++; byte[] loadFileAIDBytes = new byte[LengthofExecutableLoadFileAID]; Array.Copy(input, pos, loadFileAIDBytes, 0, LengthofExecutableLoadFileAID); ExecutableLoadFileAID = Formatting.ByteArrayToHexString(loadFileAIDBytes); pos = pos + LengthofExecutableLoadFileAID; LengthofExecutableModuleAID = input[pos]; pos++; byte[] securityDomainAIDBytes = new byte[LengthofExecutableModuleAID]; Array.Copy(input, pos, securityDomainAIDBytes, 0, LengthofExecutableModuleAID); ExecutableModuleAID = Formatting.ByteArrayToHexString(securityDomainAIDBytes); pos = pos + LengthofExecutableModuleAID; LengthofApplicationAID = input[pos]; pos++; byte[] applicationAIDBytes = new byte[LengthofApplicationAID]; Array.Copy(input, pos, applicationAIDBytes, 0, LengthofApplicationAID); ApplicationAID = Formatting.ByteArrayToHexString(applicationAIDBytes); pos = pos + LengthofApplicationAID; LengthofPrivileges = input[pos]; pos++; Privileges = new byte[LengthofPrivileges]; Array.Copy(input, pos, Privileges, 0, LengthofPrivileges); pos = pos + LengthofPrivileges; LengthofInstallParametersfield = (int)DeterminaLengthLength(input, ref pos); InstallParametersfield = new byte[LengthofInstallParametersfield]; Array.Copy(input, pos, InstallParametersfield, 0, LengthofInstallParametersfield); pos = pos + LengthofInstallParametersfield; if (LengthofInstallParametersfield > 2) { InstallParamC9 = new INSTALL_PARAM_C9_GP(); InstallParamC9.Deserialize(InstallParametersfield, 0); } LengthofInstallToken = (int)DeterminaLengthLength(input, ref pos); InstallToken = new byte[LengthofInstallToken]; Array.Copy(input, pos, InstallToken, 0, LengthofInstallToken); pos = pos + LengthofInstallToken; }
public static void GPPersoFromXmlTest(string xml) { perso perso = XMLUtil <perso> .Deserialize(xml); perso.application.ToList().ForEach(app => { installType it = app.commands.install; INSTALL_PARAM_C9_GP ip = null; if (it.tokens != null) { if (it.tokens.tlvxml != null) { ip = new INSTALL_PARAM_C9_GP(); valueC9Type c9 = it.tokens.tlvxml.valueC9; if (c9.C9_ApplicationInstanceSpecified) { ip.Value.ApplicationInstance = MapC9_ApplicationInstanceEnum(c9.C9_ApplicationInstance); } if (c9.C9_PinSharingSpecified) { ip.Value.PinSharing = MapC9_PinSharingEnum(c9.C9_PinSharing); } if (c9.C9_InterfacesAvailableSpecified) { ip.Value.InterfacesAvailable = MapC9_InterfacesAvailableEnum(c9.C9_InterfacesAvailable); } } } GPInstallRequestDataForInstall irfi = new GPInstallRequestDataForInstall() { ExecutableLoadFileAID = it.ExecutableLoadFileAID, ExecutableModuleAID = it.ExecutableModuleAID, ApplicationAID = it.ApplicationAID, Privileges = Formatting.HexStringToByteArray(it.Privileges), InstallToken = Formatting.HexStringToByteArray(it.InstallToken), InstallParamC9 = ip, }; //select //auth GPInstallRequest ir = new GPInstallRequest((byte)InstallRequestP1Enum.LastOrOnlyCommand | (byte)InstallRequestP1Enum.ForMakeSelectable | (byte)InstallRequestP1Enum.ForInstall) { CommandData = irfi.Serialize() }; System.Diagnostics.Debug.WriteLine(ir.ToPrintString()); //select //auth app.commands.storeData.ToList().ForEach(command => { GPStoreData sd = new GPStoreData { DGI = Formatting.HexStringToByteArray(command.DGI) }; if (command.data != null) { sd.DataBytes = Formatting.HexStringToByteArray(command.data); } else { sd.Data = DeserList(command.tlvxml); } GPStoreDataReqest sdr = new GPStoreDataReqest { CommandData = sd.Serialize() }; System.Diagnostics.Debug.WriteLine(sdr.ToPrintString()); }); }); }
public void PersoFromXml(string xml, string secDomainAID, string masterKey) { perso perso = XMLUtil <perso> .Deserialize(xml); byte[] masterKeyBytes = Formatting.HexStringToByteArray(masterKey); perso.application.ToList().ForEach(app => { installType it = app.commands.install; INSTALL_PARAM_C9_GP ip = null; if (it.tokens != null) { if (it.tokens.tlvxml != null) { ip = new INSTALL_PARAM_C9_GP(); valueC9Type c9 = it.tokens.tlvxml.valueC9; if (c9.C9_ApplicationInstanceSpecified) { ip.Value.ApplicationInstance = MapC9_ApplicationInstanceEnum(c9.C9_ApplicationInstance); } if (c9.C9_PinSharingSpecified) { ip.Value.PinSharing = MapC9_PinSharingEnum(c9.C9_PinSharing); } if (c9.C9_InterfacesAvailableSpecified) { ip.Value.InterfacesAvailable = MapC9_InterfacesAvailableEnum(c9.C9_InterfacesAvailable); } } } GPInstallRequestDataForInstall irfi = new GPInstallRequestDataForInstall() { ExecutableLoadFileAID = it.ExecutableLoadFileAID, ExecutableModuleAID = it.ExecutableModuleAID, ApplicationAID = it.ApplicationAID, Privileges = Formatting.HexStringToByteArray(it.Privileges), InstallToken = Formatting.HexStringToByteArray(it.InstallToken), InstallParamC9 = ip, }; persoAccessHandler.SelectApplication(Formatting.HexStringToByteArray(secDomainAID)); //persoAccessHandler.AuthWithCard(masterKey); persoAccessHandler.AuthWithCard(masterKeyBytes, cardChallenge); persoAccessHandler.InstallForPerso(irfi.ApplicationAID); byte counter = 0; List <storeDataType> storeCommands = app.commands.storeData.ToList(); storeCommands.ForEach(command => { bool isLast = (storeCommands.Count - 1) == counter; GPStoreData sd = new GPStoreData { DGI = Formatting.HexStringToByteArray(command.DGI), DataBlock = counter, IsLastBlock = isLast, }; if (command.data != null) { sd.DataBytes = Formatting.HexStringToByteArray(command.data); } else { sd.Data = DeserList(command.tlvxml); } persoAccessHandler.StoreDataToApplication(sd); counter++; }); }); }