lundi 26 novembre 2018

Node JS TLS server and client aren’t working correctly

Recently I’ve been trying to make a basic TLC server and client to maybe put on a Rasperry PI. I found an example on github and i modified it so its up to date. My issue is that Node JS keeps saying unable to verify the first certificate Even though i generated a new one.

note the certificates and keys are self signed.

Here is my code, I have not the slightest clue as to why its failing because when I set ServerOptions As the client options, it just logs Unsecure connection.

Server.js

'use strict';

const tls = require('tls');
const fs = require('fs');
const util = require('util');
const events = require('events');
const port = 4170;

const ServerOptions = {
    key: fs.readFileSync('agent1-key.pem'),
    cert: fs.readFileSync('agent1-cert.pem'),
    ca: fs.readFileSync('root-cert.pem'), // authority chain for the clients
    requestCert: true,
    rejectUnauthorized: false
};

var server = tls.createServer(ServerOptions, (socket) => {
  socket.write('welcome!\n');
  socket.setEncoding('utf8');
  socket.pipe(socket);
})

.on('connection', function(c) {
    console.log('Unsecure connection');
})

.on('secureConnect', function (c) {
    // c.authorized will be true if the client cert presented validates with our CA
    console.log('secure connection\n client authorization Status:', c);
})

.listen(port, function() {
    console.log('server listening on port' + port + '\n');
});`

Client.js

const tls = require('tls');
const fs = require('fs');
const util = require('util');
const events = require('events');
const port = 4170;

const ClientOptions = {
  key: fs.readFileSync('agent2-key.pem'),
  cert: fs.readFileSync('agent2-cert.pem'),
  ca: fs.readFileSync('root-cert.pem')
};

const socket = tls.connect(port, ClientOptions, () => {
      console.log('client connected', socket.authorized ? 'authorized' : 'unauthorized');
      process.stdin.pipe(socket);
      process.stdin.resume();
    });
    socket.setEncoding('utf8');
    socket.on('data', (data) => {
      console.log(data);
    });
    socket.on('end', () => {
      server.close();
    });

So as you probably saw, there is the ca1-cert.pem, agent1-cert.pem, agent2-cert.pem, agent1-key.pem, and agent2-key.pem. Those are the certificates.

Each of the cert files have the beginning and ending

-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

And each of the key files have the beginning and ending

-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----

In addition to that, I’m wondering how secure this is because my initial plan is to use this as a login/database server or something that cant be easily hacked into.

Thank you.




can you help me fix this css bug?

i have this problem with my css for a web i started for fun, thething is that when ever i set the position of the nav-bar to fixed.everything just goes crazy.if someone knows a solution to this.i would really appreciate it if you would help.Thank you.




How to fill an image inside an article tag

Hello there you programmers, i have a problem with make that picture fill that box or center it inside the box, like what you see here the pictures doesn't appear completely inside the box there is just a little area from it, here is the image, the code line and the output, i hope someone helps me to do that and thanks before all. The images are in the link below "i can't add them here because i didn't have yet 10 reputation" https://www.mediafire.com/file/urd6g5r7xdbxy7v/Screenshoots.zip/file




HTML-Form to Database using PHP

I've been trying to connect this HTML-Form with my MySql-Database so I can get messages sent to me from my website. But I keep Getting this message:

"The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. "

I've tried many different things from other people who had the same problem but it didn't seem to work for me.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
        <meta content="utf-8" http-equiv="encoding">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="js/jquery.js"></script>
        <link rel="stylesheet" href='https://fonts.googleapis.com/css?family=ABeeZee'>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="js/navshrink.js"></script>
        <link rel="stylesheet" type="text/css" href="css/contact.css">
    </head>



 <div class="contactCon">
       <form class="contactForm" action="contactForm.php" method="post" enctype="application/x-www-form-urlencoded">
          <ul class="flex-container">
             <li class="flex-item">
                <ul class="flex-container2">
                    <li class="flex-item2">enter code here
                        <label for="fname">First Name:</label>
                        <input type="text" id="fname" name="firstname" placeholder="Your First Name..">
                    </li>
                    <li class="flex-item2">
                        <label for="lname">Last Name:</label>
                        <input type="text" id="lname" name="lastname" placeholder="Your Last Name..">
                    </li>
                    <li class="flex-item2">
                        <label for="email">E-mail:</label>
                        <input type="text" id="email" name="email" placeholder="Your E-mail..">
                    </li>
                </ul>
                <li class="flex-item">
                    <label id="subject-label" for="subject">Subject:</label>
                    <textarea type="text" id="subject" name="message" placeholder="Write Me Something.."></textarea>
                    <input id="submit-button" type="submit" value="Submit">
                </li>
             </li>
          </ul>
       </form>
    </div>

And here is my PHP-code for the form:

<?php
  // Create Variables for Database Information
  $host = 'xxxxxx';
  $userName = 'xxxxxxx';
  $dbPassword = 'xxxxxx';
  $dbName = 'xxxxxxxx';

  // Create Connection to the Database
  $con = mysqli_connect($host,$userName,$dbPassword,$dbName);

  // Check connection
  if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
    // Create Variables for every Input
    $firstname = mysqli_real_escape_string($con, $_POST['firstname']);
    $lastname = mysqli_real_escape_string($con, $_POST['lastname']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $message = mysqli_real_escape_string($con, $_POST['message']);



    // Insert Input into the Database
    $sql = "INSERT INTO contactMe(firstname, lastname, email, message)
      VALUES ('$firstname','$lastname','$email','$message')";

    // Check for Errors
    if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    // Close Connection
    mysqli_close($con);
?>

Thanks in advance.




what i need to built web site with this futures https://ift.tt/17tpUS0?

i want to built a web with this service what can you help me please how can i built this one and what i need for ?




i need to sort array of objects in **Vue** with to attributes of the object but **Vue** go in infinite loop to sorting

vue js sort array of object with attribute and try to sort that sorted array with another attribute but Vue go in infinite loop of sorting

   chatRoomArraySorted: function(){
    console.log("func name chatRoomArraySorted");

           function compare(a, b) {
            if (a.name < b.name)
              return -1;
            if (a.name > b.name)
              return 1;
            return 0;
          }

  return this.chatRoomsArray.sort(compare);

  }
   sortedArray: function() {
    this.log("sortedArray");
    function compare1(a, b) {
     return new Date(b.lastMsg.createdAt) - new Date(a.lastMsg.createdAt);
    }

    return this.chatRoomsArray.sort(compare1);
  },




Forbid javascript in a div

At the moment I am working on a website. Inside this website administrators shall be able to post text.

I´d like to give the user a possibility to use HTML-Code, but I do not want them to be able to post javascript code.

Is there an html-Tag (or workaround) to prohibit javascript?