public class LeaseSet2 extends LeaseSet
LeaseSet2 provides several enhancements over the original LeaseSet format:
Key differences from LeaseSet:
getPublished() for version comparison instead of lease datesgetEncryptionKeys()setOfflineSignature(long, SigningPublicKey, Signature)| Modifier and Type | Field and Description |
|---|---|
protected long | _expiresExpiration timestamp in ms (1-second resolution). |
protected int | _flagsFlags for options, offline, unpublished, blinded. |
protected Signature | _offlineSignatureOffline signature. |
protected Properties | _optionsOptions and statistics properties, may be null. |
protected long | _publishedPublished timestamp in ms (1-second resolution). |
protected long | _transientExpiresTransient key expiration in ms. |
protected SigningPublicKey | _transientSigningPublicKeyTransient signing public key for offline signing. |
_byteified, _checked, _destination, _encryptionKey, _lastExpiration, _leases, _signingKey, MAX_LEASES_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_RECORD| Constructor and Description |
|---|
LeaseSet2()Creates a new LeaseSet2 with default values. |
| Modifier and Type | Method and Description |
|---|---|
void | addEncryptionKey(PublicKey key)Add an encryption key. |
void | addLease(Lease lease)Must be a Lease2. |
void | encrypt(SessionKey key)Encrypt the gateway and tunnel ID of each lease, leaving the expire dates unchanged. |
boolean | equals(Object object) |
Hash | getBlindedHash()The orignal blinded hash, where this came from. |
protected byte[] | getBytes()without sig! |
PublicKey | getEncryptionKey()If more than one key, return the first supported one. |
PublicKey | getEncryptionKey(Set<EncType> supported)If more than one key, return the first supported one. |
List<PublicKey> | getEncryptionKeys()This returns all the keys. |
long | getExpires()Published expiration, as received. |
String | getOption(String opt)Get an option value by key. |
Properties | getOptions()Gets the leaseset options. |
long | getPublished()Published timestamp, as received. |
boolean | getReceivedAsPublished()If true, we received this LeaseSet by a remote peer publishing it to
us, AND the unpublished flag is not set. |
long | getTransientExpiration()Absolute time, not time from now. |
SigningPublicKey | getTransientSigningKey()Gets the transient public key for offline signing. |
int | getType()Lease set type for the network database. |
int | hashCode()the destination has enough randomness in it to use it by itself for speed |
boolean | isBlindedWhenPublished()Set if the unencrypted LS, when published, will be blinded/encrypted |
boolean | isCurrent(long fudge)Determine whether the leaseset is currently valid, at least within a given
fudge factor. |
boolean | isOffline()Checks if this leaseset uses offline keys. |
boolean | isUnpublished()True if unpublished. |
static Signature | offlineSign(long expires,
SigningPublicKey transientSPK,
SigningPrivateKey priv)Generate a Signature to pass to setOfflineSignature() |
void | readBytes(InputStream in)This does NOT validate the signature |
protected void | readHeader(InputStream in)Read the LeaseSet2 header from a stream. |
protected void | readOfflineBytes(InputStream in)Read the offline signing section from a stream. |
void | setBlindedHash(Hash bh)Set this on creation if known |
void | setBlindedWhenPublished()Set if the unencrypted LS, when published, will be blinded/encrypted |
boolean | setOfflineSignature(long expires,
SigningPublicKey transientSPK,
Signature offlineSig)Destination must be previously set. |
void | setOptions(Properties options)Configure a set of options or statistics that the router can expose. |
void | setPublished(long now)Set published timestamp. |
void | setSigningKey(SigningPublicKey key)The revocation key. |
void | setUnpublished()Marks this leaseset as unpublished. |
void | sign(SigningPrivateKey key)Sign the structure using the supplied signing key. |
int | size()Number of bytes, NOT including signature |
String | toString() |
boolean | verifyOfflineSignature()Verify the offline signature. |
protected boolean | verifyOfflineSignature(SigningPublicKey spk)Verify the offline signature with the given key. |
boolean | verifySignature()Verify with the SPK in the dest for online sigs. |
protected void | writeBody(OutputStream out)Without sig. |
void | writeBytes(OutputStream out)Including sig. |
protected void | writeBytesWithoutSig(OutputStream out)Without sig. |
protected void | writeHeader(OutputStream out)Write the LeaseSet2 header to a stream. |
protected void | writeOfflineBytes(OutputStream out)Write the offline signing section to a stream. |
getDate, getDestination, getEarliestLeaseDate, getKeysAndCert, getLatestLeaseDate, getLease, getLeaseCount, getSigningKey, setDestination, setEncryptionKey, setReceivedBygetHash, getReceivedAsReply, getReceivedBy, getRoutingKey, getSignature, getSigningPublicKey, isLeaseSet, isLeaseSet, isRouterInfo, setReceivedAsPublished, setReceivedAsReply, setSignature, validateRoutingKeycalculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayprotected long _expires
protected int _flags
protected Signature _offlineSignature
protected Properties _options
protected long _published
protected long _transientExpires
protected SigningPublicKey _transientSigningPublicKey
public void addEncryptionKey(PublicKey key)
public void addLease(Lease lease)
addLease in class LeaseSetlease - must be a Lease2IllegalArgumentException - if not a Lease2public void encrypt(SessionKey key)
public Hash getBlindedHash()
protected byte[] getBytes()
public PublicKey getEncryptionKey()
getEncryptionKey in class LeaseSetpublic PublicKey getEncryptionKey(Set<EncType> supported)
getEncryptionKey in class LeaseSetsupported - what return types are allowedpublic List<PublicKey> getEncryptionKeys()
public long getExpires()
public String getOption(String opt)
opt - the option keypublic Properties getOptions()
public long getPublished()
public boolean getReceivedAsPublished()
getReceivedAsPublished in class DatabaseEntrypublic long getTransientExpiration()
public SigningPublicKey getTransientSigningKey()
public int getType()
public int hashCode()
public boolean isBlindedWhenPublished()
public boolean isCurrent(long fudge)
public boolean isOffline()
public boolean isUnpublished()
public static Signature offlineSign(long expires, SigningPublicKey transientSPK, SigningPrivateKey priv)
expires - absolute mstransientSPK - the key that will sign the leasesetpriv - the private signing key for the destinationpublic void readBytes(InputStream in) throws DataFormatException, IOException
readBytes in interface DataStructurereadBytes in class LeaseSetin - stream to read fromIllegalStateException - if called more than once or Destination already setDataFormatException - if the data is improperly formattedIOException - if there was a problem reading the streamprotected void readHeader(InputStream in) throws DataFormatException, IOException
in - the input streamDataFormatException - if the data is invalidIOException - if there is an error readingprotected void readOfflineBytes(InputStream in) throws DataFormatException, IOException
in - the input streamDataFormatException - if the data is invalidIOException - if there is an error readingpublic void setBlindedHash(Hash bh)
public void setBlindedWhenPublished()
IllegalStateException - if already signedpublic boolean setOfflineSignature(long expires,
SigningPublicKey transientSPK,
Signature offlineSig)expires - absolute mstransientSPK - the key that will sign the leasesetofflineSig - the signature by the spk in the destinationIllegalStateException - if already signedpublic void setOptions(Properties options)
options - if null, clears current optionsIllegalStateException - if LeaseSet2 is already signedpublic void setPublished(long now)
public void setSigningKey(SigningPublicKey key)
setSigningKey in class LeaseSetpublic void setUnpublished()
IllegalStateException - if already signedpublic void sign(SigningPrivateKey key) throws DataFormatException
sign in class DatabaseEntrykey - the signing private keyIllegalStateException - if already signedDataFormatException - if signing failspublic int size()
public boolean verifyOfflineSignature()
protected boolean verifyOfflineSignature(SigningPublicKey spk)
spk - the key to verify againstpublic boolean verifySignature()
verifySignature in class LeaseSetprotected void writeBody(OutputStream out) throws DataFormatException, IOException
public void writeBytes(OutputStream out) throws DataFormatException, IOException
writeBytes in interface DataStructurewriteBytes in class LeaseSetout - stream to write toDataFormatException - if the data was incomplete or not yet ready to be writtenIOException - if there was a problem writing to the streamprotected void writeBytesWithoutSig(OutputStream out) throws DataFormatException, IOException
protected void writeHeader(OutputStream out) throws DataFormatException, IOException
out - the output streamDataFormatException - if the data is invalidIOException - if there is an error writingprotected void writeOfflineBytes(OutputStream out) throws DataFormatException, IOException
out - the output streamDataFormatException - if the data is invalidIOException - if there is an error writing