- 论坛徽章:
- 0
|
[code]
[root@localhost ssl]# ./a.out 74.125.155.109 993
socket created
address created
server connected
Connected with RC4-MD5 encryption
cert message:
cert: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
sender: /C=US/O=Google Inc/CN=Google Internet Authority
[root@localhost ssl]# vi ssl-client.c
Press ENTER or type command to continue
[root@localhost ssl]# cat ssl-client.c
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define MAXBUF 1024
void ShowCerts(SSL * ssl)
{
X509 *cert;
char *line;
cert = SSL_get_peer_certificate(ssl);
if (cert != NULL) {
printf("cert message:\n");
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
printf("cert: %s\n", line);
free(line);
line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
printf("sender: %s\n", line);
free(line);
X509_free(cert);
} else
printf("none cert |
|