public static void recordme(Object o, CST_MSG in_msg, CST_MSG out_msg) { StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(1); Type t = st.GetType(); Console.WriteLine(t); MethodInfo mi = (MethodInfo)sf.GetMethod(); recordme(o, in_msg, out_msg, mi, myPartyName, false, false); }
public static bool Certify(CST_MSG msg) { RemoveUntrustedSymTPart(msg); if (!SymTResultCache.ContainsKey(msg.SymT)) { bool resultOfVerification = uploader.verify(msg.SymT); SymTResultCache[msg.SymT] = resultOfVerification; } return(SymTResultCache[msg.SymT]); }
private static void RemoveUntrustedSymTPart(CST_MSG msg) { string peeledSymT = msg.SymT; int pos = 0, st_of_sym = 0, brk_cnt = 0; bool signed_symT = true; for (; pos < msg.SymT.Length && msg.SymT[pos] != ')'; pos++) { if (msg.SymT[pos] == ':') { if (msg.SymT[pos + 1] == ':' || signed_symT) { string partyN = msg.SymT.Substring(st_of_sym, pos - st_of_sym); if (!trustedParties.Contains(partyN)) { peeledSymT = peeledSymT.Substring(0, st_of_sym) + new String(')', brk_cnt); break; } if (msg.SymT[pos + 1] == ':') { pos++; } } else { peeledSymT = peeledSymT.Substring(0, st_of_sym) + new String(')', brk_cnt); break; } } if (msg.SymT[pos] == '(') { brk_cnt++; if (msg.SymT[pos + 1] == '(') { signed_symT = true; pos++; brk_cnt++; } else { signed_symT = false; } st_of_sym = pos + 1; } } msg.SymT = peeledSymT; }
public static bool CertifyLocally(CST_MSG msg) { RemoveUntrustedSymTPart(msg); if (!SymTResultCache.ContainsKey(msg.SymT)) { List <MethodRecord> mrList = MethodHasher.getDehashedRecords(methodSHADictKEYSHA, msg); VProgramGenerator.EditCSproj(mrList); VProgramGenerator.generateVProgram(mrList); bool resultOfVerification = VProgramGenerator.verify(); SymTResultCache[msg.SymT] = resultOfVerification; } return(SymTResultCache[msg.SymT]); }
public static void recordme(Object o, CST_MSG in_msg, CST_MSG out_msg, MethodInfo mi, string partyName, bool signed, bool server_to_server) { Type objT = o.GetType(); var t = mi.ReflectedType; string rootClass = GetRootClassName(t); string className = objT.FullName; className = className.Replace("\\", string.Empty).Replace('+', '.'); string methodName = mi.Name; ParameterInfo[] pi = mi.GetParameters(); string[] args = new string[pi.Length]; string argType = ""; if (pi.Length > 0) { argType = pi[0].ParameterType.FullName; argType = argType.Replace("\\", string.Empty).Replace('+', '.'); } string returnType = mi.ReturnType.FullName; returnType = returnType.Replace("\\", string.Empty).Replace('+', '.'); string methodkey = returnType + " " + className + " " + rootClass + "." + methodName + "(" + argType + ")"; string sha = "0000000000000000000000000000000000000000"; if (!methodSHADict.ContainsKey(methodkey)) { string dllName = objT.Module.FullyQualifiedName; string path = Path.GetDirectoryName(dllName); string name = Path.GetFileNameWithoutExtension(dllName); var descriptionAttribute = objT.Module.Assembly .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) .OfType<AssemblyDescriptionAttribute>() .FirstOrDefault(); if (descriptionAttribute != null) sha = descriptionAttribute.Description; MethodRecord mr = new MethodRecord(className, rootClass, methodName, argType, returnType, name + "." + sha); MethodHasher.saveMethod(mr); uploader.uploadMethodRecord(MethodHasher.methodsFolder + "\\" + mr.getSHA() + ".txt", mr.getSHA()); methodSHADict.AddOrUpdate(methodkey, mr, (k, v) => v); methodSHADictKEYSHA.AddOrUpdate(mr.getSHA(), mr, (k, v) => v); sha = mr.getSHA(); } else { sha = methodSHADict[methodkey].getSHA(); } string colons = ":"; if (signed) colons = "::"; string in_msg_symT = in_msg.SymT; if (server_to_server) { int idx = in_msg_symT.IndexOf('('); if (idx != -1) in_msg_symT = '(' + in_msg_symT.Substring(0, idx) + '(' + in_msg_symT.Substring(idx, in_msg_symT.Length - idx) + "))"; } out_msg.SymT = partyName + colons + sha + "(" + in_msg_symT + ")"; }
private static void RemoveUntrustedSymTPart(CST_MSG msg) { string peeledSymT = msg.SymT; int pos = 0, st_of_sym = 0, brk_cnt = 0; bool signed_symT = true; for (; pos < msg.SymT.Length && msg.SymT[pos] != ')'; pos++) { if (msg.SymT[pos] == ':') { if (msg.SymT[pos + 1] == ':' || signed_symT) { string partyN = msg.SymT.Substring(st_of_sym, pos-st_of_sym); if (!trustedParties.Contains(partyN)) { peeledSymT = peeledSymT.Substring(0, st_of_sym) + new String(')', brk_cnt); break; } if (msg.SymT[pos + 1] == ':') pos++; } else { peeledSymT = peeledSymT.Substring(0, st_of_sym) + new String(')', brk_cnt); break; } } if (msg.SymT[pos] == '(') { brk_cnt++; if (msg.SymT[pos + 1] == '(') { signed_symT = true; pos++; brk_cnt++; } else signed_symT = false; st_of_sym = pos + 1; } } msg.SymT = peeledSymT; }
public static bool CertifyLocally(CST_MSG msg) { RemoveUntrustedSymTPart(msg); if (!SymTResultCache.ContainsKey(msg.SymT)) { List<MethodRecord> mrList = MethodHasher.getDehashedRecords(methodSHADictKEYSHA, msg); VProgramGenerator.EditCSproj(mrList); VProgramGenerator.generateVProgram(mrList); bool resultOfVerification = VProgramGenerator.verify(); SymTResultCache[msg.SymT] = resultOfVerification; } return SymTResultCache[msg.SymT]; }
public static bool Certify(CST_MSG msg) { RemoveUntrustedSymTPart(msg); if (!SymTResultCache.ContainsKey(msg.SymT)) { bool resultOfVerification = uploader.verify(msg.SymT); SymTResultCache[msg.SymT] = resultOfVerification; } return SymTResultCache[msg.SymT]; }
public static List <MethodRecord> getDehashedRecords(ConcurrentDictionary <string, MethodRecord> methodSHADictKEYSHA, CST_MSG msg) { List <MethodRecord> mrList = new List <MethodRecord>(); string[] sha_methods = msg.SymT.Split(new char[] { ' ', '(', ')' }, StringSplitOptions.RemoveEmptyEntries); foreach (string method in sha_methods) { string[] partyNameSplit = method.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (partyNameSplit.Length <= 1) { continue; } string stripped_method = partyNameSplit[1]; MethodRecord mr = null; if (!methodSHADictKEYSHA.ContainsKey(stripped_method)) { if (!File.Exists(methodsFolder + @"\" + stripped_method + ".txt")) { DLLServerDownloader.downloadMethodRecord(stripped_method); } mr = MethodHasher.getMRFromFile(stripped_method); } else { mr = methodSHADictKEYSHA[stripped_method]; } if (!Directory.Exists(dllsFolder + @"\" + mr.SHA_of_DLL)) { DLLServerDownloader.downloadDLLandDep(mr.SHA_of_DLL); } mrList.Add(mr); } return(mrList); }
public static void recordme(Object o, CST_MSG in_msg, CST_MSG out_msg, MethodInfo mi, string partyName, bool signed, bool server_to_server) { Type objT = o.GetType(); var t = mi.ReflectedType; string rootClass = GetRootClassName(t); string className = objT.FullName; className = className.Replace("\\", string.Empty).Replace('+', '.'); string methodName = mi.Name; ParameterInfo[] pi = mi.GetParameters(); string[] args = new string[pi.Length]; string argType = ""; if (pi.Length > 0) { argType = pi[0].ParameterType.FullName; argType = argType.Replace("\\", string.Empty).Replace('+', '.'); } string returnType = mi.ReturnType.FullName; returnType = returnType.Replace("\\", string.Empty).Replace('+', '.'); string methodkey = returnType + " " + className + " " + rootClass + "." + methodName + "(" + argType + ")"; string sha = "0000000000000000000000000000000000000000"; if (!methodSHADict.ContainsKey(methodkey)) { string dllName = objT.Module.FullyQualifiedName; string path = Path.GetDirectoryName(dllName); string name = Path.GetFileNameWithoutExtension(dllName); var descriptionAttribute = objT.Module.Assembly .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) .OfType <AssemblyDescriptionAttribute>() .FirstOrDefault(); if (descriptionAttribute != null) { sha = descriptionAttribute.Description; } MethodRecord mr = new MethodRecord(className, rootClass, methodName, argType, returnType, name + "." + sha); MethodHasher.saveMethod(mr); uploader.uploadMethodRecord(MethodHasher.methodsFolder + "\\" + mr.getSHA() + ".txt", mr.getSHA()); methodSHADict.AddOrUpdate(methodkey, mr, (k, v) => v); methodSHADictKEYSHA.AddOrUpdate(mr.getSHA(), mr, (k, v) => v); sha = mr.getSHA(); } else { sha = methodSHADict[methodkey].getSHA(); } string colons = ":"; if (signed) { colons = "::"; } string in_msg_symT = in_msg.SymT; if (server_to_server) { int idx = in_msg_symT.IndexOf('('); if (idx != -1) { in_msg_symT = '(' + in_msg_symT.Substring(0, idx) + '(' + in_msg_symT.Substring(idx, in_msg_symT.Length - idx) + "))"; } } out_msg.SymT = partyName + colons + sha + "(" + in_msg_symT + ")"; }