mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-02 13:32:19 -05:00
Upload key working
This commit is contained in:
parent
0f8958afb9
commit
37caddca70
@ -364,6 +364,7 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
|
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "hkp keyserver add: " + url.toString());
|
Log.d(Constants.TAG, "hkp keyserver add: " + url.toString());
|
||||||
|
Log.d(Constants.TAG, "params: " + params);
|
||||||
|
|
||||||
HttpURLConnection conn = openConnection(url);
|
HttpURLConnection conn = openConnection(url);
|
||||||
conn.setRequestMethod("POST");
|
conn.setRequestMethod("POST");
|
||||||
@ -384,6 +385,7 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
Log.d(Constants.TAG, "response code: " + conn.getResponseCode());
|
Log.d(Constants.TAG, "response code: " + conn.getResponseCode());
|
||||||
Log.d(Constants.TAG, "answer: " + readAll(conn.getInputStream(), conn.getContentEncoding()));
|
Log.d(Constants.TAG, "answer: " + readAll(conn.getInputStream(), conn.getContentEncoding()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "IOException", e);
|
||||||
throw new AddKeyException();
|
throw new AddKeyException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,6 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing {
|
|||||||
return mRing;
|
return mRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encode(ArmoredOutputStream stream) throws IOException {
|
|
||||||
getRing().encode(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Getter that returns the subkey that should be used for signing. */
|
/** Getter that returns the subkey that should be used for signing. */
|
||||||
CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException {
|
CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException {
|
||||||
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
||||||
|
@ -99,7 +99,7 @@ public class PgpImportExport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) {
|
public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) throws AddKeyException {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
ArmoredOutputStream aos = null;
|
ArmoredOutputStream aos = null;
|
||||||
try {
|
try {
|
||||||
@ -109,13 +109,9 @@ public class PgpImportExport {
|
|||||||
|
|
||||||
String armoredKey = bos.toString("UTF-8");
|
String armoredKey = bos.toString("UTF-8");
|
||||||
server.add(armoredKey);
|
server.add(armoredKey);
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
Log.e(Constants.TAG, "IOException", e);
|
||||||
} catch (AddKeyException e) {
|
throw new AddKeyException();
|
||||||
// TODO: tell the user?
|
|
||||||
return false;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (aos != null) {
|
if (aos != null) {
|
||||||
|
@ -575,8 +575,9 @@ public class KeychainIntentService extends IntentService
|
|||||||
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
||||||
PgpImportExport pgpImportExport = new PgpImportExport(this, null);
|
PgpImportExport pgpImportExport = new PgpImportExport(this, null);
|
||||||
|
|
||||||
boolean uploaded = pgpImportExport.uploadKeyRingToServer(server, keyring);
|
try {
|
||||||
if (!uploaded) {
|
pgpImportExport.uploadKeyRingToServer(server, keyring);
|
||||||
|
} catch (Keyserver.AddKeyException e) {
|
||||||
throw new PgpGeneralException("Unable to export key to selected server");
|
throw new PgpGeneralException("Unable to export key to selected server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user