Example #1
0
        // Digital-sign the data on the file
        public static void SignFile2(string destFileName, string srcFileName, string comment, bool kernelModeDriver, string certName)
        {
#if     !BU_OSS
            Con.WriteLine("Signing for '{0}'...", Path.GetFileName(destFileName));
            byte[] srcData = File.ReadAllBytes(srcFileName);

            byte[] destData = SignClient.Sign(srcData, certName, kernelModeDriver ? "Driver" : "", comment);

            try
            {
                File.Delete(destFileName);
            }
            catch
            {
            }

            File.WriteAllBytes(destFileName, destData);

            Con.WriteLine("Done.");
#else   // BU_OSS
            Con.WriteLine("Skipping the code signing for '{0}' in the build process. You can insert your own authenticode sign process here.", srcFileName);
#endif  // BU_OSS
        }
Example #2
0
        // Digital-sign the data on the memory
        public static byte[] SignMemory(byte[] srcData, string comment, bool kernelModeDriver, bool evCert, bool skipVerify)
        {
#if     !BU_OSS
            // 2020/01/19 switch to the new system
            return(SignClient.Sign(srcData, evCert ? "SoftEtherEv" : "SoftEtherFile", (kernelModeDriver ? "Driver" : "") + "," + (skipVerify ? "SkipVerify" : ""), comment));

            /*
             * int i;
             * string out_filename = null;
             * byte[] ret = null;
             *
             * string in_tmp_filename = Path.Combine(in_dir,
             *      Str.DateTimeToStrShortWithMilliSecs(DateTime.Now) + "_" +
             *      Env.MachineName + "_" +
             *      Secure.Rand63i().ToString() + ".dat");
             *
             * IO.SaveFile(in_tmp_filename, srcData);
             *
             * for (i = 0; i < NumRetries; i++)
             * {
             *      Sign sign = new Sign();
             *      sign.Proxy = new WebProxy();
             *
             *      try
             *      {
             *              out_filename = sign.ExecSignEx(Path.GetFileName(in_tmp_filename),
             *                      kernelModeDriver,
             *                      comment,
             *                      cert_id,
             *                      sha_mode);
             *              break;
             *      }
             *      catch (Exception ex)
             *      {
             *              if (i != (NumRetries - 1))
             *              {
             *                      Kernel.SleepThread(RetryIntervals);
             *              }
             *              else
             *              {
             *                      throw ex;
             *              }
             *      }
             * }
             *
             * for (i = 0; i < NumRetriesForCopy; i++)
             * {
             *      try
             *      {
             *              ret = IO.ReadFile(Path.Combine(out_dir, out_filename));
             *      }
             *      catch (Exception ex)
             *      {
             *              if (i != (NumRetriesForCopy - 1))
             *              {
             *                      Kernel.SleepThread(RetryIntervalsForCopy);
             *              }
             *              else
             *              {
             *                      throw ex;
             *              }
             *      }
             * }
             *
             * string tmpFileName = IO.CreateTempFileNameByExt(".exe");
             * try
             * {
             *      File.Delete(tmpFileName);
             * }
             * catch
             * {
             * }
             * File.WriteAllBytes(tmpFileName, ret);
             *
             * lock (lockObj)
             * {
             *      if (ExeSignChecker.CheckFileDigitalSignature(tmpFileName) == false)
             *      {
             *              throw new ApplicationException("CheckFileDigitalSignature failed.");
             *      }
             *
             *      if (kernelModeDriver)
             *      {
             *              if (ExeSignChecker.IsKernelModeSignedFile(tmpFileName) == false)
             *              {
             *                      throw new ApplicationException("IsKernelModeSignedFile failed.");
             *              }
             *      }
             * }
             *
             * try
             * {
             * }
             * catch
             * {
             *      File.Delete(tmpFileName);
             * }
             *
             * return ret;*/
#else   // BU_OSS
            return(srcData);
#endif  // BU_OSS
        }