Skip to content

Commit

Permalink
Merge pull request #21 from makamuy/master
Browse files Browse the repository at this point in the history
Add more info like hostname, port and date
  • Loading branch information
neykov authored Apr 19, 2024
2 parents 308145c + 9e7b95b commit dd22d5f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/name/neykov/secrets/MasterSecretCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import javax.crypto.SecretKey;
import javax.net.ssl.SSLSession;

import java.util.Date;
import java.text.SimpleDateFormat;

//Secrets file format:
//https://github.com/boundary/wireshark/blob/d029f48e4fd74b09848fc309630e5dfdc5d602f2/epan/dissectors/packet-ssl-utils.c#L4164-L4182
public class MasterSecretCallback {
Expand All @@ -27,14 +30,22 @@ public static void setSecretsFileName(String secretsFileName) {

public static void onMasterSecret(SSLSession sslSession, Key masterSecret) {
try {
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String dateNow = formatoFecha.format(new Date());

String peerHost = sslSession.getPeerHost();
int portHost = sslSession.getPeerPort();
String protocol = sslSession.getProtocol();
String cipherSuite = sslSession.getCipherSuite();
String sessionKey = bytesToHex(sslSession.getId());
String masterKey = bytesToHex(masterSecret.getEncoded());
write("RSA Session-ID:" + sessionKey + " Master-Key:" + masterKey);
write(dateNow + " RSA Session-ID:" + sessionKey + " peerHost:"+peerHost+":"+portHost + " CipherSuite:"+cipherSuite+ " Proto:"+protocol +" Master-Key:" + masterKey);
} catch (Exception e) {
log.log(Level.WARNING, "Error retrieving master secret from " + sslSession, e);
}
}


public static void onCalculateKeys(SSLSession sslSession, Object randomCookie, Key masterSecret) {
try {
String clientRandom = bytesToHex((byte[])get(randomCookie, "random_bytes"));
Expand Down

0 comments on commit dd22d5f

Please sign in to comment.