在用C编码的SSL服务器中,我试图捕获浏览器标题,服务器在linux机器上的端口443上运行,也通过在Windows \ System32 \ drivers中的hosts文件中添加服务器名称来解析主机名\ etc \ hosts SSL握手似乎成功,但SSL_read失败,请帮忙,也请在下面找到服务器信息输出:
ssl = SSL_new(ctx);
RETURN_NULL(ssl);
if(SSL_set_fd(ssl, client_s)<0)
printf("\n error in assigning socket to SSL:");
else
printf("\n The socket has been assigned to SSL Structure");
/* Perform SSL Handshake on the SSL server */
err = SSL_accept(ssl);
printf("\n Value of err is %d",err);
RETURN_ERR(err,"SSL_accept");
if(err==1)
printf("\n The ssl connection/Handshake has been successful");
else
printf("\n The ssl connection was not successful");
/* Informational output (optional) */
printf("\n SSL connection using %s\n", SSL_get_cipher (ssl));
/*receive the data from the client*/
//err = SSL_accept(ssl);
while(i<5)
{
err = SSL_read(ssl, in_buf, strlen(in_buf));
printf("\n value of err is %d",err);
RETURN_ERR(err,"SSL_read");
printf("\n The details from the server is\n: %s,\n Bytes Read : %d",in_buf,err);
if(err<0)
printf("\n Not Successfully received clients information");
i++;
}
err = SSL_shutdown(ssl);
/* Terminate communication on a socket */
err = close(server_s);
/* Free the SSL structure */
SSL_free(ssl);
/* Free the SSL_CTX structure */
SSL_CTX_free(ctx);
return(0);
}
我使用IE(url:https://myserver.com/test2.jpg)获得上述代码的输出如下:
root@unnidevelubuntu:/programs# gcc -lssl trial11.c -o trial11
root@unnidevelubuntu:/programs# ./trial11
Available ciphers and digests has been registered :
New SSL_CTX object created successfully :
Enter PEM pass phrase:
The key & Certificate has been loaded successfully :
Server is waiting for a TCP/IP Connection :
private key matches the certificate public key :server is ready ...
Connection from 192.168.0.15, port 56969
a new client arrives ...
The socket has been assigned to SSL Structure
Value of err is 1
The ssl connection/Handshake has been successful
SSL connection using RC4-SHA
value of err is 0
The details from the server is
: ,
Bytes Read : 0
value of err is 0
The details from the server is
: ,
Bytes Read : 0
value of err is 0
The details from the server is
: ,
Bytes Read : 0
value of err is 0
The details from the server is
答案 0 :(得分:0)
上面的问题已经解决,问题是在SSL_read中使用strlen如下: err = SSL_read(ssl,in_buf,strlen(in_buf)); printf(“\ n err的值是%d”,错误); RETURN_ERR(ERR “SSL_read”);
而不是SSL_read,您需要使用sizeof,并且程序运行正常,它会为您提供浏览器的标题。