TL; DR
I get the following error when trying to download a zip file from github using https.request through my company proxy:
An error occurred while trying to download Casper.JS 140735122252160: error: 1408F10B: SSL procedures: SSL3_GET_RECORD: invalid version number: ../ deps / openssl / openssl / ssl / s3_pkt.c: 337:
Additional Information
I am trying to edit the installation of a grunt-casperjs script to allow myself and my colleagues to install behind our proxy server. The script retrieves Casper from Github and loads it. Initially, the script did not support the proxy server, so I copied the grunt-phantomjs proxy support. Phantomjs loads via an http connection, and it works fine through our proxy server (if I change it to https url, it is not with the same error).
I tried to do the following:
- I added https.globalAgent.options.secureProtocol = 'SSLv3_method'; as previously unknown protocol error was shown.
- Using curl, the request fails
- Updated OpenSSL and Node
- I added https.globalAgent.options.secureOptions = 'SSL_OP_NO_TLSv1'; but this causes the node to return without a message after the request.
Reduced Test Case
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method'
var url = require('url');
var downloadUrl = 'https://codeload.github.com/n1k0/casperjs/zip/1.0.3'
var proxy = 'https://username:password@IP:port';
var options = url.parse(proxy);
options.path = downloadUrl;
options.headers = { Host: url.parse(downloadUrl).host }
options.headers['User-Agent'] = 'curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5'
options.headers['Proxy-Authorization'] = 'Basic ' + new Buffer(options.auth).toString('base64');
delete options.auth;
var request = https.get(options, function(response) {
console.log('response received');
}).on('error', function(e) {
console.log('An error occurred whilst trying to download Casper.JS ' + e.message);
});
function downloadZipFromGithub() {
var file = fs.createWriteStream(path.join(tmpPath, "archive.zip"));
var lengthSoFar = 0;
var npmconfDeferred = kew.defer();
npmconf.load(npmconfDeferred.makeNodeResolver());
npmconfDeferred.then(function(conf){
var requestOptions = getRequestOptions(conf.get('https-proxy'));
https.globalAgent.options.secureProtocol = 'SSLv3_method';
var request = https.get(requestOptions, function(response) {
if (response.statusCode === 301 || response.statusCode === 302) {
downloadUrl = response.headers.location;
downloadZipFromGithub();
} else {
response.pipe(file);
response.on('data', function(chunk) {
console.log('Receiving ' + Math.floor((lengthSoFar += chunk.length) / 1024) + 'K...' );
}).
on('end', unzipTheZippedFile).
on('error', function(e) {
console.log('An error occured whilst trying to download Casper.JS ' + e.message);
tidyUp();
});
}
}).on('error', function(e) {
console.log('An error occured whilst trying to download Casper.JS ' + e.message);
tidyUp();
});
});
}
function getRequestOptions(proxyUrl) {
if (proxyUrl) {
var options = url.parse(proxyUrl);
options.path = downloadUrl;
options.headers = { Host: url.parse(downloadUrl).host }
options.headers['User-Agent'] = 'curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5'
if (options.auth) {
options.headers['Proxy-Authorization'] = 'Basic ' + new Buffer(options.auth).toString('base64');
delete options.auth;
}
return options;
} else {
return url.parse(downloadUrl);
}
}