Work on upload key

This commit is contained in:
Dominik Schürmann 2014-08-20 21:44:51 +02:00
parent 45706e6534
commit e33e5b0003

View File

@ -24,8 +24,10 @@ import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.io.DataOutputStream; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@ -352,24 +354,32 @@ public class HkpKeyserver extends Keyserver {
@Override @Override
public void add(String armoredKey) throws AddKeyException { public void add(String armoredKey) throws AddKeyException {
try { try {
String query = getUrlPrefix() + mHost + ":" + mPort + "/pks/add"; String request = "/pks/add";
String params; String params;
try { try {
params = "keytext=" + URLEncoder.encode(armoredKey, "utf8"); params = "keytext=" + URLEncoder.encode(armoredKey, "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new AddKeyException(); throw new AddKeyException();
} }
Log.d(Constants.TAG, "hkp keyserver add: " + query); URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
HttpURLConnection connection = openConnection(new URL(query)); Log.d(Constants.TAG, "hkp keyserver add: " + url.toString());
connection.setRequestMethod("POST");
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded"); HttpURLConnection conn = openConnection(url);
connection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); conn.setRequestMethod("POST");
connection.setDoOutput(true); conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
wr.writeBytes(params); conn.setDoInput(true);
wr.flush(); conn.setDoOutput(true);
wr.close();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(params);
writer.flush();
writer.close();
os.close();
conn.connect();
} catch (IOException e) { } catch (IOException e) {
throw new AddKeyException(); throw new AddKeyException();
} }