The certificate Common Name (CN) does not match with the expected CN

用户在使用修改版的ssl_client1.c程序访问Yahoo进行测试时遇到X.509证书验证错误,提示证书的通用名称(CN)与预期不符。通过更换程序为ssl_client2.c,问题得以解决,但原因未知。进一步测试发现,在多个版本的mbedtls库中,ssl_client1.c程序都会出现相同的CN验证错误,直到替换hostname参数后问题才得到解决。

原文地址:https://tls.mbed.org/discussions/bug-report-issues/verifying-peer-x-509-cert

Verifying peer X.509 Cert

 

Jan 20, 2016 21:05
Dan

I am using a modified version of ssl_client1.c to access yahoo for testing purposes. I assume their certs are installed correctly, but for some reason I keep getting the following error:

"The certificate Common Name (CN) does not match with the expected CN"

My modification to the ssl_client1.c is as follows:

    /*
     * 0.1 Initialize certificates
     */
    mbedtls_printf( "  . Loading the CA root certificate ..." );
    fflush( stdout );

    char cwd_buff[PATH_MAX + 1];
    getcwd( cwd_buff, PATH_MAX + 1 );
    strcat(cwd_buff, "\\Debug\\yahoo.crt");
    mbedtls_printf("CA File: %s ", cwd_buff);

    ret = mbedtls_x509_crt_parse_file(&cacert, cwd_buff);

    if( ret < 0 )
    {
        mbedtls_printf( " failed\n  !  mbedtls_x509_crt_parse returned -0x%x\n\n", -ret );
        goto exit;
    }

    mbedtls_printf( " ok (%d skipped)\n", ret );

I don't get any errors loading the cert and I do get the HTTP of Yahoo, its just the cert that seems to be off.

 

Jan 21, 2016 01:59
Dan

Interesting.....I just tried the ssl_client2.c program and it works fine. I guess I'm not doing something correct with using the cert. Any ideas why ssl_client1.c gives the CN error?

 

Feb 10, 2016 22:07
moraine

I reproduced the same issue using unmodified ssl_client1 and ssl_server example programs for the following versions : v2.2.1, v2.2.0 ,v2.1.4 , v1.3.16, but not with v1.2.19

For information, please find below the output of ssl_client1 when I meet the issue :

  . Seeding the random number generator... ok
  . Loading the CA root certificate ... ok (0 skipped)
  . Connecting to tcp/localhost/4433... ok
  . Setting up the SSL/TLS structure... ok
  . Performing the SSL/TLS handshake.../home/bmoraine/Desktop/mbed/mbedtls-2.2.0/library/ssl_tls.c:4400: x509_verify_cert() returned -9984 (-0x2700)
 ok
  . Verifying peer X.509 certificate... failed
  ! The certificate Common Name (CN) does not match with the expected CN

  > Write to server: 18 bytes written

GET / HTTP/1.0

  < Read from server: 150 bytes read

HTTP/1.0 200 OK
Content-Type: text/html

<h2>mbed TLS Test Server</h2>
<p>Successful connection using: TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384</p>
/home/bmoraine/Desktop/mbed/mbedtls-2.2.0/library/ssl_tls.c:6509: mbedtls_ssl_read_record() returned -30848 (-0x7880)
Last error was: -30848 - SSL - The peer notified us that the connection is going to be closed

Regarding ssl_server output no error is displayed :

  . Loading the server cert. and key... ok
  . Bind on https://localhost:4433/ ... ok
  . Seeding the random number generator... ok
  . Setting up the SSL data.... ok
  . Waiting for a remote connection ... ok
  . Performing the SSL/TLS handshake... ok
  < Read from client: 18 bytes read

GET / HTTP/1.0

  > Write to client: 150 bytes written

HTTP/1.0 200 OK
Content-Type: text/html

<h2>mbed TLS Test Server</h2>
<p>Successful connection using: TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384</p>

  . Closing the connection... ok
  . Waiting for a remote connection ...

Is there a regression in ssl_client1 example or in the library itself?

 

Feb 12, 2016 11:49
moraine

It seems I fix the issue by replacing hostname parameter in the call of mbedtls_ssl_set_hostname() on line 180

I replace :

  if( ( ret = mbedtls_ssl_set_hostname( &ssl, "mbed TLS Server 1" ) ) != 0 )
   {
        mbedtls_printf( " failed\n  ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
        goto exit;
    }

by

  if( ( ret = mbedtls_ssl_set_hostname( &pms->ssl, SERVER_NAME ) ) != 0 )
    {
        mbedtls_printf( " failed\n  ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
        goto exit;
    }

For information, SERVER_NAME is defined on line 63

#define SERVER_NAME "localhost"

and is used previously used by mbedtls_net_connect() on line 141

按上文中所述将if( ( ret = mbedtls_ssl_set_hostname( &pms->ssl, localhost) ) != 0 ) 即可

在处理输出设备名称与目标字节流设备名称不匹配的问题时,需要确保命令行参数与设备配置的一致性。例如,当使用 `tiff32nc` 作为输出设备时,目标字节流设备名称应与之匹配,否则可能导致输出设备无法正确识别或处理生成的数据流。 ### 参数一致性检查 在命令行中指定输出设备和颜色配置时,应确保所有参数与设备的特性保持一致。以下是一个命令行示例: ```bash -sDEVICE=tiff32nc -sOutputICCProfile=srgb.icc -sDeviceLinkProfile=linkRGBtoCMYK.icc ``` 在这个命令中,`-sDEVICE=tiff32nc` 指定了输出设备为 `tiff32nc`,它期望 CMYK 颜色模型。同时,`-sOutputICCProfile=srgb.icc` 指定了输出颜色空间为 sRGB,而 `-sDeviceLinkProfile=linkRGBtoCMYK.icc` 则指定了一个设备链接配置文件,用于将 sRGB 映射到 CMYK。这种配置是有效的,因为输出设备的颜色模型与设备链接配置文件的输出颜色空间一致[^1]。 ### 设备名称匹配 在处理标准输出设备名称与目标字节流设备名称不匹配的问题时,需要确保命令行参数中的设备名称与实际使用的设备名称一致。例如,如果使用 `tiff32nc` 作为输出设备,则目标字节流设备名称也应为 `tiff32nc`。如果设备名称不匹配,可能会导致输出设备无法正确识别或处理生成的数据流。 ### 示例代码 以下是一个简单的 Bash 脚本示例,用于检查设备名称是否匹配: ```bash #!/bin/bash # 定义输出设备名称 output_device="tiff32nc" # 定义目标字节流设备名称 target_device="tiff32nc" # 检查设备名称是否匹配 if [ "$output_device" == "$target_device" ]; then echo "设备名称匹配,可以继续执行。" else echo "设备名称不匹配,请检查配置。" fi ``` 在这个脚本中,首先定义了输出设备名称和目标字节流设备名称,然后通过 `if` 语句检查这两个名称是否匹配。如果不匹配,会输出提示信息,提醒用户检查配置。 ### 相关问题 1. 如何验证输出设备的颜色模型是否与设备链接配置文件的输出颜色空间一致? 2. 在命令行中指定输出设备和颜色配置时,有哪些常见的错误需要注意? 3. 如何编写一个 Bash 脚本来自动化检查设备名称是否匹配? 4. 如果设备名称不匹配,可能导致哪些具体的问题? 5. 在处理颜色管理时,如何确保不同设备之间的颜色空间转换正确无误?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值