undefined reference to `DeviceAuth_GetCertificatePath' in 20.10

bill chadwick 136 Reputation points
2020-11-18T16:18:57.713+00:00

Az Sphere 20.10

Linking is giving undefined reference to `DeviceAuth_GetCertificatePath'

C:/Program Files (x86)/Microsoft Azure Sphere SDK/Sysroots/7/tools/gcc/real-ld.exe: CMakeFiles/PrivateNetworkServices.dir/main.c.obj: in function main': C:\Users\trt-dev6\azSphere\azure-sphere-samples-master\azure-sphere-samples-master\Samples\PrivateNetworkServices\out\ARM-Debug/../../main.c:448: undefined reference to DeviceAuth_GetCertificatePath'

Can anyone help resolve that please?

Azure Sphere
Azure Sphere
An Azure internet of things security solution including hardware, operating system, and cloud components.
157 questions
{count} votes

Accepted answer
  1. bill chadwick 136 Reputation points
    2020-11-19T12:11:35.897+00:00

    OK so it seems that to use DeviceAuth_GetCertificatePath

    that you must add tlsutils to the list of libraries in cMakeLists.txt

    So I guess failing to mention that is a deficiency of the azsphere documentation,

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. bill chadwick 136 Reputation points
    2020-11-19T17:21:42.117+00:00
    #define SSL_FILETYPE_PEM 1
    
     if (Application_IsDeviceAuthReady(&authReady) == 0) {
                if (authReady) {
                    const char *certPath = DeviceAuth_GetCertificatePath();
    
                    WOLFSSL_X509 *x509;
                    x509 = wolfSSL_X509_load_certificate_file(certPath, SSL_FILETYPE_PEM);
    
    
                    /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
    
    
                    /* extract subjectName  */
                    name = wolfSSL_X509_get_subject_name(x509);
                    if (name == NULL)
                        Log_Debug("wolfSSL_X509_get_subject_name failed");
                    else
                        Log_Debug("subject name:%s\n\r", wolfSSL_X509_NAME_oneline(name, subjectName, 80));
    
                    /* extract issuerName  */
                    name = wolfSSL_X509_get_issuer_name(x509);
                    if (name == NULL)
                        Log_Debug("wolfSSL_X509_get_issuer_name failed");
                    else
                        Log_Debug("issuer name:%s\n\r", wolfSSL_X509_NAME_oneline(name, issuerName, 80));
    
                    // see https://www.wolfssl.com/forums/topic958-using-notbefore-notafter.html
    
                    char *b = wolfSSL_X509_notBefore(x509);
                    Log_Debug("not before:%s\n\r", &b[2]);
                    char *a = wolfSSL_X509_notAfter(x509);
                    Log_Debug("not after:%s\n\r", &a[2]);
    
                    wolfSSL_X509_free(x509);
                }
            }
    

    prints out (tenant ID changed)

    subject name:

    issuer name:/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=tenanit-id-id-id

    not before:201119111252Z

    not after:201120121252Z