forked from I2P_Developers/i2p.i2p
Router: Add preliminary support for more LS2 types (proposal 123)
I2CP: Don't require privkeys for meta in CLS2 message
This commit is contained in:
@@ -103,11 +103,34 @@ public abstract class DatabaseEntry extends DataStructureImpl {
|
||||
* Get the type of the data structure.
|
||||
* This should be faster than instanceof.
|
||||
*
|
||||
* @return KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET
|
||||
* @return KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET or LS2 types
|
||||
* @since 0.8.2
|
||||
*/
|
||||
public abstract int getType();
|
||||
|
||||
/**
|
||||
* Convenience method, is the type any variant of leaseset?
|
||||
*
|
||||
* @return true for any type of LeaseSet, false for RouterInfo, false for others
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public boolean isLeaseSet() {
|
||||
return isLeaseSet(getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method, is the type any variant of leaseset?
|
||||
*
|
||||
* @return true for any type of LeaseSet, false for RouterInfo, false for others
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public static boolean isLeaseSet(int type) {
|
||||
return type == KEY_TYPE_LEASESET ||
|
||||
type == KEY_TYPE_LS2 ||
|
||||
type == KEY_TYPE_ENCRYPTED_LS2 ||
|
||||
type == KEY_TYPE_META_LS2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw payload data, excluding the signature, to be signed by sign().
|
||||
*
|
||||
|
||||
@@ -9,8 +9,10 @@ import net.i2p.crypto.EncType;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.DatabaseEntry;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.EncryptedLeaseSet;
|
||||
import net.i2p.data.LeaseSet;
|
||||
import net.i2p.data.LeaseSet2;
|
||||
import net.i2p.data.MetaLeaseSet;
|
||||
import net.i2p.data.PrivateKey;
|
||||
import net.i2p.data.SigningPrivateKey;
|
||||
|
||||
@@ -24,6 +26,9 @@ import net.i2p.data.SigningPrivateKey;
|
||||
* serialized after the LeaseSet, not before, so we can
|
||||
* infer the types from the LeaseSet.
|
||||
*
|
||||
* For Meta LS:
|
||||
* SigningPrivateKey and PrivateKey are not present.
|
||||
*
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public class CreateLeaseSet2Message extends CreateLeaseSetMessage {
|
||||
@@ -43,26 +48,32 @@ public class CreateLeaseSet2Message extends CreateLeaseSetMessage {
|
||||
_leaseSet = new LeaseSet();
|
||||
} else if (type == DatabaseEntry.KEY_TYPE_LS2) {
|
||||
_leaseSet = new LeaseSet2();
|
||||
} else if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
|
||||
_leaseSet = new EncryptedLeaseSet();
|
||||
} else if (type == DatabaseEntry.KEY_TYPE_META_LS2) {
|
||||
_leaseSet = new MetaLeaseSet();
|
||||
} else if (type == -1) {
|
||||
throw new EOFException("EOF reading LS type");
|
||||
} else {
|
||||
throw new I2CPMessageException("Unsupported Leaseset type: " + type);
|
||||
}
|
||||
_leaseSet.readBytes(in);
|
||||
// In CLSM this is the type of the dest, but revocation is unimplemented.
|
||||
// In CLS2M this is the type of the signature (which may be different than the
|
||||
// type of the dest if it's an offline signature)
|
||||
// and is needed by the session tag manager.
|
||||
SigType stype = _leaseSet.getSignature().getType();
|
||||
if (stype == null)
|
||||
throw new I2CPMessageException("Unsupported sig type");
|
||||
_signingPrivateKey = new SigningPrivateKey(stype);
|
||||
_signingPrivateKey.readBytes(in);
|
||||
EncType etype = _leaseSet.getEncryptionKey().getType();
|
||||
if (etype == null)
|
||||
throw new I2CPMessageException("Unsupported encryption type");
|
||||
_privateKey = new PrivateKey(etype);
|
||||
_privateKey.readBytes(in);
|
||||
if (type != DatabaseEntry.KEY_TYPE_META_LS2) {
|
||||
// In CLSM this is the type of the dest, but revocation is unimplemented.
|
||||
// In CLS2M this is the type of the signature (which may be different than the
|
||||
// type of the dest if it's an offline signature)
|
||||
// and is needed by the session tag manager.
|
||||
SigType stype = _leaseSet.getSignature().getType();
|
||||
if (stype == null)
|
||||
throw new I2CPMessageException("Unsupported sig type");
|
||||
_signingPrivateKey = new SigningPrivateKey(stype);
|
||||
_signingPrivateKey.readBytes(in);
|
||||
EncType etype = _leaseSet.getEncryptionKey().getType();
|
||||
if (etype == null)
|
||||
throw new I2CPMessageException("Unsupported encryption type");
|
||||
_privateKey = new PrivateKey(etype);
|
||||
_privateKey.readBytes(in);
|
||||
}
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Error reading the CreateLeaseSetMessage", dfe);
|
||||
}
|
||||
@@ -70,7 +81,8 @@ public class CreateLeaseSet2Message extends CreateLeaseSetMessage {
|
||||
|
||||
@Override
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
if (_sessionId == null || _signingPrivateKey == null || _privateKey == null || _leaseSet == null)
|
||||
if (_sessionId == null || _leaseSet == null ||
|
||||
(_leaseSet.getType() != DatabaseEntry.KEY_TYPE_META_LS2 && (_signingPrivateKey == null || _privateKey == null)))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
int size = 4 // sessionId
|
||||
+ 1 // type
|
||||
@@ -82,8 +94,10 @@ public class CreateLeaseSet2Message extends CreateLeaseSetMessage {
|
||||
_sessionId.writeBytes(os);
|
||||
os.write(_leaseSet.getType());
|
||||
_leaseSet.writeBytes(os);
|
||||
_signingPrivateKey.writeBytes(os);
|
||||
_privateKey.writeBytes(os);
|
||||
if (_leaseSet.getType() != DatabaseEntry.KEY_TYPE_META_LS2) {
|
||||
_signingPrivateKey.writeBytes(os);
|
||||
_privateKey.writeBytes(os);
|
||||
}
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Error writing out the message data", dfe);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user