Re: PKCS7 renewal request

From: Byron (Byron_at_discussions.microsoft.com)
Date: 09/19/05


Date: Mon, 19 Sep 2005 12:11:15 -0700

Sorry I forgot to post the code...

<%' makeCert.asp - make cert in batch mode
<!-- #include FILE="makeCertCnfTest.inc" -->

<%

'********************************************************************************

Dim agent
agent = Request("agent")
response.Write("Agent: " & agent & "; ")

Dim CertEnroll, CertRequest, CACert
Set CertEnroll = CreateObject( "CEnroll.CEnroll" )

on error resume next
' Finally Create the request
Dim RequestStr, Disposition, ID, Name

set name = Request("name")

        const CRYPT_EXPORTABLE = 1
        CertEnroll.GenKeyFlags = CRYPT_EXPORTABLE
        RequestStr = CertEnroll.createRequest( XECR_CMC, name, "1.3.6.1.5.5.7.3.2")
                
        Dim flags
        flags = CertEnroll.KeySpec
if Err.Number <> 0 then
        response.Write("Certificate: Error, " & Err.number &", "&Err.Description &
"; ")
        response.End
end if

'*************************************************************************************************
' Submit the request

Set CertRequest = CreateObject( "CertificateAuthority.Request" )
Disposition = CertRequest.Submit(CR_IN_ENCODEANY Or CR_IN_FORMATANY,
RequestStr, "", StrCAConfig )
ID = CertRequest.GetRequestId
'*************************************************************************************************
' get the cert
If Disposition = CR_DISP_ISSUED Then
    Dim Cert
    Cert = CertRequest.GetFullResponseProperty( FR_PROP_FULLRESPONSE, 0,
PROPTYPE_BINARY, CR_OUT_BASE64 )
    CertEnroll.acceptResponse Cert
    response.Write("Certificate: Ok " & "; ")
Else
        response.Write("Certificate: Error, " & Err.Description & "; ")
        response.End
End If

'*************************************************************************************************
'get the pfx in a File
        Err.Clear
        
        dim Path, binData, currDate, strDat
        currDate = Now
        strDat = DatePart("M",currDate) & DatePart("D",currDate) &
DatePart("YYYY",currDate) & _
                         DatePart("H",currDate) & DatePart("N",currDate) & DatePart("S",currDate)
        
        Path = PfxRepository + agent + strDat + ".pfx"
        
        
        CertEnroll.createFilePFX CAPsw, Path
        
        Dim fs
        Set fs = CreateObject("CFS.AuxCert")
        
        binData = fs.SerializeAsHexaString(Path)
        
        if Err.number <> 0 then
                Response.Write("P12 Error " & Err.number & ": " & Err.Description & "; ")
        else
                Response.Write("P12 Ok; ")
        end if
'*************************************************************************************************
'get the expiration Date
        Err.Clear
        
        Dim varDat
        varDat = fs.getExpirationDate(Path, CAPsw,"-")
        if Err.number <> 0 then
                Response.Write("Date Error " & Err.number & ": " & Err.Description & "; ")
        else
                Response.Write("Date Ok; ")
        end if
        
        
'*************************************************************************************************
'DB2 Connection

    Dim Con, Com, Rs, Ret
    Dim PKCEXD, PKAGID, PKP12, PKCB64

    PKCEXD = varDat
    PKAGID = Request("agent")
    PKIDAG = Request("agentID")
    PKTPAG = Request("agentType")
    PKP12 = binData
    PKCB64 = Cert
    
    Err.Clear
        
    
    
    set Con = Server.CreateObject("ADODB.Connection")
    Con.Open ConStr, User, Pasword
   
    Set Com = Server.CreateObject("ADODB.Command")
    Set Com.ActiveConnection = Con

    Com.CommandText = "UPDATE NEWBUS.PKI SET PKCB64='" & PKCB64 & "',
PKCEXD='" & PKCEXD & "', PKP12='" & PKP12 & "' WHERE PKAGID='" & PKAGID & "'"
    Com.Execute Ret
        If Ret <> 0 then
                response.Write("DB: Update Ok " & "; ")
        else
        Com.CommandText = "INSERT INTO NEWBUS.PKI (PKAGID, PKCB64, PKCEXD,
PKP12, PKIDAG, PKTPAG) VALUES ('" & PKAGID & "', '" & PKCB64 & "', '" &
PKCEXD & "', '" & PKP12 & "', '" & PKIDAG & "', '" & PKTPAG & "')"
        Com.Execute Ret
            If Ret = 0 Then
                        response.Write("DB: Error " & "; ")
                else
                        response.Write("DB: Insert Ok " & "; ")
                        
                End If
        end If
        if Err.number <> 0 then
                response.Write("DB: Error " & Err.Description & "; ")
        end if
                
    Con.Close
    
%>

"Strohm Armstrong" wrote:

> Have you looked at
> http://msdn.microsoft.com/security/default.aspx?pull=/library/en-us/dncapi/html/certenrollment.asp#certenroll_topic8
>
> It looks like you have most everything except for the call to
> put_RenewalCertificate. I assume you called CertGetCertificateContextProperty
> a second time to actually get the provider information, event though its not
> in your example code.
>
>
> "crypton" wrote:
>
> > I was not able to create a renewal request with the above code. The
> > code still fails in createRequest.
> >
> > There is almost no documentation available for creating a pkcs7 renewal
> > request.
> >
> >



Relevant Pages

  • Re: Unable to install Godaddy cert on SBS R2 Standard box
    ... I recently bought a ten year Turbo SSL cert, but I want to rebuild my server ... "Please create a new request,and request for a new certificate from ... Godaddy(issue a new certificate),then install the new certificate. ...
    (microsoft.public.windows.server.sbs)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... MsgBox "Required fields for this form are: Request ID, Date, Name, ...
    (microsoft.public.access.formscoding)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... MsgBox "Required fields for this form are: Request ID, Date, Name, ...
    (microsoft.public.access.formscoding)
  • Re: how can I change this get code to post code
    ... In a get I didn't write anything but in a post I have to so that is why the streamwriter is required. ... Now when we run rep=req.getresponsethe postdata that was put in the web request req is now being sent to the jsp page and it's reply is being stored in rep. ... dim strcontent as string ... Dim strContent As String ...
    (microsoft.public.dotnet.languages.vb)
  • Active Directory Error - The server is unwilling to process the request
    ... The server is unwilling to process the request ... The code below determines the location of the schema, ... Dim oConn 'As ADODB.Connection ...
    (microsoft.public.dotnet.general)