Asymmetric Key encryption:


OPENSSL/CERTIFICATES See crypto summary here:HERE
To check the TYPE of certificate we have:

openssl x509 -in jaime-cert.cer -inform [der/pem] -noout -text

To READ the contents of a certificate:

openssl x509 -in /nsconfig/ssl/mycompany1.co.uk.pem -text

To verify that the Kpriv used to generate the certificate is the correct one (we compare cert key (mod) and key (mod)). See External Link

openssl rsa -noout -modulus -in device-private.key | openssl md5
openssl x509 -noout -modulus -in intermediate-root-chain.crt | openssl md5

A RSA key can be used both for encryption and for signing: GENERATE private key:

openssl genrsa -out private_key.pem 4096


Extract public key from the private one:

openssl rsa -pubout -in private_key.pem -out public_key.pem


Create CA certificate

openssl req -config openssl.srx.cnf -new -x509 -extensions v3_ca -keyout private/ca.key -out certs/ca.crt -days 1500


Sign a certificate (in the CA):

openssl x509 -req -days 3650 -sha1 -CA certs/ca.crt -CAkey private/ca.key -CAserial serial -CAcreateserial -in srx-j24-id.req -out certs/srx-j24.crt -extfile ext.cfg


To convert from the b64 notation to text notation so we can see each of the parts of the key/certificate:

openssl pkey -in privkey -in privkey-A.pem -text

Same but for a certificare in crt format:

openssl x509 -in certificate.crt -text -noout

Generate CSR (Certificate signing request)

openssl genrsa -des3 -out rttpd.new.key 1024

openssl req -new -key rttpd.new.key -out rttpd.csr

openssl req -text -noout -in rttpd.csr

openssl x509 -req -days 3650 -sha1 -CA certs/ca.crt -CAkey private/ca.key -CAserial serial -CAcreateserial -in srx-j24-id.req -out certs/srx-j24.crt -extfile ext.cfg
In NETSCALER:


In F5 BIG-IP:


To REQUEST the key that signed a package..

gpg --keyserver x-hkp://pool.sks-keyservers.net --recv-keys 0x416F061063FEE659

And this is to VERIFY a signed package:

gpg --verify ./tor-browser-linux64-4.0.1_en-US.tar.xz{.asc*,}

To CREATE CA and private key:

openssl req -config openssl.srx.cnf -new -x509 -extensions v3_ca -keyout private/ca.key -out certs/ca.crt -days 1500

(I am the CA). To sign a certificate: openssl x509 -req -days 3650 -sha1 -CA certs/ca.crt -CAkey private/ca.key -CAserial serial -CAcreateserial -in srx-j24-id.req -out certs/srx-j24.crt -extfile ext.cfg


About formats and extensions


About Certificate Fields


Certificate request is made by PKCS10 https://tools.ietf.org/html/rfc2986


TLS CIPHERSUITE COMPONENTS:
https://docs.microsoft.com/en-us/windows/win32/secauthn/cipher-suites-in-schannel

To see what ciphersuite a site uses, just FF cert details, then go here and check the ciphersuite details: https://ciphersuite.info


CERTIFICATE CHAIN / WILDCARD CERTIFICATES:


CRYPTOGRAPHY NOTES


Then we have Authenticated Encryption (AE) : form of encryption which simultaneously assure the confidentiality and authenticity of data. External_Link . It uses encryption context that represents additional authenticated data (AAD) TODO: Does replace or complement the certificate-based authentication?


HTTPS > TLS1.2-3 > RSA KEY EXCHANGE

RSA Key Exchange:


Very succinct and clear HERE! Components:

encrypted = (message ^ e) mod n
decrypted = (encrypted ^ d) mod n

There's a mathematical relationship between e, d, and n that makes RSA work. If someone could factor n into p and q, they could calculate d using a - formula that connects them all. To calculate d, you need to know: e (which is public)

  1. (p-1) and (q-1)
  2. p and q are like the blueprint for making copies of the key
  3. n being hard to factor means no one can recreate the blueprint, even though they can see the lock

Process:


RSA Key Exchange:
TODO

TLS1.2 The TLS protocol comprises two layers: the TLS record and the TLS handshake protocols.

  1. Handshake
  2. Asymmetric cipher



WEB CERTIFICATES NOTES ( Transport Layer Security (TLS) certificates )


How to force apache to use certain TLS

# Be sure this is all the below SSLProtocol TLSv1.2
/etc/apache2/mods-available/ssl.conf
/etc/apache2/mods-enabled/ssl.conf
/etc/letsencrypt/options-ssl-apache.conf
apachectl restart

TODO 1:


SSH NOTES

Give this a read External Link

  1. 1st session key agreement , KEX algorithms ( PKC to seup the symmetric encryption)
    1. debug2: KEX algorithms
    2. debug2: ciphers stoc
  2. 2nd Integrity MACs ctos: / MACs ctos: chosen integrity message authentication code. All msgs after this have an hmac attached
  3. kex: server→client cipher: AGREED CIPHER (BASED ON SYMMETRIC KEY) ; kex: client→server cipher: AGREED CIPHER (BASED ON SYMMETRIC KEY)
  4. 3rd client authentication hostkeyalgs ( PKC to authenticate (key based authentication))
    1. Server uses private key to send a Challenge
    2. kex: algorithm: <AGREED ALGORITHM FOR THE PK BASED AUTHENTICATION


NOTE: stoc (server to client) ctos (client to server)

For authentication

nmap –script ssh-hostkey 10.99.16.231-254  # to see the PubK lenght (remote)
ssh-keygen -l -f ~/.ssh/id_rsa.pub  # to see the key lenght (local)

For encryption (cryptos)

nmap --script ssh2-enum-algos 192.168.0.250 -p22  # to sjow all the above algorithms 


CERTIFICATE BASED SSH

To have it started on login and the keys loaded, add this to .bashrc:

http://askubuntu.com/questions/54670/passwordless-ssh-not-working This method works for ssh from root A to root B. To be checked how to ssh with certificate to from usera@A to userB@B. I think A user needs to exist as user in B host
To use a specific public key: ssh -i .ssh/id_rsa.pub Or to load a set of private keys (in different files) and use the corresponding one every time we ssh, we can make use of ssh-agent utility:

ssh-keygen # generate my key pair Protected By Password (full path is needed)
!
eval ssh-agent /bin/bash  # starts ssh agent. eval allows to load the env variables in the shell
ssh-add ~/.ssh/* # adds the keys
ssh-add -l   # lists the keys currently loaded
# ssh-copy-id <remote-host>    # copies the pub key in the remote 'authorized_keys' and takes cares of the permissions
kill $SSH_AGENT_PID

'ssh-agent' and 'ssh-add' can be automated with this in ~/.bash_profile:

if [-z "$SSH_AUTH_SOCK" ]; then
     eval `ssh-agent -s`
     ssh-add ~/.ssh/*

For ubuntu/raspbian based systems we use this solution : https://sourceware.org/legacy-ml/cygwin/2001-06/msg00537.html

If we want to see the private key
If we want to use a different (generally lower) key algorithm:


For issues with the virtual manager keys:

We need virtual manager to use the id_rsa_gk first. Temporarily, we can remove the other keys from the agent with:

ssh-add -d  /home/jaime/.ssh/bitbucket_rsa 
ssh-add -d  /home/jaime/.ssh/id_rsa 
ssh-add -d /home/jaime/.ssh/id_rsa_git 
# we keep this one: /home/jaime/.ssh/id_rsa_gk 

TROUBLESHOOT:

ssh-keygen -p -m PEM -f bitbucket_rsa



ADD NEW CA (EG WEBSENSE) TO LINUX BOX (From: Link
Check the certificate is in pem mode (see this Link:

openssl x509 -in  websense.corporate.local.crt -text -noout

This is to convert certificate formats (eg: crt/der binary to pem ) : Link & Link
Copy ca certificate to ssl linux directory and add it to the trusted list:

cp websense.corporate.local.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust enable
update-ca-trust

CRYPTOGRAPHY IN MS WINDOWS ENVIRONMENTS

[…]