4using System.Collections.Generic;
22 private const byte MarkByte = 0xFF;
35 _commandSpyChannel =
new PdMessageSecureChannelBase(_context);
46 return SkipMarkBytes(data)[1];
55 private static ReadOnlySpan<byte> SkipMarkBytes(ReadOnlySpan<byte> data)
58 while (index < data.Length && data[index] == MarkByte)
63 return data.Slice(index);
73 var command =
new IncomingMessage(SkipMarkBytes(data), _commandSpyChannel);
95 _context.UpdateSecurityKey(keyConfiguration.KeyData);
108 var reply =
new IncomingMessage(SkipMarkBytes(data), _replySpyChannel);
126 _context.IsUsingDefaultKey = isUsingDefaultKey;
129 command.IsUsingDefaultKey = isUsingDefaultKey;
133 var crypto = _context.CreateCypher(
true);
135 [0x01, 0x82, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
137 [0x01, 0x01, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
139 [0x01, 0x02, rndA[0], rndA[1], rndA[2], rndA[3], rndA[4], rndA[5]]);
145 var serverCryptogram = command.
Payload;
146 using var crypto = _context.CreateCypher(
true, _context.SMac1);
147 var intermediate =
SecurityContext.GenerateKey(crypto, serverCryptogram);
148 crypto.Key = _context.SMac2;
155 _context.IsSecurityEstablished =
true;
166 const byte replyAddress = 0x80;
170 return new Packet(message);
200 var lines = json.Split(
'\n');
201 foreach (var line
in lines)
203 if (
string.IsNullOrWhiteSpace(line))
continue;
205 dynamic? entry = JsonSerializer.Deserialize<ExpandoObject>(line);
206 if (entry ==
null)
continue;
208 DateTime dateTime =
new DateTime(1970, 1, 1).AddSeconds(
double.Parse(entry.timeSec.ToString()))
209 .AddTicks(
long.Parse(entry.timeNano.ToString()) / 100L);
211 string data = entry.data.ToString();
220 entry.osdpTraceVersion.ToString(),
221 entry.osdpSource.ToString());
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.
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.