인증서 날짜, RSA key size 파싱 코드

2021. 12. 3. 13:21암호학/인증서

#include <stdio.h>
#include <string.h>
#include "mbedtls/ssl.h"

int main()
{
    char buf[1024];
    mbedtls_x509_crt srvcert;
    mbedtls_x509_crt_init( &srvcert );
    mbedtls_x509_crt_parse_file( &srvcert, "server.pem" );
    mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", &srvcert );
    char *buf2;
    char *buf3;

    buf2 = strstr(buf, "issued  on");
    buf2 = strtok(buf2, ":");
    buf2 = strtok(NULL, "\n");
    printf("Update = %s\n", buf2);

    buf2 = strtok(NULL, "\0");
    buf3 = strstr(buf2, "RSA key size");
    buf3 = strtok(buf3, ":");
    buf3 = strtok(NULL, "\n");
    printf("RSA Key size = %s\n", buf3);
    return 0;
}

'암호학 > 인증서' 카테고리의 다른 글

PQC(Post Quantum Cryptography) 양자 내성 암호  (0) 2021.11.26
x509 인증서 & 전자서명 심층분석  (0) 2021.11.26
/.vimrc ctags 코드  (0) 2021.11.24