ASP.NET / certificat

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default ASP.NET / certificat

    Hi all

    I'm trying to access to a virtual directory (web server is a IIS 6.0 on
    Windows 2003 server) which requires client
    certificate with HttpWebRequest class.
    Simplified function code looks like this:

    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    httpWebRequest.Method = "POST";
    httpWebRequest.ContentLength = requestData.Length;
    Stream streamWriter = (httpWebRequest.GetRequestStream());
    streamWriter.Write(requestData,0,requestData.Lengt h);
    streamWriter.Flush();
    streamWriter.Close();
    HttpWebResponse httpWebResponse =
    (HttpWebResponse)httpWebRequest.GetResponse();
    StreamReader streamReader = new
    StreamReader(httpWebResponse.GetResponseStream());

    When I tried this function in .NET Windows form
    application (C#) it works OK. But if I try to call the same
    function inside .NET ASP application (IIS 5.1 on Windows XP pro) I get
    Exception "The
    remote server returned an error: (403) Forbidden." when I trying to get
    response
    (line: HttpWebResponse httpWebResponse =
    (HttpWebResponse)httpWebRequest.GetResponse();)

    How can I do to configure my environment to allow ASP.NET application access
    my virtual directory
    Thanks,
    Jerome
    Jerome Guest

  2. #2

    Default Re: ASP.NET / certificat

    This sounds like the standard problem of not being able to access the
    private key for the certificate from the current process. This is probably
    a result of it being installed in the user's certificate store. Have you
    tried installing it in the machine store?

    Joe K.

    "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    news:D0E2FEEA-7724-4A29-B4D9-6186232DD8FE@microsoft.com...
    > Hi all
    >
    > I'm trying to access to a virtual directory (web server is a IIS 6.0 on
    > Windows 2003 server) which requires client
    > certificate with HttpWebRequest class.
    > Simplified function code looks like this:
    >
    > HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    > httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    > httpWebRequest.Method = "POST";
    > httpWebRequest.ContentLength = requestData.Length;
    > Stream streamWriter = (httpWebRequest.GetRequestStream());
    > streamWriter.Write(requestData,0,requestData.Lengt h);
    > streamWriter.Flush();
    > streamWriter.Close();
    > HttpWebResponse httpWebResponse =
    > (HttpWebResponse)httpWebRequest.GetResponse();
    > StreamReader streamReader = new
    > StreamReader(httpWebResponse.GetResponseStream());
    >
    > When I tried this function in .NET Windows form
    > application (C#) it works OK. But if I try to call the same
    > function inside .NET ASP application (IIS 5.1 on Windows XP pro) I get
    > Exception "The
    > remote server returned an error: (403) Forbidden." when I trying to get
    > response
    > (line: HttpWebResponse httpWebResponse =
    > (HttpWebResponse)httpWebRequest.GetResponse();)
    >
    > How can I do to configure my environment to allow ASP.NET application
    > access
    > my virtual directory
    > Thanks,
    > Jerome

    Joe Kaplan \(MVP - ADSI\) Guest

  3. #3

    Default Re: ASP.NET / certificat

    Thanks for your answer

    Yes, the client certificat is install in user's certificate store
    (mmc -> Certificates (local computer) -> Personal -> Certificates)
    Everthing works fine when I use a .NET Windows form application

    a another idea?

    "Joe Kaplan (MVP - ADSI)" wrote:
    > This sounds like the standard problem of not being able to access the
    > private key for the certificate from the current process. This is probably
    > a result of it being installed in the user's certificate store. Have you
    > tried installing it in the machine store?
    >
    > Joe K.
    >
    > "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    > news:D0E2FEEA-7724-4A29-B4D9-6186232DD8FE@microsoft.com...
    > > Hi all
    > >
    > > I'm trying to access to a virtual directory (web server is a IIS 6.0 on
    > > Windows 2003 server) which requires client
    > > certificate with HttpWebRequest class.
    > > Simplified function code looks like this:
    > >
    > > HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    > > httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    > > httpWebRequest.Method = "POST";
    > > httpWebRequest.ContentLength = requestData.Length;
    > > Stream streamWriter = (httpWebRequest.GetRequestStream());
    > > streamWriter.Write(requestData,0,requestData.Lengt h);
    > > streamWriter.Flush();
    > > streamWriter.Close();
    > > HttpWebResponse httpWebResponse =
    > > (HttpWebResponse)httpWebRequest.GetResponse();
    > > StreamReader streamReader = new
    > > StreamReader(httpWebResponse.GetResponseStream());
    > >
    > > When I tried this function in .NET Windows form
    > > application (C#) it works OK. But if I try to call the same
    > > function inside .NET ASP application (IIS 5.1 on Windows XP pro) I get
    > > Exception "The
    > > remote server returned an error: (403) Forbidden." when I trying to get
    > > response
    > > (line: HttpWebResponse httpWebResponse =
    > > (HttpWebResponse)httpWebRequest.GetResponse();)
    > >
    > > How can I do to configure my environment to allow ASP.NET application
    > > access
    > > my virtual directory
    > > Thanks,
    > > Jerome
    >
    >
    >
    Jerome Guest

  4. #4

    Default Re: ASP.NET / certificat

    Right, did you try installing it in the machine store? Under ASP.NET, the
    current user could be either the worker process account or an impersonated
    account (if you are impersonating), but in neither of those cases would the
    user profile be loaded.

    Placing the key in the machine store should allow access to it.

    Joe K.

    "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    news:D905B2EE-0021-4738-B4CF-2D2F5DA66262@microsoft.com...
    > Thanks for your answer
    >
    > Yes, the client certificat is install in user's certificate store
    > (mmc -> Certificates (local computer) -> Personal -> Certificates)
    > Everthing works fine when I use a .NET Windows form application
    >
    > a another idea?
    >
    > "Joe Kaplan (MVP - ADSI)" wrote:
    >
    >> This sounds like the standard problem of not being able to access the
    >> private key for the certificate from the current process. This is
    >> probably
    >> a result of it being installed in the user's certificate store. Have you
    >> tried installing it in the machine store?
    >>
    >> Joe K.
    >>
    >> "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    >> news:D0E2FEEA-7724-4A29-B4D9-6186232DD8FE@microsoft.com...
    >> > Hi all
    >> >
    >> > I'm trying to access to a virtual directory (web server is a IIS 6.0 on
    >> > Windows 2003 server) which requires client
    >> > certificate with HttpWebRequest class.
    >> > Simplified function code looks like this:
    >> >
    >> > HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    >> > httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    >> > httpWebRequest.Method = "POST";
    >> > httpWebRequest.ContentLength = requestData.Length;
    >> > Stream streamWriter = (httpWebRequest.GetRequestStream());
    >> > streamWriter.Write(requestData,0,requestData.Lengt h);
    >> > streamWriter.Flush();
    >> > streamWriter.Close();
    >> > HttpWebResponse httpWebResponse =
    >> > (HttpWebResponse)httpWebRequest.GetResponse();
    >> > StreamReader streamReader = new
    >> > StreamReader(httpWebResponse.GetResponseStream());
    >> >
    >> > When I tried this function in .NET Windows form
    >> > application (C#) it works OK. But if I try to call the same
    >> > function inside .NET ASP application (IIS 5.1 on Windows XP pro) I get
    >> > Exception "The
    >> > remote server returned an error: (403) Forbidden." when I trying to get
    >> > response
    >> > (line: HttpWebResponse httpWebResponse =
    >> > (HttpWebResponse)httpWebRequest.GetResponse();)
    >> >
    >> > How can I do to configure my environment to allow ASP.NET application
    >> > access
    >> > my virtual directory
    >> > Thanks,
    >> > Jerome
    >>
    >>
    >>

    Joe Kaplan \(MVP - ADSI\) Guest

  5. #5

    Default Re: ASP.NET / certificat

    Hi,

    I don't know how to install the key in the machine store...
    Have you got documentations about this ?

    Thanks


    "Joe Kaplan (MVP - ADSI)" wrote:
    > Right, did you try installing it in the machine store? Under ASP.NET, the
    > current user could be either the worker process account or an impersonated
    > account (if you are impersonating), but in neither of those cases would the
    > user profile be loaded.
    >
    > Placing the key in the machine store should allow access to it.
    >
    > Joe K.
    >
    > "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    > news:D905B2EE-0021-4738-B4CF-2D2F5DA66262@microsoft.com...
    > > Thanks for your answer
    > >
    > > Yes, the client certificat is install in user's certificate store
    > > (mmc -> Certificates (local computer) -> Personal -> Certificates)
    > > Everthing works fine when I use a .NET Windows form application
    > >
    > > a another idea?
    > >
    > > "Joe Kaplan (MVP - ADSI)" wrote:
    > >
    > >> This sounds like the standard problem of not being able to access the
    > >> private key for the certificate from the current process. This is
    > >> probably
    > >> a result of it being installed in the user's certificate store. Have you
    > >> tried installing it in the machine store?
    > >>
    > >> Joe K.
    > >>
    > >> "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    > >> news:D0E2FEEA-7724-4A29-B4D9-6186232DD8FE@microsoft.com...
    > >> > Hi all
    > >> >
    > >> > I'm trying to access to a virtual directory (web server is a IIS 6.0 on
    > >> > Windows 2003 server) which requires client
    > >> > certificate with HttpWebRequest class.
    > >> > Simplified function code looks like this:
    > >> >
    > >> > HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    > >> > httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    > >> > httpWebRequest.Method = "POST";
    > >> > httpWebRequest.ContentLength = requestData.Length;
    > >> > Stream streamWriter = (httpWebRequest.GetRequestStream());
    > >> > streamWriter.Write(requestData,0,requestData.Lengt h);
    > >> > streamWriter.Flush();
    > >> > streamWriter.Close();
    > >> > HttpWebResponse httpWebResponse =
    > >> > (HttpWebResponse)httpWebRequest.GetResponse();
    > >> > StreamReader streamReader = new
    > >> > StreamReader(httpWebResponse.GetResponseStream());
    > >> >
    > >> > When I tried this function in .NET Windows form
    > >> > application (C#) it works OK. But if I try to call the same
    > >> > function inside .NET ASP application (IIS 5.1 on Windows XP pro) I get
    > >> > Exception "The
    > >> > remote server returned an error: (403) Forbidden." when I trying to get
    > >> > response
    > >> > (line: HttpWebResponse httpWebResponse =
    > >> > (HttpWebResponse)httpWebRequest.GetResponse();)
    > >> >
    > >> > How can I do to configure my environment to allow ASP.NET application
    > >> > access
    > >> > my virtual directory
    > >> > Thanks,
    > >> > Jerome
    > >>
    > >>
    > >>
    >
    >
    >
    Jerome Guest

  6. #6

    Default Re: ASP.NET / certificat

    I don't have documentation unfortunately. You should be able to do this by
    opening the certificates MMC (start | run | mmc, then choose snap-ins and
    add certificates for the local machine store) and importing the P12 file for
    the certificate and private key into the personal store.

    Perhaps if someone else has done this recently, they can provide more
    details.

    Joe K.

    "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    news:D8800890-C852-43D8-9C25-EF547AA0AA71@microsoft.com...
    > Hi,
    >
    > I don't know how to install the key in the machine store...
    > Have you got documentations about this ?
    >
    > Thanks
    >
    >
    > "Joe Kaplan (MVP - ADSI)" wrote:
    >
    >> Right, did you try installing it in the machine store? Under ASP.NET,
    >> the
    >> current user could be either the worker process account or an
    >> impersonated
    >> account (if you are impersonating), but in neither of those cases would
    >> the
    >> user profile be loaded.
    >>
    >> Placing the key in the machine store should allow access to it.
    >>
    >> Joe K.
    >>
    >> "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    >> news:D905B2EE-0021-4738-B4CF-2D2F5DA66262@microsoft.com...
    >> > Thanks for your answer
    >> >
    >> > Yes, the client certificat is install in user's certificate store
    >> > (mmc -> Certificates (local computer) -> Personal -> Certificates)
    >> > Everthing works fine when I use a .NET Windows form application
    >> >
    >> > a another idea?
    >> >
    >> > "Joe Kaplan (MVP - ADSI)" wrote:
    >> >
    >> >> This sounds like the standard problem of not being able to access the
    >> >> private key for the certificate from the current process. This is
    >> >> probably
    >> >> a result of it being installed in the user's certificate store. Have
    >> >> you
    >> >> tried installing it in the machine store?
    >> >>
    >> >> Joe K.
    >> >>
    >> >> "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    >> >> news:D0E2FEEA-7724-4A29-B4D9-6186232DD8FE@microsoft.com...
    >> >> > Hi all
    >> >> >
    >> >> > I'm trying to access to a virtual directory (web server is a IIS 6.0
    >> >> > on
    >> >> > Windows 2003 server) which requires client
    >> >> > certificate with HttpWebRequest class.
    >> >> > Simplified function code looks like this:
    >> >> >
    >> >> > HttpWebRequest httpWebRequest =
    >> >> > (HttpWebRequest)WebRequest.Create(url);
    >> >> > httpWebRequest.ClientCertificates.Add(X509Certific ate.CreateFromCertFile(@"c:\dada.cer"));
    >> >> > httpWebRequest.Method = "POST";
    >> >> > httpWebRequest.ContentLength = requestData.Length;
    >> >> > Stream streamWriter = (httpWebRequest.GetRequestStream());
    >> >> > streamWriter.Write(requestData,0,requestData.Lengt h);
    >> >> > streamWriter.Flush();
    >> >> > streamWriter.Close();
    >> >> > HttpWebResponse httpWebResponse =
    >> >> > (HttpWebResponse)httpWebRequest.GetResponse();
    >> >> > StreamReader streamReader = new
    >> >> > StreamReader(httpWebResponse.GetResponseStream());
    >> >> >
    >> >> > When I tried this function in .NET Windows form
    >> >> > application (C#) it works OK. But if I try to call the same
    >> >> > function inside .NET ASP application (IIS 5.1 on Windows XP pro) I
    >> >> > get
    >> >> > Exception "The
    >> >> > remote server returned an error: (403) Forbidden." when I trying to
    >> >> > get
    >> >> > response
    >> >> > (line: HttpWebResponse httpWebResponse =
    >> >> > (HttpWebResponse)httpWebRequest.GetResponse();)
    >> >> >
    >> >> > How can I do to configure my environment to allow ASP.NET
    >> >> > application
    >> >> > access
    >> >> > my virtual directory
    >> >> > Thanks,
    >> >> > Jerome
    >> >>
    >> >>
    >> >>
    >>
    >>
    >>

    Joe Kaplan \(MVP - ADSI\) Guest

  7. #7

    Default Re: ASP.NET / certificat

    Yes, I think everything is ok in the machine store.

    But I ask me some question about ASP.NET application access rights

    In the "HttpWebRequest.ClientCertificates Property" page
    ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebrequestclassclientcertificate stopic.asp[/url])
    I can the read the following remarks:
    "...The application must have the same access rigths of the entity that
    issued the certificate"

    The probleme can be cause by ASP.NET application access rights???


    "Joe Kaplan (MVP - ADSI)" wrote:
    > I don't have documentation unfortunately. You should be able to do this by
    > opening the certificates MMC (start | run | mmc, then choose snap-ins and
    > add certificates for the local machine store) and importing the P12 file for
    > the certificate and private key into the personal store.
    >
    > Perhaps if someone else has done this recently, they can provide more
    > details.
    >
    > Joe K.
    >
    > "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    > news:D8800890-C852-43D8-9C25-EF547AA0AA71@microsoft.com...
    > > Hi,
    > >
    .....

    Jerome Guest

  8. #8

    Default Re: ASP.NET / certificat

    Depending on what the current security context is, you would need to make
    sure that you do have access to the private key too. This might be a bit
    hard to debug though. If you think an ACL issue might be the problem, using
    filemon to discover what file is being accessed and then using object access
    auditing in Windows is probably the best way to find out if you are being
    denied access to the private key file.

    Joe K.

    "Jerome" <Jerome@discussions.microsoft.com> wrote in message
    news:840BADCF-366B-4C71-ABCE-4E585D2D7C0B@microsoft.com...
    > Yes, I think everything is ok in the machine store.
    >
    > But I ask me some question about ASP.NET application access rights
    >
    > In the "HttpWebRequest.ClientCertificates Property" page
    > ([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebrequestclassclientcertificate stopic.asp[/url])
    > I can the read the following remarks:
    > "...The application must have the same access rigths of the entity that
    > issued the certificate"
    >
    > The probleme can be cause by ASP.NET application access rights???
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139