Skip to content

Commit

Permalink
Modify 'bssl client' to print the cert subject and issuer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gredner authored and davidben committed Apr 7, 2016
1 parent d44a943 commit dcb3383
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tool/transport_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dcb3383

Please sign in to comment.