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.

134 lines
4.6 KiB

  1. <%@ CODEPAGE=65001 'UTF-8%>
  2. <%' certnew.cer - (CERT)srv web - return a (NEW) certificate
  3. ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <!-- #include FILE=certdat.inc -->
  5. <!-- #include FILE=certsrck.inc -->
  6. <% ' ########## BEGIN SERVER SIDE EXECUTION ##########
  7. 'Process a Certificate Request
  8. Dim nDisposition, nResult, sCert, sErrMsg, nEncoding
  9. On Error Resume Next
  10. ' from \nt\public\sdk\inc\certcli.h
  11. Const CR_OUT_BASE64HEADER=&H00000000
  12. Const CR_OUT_BASE64=&H00000001
  13. Const CR_OUT_BINARY=&H00000002
  14. Const CR_OUT_CHAIN=&H00000100
  15. 'Disposition code ref: \nt\public\sdk\inc\certcli.h
  16. Const CR_DISP_INCOMPLETE =0
  17. Const CR_DISP_ERROR =1
  18. Const CR_DISP_DENIED =2
  19. Const CR_DISP_ISSUED =3
  20. Const CR_DISP_ISSUED_OUT_OF_BAND=4
  21. Const CR_DISP_UNDER_SUBMISSION =5
  22. Const CR_DISP_REVOKED =6
  23. Const no_disp=-1
  24. Const CR_PROP_CASIGCERT=12
  25. Const PROPTYPE_BINARY=3
  26. 'Stop 'debugging breakpoint
  27. ' determine the requested encoding
  28. If "bin"=Request.QueryString("Enc") Then
  29. nEncoding=CR_OUT_BINARY
  30. Else '"b64"=Request.QueryString("Enc")
  31. nEncoding=CR_OUT_BASE64HEADER
  32. End If
  33. ' create the object to do the request
  34. Set Session("ICertRequest")=Server.CreateObject("CertificateAuthority.Request")
  35. Set ICertRequest=Session("ICertRequest")
  36. nDisposition=no_disp
  37. Err.Clear 'make sure we catch the HRESULT and not some earlier error
  38. If "CACert"=Request.QueryString("ReqID") Then
  39. ' get the CA cert
  40. sCert=ICertRequest.GetCAProperty(sServerConfig, CR_PROP_CASIGCERT, Request.QueryString("Renewal"), PROPTYPE_BINARY, nEncoding)
  41. nResult=Err.Number
  42. sErrMsg=Err.Description
  43. If 0<>nResult Then
  44. 'internal redirect - transfer control to error page
  45. Session("nResult")=nResult
  46. Session("sErrMsg")=sErrMsg
  47. Server.Transfer("certrser.asp")
  48. End If
  49. Else
  50. ' Fetch the user's cert
  51. nDisposition=ICertRequest.RetrievePending(Request.QueryString("ReqID"), sServerConfig)
  52. nResult=Err.number
  53. sErrMsg=Err.Description
  54. If nDisposition=CR_DISP_ISSUED Then
  55. ' Remove this request from the user's cookie
  56. RemoveReq(Request.QueryString("ReqID"))
  57. sCert=ICertRequest.GetCertificate(nEncoding)
  58. Else
  59. 'internal redirect - transfer control to error page
  60. Session("nDisposition")=nDisposition
  61. Session("nResult")=nResult
  62. Session("sErrMsg")=sErrMsg
  63. Server.Transfer("certrser.asp")
  64. End If
  65. End If
  66. ' Set the MIME type of the data we return. We have two options:
  67. '
  68. ' 1) Set the MIME type to x-x509-***-cert. This works great for IE,
  69. ' but causes problems for Netscape because it will automatically
  70. ' try to install the cert
  71. ' 2) Set the MIME type to pkix-cert. This gets rid of the automatic
  72. ' installation issue, but may cause 2003 and greater to grey out the
  73. ' "open" button in the file download dialog.
  74. '
  75. ' Option #1 is implemented here. Option #2 is left commented out, but can
  76. ' easily be substituted
  77. '----------------------------------------------------------------------
  78. ' OPTION #1: set the MIME type to x-x509-***-cert in all cases
  79. '----------------------------------------------------------------------
  80. If "CACert"=Request.QueryString("ReqID") Then
  81. ' Netscape installs this type and does not expect to have a private key
  82. Response.ContentType="application/x-x509-ca-cert"
  83. Else
  84. ' Netscape installs this type and expects to have a private key
  85. Response.ContentType="application/x-x509-user-cert"
  86. End If
  87. '----------------------------------------------------------------------
  88. ' OPTION #2: prevent Netscape from automagically installing the cert,
  89. '----------------------------------------------------------------------
  90. ' so pick MIME type depending upon what we want the browser to do.
  91. 'If "inst"=Request.QueryString("Mode") Then
  92. ' ' We want Netscape to install
  93. ' If "CACert"=Request.QueryString("ReqID") Then
  94. ' ' Netscape installs this type and does not expect to have a private key
  95. ' Response.ContentType="application/x-x509-ca-cert"
  96. ' Else
  97. ' ' Netscape installs this type and expects to have a private key
  98. ' Response.ContentType="application/x-x509-user-cert"
  99. ' End If
  100. '
  101. 'Else
  102. ' ' We don't wan't Netscape to install
  103. ' Response.ContentType="application/pkix-cert" ' Netscape does not install this type
  104. 'End If
  105. ' send the cert to the client
  106. Response.Clear 'guarantee no extraneous bytes
  107. If CR_OUT_BINARY=nEncoding Then
  108. Response.BinaryWrite(sCert)
  109. Else
  110. Response.Write(sCert)
  111. End If
  112. ' ########## END SERVER SIDE EXECUTION ##########
  113. %>