Exporting Java-keystore certificates into a Textfile (.pem)

Sometimes products get simply better, so does Tomcat. Beginning with Version 7 it is possible to specify the certificates for the listener in Apache httpd (OpenSSL-Style). For me, this is much easier to understand and easier to configure.

To export all your trusted CA’s to a textfile in .pem format, you can use the much loved/hated java keytool:

The keytool lives in %JAVA_HOME%/bin/ and has to be called with this parameters:

  • -list (lists all certificates in the store)
  • -rfc (lists the certificates in rfc style
  • -keystore (path to the java-keystore you want to export
  • -storepass (password to the java-keystore you want to export

This parameterset gives you an nice formatted text-output of your certificates.

The final step is, to forward the text-output into a file, and voila – finished you have a file, which you can use in your Tomcat-Connector for the parameter „SSLCACertificateFile“.

& 'C:\Program Files\Java\jdk1.8.0_60\bin\keytool.exe' -list -rfc -keystore C:\certs\cacerts -storepass changeit > all-cas.pem

Using NotesUI* Classes in C# with COM

The NotesUI* Classes are not accesible in Visual Studio via the References-Dialog. Also in the DesignerHelp it is said, that you can not use the UI-Classes.

 

But there is a very simple Solution in C# by using the dynamic – Keyword and the .NET System.Activator Class.

 

The following Code-Sample connects to an running Notes Client and performs some actions:

class Program
    {
        static void Main(string[] args)
        {
            dynamic session = Activator.CreateInstance(Type.GetTypeFromProgID("Notes.NotesSession"));
            dynamic uiws = Activator.CreateInstance(Type.GetTypeFromProgID("Notes.NotesUIWorkspace"));
            dynamic uidb = uiws.CurrentDatabase;
            dynamic dbDir = session.GetDbDirectory("NTSDEV2008");

            Console.WriteLine("Benutzer : {0}", session.UserName);
            Console.WriteLine("Datenbank: {0}", uidb.Database.FilePath);



            uiws.OpenDatabase("NTSDEV2008", "names.nsf");

            uiws.URLOpen("https://www.google.at");
                       
            


            Console.ReadKey(); 
        }
     }

 

I found no current usecase for this at the moment, but good to know that this is possible …

Convert Lotus Notes Documents to PDFs with LotusScript and Microsoft Word

In some of our old databases we wanted to convert the NotesDocument itself to a PDF-A Documents for archiving purposes.

We did it until now by opening the NotesUIDocument in the client and converted it ot PDF-A with an PDF-Printer (PDF-Creator). But often these NotesUIDocuments did note closed correctly and at the end of the NotesAgent we had thousands of NotesUIDocuments opened in the Client…

We searched for another way to convert the NotesDocument. We tried to render it to an NotesRichtTextItem, converting it to an MimeItem (based on the work from Yuri (here…), generating some HTML. But the HTML had some glitches: Notes inserts a small transparent gif into empty table-cells, so we would have to deal with different MimeEntities wich is also a PITA.

Then I found some code (from Steven J. Knight) in the IBM-Forums wich called a Notes-API function to export Microsoft RTF (which is called by the @Command([ExportFile], „Microsoft RTF“, fileName)

This works as a charm, generating nice looking RTF-Files. Together with a Microsoft Word COM-Instance we convert it to PDA-A quite fast and reliable:

%REM 
  LoggingLibrary PdfConverter 
  Created 11.07.2013 by Harald Reisinger 
  
  Description: 
  Functions to generate RTF and PDF Documents from NotesDocuments 
  Needs the OpenLog Databse for Logging Errors (http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=OpenLog) 
%END REM 

Option Public 
Option Declare 

Use "OpenLogFunctions" 

Const APIModule = "NNOTES" 
Const wdExportFormatPDF = 17 
Const wdExportFormatXPS = 18 
Const wdExportOptimizeForOnScreen = 1 
Const wdExportOptimizeForPrint = 0 
Const wdExportAllDocument = 0 
Const wdExportCurrentPage = 2 
Const wdExportFromTo = 3 
Const wdExportSelection = 1 
Const wdExportDocumentContent = 0 
Const wdExportDocumentWithMarkup = 7 
Const wdExportCreateHeadingBookmarks = 1 
Const wdExportCreateNoBookmarks = 0 
Const wdExportCreateWordBookmarks = 2 

Declare Function MailGetMessageBodyComposite Lib APIModule Alias "MailGetMessageBodyComposite" ( ByVal hNT As Long, ByVal N As String, ByVal D As String, nD As Long) As Integer 
Declare Function ExportRTF Lib "nxrtf" Alias "ExportRTF" (ByVal sTempFile As String, ByVal flags As Long, hmod As Long, ByVal altlibrary As String, ByVal sRTFFile As String) As Integer 

%REM 
  Sub ConvertDocToRtfFile 

  Description: 
  Converts a NotesDocument to an RTF-Document and saves it under the filePath Generates and removes some temporary Files while Working 
%END REM 

Public Sub ConvertDocToRtfFile(doc As NotesDocument, filePath As String) 
  Dim tempDoc As NotesDocument 
  Dim tempRti As NotesRichTextItem 

  On Error GoTo ErrorHandler 

  Set tempDoc = doc.ParentDatabase.CreateDocument() 
  Set tempRti = tempDoc.CreateRichTextItem("Body") 
  Call doc.RenderToRTItem(tempRti) 
  Call ConvertItemToRtfFile(tempRti, filePath) 
  Exit Sub 

ErrorHandler: 
  Call LogErrorEx("Error in: ConvertDocToRtfFile", SEVERITY_HIGH, doc) 
  Error Err, Error$ 
End Sub 

%REM 
  Sub ConvertDocumentToPdf 

  Description: 
  Converts a NotesDocument to an PDF-Document and saves it under the filePath Needs an COM-Instace of a Word Application created with: 
    Dim word As Variant 
    Set word = CreateObject("Word.Application") 

    Generates and removes some temporary Files while Working 
%END REM 

Public Sub ConvertDocumentToPdf(doc As NotesDocument, word As Variant, filePath As String) 
  Dim wordDoc As Variant 

  On Error GoTo ErrorHandler 
  Call ConvertDocToRtfFile(doc, filePath & ".rtf") 'http://msdn.microsoft.com/en-us/library/office/bb216319(v=office.12).aspx 
  Set wordDoc = word.Documents.Open(filePath & ".rtf", False, True, False) 'http://msdn.microsoft.com/en-us/library/office/bb256835(v=office.12).aspx 
  Call wordDoc.ExportAsFixedFormat(filePath, wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument, 0, 9999999, wdExportDocumentContent, True, True, wdExportCreateHeadingBookmarks, True, True, True, Nothing) 
  Call wordDoc.Close(0) 
  Kill filePath & ".rtf" 
  Exit Sub 

ErrorHandler: 
  Call LogErrorEx("Error in: ConvertDocumentToPdf", SEVERITY_HIGH, doc) 
  Error Err, Error$ 
End Sub 

%REM 
  Function ConvertItemToRtfFile 

  Description: Converts an NotesRichTextItem to an RTF-Document and saves it under the filePath Generates and removes a temporary File while Working 
%END REM 

Public Sub ConvertItemToRtfFile(item As NotesRichTextItem, filePath As String) 
  On Error GoTo ErrorHandler 

  Dim fileSize As Long 
  Dim doc As NotesDocument 

  Set doc = item.Parent 
  Call MailGetMessageBodyComposite(doc.handle , "Body", filePath & ".cd", fileSize) 
  Call ExportRTF(filePath & ".cd", 0, 0, "", filePath) 
  Kill filePath & ".cd" 
  Exit Sub 

ErrorHandler: 
  Call LogErrorEx("Error in: ConvertItemToRtfFile", SEVERITY_MEDIUM, doc) 
  Error Err, Error$ 
End Sub