@@ -0,0 +1,1905 @@
+package i5.las2peer.tools;%0A%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.security.PublicKey;%0A%0Aimport org.w3c.dom.DOMException;%0Aimport org.w3c.dom.Element;%0A%0Aimport i5.las2peer.persistency.MalformedXMLException;%0Aimport i5.las2peer.security.Agent;%0A%0Apublic class AgentIdMigrator %7B%0A%0A%09public static void main(String%5B%5D args)%0A%09%09%09throws MalformedXMLException, DOMException, SerializationException, IOException %7B%0A%09%09if (args.length %3C 1) %7B%0A%09%09%09System.out.println(%22Usage: agent-filename.xml %5Bagent-filename.xml...%5D%22);%0A%09%09%09System.exit(1);%0A%09%09%7D else %7B%0A%09%09%09// change agent id to derived one from public key%0A%09%09%09for (String agentFilename : args) %7B%0A%09%09%09%09migrateAgentXMLFile(agentFilename);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09public static void migrateAgentXMLFile(String xmlFilename)%0A%09%09%09throws MalformedXMLException, DOMException, SerializationException, IOException %7B%0A%09%09System.out.println(%22Migrating XML file: %22 + xmlFilename);%0A%09%09Element root = XmlTools.getRootElement(new File(xmlFilename), %22las2peer:agent%22);%0A%09%09replaceAgentId(root);%0A%09%09Agent migratedAgent = Agent.createFromXml(root);%0A%09%09String migratedXMLStr = migratedAgent.toXmlString();%0A%09%09FileWriter fw = new FileWriter(xmlFilename);%0A%09%09fw.write(migratedXMLStr);%0A%09%09fw.close();%0A%09%7D%0A%0A%09public static void replaceAgentId(Element root) throws MalformedXMLException, DOMException, SerializationException %7B%0A%09%09Element elId = XmlTools.getSingularElement(root, %22id%22);%0A%09%09Element pubKey = XmlTools.getSingularElement(root, %22publickey%22);%0A%09%09if (!pubKey.getAttribute(%22encoding%22).equals(%22base64%22)) %7B%0A%09%09%09throw new MalformedXMLException(%22base64 encoding expected%22);%0A%09%09%7D%0A%09%09PublicKey publicKey = (PublicKey) SerializeTools.deserializeBase64(pubKey.getTextContent());%0A%09%09String safeId = CryptoTools.publicKeyToSHA512(publicKey);%0A%09%09System.out.println(%22Replace agent id '%22 + elId.getTextContent() + %22' with safe agent id '%22 + safeId + %22'%22);%0A%09%09elId.setTextContent(safeId);%0A%09%7D%0A%0A%7D%0A

add AgentIdMigrator tool for agent id migration