Labels

2009/11/28

Colorful output in expect.

If you want to change shell color attributes from expect make sure that you escape at least the first three characters of the ANSI color sequence. This is necessary due to the way expect interprets strings. For instance, if you try to declare the red color sequence like this:
set red "\x1b[1;31;40m"
expect will think that you forgot to close the square bracket. If you escape the square bracket and continue like this:
set red "\x1b\x5b1;31;40m"
expect will think that the following "1" belongs to the preceding"\x5b". The following trick can be used to quickly convert an un-escaped string to a fully hex-escaped one:
$ export RED="\x1b[1;31;40m"
$ python -c "print ''.join([r'\x%x' % ord(c) for c in \"$COLOR\"])"
\x1b\x5b\x31\x3b\x33\x31\x3b\x34\x30\x6d
ANSI sequence strings escaped this way can be further used in except scripts.

#!/usr/bin/env expect

# Colorful output from expect.
# Slawek Ligus

proc stripe_write {text} {
# This procedure prints every second character of a given
# string argument $text in red.

# RED="\x1b[1;31;40m"
set red "\x1b\x5b\x31\x3b\x33\x31\x3b\x34\x30\x6d"
# NORMAL="\x1b[1;0;40m"
set normal "\x1b\x5b\x31\x3b\x30\x3b\x34\x30\x6d"
for {set i 0} {$i < [string length $text]} {incr i 2} {
puts -nonewline "$red[string index $text $i]"
puts -nonewline "$normal[string index $text [expr $i+1]]"
}
puts -nonewline $normal
}

stripe_write " Expect in color. \n"
stripe_write " http://blog.ooz.ie/ \n"
stripe_write "=====================\n"

2009/11/01

Network Security with OpenSSL - exercises.

Set of exercises to the book of Network Security with OpenSSL by J. Viega, M. Messier, P. Chandra.
  1. Explain the following terms: SSL, TLS, CA, CRL, OCSP, PKI, PRNG
  2. List goals of cryptography.
  3. What is the difference between symmetric and public key encryption?
  4. List three cryptographic hash functions. What are their strengths and weaknesses?
  5. Explain what the term "digital signature" means.
  6. What are the challenges of SSL?
  7. Build OpenSSL from source.
  8. Use openssl to compute SHA1 and MD5 message digests for a given file.
  9. Encrypt and decrypt a file using 3DES.
  10. Generate parameters for Diffie-Hellman key exchange.
  11. Create a pair of DSA and RSA keys.
  12. What is the major difference between RSA and DSA?
  13. Explain the purpose of a CRL.
  14. What are Certificate extensions and how to use them?
  15. Do some research about OCSP (RFC2560)
  16. Create a CA environment.
  17. Generate a self signed certificate.
  18. Generate a certificate request.
  19. Issue a few certificates from certificate requests.
  20. Revoke some of the generated certificates.
  21. Retrieve HTTPS certificates of some of the Internet giants, e.g.
    $ echo|openssl s_client -connect www.google.com:443|\
    sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.txt
  22. Print the certificate in the text form
    $ cat cert.txt|openssl x509 -text