Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

How to perform HTTPS request with no certificate validation

Closed Thread
 
Thread Tools Display Modes
Old 06-30-2008   #1 (permalink)
NickB
Guest


 

How to perform HTTPS request with no certificate validation

Hi

I'm trying to work as a client with an HTTPS server that does not have a
valid certificate.
How can I fetch an HTTPS URL without certificate validation?

What I've tried is:
$wc = new-object system.net.webclient
$wc.Credentials = $nc // NetworkCredentials - previously defined
$wc.DownloadFile($url, "temp.html")

And then I got:

Exception calling "DownloadFile" with "2" argument(s): "The underlying
connecti
on was closed: Could not establish trust relationship for the SSL/TLS secure
ch
annel."

So I read that I might need to set the validation callback of the
ServicePointManager to always return true - but what is the syntax to do
that? Or is there some other way to skip cert validation?

(I'm referring to the folloing callback:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback)

Thanks in advance,
-Nick


Old 06-30-2008   #2 (permalink)
Oisin (x0n) Grehan [MVP]
Guest


 

Re: How to perform HTTPS request with no certificate validation

On Jun 30, 10:23*am, NickB <Ni...@xxxxxx> wrote:
Quote:

> Hi
>
> I'm trying to work as a client with an HTTPS server that does not have a
> valid certificate.
> How can I fetch an HTTPS URL without certificate validation?
>
> What I've tried is:
> $wc = new-object system.net.webclient
> $wc.Credentials = $nc * * * * * // NetworkCredentials - previously defined
> $wc.DownloadFile($url, "temp.html")
>
> And then I got:
>
> Exception calling "DownloadFile" with "2" argument(s): "The underlying
> connecti
> on was closed: Could not establish trust relationship for the SSL/TLS secure
> ch
> annel."
>
> So I read that I might need to set the validation callback of the
> ServicePointManager to always return true - but what is the syntax to do
> that? Or is there some other way to skip cert validation?
>
> (I'm referring to the folloing callback:
> [System.Net.ServicePointManager]::ServerCertificateValidationCallback)
>
> Thanks in advance,
> -Nick
Hi Nick,

Is the certificate expired, or is the certificate DN different from
the network name you're using to access the machine in the script?

If it's the former, you're out of luck with PowerShell 1.0 because you
cannot assign scriptblocks that return a value as event handlers. The
ServerCertificateValidationCallback has a boolean return type, so you
cannot do this with pure script. If on the other hand, the ssl cert is
for www.blah.com (public ip) and you are connecting to blahnetbiosname
(192.168.*) , you could workaround the problem by adding an entry to
your HOSTS file for www.blah.com to resolve to the private ip.

If you are trying to circumvent an expired cert, let us know and I'll
hack something up for you.

- Oisin
- Oisin
Old 06-30-2008   #3 (permalink)
NickB
Guest


 

Re: How to perform HTTPS request with no certificate validation



"Oisin (x0n) Grehan [MVP]" wrote:
Quote:

> On Jun 30, 10:23 am, NickB <Ni...@xxxxxx> wrote:
Quote:

> > Hi
> >
> > I'm trying to work as a client with an HTTPS server that does not have a
> > valid certificate.
> > How can I fetch an HTTPS URL without certificate validation?
> >
> > What I've tried is:
> > $wc = new-object system.net.webclient
> > $wc.Credentials = $nc // NetworkCredentials - previously defined
> > $wc.DownloadFile($url, "temp.html")
> >
> > And then I got:
> >
> > Exception calling "DownloadFile" with "2" argument(s): "The underlying
> > connecti
> > on was closed: Could not establish trust relationship for the SSL/TLS secure
> > ch
> > annel."
> >
> > So I read that I might need to set the validation callback of the
> > ServicePointManager to always return true - but what is the syntax to do
> > that? Or is there some other way to skip cert validation?
> >
> > (I'm referring to the folloing callback:
> > [System.Net.ServicePointManager]::ServerCertificateValidationCallback)
> >
> > Thanks in advance,
> > -Nick
>
> Hi Nick,
>
> Is the certificate expired, or is the certificate DN different from
> the network name you're using to access the machine in the script?
>
> If it's the former, you're out of luck with PowerShell 1.0 because you
> cannot assign scriptblocks that return a value as event handlers. The
> ServerCertificateValidationCallback has a boolean return type, so you
> cannot do this with pure script. If on the other hand, the ssl cert is
> for www.blah.com (public ip) and you are connecting to blahnetbiosname
> (192.168.*) , you could workaround the problem by adding an entry to
> your HOSTS file for www.blah.com to resolve to the private ip.
>
> If you are trying to circumvent an expired cert, let us know and I'll
> hack something up for you.
>
> - Oisin
> - Oisin
>
It seems that the certificate has expired, and also the CA is not trusted
(at least by my web browser). I'm not sure what the status of PowerShell 2.0
is but I'm willing to give it a try if I can override the callback there.
If not I'll just write a small program that downloads a file and execute it
from PowerShell.

Thanks a lot
-Nick
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
certificate request Error: 0x80070005 florina Network & Internet 6 2 Weeks Ago 02:19 AM
Unable to request a Thawte Freemail X.509 certificate B.J.M. Segond von Banchet Vista security 5 05-22-2008 12:52 PM
certificate signing request Neil Chambers PowerShell 1 04-20-2007 06:22 AM
Request Certificate with MMC fails ACA Vista security 3 03-09-2007 11:56 AM
How to perform an http get request from a browser hosted applicati Jens Avalon 1 04-07-2006 09:17 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

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