Showing posts with label snippet. Show all posts
Showing posts with label snippet. Show all posts

Saturday, May 9, 2015

aha!

Some command-line tools produce nicely coloured output when running on ANSI terminals. However, when saving output of these tools into a text file for sharing, these colors are often lost, either due to copy/pasting that is not aware of colour codes or because the tools themselves detect the redirection and then output plain text only :)

In cases where tools preserve the ANSI colour codes on redirection, tiny aha (ANSI HTML Adapter) tool written by Alexander Matthes can be helpful when sharing the output with others. Its available from Debian packages or as source code at GitHub.

Its HTML output will look like below—this particular output example is from command which red-coloured output parts should catch recipient’s attention.

sslscan example.org:443 | aha --title "sslscan example.org:443" > output.html


Version: -static
OpenSSL 1.0.1m-dev xx XXX xxxx

Testing SSL server example.org on port 443

  TLS renegotiation:
Secure session renegotiation supported

  TLS Compression:
Compression disabled

  Heartbleed:
TLS 1.0 not vulnerable to heartbleed
TLS 1.1 not vulnerable to heartbleed
TLS 1.2 not vulnerable to heartbleed

  Supported Server Cipher(s):
Accepted  SSLv3    256 bits  DHE-RSA-AES256-SHA
Accepted  SSLv3    256 bits  AES256-SHA
Accepted  SSLv3    128 bits  DHE-RSA-AES128-SHA
Accepted  SSLv3    128 bits  AES128-SHA
Accepted  SSLv3    128 bits  RC4-SHA
Accepted  SSLv3    128 bits  RC4-MD5
Accepted  SSLv3    112 bits  EDH-RSA-DES-CBC3-SHA
Accepted  SSLv3    112 bits  DES-CBC3-SHA
Accepted  TLSv1.0  256 bits  DHE-RSA-AES256-SHA
Accepted  TLSv1.0  256 bits  AES256-SHA
Accepted  TLSv1.0  128 bits  DHE-RSA-AES128-SHA
Accepted  TLSv1.0  128 bits  AES128-SHA
Accepted  TLSv1.0  128 bits  RC4-SHA
Accepted  TLSv1.0  128 bits  RC4-MD5
Accepted  TLSv1.0  112 bits  EDH-RSA-DES-CBC3-SHA
Accepted  TLSv1.0  112 bits  DES-CBC3-SHA

  Preferred Server Cipher(s):
SSLv3    256 bits  DHE-RSA-AES256-SHA
TLSv1.0  256 bits  DHE-RSA-AES256-SHA

  SSL Certificate:
Signature Algorithm: sha256WithRSAEncryption
RSA Key Strength:    2048

Subject:  example.org
Altnames: DNS:example.org, DNS:www.example.org
Issuer:   COMODO RSA Domain Validation Secure Server CA


Sunday, December 28, 2014

Quick 2-tuples in Java

For cases one does not want or need (because it would never find reuse!) to create wrapper class for pairing two values of any types (a 2-tuple) in Java, Map.Entry public inner interface in java.util.Map container can be acceptable alternative. Code relying on java.util.Collections.singletonMap (constant additional space use!) to return a pair from Java method can be written as such:

// returns pair (2-tuple)
private Map.Entry<Integer, Record> bar() {
  // ... recordCount and record created
  return Collections.singletonMap(recordCount, record).entrySet().iterator().next();
}

// 2-tuple extraction with getKey()/getValue()
public void foo() {
  Map.Entry<Integer, Record> pair = bar();
  Integer recordCount = pair.getKey();
  Record record = pair.getValue();
  // use paired values ...
}