Repo created
48
plugins/openpgp-api-lib/CHANGELOG.md
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Version history
|
||||
|
||||
## Version 10
|
||||
* Retrieve whole public key via ACTION_GET_KEY
|
||||
|
||||
## Version 9
|
||||
* AIDL Service has been changed from IOpenPgpService.aidl to IOpenPgpService2.aidl
|
||||
This fixes truncated data streams (thanks to 'mgeier63').
|
||||
* Fix for OpenPgpKeyPreference: Properly execute pending user interactions
|
||||
* Charset moved to OpenPgpMetadata
|
||||
|
||||
## Version 8
|
||||
* OpenPgpSignatureResult:
|
||||
method getStatus() renamed to getResult()
|
||||
constants have been renamed for clarity
|
||||
new constants: RESULT_NO_SIGNATURE, RESULT_INVALID_INSECURE
|
||||
isSignatureOnly() has been deprecated
|
||||
* RESULT_TYPES have been removed
|
||||
* new OpenPgpDecryptionResult returned via RESULT_DECRYPTION
|
||||
* OpenPgpSignatureResult and OpenPgpDecryptionResult are never null, they are always returned.
|
||||
|
||||
## Version 7
|
||||
* Deprecation of ACCOUNT_NAME, please use ACTION_GET_SIGN_KEY_ID to get key id
|
||||
* Introduce EXTRA_SIGN_KEY_ID
|
||||
* New extra for ACTION_ENCRYPT and ACTION_SIGN_AND_ENCRYPT: EXTRA_ENABLE_COMPRESSION (default to true)
|
||||
* Return PendingIntent to view key for signatures
|
||||
* New result for ACTION_DECRYPT_VERIFY: RESULT_TYPE
|
||||
* New ACTION_GET_SIGN_KEY_ID
|
||||
* EXTRA_PASSPHRASE changed from String to char[]
|
||||
|
||||
## Version 6
|
||||
* Deprecate ACTION_SIGN
|
||||
* Introduce ACTION_CLEARTEXT_SIGN and ACTION_DETACHED_SIGN
|
||||
* New extra for ACTION_DETACHED_SIGN: EXTRA_DETACHED_SIGNATURE
|
||||
* New result for ACTION_DECRYPT_VERIFY: RESULT_DETACHED_SIGNATURE
|
||||
* New result for ACTION_DECRYPT_VERIFY: RESULT_CHARSET
|
||||
|
||||
## Version 5
|
||||
* OpenPgpSignatureResult: new consts RESULT_INVALID_KEY_REVOKED and RESULT_INVALID_KEY_EXPIRED
|
||||
* OpenPgpSignatureResult: ArrayList<String> userIds
|
||||
|
||||
## Version 4
|
||||
* No changes to existing methods -> backward compatible
|
||||
* Introduction of ACTION_DECRYPT_METADATA, RESULT_METADATA, EXTRA_ORIGINAL_FILENAME, and OpenPgpMetadata parcel
|
||||
* Introduction of internal NFC extras: EXTRA_NFC_SIGNED_HASH, EXTRA_NFC_SIG_CREATION_TIMESTAMP
|
||||
|
||||
## Version 3
|
||||
* First public stable version
|
||||
202
plugins/openpgp-api-lib/LICENSE
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
169
plugins/openpgp-api-lib/README.md
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
# OpenPGP API library
|
||||
|
||||
The OpenPGP API provides methods to execute OpenPGP operations, such as sign, encrypt, decrypt, verify, and more without user interaction from background threads. This is done by connecting your client application to a remote service provided by [OpenKeychain](http://www.openkeychain.org) or other OpenPGP providers.
|
||||
|
||||
### News
|
||||
|
||||
#### Version 10
|
||||
* Retrieve whole public key via ACTION_GET_KEY
|
||||
|
||||
[Full changelog here…](https://github.com/open-keychain/openpgp-api/blob/master/CHANGELOG.md)
|
||||
|
||||
### License
|
||||
While OpenKeychain itself is GPLv3+, the API library is licensed under Apache License v2.
|
||||
Thus, you are allowed to also use it in closed source applications as long as you respect the [Apache License v2](https://github.com/open-keychain/openpgp-api/blob/master/LICENSE).
|
||||
|
||||
### Add the API library to your project
|
||||
|
||||
Add this to your build.gradle:
|
||||
|
||||
```gradle
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.sufficientlysecure:openpgp-api:10.0'
|
||||
}
|
||||
```
|
||||
|
||||
### Full example
|
||||
A full working example is available in the [example project](https://github.com/open-keychain/openpgp-api/blob/master/example). The [``OpenPgpApiActivity.java``](https://github.com/open-keychain/openpgp-api/blob/master/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java) contains most relevant sourcecode.
|
||||
|
||||
### API
|
||||
|
||||
[OpenPgpApi](https://github.com/open-keychain/openpgp-api/blob/master/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java) contains all possible Intents and available extras.
|
||||
|
||||
### Short tutorial
|
||||
|
||||
**This tutorial only covers the basics, please consult the full example for a complete overview over all methods**
|
||||
|
||||
The API is **not** designed around ``Intents`` which are started via ``startActivityForResult``. These Intent actions typically start an activity for user interaction, so they are not suitable for background tasks. Most API design decisions are explained at [the bottom of this wiki page](https://github.com/open-keychain/open-keychain/wiki/OpenPGP-API#internal-design-decisions).
|
||||
|
||||
We will go through the basic steps to understand how this API works, following this (greatly simplified) sequence diagram:
|
||||

|
||||
|
||||
In this diagram the client app is depicted on the left side, the OpenPGP provider (in this case OpenKeychain) is depicted on the right.
|
||||
The remote service is defined via the [AIDL](http://developer.android.com/guide/components/aidl.html) file [``IOpenPgpService``](https://github.com/open-keychain/openpgp-api/blob/master/openpgp-api/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl).
|
||||
It contains only one exposed method which can be invoked remotely:
|
||||
```java
|
||||
interface IOpenPgpService {
|
||||
Intent execute(in Intent data, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
|
||||
}
|
||||
```
|
||||
The interaction between the apps is done by binding from your client app to the remote service of OpenKeychain.
|
||||
``OpenPgpServiceConnection`` is a helper class from the library to ease this step:
|
||||
```java
|
||||
OpenPgpServiceConnection mServiceConnection;
|
||||
|
||||
public void onCreate(Bundle savedInstance) {
|
||||
[...]
|
||||
mServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain");
|
||||
mServiceConnection.bindToService();
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
[...]
|
||||
if (mServiceConnection != null) {
|
||||
mServiceConnection.unbindFromService();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Following the sequence diagram, these steps are executed:
|
||||
|
||||
1. Define an ``Intent`` containing the actual PGP instructions which should be done, e.g.
|
||||
```java
|
||||
Intent data = new Intent();
|
||||
data.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
||||
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{"dominik@dominikschuermann.de"});
|
||||
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||
```
|
||||
Define an ``InputStream`` currently holding the plaintext, and an ``OutputStream`` where you want the ciphertext to be written by OpenKeychain's remote service:
|
||||
```java
|
||||
InputStream is = new ByteArrayInputStream("Hello world!".getBytes("UTF-8"));
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
```
|
||||
Using a helper class from the library, ``is`` and ``os`` are passed via ``ParcelFileDescriptors`` as ``input`` and ``output`` together with ``Intent data``, as depicted in the sequence diagram, from the client to the remote service.
|
||||
Programmatically, this can be done with:
|
||||
```java
|
||||
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
|
||||
Intent result = api.executeApi(data, is, os);
|
||||
```
|
||||
|
||||
2. The PGP operation is executed by OpenKeychain and the produced ciphertext is written into ``os`` which can then be accessed by the client app.
|
||||
|
||||
3. A result Intent is returned containing one of these result codes:
|
||||
* ``OpenPgpApi.RESULT_CODE_ERROR``
|
||||
* ``OpenPgpApi.RESULT_CODE_SUCCESS``
|
||||
* ``OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED``
|
||||
|
||||
If ``RESULT_CODE_USER_INTERACTION_REQUIRED`` is returned, an additional ``PendingIntent`` is returned to the client, which must be used to get user input required to process the request.
|
||||
A ``PendingIntent`` is executed with ``startIntentSenderForResult``, which starts an activity, originally belonging to OpenKeychain, on the [task stack](http://developer.android.com/guide/components/tasks-and-back-stack.html) of the client.
|
||||
Only if ``RESULT_CODE_SUCCESS`` is returned, ``os`` actually contains data.
|
||||
A nearly complete example looks like this:
|
||||
```java
|
||||
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||
case OpenPgpApi.RESULT_CODE_SUCCESS: {
|
||||
try {
|
||||
Log.d(OpenPgpApi.TAG, "output: " + os.toString("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(Constants.TAG, "UnsupportedEncodingException", e);
|
||||
}
|
||||
|
||||
if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE)) {
|
||||
OpenPgpSignatureResult sigResult
|
||||
= result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
|
||||
[...]
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
|
||||
PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||
try {
|
||||
startIntentSenderForResult(pi.getIntentSender(), 42, null, 0, 0, 0);
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
Log.e(Constants.TAG, "SendIntentException", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OpenPgpApi.RESULT_CODE_ERROR: {
|
||||
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
||||
[...]
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
4. Results from a ``PendingIntent`` are returned in ``onActivityResult`` of the activity, which executed ``startIntentSenderForResult``.
|
||||
The returned ``Intent data`` in ``onActivityResult`` contains the original PGP operation definition and new values acquired from the user interaction.
|
||||
Thus, you can now execute the ``Intent`` again, like done in step 1.
|
||||
This time it should return with ``RESULT_CODE_SUCCESS`` because all required information has been obtained by the previous user interaction stored in this ``Intent``.
|
||||
```java
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
[...]
|
||||
// try again after user interaction
|
||||
if (resultCode == RESULT_OK) {
|
||||
switch (requestCode) {
|
||||
case 42: {
|
||||
encrypt(data); // defined like in step 1
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Tipps
|
||||
* ``api.executeApi(data, is, os);`` is a blocking call. If you want a convenient asynchronous call, use ``api.executeApiAsync(data, is, os, new MyCallback([... ]));``, where ``MyCallback`` is an private class implementing ``OpenPgpApi.IOpenPgpCallback``.
|
||||
See [``OpenPgpApiActivity.java``](https://github.com/open-keychain/openpgp-api/blob/master/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java) for an example.
|
||||
* Using
|
||||
|
||||
```java
|
||||
mServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain");
|
||||
```
|
||||
connects to OpenKeychain directly.
|
||||
If you want to let the user choose between OpenPGP providers, you can implement the [``OpenPgpAppPreference.java``](https://github.com/open-keychain/openpgp-api/tree/master/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java) like done in the example app.
|
||||
|
||||
* To enable installing a debug and release version at the same time, the `debug` build of OpenKeychain uses `org.sufficientlysecure.keychain.debug` as a package name. Make sure you connect to the right one during development!
|
||||
17
plugins/openpgp-api-lib/openpgp-api/build.gradle.kts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
plugins {
|
||||
id(ThunderbirdPlugins.Library.android)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.openintents.openpgp"
|
||||
|
||||
buildFeatures {
|
||||
aidl = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.androidx.lifecycle.common)
|
||||
implementation(libs.timber)
|
||||
implementation(libs.preferencex)
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
interface IOpenPgpService {
|
||||
|
||||
/**
|
||||
* do NOT use this, data returned from the service through "output" may be truncated
|
||||
* @deprecated
|
||||
*/
|
||||
Intent execute(in Intent data, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
interface IOpenPgpService2 {
|
||||
|
||||
/**
|
||||
* see org.openintents.openpgp.util.OpenPgpApi for documentation
|
||||
*/
|
||||
ParcelFileDescriptor createOutputPipe(in int pipeId);
|
||||
|
||||
/**
|
||||
* see org.openintents.openpgp.util.OpenPgpApi for documentation
|
||||
*/
|
||||
Intent execute(in Intent data, in ParcelFileDescriptor input, int pipeId);
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class AutocryptPeerUpdate implements Parcelable {
|
||||
/**
|
||||
* Since there might be a case where new versions of the client using the library getting
|
||||
* old versions of the protocol (and thus old versions of this class), we need a versioning
|
||||
* system for the parcels sent between the clients and the providers.
|
||||
*/
|
||||
private static final int PARCELABLE_VERSION = 1;
|
||||
|
||||
|
||||
private final byte[] keyData;
|
||||
private final Date effectiveDate;
|
||||
private final PreferEncrypt preferEncrypt;
|
||||
|
||||
|
||||
private AutocryptPeerUpdate(byte[] keyData, Date effectiveDate, PreferEncrypt preferEncrypt) {
|
||||
this.keyData = keyData;
|
||||
this.effectiveDate = effectiveDate;
|
||||
this.preferEncrypt = preferEncrypt;
|
||||
}
|
||||
|
||||
private AutocryptPeerUpdate(Parcel source, int version) {
|
||||
this.keyData = source.createByteArray();
|
||||
this.effectiveDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
||||
this.preferEncrypt = PreferEncrypt.values()[source.readInt()];
|
||||
}
|
||||
|
||||
|
||||
public static AutocryptPeerUpdate create(byte[] keyData, Date timestamp, boolean isMutual) {
|
||||
return new AutocryptPeerUpdate(keyData, timestamp, isMutual ? PreferEncrypt.MUTUAL : PreferEncrypt.NOPREFERENCE);
|
||||
}
|
||||
|
||||
public byte[] getKeyData() {
|
||||
return keyData;
|
||||
}
|
||||
|
||||
public boolean hasKeyData() {
|
||||
return keyData != null;
|
||||
}
|
||||
|
||||
public Date getEffectiveDate() {
|
||||
return effectiveDate;
|
||||
}
|
||||
|
||||
public PreferEncrypt getPreferEncrypt() {
|
||||
return preferEncrypt;
|
||||
}
|
||||
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
/**
|
||||
* NOTE: When adding fields in the process of updating this API, make sure to bump
|
||||
* {@link #PARCELABLE_VERSION}.
|
||||
*/
|
||||
dest.writeInt(PARCELABLE_VERSION);
|
||||
// Inject a placeholder that will store the parcel size from this point on
|
||||
// (not including the size itself).
|
||||
int sizePosition = dest.dataPosition();
|
||||
dest.writeInt(0);
|
||||
int startPosition = dest.dataPosition();
|
||||
|
||||
// version 1
|
||||
dest.writeByteArray(keyData);
|
||||
if (effectiveDate != null) {
|
||||
dest.writeInt(1);
|
||||
dest.writeLong(effectiveDate.getTime());
|
||||
} else {
|
||||
dest.writeInt(0);
|
||||
}
|
||||
|
||||
dest.writeInt(preferEncrypt.ordinal());
|
||||
|
||||
// Go back and write the size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
dest.writeInt(parcelableSize);
|
||||
dest.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
public static final Creator<AutocryptPeerUpdate> CREATOR = new Creator<AutocryptPeerUpdate>() {
|
||||
public AutocryptPeerUpdate createFromParcel(final Parcel source) {
|
||||
int version = source.readInt(); // parcelableVersion
|
||||
int parcelableSize = source.readInt();
|
||||
int startPosition = source.dataPosition();
|
||||
|
||||
AutocryptPeerUpdate vr = new AutocryptPeerUpdate(source, version);
|
||||
|
||||
// skip over all fields added in future versions of this parcel
|
||||
source.setDataPosition(startPosition + parcelableSize);
|
||||
|
||||
return vr;
|
||||
}
|
||||
|
||||
public AutocryptPeerUpdate[] newArray(final int size) {
|
||||
return new AutocryptPeerUpdate[size];
|
||||
}
|
||||
};
|
||||
|
||||
public enum PreferEncrypt {
|
||||
NOPREFERENCE, MUTUAL
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
package org.openintents.openpgp;
|
||||
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.Lifecycle.Event;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
|
||||
import org.openintents.openpgp.util.OpenPgpProviderUtil;
|
||||
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
||||
import org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class OpenPgpApiManager implements LifecycleObserver {
|
||||
private final Context context;
|
||||
|
||||
@Nullable
|
||||
private String openPgpProvider;
|
||||
@Nullable
|
||||
private OpenPgpApiManagerCallback callback;
|
||||
|
||||
private OpenPgpServiceConnection openPgpServiceConnection;
|
||||
private OpenPgpApi openPgpApi;
|
||||
private PendingIntent userInteractionPendingIntent;
|
||||
private OpenPgpProviderState openPgpProviderState = OpenPgpProviderState.UNCONFIGURED;
|
||||
|
||||
public OpenPgpApiManager(Context context, LifecycleOwner lifecycleOwner) {
|
||||
this.context = context;
|
||||
|
||||
lifecycleOwner.getLifecycle().addObserver(this);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_CREATE)
|
||||
void onLifecycleCreate() {
|
||||
setupCryptoProvider();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_START)
|
||||
void onLifecycleStart() {
|
||||
refreshConnection();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_DESTROY)
|
||||
public void onLifecycleDestroy() {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
public void setOpenPgpProvider(@Nullable String openPgpProvider, OpenPgpApiManagerCallback callback) {
|
||||
if (openPgpProvider == null || !openPgpProvider.equals(this.openPgpProvider)) {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
this.openPgpProvider = openPgpProvider;
|
||||
this.callback = callback;
|
||||
|
||||
setupCryptoProvider();
|
||||
}
|
||||
|
||||
private void setupCryptoProvider() {
|
||||
if (TextUtils.isEmpty(openPgpProvider)) {
|
||||
setOpenPgpProviderState(OpenPgpProviderState.UNCONFIGURED);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean providerIsBound = openPgpServiceConnection != null && openPgpServiceConnection.isBound();
|
||||
if (providerIsBound) {
|
||||
refreshConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
if (openPgpServiceConnection != null) {
|
||||
// An OpenPgpServiceConnection has already been created, but hasn't been bound yet.
|
||||
// We'll just wait for OnBound.onBound() to be called.
|
||||
return;
|
||||
}
|
||||
|
||||
setOpenPgpProviderState(OpenPgpProviderState.UNINITIALIZED);
|
||||
openPgpServiceConnection = new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() {
|
||||
@Override
|
||||
public void onBound(IOpenPgpService2 service) {
|
||||
openPgpApi = new OpenPgpApi(context, service);
|
||||
refreshConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
Timber.e(e, "error connecting to crypto provider!");
|
||||
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
|
||||
callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionFailed);
|
||||
}
|
||||
});
|
||||
refreshConnection();
|
||||
}
|
||||
|
||||
public void refreshConnection() {
|
||||
boolean isOkStateButLostConnection = openPgpProviderState == OpenPgpProviderState.OK &&
|
||||
(openPgpServiceConnection == null || !openPgpServiceConnection.isBound());
|
||||
if (isOkStateButLostConnection) {
|
||||
userInteractionPendingIntent = null;
|
||||
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
|
||||
callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionLost);
|
||||
return;
|
||||
}
|
||||
|
||||
if (openPgpServiceConnection == null) {
|
||||
userInteractionPendingIntent = null;
|
||||
setupCryptoProvider();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!openPgpServiceConnection.isBound()) {
|
||||
userInteractionPendingIntent = null;
|
||||
Timber.d("attempting to bind to openpgp provider: %s (%s)", openPgpProvider, openPgpServiceConnection);
|
||||
openPgpServiceConnection.bindToService();
|
||||
return;
|
||||
}
|
||||
|
||||
if (userInteractionPendingIntent != null) {
|
||||
setOpenPgpProviderState(OpenPgpProviderState.UI_REQUIRED);
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_CHECK_PERMISSION);
|
||||
getOpenPgpApi().executeApiAsync(intent, null, null, new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
if (openPgpProviderState != OpenPgpProviderState.UNCONFIGURED) {
|
||||
onPgpPermissionCheckResult(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onUserInteractionResult() {
|
||||
userInteractionPendingIntent = null;
|
||||
refreshConnection();
|
||||
}
|
||||
|
||||
public PendingIntent getUserInteractionPendingIntent() {
|
||||
return userInteractionPendingIntent;
|
||||
}
|
||||
|
||||
private void onPgpPermissionCheckResult(Intent result) {
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
switch (resultCode) {
|
||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||
setOpenPgpProviderState(OpenPgpProviderState.OK);
|
||||
break;
|
||||
|
||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
||||
userInteractionPendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||
setOpenPgpProviderState(OpenPgpProviderState.UI_REQUIRED);
|
||||
break;
|
||||
|
||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||
default:
|
||||
if (result.hasExtra(OpenPgpApi.RESULT_ERROR)) {
|
||||
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
||||
handleOpenPgpError(error);
|
||||
} else {
|
||||
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
|
||||
callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionFailed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setOpenPgpProviderState(OpenPgpProviderState state) {
|
||||
boolean statusChanged = openPgpProviderState != state;
|
||||
if (statusChanged) {
|
||||
Timber.d("callback provider status changed from %s to %s", openPgpProviderState, state);
|
||||
openPgpProviderState = state;
|
||||
if (callback != null) {
|
||||
callback.onOpenPgpProviderStatusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleOpenPgpError(@Nullable OpenPgpError error) {
|
||||
Timber.e("OpenPGP Api error: %s", error);
|
||||
|
||||
if (error != null && error.getErrorId() == OpenPgpError.INCOMPATIBLE_API_VERSIONS) {
|
||||
callbackOpenPgpProviderError(OpenPgpProviderError.VersionIncompatible);
|
||||
setOpenPgpProviderState(OpenPgpProviderState.UNCONFIGURED);
|
||||
} else {
|
||||
callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionFailed);
|
||||
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private void callbackOpenPgpProviderError(OpenPgpProviderError providerError) {
|
||||
Timber.d("callback provider connection error %s", providerError);
|
||||
if (callback != null) {
|
||||
callback.onOpenPgpProviderError(providerError);
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnect() {
|
||||
openPgpApi = null;
|
||||
if (openPgpServiceConnection != null) {
|
||||
openPgpServiceConnection.unbindFromService();
|
||||
}
|
||||
openPgpServiceConnection = null;
|
||||
}
|
||||
|
||||
public OpenPgpApi getOpenPgpApi() {
|
||||
if (openPgpServiceConnection == null || !openPgpServiceConnection.isBound()) {
|
||||
Timber.e("Obtained OpenPgpApi object, but service is not bound! Inconsistent state?");
|
||||
}
|
||||
return openPgpApi;
|
||||
}
|
||||
|
||||
public String getReadableOpenPgpProviderName() {
|
||||
String openPgpProviderName =
|
||||
OpenPgpProviderUtil.getOpenPgpProviderName(context.getPackageManager(), openPgpProvider);
|
||||
return openPgpProviderName != null ? openPgpProviderName : openPgpProvider;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public OpenPgpProviderState getOpenPgpProviderState() {
|
||||
return openPgpProviderState;
|
||||
}
|
||||
|
||||
public enum OpenPgpProviderState {
|
||||
UNCONFIGURED,
|
||||
UNINITIALIZED,
|
||||
UI_REQUIRED,
|
||||
ERROR,
|
||||
OK
|
||||
}
|
||||
|
||||
public enum OpenPgpProviderError {
|
||||
ConnectionFailed, ConnectionLost, VersionIncompatible
|
||||
}
|
||||
|
||||
public interface OpenPgpApiManagerCallback {
|
||||
void onOpenPgpProviderStatusChanged();
|
||||
void onOpenPgpProviderError(OpenPgpProviderError error);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class OpenPgpDecryptionResult implements Parcelable {
|
||||
/**
|
||||
* Since there might be a case where new versions of the client using the library getting
|
||||
* old versions of the protocol (and thus old versions of this class), we need a versioning
|
||||
* system for the parcels sent between the clients and the providers.
|
||||
*/
|
||||
public static final int PARCELABLE_VERSION = 2;
|
||||
|
||||
// content not encrypted
|
||||
public static final int RESULT_NOT_ENCRYPTED = -1;
|
||||
// insecure!
|
||||
public static final int RESULT_INSECURE = 0;
|
||||
// encrypted
|
||||
public static final int RESULT_ENCRYPTED = 1;
|
||||
|
||||
public final int result;
|
||||
public final byte[] sessionKey;
|
||||
public final byte[] decryptedSessionKey;
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public OpenPgpDecryptionResult(int result) {
|
||||
this.result = result;
|
||||
this.sessionKey = null;
|
||||
this.decryptedSessionKey = null;
|
||||
}
|
||||
|
||||
public OpenPgpDecryptionResult(int result, byte[] sessionKey, byte[] decryptedSessionKey) {
|
||||
this.result = result;
|
||||
if ((sessionKey == null) != (decryptedSessionKey == null)) {
|
||||
throw new AssertionError("sessionkey must be null iff decryptedSessionKey is null");
|
||||
}
|
||||
this.sessionKey = sessionKey;
|
||||
this.decryptedSessionKey = decryptedSessionKey;
|
||||
}
|
||||
|
||||
public OpenPgpDecryptionResult(OpenPgpDecryptionResult b) {
|
||||
this.result = b.result;
|
||||
this.sessionKey = b.sessionKey;
|
||||
this.decryptedSessionKey = b.decryptedSessionKey;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
/**
|
||||
* NOTE: When adding fields in the process of updating this API, make sure to bump
|
||||
* {@link #PARCELABLE_VERSION}.
|
||||
*/
|
||||
dest.writeInt(PARCELABLE_VERSION);
|
||||
// Inject a placeholder that will store the parcel size from this point on
|
||||
// (not including the size itself).
|
||||
int sizePosition = dest.dataPosition();
|
||||
dest.writeInt(0);
|
||||
int startPosition = dest.dataPosition();
|
||||
// version 1
|
||||
dest.writeInt(result);
|
||||
// version 2
|
||||
dest.writeByteArray(sessionKey);
|
||||
dest.writeByteArray(decryptedSessionKey);
|
||||
// Go back and write the size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
dest.writeInt(parcelableSize);
|
||||
dest.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpDecryptionResult> CREATOR = new Creator<OpenPgpDecryptionResult>() {
|
||||
public OpenPgpDecryptionResult createFromParcel(final Parcel source) {
|
||||
int version = source.readInt(); // parcelableVersion
|
||||
int parcelableSize = source.readInt();
|
||||
int startPosition = source.dataPosition();
|
||||
|
||||
int result = source.readInt();
|
||||
byte[] sessionKey = version > 1 ? source.createByteArray() : null;
|
||||
byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null;
|
||||
|
||||
OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(result, sessionKey, decryptedSessionKey);
|
||||
|
||||
// skip over all fields added in future versions of this parcel
|
||||
source.setDataPosition(startPosition + parcelableSize);
|
||||
|
||||
return vr;
|
||||
}
|
||||
|
||||
public OpenPgpDecryptionResult[] newArray(final int size) {
|
||||
return new OpenPgpDecryptionResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\nresult: " + result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class OpenPgpError implements Parcelable {
|
||||
/**
|
||||
* Since there might be a case where new versions of the client using the library getting
|
||||
* old versions of the protocol (and thus old versions of this class), we need a versioning
|
||||
* system for the parcels sent between the clients and the providers.
|
||||
*/
|
||||
public static final int PARCELABLE_VERSION = 1;
|
||||
|
||||
// possible values for errorId
|
||||
public static final int CLIENT_SIDE_ERROR = -1;
|
||||
public static final int GENERIC_ERROR = 0;
|
||||
public static final int INCOMPATIBLE_API_VERSIONS = 1;
|
||||
public static final int NO_OR_WRONG_PASSPHRASE = 2;
|
||||
public static final int NO_USER_IDS = 3;
|
||||
public static final int OPPORTUNISTIC_MISSING_KEYS = 4;
|
||||
|
||||
int errorId;
|
||||
String message;
|
||||
|
||||
public OpenPgpError() {
|
||||
}
|
||||
|
||||
public OpenPgpError(int errorId, String message) {
|
||||
this.errorId = errorId;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public OpenPgpError(OpenPgpError b) {
|
||||
this.errorId = b.errorId;
|
||||
this.message = b.message;
|
||||
}
|
||||
|
||||
public int getErrorId() {
|
||||
return errorId;
|
||||
}
|
||||
|
||||
public void setErrorId(int errorId) {
|
||||
this.errorId = errorId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "OpenPGP-Api Error (" + errorId + "): " + message;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
/**
|
||||
* NOTE: When adding fields in the process of updating this API, make sure to bump
|
||||
* {@link #PARCELABLE_VERSION}.
|
||||
*/
|
||||
dest.writeInt(PARCELABLE_VERSION);
|
||||
// Inject a placeholder that will store the parcel size from this point on
|
||||
// (not including the size itself).
|
||||
int sizePosition = dest.dataPosition();
|
||||
dest.writeInt(0);
|
||||
int startPosition = dest.dataPosition();
|
||||
// version 1
|
||||
dest.writeInt(errorId);
|
||||
dest.writeString(message);
|
||||
// Go back and write the size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
dest.writeInt(parcelableSize);
|
||||
dest.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpError> CREATOR = new Creator<OpenPgpError>() {
|
||||
public OpenPgpError createFromParcel(final Parcel source) {
|
||||
source.readInt(); // parcelableVersion
|
||||
int parcelableSize = source.readInt();
|
||||
int startPosition = source.dataPosition();
|
||||
|
||||
OpenPgpError error = new OpenPgpError();
|
||||
error.errorId = source.readInt();
|
||||
error.message = source.readString();
|
||||
|
||||
// skip over all fields added in future versions of this parcel
|
||||
source.setDataPosition(startPosition + parcelableSize);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
public OpenPgpError[] newArray(final int size) {
|
||||
return new OpenPgpError[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class OpenPgpMetadata implements Parcelable {
|
||||
/**
|
||||
* Since there might be a case where new versions of the client using the library getting
|
||||
* old versions of the protocol (and thus old versions of this class), we need a versioning
|
||||
* system for the parcels sent between the clients and the providers.
|
||||
*/
|
||||
public static final int PARCELABLE_VERSION = 2;
|
||||
|
||||
String filename;
|
||||
String mimeType;
|
||||
String charset;
|
||||
long modificationTime;
|
||||
long originalSize;
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public long getModificationTime() {
|
||||
return modificationTime;
|
||||
}
|
||||
|
||||
public long getOriginalSize() {
|
||||
return originalSize;
|
||||
}
|
||||
|
||||
public String getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public OpenPgpMetadata() {
|
||||
}
|
||||
|
||||
public OpenPgpMetadata(String filename, String mimeType, long modificationTime,
|
||||
long originalSize, String charset) {
|
||||
this.filename = filename;
|
||||
this.mimeType = mimeType;
|
||||
this.modificationTime = modificationTime;
|
||||
this.originalSize = originalSize;
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public OpenPgpMetadata(String filename, String mimeType, long modificationTime,
|
||||
long originalSize) {
|
||||
this.filename = filename;
|
||||
this.mimeType = mimeType;
|
||||
this.modificationTime = modificationTime;
|
||||
this.originalSize = originalSize;
|
||||
}
|
||||
|
||||
public OpenPgpMetadata(OpenPgpMetadata b) {
|
||||
this.filename = b.filename;
|
||||
this.mimeType = b.mimeType;
|
||||
this.modificationTime = b.modificationTime;
|
||||
this.originalSize = b.originalSize;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
/**
|
||||
* NOTE: When adding fields in the process of updating this API, make sure to bump
|
||||
* {@link #PARCELABLE_VERSION}.
|
||||
*/
|
||||
dest.writeInt(PARCELABLE_VERSION);
|
||||
// Inject a placeholder that will store the parcel size from this point on
|
||||
// (not including the size itself).
|
||||
int sizePosition = dest.dataPosition();
|
||||
dest.writeInt(0);
|
||||
int startPosition = dest.dataPosition();
|
||||
// version 1
|
||||
dest.writeString(filename);
|
||||
dest.writeString(mimeType);
|
||||
dest.writeLong(modificationTime);
|
||||
dest.writeLong(originalSize);
|
||||
// version 2
|
||||
dest.writeString(charset);
|
||||
// Go back and write the size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
dest.writeInt(parcelableSize);
|
||||
dest.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpMetadata> CREATOR = new Creator<OpenPgpMetadata>() {
|
||||
public OpenPgpMetadata createFromParcel(final Parcel source) {
|
||||
int version = source.readInt(); // parcelableVersion
|
||||
int parcelableSize = source.readInt();
|
||||
int startPosition = source.dataPosition();
|
||||
|
||||
OpenPgpMetadata vr = new OpenPgpMetadata();
|
||||
vr.filename = source.readString();
|
||||
vr.mimeType = source.readString();
|
||||
vr.modificationTime = source.readLong();
|
||||
vr.originalSize = source.readLong();
|
||||
if (version >= 2) {
|
||||
vr.charset = source.readString();
|
||||
}
|
||||
|
||||
// skip over all fields added in future versions of this parcel
|
||||
source.setDataPosition(startPosition + parcelableSize);
|
||||
|
||||
return vr;
|
||||
}
|
||||
|
||||
public OpenPgpMetadata[] newArray(final int size) {
|
||||
return new OpenPgpMetadata[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "\nfilename: " + filename;
|
||||
out += "\nmimeType: " + mimeType;
|
||||
out += "\nmodificationTime: " + modificationTime;
|
||||
out += "\noriginalSize: " + originalSize;
|
||||
out += "\ncharset: " + charset;
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class OpenPgpSignatureResult implements Parcelable {
|
||||
/**
|
||||
* Since there might be a case where new versions of the client using the library getting
|
||||
* old versions of the protocol (and thus old versions of this class), we need a versioning
|
||||
* system for the parcels sent between the clients and the providers.
|
||||
*/
|
||||
private static final int PARCELABLE_VERSION = 3;
|
||||
|
||||
// content not signed
|
||||
public static final int RESULT_NO_SIGNATURE = -1;
|
||||
// invalid signature!
|
||||
public static final int RESULT_INVALID_SIGNATURE = 0;
|
||||
// successfully verified signature, with confirmed key
|
||||
@Deprecated
|
||||
public static final int RESULT_VALID_CONFIRMED = 1;
|
||||
public static final int RESULT_VALID_KEY_CONFIRMED = 1;
|
||||
// no key was found for this signature verification
|
||||
public static final int RESULT_KEY_MISSING = 2;
|
||||
// successfully verified signature, but with unconfirmed key
|
||||
@Deprecated
|
||||
public static final int RESULT_VALID_UNCONFIRMED = 3;
|
||||
public static final int RESULT_VALID_KEY_UNCONFIRMED = 3;
|
||||
// key has been revoked -> invalid signature!
|
||||
public static final int RESULT_INVALID_KEY_REVOKED = 4;
|
||||
// key is expired -> invalid signature!
|
||||
public static final int RESULT_INVALID_KEY_EXPIRED = 5;
|
||||
// insecure cryptographic algorithms/protocol -> invalid signature!
|
||||
@Deprecated
|
||||
public static final int RESULT_INVALID_INSECURE = 6;
|
||||
public static final int RESULT_INVALID_KEY_INSECURE = 6;
|
||||
|
||||
private final int result;
|
||||
private final long keyId;
|
||||
private final String primaryUserId;
|
||||
private final ArrayList<String> userIds;
|
||||
private final ArrayList<String> confirmedUserIds;
|
||||
private final SenderStatusResult senderStatusResult;
|
||||
|
||||
private OpenPgpSignatureResult(int signatureStatus, String signatureUserId, long keyId,
|
||||
ArrayList<String> userIds, ArrayList<String> confirmedUserIds, SenderStatusResult senderStatusResult,
|
||||
Boolean signatureOnly) {
|
||||
this.result = signatureStatus;
|
||||
this.primaryUserId = signatureUserId;
|
||||
this.keyId = keyId;
|
||||
this.userIds = userIds;
|
||||
this.confirmedUserIds = confirmedUserIds;
|
||||
this.senderStatusResult = senderStatusResult;
|
||||
}
|
||||
|
||||
private OpenPgpSignatureResult(Parcel source, int version) {
|
||||
this.result = source.readInt();
|
||||
// we dropped support for signatureOnly, but need to skip the value for compatibility
|
||||
source.readByte();
|
||||
this.primaryUserId = source.readString();
|
||||
this.keyId = source.readLong();
|
||||
|
||||
if (version > 1) {
|
||||
this.userIds = source.createStringArrayList();
|
||||
} else {
|
||||
this.userIds = null;
|
||||
}
|
||||
if (version > 2) {
|
||||
this.senderStatusResult = readEnumWithNullAndFallback(
|
||||
source, SenderStatusResult.VALUES, SenderStatusResult.UNKNOWN);
|
||||
this.confirmedUserIds = source.createStringArrayList();
|
||||
} else {
|
||||
this.senderStatusResult = SenderStatusResult.UNKNOWN;
|
||||
this.confirmedUserIds = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public SenderStatusResult getSenderStatusResult() {
|
||||
return senderStatusResult;
|
||||
}
|
||||
|
||||
public String getPrimaryUserId() {
|
||||
return primaryUserId;
|
||||
}
|
||||
|
||||
public List<String> getUserIds() {
|
||||
return Collections.unmodifiableList(userIds);
|
||||
}
|
||||
|
||||
public List<String> getConfirmedUserIds() {
|
||||
return Collections.unmodifiableList(confirmedUserIds);
|
||||
}
|
||||
|
||||
public long getKeyId() {
|
||||
return keyId;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
/**
|
||||
* NOTE: When adding fields in the process of updating this API, make sure to bump
|
||||
* {@link #PARCELABLE_VERSION}.
|
||||
*/
|
||||
dest.writeInt(PARCELABLE_VERSION);
|
||||
// Inject a placeholder that will store the parcel size from this point on
|
||||
// (not including the size itself).
|
||||
int sizePosition = dest.dataPosition();
|
||||
dest.writeInt(0);
|
||||
int startPosition = dest.dataPosition();
|
||||
// version 1
|
||||
dest.writeInt(result);
|
||||
// signatureOnly is deprecated since version 3. we pass a dummy value for compatibility
|
||||
dest.writeByte((byte) 0);
|
||||
dest.writeString(primaryUserId);
|
||||
dest.writeLong(keyId);
|
||||
// version 2
|
||||
dest.writeStringList(userIds);
|
||||
// version 3
|
||||
writeEnumWithNull(dest, senderStatusResult);
|
||||
dest.writeStringList(confirmedUserIds);
|
||||
// Go back and write the size
|
||||
int parcelableSize = dest.dataPosition() - startPosition;
|
||||
dest.setDataPosition(sizePosition);
|
||||
dest.writeInt(parcelableSize);
|
||||
dest.setDataPosition(startPosition + parcelableSize);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpSignatureResult> CREATOR = new Creator<OpenPgpSignatureResult>() {
|
||||
public OpenPgpSignatureResult createFromParcel(final Parcel source) {
|
||||
int version = source.readInt(); // parcelableVersion
|
||||
int parcelableSize = source.readInt();
|
||||
int startPosition = source.dataPosition();
|
||||
|
||||
OpenPgpSignatureResult vr = new OpenPgpSignatureResult(source, version);
|
||||
|
||||
// skip over all fields added in future versions of this parcel
|
||||
source.setDataPosition(startPosition + parcelableSize);
|
||||
|
||||
return vr;
|
||||
}
|
||||
|
||||
public OpenPgpSignatureResult[] newArray(final int size) {
|
||||
return new OpenPgpSignatureResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "\nresult: " + result;
|
||||
out += "\nprimaryUserId: " + primaryUserId;
|
||||
out += "\nuserIds: " + userIds;
|
||||
out += "\nkeyId: " + OpenPgpUtils.convertKeyIdToHex(keyId);
|
||||
return out;
|
||||
}
|
||||
|
||||
public static OpenPgpSignatureResult createWithValidSignature(int signatureStatus, String primaryUserId,
|
||||
long keyId, ArrayList<String> userIds, ArrayList<String> confirmedUserIds, SenderStatusResult senderStatusResult) {
|
||||
if (signatureStatus == RESULT_NO_SIGNATURE || signatureStatus == RESULT_KEY_MISSING ||
|
||||
signatureStatus == RESULT_INVALID_SIGNATURE) {
|
||||
throw new IllegalArgumentException("can only use this method for valid types of signatures");
|
||||
}
|
||||
return new OpenPgpSignatureResult(
|
||||
signatureStatus, primaryUserId, keyId, userIds, confirmedUserIds, senderStatusResult, null);
|
||||
}
|
||||
|
||||
public static OpenPgpSignatureResult createWithNoSignature() {
|
||||
return new OpenPgpSignatureResult(RESULT_NO_SIGNATURE, null, 0L, null, null, null, null);
|
||||
}
|
||||
|
||||
public static OpenPgpSignatureResult createWithKeyMissing(long keyId) {
|
||||
return new OpenPgpSignatureResult(RESULT_KEY_MISSING, null, keyId, null, null, null, null);
|
||||
}
|
||||
|
||||
public static OpenPgpSignatureResult createWithInvalidSignature() {
|
||||
return new OpenPgpSignatureResult(RESULT_INVALID_SIGNATURE, null, 0L, null, null, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public OpenPgpSignatureResult withSignatureOnlyFlag(boolean signatureOnly) {
|
||||
return new OpenPgpSignatureResult(
|
||||
result, primaryUserId, keyId, userIds, confirmedUserIds, senderStatusResult, signatureOnly);
|
||||
}
|
||||
|
||||
private static <T extends Enum<T>> T readEnumWithNullAndFallback(Parcel source, T[] enumValues, T fallback) {
|
||||
int valueOrdinal = source.readInt();
|
||||
if (valueOrdinal == -1) {
|
||||
return null;
|
||||
}
|
||||
if (valueOrdinal >= enumValues.length) {
|
||||
return fallback;
|
||||
}
|
||||
return enumValues[valueOrdinal];
|
||||
}
|
||||
|
||||
private static void writeEnumWithNull(Parcel dest, Enum<?> enumValue) {
|
||||
if (enumValue == null) {
|
||||
dest.writeInt(-1);
|
||||
return;
|
||||
}
|
||||
dest.writeInt(enumValue.ordinal());
|
||||
}
|
||||
|
||||
public enum SenderStatusResult {
|
||||
// Order is significant here - only add to the end for parcelable compatibility!
|
||||
UNKNOWN, USER_ID_CONFIRMED, USER_ID_UNCONFIRMED, USER_ID_MISSING;
|
||||
public static final SenderStatusResult[] VALUES = values();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,664 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp.util;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import org.openintents.openpgp.IOpenPgpService2;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSinkTransferThread;
|
||||
import org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSourceTransferThread;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class OpenPgpApi {
|
||||
|
||||
public static final String SERVICE_INTENT_2 = "org.openintents.openpgp.IOpenPgpService2";
|
||||
|
||||
/**
|
||||
* see CHANGELOG.md
|
||||
*/
|
||||
public static final int API_VERSION = 12;
|
||||
|
||||
/**
|
||||
* General extras
|
||||
* --------------
|
||||
*
|
||||
* required extras:
|
||||
* int EXTRA_API_VERSION (always required)
|
||||
*
|
||||
* returned extras:
|
||||
* int RESULT_CODE (RESULT_CODE_ERROR, RESULT_CODE_SUCCESS or RESULT_CODE_USER_INTERACTION_REQUIRED)
|
||||
* OpenPgpError RESULT_ERROR (if RESULT_CODE == RESULT_CODE_ERROR)
|
||||
* PendingIntent RESULT_INTENT (if RESULT_CODE == RESULT_CODE_USER_INTERACTION_REQUIRED)
|
||||
*/
|
||||
|
||||
/**
|
||||
* This action performs no operation, but can be used to check if the App has permission
|
||||
* to access the API in general, returning a user interaction PendingIntent otherwise.
|
||||
* This can be used to trigger the permission dialog explicitly.
|
||||
*
|
||||
* This action uses no extras.
|
||||
*/
|
||||
public static final String ACTION_CHECK_PERMISSION = "org.openintents.openpgp.action.CHECK_PERMISSION";
|
||||
|
||||
@Deprecated
|
||||
public static final String ACTION_SIGN = "org.openintents.openpgp.action.SIGN";
|
||||
|
||||
/**
|
||||
* Sign text resulting in a cleartext signature
|
||||
* Some magic pre-processing of the text is done to convert it to a format usable for
|
||||
* cleartext signatures per RFC 4880 before the text is actually signed:
|
||||
* - end cleartext with newline
|
||||
* - remove whitespaces on line endings
|
||||
*
|
||||
* required extras:
|
||||
* long EXTRA_SIGN_KEY_ID (key id of signing key)
|
||||
*
|
||||
* optional extras:
|
||||
* char[] EXTRA_PASSPHRASE (key passphrase)
|
||||
*/
|
||||
public static final String ACTION_CLEARTEXT_SIGN = "org.openintents.openpgp.action.CLEARTEXT_SIGN";
|
||||
|
||||
/**
|
||||
* Sign text or binary data resulting in a detached signature.
|
||||
* No OutputStream necessary for ACTION_DETACHED_SIGN (No magic pre-processing like in ACTION_CLEARTEXT_SIGN)!
|
||||
* The detached signature is returned separately in RESULT_DETACHED_SIGNATURE.
|
||||
*
|
||||
* required extras:
|
||||
* long EXTRA_SIGN_KEY_ID (key id of signing key)
|
||||
*
|
||||
* optional extras:
|
||||
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for detached signature)
|
||||
* char[] EXTRA_PASSPHRASE (key passphrase)
|
||||
*
|
||||
* returned extras:
|
||||
* byte[] RESULT_DETACHED_SIGNATURE
|
||||
* String RESULT_SIGNATURE_MICALG (contains the name of the used signature algorithm as a string)
|
||||
*/
|
||||
public static final String ACTION_DETACHED_SIGN = "org.openintents.openpgp.action.DETACHED_SIGN";
|
||||
|
||||
/**
|
||||
* Encrypt
|
||||
*
|
||||
* required extras:
|
||||
* String[] EXTRA_USER_IDS (=emails of recipients, if more than one key has a user_id, a PendingIntent is returned via RESULT_INTENT)
|
||||
* or
|
||||
* long[] EXTRA_KEY_IDS
|
||||
*
|
||||
* optional extras:
|
||||
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for output)
|
||||
* char[] EXTRA_PASSPHRASE (key passphrase)
|
||||
* String EXTRA_ORIGINAL_FILENAME (original filename to be encrypted as metadata)
|
||||
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default ist true)
|
||||
*/
|
||||
public static final String ACTION_ENCRYPT = "org.openintents.openpgp.action.ENCRYPT";
|
||||
|
||||
/**
|
||||
* Sign and encrypt
|
||||
*
|
||||
* required extras:
|
||||
* String[] EXTRA_USER_IDS (=emails of recipients, if more than one key has a user_id, a PendingIntent is returned via RESULT_INTENT)
|
||||
* or
|
||||
* long[] EXTRA_KEY_IDS
|
||||
*
|
||||
* optional extras:
|
||||
* long EXTRA_SIGN_KEY_ID (key id of signing key)
|
||||
* boolean EXTRA_REQUEST_ASCII_ARMOR (request ascii armor for output)
|
||||
* char[] EXTRA_PASSPHRASE (key passphrase)
|
||||
* String EXTRA_ORIGINAL_FILENAME (original filename to be encrypted as metadata)
|
||||
* boolean EXTRA_ENABLE_COMPRESSION (enable ZLIB compression, default ist true)
|
||||
*/
|
||||
public static final String ACTION_SIGN_AND_ENCRYPT = "org.openintents.openpgp.action.SIGN_AND_ENCRYPT";
|
||||
|
||||
public static final String ACTION_QUERY_AUTOCRYPT_STATUS = "org.openintents.openpgp.action.QUERY_AUTOCRYPT_STATUS";
|
||||
|
||||
/**
|
||||
* Decrypts and verifies given input stream. This methods handles encrypted-only, signed-and-encrypted,
|
||||
* and also signed-only input.
|
||||
* OutputStream is optional, e.g., for verifying detached signatures!
|
||||
*
|
||||
* If OpenPgpSignatureResult.getResult() == OpenPgpSignatureResult.RESULT_KEY_MISSING
|
||||
* in addition a PendingIntent is returned via RESULT_INTENT to download missing keys.
|
||||
* On all other status, in addition a PendingIntent is returned via RESULT_INTENT to open
|
||||
* the key view in OpenKeychain.
|
||||
*
|
||||
* optional extras:
|
||||
* byte[] EXTRA_DETACHED_SIGNATURE (detached signature)
|
||||
*
|
||||
* returned extras:
|
||||
* OpenPgpSignatureResult RESULT_SIGNATURE
|
||||
* OpenPgpDecryptionResult RESULT_DECRYPTION
|
||||
* OpenPgpDecryptMetadata RESULT_METADATA
|
||||
* String RESULT_CHARSET (charset which was specified in the headers of ascii armored input, if any)
|
||||
*/
|
||||
public static final String ACTION_DECRYPT_VERIFY = "org.openintents.openpgp.action.DECRYPT_VERIFY";
|
||||
|
||||
/**
|
||||
* Decrypts the header of an encrypted file to retrieve metadata such as original filename.
|
||||
*
|
||||
* This does not decrypt the actual content of the file.
|
||||
*
|
||||
* returned extras:
|
||||
* OpenPgpDecryptMetadata RESULT_METADATA
|
||||
* String RESULT_CHARSET (charset which was specified in the headers of ascii armored input, if any)
|
||||
*/
|
||||
public static final String ACTION_DECRYPT_METADATA = "org.openintents.openpgp.action.DECRYPT_METADATA";
|
||||
|
||||
/**
|
||||
* Select key id for signing
|
||||
*
|
||||
* optional extras:
|
||||
* String EXTRA_USER_ID
|
||||
*
|
||||
* returned extras:
|
||||
* long EXTRA_SIGN_KEY_ID
|
||||
*/
|
||||
public static final String ACTION_GET_SIGN_KEY_ID = "org.openintents.openpgp.action.GET_SIGN_KEY_ID";
|
||||
|
||||
/**
|
||||
* Get key ids based on given user ids (=emails)
|
||||
*
|
||||
* required extras:
|
||||
* String[] EXTRA_USER_IDS
|
||||
*
|
||||
* returned extras:
|
||||
* long[] RESULT_KEY_IDS
|
||||
*/
|
||||
public static final String ACTION_GET_KEY_IDS = "org.openintents.openpgp.action.GET_KEY_IDS";
|
||||
|
||||
/**
|
||||
* This action returns RESULT_CODE_SUCCESS if the OpenPGP Provider already has the key
|
||||
* corresponding to the given key id in its database.
|
||||
*
|
||||
* It returns RESULT_CODE_USER_INTERACTION_REQUIRED if the Provider does not have the key.
|
||||
* The PendingIntent from RESULT_INTENT can be used to retrieve those from a keyserver.
|
||||
*
|
||||
* If an Output stream has been defined the whole public key is returned.
|
||||
* required extras:
|
||||
* long EXTRA_KEY_ID
|
||||
*
|
||||
* optional extras:
|
||||
* String EXTRA_REQUEST_ASCII_ARMOR (request that the returned key is encoded in ASCII Armor)
|
||||
*/
|
||||
public static final String ACTION_GET_KEY = "org.openintents.openpgp.action.GET_KEY";
|
||||
|
||||
/**
|
||||
* Backup all keys given by EXTRA_KEY_IDS and if requested their secret parts.
|
||||
* The encrypted backup will be written to the OutputStream.
|
||||
* The client app has no access to the backup code used to encrypt the backup!
|
||||
* This operation always requires user interaction with RESULT_CODE_USER_INTERACTION_REQUIRED!
|
||||
*
|
||||
* required extras:
|
||||
* long[] EXTRA_KEY_IDS (keys that should be included in the backup)
|
||||
* boolean EXTRA_BACKUP_SECRET (also backup secret keys)
|
||||
*/
|
||||
public static final String ACTION_BACKUP = "org.openintents.openpgp.action.BACKUP";
|
||||
|
||||
/**
|
||||
* Update the status of some Autocrypt peer, identified by their peer id.
|
||||
*
|
||||
* required extras:
|
||||
* String EXTRA_AUTOCRYPT_PEER_ID (autocrypt peer id to update)
|
||||
* AutocryptPeerUpdate EXTRA_AUTOCRYPT_PEER_UPDATE (actual peer update)
|
||||
*/
|
||||
public static final String ACTION_UPDATE_AUTOCRYPT_PEER = "org.openintents.openpgp.action.UPDATE_AUTOCRYPT_PEER";
|
||||
|
||||
/* Intent extras */
|
||||
public static final String EXTRA_API_VERSION = "api_version";
|
||||
|
||||
// ACTION_DETACHED_SIGN, ENCRYPT, SIGN_AND_ENCRYPT, DECRYPT_VERIFY
|
||||
// request ASCII Armor for output
|
||||
// OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
|
||||
public static final String EXTRA_REQUEST_ASCII_ARMOR = "ascii_armor";
|
||||
|
||||
// ACTION_DETACHED_SIGN
|
||||
public static final String RESULT_DETACHED_SIGNATURE = "detached_signature";
|
||||
public static final String RESULT_SIGNATURE_MICALG = "signature_micalg";
|
||||
|
||||
// ENCRYPT, SIGN_AND_ENCRYPT, QUERY_AUTOCRYPT_STATUS
|
||||
public static final String EXTRA_USER_IDS = "user_ids";
|
||||
public static final String EXTRA_KEY_IDS = "key_ids";
|
||||
public static final String EXTRA_KEY_IDS_SELECTED = "key_ids_selected";
|
||||
public static final String EXTRA_SIGN_KEY_ID = "sign_key_id";
|
||||
|
||||
public static final String RESULT_KEYS_CONFIRMED = "keys_confirmed";
|
||||
public static final String RESULT_AUTOCRYPT_STATUS = "autocrypt_status";
|
||||
public static final int AUTOCRYPT_STATUS_UNAVAILABLE = 0;
|
||||
public static final int AUTOCRYPT_STATUS_DISCOURAGE = 1;
|
||||
public static final int AUTOCRYPT_STATUS_AVAILABLE = 2;
|
||||
public static final int AUTOCRYPT_STATUS_MUTUAL = 3;
|
||||
|
||||
// optional extras:
|
||||
public static final String EXTRA_PASSPHRASE = "passphrase";
|
||||
public static final String EXTRA_ORIGINAL_FILENAME = "original_filename";
|
||||
public static final String EXTRA_ENABLE_COMPRESSION = "enable_compression";
|
||||
public static final String EXTRA_OPPORTUNISTIC_ENCRYPTION = "opportunistic";
|
||||
|
||||
// GET_SIGN_KEY_ID
|
||||
public static final String EXTRA_USER_ID = "user_id";
|
||||
public static final String EXTRA_PRESELECT_KEY_ID = "preselect_key_id";
|
||||
public static final String EXTRA_SHOW_AUTOCRYPT_HINT = "show_autocrypt_hint";
|
||||
|
||||
// GET_KEY
|
||||
public static final String EXTRA_KEY_ID = "key_id";
|
||||
public static final String EXTRA_MINIMIZE = "minimize";
|
||||
public static final String EXTRA_MINIMIZE_USER_ID = "minimize_user_id";
|
||||
public static final String RESULT_KEY_IDS = "key_ids";
|
||||
|
||||
// AUTOCRYPT_KEY_TRANSFER
|
||||
public static final String ACTION_AUTOCRYPT_KEY_TRANSFER = "autocrypt_key_transfer";
|
||||
|
||||
// BACKUP
|
||||
public static final String EXTRA_BACKUP_SECRET = "backup_secret";
|
||||
|
||||
/* Service Intent returns */
|
||||
public static final String RESULT_CODE = "result_code";
|
||||
|
||||
// get actual error object from RESULT_ERROR
|
||||
public static final int RESULT_CODE_ERROR = 0;
|
||||
// success!
|
||||
public static final int RESULT_CODE_SUCCESS = 1;
|
||||
// get PendingIntent from RESULT_INTENT, start PendingIntent with startIntentSenderForResult,
|
||||
// and execute service method again in onActivityResult
|
||||
public static final int RESULT_CODE_USER_INTERACTION_REQUIRED = 2;
|
||||
|
||||
public static final String RESULT_ERROR = "error";
|
||||
public static final String RESULT_INTENT = "intent";
|
||||
|
||||
// DECRYPT_VERIFY
|
||||
public static final String EXTRA_DETACHED_SIGNATURE = "detached_signature";
|
||||
public static final String EXTRA_PROGRESS_MESSENGER = "progress_messenger";
|
||||
public static final String EXTRA_DATA_LENGTH = "data_length";
|
||||
public static final String EXTRA_DECRYPTION_RESULT = "decryption_result";
|
||||
public static final String EXTRA_SENDER_ADDRESS = "sender_address";
|
||||
public static final String EXTRA_SUPPORT_OVERRIDE_CRYPTO_WARNING = "support_override_crpto_warning";
|
||||
public static final String RESULT_SIGNATURE = "signature";
|
||||
public static final String RESULT_DECRYPTION = "decryption";
|
||||
public static final String RESULT_METADATA = "metadata";
|
||||
public static final String RESULT_INSECURE_DETAIL_INTENT = "insecure_detail_intent";
|
||||
public static final String RESULT_OVERRIDE_CRYPTO_WARNING = "override_crypto_warning";
|
||||
// This will be the charset which was specified in the headers of ascii armored input, if any
|
||||
public static final String RESULT_CHARSET = "charset";
|
||||
|
||||
// UPDATE_AUTOCRYPT_PEER
|
||||
public static final String EXTRA_AUTOCRYPT_PEER_ID = "autocrypt_peer_id";
|
||||
public static final String EXTRA_AUTOCRYPT_PEER_UPDATE = "autocrypt_peer_update";
|
||||
public static final String EXTRA_AUTOCRYPT_PEER_GOSSIP_UPDATES = "autocrypt_peer_gossip_updates";
|
||||
|
||||
// INTERNAL, must not be used
|
||||
public static final String EXTRA_CALL_UUID1 = "call_uuid1";
|
||||
public static final String EXTRA_CALL_UUID2 = "call_uuid2";
|
||||
|
||||
IOpenPgpService2 mService;
|
||||
Context mContext;
|
||||
final AtomicInteger mPipeIdGen = new AtomicInteger();
|
||||
|
||||
public OpenPgpApi(Context context, IOpenPgpService2 service) {
|
||||
this.mContext = context;
|
||||
this.mService = service;
|
||||
}
|
||||
|
||||
public interface IOpenPgpCallback {
|
||||
void onReturn(final Intent result);
|
||||
}
|
||||
|
||||
public interface IOpenPgpSinkResultCallback<T> {
|
||||
void onProgress(int current, int max);
|
||||
void onReturn(final Intent result, T sinkResult);
|
||||
}
|
||||
|
||||
public interface CancelableBackgroundOperation {
|
||||
void cancelOperation();
|
||||
}
|
||||
|
||||
private class OpenPgpSourceSinkAsyncTask<T> extends AsyncTask<Void, Integer, OpenPgpDataResult<T>>
|
||||
implements CancelableBackgroundOperation {
|
||||
Intent data;
|
||||
OpenPgpDataSource dataSource;
|
||||
OpenPgpDataSink<T> dataSink;
|
||||
IOpenPgpSinkResultCallback<T> callback;
|
||||
|
||||
private OpenPgpSourceSinkAsyncTask(Intent data, OpenPgpDataSource dataSource,
|
||||
OpenPgpDataSink<T> dataSink, IOpenPgpSinkResultCallback<T> callback) {
|
||||
this.data = data;
|
||||
this.dataSource = dataSource;
|
||||
this.dataSink = dataSink;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OpenPgpDataResult<T> doInBackground(Void... unused) {
|
||||
return executeApi(data, dataSource, dataSink);
|
||||
}
|
||||
|
||||
protected void onPostExecute(OpenPgpDataResult<T> result) {
|
||||
callback.onReturn(result.apiResult, result.sinkResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelOperation() {
|
||||
cancel(true);
|
||||
if (dataSource != null) {
|
||||
dataSource.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Intent> {
|
||||
Intent data;
|
||||
InputStream is;
|
||||
OutputStream os;
|
||||
IOpenPgpCallback callback;
|
||||
|
||||
private OpenPgpAsyncTask(Intent data, InputStream is, OutputStream os, IOpenPgpCallback callback) {
|
||||
this.data = data;
|
||||
this.is = is;
|
||||
this.os = os;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent doInBackground(Void... unused) {
|
||||
return executeApi(data, is, os);
|
||||
}
|
||||
|
||||
protected void onPostExecute(Intent result) {
|
||||
callback.onReturn(result);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> CancelableBackgroundOperation executeApiAsync(Intent data, OpenPgpDataSource dataSource,
|
||||
OpenPgpDataSink<T> dataSink, final IOpenPgpSinkResultCallback<T> callback) {
|
||||
Messenger messenger = new Messenger(new Handler(new Handler.Callback() {
|
||||
@Override
|
||||
public boolean handleMessage(Message message) {
|
||||
callback.onProgress(message.arg1, message.arg2);
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
data.putExtra(EXTRA_PROGRESS_MESSENGER, messenger);
|
||||
|
||||
OpenPgpSourceSinkAsyncTask<T> task = new OpenPgpSourceSinkAsyncTask<>(data, dataSource, dataSink, callback);
|
||||
|
||||
// don't serialize async tasks!
|
||||
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
public AsyncTask executeApiAsync(Intent data, OpenPgpDataSource dataSource, IOpenPgpSinkResultCallback<Void> callback) {
|
||||
OpenPgpSourceSinkAsyncTask<Void> task = new OpenPgpSourceSinkAsyncTask<>(data, dataSource, null, callback);
|
||||
|
||||
// don't serialize async tasks!
|
||||
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
public void executeApiAsync(Intent data, InputStream is, OutputStream os, IOpenPgpCallback callback) {
|
||||
OpenPgpAsyncTask task = new OpenPgpAsyncTask(data, is, os, callback);
|
||||
|
||||
// don't serialize async tasks!
|
||||
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
|
||||
}
|
||||
|
||||
public static class OpenPgpDataResult<T> {
|
||||
Intent apiResult;
|
||||
T sinkResult;
|
||||
|
||||
public OpenPgpDataResult(Intent apiResult, T sinkResult) {
|
||||
this.apiResult = apiResult;
|
||||
this.sinkResult = sinkResult;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> OpenPgpDataResult<T> executeApi(Intent data, OpenPgpDataSource dataSource, OpenPgpDataSink<T> dataSink) {
|
||||
ParcelFileDescriptor input = null;
|
||||
ParcelFileDescriptor output = null;
|
||||
try {
|
||||
if (dataSource != null) {
|
||||
Long expectedSize = dataSource.getSizeForProgress();
|
||||
if (expectedSize != null) {
|
||||
data.putExtra(EXTRA_DATA_LENGTH, (long) expectedSize);
|
||||
} else {
|
||||
data.removeExtra(EXTRA_PROGRESS_MESSENGER);
|
||||
}
|
||||
input = dataSource.startPumpThread();
|
||||
}
|
||||
|
||||
DataSinkTransferThread<T> pumpThread = null;
|
||||
int outputPipeId = 0;
|
||||
|
||||
if (dataSink != null) {
|
||||
outputPipeId = mPipeIdGen.incrementAndGet();
|
||||
output = mService.createOutputPipe(outputPipeId);
|
||||
pumpThread = ParcelFileDescriptorUtil.asyncPipeToDataSink(dataSink, output);
|
||||
}
|
||||
|
||||
Intent result = executeApi(data, input, outputPipeId);
|
||||
|
||||
if (pumpThread == null) {
|
||||
return new OpenPgpDataResult<>(result, null);
|
||||
}
|
||||
|
||||
// wait for ALL data being pumped from remote side
|
||||
pumpThread.join();
|
||||
return new OpenPgpDataResult<>(result, pumpThread.getResult());
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Exception in executeApi call");
|
||||
Intent result = new Intent();
|
||||
result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
|
||||
result.putExtra(RESULT_ERROR,
|
||||
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
|
||||
return new OpenPgpDataResult<>(result, null);
|
||||
} finally {
|
||||
closeLoudly(output);
|
||||
}
|
||||
}
|
||||
|
||||
public Intent executeApi(Intent data, InputStream is, OutputStream os) {
|
||||
ParcelFileDescriptor input = null;
|
||||
ParcelFileDescriptor output = null;
|
||||
try {
|
||||
if (is != null) {
|
||||
input = ParcelFileDescriptorUtil.pipeFrom(is);
|
||||
}
|
||||
|
||||
Thread pumpThread = null;
|
||||
int outputPipeId = 0;
|
||||
|
||||
if (os != null) {
|
||||
outputPipeId = mPipeIdGen.incrementAndGet();
|
||||
output = mService.createOutputPipe(outputPipeId);
|
||||
pumpThread = ParcelFileDescriptorUtil.pipeTo(os, output);
|
||||
}
|
||||
|
||||
Intent result = executeApi(data, input, outputPipeId);
|
||||
|
||||
// wait for ALL data being pumped from remote side
|
||||
if (pumpThread != null) {
|
||||
pumpThread.join();
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Exception in executeApi call");
|
||||
Intent result = new Intent();
|
||||
result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
|
||||
result.putExtra(RESULT_ERROR,
|
||||
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
|
||||
return result;
|
||||
} finally {
|
||||
closeLoudly(output);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class OpenPgpDataSource {
|
||||
private boolean isCancelled;
|
||||
private ParcelFileDescriptor writeSidePfd;
|
||||
|
||||
|
||||
public abstract void writeTo(OutputStream os) throws IOException;
|
||||
|
||||
public Long getSizeForProgress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor startPumpThread() throws IOException {
|
||||
if (writeSidePfd != null) {
|
||||
throw new IllegalStateException("startPumpThread() must only be called once!");
|
||||
}
|
||||
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
|
||||
ParcelFileDescriptor readSidePfd = pipe[0];
|
||||
writeSidePfd = pipe[1];
|
||||
|
||||
new DataSourceTransferThread(this, new ParcelFileDescriptor.AutoCloseOutputStream(writeSidePfd)).start();
|
||||
|
||||
return readSidePfd;
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
isCancelled = true;
|
||||
try {
|
||||
writeSidePfd.close();
|
||||
} catch (IOException e) {
|
||||
// this is fine
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OpenPgpDataSink<T> {
|
||||
T processData(InputStream is) throws IOException;
|
||||
}
|
||||
|
||||
public Intent executeApi(Intent data, OpenPgpDataSource dataSource, OutputStream os) {
|
||||
ParcelFileDescriptor input = null;
|
||||
ParcelFileDescriptor output;
|
||||
try {
|
||||
if (dataSource != null) {
|
||||
Long expectedSize = dataSource.getSizeForProgress();
|
||||
if (expectedSize != null) {
|
||||
data.putExtra(EXTRA_DATA_LENGTH, (long) expectedSize);
|
||||
} else {
|
||||
data.removeExtra(EXTRA_PROGRESS_MESSENGER);
|
||||
}
|
||||
input = dataSource.startPumpThread();
|
||||
}
|
||||
|
||||
Thread pumpThread = null;
|
||||
int outputPipeId = 0;
|
||||
|
||||
if (os != null) {
|
||||
outputPipeId = mPipeIdGen.incrementAndGet();
|
||||
output = mService.createOutputPipe(outputPipeId);
|
||||
pumpThread = ParcelFileDescriptorUtil.pipeTo(os, output);
|
||||
}
|
||||
|
||||
Intent result = executeApi(data, input, outputPipeId);
|
||||
|
||||
// wait for ALL data being pumped from remote side
|
||||
if (pumpThread != null) {
|
||||
pumpThread.join();
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Exception in executeApi call");
|
||||
Intent result = new Intent();
|
||||
result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
|
||||
result.putExtra(RESULT_ERROR,
|
||||
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* InputStream and OutputStreams are always closed after operating on them!
|
||||
*/
|
||||
private Intent executeApi(Intent data, ParcelFileDescriptor input, int outputPipeId) {
|
||||
try {
|
||||
// always send version from client
|
||||
data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION);
|
||||
|
||||
Intent result;
|
||||
|
||||
// blocks until result is ready
|
||||
result = mService.execute(data, input, outputPipeId);
|
||||
|
||||
// set class loader to current context to allow unparcelling
|
||||
// of OpenPgpError and OpenPgpSignatureResult
|
||||
// http://stackoverflow.com/a/3806769
|
||||
result.setExtrasClassLoader(mContext.getClassLoader());
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Exception in executeApi call");
|
||||
Intent result = new Intent();
|
||||
result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
|
||||
result.putExtra(RESULT_ERROR,
|
||||
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
|
||||
return result;
|
||||
} finally {
|
||||
// close() is required to halt the TransferThread
|
||||
closeLoudly(input);
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeLoudly(ParcelFileDescriptor input) {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "IOException when closing ParcelFileDescriptor!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface PermissionPingCallback {
|
||||
void onPgpPermissionCheckResult(Intent result);
|
||||
}
|
||||
|
||||
public void checkPermissionPing(final PermissionPingCallback permissionPingCallback) {
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_CHECK_PERMISSION);
|
||||
executeApiAsync(intent, null, null, new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
permissionPingCallback.onPgpPermissionCheckResult(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,334 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The K-9 Dog Walkers
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp.util;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.content.res.TypedArray;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpApiManager;
|
||||
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpApiManagerCallback;
|
||||
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderError;
|
||||
import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderState;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.R;
|
||||
import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class OpenPgpKeyPreference extends Preference implements OpenPgpApiManagerCallback {
|
||||
private long keyId;
|
||||
private String defaultUserId;
|
||||
private boolean showAutocryptHint;
|
||||
private OpenPgpApiManager openPgpApiManager;
|
||||
private Intent cachedActivityResultData;
|
||||
private Fragment intentSenderFragment;
|
||||
|
||||
private PendingIntent pendingIntentSelectKey;
|
||||
private boolean pendingIntentRunImmediately;
|
||||
|
||||
private String keyPrimaryUserId;
|
||||
private long keyCreationTime;
|
||||
|
||||
private static final int REQUEST_CODE_API_MANAGER = 9998;
|
||||
private static final int REQUEST_CODE_KEY_PREFERENCE = 9999;
|
||||
|
||||
private static final int NO_KEY = 0;
|
||||
|
||||
public OpenPgpKeyPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setOpenPgpProvider(OpenPgpApiManager openPgpApiManager, String openPgpProvider) {
|
||||
this.openPgpApiManager = openPgpApiManager;
|
||||
this.openPgpApiManager.setOpenPgpProvider(openPgpProvider, this);
|
||||
refreshTitleAndSummary();
|
||||
}
|
||||
|
||||
public void setIntentSenderFragment(Fragment fragment) {
|
||||
intentSenderFragment = fragment;
|
||||
}
|
||||
|
||||
public void setDefaultUserId(String userId) {
|
||||
defaultUserId = userId;
|
||||
}
|
||||
|
||||
public void setShowAutocryptHint(boolean showAutocryptHint) {
|
||||
this.showAutocryptHint = showAutocryptHint;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
switch (openPgpApiManager.getOpenPgpProviderState()) {
|
||||
// The GET_SIGN_KEY action is special, in that it can be used as an implicit registration
|
||||
// to the API. Therefore, we can ignore the UI_REQUIRED here. If it comes up regardless,
|
||||
// it will also work as a regular pending intent.
|
||||
case UI_REQUIRED:
|
||||
case OK: {
|
||||
apiGetOrStartPendingIntent();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
refreshTitleAndSummary();
|
||||
openPgpApiManager.refreshConnection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpenPgpProviderStatusChanged() {
|
||||
if (openPgpApiManager.getOpenPgpProviderState() == OpenPgpProviderState.OK) {
|
||||
apiRetrievePendingIntentAndKeyInfo();
|
||||
} else {
|
||||
pendingIntentSelectKey = null;
|
||||
pendingIntentRunImmediately = false;
|
||||
cachedActivityResultData = null;
|
||||
refreshTitleAndSummary();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpenPgpProviderError(OpenPgpProviderError error) {
|
||||
if (error == OpenPgpProviderError.ConnectionLost) {
|
||||
openPgpApiManager.refreshConnection();
|
||||
}
|
||||
}
|
||||
|
||||
private void apiRetrievePendingIntentAndKeyInfo() {
|
||||
Intent data;
|
||||
if (cachedActivityResultData != null) {
|
||||
data = cachedActivityResultData;
|
||||
cachedActivityResultData = null;
|
||||
} else {
|
||||
data = new Intent();
|
||||
}
|
||||
apiRetrievePendingIntentAndKeyInfo(data);
|
||||
}
|
||||
|
||||
private void apiRetrievePendingIntentAndKeyInfo(Intent data) {
|
||||
data.setAction(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
|
||||
data.putExtra(OpenPgpApi.EXTRA_USER_ID, defaultUserId);
|
||||
data.putExtra(OpenPgpApi.EXTRA_PRESELECT_KEY_ID, keyId);
|
||||
data.putExtra(OpenPgpApi.EXTRA_SHOW_AUTOCRYPT_HINT, showAutocryptHint);
|
||||
OpenPgpApi api = openPgpApiManager.getOpenPgpApi();
|
||||
api.executeApiAsync(data, null, null, openPgpCallback);
|
||||
}
|
||||
|
||||
private IOpenPgpCallback openPgpCallback = new IOpenPgpCallback() {
|
||||
@Override
|
||||
public void onReturn(Intent result) {
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
switch (resultCode) {
|
||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
|
||||
PendingIntent pendingIntentSelectKey = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||
|
||||
if (result.hasExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
|
||||
long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, NO_KEY);
|
||||
long keyCreationTime = result.getLongExtra("key_creation_time", 0);
|
||||
String primaryUserId = result.getStringExtra("primary_user_id");
|
||||
|
||||
updateWidgetData(keyId, primaryUserId, keyCreationTime, pendingIntentSelectKey);
|
||||
} else {
|
||||
updateWidgetData(pendingIntentSelectKey);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case OpenPgpApi.RESULT_CODE_ERROR: {
|
||||
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
||||
Timber.e("RESULT_CODE_ERROR: %s", error.getMessage());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void apiGetOrStartPendingIntent() {
|
||||
if (pendingIntentSelectKey != null) {
|
||||
apiStartPendingIntent();
|
||||
return;
|
||||
}
|
||||
|
||||
pendingIntentRunImmediately = true;
|
||||
apiRetrievePendingIntentAndKeyInfo();
|
||||
}
|
||||
|
||||
private void apiStartPendingIntent() {
|
||||
if (pendingIntentSelectKey == null) {
|
||||
Timber.e("Tried to launch pending intent but didn't have any?");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
intentSenderFragment
|
||||
.startIntentSenderForResult(pendingIntentSelectKey.getIntentSender(), REQUEST_CODE_KEY_PREFERENCE,
|
||||
null, 0, 0, 0, null);
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
Timber.e(e,"Error launching pending intent");
|
||||
} finally {
|
||||
pendingIntentSelectKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWidgetData(PendingIntent pendingIntentSelectKey) {
|
||||
this.keyPrimaryUserId = null;
|
||||
this.keyCreationTime = 0;
|
||||
this.pendingIntentSelectKey = pendingIntentSelectKey;
|
||||
|
||||
maybeRunPendingIntentImmediately();
|
||||
refreshTitleAndSummary();
|
||||
}
|
||||
|
||||
private void updateWidgetData(long keyId, String primaryUserId, long keyCreationTime,
|
||||
PendingIntent pendingIntentSelectKey) {
|
||||
setAndPersist(keyId);
|
||||
this.keyPrimaryUserId = primaryUserId;
|
||||
this.keyCreationTime = keyCreationTime;
|
||||
this.pendingIntentSelectKey = pendingIntentSelectKey;
|
||||
|
||||
callChangeListener(keyId);
|
||||
maybeRunPendingIntentImmediately();
|
||||
refreshTitleAndSummary();
|
||||
}
|
||||
|
||||
private void maybeRunPendingIntentImmediately() {
|
||||
if (!pendingIntentRunImmediately) {
|
||||
return;
|
||||
}
|
||||
|
||||
pendingIntentRunImmediately = false;
|
||||
apiStartPendingIntent();
|
||||
}
|
||||
|
||||
private void refreshTitleAndSummary() {
|
||||
boolean isConfigured = openPgpApiManager != null &&
|
||||
openPgpApiManager.getOpenPgpProviderState() != OpenPgpProviderState.UNCONFIGURED;
|
||||
setEnabled(isConfigured);
|
||||
|
||||
if (this.keyId == NO_KEY) {
|
||||
setTitle(R.string.openpgp_key_title);
|
||||
setSummary(R.string.openpgp_no_key_selected);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.keyPrimaryUserId != null && this.keyCreationTime != 0) {
|
||||
Context context = getContext();
|
||||
|
||||
UserId userId = OpenPgpUtils.splitUserId(keyPrimaryUserId);
|
||||
if (userId.email != null) {
|
||||
setTitle(context.getString(R.string.openpgp_key_using, userId.email));
|
||||
} else if (userId.name != null) {
|
||||
setTitle(context.getString(R.string.openpgp_key_using, userId.name));
|
||||
} else {
|
||||
setTitle(R.string.openpgp_key_using_no_name);
|
||||
}
|
||||
|
||||
String creationTimeStr = DateUtils.formatDateTime(context, keyCreationTime,
|
||||
DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME |
|
||||
DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH);
|
||||
setSummary(context.getString(R.string.openpgp_key_created, creationTimeStr));
|
||||
} else {
|
||||
setTitle(R.string.openpgp_key_title);
|
||||
setSummary(R.string.openpgp_key_selected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API
|
||||
*/
|
||||
public void setValue(long keyId) {
|
||||
setAndPersist(keyId);
|
||||
refreshTitleAndSummary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API
|
||||
*/
|
||||
public long getValue() {
|
||||
return keyId;
|
||||
}
|
||||
|
||||
private void setAndPersist(long newValue) {
|
||||
keyId = newValue;
|
||||
notifyDependencyChange(shouldDisableDependents());
|
||||
|
||||
// Save to persistent storage (this method will make sure this
|
||||
// preference should be persistent, along with other useful checks)
|
||||
persistLong(keyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
// This preference type's value type is Long, so we read the default
|
||||
// value from the attributes as an Integer.
|
||||
return (long) a.getInteger(index, NO_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||
if (restoreValue) {
|
||||
// Restore state
|
||||
keyId = getPersistedLong(keyId);
|
||||
notifyDependencyChange(shouldDisableDependents());
|
||||
} else {
|
||||
// Set state
|
||||
long value = (Long) defaultValue;
|
||||
setAndPersist(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDisableDependents() {
|
||||
return keyId == NO_KEY || super.shouldDisableDependents();
|
||||
}
|
||||
|
||||
public boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_API_MANAGER:
|
||||
openPgpApiManager.onUserInteractionResult();
|
||||
return true;
|
||||
case REQUEST_CODE_KEY_PREFERENCE:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
cachedActivityResultData = data;
|
||||
// this might happen early in the lifecycle (e.g. before onResume). if the provider isn't connected
|
||||
// here, apiRetrievePendingIntentAndKeyInfo() will be called as soon as it is.
|
||||
OpenPgpProviderState openPgpProviderState = openPgpApiManager.getOpenPgpProviderState();
|
||||
if (openPgpProviderState == OpenPgpProviderState.OK ||
|
||||
openPgpProviderState == OpenPgpProviderState.UI_REQUIRED) {
|
||||
apiRetrievePendingIntentAndKeyInfo();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package org.openintents.openpgp.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
|
||||
public class OpenPgpProviderUtil {
|
||||
private static final String PACKAGE_NAME_APG = "org.thialfihar.android.apg";
|
||||
private static final ArrayList<String> DISALLOWED_PROVIDERS = new ArrayList<>();
|
||||
static {
|
||||
DISALLOWED_PROVIDERS.add(PACKAGE_NAME_APG);
|
||||
}
|
||||
|
||||
public static List<String> getOpenPgpProviderPackages(Context context) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
|
||||
if (resInfo == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (ResolveInfo resolveInfo : resInfo) {
|
||||
if (resolveInfo.serviceInfo == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.add(resolveInfo.serviceInfo.packageName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getOpenPgpProviderName(PackageManager packageManager, String openPgpProvider) {
|
||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
intent.setPackage(openPgpProvider);
|
||||
List<ResolveInfo> resInfo = packageManager.queryIntentServices(intent, 0);
|
||||
if (resInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ResolveInfo resolveInfo : resInfo) {
|
||||
if (resolveInfo.serviceInfo == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return String.valueOf(resolveInfo.serviceInfo.loadLabel(packageManager));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isProviderAllowed(String packageName) {
|
||||
return !DISALLOWED_PROVIDERS.contains(packageName);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp.util;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
|
||||
import org.openintents.openpgp.IOpenPgpService2;
|
||||
|
||||
public class OpenPgpServiceConnection {
|
||||
|
||||
// callback interface
|
||||
public interface OnBound {
|
||||
void onBound(IOpenPgpService2 service);
|
||||
|
||||
void onError(Exception e);
|
||||
}
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
private IOpenPgpService2 mService;
|
||||
private String mProviderPackageName;
|
||||
|
||||
private OnBound mOnBoundListener;
|
||||
|
||||
/**
|
||||
* Create new connection
|
||||
*
|
||||
* @param context
|
||||
* @param providerPackageName specify package name of OpenPGP provider,
|
||||
* e.g., "org.sufficientlysecure.keychain"
|
||||
*/
|
||||
public OpenPgpServiceConnection(Context context, String providerPackageName) {
|
||||
this.mApplicationContext = context.getApplicationContext();
|
||||
this.mProviderPackageName = providerPackageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new connection with callback
|
||||
*
|
||||
* @param context
|
||||
* @param providerPackageName specify package name of OpenPGP provider,
|
||||
* e.g., "org.sufficientlysecure.keychain"
|
||||
* @param onBoundListener callback, executed when connection to service has been established
|
||||
*/
|
||||
public OpenPgpServiceConnection(Context context, String providerPackageName,
|
||||
OnBound onBoundListener) {
|
||||
this(context, providerPackageName);
|
||||
this.mOnBoundListener = onBoundListener;
|
||||
}
|
||||
|
||||
public IOpenPgpService2 getService() {
|
||||
return mService;
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
return (mService != null);
|
||||
}
|
||||
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
mService = IOpenPgpService2.Stub.asInterface(service);
|
||||
if (mOnBoundListener != null) {
|
||||
mOnBoundListener.onBound(mService);
|
||||
}
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
mService = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If not already bound, bind to service!
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void bindToService() {
|
||||
// if not already bound...
|
||||
if (mService == null) {
|
||||
try {
|
||||
Intent serviceIntent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
// NOTE: setPackage is very important to restrict the intent to this provider only!
|
||||
serviceIntent.setPackage(mProviderPackageName);
|
||||
boolean connect = mApplicationContext.bindService(serviceIntent, mServiceConnection,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
if (!connect) {
|
||||
throw new Exception("bindService() returned false!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (mOnBoundListener != null) {
|
||||
mOnBoundListener.onError(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// already bound, but also inform client about it with callback
|
||||
if (mOnBoundListener != null) {
|
||||
mOnBoundListener.onBound(mService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unbindFromService() {
|
||||
mApplicationContext.unbindService(mServiceConnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp.util;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class OpenPgpUtils {
|
||||
|
||||
public static final Pattern PGP_MESSAGE = Pattern.compile(
|
||||
"(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
|
||||
Pattern.DOTALL);
|
||||
|
||||
public static final String PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----";
|
||||
public static final String PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE = "-----BEGIN PGP SIGNATURE-----";
|
||||
|
||||
public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile(
|
||||
"(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
|
||||
Pattern.DOTALL);
|
||||
|
||||
public static final int PARSE_RESULT_NO_PGP = -1;
|
||||
public static final int PARSE_RESULT_MESSAGE = 0;
|
||||
public static final int PARSE_RESULT_SIGNED_MESSAGE = 1;
|
||||
|
||||
public static int parseMessage(String message) {
|
||||
return parseMessage(message, false);
|
||||
}
|
||||
|
||||
public static int parseMessage(String message, boolean anchorToStart) {
|
||||
Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message);
|
||||
Matcher matcherMessage = PGP_MESSAGE.matcher(message);
|
||||
|
||||
if (anchorToStart ? matcherMessage.matches() : matcherMessage.find()) {
|
||||
return PARSE_RESULT_MESSAGE;
|
||||
} else if (anchorToStart ? matcherSigned.matches() : matcherSigned.find()) {
|
||||
return PARSE_RESULT_SIGNED_MESSAGE;
|
||||
} else {
|
||||
return PARSE_RESULT_NO_PGP;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
|
||||
return !resInfo.isEmpty();
|
||||
}
|
||||
|
||||
public static String convertKeyIdToHex(long keyId) {
|
||||
return "0x" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId);
|
||||
}
|
||||
|
||||
private static String convertKeyIdToHex32bit(long keyId) {
|
||||
String hexString = Long.toHexString(keyId & 0xffffffffL).toLowerCase(Locale.ENGLISH);
|
||||
while (hexString.length() < 8) {
|
||||
hexString = "0" + hexString;
|
||||
}
|
||||
return hexString;
|
||||
}
|
||||
|
||||
public static String extractClearsignedMessage(String text) {
|
||||
if (text == null || !text.startsWith(PGP_MARKER_CLEARSIGN_BEGIN_MESSAGE)) {
|
||||
return null;
|
||||
}
|
||||
int endOfHeader = text.indexOf("\r\n\r\n") +4;
|
||||
if (endOfHeader < 0) {
|
||||
return null;
|
||||
}
|
||||
int endOfCleartext = text.indexOf(PGP_MARKER_CLEARSIGN_BEGIN_SIGNATURE);
|
||||
if (endOfCleartext < 0) {
|
||||
endOfCleartext = text.length();
|
||||
}
|
||||
|
||||
return text.substring(endOfHeader, endOfCleartext);
|
||||
}
|
||||
|
||||
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
|
||||
|
||||
/**
|
||||
* Splits userId string into naming part, email part, and comment part
|
||||
* <p/>
|
||||
* User ID matching:
|
||||
* http://fiddle.re/t4p6f
|
||||
*
|
||||
* @param userId
|
||||
* @return theParsedUserInfo
|
||||
*/
|
||||
public static UserId splitUserId(final String userId) {
|
||||
if (!TextUtils.isEmpty(userId)) {
|
||||
final Matcher matcher = USER_ID_PATTERN.matcher(userId);
|
||||
if (matcher.matches()) {
|
||||
return new UserId(matcher.group(1), matcher.group(3), matcher.group(2));
|
||||
}
|
||||
}
|
||||
return new UserId(null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed user id. Returns null if name is null!
|
||||
*/
|
||||
public static String createUserId(UserId userId) {
|
||||
String userIdString = userId.name; // consider name a required value
|
||||
if (userIdString != null && !TextUtils.isEmpty(userId.comment)) {
|
||||
userIdString += " (" + userId.comment + ")";
|
||||
}
|
||||
if (userIdString != null && !TextUtils.isEmpty(userId.email)) {
|
||||
userIdString += " <" + userId.email + ">";
|
||||
}
|
||||
|
||||
return userIdString;
|
||||
}
|
||||
|
||||
public static class UserId {
|
||||
public final String name;
|
||||
public final String email;
|
||||
public final String comment;
|
||||
|
||||
public UserId(String name, String email, String comment) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* 2013 Florian Schmaus <flo@geekplace.eu>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openintents.openpgp.util;
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.OsConstants;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSink;
|
||||
import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class ParcelFileDescriptorUtil {
|
||||
|
||||
public static ParcelFileDescriptor pipeFrom(InputStream inputStream)
|
||||
throws IOException {
|
||||
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
|
||||
ParcelFileDescriptor readSide = pipe[0];
|
||||
ParcelFileDescriptor writeSide = pipe[1];
|
||||
|
||||
new TransferThread(inputStream, new ParcelFileDescriptor.AutoCloseOutputStream(writeSide))
|
||||
.start();
|
||||
|
||||
return readSide;
|
||||
}
|
||||
|
||||
public static TransferThread pipeTo(OutputStream outputStream, ParcelFileDescriptor output) {
|
||||
|
||||
AutoCloseInputStream InputStream = new AutoCloseInputStream(output);
|
||||
TransferThread t = new TransferThread(InputStream, outputStream);
|
||||
|
||||
t.start();
|
||||
return t;
|
||||
}
|
||||
|
||||
static class TransferThread extends Thread {
|
||||
final InputStream mIn;
|
||||
final OutputStream mOut;
|
||||
|
||||
TransferThread(InputStream in, OutputStream out) {
|
||||
super("IPC Transfer Thread");
|
||||
mIn = in;
|
||||
mOut = out;
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] buf = new byte[4096];
|
||||
int len;
|
||||
|
||||
try {
|
||||
while ((len = mIn.read(buf)) > 0) {
|
||||
mOut.write(buf, 0, len);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "IOException when writing to out");
|
||||
} finally {
|
||||
try {
|
||||
mIn.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
try {
|
||||
mOut.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> DataSinkTransferThread<T> asyncPipeToDataSink(
|
||||
OpenPgpDataSink<T> dataSink, ParcelFileDescriptor output) {
|
||||
InputStream inputStream = new BufferedInputStream(new AutoCloseInputStream(output));
|
||||
DataSinkTransferThread<T> dataSinkTransferThread = new DataSinkTransferThread<>(dataSink, inputStream);
|
||||
dataSinkTransferThread.start();
|
||||
return dataSinkTransferThread;
|
||||
}
|
||||
|
||||
static class DataSourceTransferThread extends Thread {
|
||||
final OpenPgpDataSource dataSource;
|
||||
final OutputStream outputStream;
|
||||
|
||||
DataSourceTransferThread(OpenPgpDataSource dataSource, OutputStream outputStream) {
|
||||
super("IPC Transfer Thread (TO service)");
|
||||
this.dataSource = dataSource;
|
||||
this.outputStream = outputStream;
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
dataSource.writeTo(outputStream);
|
||||
} catch (IOException e) {
|
||||
if (dataSource.isCancelled()) {
|
||||
Timber.d("Stopped writing because operation was cancelled.");
|
||||
} else if (isIOExceptionCausedByEPIPE(e)) {
|
||||
Timber.d("Stopped writing due to broken pipe (other end closed pipe?)");
|
||||
} else {
|
||||
Timber.e(e, "IOException when writing to out");
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isIOExceptionCausedByEPIPE(IOException e) {
|
||||
Throwable cause = e.getCause();
|
||||
return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE;
|
||||
}
|
||||
|
||||
static class DataSinkTransferThread<T> extends Thread {
|
||||
final OpenPgpDataSink<T> dataSink;
|
||||
final InputStream inputStream;
|
||||
T sinkResult;
|
||||
|
||||
DataSinkTransferThread(OpenPgpDataSink<T> dataSink, InputStream inputStream) {
|
||||
super("IPC Transfer Thread (FROM service)");
|
||||
this.dataSink = dataSink;
|
||||
this.inputStream = inputStream;
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sinkResult = dataSink.processData(inputStream);
|
||||
} catch (IOException e) {
|
||||
if (isIOExceptionCausedByEPIPE(e)) {
|
||||
Timber.e("Stopped read due to broken pipe (other end closed pipe?)");
|
||||
} else {
|
||||
Timber.e(e, "IOException while reading from in");
|
||||
}
|
||||
sinkResult = null;
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T getResult() {
|
||||
if (isAlive()) {
|
||||
throw new IllegalStateException("result must be accessed only *after* the thread finished execution!");
|
||||
}
|
||||
return sinkResult;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Žádný</string>
|
||||
<string name="openpgp_install_openkeychain_via">Instalovat OpenKeychain pomocí %s</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Keine Auswahl</string>
|
||||
<string name="openpgp_install_openkeychain_via">Installiere OpenKeychain über %s</string>
|
||||
<string name="openpgp_no_key_selected">Kein Schlüssel ausgewählt</string>
|
||||
<string name="openpgp_key_selected">Schlüssel wurde ausgewählt</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Ninguno</string>
|
||||
<string name="openpgp_install_openkeychain_via">Instalar OpenKeychain mediante %s</string>
|
||||
<string name="openpgp_no_key_selected">No se seleccionó clave</string>
|
||||
<string name="openpgp_key_selected">Se ha seleccionado clave</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Ezer ez</string>
|
||||
<string name="openpgp_install_openkeychain_via">Ezarri OpenKeychain %s bidez</string>
|
||||
<string name="openpgp_no_key_selected">Ez da giltzarik hautatu</string>
|
||||
<string name="openpgp_key_selected">Giltza hautatu da</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Aucun</string>
|
||||
<string name="openpgp_install_openkeychain_via">Installer OpenKeychain par %s</string>
|
||||
<string name="openpgp_no_key_selected">Aucune clef sélectionnée</string>
|
||||
<string name="openpgp_key_selected">La clef a été sélectionnée</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Nessuno</string>
|
||||
<string name="openpgp_install_openkeychain_via">Installa OpenKeychain via %s</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">無し</string>
|
||||
<string name="openpgp_install_openkeychain_via">%s 経由でOpenKeychainをインストール</string>
|
||||
<string name="openpgp_no_key_selected">鍵が選択されていません</string>
|
||||
<string name="openpgp_key_selected">鍵は選択済みです</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Geen</string>
|
||||
<string name="openpgp_install_openkeychain_via">Installeer OpenKeychain via %s</string>
|
||||
<string name="openpgp_no_key_selected">Geen sleutel geselecteerd</string>
|
||||
<string name="openpgp_key_selected">Sleutel is geselecteerd</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Brak</string>
|
||||
<string name="openpgp_install_openkeychain_via">Instaluj OpenKeychain przez %s</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources/>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Нет</string>
|
||||
<string name="openpgp_install_openkeychain_via">Установить OpenKeychain через %s</string>
|
||||
<string name="openpgp_no_key_selected">Ключ не выбран</string>
|
||||
<string name="openpgp_key_selected">Ключ был выбран</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Brez</string>
|
||||
<string name="openpgp_install_openkeychain_via">Namesti OpenKeychain prek %s</string>
|
||||
<string name="openpgp_no_key_selected">Izbran ni noben ključ</string>
|
||||
<string name="openpgp_key_selected">Ključ je bil izbran</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Ништа</string>
|
||||
<string name="openpgp_install_openkeychain_via">Инсталирај Отворени кључарник преко %s</string>
|
||||
<string name="openpgp_no_key_selected">Није изабран кључ</string>
|
||||
<string name="openpgp_key_selected">Кључ је изабран</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Ingen</string>
|
||||
<string name="openpgp_install_openkeychain_via">Installera OpenKeychain via %s</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Hiç</string>
|
||||
<string name="openpgp_install_openkeychain_via">%s aracılığıyla OpenKeychain\'i yükle</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">Жоден</string>
|
||||
<string name="openpgp_install_openkeychain_via">Встановити OpenKeychain через %s</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_list_preference_none">無</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<resources>
|
||||
<string name="openpgp_no_key_selected">尚未选择密钥</string>
|
||||
<string name="openpgp_key_selected">已经选中密钥</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="openpgp_list_preference_none">None</string>
|
||||
<string name="openpgp_install_openkeychain_via">Install OpenKeychain via %s</string>
|
||||
|
||||
<string name="openpgp_key_title">"Configure end-to-end key"</string>
|
||||
<string name="openpgp_no_key_selected">No end-to-end key selected</string>
|
||||
<string name="openpgp_key_selected">End-to-end key selected</string>
|
||||
<string name="openpgp_key_using">"Using key: %s"</string>
|
||||
<string name="openpgp_key_using_no_name">"Using key: <![CDATA[<no name>]]>"</string>
|
||||
<string name="openpgp_key_created">"Created %s"</string>
|
||||
</resources>
|
||||