Auto-Load Configuration of CodeSafe 5 Applications via the nShield 5c

The nShield 5c (Connect) with this configuration supports the following CodeSafe 5 functionality:

  • CodeSafe 5 applications can be started directly via the nShield 5c (Connect) config file, with the CodeSafe 5 image, Developer ID certificates, and encryption key (if specified) pulled automatically from the RFS.

  • Applications specified in the nShield 5c config are started automatically when the nShield 5c is rebooted or module cleared.

  • CodeSafe 5 applications loaded directly from the nShield 5c can make their SEE World ID available as a published object, enabling multiple remote client machines to communicate with the same CodeSafe 5 application via the SEEJobs protocol.

Installation and Setup

Install the latest nShield host-side software and run the rfs-setup utility to allow the nShield 5c to retrieve the required Developer ID certificate(s) from the RFS’s cscerts volume. If you configured your RFS before v13.9.5, run rfs-setup again to add the permission for the new volume.

Build and sign the CodeSafe 5 image as described in Building CodeSafe 5 applications.

Permit the nShield 5c to have a configuration file pushed from a remote machine. By default, the configuration file can be pushed from the RFS, provided it is authenticated. To allow another remote client to push configuration, use the 5c’s Client config push menu from its front panel UI (menu 1-1-6-2). For more information, see Connect configuration.

Configure the nShield 5c to append its logs (hardserver and system logs) to the RFS once per minute in order to get timely feedback on CodeSafe 5 configuration operations. For more information, see Connect logging configuration.

Copy the Developer ID certificate(s) required by the CodeSafe 5 application to this directory on the RFS /opt/nfast/kmdata/cscerts (Linux) or C:\ProgramData\nCipher\Key Management Data\cscerts (Windows).

Copy the CodeSafe 5 image into /opt/nfast/custom-seemachines (Linux) or C:\Program Files\nCipher\nfast\custom-seemachines (Windows).

If the CodeSafe 5 image is encrypted, make sure the seeconf key that protects it is present on the RFS in the Security World key data directory /opt/nfast/kmdata/local (Linux) or C:\ProgramData\nCipher\Key Management Data\local (Windows), so that the key is pulled to the appliance along with the image.

Configuring CodeSafe 5 Auto-Load

Copy the original nShield 5c configuration file /opt/nfast/kmdata/hsm-<ESN>/config/config (Linux) or C:\ProgramData\nCipher\Key Management Data\hsm-<ESN>\config\config (Windows) to config.new in the same directory.

SEEJobs Configuration

Edit the nShield 5c config.new file’s [codesafe] section on the RFS to have the following contents (replace seemachine.cs5 with the actual filename - this will be pulled from the RFS volume for custom-seemachines so just the filename and not the path must be used here):

[codesafe]
image_file=seemachine.cs5
worldid_pubname=mysee
pull_rfs=yes

Optimized SEEJobs Configuration

The seejobs_transport=plain option may be used to allow plaintext communication internally inside the appliance, between the 5c (Connect) hardserver and the CodeSafe 5 application running on the HSM inside the appliance. This improves SEEJobs latency and throughput and may be appropriate if plaintext internal communication is acceptable for your security model. Remote communication for SEEJobs is secured via nCipher Secure Transport/Impath regardless of this setting, so communication is always secured on the external network.

[codesafe]
image_file=seemachine.cs5
seejobs_transport=plain
worldid_pubname=mysee
pull_rfs=yes

Firewall rules for plaintext SEEJobs

With seejobs_transport=plain, the 5c hardserver connects directly to the SEEJobs port in the CodeSafe 5 application rather than through the SSH tunnel, so the application’s firewall rules must permit plaintext access to that port. The seejobs_port (default 8888) must be listed in the incoming tcp ports of the application’s network-conf.json (see Example network-conf.json file). Specifying the port only as the ssh_tunnel container_port is not sufficient.

The following network-conf.json permits SEEJobs on port 8888 both in plaintext and through the SSH tunnel. Therefore, the application can use either seejobs_transport=plain or the default seejobs_transport=ssh. The CodeSafe SDK’s echo example uses this configuration:

{
    "incoming" : {
        "tcp" : {
            "protos" : [ "ipv6" ], "ports" : [ 8888 ]
        }
    },
    "outgoing" : {
        "tcp" : {
            "protos" : [ "ipv6" ], "ports" : []
        }
    },
    "ssh_tunnel" : {
             "container_port" : 8888
    }
}

When the CodeSafe 5 application is auto-loaded from the nShield 5c config, the seejobs_port is not exposed on the 5c’s external network interface, either in plaintext or over SSH, so permitting it in incoming does not make it accessible outside the appliance.

If seejobs_transport=plain is used without the seejobs_port in the incoming tcp ports, the HSM firewall silently drops the connection from the 5c hardserver. The CodeSafe 5 application loads and starts, but SEEJobs never reach it. The 5c hardserver log reports repeated ncssh dial timeouts (TCP connection Dial …​ failed (i/o timeout)) over several minutes, followed by Failed to dial remote host and SEE Jobs communication failed. Client Cmd_SEEJob commands stall and then fail with CrossModule errors (reason HardwareFailed).

To resolve this, rebuild and re-sign the CodeSafe 5 application with the seejobs_port in the incoming tcp ports of its network-conf.json, or remove seejobs_transport=plain from the [codesafe] section to use the default SSH tunnel.

Non-SEEJobs Configuration

If SEEJobs are not being used, the seejobs_port option can be set to 0. The worldid_pubname option may still be specified, but may not be relevant unless the SEE World ID is needed for ticketing objects. Non-SEEJobs TCP protocols that are allowed in the CodeSafe 5 application’s firewall rules will be exposed on the 5c’s external network interface in this case.

[codesafe]
image_file=seemachine.cs5
seejobs_port=0
pull_rfs=yes

Encrypted Image Configuration

If the CodeSafe 5 image is encrypted, add the encryption_key field and set it to the ident of the seeconf key that protects the image. The key must be module-protected, and must be present in the Security World used by the appliance. For an unencrypted image, omit this field or leave it blank.

[codesafe]
image_file=seemachine.cs5
worldid_pubname=mysee
encryption_key=aes256seeconf
pull_rfs=yes

For information about creating encrypted images and their seeconf keys, see Encrypt a CodeSafe 5 image.

Copying the Configuration and CodeSafe 5 Application to the Appliance

For more information on the [codesafe] section, see CodeSafe 5 configuration section.

Permit the nShield 5c to have a configuration file pushed from a remote machine. By default, the configuration file can be pushed from the RFS machine, provided it is authenticated.

To allow another remote machine to push configuration, use the 5c’s Client config push menu from its front panel UI (menu 1-1-6-2).

Configure the nShield 5c to append its logs (hardserver and system logs) to the RFS once per minute in order to get timely feedback on CodeSafe 5 configuration operations. Alternatively, you can configure a remote UDP syslog server to receive streamed logs, or you can obtain the most recent logs that have not yet been pushed to the RFS on demand from a privileged client by using the following commands (replace -m1 with the module number of the 5c):

appliance-cli -m1 getservlog --log hardserver
appliance-cli -m1 getservlog --log system

Push the configuration to the nShield 5c using the cfg-pushnethsm utility.

On Linux:

cfg-pushnethsm -a <nShield 5c IP address> -m <module number> /opt/nfast/kmdata/hsm-<ESN>/config/config.new

On Windows:

cfg-pushnethsm -a <nShield 5c IP address> -m <module number> "C:\ProgramData\nCipher\Key Management Data\hsm-<ESN>\config\config.new"

Because the configuration is set with pull_rfs=yes, pushing it makes the nShield 5c to automatically fetch the CodeSafe 5 image, Developer ID certificates, and the encryption key (if configured) from the RFS into the appliance’s storage within a few seconds. If any of these files change on the RFS, push the configuration again with pull_rfs=yes to re-fetch them. The fetched files are cached in the appliance’s storage until they are explicitly removed; see Removing Cached CodeSafe 5 Files from the nShield 5c. This will not immediately apply the configuration to the HSM itself or stop any currently running CodeSafe 5 application, but will allow the new configuration to be applied on the next reboot or clear of the module, at which point the new CodeSafe 5 application will be loaded and started automatically.

Starting the CodeSafe 5 Application

Clear the nShield 5c to apply the new configuration and start the CodeSafe 5 application:

nopclearfail -m <module number> --clear --wait

Wait for the CodeSafe 5 application to be automatically loaded and started. Check the nShield 5c’s hardserver log (using one of the logging options explained in the previous section) for the following message, which indicates that the application has been started:

Startup: hsc_codesafe:INFO: READY: /config/see/machine/seemachine.cs5 running on <ESN> (#1); SEE World ID published as mysee; appliance-cli -m <module number> cs5 getlog <UUID> to retrieve logs

Note that seemachine.cs5 mentioned in the log message is the internal filename when it has been copied from the RFS. The actual file on the RFS with the original filename specified in the config file is what will have been copied.

Clients can now communicate with the CodeSafe 5 application.

See the Debugging CodeSafe 5 applications section for information about debugging a CodeSafe 5 application.

Stopping and Destroying the CodeSafe 5 Application

To stop or destroy the CodeSafe 5 application on the nShield 5c, use the following appliance-cli commands (replace -m1 with the module number of the 5c):

appliance-cli -m1 cs5 stop [<UUID>]
appliance-cli -m1 cs5 destroy [<UUID>]
  • cs5 stop gracefully terminates the application’s programs and stops its container. On success, it reports SEE machine stopped.

  • cs5 destroy removes the application container, and any user data created during the life of the application, from the HSM. Stop the application before you destroy it. On success, it reports SEE machine destroyed.

If you do not specify <UUID>, the command acts on the CodeSafe 5 application currently loaded on the HSM. The UUID is also reported in the READY message in the hardserver log; see Starting the CodeSafe 5 Application.

These commands are also available as cs5 stop and cs5 destroy from the nShield 5c serial console.

If auto-load is still configured, the CodeSafe 5 application is loaded and started again on the next reboot or clear of the module. To prevent this, set enabled=no in the [codesafe] section and push the configuration, or remove the cached CodeSafe 5 files as described in Removing Cached CodeSafe 5 Files from the nShield 5c.

These commands are not available when a remote CodeSafe 5 client is enrolled with the nShield 5c:

Unable to run command '<name>' - This command is not available when a remote CodeSafe 5 client is in use.

In this case, run csadmin stop and csadmin destroy from the enrolled client; see Stop a CodeSafe application and Destroy a CodeSafe application.

Removing Cached CodeSafe 5 Files from the nShield 5c

The CodeSafe 5 image and Developer ID certificates that the nShield 5c pulls from the RFS remain cached in the appliance’s storage. They are not removed when you delete the files from the RFS or when you remove a certificate from the HSM with appliance-cli cs5 certremove.

To delete the cached files from the nShield 5c storage:

  1. In the [codesafe] section of the config.new file for the nShield 5c on the RFS, set image_file to empty and set pull_rfs=yes:

    [codesafe]
    image_file=
    pull_rfs=yes
  2. Push the configuration to the nShield 5c using the cfg-pushnethsm utility, as described in Copying the Configuration and CodeSafe 5 Application to the Appliance.

When the configuration is pushed, the nShield 5c deletes the cached CodeSafe 5 image and all cached Developer ID certificates from its storage. No CodeSafe 5 application is auto-loaded on subsequent reboots or clears of the module until image_file is configured again.

To remove an application that is already loaded on the HSM, see Stopping and Destroying the CodeSafe 5 Application.

To resume auto-loading, set image_file to the required CodeSafe 5 image with pull_rfs=yes and push the configuration again. The nShield 5c then pulls the image and all Developer ID certificates currently in the cscerts volume on the RFS.

To remove a Developer ID certificate from the nShield 5c completely, see Remove a Developer ID certificate from an nShield 5c appliance.

The classic CodeSafe [load_seemachine] section on an nShield Connect XC or Connect+ supports the same behavior. See Removing SEE machines and cached files from an nShield Connect.