Skip to main content
Delphix

How to Convert a Certificate to One Line Format For CLI/API Operations (KBA6669)

 

KBA

KBA# 6669

Applicable Delphix Versions

Click here to view the versions of the Delphix engine to which this article applies
Major Release All Sub Releases
6.0 6.0.0.0, 6.0.1.0, 6.0.1.1, 6.0.2.0, 6.0.2.1, 6.0.3.0, 6.0.3.1, 6.0.4.0, 6.0.4.1, 6.0.5.0

5.3

5.3.0.0, 5.3.0.1, 5.3.0.2, 5.3.0.3, 5.3.1.0, 5.3.1.1, 5.3.1.2, 5.3.2.0, 5.3.3.0, 5.3.3.1, 5.3.4.0, 5.3.5.0 5.3.6.0, 5.3.7.0, 5.3.7.1, 5.3.8.0, 5.3.8.1, 5.3.9.0

5.2

5.2.2.0, 5.2.2.1, 5.2.3.0, 5.2.4.0, 5.2.5.0, 5.2.5.1, 5.2.6.0, 5.2.6.1

5.1

5.1.0.0, 5.1.1.0, 5.1.2.0, 5.1.3.0, 5.1.4.0, 5.1.5.0, 5.1.5.1, 5.1.6.0, 5.1.7.0, 5.1.8.0, 5.1.8.1, 5.1.9.0, 5.1.10.0

5.0

5.0.1.0, 5.0.1.1, 5.0.2.0, 5.0.2.1, 5.0.2.2, 5.0.2.3, 5.0.3.0, 5.0.3.1, 5.0.4.0, 5.0.4.1 ,5.0.5.0, 5.0.5.1, 5.0.5.2, 5.0.5.3, 5.0.5.4

4.3

4.3.1.0, 4.3.2.0, 4.3.2.1, 4.3.3.0, 4.3.4.0, 4.3.4.1, 4.3.5.0

4.2

4.2.0.0, 4.2.0.3, 4.2.1.0, 4.2.1.1, 4.2.2.0, 4.2.2.1, 4.2.3.0, 4.2.4.0 , 4.2.5.0, 4.2.5.1

4.1

4.1.0.0, 4.1.2.0, 4.1.3.0, 4.1.3.1, 4.1.3.2, 4.1.4.0, 4.1.5.0, 4.1.6.0

How to Task

Although the Delphix GUI allows for multiple line input text boxes for certificate installation (HTTPS certificate replacement, truststore installation, or password vault configuration), it may be desirable to leverage CLI or API functions to complete this configuration. As such, the formatting of JSON data for API input requires that certificates or private keys be entered as a single line. JSON does not support multiple line input. This requires that the existing line breaks be removed and replaced with \n text to indicate a line break (linefeed).

Prerequisites

The certificate(s) and private key(s) desired for installation are expected be in PEM format (Base64 ASCII encoded).

Convert to one line - UNIX/Linux

A simple awk command can be leveraged to make the replacement:

awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' <certificate name>

This awk command subfunction removes each line break (\r), and prints output without new line, adding \n text after each line read, ultimately generating a single line output. This can optionally be redirected to a file as desired.

Before:

-----BEGIN CERTIFICATE-----
MIIGjjCCBHagAwIBAgIINYnyXkb5dK0wDQYJKoZIhvcNAQELBQAwgZoxCzAJBgNV
BAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMUmVkd29vZCBDaXR5MRIwEAYD
.
.

After (output severely abbreviated to illustrate single-line with \n text desired):

-----BEGIN CERTIFICATE-----\nMIIGjjCCBHagAwIBAgIINYnyXkb5dK0wD.....

The subsequent output can then be entered in the relevant REST API POST field.

 

Convert to one line - Windows

If additional software installation is available, a Windows administrator may leverage Cygwin, which installs a collection of GNU and Open Source tools for Windows users. Alternatively, Microsoft also provides a Linux Subsystem option for Windows 10 which adds a compatibility layer, allowing execution of Linux binaries.

If these options are unavailable, many common third party text editors offer advanced find/replace capabilities which can approximate the Unix/Linux process discussed above, though usually will take two steps.

The following example leverages Regular expression find/replace available in Notepad++.  

Note

Note:

The methods expressed here are not exhaustive or necessarily the optimal solution. Delphix may not be able to provide equivalent methods for other applications; this example is provided for convenience using one of the most common third-party utilities.

After opening the original key or PEM file, CTRL-H to find/replace (or go to Search > Replace in menu bar). Add the character $ in the Find what: box, then add \\n in the Replace with: box. Search Mode selection must be Regular expression.

clipboard_e63b86d69ba04b5c905a8fd8023693e5f.png

The $ character in a regular expression is the anchor at end of line; this will append it with \n text, but the text must be escaped with an additional \ for it to be added as text rather than encoding a Unix line break.

Once this is completed, each line should have \n appended:
clipboard_e6883616fcec4daa2de806852fcda4c12.png

Since the Join Lines option will include spaces, another find/replace will be performed using Regular expression, this time the Find will be \n and Replace with: will be left blank.



This find/replace will remove the actual end of line encoding and result in our desired one-line certificate or key with \n text inserted:

clipboard_e517c34a31245b394aee9730754aec253.png

The subsequent output can then be entered in the relevant REST API POST field.