4using System.Collections.Generic;
6using System.Globalization;
23 private const byte MarkByte = 0xFF;
36 _commandSpyChannel =
new PdMessageSecureChannelBase(_context);
47 return SkipMarkBytes(data)[1];
56 private static ReadOnlySpan<byte> SkipMarkBytes(ReadOnlySpan<byte> data)
59 while (index < data.Length && data[index] == MarkByte)
64 return data.Slice(index);
74 var command =
new IncomingMessage(SkipMarkBytes(data), _commandSpyChannel);
96 _context.UpdateSecurityKey(keyConfiguration.KeyData);
109 var reply =
new IncomingMessage(SkipMarkBytes(data), _replySpyChannel);
127 _context.IsUsingDefaultKey = isUsingDefaultKey;
130 command.IsUsingDefaultKey = isUsingDefaultKey;
134 var crypto = _context.CreateCypher(
true);
136 [0x01, 0x82, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
138 [0x01, 0x01, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
140 [0x01, 0x02, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
146 var serverCryptogram = command.
Payload;
147 using var crypto = _context.CreateCypher(
true, _context.SMac1);
148 var intermediate =
SecurityContext.GenerateKey(crypto, serverCryptogram);
149 crypto.Key = _context.SMac2;
156 _context.IsSecurityEstablished =
true;
167 const byte replyAddress = 0x80;
171 return new Packet(message);
201 var lines = json.Split(
'\n');
202 foreach (var line
in lines)
204 if (
string.IsNullOrWhiteSpace(line))
continue;
206 dynamic? entry = JsonSerializer.Deserialize<ExpandoObject>(line);
207 if (entry ==
null)
continue;
209 DateTime dateTime =
new DateTime(1970, 1, 1)
210 .AddSeconds(
double.Parse(entry.timeSec.ToString(), CultureInfo.InvariantCulture))
211 .AddTicks(
long.Parse(entry.timeNano.ToString(), CultureInfo.InvariantCulture) / 100L);
213 string data = entry.data.ToString();
220 if (!IsCompleteFrame(SkipMarkBytes(rawData)))
continue;
228 entry.osdpTraceVersion.ToString(),
229 entry.osdpSource.ToString());
239 private static bool IsCompleteFrame(ReadOnlySpan<byte> data)
242 const int minimumFrameSize = 7;
244 return data.Length >= minimumFrameSize &&
246 (data[2] | (data[3] << 8)) == data.Length;
Represents a message that was received from the wire.
bool IsPayloadDecrypted
Indicates whether the payload was successfully decrypted.
byte[] SecureBlockData
Raw security block bytes.
byte[] Payload
Returns the raw message payload.
const byte StartOfMessage
OSDP message SOM (start of the message) byte.
Message channel which represents the Access Control Unit (ACU) side of the OSDP communications (i....
V2 implementation of a SecureChannel class.
Security context used within MessageSecureChannel.
Command data to set the encryption key configuration on a PD.
static EncryptionKeyConfiguration ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Information details of a message packet.
IEnumerable< OSDPCaptureEntry > ParseCaptureFile(string json)
Parses an OSDP capture file in JSON format.
bool TryParsePacket(byte[] data, out Packet? packet)
Attempts to parse raw OSDP data into a Packet without throwing exceptions.
byte PeekAddressByte(ReadOnlySpan< byte > data)
Retrieves the address byte from raw OSDP data without parsing the entire message.
Packet ParsePacket(byte[] data)
Parses raw OSDP data into a Packet, automatically detecting command vs.
IncomingMessage ParseCommand(byte[] data)
Parses raw OSDP command data into an IncomingMessage, handling the secure channel establishment.
IncomingMessage ParseReply(byte[] data)
Parses raw OSDP reply data into an IncomingMessage, handling the secure channel establishment.
MessageSpy(byte[]? securityKey=null)
Initializes a new instance of the MessageSpy class with an optional security key.
One line entry of a file that captures OSDP messages.
Helper routines for manipulating binary representations of data that are used within the OSDP....
static IEnumerable< byte > HexToBytes(IEnumerable< char > seq)
Convert a sequence of hex digit characters into their byte representation.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
@ InitialRMac
osdp_RMAC_I - client cryptogram packet and the initial R-MAC
CommandType
Identifies the type of OSDP protocol command (ACU -> PD) message.
@ ServerCryptogram
osdp_SCRYPT - server's random number and server cryptogram
@ KeySet
osdp_KEYSET - Encryption key set
@ SessionChallenge
osdp_CHLNG - challenge and secure session initialization request
TraceDirection
Direction of trace.