Sin categoría

Seguridad General en BD, Seguridad Específica en MongoDB

Posted on Actualizado enn

La conferencia se divide en:

  • Seguridad general.
  • BD NoSql (documentales, clave valor, columna y de grafos).
  • Seguridad General en BD.
  • Seguridad Específica en BD NoSql (MongoDB)
  • Demo
    • MongoDB
      • Instalación
      • Usar MongoDB la autentificación
      • Crear Usuarios
      • Asignar Roles y Privilegios para usuarios
    • AWS
      • EC2
      • Security group
    • RoboMongo

En mi canal (por si en algún momento borran el oficial)

En el canal de Campus Party

Add channels to Roku

Posted on Actualizado enn

Create an app for Roku
*1. Download the https://sdkdocs.roku.com/display/sdkdoc/Playing+Videos#PlayingVideos-BroadcastVideo “VideoList.zip”
*2. Modify the videocontent.xml
*3. url = “http://xxx.xx.x.x/series/games/thrones.tp2x04.mp4″/>
*4. Create again the zip with the manifest at root
5. In my Roku I did this
To enable development mode, enter the special remote control sequence: Home 3x, Up 2x, Right, Left, Right, Left, Right. The entire sequence must be entered within 10 seconds.
*6. Go to my ip 192.168.0.x  [rokudeve / pass ****] and uploaded the zip file, like developer

https://sdkdocs.roku.com/display/sdkdoc/Loading+and+Running+Your+Application

1. Open a putty console and 192.168.0.x / 8080 / telnet, and wrote that, genkey twice, it generates a password and developerid
https://sdkdocs.roku.com/display/sdkdoc/Roku+Billing+and+In-Channel+Purchasing

2Lxxx344 (Roku T)
>genkey
Command not recognized
>genkey
……………………..+++
……………………………………………………………………………….+++
Password: w7lxxCNw==
DevID: e40axx87b
>

*2. Go to packager at right upper corner, write the password you create before, Download the pkg

https://developer.roku.com/developer-channels/channels/

*1. Sdk / private
*2. Video
*3. Add 504×405 jpg file
*4. Add the pkg you already created
*5. Submit for publishing
*6. Access code add
Another link: http://mkvxstream.blogspot.com/2016/03/how-to-create-roku-channel-part-four.html

*second time

 

SOLID – object oriented design

Posted on Actualizado enn

S.O.L.I.D is an acronym for the first five object-oriented design(OOD) principles by Robert C. Martin. [herencia, composición, abstracción, encapsulamiento o polimorfismo].

  • S – Single-responsiblity principle
  • O – Open-closed principle
  • L – Liskov substitution principle
  • I – Interface segregation principle
  • D – Dependency Inversion Principle

Single-responsibility Principle

Single-responsability: Each object must have only one responsability

As an example, consider a module that compiles and prints a report. Imagine such a module can be changed for two reasons. First, the content of the report could change. Second, the format of the report could change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different tim

Open/Close: Objects open for extension, closed for modification.
La forma más común de seguir el principio OCP es usar interfaces o clases abstractas de las que dependen implementaciones concretas. De esta forma puede cambiarse la implementación de la clase concreta manteniéndose la interfaz intacta.

https://www.adictosaltrabajo.com/tutoriales/solid-2/

Liskov Substitution: subclass/derived class should be like base/parent class.
Shell

class InterfazVehiculo{
function acelerar();
}

class Camion{
function acelerar() extends InterfazVehiculo{
introducirMasCombustible();
}
}

class CocheElectrico extends InterfazVehiculo{
function acelerar(){
incrementarVoltaje();
}
}

class Conductor{
function conducir(InterfazVehiculo vehiculo){
// otras funcionalidades…
v.acelerar();
}
}

https://www.adictosaltrabajo.com/tutoriales/solid-3/

Interface Segregation: lot of interfaces few methods rather than lots of methods few interfaces.

bad

good

https://www.adictosaltrabajo.com/tutoriales/solid-4/

Dependency Inversion: Components with abstractions, not with a specific implementation (concretions).

https://www.adictosaltrabajo.com/tutoriales/solid-5/

“Estos principios están en un nivel más alto que los patrones de diseño. No son un ejemplo concreto que debáis utilizar para resolver un problema. Son una forma de pensar, ideas que hay que tener en la cabeza mientras se programa para intentar mantener un código limpio y mantenible.”

Free certificates / Godaddy SSL

Posted on Actualizado enn

1.-Create free certificates

  • https://www.sslforfree.com/
  • select manual verification (dns)
    • How to add TXT to verify in godaddy.com
    • go to manage, and the key, for example:

2.-Download openssl https://code.google.com/archive/p/openssl-for-windows/downloads I downloaded the openssl-0.9.8k_X64.zip and copied openssl.exe / libeay32.dll / ssleay32.dll to my folder with ca_bundle.crt / certificate.crt / private.key the ran this:

  • c:\something>openssl pkcs12 -export -out aeinmobiliaria.com.mx.pfx -inkey private.key -in certificate.crt
  • And enter a password
  • and in Azure, custom domains http://www.aeinmobiliaria.com.mx and aeinmobiliaria.com.mx / CNAME>

3.-Then go to azure, upload it the pfx y appservice/ssl certificates and add a binding to:

  • hostname: aeinmobiliaria.com.mx
  • certificate: ainmobiliaria.com.mx (51……6E)
  • Ssl type: sni ssl

https://docs.microsoft.com/en-us/azure/app-service-web/app-service-web-tutorial-custom-ssl

  • so I had to include in godaddy
Edit
  • That is it

more useful links

ssl checker

https://www.sslshopper.com/ssl-checker.html#hostname=https://aeinmobiliaria.com.mx

tcp connection / pings

https://check-host.net/check-tcp?host=aeinmobiliaria.com.mx:443

Using cloudflare.com even in the free version you can use their ssl cert, some useful links…

https://www.troyhunt.com/how-to-get-your-ssl-for-free-on-shared/

http://wp.sjkp.dk/use-free-letsencrypt-ssl-certificate-with-azure-web-apps/

https://docs.microsoft.com/da-dk/azure/app-service-web/web-sites-custom-domain-name

Design patterns

Posted on Actualizado enn

Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.

The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral (for a complete list see below).

  • CREATIONAL PATTERNS
    • Abstract factory *
    • Builder
    • Factory Method *
    • Prototype
    • Singleton
  • STRUCTURAL PATTERNS
    • Adapter *
    • Bridge
    • Composite *
    • Decorator *
    • Facade
    • Flyweight
    • proxy
  • BEHAVIORAL PATTERS
    • Chain of responsibility
    • Command
    • Interpreter
    • Iterator
    • Mediator
    • Memento
    • Observer *
    • State
    • Strategy *
    • Template Method *
    • Visitor

*Commons and easiers patters

Singleton (just one instance):

using System;

public class Singleton
{
   private static Singleton instance;

   private Singleton() {}

   public static Singleton Instance
   {
      get
      {
         if (instance == null)
         {
            instance = new Singleton();
         }
         return instance;
      }
   }
}

Strategy

UML class diagram

using System;
 
namespace DoFactory.GangOfFour.Strategy.Structural
{
  /// 
  /// MainApp startup class for Structural
  /// Strategy Design Pattern.
  ///
  class MainApp
  {
    /// 
    /// Entry point into console application.
    ///
    static void Main()
    {
      Context context;
 
      // Three contexts following different strategies
      context = new Context(new ConcreteStrategyA());
      context.ContextInterface();
 
      context = new Context(new ConcreteStrategyB());
      context.ContextInterface();
 
      context = new Context(new ConcreteStrategyC());
      context.ContextInterface();
 
      // Wait for user
      Console.ReadKey();
    }
  }
 
  /// 
  /// The 'Strategy' abstract class
  ///
  abstract class Strategy
  {
    public abstract void AlgorithmInterface();
  }
 
  /// 
  /// A 'ConcreteStrategy' class
  ///
  class ConcreteStrategyA : Strategy
  {
    public override void AlgorithmInterface()
    {
      Console.WriteLine(
        "Called ConcreteStrategyA.AlgorithmInterface()");
    }
  }
 
  /// 
  /// A 'ConcreteStrategy' class
  ///
  class ConcreteStrategyB : Strategy
  {
    public override void AlgorithmInterface()
    {
      Console.WriteLine(
        "Called ConcreteStrategyB.AlgorithmInterface()");
    }
  }
 
  /// 
  /// A 'ConcreteStrategy' class
  ///
  class ConcreteStrategyC : Strategy
  {
    public override void AlgorithmInterface()
    {
      Console.WriteLine(
        "Called ConcreteStrategyC.AlgorithmInterface()");
    }
  }
 
  /// 
  /// The 'Context' class
  ///
  class Context
  {
    private Strategy _strategy;
 
    // Constructor
    public Context(Strategy strategy)
    {
      this._strategy = strategy;
    }
 
    public void ContextInterface()
    {
      _strategy.AlgorithmInterface();
    }
  }
}

Output

Called ConcreteStrategyA.AlgorithmInterface()
Called ConcreteStrategyB.AlgorithmInterface()
Called ConcreteStrategyC.AlgorithmInterface()
Real World

using System;
using System.Collections.Generic;

namespace DoFactory.GangOfFour.Strategy.RealWorld
{
  ///
  /// MainApp startup class for Real-World
  /// Strategy Design Pattern.
  ///

  class MainApp
  {
    ///
    /// Entry point into console application.
    ///

    static void Main()
    {
      // Two contexts following different strategies
      SortedList studentRecords = new SortedList();

      studentRecords.Add("Samual");
      studentRecords.Add("Jimmy");
      studentRecords.Add("Sandra");
      studentRecords.Add("Vivek");
      studentRecords.Add("Anna");

      studentRecords.SetSortStrategy(new QuickSort());
      studentRecords.Sort();

      studentRecords.SetSortStrategy(new ShellSort());
      studentRecords.Sort();

      studentRecords.SetSortStrategy(new MergeSort());
      studentRecords.Sort();

      // Wait for user
      Console.ReadKey();
    }
  }

  ///
  /// The 'Strategy' abstract class
  ///

  abstract class SortStrategy
  {
    public abstract void Sort(List<string> list);
  }

  ///
  /// A 'ConcreteStrategy' class
  ///

  class QuickSort : SortStrategy
  {
    public override void Sort(List<string> list)
    {
      list.Sort(); // Default is Quicksort
      Console.WriteLine("QuickSorted list ");
    }
  }

  ///
  /// A 'ConcreteStrategy' class
  ///

  class ShellSort : SortStrategy
  {
    public override void Sort(List<string> list)
    {
      //list.ShellSort(); not-implemented
      Console.WriteLine("ShellSorted list ");
    }
  }

  ///
  /// A 'ConcreteStrategy' class
  ///

  class MergeSort : SortStrategy
  {
    public override void Sort(List<string> list)
    {
      //list.MergeSort(); not-implemented
      Console.WriteLine("MergeSorted list ");
    }
  }

  ///
  /// The 'Context' class
  ///

  class SortedList
  {
    private List<string> _list = new List<string>();
    private SortStrategy _sortstrategy;

    public void SetSortStrategy(SortStrategy sortstrategy)
    {
      this._sortstrategy = sortstrategy;
    }

    public void Add(string name)
    {
      _list.Add(name);
    }

    public void Sort()
    {
      _sortstrategy.Sort(_list);

      // Iterate over list and display results
      foreach (string name in _list)
      {
        Console.WriteLine(" " + name);
      }
      Console.WriteLine();
    }
  }
}
Output
QuickSorted list
Anna
Jimmy
Samual
Sandra
VivekShellSorted list
Anna
Jimmy
Samual
Sandra
VivekMergeSorted list
Anna
Jimmy
Samual
Sandra
Vivek

AWS/azure (ubuntu) + Docker + Nodejs + Loadbalancer

Posted on Actualizado enn

  • Installing Docker in Ubuntu
    • In ec2(aws)/virtualmachine(azure) create a ubuntu server
    • Login to console using bitvise (ubuntu/publickey/global3[yourkey]), in Azure you can use a password too.
    • $ sudo apt-get update # Fetches the list of available updates
      $ sudo apt-get upgrade # Strictly upgrades the current packages
      $ sudo apt-get dist-upgrade # Installs updates (new ones)
    • $ sudo curl -fsSL https://get.docker.com/ | sh
    • $ sudo docker version
      • optional: down a hello image and run (copy to local)
      • $ sudo docker run hello-world
    • list image / containers
    • $ sudo docker images  / sudo docker ps -a
    • Create the image to upload to docker hub
  • NodeJS – server.js
var express=require('express')
var PORT=8080;
var app = express();
app.get('/', function(req,res){
	res.send('hi mother');
});
app.listen(PORT);
console.log('running on local '+PORT);
  • NodeJS – Package.json to configure needs
{
  "name": "hello",
  "version": "1.0.0",
  "main": "server.js",
  "author": "hemc",
  "description": "",
  "dependencies": {
    "express": "^4.15.2"
  }
}
  • Dockerfile (without extensión)
FROM node:6.9.4
EXPOSE 8080
WORKDIR /app
RUN npm install nodemon -g
COPY package.json /app/package.json
RUN npm install
COPY server.js /app
CMD ["nodejs", "/app/server.js"]
    all 3 in same folder, for example
  • Then we build the container image with a user to upload to dockerhub, local image name:
  • ~/nodeHello$ sudo docker build -t minode/test4 .  (point at the end)
  • Upload to docker hub
    • $sudo docker run -it minode/test4
      • new console
    • $sudo docker ps -a
      • containerid my user on dockerhub web image name
    • $sudo docker commit e1078f8d0cfb minode/onlinetest4
    • $sudo docker run -it minode/onlinetest4
      • uploading
    • $sudo docker login –username=minode
      • +password
    • $sudo docker push minode/onlinetest4

=============docker aws===============

  • Create cluser
    • t2 micro / instances 2 / key pairs (your keys) / port range 8080
  • Create task
    • default values
    • create container
      • default + minode/test4
  • Create service (back to cluster first tab)
    • numtask=4
  • Review EC2 / instances, verify inbound rules are port 8080 open
  • Verify ip:8080 of two instance
  • Loadbalancer
    • select vpc with access to zone where the instances are placed, security group with port 8080 open a follow loadbalancer classic tutorial
  • Delete cluster
    • Delete cluster in main page
    • Go inside task two times and desregister task
    • Delete load balancer and verify instances are deleted
  • To delete images
    • $ sudo docker rmi

Part 1


Part 2


Part 3


Part 4

(by the way, mute the videos, I was listening spain radio)

Reference

http://www.ybrikman.com/writing/2015/11/11/running-docker-aws-ground-up/

https://aws.amazon.com/es/getting-started/tutorials/deploy-docker-containers/

https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

https://community.risingstack.com/deploying-node-js-microservices-to-aws-using-docker/

 

You can login into container with:

docker exec -it bash
and run:

apt-get update
apt-get install nano

Docker images are delivered trimmed to bare minimum – so no editor is installed with the shipped container. That’s why there’s a need to install it manually.

To show only running containers use:
docker ps
To show all containers use:
docker ps -a