How to convert an IPV4 netmask to CIDR

To switch from an IPV4 netmask to the equivalent CIDR it might occur to do the simplest thing, that is to use a nested "case" block or "if" to obtain the equivalent CIDR so much so that the available netmasks or CIDR are only 32 and that is

(more…)

Convert a decimal number to hexadecimal from Bash

As for the faq with the conversion to binary, also in this we make use of the fantastic bash braces extensions to convert to hexadecimal.

So, always considering the bash faq on the binary we start initially by converting a decimal number between 0 and 255 which corresponds to a hexadecimal digit between 0 and FF:

(more…)

Convert a decimal number to binary from Bash

Suppose we are working on a bash script and that for some need, not too difficult from reality, it is essential to have to convert a number or a decimal variable into a binary number.

There are of course several solutions but the one I propose does not make use of external programs but it is bash in all respects.

First we need to know the maximum value of the binary number to be obtained in Bash or in how many bits it can be included.

(more…)

Random password generation with Ruby

Suppose we want to generate a random, robust and fairly secure password using Ruby then we create a "random_password" function that returns a password with 12 characters or if we want one with more or less we have to pass this value as a parameter.

First we define the range of characters allowed for the password

(more…)

Trust certificate authority per firma digitale

If you try to verify the signature of a p7m file without the Certification Authority (la CA), the verification fails ("unable to load certificate") because we do not have CA trust certificates (so-called Trusts).
These Certificate Authorities have been defined by Italian law and are registered on the CNIPA, which since December 2009 has become DigitPA, as a certificate of XML certificates and found them on the same site at https://applicazioni.cnipa.gov.it/TSL/_IT_TSL_signed.xml.

(more…)

Checking the signature of a p7m document

Consider the case where the signed document is a pdf (document.pdf.p7m).

To verify the signature and extract the content file, we use the openssl command with the smime parameter for signature verification (-verify)

(more…)

Extraction of the certificate of a digitally signed files (p7m)

Let's consider the case where the signed document is a pdf (document.pdf.p7m).

To extract the certificate used to sign the p7m we use the openssl command with the pkcs parameter

(more…)

Extracting the contents of a digitally signed file (p7m)

Let's consider the case where the signed document is a pdf (document.pdf.p7m).

To extract the content file we use the openssl command with the smime parameter for signature verification (-verify)

(more…)

Redirigere un servizio locale in remoto con ssh

Supponiamo di volerci connetterci da casa al pc dell' ufficio (che può accede al server "mioserver" in server farm)  non raggiungibile nemmeno in VPN; basta che dal pc di ufficio lanciamo il comando ssh:

ssh -N -f -R 2222:localhost:22 mioutente@mioserver
(more…)

Come redirigere una connessione remota in locale tramite ssh

Supponiamo che l'host "mioserver" sia autorizzato ad accedere su una DMZ al server mysql della server farm, per poter accedere direttamente anche con il computer locale al server mysql possiamo lanciare il comando locale

ssh -L 3333:mysql_server_name_o_ip:3306 mioutente@mioserver
(more…)