private void insert(BitmessageAddress address) throws IOException, SQLException { try ( Connection connection = config.getConnection(); PreparedStatement ps = connection.prepareStatement( "INSERT INTO Address (address, version, alias, public_key, private_key, subscribed, chan) " + "VALUES (?, ?, ?, ?, ?, ?, ?)") ) { ps.setString(1, address.getAddress()); ps.setLong(2, address.getVersion()); ps.setString(3, address.getAlias()); writePubkey(ps, 4, address.getPubkey()); writeBlob(ps, 5, address.getPrivateKey()); ps.setBoolean(6, address.isSubscribed()); ps.setBoolean(7, address.isChan()); ps.executeUpdate(); } }
private void update(BitmessageAddress address) throws IOException, SQLException { StringBuilder statement = new StringBuilder("UPDATE Address SET alias=?"); if (address.getPubkey() != null) { statement.append(", public_key=?"); } if (address.getPrivateKey() != null) { statement.append(", private_key=?"); } statement.append(", subscribed=?, chan=? WHERE address=?"); try ( Connection connection = config.getConnection(); PreparedStatement ps = connection.prepareStatement(statement.toString()) ) { int i = 0; ps.setString(++i, address.getAlias()); if (address.getPubkey() != null) { writePubkey(ps, ++i, address.getPubkey()); } if (address.getPrivateKey() != null) { writeBlob(ps, ++i, address.getPrivateKey()); } ps.setBoolean(++i, address.isSubscribed()); ps.setBoolean(++i, address.isChan()); ps.setString(++i, address.getAddress()); ps.executeUpdate(); } }
protected void receive(ObjectMessage object, GetPubkey getPubkey) { BitmessageAddress identity = ctx.getAddressRepository().findIdentity(getPubkey.getRipeTag()); if (identity != null && identity.getPrivateKey() != null && !identity.isChan()) { LOG.info("Got pubkey request for identity " + identity); // FIXME: only send pubkey if it wasn't sent in the last 28 days ctx.sendPubkey(identity, object.getStream()); } }
public WifExporter addIdentity(BitmessageAddress identity) { Profile.Section section = ini.add(identity.getAddress()); section.add("label", identity.getAlias()); section.add("enabled", true); section.add("decoy", false); if (identity.isChan()) { section.add("chan", identity.isChan()); } section.add("noncetrialsperbyte", identity.getPubkey().getNonceTrialsPerByte()); section.add("payloadlengthextrabytes", identity.getPubkey().getExtraBytes()); section.add("privsigningkey", exportSecret(identity.getPrivateKey().getPrivateSigningKey())); section.add("privencryptionkey", exportSecret(identity.getPrivateKey().getPrivateEncryptionKey())); return this; }