2009-01-20 17:12:24 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import net.i2p.data.DataFormatException;
|
|
|
|
import net.i2p.data.Hash;
|
|
|
|
import net.i2p.data.SessionKey;
|
2009-02-25 01:18:38 +00:00
|
|
|
import net.i2p.util.ConvertToHash;
|
2009-01-20 17:12:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Support additions via B64 Destkey, B64 Desthash, or blahblah.i2p
|
|
|
|
*/
|
|
|
|
public class ConfigKeyringHandler extends FormHandler {
|
|
|
|
private String _peer;
|
|
|
|
private String _key;
|
|
|
|
|
2009-08-15 16:08:33 +00:00
|
|
|
@Override
|
2009-01-20 17:12:24 +00:00
|
|
|
protected void processForm() {
|
|
|
|
if ("Add key".equals(_action)) {
|
|
|
|
if (_peer == null || _key == null) {
|
|
|
|
addFormError("You must enter a destination and a key");
|
|
|
|
return;
|
|
|
|
}
|
2009-02-25 01:18:38 +00:00
|
|
|
Hash h = ConvertToHash.getHash(_peer);
|
2009-01-20 17:12:24 +00:00
|
|
|
SessionKey sk = new SessionKey();
|
|
|
|
try {
|
|
|
|
sk.fromBase64(_key);
|
|
|
|
} catch (DataFormatException dfe) {}
|
2009-02-25 01:18:38 +00:00
|
|
|
if (h != null && h.getData() != null && sk.getData() != null) {
|
2009-01-20 17:12:24 +00:00
|
|
|
_context.keyRing().put(h, sk);
|
|
|
|
addFormNotice("Key for " + h.toBase64() + " added to keyring");
|
|
|
|
} else {
|
|
|
|
addFormError("Invalid destination or key");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addFormError("Unsupported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPeer(String peer) { _peer = peer; }
|
|
|
|
public void setKey(String peer) { _key = peer; }
|
|
|
|
}
|