java.lang.Object
net.i2p.client.datagram.I2PDatagramDissector
Class for dissecting I2P repliable datagrams, checking the authenticity of the sender. Note that objects of this class are NOT THREAD SAFE!
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intLargest datagram buffer allocated.private final DSAEngineThe engine verifying the signature.private final SHA256GeneratorThe hash of the payload.private static final intSmallest size of a valid datagram.private DestinationThe destination received with the datagram.private byte[]The hash received with the datagram.private final byte[]The buffer holding the payload.private intLength of the received payload.private SignatureThe signature received with the datagram.private booleanTrue when the datagram passed the checks.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionExtract the hash of the payload of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.byte[]Extract the payload carried by an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.Extract the sender of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.getHash()Extract the hash of the payload of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), verifying the datagram signature.byte[]The payload carried by an I2P repliable datagram (previously loaded with theloadI2PDatagram(byte[])method), verifying the datagram signature.The sender of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), verifying the datagram signature.voidloadI2PDatagram(byte[] dgram) Load an I2P repliable datagram into the dissector.voidVerify the signature of this datagram (previously loaded with the loadI2PDatagram() method).
Field Details
DGRAM_BUFSIZE
private static final int DGRAM_BUFSIZELargest datagram buffer allocated.- See Also:
MIN_DGRAM_SIZE
private static final int MIN_DGRAM_SIZESmallest size of a valid datagram.- See Also:
dsaEng
The engine verifying the signature.hashGen
The hash of the payload.rxHash
private byte[] rxHashThe hash received with the datagram.rxSign
The signature received with the datagram.rxDest
The destination received with the datagram.rxPayload
private final byte[] rxPayloadThe buffer holding the payload.rxPayloadLen
private int rxPayloadLenLength of the received payload.valid
private boolean validTrue when the datagram passed the checks.
Constructor Details
I2PDatagramDissector
public I2PDatagramDissector()Crate a new I2P repliable datagram dissector.
Method Details
loadI2PDatagram
Load an I2P repliable datagram into the dissector. Does NOT verify the signature.Format is:
- Destination (387+ bytes)
- Signature (40+ bytes, type and length as implied by signing key type in the Destination)
- Payload
For DSA_SHA1 Destinations, the signature is of the SHA-256 Hash of the payload.
As of 0.9.14, for non-DSA_SHA1 Destinations, the signature is of the payload itself.
- Parameters:
dgram- non-null I2P repliable datagram to be loaded- Throws:
DataFormatException- If there's an error in the datagram format
getPayload
The payload carried by an I2P repliable datagram (previously loaded with theloadI2PDatagram(byte[])method), verifying the datagram signature.- Returns:
- A byte array containing the datagram payload
- Throws:
I2PInvalidDatagramException- if the signature verification fails
getSender
The sender of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), verifying the datagram signature.- Returns:
- The Destination of the I2P repliable datagram sender
- Throws:
I2PInvalidDatagramException- if the signature verification fails
getHash
Extract the hash of the payload of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), verifying the datagram signature.As of 0.9.14, for signature types other than DSA_SHA1, this returns null.
- Returns:
- The hash of the payload of the I2P repliable datagram
- Throws:
I2PInvalidDatagramException- if the signature verification fails
extractPayload
public byte[] extractPayload()Extract the payload carried by an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.- Returns:
- A byte array containing the datagram payload
extractSender
Extract the sender of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.- Returns:
- The Destination of the I2P repliable datagram sender
extractHash
Extract the hash of the payload of an I2P repliable datagram (previously loaded with the loadI2PDatagram() method), without verifying the datagram signature.As of 0.9.14, for signature types other than DSA_SHA1, this returns null.
- Returns:
- The hash of the payload of the I2P repliable datagram
verifySignature
Verify the signature of this datagram (previously loaded with the loadI2PDatagram() method).- Throws:
I2PInvalidDatagramException- if the signature is invalid