Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.0 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM crypto.cmd
  5. REM Applies MAC and signature to a list of crypto components
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. if defined _CPCMAGIC goto CPCBegin
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH};
  17. use PbuildEnv;
  18. use ParseArgs;
  19. use Logmsg;
  20. sub Usage { print<<USAGE; exit(1) }
  21. crypto [-l <language>]
  22. Applies MAC and signature to a list of crypto components
  23. USAGE
  24. sub Dependencies {
  25. if ( !open DEPEND, ">>$ENV{_NTPOSTBLD}\\..\\build_logs\\dependencies.txt" ) {
  26. errmsg("Unable to open dependency list file.");
  27. die;
  28. }
  29. print DEPEND<<DEPENDENCIES;
  30. \[$0\]
  31. IF {
  32. dssenh.dll
  33. rsaenh.dll
  34. gpkcsp.dll
  35. slbcsp.dll
  36. sccbase.dll
  37. } ADD {
  38. DEPENDENCIES
  39. print DEPEND " dump\\advapi_vaultsign.txt\n" if $ENV{VAULTSIGN};
  40. print DEPEND " dump\\advapi_enigma.txt\n" if $ENV{ENIGMA};
  41. print DEPEND "}\n\n";
  42. close DEPEND;
  43. exit;
  44. }
  45. my $qfe;
  46. parseargs('?' => \&Usage,
  47. 'plan' => \&Dependencies,
  48. 'qfe:' => \$qfe);
  49. if ( -f "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  50. if ( !open SKIP, "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  51. errmsg("Unable to open skip list file.");
  52. die;
  53. }
  54. while (<SKIP>) {
  55. chomp;
  56. exit if lc$_ eq lc$0;
  57. }
  58. close SKIP;
  59. }
  60. # *** NEXT FEW LINES ARE TEMPLATE ***
  61. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  62. __END__
  63. :CPCBegin
  64. set _CPCMAGIC=
  65. setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  66. REM *** BEGIN YOUR CMD SCRIPT BELOW ***
  67. REM
  68. REM Based on the postbuild environment, determine the appropriate
  69. REM signature processing to be done.
  70. REM
  71. if "1" == "%enigma%" if "1" == "%vaultsign%" (
  72. call errmsg "Both ENIGMA and VAULTSIGN options are set. Please enable only one."
  73. goto :EOF
  74. )
  75. if "1" == "%enigma%" (
  76. REM Check for binplaced marker file to verify that
  77. REM advapi32.dll was built with the Test Key enabled.
  78. if not exist %_NTPOSTBLD%\dump\advapi_enigma.txt (
  79. call errmsg "ENIGMA is set, but advapi32.dll was built without the Test Key enabled."
  80. goto :EOF
  81. )
  82. REM Will check for valid test key signature resources
  83. set ShowSigCmd=showsig
  84. REM The binary will be signed by this script
  85. set DoEnigmaSign=1
  86. ) else if "1" == "%vaultsign%" (
  87. REM Check for binplaced marker file to verify that
  88. REM advapi32.dll was built to require Vault Signatures.
  89. if not exist %_NTPOSTBLD%\dump\advapi_vaultsign.txt (
  90. call errmsg "VAULTSIGN is set, but advapi32.dll was not built with that option."
  91. goto :EOF
  92. )
  93. REM Will check for valid MS vault key signature resource
  94. set ShowSigCmd=showsig -t
  95. ) else set ShowSigCmd=
  96. REM MS Software CSPs
  97. call :SignFile dssenh.dll MAC
  98. call :SignFile rsaenh.dll MAC
  99. REM Smart Card CSPs
  100. call :SignFile gpkcsp.dll
  101. call :SignFile slbcsp.dll
  102. call :SignFile sccbase.dll
  103. goto :EOF
  104. :SignFile
  105. set image=%_NTPOSTBLD%\%1
  106. REM handle incremental case by skipping non-existant files
  107. if not exist %image% goto :EOF
  108. REM
  109. REM Check if signing is turned on
  110. REM
  111. if "1" == "%vaultsign%" (
  112. call logmsg "Performing signature check on vault signed CSP"
  113. goto :CheckSignature
  114. )
  115. REM imagecfg can't be called with ExecuteCmd since it does not set error values
  116. call logmsg "Executing imagecfg -n %Image%"
  117. imagecfg -n %Image%
  118. REM
  119. REM check if we have to apply a MAC
  120. REM
  121. if "%2" == "MAC" (
  122. call logmsg "Executing maccsp s %Image%"
  123. maccsp s %Image%
  124. )
  125. if not "1" == "%enigma%" (
  126. call logmsg "Not test signing %Image% (CSP test signing is turned off)"
  127. goto :CheckSignature
  128. )
  129. call ExecuteCmd "signcsp %Image%"
  130. if errorlevel 1 (
  131. call errmsg "signcsp %Image% failed (Check access to CryptoServer)"
  132. goto :EOF
  133. )
  134. :CheckSignature
  135. if "" == "%ShowSigCmd%" (
  136. call logmsg "Not checking signature of %Image% (no signature checking options enabled)"
  137. goto :EOF
  138. )
  139. call ExecuteCmd "%ShowSigCmd% %Image%"
  140. :end