mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Merge pull request #455 from thi/454-fix-convert-key-id-to-hey-to-handle-short-key-ids
454 fix convert key id to hey to handle short key ids
This commit is contained in:
commit
747a41a0be
@ -477,6 +477,11 @@ public class PgpKeyHelper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String convertKeyIdToHex(long keyId) {
|
public static String convertKeyIdToHex(long keyId) {
|
||||||
|
long upper = keyId >> 32;
|
||||||
|
if (upper == 0) {
|
||||||
|
// this is a short key id
|
||||||
|
return convertKeyIdToHexShort(keyId);
|
||||||
|
}
|
||||||
return "0x" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId);
|
return "0x" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,11 @@ import org.apache.http.client.methods.HttpPost;
|
|||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -179,6 +181,7 @@ public class HkpKeyServer extends KeyServer {
|
|||||||
for (int i = 0; i < ips.length; ++i) {
|
for (int i = 0; i < ips.length; ++i) {
|
||||||
try {
|
try {
|
||||||
String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request;
|
String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request;
|
||||||
|
Log.d(Constants.TAG, "hkp keyserver query: " + url);
|
||||||
URL realUrl = new URL(url);
|
URL realUrl = new URL(url);
|
||||||
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
|
||||||
conn.setConnectTimeout(5000);
|
conn.setConnectTimeout(5000);
|
||||||
@ -277,9 +280,10 @@ public class HkpKeyServer extends KeyServer {
|
|||||||
public String get(long keyId) throws QueryException {
|
public String get(long keyId) throws QueryException {
|
||||||
HttpClient client = new DefaultHttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
try {
|
try {
|
||||||
HttpGet get = new HttpGet("http://" + mHost + ":" + mPort
|
String query = "http://" + mHost + ":" + mPort +
|
||||||
+ "/pks/lookup?op=get&options=mr&search=" + PgpKeyHelper.convertKeyIdToHex(keyId));
|
"/pks/lookup?op=get&options=mr&search=" + PgpKeyHelper.convertKeyIdToHex(keyId);
|
||||||
|
Log.d(Constants.TAG, "hkp keyserver get: " + query);
|
||||||
|
HttpGet get = new HttpGet(query);
|
||||||
HttpResponse response = client.execute(get);
|
HttpResponse response = client.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||||
throw new QueryException("not found");
|
throw new QueryException("not found");
|
||||||
@ -305,8 +309,9 @@ public class HkpKeyServer extends KeyServer {
|
|||||||
public void add(String armoredText) throws AddKeyException {
|
public void add(String armoredText) throws AddKeyException {
|
||||||
HttpClient client = new DefaultHttpClient();
|
HttpClient client = new DefaultHttpClient();
|
||||||
try {
|
try {
|
||||||
HttpPost post = new HttpPost("http://" + mHost + ":" + mPort + "/pks/add");
|
String query = "http://" + mHost + ":" + mPort + "/pks/add";
|
||||||
|
HttpPost post = new HttpPost(query);
|
||||||
|
Log.d(Constants.TAG, "hkp keyserver add: " + query);
|
||||||
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
|
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
|
||||||
nameValuePairs.add(new BasicNameValuePair("keytext", armoredText));
|
nameValuePairs.add(new BasicNameValuePair("keytext", armoredText));
|
||||||
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
||||||
|
Loading…
Reference in New Issue
Block a user