Data: Consolidate offline key check

i2ptunnel: Prevent registration auth if key offline
This commit is contained in:
zzz
2019-03-09 11:47:03 +00:00
parent 409207e02d
commit d6a53cc3a6
5 changed files with 20 additions and 42 deletions

View File

@ -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

View File

@ -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);

View File

@ -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
*/