forked from I2P_Developers/i2p.i2p
Data: Consolidate offline key check
i2ptunnel: Prevent registration auth if key offline
This commit is contained in:
@ -577,7 +577,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
SigType dtype = _myDestination.getSigningPublicKey().getType();
|
||||
_signingPrivateKey = new SigningPrivateKey(dtype);
|
||||
_signingPrivateKey.readBytes(destKeyStream);
|
||||
if (isOffline(_signingPrivateKey)) {
|
||||
if (_signingPrivateKey.isOffline()) {
|
||||
_offlineExpiration = DataHelper.readLong(destKeyStream, 4) * 1000;;
|
||||
int itype = (int) DataHelper.readLong(destKeyStream, 2);
|
||||
SigType type = SigType.getByCode(itype);
|
||||
@ -593,19 +593,6 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant time
|
||||
* @since 0.9.38
|
||||
*/
|
||||
private static boolean isOffline(SigningPrivateKey spk) {
|
||||
byte b = 0;
|
||||
byte[] data = spk.getData();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
b |= data[i];
|
||||
}
|
||||
return b == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this session have offline and transient keys?
|
||||
* @since 0.9.38
|
||||
|
@ -620,19 +620,6 @@ public class PrivateKeyFile {
|
||||
|
||||
//// offline methods
|
||||
|
||||
/**
|
||||
* Constant time
|
||||
* @since 0.9.38
|
||||
*/
|
||||
private static boolean isOffline(SigningPrivateKey spk) {
|
||||
byte b = 0;
|
||||
byte[] data = spk.getData();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
b |= data[i];
|
||||
}
|
||||
return b == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this session have offline and transient keys?
|
||||
* @since 0.9.38
|
||||
@ -646,7 +633,7 @@ public class PrivateKeyFile {
|
||||
* @since 0.9.38
|
||||
*/
|
||||
public void setOfflineData(long expires, SigningPublicKey transientPub, Signature sig, SigningPrivateKey transientPriv) {
|
||||
if (!isOffline(signingPrivKey)) {
|
||||
if (!signingPrivKey.isOffline()) {
|
||||
SigType type = getSigningPrivKey().getType();
|
||||
byte[] dbytes = new byte[type.getPrivkeyLen()];
|
||||
signingPrivKey = new SigningPrivateKey(type, dbytes);
|
||||
|
@ -100,6 +100,21 @@ public class SigningPrivateKey extends SimpleDataStructure {
|
||||
return Blinding.blind(this, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant time
|
||||
* @return true if all zeros
|
||||
* @since 0.9.39 moved from PrivateKeyFile
|
||||
*/
|
||||
public boolean isOffline() {
|
||||
if (_data == null)
|
||||
return true;
|
||||
byte b = 0;
|
||||
for (int i = 0; i < _data.length; i++) {
|
||||
b |= _data[i];
|
||||
}
|
||||
return b == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.8
|
||||
*/
|
||||
|
Reference in New Issue
Block a user