Main Content

changeCertificate

Change certificate of REST function connector

Since R2024a

    Description

    MATLAB® generates self-signed certificates which expire in 365 days. If the certificate has expired, or you want to use your own certificate or generate a new certificate, call the changeCertificate function. The function overwrites the existing certificate with the same name to the same location and overwrites the private key for the certificate in the desktop vault. To change the certificate on a currently running function connector, first call stop on the RESTFunctionConnectorObject object, then call changeCertificate.

    For more information, see HTTPS and Certificates.

    changeCertificate(conn) generates a new certificate and updates the certificate file at the location specified by the Certificate property of the connector conn.

    changeCertificate(conn,Name=Value) specifies paths to a certificate file and private key file using name-value arguments. For example, changeCertificate(conn,PrivateKey="C:\myDir\myPrivateKey.pem",Certificate="C:\myDir\myCertificate.pem") specifies a custom certificate and private key for the connector.

    example

    Examples

    collapse all

    To make an HTTPS request to a server, use the certificate on the client machine.

    Get a connector.

    conn = restFunctionConnector;
    conn.ClientAccessMode = remote;

    Specify a custom certificate with the PrivateKey and Certificate name-value arguments. The changeCertificate function copies the public key myPublicKey.pem located at C:\myDir to the location specified in the Certificate property of the connector, <mwPath>\restfcnconnector\publickey.pem.

    changeCertificate(conn,PrivateKey="C:\myDir\myPrivateKey.pem", ...
        Certificate="C:\myDir\myPublicKey.pem")
    conn = 
      RESTFunctionConnector with properties: 
     
                                 Port: 9920 
                          LogLocation: "<mwPath>\restfcnconnector\logs" 
                             HostName: "" 
                     ClientAccessMode: remote 
                         ServiceNames: 1x0 string 
              RESTPersonalAccessToken: "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA=" 
                  TokenExpirationDate: 19-Oct-2023 
                          Certificate: "<mwPath>\restfcnconnector\publickey.pem" 
            CertificateExpirationDate: 20-Mar-2024 
                              BaseUrl: "" 
                               Status: notrunning

    Input Arguments

    collapse all

    The REST function connector, specified as a RESTFunctionConnector object.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: changeCertificate(conn,PrivateKey="C:\myDir\myPrivateKey.pem",Certificate="C:\myDir\myCertificate.pem") specifies a custom certificate and private key for the connector.

    Path to the certificate private key (.pem) file, specified as a string scalar or character vector. If you specify this name-value argument, you also must specify the Certificate name-value argument.

    Example: "C:\myDir\myPrivateKey.pem"

    Path to the certificate (.pem) file, specified as a string scalar or character vector. If you specify this name-value argument, you also must specify the PrivateKey name-value argument. The function copies the certificate at the specified path to the location specified in the Certificate property of the connector conn.

    Example: "C:\myDir\myCertificate.pem"

    Version History

    Introduced in R2024a