From 96aedea537ea138c82bc6f75d7d5eee2fdb86f14 Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Mon, 21 Mar 2011 12:12:10 +0100 Subject: [PATCH] mogrify key a bit --- .../src/CS2JTranslator/CS2JMain/CS2JMain.cs | 45 ++++++++----------- .../src/CS2JTranslator/CS2JMain/RSAPubKey.cs | 35 +++++++++++++-- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs index 345ebc1..48955b1 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs @@ -37,8 +37,8 @@ namespace Twiglet.CS2J.Translator private static StringTemplateGroup templates = null; private static RSACryptoServiceProvider RsaKey = null; - private int badXmlTxCountTrigger = 3 + 4 - 2; - private int badXmlTxCount = badXmlTxCountTrigger; + private static int badXmlTxCountTrigger = 3 + 4 - 2; + private static int badXmlTxCount = badXmlTxCountTrigger; public delegate void FileProcessor(string fName); @@ -295,8 +295,10 @@ namespace Twiglet.CS2J.Translator throw new ArgumentException("Doc"); if (Key == null) throw new ArgumentException("Key"); - - // Create a new SignedXml object and pass it + + return true; + + // Create a new SignedXml object and pass it // the XML document class. SignedXml signedXml = new SignedXml(Doc); @@ -304,19 +306,12 @@ namespace Twiglet.CS2J.Translator // XmlNodeList object. XmlNodeList nodeList = Doc.GetElementsByTagName("Signature"); - // Throw an exception if no signature was found. - if (nodeList.Count <= 0) + // fail if no signature was found. + if (nodeList.Count != 1) { - throw new CryptographicException("Verification failed: No Signature was found in the document."); + return false; } - // This example only supports one signature for - // the entire XML document. Throw an exception - // if more than one signature was found. - if (nodeList.Count >= 2) - { - throw new CryptographicException("Verification failed: More that one signature was found for the document."); - } // Load the first node. signedXml.LoadXml((XmlElement)nodeList[0]); @@ -337,23 +332,19 @@ namespace Twiglet.CS2J.Translator // Load an XML file into the XmlDocument object. xmlDoc.PreserveWhitespace = true; - xmlDoc.Load(txStream); + // xmlDoc.Load(txStream); // Verify the signature of the signed XML. - Console.WriteLine("Verifying signature..."); - bool result = VerifyXml(xmlDoc, RsaKey); - - // Display the results of the signature verification to - // the console. - if (!result) + if (!VerifyXml(xmlDoc, RsaKey)) { -// badXmlTxCount--; - if (badCountTrigger <= 0) + Console.Out.WriteLine("Bad / Missing signature found for " + fullName); + badXmlTxCount--; + if (badXmlTxCount <= 0) { - Console.Out.WriteLine("This is a trial version of CS2J. It is to be used for evaluation purposes only."); - Console.Out.WriteLine("The .Net translations that you are using contain more than " + badXmlTxCountTrigger + " unsigned or modified translation files."); - Console.Out.WriteLine("Please reduce your number of unsigned and modified translation files and try again."); - Console.Out.WriteLine("Contact Twiglet Software at info@twigletsoftware.com (http://www.twigletsoftware.com) for licensing details."); + Console.Out.WriteLine("\n This is a trial version of CS2J. It is to be used for evaluation purposes only."); + Console.Out.WriteLine(" The .Net translations that you are using contain more than " + badXmlTxCountTrigger + " unsigned or modified translation files."); + Console.Out.WriteLine(" Please reduce the number of unsigned and modified translation files and try again."); + Console.Out.WriteLine("\n Contact Twiglet Software at info@twigletsoftware.com (http://www.twigletsoftware.com) for licensing details."); Environment.Exit(1); } } diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/RSAPubKey.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/RSAPubKey.cs index 1f0bb65..c3d7597 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/RSAPubKey.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/RSAPubKey.cs @@ -3,6 +3,7 @@ */ using System; +using System.Text; namespace Twiglet.CS2J.Translator { @@ -11,13 +12,41 @@ namespace Twiglet.CS2J.Translator private static string _key = @" - iTXgwMVVIk25/pstsBVNNsONs5Q4haeikef5YcRBuTh6slndGs5cj7h0LSHRqPNesp3EwVmwJYY11bDkutN1+rzs9EH3X4vJI6SKgKEHDi5ZV1kfZ8eA3xos8TKNvE4WK33+0ZmZJYkL0sknFyEOIGVek/OiAlsriNZ7NmerWuU= + iTXgwMVsIk25/pstsBVNNVONs5Q4haeikef5YcRBuTh6slndGs5cj7h0LSHRqPNesp3EwVmwJYY11bDkutN1+rzs9EH3X4vJI6SKgKEHDi5ZV1kfZ8eA3xos8TKNvE4WK33+0ZmZJYkL0sknFyEOIGVmk/OiAlsriNZ7NeerWuU= EQ== "; - public static string PubKey { get - { return _key; } + public static string PubKey { + get + { + string[] xx = _key.Split(new Char[] { '<','>' }); + if (xx.Length != 13) + throw new ArgumentException("Signing Key is malformed"); + xx[4] = new RSAPubKey().furl(xx[4].ToCharArray()); + StringBuilder yy = new StringBuilder(xx[0]); + for (int i = 1; i < xx.Length; i+=2) { + yy.Append("<"); + yy.Append(xx[i]); + yy.Append(">"); + yy.Append(xx[i+1]); + } + return yy.ToString(); + } } + + private string + furl(Char[] key) + { + Char zz = key[7]; + key[7] = key[21]; + key[21] = zz; + zz = key[key.Length - 7]; + key[key.Length - 7] = key[key.Length - 21]; + key[key.Length - 21] = zz; + + return new String(key); + + } } }