* Certificate: Fix null cert hash code

* Hash: Cleanup of cached hash
* NetDB: Randomize returned DSM timestamp
This commit is contained in:
zzz
2014-03-15 18:43:42 +00:00
parent af7ce8e18e
commit 24e6750529
5 changed files with 39 additions and 27 deletions

View File

@@ -244,20 +244,20 @@ public class Certificate extends DataStructureImpl {
StringBuilder buf = new StringBuilder(64);
buf.append("[Certificate: type: ");
if (getCertificateType() == CERTIFICATE_TYPE_NULL)
buf.append("Null certificate");
buf.append("Null");
else if (getCertificateType() == CERTIFICATE_TYPE_KEY)
buf.append("Key certificate");
buf.append("Key");
else if (getCertificateType() == CERTIFICATE_TYPE_HASHCASH)
buf.append("Hashcash certificate");
buf.append("HashCash");
else if (getCertificateType() == CERTIFICATE_TYPE_HIDDEN)
buf.append("Hidden certificate");
buf.append("Hidden");
else if (getCertificateType() == CERTIFICATE_TYPE_SIGNED)
buf.append("Signed certificate");
buf.append("Signed");
else
buf.append("Unknown certificate type (").append(getCertificateType()).append(")");
buf.append("Unknown type (").append(getCertificateType()).append(')');
if (_payload == null) {
buf.append(" null payload");
buf.append(" payload: null");
} else {
buf.append(" payload size: ").append(_payload.length);
if (getCertificateType() == CERTIFICATE_TYPE_HASHCASH) {
@@ -334,7 +334,8 @@ public class Certificate extends DataStructureImpl {
/** Overridden for efficiency */
@Override
public int hashCode() {
return 99999;
// must be the same as type + payload above
return 0;
}
}
}

View File

@@ -34,7 +34,7 @@ public class KeysAndCert extends DataStructureImpl {
protected PublicKey _publicKey;
protected SigningPublicKey _signingKey;
protected Certificate _certificate;
protected Hash __calculatedHash;
private Hash __calculatedHash;
protected byte[] _padding;
public Certificate getCertificate() {
@@ -48,7 +48,6 @@ public class KeysAndCert extends DataStructureImpl {
if (_certificate != null)
throw new IllegalStateException();
_certificate = cert;
__calculatedHash = null;
}
public PublicKey getPublicKey() {
@@ -62,7 +61,6 @@ public class KeysAndCert extends DataStructureImpl {
if (_publicKey != null)
throw new IllegalStateException();
_publicKey = key;
__calculatedHash = null;
}
public SigningPublicKey getSigningPublicKey() {
@@ -76,7 +74,6 @@ public class KeysAndCert extends DataStructureImpl {
if (_signingKey != null)
throw new IllegalStateException();
_signingKey = key;
__calculatedHash = null;
}
/**
@@ -87,7 +84,6 @@ public class KeysAndCert extends DataStructureImpl {
if (_padding != null)
throw new IllegalStateException();
_padding = padding;
__calculatedHash = null;
}
/**
@@ -109,7 +105,6 @@ public class KeysAndCert extends DataStructureImpl {
_signingKey = spk;
_certificate = cert;
}
__calculatedHash = null;
}
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
@@ -169,8 +164,10 @@ public class KeysAndCert extends DataStructureImpl {
ByteArrayOutputStream baos = new ByteArrayOutputStream(400);
writeBytes(baos);
identBytes = baos.toByteArray();
} catch (Throwable t) {
return null;
} catch (IOException ioe) {
throw new IllegalStateException("KAC hash error", ioe);
} catch (DataFormatException dfe) {
throw new IllegalStateException("KAC hash error", dfe);
}
__calculatedHash = SHA256Generator.getInstance().calculateHash(identBytes);
return __calculatedHash;