I'm trying to write the traffic secrets to an SSL keylog file so i could see my traffic in Wireshark.
With TLS 1.2 i had this modified CalculateKeyBlock function in TlsUtilities.cs:
internal static byte[] CalculateKeyBlock(TlsContext context, int size)
{
SecurityParameters securityParameters = context.SecurityParameters;
byte[] master_secret = securityParameters.MasterSecret;
byte[] seed = Concat(securityParameters.ServerRandom, securityParameters.ClientRandom);
if (IsSsl(context))
return CalculateKeyBlock_Ssl(master_secret, seed, size);
#if UNITY_EDITOR
// https://www.m00nie.com/2015/05/decrypt-https-ssltls-with-wireshark/
// https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format
string SSLKEYLOGFILE = Environment.GetEnvironmentVariable("SSLKEYLOGFILE", EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(SSLKEYLOGFILE))
using (var writer = new StreamWriter(System.IO.File.Open(SSLKEYLOGFILE, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)))
writer.Write(string.Format("# Generated by BestHTTP\r\nCLIENT_RANDOM {0} {1}",
BouncyCastle.Utilities.Encoders.Hex.ToHexString(securityParameters.ClientRandom),
BouncyCastle.Utilities.Encoders.Hex.ToHexString(master_secret)));
#endif
return PRF(context, master_secret, ExporterLabel.key_expansion, seed, size);
}
I don't know whether it was the best place to add, but it worked for my use case so i was happy with it.
However, I'm in trouble with TLS 1.3. For TLS 1.3 there are 7 labels (CLIENT_EARLY_TRAFFIC_SECRET, CLIENT_HANDSHAKE_TRAFFIC_SECRET, ..., EXPORTER_SECRET) and my understanding is that i should use at least 5 of them.
My guess is all the required fields can be found in the SecurityParameters class (that i can access through TlsClientProtocol's m_tlsClientContext.SecurityParameters), but i'm not sure what field matches what label (except for ClientRandom :) ).
To summ it up, I have two questions:
1.) What fields can be used for the following labels:
- CLIENT_EARLY_TRAFFIC_SECRET: the hex-encoded early traffic secret for the client side (for TLS 1.3)
- CLIENT_HANDSHAKE_TRAFFIC_SECRET: the hex-encoded handshake traffic secret for the client side (for TLS 1.3)
- SERVER_HANDSHAKE_TRAFFIC_SECRET: the hex-encoded handshake traffic secret for the server side (for TLS 1.3)
- CLIENT_TRAFFIC_SECRET_0: the first hex-encoded application traffic secret for the client side (for TLS 1.3)
- SERVER_TRAFFIC_SECRET_0: the first hex-encoded application traffic secret for the server side (for TLS 1.3)
- EARLY_EXPORTER_SECRET: the hex-encoded early exporter secret (for TLS 1.3).
- EXPORTER_SECRET: the hex-encoded exporter secret (for TLS 1.3)
2.) What could be the best place to write these out to the SSL Keylog file?
Thanks in advance!
I'm trying to write the traffic secrets to an SSL keylog file so i could see my traffic in Wireshark.
With TLS 1.2 i had this modified
CalculateKeyBlockfunction inTlsUtilities.cs:I don't know whether it was the best place to add, but it worked for my use case so i was happy with it.
However, I'm in trouble with TLS 1.3. For TLS 1.3 there are 7 labels (CLIENT_EARLY_TRAFFIC_SECRET, CLIENT_HANDSHAKE_TRAFFIC_SECRET, ..., EXPORTER_SECRET) and my understanding is that i should use at least 5 of them.
My guess is all the required fields can be found in the
SecurityParametersclass (that i can access throughTlsClientProtocol'sm_tlsClientContext.SecurityParameters), but i'm not sure what field matches what label (except forClientRandom:) ).To summ it up, I have two questions:
1.) What fields can be used for the following labels:
2.) What could be the best place to write these out to the SSL Keylog file?
Thanks in advance!