java - Extract certificate from SSLContext -
i'm creating sslcontext in standard way:
- take .p12 certificate file,
- create keystore , load certificate it,
- create keymanagerfactory, init keystore, , keymanagers,
- create trustmanagerfactory, init null, , trustmanagers.
- create sslcontext , init keymanagers , trustmanagers.
the question - how can extract keystore , certificate data sslcontext? task obtain fingerprint hash certficate.
is possible or have separately, reading certificate file?
it can done if have custom trustmanager. can refer link custom class. private savingtrustmanager
static class.
and place using java's default trustmanager, use class can retrieve certificate server sent.
sslcontext context = sslcontext.getinstance("tls"); trustmanagerfactory tmf = trustmanagerfactory.getinstance(trustmanagerfactory.getdefaultalgorithm()); tmf.init(dummytruststore); x509trustmanager defaulttrustmanager = (x509trustmanager) tmf.gettrustmanagers()[0]; savingtrustmanager savingtrustmanager = new savingtrustmanager(defaulttrustmanager); context.init(null, new trustmanager[] { savingtrustmanager }, null); sslsocketfactory factory = context.getsocketfactory();
and after have started handshake, can certificates savingtrustmanager static member variable chain
, like:
savingtrustmanager.chain
Comments
Post a Comment