Leaked source code of windows server 2003
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.

143 lines
3.8 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM snsignfiles.cmd
  4. @REM Use PRS to strong name sign files
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. use strict;
  13. use lib $ENV{RAZZLETOOLPATH};
  14. use ParseArgs;
  15. use Win32::OLE qw(in);
  16. use File::Basename;
  17. use File::Copy;
  18. use Logmsg;
  19. sub Usage { print<<USAGE; exit(1) }
  20. snsignfiles <file 1> <file 2> ... <file n>
  21. Submits files to PRS for strong name signing. The original files will be
  22. updated in place with the signed file.
  23. USAGE
  24. my (@signers, @files);
  25. parseargs('?' => \&Usage,
  26. 's:' => \@signers,
  27. \@files);
  28. if (@ARGV) {
  29. Usage();
  30. }
  31. # command line signers override the hardcoded list
  32. if (!@signers) {
  33. @signers = qw(jeremyd wadela jfeltis miker);
  34. }
  35. my %files;
  36. my @signfiles;
  37. for my $file (@files) {
  38. if ($files{lc basename($file)}++) {
  39. # could handle this better by munging conflicting filenames
  40. # and unmunging when copying back from PRS
  41. errmsg("Filenames must be unique. $file conflicts.");
  42. exit 1;
  43. }
  44. # could add clever bindiff or sn logic here to handle incremental
  45. # postbuild nicely
  46. push @signfiles, $file;
  47. }
  48. if (!$ENV{MAIN_BUILD_LAB_MACHINE}) {
  49. logmsg("Skipping strong name signing on non-mainlab machine");
  50. exit 0;
  51. }
  52. my $cs = new Win32::OLE('SecureCodeSign.CodeSign');
  53. if (!defined $cs) {
  54. errmsg("Unable to create code signing object. See http://prslab " .
  55. "for instructions on setting this machine up for automated " .
  56. "submissions.");
  57. exit 1;
  58. }
  59. if (!$cs->Init('PRODUCTION')) {
  60. errmsg("Unable to initialize code siging object.");
  61. for my $e (in $cs->{RequestErrors}) {
  62. errmsg(sprintf("Init error: %d %s\n",
  63. $e->ErrorNumber,
  64. $e->ErrorDescription));
  65. }
  66. exit 1;
  67. }
  68. # PRS certificate ID number for Microsoft Resuable Component key
  69. # pubkey token 31bf3856ad364e35
  70. $cs->{SNCertificateID} = 35;
  71. $cs->{JobDescription} = "Windows build automated SN signing";
  72. for my $file (@signfiles) {
  73. # I don't believe the 2nd and 3rd field are used for SN signing
  74. $cs->SignFiles->add($file, $file, "http://www.microsoft.com/windows");
  75. }
  76. for my $signer (@signers) {
  77. $cs->Signers->add($signer);
  78. }
  79. if (!$cs->Submit()) {
  80. errmsg("Unable to submit code signing object");
  81. for my $e (in $cs->{RequestErrors}) {
  82. errmsg(sprintf("Submit error: %d %s\n",
  83. $e->ErrorNumber,
  84. $e->ErrorDescription));
  85. }
  86. exit 1;
  87. }
  88. logmsg(sprintf("Successfully submitted job #%d", $cs->{JobID}));
  89. my $last_status;
  90. while (1) {
  91. $cs->UpdateStatus();
  92. my $status = $cs->{Status};
  93. if (!defined $last_status or $status != $last_status) {
  94. timemsg(sprintf("Request status: %d", $status));
  95. }
  96. if ($status == 8) {
  97. logmsg("PRS request is complete");
  98. last;
  99. }
  100. elsif (60 <= $status and $status <= 70) {
  101. errmsg(sprintf("Signing failed: %d", $status));
  102. for my $e (in $cs->{RequestErrors}) {
  103. errmsg(sprintf("Signing error: %d %s\n",
  104. $e->ErrorNumber,
  105. $e->ErrorDescription));
  106. }
  107. exit 1;
  108. }
  109. $last_status = $status;
  110. sleep 15;
  111. }
  112. my $signed_path = $cs->{SignedPath};
  113. for my $file (@signfiles) {
  114. my $src = $signed_path . '\\' . basename($file);
  115. my $dst = $file;
  116. logmsg("Copying $src to $dst");
  117. if (!copy($src, $dst)) {
  118. errmsg("Unable to copy file $src to $dst: $!");
  119. exit 1;
  120. }
  121. }
  122. logmsg("Strong name signing completed successfully");
  123. exit 0;