Fancy Key- and Truststores in HCL Domino

Have you ever tried, to access HTTPS Resources outside with Java (in Agents or xPages) in HCL-Domino. Of course you can add your certificates to the cacerts-file within the Domino JVM. But with the next update it maybe will be gone for good, because the installer decided to replace it with his own.

But you can use some fancy Java-Tricks and create your own truststores and keystores and use them in your Java-Code.

The key Item here is the javax.net.ssl.SSLSocketFactory. Create an instace of this and pass it to your HttpsURLConnection.

First, you need am Method, which creates a javax.net.ssl.SSLSocketFactory:

/**
 * Create an Instacce of javax.net.ssl.SSLSocketFactory with a given keystore and trusstore
 * 
 * @param trustFileInputStream   a InputStream to a Java-Keystore File containing the trusted certifcates
 * @param tustPassword           the passwort for the Truststore File
 * @param keyFileInputStream     a InputStream to a Java-Keystore-File containing the client-certificate
 * @param keyPassword            the passwort for hte Keystore-File
 * 
 * @return a javax.net.ssl.SSLSocketFactory Instance configured with the provided key- and truststore.
 * 
 */
public static SSLSocketFactory getFactory(InputStream trustFileInputStream, String trustPassword, InputStream keyFileInputStream, String keyPassword)
              throws Exception {

  // the keystore holds my ClientCertificates, it is only needed if you need Client-Certificate authentication
  // I choose the PKCS12 File-Format (private key protected with a passphrase)
  KeyStore keyStore = KeyStore.getInstance("PKCS12");
  keyStore.load(keyFileInputStream, keyPassword.toCharArray());

  KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  keyManagerFactory.init(keyStore, keyPassword.toCharArray());

  KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();

  // the truststore holds all the certificates you want to trust, i.e. the certifcate from the lets-encrypt-ca
  // I choose the JKS [JavaKeyStore] Format, the same formate as the famous cacerts-File
  KeyStore trustStore = KeyStore.getInstance("JKS");
  trustStore.load(trustFileInputStream, trustPassword.toCharArray());

  TrustManagerFactory trustManagerFactory = TrustManagerFactory
                  .getInstance(TrustManagerFactory.getDefaultAlgorithm());
  trustManagerFactory.init(trustStore);

  TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();

  // please do not use any TLS-Version below 1.2, if possible use 1.3 :)
  SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
  sslContext.init(keyManagers, trustManagers, new SecureRandom());

  return sslContext.getSocketFactory();
}

Then some code to put the SSLSocketFactory into use. I hope you are familiar with HCL-Domino Java programming, there are some things you will need to now.

At first I get some attachments holding the files needed (ClientCertificate and TrustStore) and the passwords for them. All these things are stored in a Notes Document and are finally passed to the method from above.

Then we create an javax.net.HttpsUrlConnection and simply POST some (here not printed) content to an java.net.Url

RichTextItem rti_cert = (RichTextItem) profile_doc.getFirstItem("ClientCertificate");
EmbeddedObject eo_cert = (EmbeddedObject) rti_cert.getEmbeddedObjects().get(0);

RichTextItem rti_trust = (RichTextItem) profile_doc.getFirstItem("TrustStore");
EmbeddedObject eo_trust = (EmbeddedObject) rti_trust.getEmbeddedObjects().get(0);
               
InputStream trustfileInputStream = eo_trust.getInputStream();
InputStream keyFileInputStream = eo_cert.getInputStream();
               
String client_cert_password = profile_doc.getItemValueString("ClientCertPassword");
String truststore_password = profile_doc.getItemValueString("TrustStorePasswort");                
               
SSLSocketFactory ssl_socket_factory = SSLUtils.getFactory(trustfileInputStream,truststore_password, keyFileInputStream, client_cert_password);
       
System.out.println("Create HTTPS Connection to " + url.toString());
HttpsURLConnection conn;
conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(ssl_socket_factory);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
conn.setRequestMethod("POST");
System.out.println("Writing Content to output stream");
OutputStream os = conn.getOutputStream();
os.write(content.getBytes());
os.close();
System.out.println("Writing Content to output stream done");
               
eo_cert.recycle();
eo_cert = null;
rti_cert.recycle();
rti_cert = null;        
               
eo_trust.recycle();
eo_trust = null;
rti_trust.recycle();
rti_trust = null; 

I hope this post has some information for you to use.

Raspian and Media-Keys

Do you have a Keyboard with Media-Keys connected to your Raspberry PI? So do I 🙂

I’ve added following lines to my ‚lxde-pi-rc.xml‘ File in ‚/home/pi/.config/openbox‘ in the keyboard-section:

<keybind key="XF86AudioRaiseVolume">
  <action name="Execute">
    <command>amixer set PCM 250+ unmute</command>
  </action>
</keybind>
<keybind key="XF86AudioLowerVolume">
  <action name="Execute">
    <command>amixer set PCM 250- unmute</command>
  </action>
</keybind>
<keybind key="XF86AudioMute">
  <action name="Execute">
    <command>amixer set PCM toggle</command>
  </action>
</keybind>

Works like a charm!

Münchausen Zahlen

Dieses Posting ist furchtbar inspiriert durch einen Eintrag von diesem Blog: https://zach.se/munchausen-numbers-and-how-to-find-them/

Wer mehr zu den Münchhausen-Zahlen wissen will, findet es genauer hier beschrieben: https://de.wikipedia.org/wiki/M%C3%BCnchhausen-Zahl

Kurz gesagt: 3^3 + 4^4 + 3^3 + 5^5 = 3435

In F# schreibt man das so, Zweck der Übung ist ja, das ich mich gerade ein wenig in F# reinschnuppere:

let specialpown (i:int64) =
    match i with
    | 0L -> 0L
    | _ -> pown i (int i)
    
let digits (number:int64) = 
    (string) number |> Seq.map(fun i -> ( (int64) ((int i) % 48) ) )

let isMunchhausen number =
    digits number |> Seq.map (fun i -> specialpown i) |> Seq.sum = number 

digits 1234L |> Seq.toList
isMunchhausen 3435L

seq { 1L..500000000L } |> Seq.filter isMunchhausen |> Seq.toList

F# interactive zeigt dann folgendes in der Konsole:

val specialpown : i:int64 -> int64
val digits : number:int64 -> seq<int64>
val isMunchhausen : number:int64 -> bool
val it : int64 list = [1L; 3435L; 438579088L]

Ja, und die einzigen (bisher) bekannten Münchhausenzahlen sind diese 3:

  • 1
  • 3.435
  • 438.579.088

 

Send a „Cancel current Operation“ to IBM Notes with Powershell

On new Notebooks or Tablets, one key is missing:

– the pause-key

To cancel the current Operation within Notes, you can send a key-combination to the Notes-Process.

I realized this with the following Powershell-Script:

add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms

$id = (Get-Process "notes2").Id
[Microsoft.VisualBasic.Interaction]::AppActivate($id)
[System.Windows.Forms.SendKeys]::SendWait(“{BREAK}”)

DNS resolving Issues with ASUS RT-AC87U

I recently bought an new Router – the ASUS RT-AC87U.

I used it for some weeks with no problems, unless I tried to insert my 3G Data-Stick into the USB-Port (for failover reasons).

Since then, I did have occasional problems in resolving various internet adresses.


PS C:\Users\Harald> nslookup orf.at
Server: router.asus.com
Address: 192.168.1.1

*** orf.at wurde von router.asus.com nicht gefunden: Query refused.

Query refused? At first, I blamed my provider, and tried to configure the dns-adresses in the router to the Google-DNS-Servers (8.8.8.8 and 8.8.4.4) – unfortunately this did not help. The same error messages appeared and appeard. Refreshing the Site in the browser did help in most cases.

The Asus-Routers uses the dnsmasq DNS-Deamon to act as a DNS-Server. However, the DNS-Servers the deamon uses itsself are in the /etc/resolv.conf file. And there lies the magic (or the root of my problem).

If the router gets the (2) DNS-Servers Adresses from the Provider, it stores these IPs in the resolv.conf file. If you configure DUAL-WAN, you will get 4 DNS-Adresses into the file (2 for each provider). Providers usually only allow DNS-Queries from there own network…

So in some cases, the router uses WAN-Connection from Provider A, but tries to resolve the addresses with the DNS-Server from Provider B – which then gets refused.

What did I do?

I set the DNS-Server Adresses manually in /etc/resolv.conf via vi to only two entries (8.8.8.8, 8.8.4.4) and until now it works like a charm.