Показват се публикациите с етикет openssl. Показване на всички публикации
Показват се публикациите с етикет openssl. Показване на всички публикации

четвъртък, 24 април 2014 г.

test available ssl ciphers

testciphers.sh
#!/usr/bin/env bash

# OpenSSL requires the port number.
SERVER=$1 #host:port
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')

echo Obtaining cipher list from $(openssl version).

for cipher in ${ciphers[@]}
do
echo -n Testing $cipher...
result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1)
if [[ "$result" =~ "Cipher is ${cipher}" ]] ; then
  echo YES
else
  if [[ "$result" =~ ":error:" ]] ; then
    error=$(echo -n $result | cut -d':' -f6)
    echo NO \($error\)
  else
    echo UNKNOWN RESPONSE
    echo $result
  fi
fi
sleep $DELAY
done

сряда, 23 април 2014 г.

openssl Commands

Source:  https://www.sslshopper.com/article-most-common-openssl-commands.html

 Again copy/pasta to have it near when needed:

General OpenSSL Commands

These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.
  • Generate a new private key and Certificate Signing Request
    openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
  • Generate a self-signed certificate (see How to Create and Install an Apache Self Signed Certificate for more info)
    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt
  • Generate a certificate signing request (CSR) for an existing private key
    openssl req -out CSR.csr -key privateKey.key -new
  • Generate a certificate signing request based on an existing certificate
    openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
  • Remove a passphrase from a private key
    openssl rsa -in privateKey.pem -out newPrivateKey.pem

Checking Using OpenSSL

If you need to check the information within a Certificate, CSR or Private Key, use these commands. You can also check CSRs and check certificates using our online tools.
  • Check a Certificate Signing Request (CSR)
    openssl req -text -noout -verify -in CSR.csr
  • Check a private key
    openssl rsa -in privateKey.key -check
  • Check a certificate
    openssl x509 -in certificate.crt -text -noout
  • Check a PKCS#12 file (.pfx or .p12)
    openssl pkcs12 -info -in keyStore.p12

Debugging Using OpenSSL

If you are receiving an error that the private doesn't match the certificate or that a certificate that you installed to a site is not trusted, try one of these commands. If you are trying to verify that an SSL certificate is installed correctly, be sure to check out the SSL Checker.
  • Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key
    openssl x509 -noout -modulus -in certificate.crt | openssl md5
    openssl rsa -noout -modulus -in privateKey.key | openssl md5
    openssl req -noout -modulus -in CSR.csr | openssl md5
  • Check an SSL connection. All the certificates (including Intermediates) should be displayed
    openssl s_client -connect www.paypal.com:443

Converting Using OpenSSL

These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software. For example, you can convert a normal PEM file that would work with Apache to a PFX (PKCS#12) file and use it with Tomcat or IIS. Use our SSL Converter to convert certificates without messing with OpenSSL.
  • Convert a DER file (.crt .cer .der) to PEM
    openssl x509 -inform der -in certificate.cer -out certificate.pem
  • Convert a PEM file to DER
    openssl x509 -outform der -in certificate.pem -out certificate.der
  • Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
    openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes
    You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
  • Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)
    openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

вторник, 22 април 2014 г.

openssl verify

Make a folder to contain your public certificates:

#mkdir certs
#cd certs

Get public cert for the server you want to check:
#openssl s_client -showcerts -connect server:port

Copy from the "-----BEGIN CERTIFICATE-----" to the "-----END CERTIFICATE-----" , and save it in a file ending in .pem

Get issuer (CA) root certificate ("Certification Authority Root Certificate")
should be provided by your issuer or if you are your own CA you should know how to get this. Place it in the same directory as the certificate of your server (the one you are testing).

 Rehash the certificates. This is basically creating a link files to your .pem files. Names are based on the certificate content so openssl command will be able to operate on the files.

#for file in *.pem; do ln -s $file `openssl x509 -hash -noout -in $file`.0; done

Verify the certificate:

#openssl s_client -CApath . -connect server:port

Output should be similar to:
..
..
..
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DES-CBC3-SHA
    Session-ID: 53563D55F85CD643713643B7163A8C25113B114703C975DEA1C57D659FFBF96E
    Session-ID-ctx:
    Master-Key: 7288C083E0723BC61C4C21DC91908E34BD5C65695064E4E114FF4ED763ECA1D489794B9911E69021B8A8083A9CAB18EE
    Key-Arg   : None
    Krb5 Principal: None
    PSK identity: None
    PSK identity hint: None
    Start Time: 1398160725
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
..
..

If you see Verify return code: 0 (ok) you are good!

вторник, 19 април 2011 г.

Криптиране от команден (bash скрипт) ред в Linux

наскоро ми трябваше сигурен начин да криприрам информацията с която един bash скрип работи. Това което намерих са следните функции:

function encrypt {
  if [ -n "$1" ]; then
  openssl aes-256-cbc -a -salt -in "$1" -out "$1.enc"
  else
  openssl aes-256-cbc -a -salt
  fi
}

function decrypt {
  if [ -n "$1" ]; then
  openssl aes-256-cbc -a -d -in "$1" -out "${1%\.enc}" else
  openssl aes-256-cbc -a -d
  fi
}

разбира се може да се ползват и други алгоритми не само aes-256-cbc


ако поставим горните редове в .bashrc ще имаме възможност да изпълняваме команди от типа на:
за криптиране на архив
tar -czf - *|encrypt > allfiles.tgz.enc

за декриптиране
decrypt allfiles.tgz.enc

за декриптиране и разархивиране
cat allfiles.tgz.enc|dectypt|tar -xzf -