9
9
package de .rub .nds .tlsscanner .probe .certificate ;
10
10
11
11
import de .rub .nds .tlsattacker .core .constants .SignatureAndHashAlgorithm ;
12
+
13
+ import java .io .IOException ;
14
+ import java .security .NoSuchAlgorithmException ;
12
15
import java .security .PublicKey ;
16
+ import java .security .MessageDigest ;
13
17
import java .util .Date ;
14
18
import org .bouncycastle .asn1 .x509 .Certificate ;
15
19
20
+ import javax .xml .bind .DatatypeConverter ;
21
+
16
22
/**
17
23
*
18
24
* @author Robert Merget - [email protected]
@@ -37,6 +43,8 @@ class CertificateReportImplementation implements CertificateReport {
37
43
private Boolean dnsCAA ;
38
44
private Boolean trusted ;
39
45
private Certificate certificate ;
46
+ private String sha256FingerprintHex ;
47
+
40
48
41
49
public CertificateReportImplementation () {
42
50
}
@@ -46,8 +54,21 @@ public Certificate getCertificate() {
46
54
return certificate ;
47
55
}
48
56
57
+ @ Override
58
+ public String getSHA256Fingerprint () {
59
+ return sha256FingerprintHex ;
60
+ }
61
+
49
62
public void setCertificate (Certificate certificate ) {
50
63
this .certificate = certificate ;
64
+ try {
65
+ this .sha256FingerprintHex = DatatypeConverter .printHexBinary (
66
+ MessageDigest .getInstance ("SHA-256" ).digest (certificate .getEncoded ())).toLowerCase ();
67
+ } catch (NoSuchAlgorithmException e ) {
68
+ e .printStackTrace ();
69
+ } catch (IOException e ) {
70
+ e .printStackTrace ();
71
+ }
51
72
}
52
73
53
74
@ Override
@@ -206,6 +227,7 @@ public void setTrusted(Boolean trusted) {
206
227
@ Override
207
228
public String toString () {
208
229
StringBuilder builder = new StringBuilder ();
230
+ builder .append ("Fingerprint: " ).append (sha256FingerprintHex ).append ("\n " );
209
231
if (subject != null ) {
210
232
builder .append ("Subject: " ).append (subject ).append ("\n " );
211
233
}
0 commit comments