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));
/** * 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 void readHeader(InputStream in) throws DataFormatException, IOException { _destination = Destination.create(in); _published = DataHelper.readLong(in, 4) * 1000; _expires = _published + (DataHelper.readLong(in, 2) * 1000); _flags = (int) DataHelper.readLong(in, 2); if (isOffline()) readOfflineBytes(in); }
protected void writeHeader(OutputStream out) throws DataFormatException, IOException { _destination.writeBytes(out); if (_published <= 0) _published = Clock.getInstance().now(); long pub1k = _published / 1000; DataHelper.writeLong(out, 4, pub1k); // Divide separately to prevent rounding errors DataHelper.writeLong(out, 2, ((_expires / 1000) - pub1k)); DataHelper.writeLong(out, 2, _flags); if (isOffline()) writeOfflineBytes(out); }
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()); }
return false; SigningPublicKey spk; if (isOffline()) {
SigType type = isOffline() ? _transientSigningPublicKey.getType() : _destination.getSigningPublicKey().getType(); _signature = new Signature(type); _signature.readBytes(in);