outmoded / university

Community learning experiment
Other
371 stars 194 forks source link

Static Assets, Partials, and TLS #144

Closed zoe-1 closed 9 years ago

zoe-1 commented 9 years ago

Static Assets, Partials, and TLS

Configure the application to use TLS/SSL

Configure the application to always use TLS Transport Layer Security.
Every http request should be redirected to https. Two references:

Original due date was June 6, 2015.

Next After This Assignment

zoe-1 commented 9 years ago

Promote hapijs / university on Twitter

Make tweets promoting hapijs / university with the @hapijs tag in the tweet.
Then, @hueniverse can retweet them and get the word out. I will promote too, my twitter account is jswenson74.

Cheers!

ghost commented 9 years ago

One question : on the home page , do we still have to display the path ?

zoe-1 commented 9 years ago

@roelof1967 The path in the home page should be removed. Forgot to mention that. Thanks.

zoe-1 commented 9 years ago

Tips for Assignment6

/*
 * Redirect everything to tls
 */
server.ext('onRequest', function (request, reply) {

    if (request.connection.info.protocol === 'http') {
        return reply.redirect('https://localhost:8001' + request.url.path).code(301);
    }

    return reply.continue();
});
var Config = require('./config/config.js');
/*
 *  Important part of manifest JSON declaration for web-tls
 */
 "connections": [
      {
          port: 8000,
          labels: ['web']
      },
      {
          host: 'localhost',
          port: 8001,
          labels: ['web-tls'],
          tls: Config.tls
      }
  ],
//
//  config.js  Used above in the manifest. 
//
var fs = require('fs');
var config = module.exports = {};

//  tls Trasport Layer Security (tls)
config.tls = {
    key: fs.readFileSync('./lib/config/certs/server.key'),     // Path to key
    cert: fs.readFileSync('./lib/config/certs/server.crt'),      // Path to Certificate

    // This is necessary only if using the client certificate authentication.
    requestCert: true,

    // This is necessary only if the client uses the self-signed certificate.
    ca: []
};
In assignment, forgot to mention that you can make a config.js file to use for loading tis certs

Above is to illustrate this.


//
//  How to test on tls connection
//
it('GET request should respond properly.', function(done){

        University.init(0, function(err, server){

            expect(server.info.port).to.be.above(0);

            // IMPORTANT   this is how to inject into tis connection avoiding the redirect.
            var tlserver = server.select('web-tls');

            tlserver.inject({url: '/home', method: 'GET' }, function (response) {

                expect(response.statusCode).to.equal(200);
                server.stop(done);
            });
        });
});
ghost commented 9 years ago

I get a error message cannot call method of "replace" on udefined on the above test. Anyone who knows a good tutorial for making the certificates. I only get a perm file instead of the key and crt file

zoe-1 commented 9 years ago

@roelof1967 links to tutorials below: openssl-essentials Heroku Tutorial Generate Self Signed Cert Another Tutorial Ubuntu http://en.wikipedia.org/wiki/Self-signed_certificate

hussainanjar commented 9 years ago

@zoe-1 you said moving manifest in an external file is a good idea, why didn't we do it then ?

hussainanjar commented 9 years ago

@zoe-1 in the assignment you have asked to keep certs under lib/certs while in the example above shared, it is pointing to lib/config/certs which path is the requirement of this assignment, I think the first one makes more sense.

hussainanjar commented 9 years ago

One more problem after pulling in the laster master its not running getting following error when I run node start

module.js:338
    throw err;
          ^
Error: Cannot find module '/Users/hussainanjar/workspace/personal/university/start'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
zoe-1 commented 9 years ago

@hussainanjar

hussainanjar commented 9 years ago

@zoe-1 thanks :)

AdriVanHoudt commented 9 years ago

another tutorial to make the certificates http://www.akadia.com/services/ssh_test_certificate.html

zoe-1 commented 9 years ago

In order to give people more time to submit PRs, extending assignment6 due date until: June 12, 2015. Received two requests to slow things down a bit. Hopefully, this extension will give others space to complete the assignments.

Please share feed back on the pace of assignments, difficulty, etc...

zoe-1 commented 9 years ago

Critique of Assignment6 PRs.

I want to close this assignment and merge in a PR, however, all the PRs have some issues to fix before any can be merged. See comments below and the comments made in your projects. I reviewed all of them.

server.select('web').ext('onRequest', function (request, reply) {

    return reply.redirect('https://localhost:8001' + request.url.path).permanent();
});

Tip: Write out your question and comments relating to problems you are trying to solve before posting them. As you type the comment, question, or problem to post it will cause you to define the problem and find the vocabulary to articulate it. This will create clarity and often results in you finding the solution before you post anything.

AdriVanHoudt commented 9 years ago

Nice feedback, although it might be more usefull to test soms random urls to see if they redirect to https, that wat you can be even more sure that all URLs are forwarded and not just the ones we have now, doing this for every route seems redundant, the point of being more protective I fully support though

zoe-1 commented 9 years ago

@AdriVanHoudt Good to have you back making comments again :-)

AdriVanHoudt commented 9 years ago

I only have time for some comments I'm afraid ^^