java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.DatabaseEntry
net.i2p.data.LeaseSet
net.i2p.data.LeaseSet2
- All Implemented Interfaces:
Serializable, DataStructure
- Direct Known Subclasses:
EncryptedLeaseSet, MetaLeaseSet
Implementation of LeaseSet2 as specified in Proposal 123: New NetDb Entries.
LeaseSet2 provides several enhancements over the original LeaseSet format:
- Support for multiple encryption keys with server preference ordering
- Offline signature support for reduced router load
- Published and expiration timestamps independent of lease times
- Options and statistics support
- Blinded and encrypted LeaseSet support
Key differences from LeaseSet:
- Uses
getPublished()for version comparison instead of lease dates - Supports multiple encryption keys via
getEncryptionKeys() - Includes offline signing capabilities via
setOfflineSignature(long, SigningPublicKey, Signature) - Has separate published and expires timestamps
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longExpiration timestamp in ms (1-second resolution).protected intFlags for options, offline, unpublished, blinded.protected SignatureOffline signature.protected PropertiesOptions and statistics properties, may be null.protected longPublished timestamp in ms (1-second resolution).protected longTransient key expiration in ms.protected SigningPublicKeyTransient signing public key for offline signing.Fields inherited from class LeaseSet
_byteified, _checked, _destination, _encryptionKey, _lastExpiration, _leases, _signingKey, MAX_LEASESModifier and TypeFieldDescriptionprotected byte[]Cached serialized byte array for performance.protected booleanWhether decryption has been attempted.protected DestinationDestination this LeaseSet is for.protected PublicKeyEncryption public key for the destination.protected longLatest expiration time among all leases.Leases must stay in the order received, or signature verification will fail.protected SigningPublicKeyRevocation or blinded signing key.static final intUnlimited before 0.6.3; 6 as of 0.6.3; Increased in version 0.9.Fields inherited from class DatabaseEntry
_signature, KEY_TYPE_ENCRYPTED_LS2, KEY_TYPE_LEASESET, KEY_TYPE_LS2, KEY_TYPE_META_LS2, KEY_TYPE_ROUTERINFO, KEY_TYPE_SERVICE_LIST, KEY_TYPE_SERVICE_RECORDModifier and TypeFieldDescriptionprotected SignatureCryptographic signature.static final intEncrypted LeaseSet 2 type.static final intLeaseSet (v1) type.static final intLeaseSet 2 type.static final intMeta LeaseSet 2 type.static final intRouter info type.static final intService list type.static final intService record type.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidAdd an encryption key.voidMust be a Lease2.voidencrypt(SessionKey key) Encrypt the gateway and tunnel ID of each lease, leaving the expire dates unchanged.booleanThe original blinded hash, where this came from.protected byte[]getBytes()Without the signature!If more than one key, return the first supported one.getEncryptionKey(Set<EncType> supported) If more than one key, return the first supported one.This returns all the keys.longPublished expiration, as received.Option value for the given key.Leaseset options.longPublished timestamp, as received.booleanIf true, we received this LeaseSet by a remote peer publishing it to us, AND the unpublished flag is not set.longAbsolute time, not time from now.Transient public key for offline signing.intgetType()Lease set type for the network database.inthashCode()The destination has enough randomness in it to use it by itself for speed.booleanWhether the unencrypted LS, when published, will be blinded/encrypted.booleanisCurrent(long fudge) Determine whether the leaseset is currently valid, at least within a given fudge factor.booleanChecks if this leaseset uses offline keys.booleanTrue if unpublished.static SignatureofflineSign(long expires, SigningPublicKey transientSPK, SigningPrivateKey priv) Generate a Signature to pass tosetOfflineSignature(long, SigningPublicKey, Signature).voidreadBytes(InputStream in) This does NOT validate the signature.protected voidRead the LeaseSet2 header from a stream.protected voidRead the offline signing section from a stream.voidsetBlindedHash(Hash bh) Blinded hash, if known at creation.voidMark the unencrypted LS to be blinded/encrypted when published.booleansetOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) Destination must be previously set.voidsetOptions(Properties options) Configure a set of options or statistics that the router can expose.voidsetPublished(long now) Published timestamp.voidThe revocation key.voidMarks this leaseset as unpublished.voidsign(SigningPrivateKey key) Sign the structure using the supplied signing key.intsize()Number of bytes, NOT including signature.toString()booleanVerify the offline signature.protected booleanVerify the offline signature with the given key.booleanVerify with the SPK in the dest for online sigs.protected voidwriteBody(OutputStream out) Without sig.voidwriteBytes(OutputStream out) Including sig.protected voidWithout sig.protected voidwriteHeader(OutputStream out) Write the LeaseSet2 header to a stream.protected voidWrite the offline signing section to a stream.Methods inherited from class LeaseSet
getDate, getDestination, getEarliestLeaseDate, getKeysAndCert, getLatestLeaseDate, getLease, getLeaseCount, getSigningKey, setDestination, setEncryptionKey, setReceivedByModifier and TypeMethodDescriptionlonggetDate()Same asLeaseSet.getEarliestLeaseDate().Warning - will be null for LS2 EncryptedLeaseSets if not decrypted.longRetrieve the end date of the earliest lease included in this leaseSet.Keys and certificate for this lease set.longRetrieve the end date of the latest lease included in this leaseSet.getLease(int index) Lease at the given index.intNumber of leases in this leaseset.The revocation key.voidsetDestination(Destination dest) Destination for this leaseset.voidsetEncryptionKey(PublicKey encryptionKey) Encryption public key for this leaseset.voidsetReceivedBy(Hash localClient) Record the local client that received this leaseset.Methods inherited from class DatabaseEntry
getHash, getReceivedAsReply, getReceivedBy, getRoutingKey, getSignature, getSigningPublicKey, isLeaseSet, isLeaseSet, isRouterInfo, setReceivedAsPublished, setReceivedAsReply, setSignature, validateRoutingKeyModifier and TypeMethodDescriptiongetHash()A common interface to the Hash of the two subclasses.booleanIf true, we received this LeaseSet by searching for it Default false.The Hash of the local client that received this LS, null if the router or unknown.Routing key for the structure using the current modifier in the RoutingKeyGenerator.Retrieve the proof that the identity stands behind the info here.protected SigningPublicKeyIdentical to getDestination().DatabaseEntry.getSigningPublicKey()in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.booleanConvenience method, is the type any variant of leaseset?static booleanisLeaseSet(int type) Convenience method, is the type any variant of leaseset?booleanConvenience method, is the type any variant of router info?voidMarks this entry as received via published mode.voidMarks this entry as received via reply.voidsetSignature(Signature signature) Configure the proof that the entity stands behind the info here.booleanValidates the routing key for this entry.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.
Field Details
_flags
protected int _flagsFlags for options, offline, unpublished, blinded._published
protected long _publishedPublished timestamp in ms (1-second resolution)._expires
protected long _expiresExpiration timestamp in ms (1-second resolution)._transientExpires
protected long _transientExpiresTransient key expiration in ms._transientSigningPublicKey
Transient signing public key for offline signing._offlineSignature
Offline signature._options
Options and statistics properties, may be null.
Constructor Details
LeaseSet2
public LeaseSet2()Creates a new LeaseSet2 with default values.
Method Details
getPublished
public long getPublished()Published timestamp, as received. Different than getDate() or getEarliestLeaseDate(), which are the earliest lease expiration.Use this for LS2 version comparison, NOT getEarliestLeaseDate(), because that will return -1 for EncryptedLS and MetaLS.
- Returns:
- in ms, with 1 second resolution
setPublished
public void setPublished(long now) Published timestamp. Will be rounded to nearest second. If not called, will be set on write.- Parameters:
now- the publication time in milliseconds since the epoch, rounded to the nearest second before being stored
getExpires
public long getExpires()Published expiration, as received. May be different than getLatestLeaseDate(), which is the latest lease expiration.- Returns:
- in ms, with 1 second resolution
isUnpublished
public boolean isUnpublished()True if unpublished.- Returns:
- true if unpublished
setUnpublished
public void setUnpublished()Marks this leaseset as unpublished.- Throws:
IllegalStateException- if already signed
isBlindedWhenPublished
public boolean isBlindedWhenPublished()Whether the unencrypted LS, when published, will be blinded/encrypted.- Returns:
- whether blinded when published
setBlindedWhenPublished
public void setBlindedWhenPublished()Mark the unencrypted LS to be blinded/encrypted when published.- Throws:
IllegalStateException- if already signed
getReceivedAsPublished
public boolean getReceivedAsPublished()If true, we received this LeaseSet by a remote peer publishing it to us, AND the unpublished flag is not set. Default false.- Overrides:
getReceivedAsPublishedin classDatabaseEntry- Returns:
- the received as published
getOption
getOptions
getEncryptionKey
If more than one key, return the first supported one. If none supported, return the first one.- Overrides:
getEncryptionKeyin classLeaseSet- Returns:
- the encryption key
getEncryptionKey
If more than one key, return the first supported one. If none supported, return null.- Overrides:
getEncryptionKeyin classLeaseSet- Parameters:
supported- what return types are allowed- Returns:
- first supported key or null
addEncryptionKey
Add an encryption key.Encryption keys should be added in order of server preference, most-preferred first.
- Parameters:
key- the key to append; the first one added becomes the key returned bygetEncryptionKey()
getEncryptionKeys
This returns all the keys. getEncryptionKey() returns the first one.Encryption keys should be in order of server preference, most-preferred first. Client behavior should be to select the first key with a supported encryption type. Clients may use other selection algorithms based on encryption support, relative performance, and other factors.
- Returns:
- not a copy, do not modify, null if none
setOptions
Configure a set of options or statistics that the router can expose. Makes a copy, and replaces any options set previously.- Parameters:
options- if null, clears current options- Throws:
IllegalStateException- if LeaseSet2 is already signed
isOffline
public boolean isOffline()Checks if this leaseset uses offline keys.- Returns:
- true if the leaseset is signed with transient offline keys
getTransientSigningKey
Transient public key for offline signing.- Returns:
- transient public key or null if not offline signed
getTransientExpiration
public long getTransientExpiration()Absolute time, not time from now.- Returns:
- transient expiration time or 0 if not offline signed
setOfflineSignature
public boolean setOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) Destination must be previously set.- Parameters:
expires- when the offline signature stops being valid, in milliseconds since the epochtransientSPK- the key that will sign the leasesetofflineSig- the signature by the spk in the destination- Returns:
- success, false if verify failed or expired
- Throws:
IllegalStateException- if already signed
offlineSign
public static Signature offlineSign(long expires, SigningPublicKey transientSPK, SigningPrivateKey priv) Generate a Signature to pass tosetOfflineSignature(long, SigningPublicKey, Signature).- Parameters:
expires- when the offline signature stops being valid, in milliseconds since the epoch; the signature covers whole seconds onlytransientSPK- the key that will sign the leasesetpriv- the private signing key for the destination- Returns:
- null on error
verifyOfflineSignature
public boolean verifyOfflineSignature()Verify the offline signature.- Returns:
- true if valid
verifyOfflineSignature
Verify the offline signature with the given key.- Parameters:
spk- the key to verify against- Returns:
- true if valid
setBlindedHash
Blinded hash, if known at creation.- Parameters:
bh- the blinded hash of this leaseset's destination, as computed at creation time for an encrypted LeaseSet2
getBlindedHash
The original blinded hash, where this came from.- Returns:
- null if unknown or not previously blinded
getType
setSigningKey
The revocation key. Overridden to do nothing, as we're using the _signingKey field for the blinded key in Enc LS2.- Overrides:
setSigningKeyin classLeaseSet- Parameters:
key- the revocation key, which must match the signing public key type of the destination or the leaseset cannot be verified
isCurrent
public boolean isCurrent(long fudge) Determine whether the leaseset is currently valid, at least within a given fudge factor. Overridden to use the expiration time instead of the last expiration.getBytes
readBytes
This does NOT validate the signature.- Specified by:
readBytesin interfaceDataStructure- Overrides:
readBytesin classLeaseSet- Parameters:
in- stream to read from- Throws:
IllegalStateException- if called more than once or Destination already setDataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
writeBytes
Including sig. This does NOT validate the signature.- Specified by:
writeBytesin interfaceDataStructure- Overrides:
writeBytesin classLeaseSet- Parameters:
out- stream to write to- Throws:
DataFormatException- if the data was incomplete or not yet ready to be writtenIOException- if there was a problem writing to the stream
writeBytesWithoutSig
Without sig. This does NOT validate the signature.- Parameters:
out- the stream to write the header and body to- Throws:
DataFormatException- if the destination or encryption key is unsetIOException- if the stream cannot be written
writeBody
Without sig. This does NOT validate the signature.- Parameters:
out- the stream to write the properties, encryption keys and leases to- Throws:
DataFormatException- if the leases or a key cannot be serializedIOException- if the stream cannot be written
readHeader
Read the LeaseSet2 header from a stream.- Parameters:
in- the input stream- Throws:
DataFormatException- if the data is invalidIOException- if there is an error reading
writeHeader
Write the LeaseSet2 header to a stream.- Parameters:
out- the output stream- Throws:
DataFormatException- if the data is invalidIOException- if there is an error writing
readOfflineBytes
Read the offline signing section from a stream.- Parameters:
in- the input stream- Throws:
DataFormatException- if the data is invalidIOException- if there is an error reading
writeOfflineBytes
Write the offline signing section to a stream.- Parameters:
out- the output stream- Throws:
DataFormatException- if the data is invalidIOException- if there is an error writing
size
addLease
Must be a Lease2.- Overrides:
addLeasein classLeaseSet- Parameters:
lease- must be a Lease2- Throws:
IllegalArgumentException- if not a Lease2
sign
Sign the structure using the supplied signing key. Overridden because LS2 sigs cover the type byte.- Overrides:
signin classDatabaseEntry- Parameters:
key- the signing private key- Throws:
IllegalStateException- if already signedDataFormatException- if signing fails
verifySignature
public boolean verifySignature()Verify with the SPK in the dest for online sigs. Verify with the SPK in the offline sig section for offline sigs.- Overrides:
verifySignaturein classLeaseSet- Returns:
- true if a non-RSA signature is present and verifies against the online or offline signing key as appropriate
equals
hashCode
toString
encrypt
Encrypt the gateway and tunnel ID of each lease, leaving the expire dates unchanged. This adds an extra dummy lease, because AES data must be padded to 16 bytes. The fact that it is encrypted is not stored anywhere. Must be called after all the leases are in place, but before sign().