/** * @param lease must be a MetaLease * @throws IllegalArgumentException if not a MetaLease */ @Override public void addLease(Lease lease) { if (!(lease instanceof MetaLease)) throw new IllegalArgumentException(); super.addLease(lease); _expires = _lastExpiration; }
@Override public boolean equals(Object object) { if (object == this) return true; if ((object == null) || !(object instanceof LeaseSet2)) return false; LeaseSet2 ls = (LeaseSet2) object; return DataHelper.eq(_signature, ls.getSignature()) && DataHelper.eq(_leases, ls._leases) && DataHelper.eq(getEncryptionKey(), ls.getEncryptionKey()) && DataHelper.eq(_destination, ls.getDestination()); }
buf.append("[LeaseSet2: "); buf.append("\n\tDestination: ").append(_destination); List<PublicKey> keys = getEncryptionKeys(); int sz = keys.size(); buf.append("\n\tEncryption Keys: ").append(sz); buf.append("\n\tEncryption Key ").append(i).append(": ").append(keys.get(i)); if (isOffline()) { buf.append("\n\tTransient Key: ").append(_transientSigningPublicKey); buf.append("\n\tTransient Expires: ").append(new java.util.Date(_transientExpires)); buf.append("\n\tUnpublished? ").append(isUnpublished()); buf.append("\n\tSignature: ").append(_signature); buf.append("\n\tPublished: ").append(new java.util.Date(_published)); buf.append("\n\tExpires: ").append(new java.util.Date(_expires)); buf.append("\n\tLeases: #").append(getLeaseCount()); for (int i = 0; i < getLeaseCount(); i++) buf.append("\n\t\t").append(getLease(i)); buf.append("]"); return buf.toString();
return false; SigningPublicKey spk; if (isOffline()) { if (type == null || type.getBaseAlgorithm() == SigAlgo.RSA) return false; if (!verifyOfflineSignature()) return false; spk = _transientSigningPublicKey; } else { spk = getSigningPublicKey(); int len = size(); ByteArrayOutputStream out = new ByteArrayOutputStream(1 + len); try { out.write(getType()); writeBytesWithoutSig(out); } catch (IOException ioe) { ioe.printStackTrace();
if (isLS2) { if (_ls2Type == DatabaseEntry.KEY_TYPE_LS2) { leaseSet = new LeaseSet2(); } else if (_ls2Type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) { leaseSet = new EncryptedLeaseSet(); ((LeaseSet2)leaseSet).setUnpublished(); } else { leaseSet = new LeaseSet();
_leaseSet = new LeaseSet(); } else if (type == DatabaseEntry.KEY_TYPE_LS2) { _leaseSet = new LeaseSet2(); } else if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) { _leaseSet = new EncryptedLeaseSet(); List<PublicKey> pks = ls2.getEncryptionKeys(); if (pks == null) throw new I2CPMessageException("TODO decrypt");
/** * Number of bytes, NOT including signature */ @Override public int size() { int rv = _destination.size() + 10 + (_leases.size() * Lease2.LENGTH); for (PublicKey key : getEncryptionKeys()) { rv += 4; rv += key.length(); } if (isOffline()) rv += 6 + _transientSigningPublicKey.length() + _offlineSignature.length(); if (_options != null && !_options.isEmpty()) { try { rv += DataHelper.toProperties(_options).length; } catch (DataFormatException dfe) { throw new IllegalStateException("bad options", dfe); } } else { rv += 2; } return rv; }
protected boolean verifyOfflineSignature(SigningPublicKey spk) { if (!isOffline()) return false; I2PAppContext ctx = I2PAppContext.getGlobalContext(); if (_transientExpires < ctx.clock().now()) return false; ByteArrayOutputStream baos = new ByteArrayOutputStream(128); try { DataHelper.writeLong(baos, 4, _transientExpires / 1000); DataHelper.writeLong(baos, 2, _transientSigningPublicKey.getType().getCode()); _transientSigningPublicKey.writeBytes(baos); } catch (IOException ioe) { return false; } catch (DataFormatException dfe) { return false; } byte[] data = baos.toByteArray(); return ctx.dsa().verifySignature(_offlineSignature, data, 0, data.length, getSigningPublicKey()); }
if (_ls2Type != DatabaseEntry.KEY_TYPE_META_LS2) { for (PublicKey key : li.getPublicKeys()) { ls2.addEncryptionKey(key); boolean ok = ls2.setOfflineSignature(session.getOfflineExpiration(), session.getTransientSigningPublicKey(), session.getOfflineSignature()); if (!ok) {
_dbEntry = new LeaseSet(); else if (dbType == DatabaseEntry.KEY_TYPE_LS2) _dbEntry = new LeaseSet2(); else if (dbType == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) _dbEntry = new EncryptedLeaseSet();
/** * @return 0-16, or 0 if not decrypted. */ @Override public int getLeaseCount() { // TODO attempt decryption return _decryptedLS2 != null ? _decryptedLS2.getLeaseCount() : 0; }
/** * @return null if not decrypted. */ @Override public Lease getLease(int index) { // TODO attempt decryption return _decryptedLS2 != null ? _decryptedLS2.getLease(index) : null; }
/** * Without sig. This does NOT validate the signature */ protected void writeBody(OutputStream out) throws DataFormatException, IOException { if (_options != null && !_options.isEmpty()) { DataHelper.writeProperties(out, _options); } else { DataHelper.writeLong(out, 2, 0); } List<PublicKey> keys = getEncryptionKeys(); out.write((byte) keys.size()); for (PublicKey key : keys) { EncType type = key.getType(); if (type != null) { DataHelper.writeLong(out, 2, type.getCode()); } else { DataHelper.writeLong(out, 2, key.getUnknownTypeCode()); } DataHelper.writeLong(out, 2, key.length()); key.writeBytes(out); } out.write((byte) _leases.size()); for (Lease lease : _leases) { lease.writeBytes(out); } }
if (isLS2) { if (_ls2Type == DatabaseEntry.KEY_TYPE_LS2) { leaseSet = new LeaseSet2(); } else if (_ls2Type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) { leaseSet = new EncryptedLeaseSet(); ((LeaseSet2)leaseSet).setUnpublished(); } else { leaseSet = new LeaseSet();
lease.readBytes(in); super.addLease(lease);