Version: 8.0.x

Create Certificates

Create Certificates and keys#

Set the OpenHIM key#

To set the OpenHIM server key, you need to make a TLS request to the OpenHIM API for the below method and endpoint and supply a JSON object with the key.

Method: POST
Endpoint: {openhim_url}:8080/keystore/key
Payload: JSON object with the key

Examples#

Note: In the examples below, we are using the token authentication type to authenticate requests

Key Example#

Before we can send our request to the OpenHIM API we need to ensure that we construct our valid HTTP headers to successfully authenticate with the OpenHIM API.

Copy the below code at the bottom of your nodejs script that handles the authentication of the OpenHIM headers as described in the authentication section.

Replace the openhimOptions values with the correct implementation details and supply the SampleData payload to submit.

// append below code to the "openhim-api.js" script containing the authentication methods.
// This is described within the authentication section
(async () => {
const openhimOptions = {
apiURL: 'https://localhost:8080',
apiEndpoint: '/keystore/key',
username: '[email protected]',
password: 'openhim-password',
rejectUnauthorized: false
}
const SampleData = 'SampleData'
const headers = await genAuthHeaders(openhimOptions)
const options = {
method: 'POST',
url: `${openhimOptions.apiURL}${openhimOptions.apiEndpoint}`,
rejectUnauthorized: openhimOptions.rejectUnauthorized,
headers: headers,
body: SampleData,
json: true
}
request(options, (error, response, body) => {
if (error) throw new Error(error)
console.log({
statusCode: response.statusCode,
body
})
})
})()

Execute the below command in your terminal to run the nodejs script

node openhim-api.js

The response status will be 201 if successful.

Set up the certificate#

To set the OpenHIM server certificate, you need to make a TLS request to the OpenHIM API for the below method and endpoint and supply a JSON object with the certificate.

Method: POST
Endpoint: {openhim_url}:8080/keystore/cert
Payload: JSON object with the certificate

Certificate Example#

Before we can send our request to the OpenHIM API we need to ensure that we construct our valid HTTP headers to successfully authenticate with the OpenHIM API.

Copy the below code at the bottom of your nodejs script that handles the authentication of the OpenHIM headers as described in the authentication section.

Replace the openhimOptions values with the correct implementation details and supply the SampleData payload to submit.

// append below code to the "openhim-api.js" script containing the authentication methods.
// This is described within the authentication section
(async () => {
const openhimOptions = {
apiURL: 'https://localhost:8080',
apiEndpoint: '/keystore/cert',
username: '[email protected]',
password: 'openhim-password',
rejectUnauthorized: false
}
const SampleData = 'SampleData'
const headers = await genAuthHeaders(openhimOptions)
const options = {
method: 'POST',
url: `${openhimOptions.apiURL}${openhimOptions.apiEndpoint}`,
rejectUnauthorized: openhimOptions.rejectUnauthorized,
headers: headers,
body: SampleData,
json: true
}
request(options, (error, response, body) => {
if (error) throw new Error(error)
console.log({
statusCode: response.statusCode,
body
})
})
})()

Execute the below command in your terminal to run the nodejs script

node openhim-api.js

The response status will be 201 if successful.

Add certificate to list of ca certificates#

To add a certificate to the list of ca certificates, you need to make a TLS request to the OpenHIM API for the below method and endpoint and supply a JSON object with the certificate.

Method: POST
Endpoint: {openhim_url}:8080/keystore/ca/cert
Payload: JSON object with the certificate

Adding certificate Example#

Before we can send our request to the OpenHIM API we need to ensure that we construct our valid HTTP headers to successfully authenticate with the OpenHIM API.

Copy the below code at the bottom of your nodejs script that handles the authentication of the OpenHIM headers as described in the authentication section.

Replace the openhimOptions values with the correct implementation details and supply the SampleData payload to submit. The sample data in the example for setting up of a certificate can used here. The sample data in the example for setting up of a server certificate can used here.

// append below code to the "openhim-api.js" script containing the authentication methods.
// This is described within the authentication section
(async () => {
const openhimOptions = {
apiURL: 'https://localhost:8080',
apiEndpoint: '/keystore/ca/cert',
username: '[email protected]',
password: 'openhim-password',
rejectUnauthorized: false
}
const SampleData = 'SampleData'
const headers = await genAuthHeaders(openhimOptions)
const options = {
method: 'POST',
url: `${openhimOptions.apiURL}${openhimOptions.apiEndpoint}`,
rejectUnauthorized: openhimOptions.rejectUnauthorized,
headers: headers,
body: SampleData,
json: true
}
request(options, (error, response, body) => {
if (error) throw new Error(error)
console.log({
statusCode: response.statusCode,
body
})
})
})()

Execute the below command in your terminal to run the nodejs script

node openhim-api.js

The response status will be 201 if successful.