【问题标题】:Parse the Subject name of a X.509 certificate to a buffer将 X.509 证书的主题名称解析到缓冲区
【发布时间】:2021-03-16 04:30:29
【问题描述】:

我正在尝试将 X.509 证书的主题名称解析到缓冲区中,但我收到的是负值。可能出了什么问题?

   int32_t ret;
   size_t n = 0;
   uint8_t *p = NULL;
   mbedtls_x509_crt testcert;
   mbedtls_x509_crt_init(&testcert);
   if (ret = mbedtls_x509_crt_parse_file(&testcert, "testcert.pem"))
   {
     printf(" failed\n  !  mbedtls_x509_crt_parse_file returned -0x%04x\n\n", -ret);
     return ret;
   }
   ret = mbedtls_x509_dn_gets(p, n, &testcert.subject);
   if (ret <= 0)
   {
      printf("mbedtls_x509_dn_gets returned %02x", -ret);
      return ret;
   }

【问题讨论】:

    标签: c visual-studio cryptography pki mbedtls


    【解决方案1】:

    我在上面的代码 sn-p 中犯了错误。

    1. 我没有为指针 p 分配内存
    2. "n" 应该是 缓冲区的最大大小

    纠正这两件事后,我能够将 CN 解析为缓冲区。

    谢谢

    【讨论】:

    • p = malloc(sizeof(uint8_t)); ret = mbedtls_x509_dn_gets(p, MAX_DATA_SIZE, &clientcert.subject); MAX_DATA_SIZE = 4096
    猜你喜欢
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多