Modify 'bssl client' to print the cert subject and issuer

This is the one piece of functionality I miss from the openssl tool -
the ability to see some basic information about the server cert.

Sample output:
==========
$ bssl client -connect www.google.com
Connecting to [2607:f8b0:4006:80d::1010]:443
Connected.
  Version: TLSv1.2
  Resumed session: no
  Cipher: ECDHE-RSA-AES128-GCM-SHA256
  ECDHE curve: P-256
  Secure renegotiation: yes
  Next protocol negotiated:
  ALPN protocol:
  Cert subject: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
  Cert issuer: /C=US/O=Google Inc/CN=Google Internet Authority G2
==========

Change-Id: I758682784752a616628138e420f52586d5a1bb31
Reviewed-on: https://boringssl-review.googlesource.com/7620
Reviewed-by: David Benjamin <davidben@google.com>
This commit is contained in:
Gabriel Redner 2016-04-06 15:47:28 -04:00 committed by David Benjamin
parent d44a943111
commit dcb3383463

View File

@ -44,6 +44,7 @@ typedef int ssize_t;
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include "internal.h"
#include "transport_common.h"
@ -191,6 +192,19 @@ void PrintConnectionInfo(const SSL *ssl) {
unsigned alpn_len;
SSL_get0_alpn_selected(ssl, &alpn, &alpn_len);
fprintf(stderr, " ALPN protocol: %.*s\n", alpn_len, alpn);
// Print the server cert subject and issuer names.
X509 *peer = SSL_get_peer_certificate(ssl);
if (peer != NULL) {
fprintf(stderr, " Cert subject: ");
X509_NAME_print_ex_fp(stderr, X509_get_subject_name(peer), 0,
XN_FLAG_ONELINE);
fprintf(stderr, "\n Cert issuer: ");
X509_NAME_print_ex_fp(stderr, X509_get_issuer_name(peer), 0,
XN_FLAG_ONELINE);
fprintf(stderr, "\n");
X509_free(peer);
}
}
bool SocketSetNonBlocking(int sock, bool is_non_blocking) {