Thursday, July 13, 2017

How to verify Private Key with a Certificate (SSL)

Private key contains series of numbers. Two numbers are for the Public key, others are for Private key.
Public key bits are also embedded in the Certificate.
To check that Public key in your Certificate matches the "Public key" inside your Private key, you need to view the Certificate & Private key and compare the numbers.

To view the Certificate and Private key please follow the commands.

# openssl x509 -noout -text -in domain.crt
# openssl rsa -noout -text -in domain.key

The 'modulus' and the 'public exponent' portions in the key and the Certificate must match. Human eye it is dificult to compare the 'public exponent', it is usually 65537. To compare these in shorter number follow the commands, it will show the hash.

# openssl x509 -noout -modulus -in domain.crt | openssl md5
Result: (stdin)= 065ae4a31a6f5623e86f5bc17532c7e3

# openssl rsa -noout -modulus -in domain.key | openssl md5
Result: (stdin)= cce154b2e767186b3e146af70101f046

Compare it in single command

# openssl x509 -noout -modulus -in domain.crt | openssl md5 ;\
  openssl rsa -noout -modulus -in domain.key | openssl md5
Result:
(stdin)= 065ae4a31a6f5623e86f5bc17532c7e3
(stdin)= cce154b2e767186b3e146af70101f046

You can also compare CSR with the Private key with following command

# openssl req -noout -modulus -in domain.csr | openssl md5
Result: (stdin)= cce154b2e767186b3e146af70101f046

Tuesday, April 11, 2017

Command to find your public IP.


If you are behind a router and don't know your public IP.
You could request some website to get your IP using curl or wget. 
Following commands will give you the result.
It returns just the plain text IP, nothing else

  • curl http://checkip.amazonaws.com
  • curl ipinfo.io/ip
  • curl icanhazip.com or wget -qO- icanhazip.com
  • curl ident.me; echo or curl v4.ident.me; echo
  • wget -qO- http://ipecho.net/plain ; echo
  • curl ipecho.net/plain ; echo
  • curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
  • curl ifconfig.me

Wednesday, March 22, 2017

Redirecting Hash(#) Fragments with Apache rewrite.

The character string beginning with a pound sign, # being interpreted as its HTML entity hex equivalent, %23..
It can led the url with 404 error.
It is very simple to redirect hash-fragment requests to proper destination using rewrite techniues.

You can find in the web access logs with HTML character code %23 for #.

Example1:

http://www.test.com/path/%23blog-123

To fix this you can do like this.

RewriteRule ^/(.*)%23blog-(.*)$ /$1#blog-$2 [R=301,L,NE]

In the given example  the first (.*) is used to replace the $1, and the second (.*) is used to replace the $2. The key here is the NE flag, which prevents # from being converted to its hex code of %23 during the rewrite.

Example2:

It is also easy to do general url redirection.
Let's assume you wanted to redirect url /web/tips-for-parents to /take-away-for-enablers/#familiestrack
RewriteRule  ^/web/tips-for-parents  /take-away-for-enablers/#familiestrack [R=301,L,NE]

Exaple3:

Lets redirect a part of the url which is appended as hash-fragment.
RewriteRule ^/path-of-url/(.*)/?$  /path-of-url/#$1 [R=301,L,NE]

So if request is for /path-of-url/newsite, it will redirected to /path-of-url/#newsite


NE|noescape : By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.

Apache flag NE