メインコンテンツ

setupTLSCertificate

Setup TLS certificate file for HTTPS and other protocols

Since R2026a

Description

setupTLSCertificate(target_object,enableHTTPS,certificatePath,keyPath) configures TLS certificate support on a target computer. Use this function to configure a target computer for HTTPS and other certificate and key-based protocols.

example

Examples

collapse all

The setupTLSCertificate function configures a target computer for HTTPS and other certificate and key-based protocols. When run with the enableHTTPS argument value true, the function provides the SSL certificate and private key, updates system configuration files, and restarts the Simulink® Real-Time™ daemons.

% This example shows how to use setupTLSCertificate 
% to configure HTTPS on a target computer

% Create target object for default target computer
tg = slrealtime;

% Connect to the target computer
connect(tg);

% Display target object TargetOptions 
% before enabling HTTPS
disp('Before enabling HTTPS');
disp(tg.TargetOptions);

% Define file names for certificate and key files
certFile = 'server.crt';
keyFile  = 'server.key';

% Generate private key by using openssl
disp('Generating private key...');
cmdKey = sprintf('openssl genrsa -out %s 2048', keyFile);
statusKey = system(cmdKey);
if statusKey ~= 0
    error('Failed to generate private key.');
end

% Generate self-signed certificate by using openssl
disp('Generating self-signed certificate...');
subject = '/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost';
cmdCert = sprintf('openssl req -new -x509 -key %s -out %s -days 365 -subj "%s"', ...
                  keyFile, certFile, subject);
statusCert = system(cmdCert);
if statusCert ~= 0
    error('Failed to generate certificate.');
end

fprintf('Certificate and key generated: %s %s\n', certFile, keyFile);

% Enable HTTPS on target computer by using 
% the generated certificate and key
disp('Enabling HTTPS on target...');
setupTLSCertificate(tg, 1, certFile, keyFile);

% Display target object TargetOptions 
% after enabling HTTPS
disp('After enabling HTTPS');
disp(tg.TargetOptions);

% Disable HTTPS on target computer
disp('Disabling HTTPS on target...');
setupTLSCertificate(tg, 0);

% Display target object TargetOptions 
% after disabling HTTPS
disp('After disabling HTTPS');
disp(tg.TargetOptions);

Input Arguments

collapse all

Object that represents target computer, specified as a Target object. The object provides access to methods that manipulate the target computer properties.

Example: tg

Indicates whether to enable (true) or disable (false) HTTPS protocol.

Example: false

Provides the name of the certificate file. The setupTLSCertificate function copies the certificate file to the target computer. This argument is required when enableHTTPS is true.

Example: 'server.crt'

Provides the name of the key file. The setupTLSCertificate function copies the key file to the target computer. This argument is required when enableHTTPS is true.

Example: 'server.key'

Version History

Introduced in R2026a