Oracle / Sun Java – JRE/JDK Download Using Wget

Oracle / Sun License Agreement

Oracle / Sun License Agreement

Many Linux distributions do not include an easy RPM installation of the office Sun/Oracle Java JDK/JRE requiring users to manually download the rpm from Oracle. Unfortunately, before you download, Oracle requires you to accept their Oracle Binary Code License Agreement for Java SE. Therein presents the problem.

Because most of my Linux servers do not have a X-Windows environment installed, I’m forced to use command line tools: curl or wget. A few text based browsers exist (Lynx, Links), but these are typically not installed by default and often come with their own additional dependencies. I prefer to keep my servers running as minimal as possible. “Less is more…”. In the past, I’ve accepted the license and downloaded via the client and then used SCP to transfer the file. Not ideal… but it works. But let’s see if we can do better.

So we browse to the page on our client workstation with our browser, accept the agreement and notice that the urls for the downloads change: http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz.

PERFECT! Let’s download that:

[user@server ~]# wget http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
--2014-10-14 11:01:45--  http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
Resolving download.oracle.com... 205.213.110.138, 205.213.110.139
Connecting to download.oracle.com|205.213.110.138|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm [following]
--2014-10-14 11:01:45--  https://edelivery.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
Resolving edelivery.oracle.com... 172.226.99.109
Connecting to edelivery.oracle.com|172.226.99.109|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/errors/download-fail-1505220.html [following]
--2014-10-14 11:01:45--  http://download.oracle.com/errors/download-fail-1505220.html
Connecting to download.oracle.com|205.213.110.138|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5307 (5.2K) 
Saving to: jdk-7u67-linux-x64.rpm

100%[==========================================================================================>] 5,307       --.-K/s   in 0s

2014-10-14 11:01:45 (218 MB/s) - jdk-7u67-linux-x64.rpm

It looks like it worked… but if you look closer, you’ll notice that our 100+ MB file is only about 5K in size:

[root@nexus1 t]# ls -la
total 16
drwxr-xr-x. 2 root root 4096 Oct 14 11:01 .
dr-xr-x---. 5 root root 4096 Oct 14 11:01 ..
-rw-r--r--. 1 root root 5307 Mar 20  2012 jdk-7u67-linux-x64.rpm

Viewing the contents of the file, we downloaded an HTML file that includes the following message:

In order to download products from Oracle Technology Network you must agree to the OTN license terms..

*SIGH*. Nothing is ever easy…

Let’s look at the HTML/javascript for that download page and see if we can figure out how it’s working, perhaps reverse engineer it? The interesting piece of code is when the Accept License Agreement button is clicked.

<form name="agreementFormjdk-7u67-oth-JPR" method="post" action="radio" class="lic_form">
  <input type="radio" value="on" name="agreementjdk-7u67-oth-JPR" onclick="acceptAgreement(window.self, 'jdk-7u67-oth-JPR');"> &nbsp;Accept License Agreement&nbsp;&nbsp;&nbsp; 
  <input type="radio" value="on" name="agreementjdk-7u67-oth-JPR" onclick="declineAgreement(window.self, 'jdk-7u67-oth-JPR');" checked="checked"> &nbsp; Decline License Agreement
</form>

A call is made to the acceptAgreement function.

As we wade through the page, which horribly pollutes the global namespace and doesn’t follow any javascript best practices, we come across our function:

// Dynamically generated download page for OTN. 
// Aurelio Garcia-Ribeyro, 2012-05-21, based off of pre-existing code for OTN license acceptance
function acceptAgreement(windowRef, part){
	var doc = windowRef.document;
	disableDownloadAnchors(doc, false, part);
	hideAgreementDiv(doc, part);
	writeSessionCookie( 'oraclelicense', 'accept-securebackup-cookie' );
}

So basically, the download links are using a handler that looks for a cookie called ‘oraclelicense’. That we can work with. We basically need to send that cookie header with our command line request.

Lets try it using wget:

[user@server ~]# wget --header='Cookie: oraclelicense=accept-securebackup-cookie' http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
--2014-10-14 11:12:39--  http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
Resolving download.oracle.com... 205.213.110.138, 205.213.110.139
Connecting to download.oracle.com|205.213.110.138|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm [following]
--2014-10-14 11:12:39--  https://edelivery.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
Resolving edelivery.oracle.com... 172.226.99.109
Connecting to edelivery.oracle.com|172.226.99.109|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm?AuthParam=1413303279_659b15372dcaf37e8073becb5f049d60 [following]
--2014-10-14 11:12:39--  http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm?AuthParam=1413303279_659b15372dcaf37e8073becb5f049d60
Reusing existing connection to download.oracle.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 126857158 (121M) [application/x-redhat-package-manager]
Saving to: jdk-7u67-linux-x64.rpm

100%[==========================================================================================>] 126,857,158 28.1M/s   in 4.4s

2014-10-14 11:12:44 (27.5 MB/s) - jdk-7u67-linux-x64.rpm

SUCCESS!!! We now have the real files, but you could do an MD5 check to verify the contents (if an MD5 file was published…).

For quick reference, the command to set the cookie for the GET operation is:

wget --header='Cookie: oraclelicense=accept-securebackup-cookie' <download url>

1 comment

Leave a Reply

Your email address will not be published.