Click here

Tuesday, October 2, 2018

Import private key and certificate into java keystore


From time to time you have to update your SSL keys and certificates. In some cases you may have a mixed infrastructure e.g. "normal" http servers and tomcat or other java based servers. In the latter case you'll have to import your shiny new certificate and key into your java keystore.
There are several methods that you can use but I found the following the most simple:
  1. Export your key, certificate and ca-certificate into a PKCS12 bundle via
    COPY
    % openssl pkcs12 -export -in my.crt -inkey my.key -chain -CAfile my-ca-file.crt -name "my-domain.com" -out my.p12
  2. Be sure to set an export password! (see further below for an explanation)
  3. If you get the following error message "Error unable to get issuer certificate getting chain." then you should concatenate the openssl ca-certs with your own ca-cert into one file and use that as parameter for -CAfile. Example:
    COPY
    % cat /etc/ssl/cert.pem my-ca-file.crt > ca-certs.pem % openssl pkcs12 -export -in my.crt -inkey my.key -chain -CAfile ca-certs.pem -name "my-domain.com" -out my.p12
  4. Import the PKCS12 file into a new java keystore via
    COPY
    % keytool -importkeystore -deststorepass MY-KEYSTORE-PASS -destkeystore my-keystore.jks -srckeystore my.p12 -srcstoretype PKCS12
Attention!
If you don't set an export password in the first step the import via keytool will most likely bail out with an NullPointerException.

Wednesday, September 19, 2018

Python - List comprehension

List comprehensions are a tool for transforming one list (any iterable actually) into another list. During this transformation, elements can be conditionally included in the new list and each element can be transformed as needed.

The basic syntax is
[ expression for item in list if conditional ]

This is equivalent to:

for item in list:
    if conditional:
        expression

Example
1)
x = 1
y = 1
z = 1

lis = []
lis = [ [i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if (i+j+k) != N]
print lis

Output
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]

Above is the nested for loop
2)
x = [i for i in range(10)]
print x

This will give the output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Thursday, September 13, 2018

Python - Print without newline and space


In python , by default print inserts newline character at the end of an output

For example:



Output
1
2

1) To ignore the new line at the end of an output, you can do it multiple ways

In python 2.x



Output
1 2

2) To ignore the space in between



Output
12

Using backspace character replaces the space in between. Comma at the end replaces the newline character with an empty string.  If you use + operator , both the operators has to be in string format

3) To print without using string



Output
12

Comma at the end replaces the new line character. Printing an empty string suppresses the space in between

4) Python 3.x has an easy way of doing this



Using end statement, replaces the end terminator with an empty string.

print('a', 'b', 'c', sep='')
to suppress the white space separator between items.





Friday, April 20, 2018

ldconfig , to set library path in linux

LDCONFIG
( Where are the Libs ? )


Sometimes when you install a program from source it can complain that a certain library is missing . . . and still you know that the lib it is complaining about is actually installed on your system. But most likely it is not on the default place ( /usr/lib ) where the program looks for the lib.

There is a file on your system where all the paths to the libraries are mentioned: the /etc/ld.so.conf file. Here is an example of the /etc/ld.so.conf file on Slackware:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib


So, what's the solution ?

1). First locate the lib the program is complaining about, maybe it is in /usr/lib/qt/lib or in /usr/include or any other odd location.

2). Next add the path to that lib in the /etc/ld.so.conf file. So, for our example the /etc/ld.so.conf file would look like:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib
/usr/lib/qt/lib
/usr/include

3). Finally to let the system know that you updated the /etc/ld.so.conf file and make it use the new values give the command:
CODE
# ldconfig

Friday, March 23, 2018

Squid stats - Beginner's guide

Squidclient is a tool that can access the squid service, and retrieve statistics on the service. For example, to get some general performance statistic, run the following command on the squid server

Friday, March 9, 2018

Docker - Beginner's guide

1) What is docker?

A client program named Docker.

A server program that manages a Linux system[ listen for messages from the command line and manages the running system].

A program that builds container's from code

A service that distributes the containers across the internet

A company that makes containers


2) What is docker container?

Self contained sealed unit of software. Contains elements required to run the code. Includes batteries and operating system

Includes - Code, configs , processes, Networking[to allow the containers to talk to other containers],dependencies and operation system.

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.


3) What is docker engine?

"Docker engine" is the part of Docker which creates and runs Docker containers.

Because the Docker Engine daemon uses Linux-specific kernel features, you can’t run Docker Engine natively on Windows. Instead, you must use the Docker Machine command, docker-machine, to create and attach to a small Linux VM on your machine. This VM hosts Docker Engine for you on your Windows system

Basics
A Docker container is a live running instance of a Docker image.
A Docker image is a file you have created to run a specific service or program in a particular OS.So, for example, say I want a web proxy; I can create a Docker image which is a standard install of Ubuntu 14.04 with just the squid3 package installed, and some specific configuration that I want to enforce authentication to be used with that squid proxy. I've created the docker image, but it's just a file.To use it, I need to create a Docker container which uses that file to become a live running squid VM with the config of my choice.

"Docker engine" (or just "Docker") is the program which creates and runs the Docker container from the Docker image file

Basic docker commands


  1. docker run -ti debian bash[  start an debian image with bash prompt]
-i, --interactive Keep STDIN open even if not attached

-t allocate a Pseudo TTY
-ti - terminal interactive which causes it have a full  terminal within the image so that you can run the shell and get things like tab completion and formatting to work completely

  1. docker images [ shows images]

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

REPOSIROY - Where it came from
TAG - Version number
IMAGE ID - internal docker representation of the image


  1. docker ps - to find running containers
root@debian:/home/saravanan# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0e512fe50c7b        debian              "bash"              14 seconds ago      Up 13 seconds                           gifted_mcclintock
  1. docker kill container-id  [ to kill the running container]
  2. Docker container ID and Image ID's are different
  3. docker ps -l = to display last stopped container

droot@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
910bce8bfc26        debian              "bash"              9 minutes ago       Exited (127) 2 seconds ago                       elastic_curran

Status shows the exit status of the container

7. docker  ps -a ,  to display all the container's including stopped containers.  Suppose if you create a file and exited that container, it is called stopped container. The file created in that container will never get deleted . It's there in   a stopped container. If we execute a docker run command from an image , it will spawn a new instance of an image and it does not contain the file which was created in  another instance of an image.

8. Docker image ====>[ docker run] =====> Running container ==[exit]==> Stopped container=== [docker commit] =======> New image

9. docker commit container-id

To modify and save a container as an image

root@debian:/home/saravanan# docker  run -ti debian bash

root@70f0efed3d3f:/# ls 
bin  boot  dev        etc  home  lib        lib64  media  mnt  opt        proc  root  run  sbin  srv  sys  tmp  usr  var
root@70f0efed3d3f:/# touch HELLO-WORLD
root@70f0efed3d3f:/# exit
Exit

root@debian:/home/saravanan# docker ps -l , to list last exited container
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd

Method 1
root@debian:/home/saravanan# docker commit 70f0efed3d3f [ to commit a container, input -container ID]
sha256:56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961

root@debian:/home/saravanan#

root@debian:/home/saravanan# docker tag  56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961 my-image [ to tag an image]

Method 2
root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd


root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
0355fd7bcf33        my-image            "bash"              4 minutes ago       Exited (127) 10 seconds ago                       heuristic_ptolemy

root@debian:/home/saravanan# docker commit competent_boyd my-image2  [ commit and tag an image, Input - container name and tag name]
sha256:496ecb935c3c72ec79381f5c89d7a4b48a9b409ddeab4ad6e1059e8862eaf444

root@debian:/home/saravanan# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image2           latest              496ecb935c3c        7 seconds ago       100MB
my-image            latest              56eaac55c922        7 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
root@debian:/home/saravanan#


root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image            latest              56eaac55c922        2 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker run -ti my-image
root@0355fd7bcf33:/# ls
HELLO-WORLD  bin  boot        dev  etc  home        lib  lib64  media  mnt        opt  proc  root  run  sbin  srv  sys  tmp  usr        var

root@0355fd7bcf33:/# 

Tuesday, March 6, 2018

Virtual box Full screen mode for debian

  1. Login as root;
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu, then run mount /media/cdrom.
  7. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen

Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunda...