Beispiel #1
0
        public static bool Certify(string SymT, string vPath)
        {
            List <MethodRecord> methodList = MethodHasher.getDehashedRecords(SymT);

            VProgramGenerator.generateVProgram(methodList, vPath);
            VProgramGenerator.EditCSproj(methodList, vPath);
            bool resultOfVerification = VProgramGenerator.verify(vPath);

            return(resultOfVerification);
        }
Beispiel #2
0
        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]);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public static List <MethodRecord> getDehashedRecords(string SymT)
        {
            List <MethodRecord> mrList = new List <MethodRecord>();

            string[] sha_methods = 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 = MethodHasher.getMRFromFile(stripped_method);

                mrList.Add(mr);
            }

            return(mrList);
        }
Beispiel #5
0
        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 + ")";
        }