ServiceNow REST Integration - Configure ServiceNow
The following describes how to configure ServiceNow to perform a REST call against EJBCA that will gather metadata for each certificate and create a Generic Database Query Report containing all certificate metadata ( Username, Revocation Status, Expiration Date, Subject DN, and Issuer DN ).
Set up Mutual Authentication
The following lists the steps required to set up mutual authentication to establish trust.
To set up mutual authentication:
Log into Service Now Management Console.
In the Filter bar, type Certificates.
Select Certificates under System Definitions.
Next, perform the steps in the following sections to set up trust stores.
PKCS12 Authentication Trust Store
To set up the PKCS12 Authentication Trust Store:
On the System Definition > Certificates page, select New.
Complete the following fields:
Name: Enter EJBCA-RA.
Type: Select PKCS12 Key Store from the drop-down.
Key store password: Enter the PKCS12 password.
Active: Selected.
Short description: EJBCA Registration Authority.
Select the Attachment icon under the search bar, select Choose file, and select the P12 file.
Click Update.
Certificate Authority Trust Store (EJBCA RA Issuing CA)
To set up the Certificate Authority Trust Store (EJBCA RA Issuing CA):
On the System Definition > Certificates page, select New.
Complete the following fields:
Name: Enter EJBCA-RA-IssuingCA.
Format: PEM.
Type: Trust Cert Store.
Active: Selected.
Copy and paste the base64 certificate of the CA that issued the RA cert into the PEM Certificate field.
Click Update.
Certificate Authority Trust Store (EJBCA TLS Cert Issuing CA)
These steps are only required if different from RA Issuing CA.
To set up the Certificate Authority Trust Store (EJBCA TLS Cert Issuing CA):
On the System Definition > Certificates page, select New.
Complete the following fields:
Name: Enter EJBCA-TLS-IssuingCA.
Format: PEM.
Type: Trust Cert Store.
Active: Selected.
Copy and paste the base64 certificate of the CA that issued the TLS cert into the PEM Certificate field.
Click Update.
Configure REST Status Message
To configure and test the REST status message:
In the Filter bar, type REST Message.
Select REST Message under System Web Services.
Click New.
Complete the following fields:
Name: EJBCA
Endpoint: https://ejbcafqdn/ejbca/ejbca-rest-api
Use mutual authentication: Selected
Next to the Mutual authentication profile, click the Search icon.
Click New next to HTTP Methods.
Enter ejbcatls in the Protocol field.
Select the Keystore field and select EJBCA-RA.
Click Submit.
Select EJBCA from the REST Message list.
Click New.
Complete the following fields:
Name: Status Check
Endpoint: https://ejbcafqdn/ejbca/ejbca-rest-api/v1/certificate/status
Use mutual authentication: Selected
Click the Search Icon and select ejbcatls
Click Submit.
Select the Status Check REST Message.
Click Test:
The screen will load with the response starting with {"status":"OK","version":"1.0","revision"}.
If a Status "OK" is not returned, repeat the previous steps until an OK is returned.
Status "OK" indicates the mutual authentication, Registration Authority access rules, and REST protocol initial configurations are correct.
Do not proceed to the remaining procedures until the previous OK status is returned from the REST test message.
Build Certificate Query Table
The following sections provide steps required to run scheduled jobs that generate reports on expiring certificates using the Certificate Search Rest Call:
Create Certificate Search REST Call
To create a certificate search REST call:
In the Filter bar, type REST Message.
Select REST Message under System Web Services.
Click New.
Complete the following fields:
Name: EJBCA
Use mutual authentication: Selected
Next to the Mutual authentication profile, click the Search icon.
Click New next to HTTP Methods.
Enter ejbcatls in the Protocol field.
Select the Keystore field and select EJBCA-RA.
Click Submit.
Select EJBCA from the REST Message list.
Click New in the HTTP Methods list.
Complete the following fields:
Name: Certificate Search V2
HTTP method: POST
Endpoint: https://ejbcafqdn/ejbca/ejbca-rest-api/v2/certificate/search
Use mutual authentication: Selected
Click the Search Icon and select ejbcatls
Click Submit.
Select the Certificate Search V2 HTTP Method.
In the Variables Substitution section at the bottom, click New.
Click the HTTP Request tab.
Under HTTP Headers double-click on "Insert a new row...", enter Accept in the text box, and click the green checkmark.
Double-click in the Value column on the same row, enter application/json in the text box, and click the green checkmark.
On the next row enter Content-Type and application/json.
Click Update.
Select the Certificate Search V2 HTTP Method.
Under HTTP Query Parameters enter the text in the box below in the Content box and click Test.
The HTTP Status should be 200 and the Response box should have a success body from the REST call.
Click Delete.
This REST call will return the most recent 10000 certificates that have an ACTIVE status. Increase the page_size to capture more certificates
{
"pagination"
: {
"page_size"
:
10000
,
"current_page"
:
1
},
"sort"
: {
"property"
:
"UPDATE_TIME"
,
"operation"
:
"ASC"
},
"criteria"
: [
{
"property"
:
"CERT_STATUS"
,
"value"
:
"ACTIVE"
,
"operation"
:
"EQUAL"
}
]
}
Create Query Table
To create an EJBCA Certificate Query Table:
In the Filter bar, type tables and select Tables under System Definition.
Click New.
Enter EJBCA Certificate Query Table in the Label field.
Copy the Name that is generated based on the Label and paste it into a text editor. This name will be needed later.
Click Submit.
Change the Search field to Label and enter EJBCA Certificate Query Table in the text box.
Click EJBCA Certificate Query Table.
Click New in the Columns section.
Enter string in the Type field and select String (Full UTF-8).
Enter Revocation Date as the Column label.
Click Submit.
Repeat the previous steps for the remaining columns using the list below and click Update when finished:
Revocation Reason
Expiration Date
Issuer DN
Serial Number
Status
Subject Alternative Name(s)
Subject Key Identifier
Type
Last Updated
User
Click Update.
Create Staging Table
The Certificate Search REST call needs to parse the returned JSON data from the response body and place it in a staging table to later be transformed. The transformation will occur and the data will be placed in the table used for reporting
Create a CSV file with the headers below in Row 1 and save the file as data_set_table. The headers are case-sensitive and must match what is in the response body to be loaded.
revocationDate
revocationReason
expireDate
issuerDN
serialNumber
status
subjectAltName
subjectDN
subjectKeyId
type
updateTime
username
In the Filter bar, type load data and select it
Enter EJBCA Certificate Query in the Label field
Copy the Name that is generated based on the Label and paste it into a text editor. This will be needed later.
Select Choose File and select the data_set_table.
Click Submit.
A Progress page will display a state of Complete.
Click the Create a transform map hyperlink.
Create Transform Mapping
To create an EJBCA query transform mapping:
In the Filter bar, type transform maps and select it.
Click New.
Enter EJBCA Query Transform Mapping.
Click the Source table drop-down, enter ejbca and select the staging table from the drop-down.
Click Target table.
Click Submit.
Change the Search field to Label and enter EJBCA Query Transform Mapping in the text box.
Click EJBCA Query Transform Mapping.
Click the Mapping Assist link under Related Links.
In the left column, select all the headers in the data_set_table file, and click Add.
In the right column, click each item, click Add, and move the item up or down until the item is in line with the data_set_table header.
Click Save.
In the Field Maps, change the Coalesce value for serial_number to true.
Click Update and click OK on the prompt to index the table due to the Coalesce feature.
Create Script Includes
Perform the steps in the sections below to create scripts:
Create getJSONObjectsViaRest
In the Filter bar, type transform maps and select it.
Click New.
Enter getJSONObjectsViaRest in the Name field.
Change Accessible from to All application scopes.
Paste the code block below into the Script box and click Submit.
function
getJSONObjectsViaRest(endpoint, objects, api, request) {
var
pagedR =
new
sn_ws.RESTMessageV2(api, request);
if
(endpoint !==
null
) {
pagedR.setEndpoint(endpoint);
}
var
pagedResponse = pagedR.execute();
var
pagedResponseBody = pagedResponse.getBody();
var
pagedhttpStatus = pagedResponse.getStatusCode();
var
pagedObj = JSON.parse(pagedResponseBody);
objects = objects.concat(pagedObj.certificates);
return
objects;
}
Create insertGlideRecord
Click New.
Enter insertglideRecord in the Name field.
Change Accessible from to All application scopes.
Paste the code block below into the Script box and click Submit.
function
insertGlideRecord(GlideReference, field, value) {
if
(GlideReference.isValidField(field)) {
GlideReference.setValue(field, value);
}
}
Create loadRestInTable
Click New.
Enter loadRestInTable in the Name field.
Change Accessible from to All application scopes.
Paste the code block below into the Script box and click Submit.
function
loadRestInTable(rest_message, http_method, target_table) {
try
{
var
objects = getJSONObjectsViaRest(
null
, [], rest_message, http_method);
for
(
var
i=0; i<objects.length; i++ ) {
parseJSONObject(objects[i], target_table);
}
}
catch
(ex) {
var
message = ex.message;
gs.info(
'JSON IMPORT ERROR: '
+ message);
}
}
Create parseJSONObject
Click New.
Enter parseJSONObject in the Name field.
Change Accessible from to All application scopes.
Paste the code block below into the Script box and click Submit.
function
parseJSONObject(object, target_table) {
var
JSONImport =
new
GlideRecord(target_table);
JSONImport.initialize();
for
(
var
key
in
object) {
if
(object.hasOwnProperty(key)) {
var
field = key.toLowerCase();
var
actualField =
""
;
var
value =
""
;
if
(
typeof
(object[key]) ===
"object"
) {
if
(!Array.isArray(object[key])) {
for
(
var
inner_key
in
object[key]) {
actualField = (
'u_'
+ field +
"_"
+ inner_key).toLowerCase();
value = object[key][inner_key];
insertGlideRecord(JSONImport, actualField, value);
}
}
}
else
{
value = object[key].toString();
actualField =
'u_'
+ field;
}
insertGlideRecord(JSONImport, actualField, value);
}
}
JSONImport.insert();
}
Create Daily Calendar
To create a daily calendar:
In the Filter bar, type calendar and select it.
Click New.
Enter Every day in the Name field.
Click New in Days list.
Select Monday from Day of the week drop-down and click Submit.
Repeat step 5 for the remaining 6 days.
Create Scheduled Job
To create a scheduled job:
In the Filter bar, type scheduled jobs and select Scheduled Jobs under System Definition.
Click New.
Select Automatically run a script of your choosing.
Enter EJBCA - Daily Certificate Query in the Name field.
Select Daily from the Run drop-down list.
Enter 02 00 00 in the Time field.
Enter the following in the Run this box and click Submit.
Update the query name to match the name in ServiceNow:
loadRestInTable(
'EJBCA'
,
'Certificate Search V2'
,
'x_138548_demo_ejbca_certificate_query'
);
1st var = REST Message, 2nd var = HTTP Method configured in the REST Message, 3rd var = Staging table.
Make sure to modify these values if different names are used for these three variables being called.
Generate a Generic Report from the Database Query
To generate a generic report from the database query:
In the Filter bar, type reports and select Create New under Reports.
Enter EJBCA - Generic Database Query.
Click the Table drop-down and enter the table name generated when the EJBCA Certificate Query Table was created in step Create Query Table.
Click Next.
Select List under Other.
Click Next.
Click Choose Columns and select the desired fields.
Click Save in the top right.
Test Query and Report
As the final step, you can now test the query and report.
A certificate needs to be generated in EJBCA before completing the test procedure.
To test the query and view the created report containing all certificate metadata:
Navigate back to the EJBCA - Daily Certificate Query in System Definition > Scheduled Jobs.
Click Execute Now.
Return to the EJBCA - Generic Database Query and view the response data.