Package net.i2p.data
Class EncryptedLeaseSet
- java.lang.Object
-
- net.i2p.data.DataStructureImpl
-
- net.i2p.data.DatabaseEntry
-
- net.i2p.data.LeaseSet
-
- net.i2p.data.LeaseSet2
-
- net.i2p.data.EncryptedLeaseSet
-
- All Implemented Interfaces:
Serializable,DataStructure
public class EncryptedLeaseSet extends LeaseSet2
Use getSigningKey() / setSigningKey() (revocation key in super) for the blinded key. PRELIMINARY - Subject to change - see proposal 123- Since:
- 0.9.38
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class net.i2p.data.LeaseSet2
_expires, _flags, _offlineSignature, _options, _published, _transientExpires, _transientSigningPublicKey
-
Fields inherited from class net.i2p.data.LeaseSet
_byteified, _checked, _destination, _encryptionKey, _lastExpiration, _leases, _receivedAsPublished, _signingKey, MAX_LEASES
-
Fields inherited from class net.i2p.data.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_RECORD
-
-
Constructor Summary
Constructors Constructor Description EncryptedLeaseSet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencrypt(int authType, List<? extends SimpleDataStructure> clientKeys)Throws IllegalStateException if not initialized.voidencrypt(SessionKey skey)Throws IllegalStateException if not initialized.booleanequals(Object object)LeaseSet2getDecryptedLeaseSet()PublicKeygetEncryptionKey(Set<EncType> supported)If more than one key, return the first supported one.List<PublicKey>getEncryptionKeys()This returns all the keys.HashgetHash()This must be used instead of getDestination().getHash().LeasegetLease(int index)intgetLeaseCount()protected SigningPublicKeygetSigningPublicKey()Overridden to return the blinded key so super.verifySignature() will work.intgetType()Get the type of the data structure.inthashCode()the destination has enough randomness in it to use it by itself for speedvoidreadBytes(InputStream in)This does NOT validate the signatureprotected voidreadHeader(InputStream in)Overridden because we have a blinded key, not a destprotected voidreadOfflineBytes(InputStream in)Overridden because we have a blinded key, not a destvoidsetClientPrivateKey(PrivateKey privKey)Must be set before verify for per-client auth.voidsetDestination(Destination dest)Overridden to set the blinded key.voidsetSecret(String secret)Must be set before sign or verify.voidsetSigningKey(SigningPublicKey spk)Overridden to set the blinded key.voidsign(SigningPrivateKey key)Sign the structure using the supplied signing key.voidsign(SigningPrivateKey key, int authType, List<? extends SimpleDataStructure> clientKeys)Sign the structure using the supplied signing key.intsize()Number of bytes, NOT including signatureStringtoString()booleanverifyOfflineSignature()Overridden because we have a blinded key, not a destbooleanverifySignature()Overridden to decrypt if possible, and verify inner sig also.booleanverifySignature(PrivateKey clientKey)Decrypt if possible, and verify inner sig also.protected voidwriteBytesWithoutSig(OutputStream out)Before encrypt() is called, the inner leaseset.protected voidwriteHeader(OutputStream out)Overridden because we have a blinded key, not a destprotected voidwriteOfflineBytes(OutputStream out)Overridden because we have a blinded key, not a dest-
Methods inherited from class net.i2p.data.LeaseSet2
addEncryptionKey, addLease, getBlindedHash, getBytes, getEncryptionKey, getExpires, getOption, getPublished, getReceivedAsPublished, getTransientExpiration, getTransientSigningKey, isBlindedWhenPublished, isCurrent, isOffline, isUnpublished, offlineSign, setBlindedHash, setBlindedWhenPublished, setOfflineSignature, setOptions, setUnpublished, verifyOfflineSignature, writeBody, writeBytes
-
Methods inherited from class net.i2p.data.LeaseSet
getDate, getDestination, getEarliestLeaseDate, getKeysAndCert, getLatestLeaseDate, getReceivedAsReply, getReceivedBy, getSigningKey, setEncryptionKey, setReceivedAsPublished, setReceivedAsReply, setReceivedBy, verifySignature
-
Methods inherited from class net.i2p.data.DatabaseEntry
getRoutingKey, getSignature, isLeaseSet, isLeaseSet, setSignature, validateRoutingKey
-
Methods inherited from class net.i2p.data.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
-
-
-
-
Method Detail
-
getDecryptedLeaseSet
public LeaseSet2 getDecryptedLeaseSet()
- Returns:
- leaseset or null if not decrypted.
- Since:
- 0.9.39
-
setSecret
public void setSecret(String secret)
Must be set before sign or verify. Must be called before setDestination() or setSigningKey(), or alpha will be wrong.- Parameters:
secret- null or "" for none (default)- Since:
- 0.9.39
-
setClientPrivateKey
public void setClientPrivateKey(PrivateKey privKey)
Must be set before verify for per-client auth.- Parameters:
privKey- non-null- Since:
- 0.9.41
-
getType
public int getType()
Description copied from class:DatabaseEntryGet the type of the data structure. This should be faster than instanceof.
-
getLeaseCount
public int getLeaseCount()
- Overrides:
getLeaseCountin classLeaseSet- Returns:
- 0-16, or 0 if not decrypted.
-
getLease
public Lease getLease(int index)
-
getEncryptionKeys
public List<PublicKey> getEncryptionKeys()
Description copied from class:LeaseSet2This 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.- Overrides:
getEncryptionKeysin classLeaseSet2- Returns:
- null if not decrypted.
- Since:
- 0.9.39
-
getEncryptionKey
public PublicKey getEncryptionKey(Set<EncType> supported)
If more than one key, return the first supported one. If none supported, return null.- Overrides:
getEncryptionKeyin classLeaseSet2- Parameters:
supported- what return types are allowed- Returns:
- first supported key or null
- Since:
- 0.9.44
-
setDestination
public void setDestination(Destination dest)
Overridden to set the blinded key. setSecret() MUST be called before this for non-null secret, or alpha will be wrong.- Overrides:
setDestinationin classLeaseSet- Parameters:
dest- non-null, must be EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519- Throws:
IllegalStateException- if already signedIllegalArgumentException- if not EdDSA
-
setSigningKey
public void setSigningKey(SigningPublicKey spk)
Overridden to set the blinded key. setSecret() MUST be called before this for non-null secret, or alpha will be wrong.- Overrides:
setSigningKeyin classLeaseSet2- Parameters:
spk- unblinded key non-null, must be EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519- Throws:
IllegalStateException- if already signedIllegalArgumentException- if not EdDSA- Since:
- 0.9.40
-
getSigningPublicKey
protected SigningPublicKey getSigningPublicKey()
Overridden to return the blinded key so super.verifySignature() will work.- Overrides:
getSigningPublicKeyin classDatabaseEntry- Returns:
- SPK or null
-
readBytes
public void readBytes(InputStream in) throws DataFormatException, IOException
This does NOT validate the signature- Specified by:
readBytesin interfaceDataStructure- Overrides:
readBytesin classLeaseSet2- 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
-
writeBytesWithoutSig
protected void writeBytesWithoutSig(OutputStream out) throws DataFormatException, IOException
Before encrypt() is called, the inner leaseset. After encrypt() is called, the encrypted data. Without sig. This does NOT validate the signature- Overrides:
writeBytesWithoutSigin classLeaseSet2- Throws:
DataFormatExceptionIOException
-
verifyOfflineSignature
public boolean verifyOfflineSignature()
Overridden because we have a blinded key, not a dest- Overrides:
verifyOfflineSignaturein classLeaseSet2
-
readHeader
protected void readHeader(InputStream in) throws DataFormatException, IOException
Overridden because we have a blinded key, not a dest- Overrides:
readHeaderin classLeaseSet2- Throws:
DataFormatExceptionIOException
-
writeHeader
protected void writeHeader(OutputStream out) throws DataFormatException, IOException
Overridden because we have a blinded key, not a dest- Overrides:
writeHeaderin classLeaseSet2- Throws:
DataFormatExceptionIOException
-
readOfflineBytes
protected void readOfflineBytes(InputStream in) throws DataFormatException, IOException
Overridden because we have a blinded key, not a dest- Overrides:
readOfflineBytesin classLeaseSet2- Throws:
DataFormatExceptionIOException
-
writeOfflineBytes
protected void writeOfflineBytes(OutputStream out) throws DataFormatException, IOException
Overridden because we have a blinded key, not a dest- Overrides:
writeOfflineBytesin classLeaseSet2- Throws:
DataFormatExceptionIOException
-
getHash
public Hash getHash()
This must be used instead of getDestination().getHash(). Overridden because we have a blinded key, not a dest. This is the hash of the signing public key type and the signing public key. Throws IllegalStateException if not initialized.- Overrides:
getHashin classDatabaseEntry- Returns:
- Hash or null
- Throws:
IllegalStateException
-
encrypt
public void encrypt(SessionKey skey)
Throws IllegalStateException if not initialized.- Overrides:
encryptin classLeaseSet2- Parameters:
skey- ignored- Throws:
IllegalStateException
-
encrypt
public void encrypt(int authType, List<? extends SimpleDataStructure> clientKeys)Throws IllegalStateException if not initialized. Ref: proposal 123- Parameters:
authType- 0, 1, or 3, see BlindDataclientKeys- The client's X25519 public or private keys, null if unused- Throws:
IllegalStateException
-
sign
public void sign(SigningPrivateKey key) throws DataFormatException
Sign the structure using the supplied signing key. Overridden because we sign the inner, then blind and encrypt and sign the outer.- Overrides:
signin classLeaseSet2- Throws:
IllegalStateException- if already signedDataFormatException
-
sign
public void sign(SigningPrivateKey key, int authType, List<? extends SimpleDataStructure> clientKeys) throws DataFormatException
Sign the structure using the supplied signing key. Overridden because we sign the inner, then blind and encrypt and sign the outer.- Parameters:
authType- 0, 1, or 3, see BlindDataclientKeys- X25519 public keys for DH, private keys for PSK- Throws:
IllegalStateException- if already signedDataFormatException- Since:
- 0.9.41
-
verifySignature
public boolean verifySignature()
Overridden to decrypt if possible, and verify inner sig also. Must call setDestination() prior to this if attempting decryption. Must call setClientKey() prior to this if attempting decryption.- Overrides:
verifySignaturein classLeaseSet2- Returns:
- valid
-
verifySignature
public boolean verifySignature(PrivateKey clientKey)
Decrypt if possible, and verify inner sig also. Must call setDestination() prior to this if attempting decryption.- Parameters:
clientKey- PrivateKey for DH or PSK, or null if none- Returns:
- valid
- Since:
- 0.9.41
-
hashCode
public int hashCode()
the destination has enough randomness in it to use it by itself for speed
-
-