TWAPI TCL The target principal name is incorrect - windows

I have a file on a server and I am trying to read it.
My code is as follows:
package require http
package require twapi_crypto
http::register https 443 [list ::twapi::tls_socket]
set token [http::geturl "https://$ipaddress/filename"]
set status [http::status $token]
set data [http::data $token]
put $data
and I get the following error:
The target principal name is incorrect
while executing
"InitializeSecurityContext $Credentials $Handle $Target $Inattr 0 $Datarep $inbuflist 0"
(procedure "sspi_step" line 16)
invoked from within
"sspi_step $SpiContext $data"
(procedure "_negotiate2" line 19)
invoked from within
"_negotiate2 $chan"
(procedure "rethrow" line 2)
invoked from within
"rethrow"
invoked from within
"trap {
_negotiate2 $chan
} onerror {} {
variable channels
if {[info exists _channels($chan)]} {
dict set _chan..."
(procedure "_negotiate line 3)
invoked from within
"_negotiate $chan"
(procedure "::twapi::tls::_so_write_andler" line12)
invoked from within
"::twapi::tls::_so_write_handle rc0"
Can somebody redirect me here where the issue is? I get warning from IE when I am trying to access the file and have to click continue even though I have added the certificate to the browser, This is running on a windows machine.

I'm guessing that the subject Common Name on the certificate isn't matching the IP address you're passing in, which is to be expected. You have to use the host name when opening an HTTPS connection.
# Use the right hostname of course
set hostname "securetesting.example.com"
set token [http::geturl "https://$hostname/filename"]
This because that name is used to determine whether the server that you've connected to is the one that you've asked to connect to. Without that, it could be a secure connection to absolutely anyone and that's not a useful kind of security! Yes, this means that you need to spend some time getting DNS right as part of deploying, and yes, this is a bit of a pain. Security usually is.
Interestingly, you should also give the hostname properly even with plain unencrypted HTTP as servers can host multiple sites. The only time you get away with it is when talking unencrypted to a server that only serves up a single site; the web hasn't really worked that way for many years.

Related

Typo3 behind Proxy

I'm trying to get a Typo3 (6.2) instance running behind a (forwarding) proxy (squid). I have set
'HTTP' => array(
'adapter' => 'curl',
'proxy_host' => 'my.local.proxy.ip',
'proxy_port' => '8080',
)
as well as
'SYS' => array(
'curlProxyServer' => 'http://my.local.proxy.ip:8080',
'curlUse' => '1'
)
The proxy doesn't ask for credentials.
When I try to update the extension list, I get the error message
Update Extension List
Could not access remote resource http://repositories.typo3.org/mirrors.xml.gz.
If I try Get preconfigured distribution, it says
1342635425
Could not access remote resource http://repositories.typo3.org/mirrors.xml.gz.
According to the proxy log, the server doesn't even try to connect to the proxy.
I can easily download the file using wget on the command line.
Ok, I've investigated he issue a bit more and from what I can tell, the Typo3 doesn't even try to connect anywhere.
I used tcpdump and wireshark to analyze the network traffic. The site claims to have tried sending a http-Request to repositories.typo3.org so I'd expect to find either a proxy connection attempt or a DNS query followed by an attempt to connect to that IP. (Of course, the latter is known not to work.) However, none of this happens.
I've tried some slight changes in the variable curlProxyServer. The documentation clearly states
String: Proxyserver as http://proxy:port/. Deprecated since 4.6 - will be removed in TYPO3 CMS 7. See below for http options.
So I tried adding the trailing "/" and removing the "http://" - no change. I'm confident there's no problem whatsoever regarding the proxy as the proxy isn't even contacted and has been working perfectly fine for everything else for years.
The error message comes from \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::fetchFile(). This one uses \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl() to get the actual file content.
According to your setting, it should use the first part of the function, because curlUse is set and the URL starts with http or https.
So what you would need to do now is to throw some debug lines in the code and check at what point the request goes wrong.
Look at the source code, three possibilities come to mind:
The curl proxy parameters does not support a scheme, thus it should be 'curlProxyServer' => 'my.local.proxy.ip:8080',.
Some redirect does not work.
Your proxy has problems with https, because the TYPO3 TER should be queried over https.

Windows HTTP server API, UrlPrefix failing with Error 5, on HttpAddUrl

Good afternoon,
I'm following the example on Windows Http Server Api, found here:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx
I get my project to compile and work when I enter http://localhost:8080/test as the URl into HttpAddUrl function, and point my browser to http://localhost:8080/test on the same machine as I run the http server in the above example.
The webpage shows the response and everything works well.
here is my call to HttpAddUrl
retCode = HttpAddUrl(
hReqQueue, // Req Queue
L"http://localhost:8080/test/", // Fully qualified URL
NULL // Reserved
);
My problem, however is sending the request from another machine on the same LAN.
I tried pointing the browser to http://192.168.1.2:8080/test/ but I got a 404 error,
Then I tried changing the HttpAddUrl function to
retCode = HttpAddUrl(
hReqQueue, // Req Queue
L"http://192.168.1.2:8080/test/", // Fully qualified URL
NULL // Reserved
)
This only returned retCode = 5 (which I also cannot determine the meaning of, if somebody can help me determine the enumeration for this error variable)
Does anybody know what I am supposed to enter into the HttpAddUrl function if I want to sen an HTTP request from another machine to the local server.
Thanks,
-D
Resolved, it turns out I was not running Visual Studio with Admin privileges, error 5 was system error "Access Denied"
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
The URL of L"http://192.168.1.2:8080/test/" was corrent

How can I rewrite URLs in the Zeus web server for Mobile useragent?

I need to redirect anyone with a mobile user agent to a file called mobile.php.
My web hosting provider, Net Registry uses the Zeus web server.
Here's the script I've written from my research
RULE_1_START:
# get the document root
map path into SCRATCH:DOCROOT from /
match IN:User-Agent into $ with iPad|iPod|iPhone|Android|s+Mobile
if matched then
set OUT:Location = /mobile.php
endif
RULE_1_END:
I used the instructions on my host's site.
I pasted that into their console and it has worked to do redirects. Net registry have some odd console thing that you submit and it takes 10 minutes to update the zeus server config (annoying as hell).
Anyway my issue is that it redirects me to the wrong location:
So if you visit the site, with a user agent string that contains ipad|ipod|android|\s+mobile then you will trigger it ()
It takes me here:
http://example.com.au/mobile.php,%20catalog/index.php
I can't work out how to fix that, or why that happens because at the moment this file exists:
http://example.com.au/mobile.php
as does this one:
http://example.com.au/index.php. Contents of this file are:
<?php header("Location: catalog/index.php");
Any ideas on how I can make this work more like an apache .htaccess url Rewrite?
the official Zeus documentation
Fixed it by changing
set OUT:Location = /mobile.php
to
set URL = /mobile.php
From the manual...
Using Request Rewrite Scripts
To use the request rewriting functionality, create a script in the Zeus Request
Rewrite Scripting Language. The script contains instructions telling the
Virtual Server how to change the URL or headers of requests that match specified criteria.
The Virtual Server compiles the script, and (if the rewrite functionality is
enabled) uses it every time it receives a request. It runs the commands in the
script, changing the URL if it matches the specified criteria. Once the script is
finished, the Virtual Server continues processing the resulting URL.Zeus Web Server 4.3 User Guide
142 Configuring URL Handling
When changing the URL, the rewrite functionality can only change the local
part of it, that is, the part of the URL after the host name. For example, if a
user requests http://www.myhost.com/sales/uk.html, the rewrite
functionality can only make changes to /sales/uk.html. This means that
you cannot use the rewrite functionality to change the request to refer to a
file on another Virtual Server.
For example, the following script illustrates how to change requests for any
HTML files in the /sales directory so that the user receives them from the
/newsales directory instead:
match URL into $ with ^/sales/(.).html
if matched set URL=/newsales/$1.html
The rewrite functionality can also change the HTTP headers that were received
with a request, and create new HTTP headers to be returned to the user. For
example, the following script changes the HTTP host header, so that a request
for www.mysite.com/subserver is redirected to the Subserver
www.subserver.mysite.com:
match URL into $ with ^/([^/]+)/(.)$
if matched then
set IN:Host = www.$1.mysite.com
set URL = /$2
endif

What's the cgi-bin equivalent of getRequestDispatcher("/myURL").forward(request, response)?

I'm using #!/bin/sh as my language.
Doing a redirect would be easy. Just return the right HTTP header like:
Location: http://www.w3.org/pub/WWW/People.html
The problem is that the user will see the URL change in their browser.
Technically "forward" is a internal redirect which is normally supported by your "framework" (ie the Servlet API that you specified). I guess to get an "internal forward" to work in #!/bin/sh you would need to do something like this (psuedocode)
# before i've printed anything to the output
if "should i forward"
my_other_cgi_page.sh
exit
fi
I guess just call that like
myURL
because all CGI data will be in the environment variables (not sure about POST request though)

How do I find out what my external IP address is?

My computers are sitting behind a router/firewall. How do I programmatically find out what my external IP address is. I can use http://www.whatsmyip.org/ for ad-hoc queries, but the TOS don't allow for automated checks.
Any ideas?
http://ipecho.net/plain appears to be a
workable alternative, as whatismyip.com now requires membership for
their automated link. They very kindly appear to be
offering this service for free,
so please don't abuse it.
Unfortunately there is no easy way to do it.
I would use a site like www.whatsmyip.org and parse the output.
checkip.dyndns.com returns a very simple HTML file which looks like this:
<html>
<head>
<title>Current IP Check</title>
</head>
<body>
Current IP Address: 84.151.156.163
</body>
</html>
This should be very easy to parse.
Moreover the site is exists for about ten years.
There is hope that it will be around for a while.
If you have access to a webserver with modphp, you can roll your own:
<?php print $_SERVER['REMOTE_ADDR']; ?>
If you don't want that to get abused, you'll have to keep it secret or add request limits.
I've been using one on my server for years.
Explicitly:
Create a file called whatismyip.php in your public_html folder in your website. It can be called anything and be anywhere in your webroot.
Add the line above, and then query your server:
curl http://example.com/whatismyip.php
for example.
Unfortunately as of 2013, whatismyip.com charge for the service.
http://www.icanhazip.com is still going strong, 3 years later. Just outputs the IP as text, absolutely nothing else.
http://checkip.dyndns.org still works as well.
You can also use Google if you want to be sure it won't go down, but it can still block you for TOS violations.
https://www.google.ie/search?q=whats+is+my+ip
But even when they block me, they still tell me my client IP address in the error message.
curl ifconfig.me
or
curl ifconfig.me/ip
Incase you don't have curl installed,
wget ifconfig.me/ip 2>/dev/null && cat ip
Hope this helps.
If the router you are behind speak UPnP you could always use a UPnP library for whatever language you are developing in to query the router for its external ip.
http://myexternalip.com provides this kind of information. To
retrieve your IP you have plenty of options:
http://myexternalip.com/ - browser + lot's of examples of how to use it
http://myexternalip.com/raw - a pure text answer, only your ip, no other crap
http://myexternalip.com/json - a resposnse ready for json-parsers, also supports jsonp
HEAD http://myexternalip.com - send only a HEAD-request and get the answer
Since this question was asked a while back, there's now a freely available web service designed specifically to allow you to determine your IP address programmatically, called ipify.
$ curl 'https://api.ipify.org?format=json'
Results in
{"ip": "1.2.3.4" /* your public IP */}
Another way is if you have access to a cloud email (yahoo, google, hotmail), send yourself an email. Then view the headers and you should see your IP address in there.
I would look up the exact area but the headers may vary from each implmentation, Look for the received-by and follow that until you get to something that looks like sent-by
EDIT: This answers the how to find IP address, not the via PROGRAMMATIC approach
My WRT54G router tells me through its Local Router Access feature (the http(s) administration interface), and I imagine something similar could be done with many other devices. In this case, the entry page gives the octets of the IPv4 address in four lines containing this phrase:
class=num maxLength=3 size=3 value='i' name='wan_ipaddr_N' id='wan_ipaddr_N'
Where i is the octet value and N is the octet number. This bit of doggerel fetches and parses it for me, courtesy of cygwin:
#! /usr/bin/env perl
use strict;
use warnings 'all';
my( $account, $password ) = #ARGV;
open QUERY,
"curl --sslv3 --user '$account:$password' https://Linksys/ --silent |"
or die "Failed to connect to router";
my #ipaddr = ('x','x','x','x');
while( <QUERY> ) {
$ipaddr[$2] = $1 if /value='(\d+)' name='wan_ipaddr_([0-3])/;
}
close QUERY;
print join('.', #ipaddr);
There is no guarantee that this will work with all versions of the router firmware.
If your router is set to use http for this interface, drop the --sslv3 curl option, and you can use dotted-decimal notation to address the router. To use https with the curl options above, I also did this:
Used a browser to fetch the router's self-signed certificate (saved as Linksys.crt).
Added it to my CA bundle:
openssl x509 -in Linksys.crt -text >> /usr/ssl/certs/ca-bundle.crt
Added 'Linksys' to my hosts file (C:\Windows\System32\Drivers\etc\HOSTS on my Win8 box), as an alias for the router's address. If the dotted-decimal notation is given to curl instead of this alias, it rejects the connection on account of a certificate subject name mismatch.
Alternatively, you could just use the --insecure option to bypass certificate verification, which probably makes more sense in the circumstances.
whatismyip.com or ipchicken.com are very easy to parse.
If you have a webhost or vps you can also determine it, without fear of it randomly going down leaving you stuck.
ifcfg.me
allows Lookup via
nslookup
telnet
ftp
and http
even works with IPv6
Simple but not elegant for this use. I created a VBS file with the following code to drop the result to dropbox and google drive ... have to delete the file for new one to sync though for some reason.
This runs on a PC at my home. My PC is set to resume on power outage and a task is scheduled to run this every day once (note if you have it run often, the site will block your requests).
Now I can get my IP address on the road and watch people steal my stuff :-)
get_html "http://ipecho.net/plain", "C:\Users\joe\Google Drive\IP.html"
get_html "http://ipecho.net/plain", "C:\Users\joe\Dropbox\IP.html"
sub get_html (up_http, down_http)
dim xmlhttp : set xmlhttp = createobject("msxml2.xmlhttp.3.0")
xmlhttp.open "get", up_http, false
xmlhttp.send
dim fso : set fso = createobject ("scripting.filesystemobject")
dim newfile : set newfile = fso.createtextfile(down_http, true)
newfile.write (xmlhttp.responseText)
newfile.close
set newfile = nothing
set xmlhttp = nothing
end sub

Resources