org.witness.proofmode.crypto.PgpUtils Java Examples

The following examples show how to use org.witness.proofmode.crypto.PgpUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
private void publishKey ()
{

    try {
        if (mPgpUtils == null)
            mPgpUtils = PgpUtils.getInstance(this,mPrefs.getString("password",PgpUtils.DEFAULT_PASSWORD));

        mPgpUtils.publishPublicKey();
        String fingerprint = mPgpUtils.getPublicKeyFingerprint();

        Toast.makeText(this, R.string.open_public_key_page, Toast.LENGTH_LONG).show();

        openUrl(PgpUtils.URL_LOOKUP_ENDPOINT + fingerprint);
    }
    catch (IOException ioe)
    {
        Log.e("Proofmode","error publishing key",ioe);
    }
}
 
Example #2
Source File: MainActivity.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
private void shareKey ()
{


    try {

        if (mPgpUtils == null)
            mPgpUtils = PgpUtils.getInstance(this,mPrefs.getString("password",PgpUtils.DEFAULT_PASSWORD));

        mPgpUtils.publishPublicKey();
        String pubKey = mPgpUtils.getPublicKey();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,pubKey);
        startActivity(intent);
    }
    catch (IOException ioe)
    {
        Log.e("Proofmode","error publishing key",ioe);
    }
}
 
Example #3
Source File: ProofMode.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private static void writeProof (Context context, String mediaPath, String hash, boolean showDeviceIds, boolean showLocation, boolean showMobileNetwork, String safetyCheckResult, boolean isBasicIntegrity, boolean isCtsMatch, long notarizeTimestamp, String notes)
{

    File fileMedia = new File(mediaPath);

    File fileMediaSig = new File(mediaPath + OPENPGP_FILE_TAG);
    File fileMediaProof = new File(mediaPath + PROOF_FILE_TAG);
    File fileMediaProofSig = new File(mediaPath + PROOF_FILE_TAG + OPENPGP_FILE_TAG);

    try {

        //sign the media file
        if (!fileMediaSig.exists())
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMedia), new FileOutputStream(fileMediaSig), PgpUtils.DEFAULT_PASSWORD);

        //add data to proof csv and sign again
        boolean writeHeaders = !fileMediaProof.exists();
        writeTextToFile(context, fileMediaProof, buildProof(context, mediaPath, writeHeaders, showDeviceIds, showLocation, showMobileNetwork, safetyCheckResult, isBasicIntegrity, isCtsMatch, notarizeTimestamp, notes));

        if (fileMediaProof.exists()) {
            //sign the proof file again
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMediaProof), new FileOutputStream(fileMediaProofSig), PgpUtils.DEFAULT_PASSWORD);
        }

    } catch (Exception e) {
        Log.e("MediaWatcher", "Error signing media or proof", e);
    }

}
 
Example #4
Source File: MediaWatcher.java    From proofmode with GNU General Public License v3.0 5 votes vote down vote up
private void writeProof (Context context, Uri uriMedia, String hash, boolean showDeviceIds, boolean showLocation, boolean showMobileNetwork, String safetyCheckResult, boolean isBasicIntegrity, boolean isCtsMatch, long notarizeTimestamp, String notes)
{

  //  File fileMedia = new File(mediaPath);
    File fileFolder = getHashStorageDir(hash);

    if (fileFolder != null) {

        File fileMediaSig = new File(fileFolder, hash + OPENPGP_FILE_TAG);
        File fileMediaProof = new File(fileFolder, hash + PROOF_FILE_TAG);
        File fileMediaProofSig = new File(fileFolder, hash + PROOF_FILE_TAG + OPENPGP_FILE_TAG);

        try {

            //sign the media file
            if (!fileMediaSig.exists())
                PgpUtils.getInstance(context).createDetachedSignature(context.getContentResolver().openInputStream(uriMedia), new FileOutputStream(fileMediaSig), PgpUtils.DEFAULT_PASSWORD);

            //add data to proof csv and sign again
            boolean writeHeaders = !fileMediaProof.exists();
            String buildProof = buildProof(context, uriMedia, writeHeaders, showDeviceIds, showLocation, showMobileNetwork, safetyCheckResult, isBasicIntegrity, isCtsMatch, notarizeTimestamp, notes);
            writeTextToFile(context, fileMediaProof, buildProof);

            if (fileMediaProof.exists()) {
                //sign the proof file again
                PgpUtils.getInstance(context).createDetachedSignature(fileMediaProof, fileMediaProofSig, PgpUtils.DEFAULT_PASSWORD);
            }

        } catch (Exception e) {
            Log.e("MediaWatcher", "Error signing media or proof", e);
        }
    }
}
 
Example #5
Source File: ProofMode.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private static void writeProof (Context context, String mediaPath, String hash, boolean showDeviceIds, boolean showLocation, boolean showMobileNetwork, String safetyCheckResult, boolean isBasicIntegrity, boolean isCtsMatch, long notarizeTimestamp, String notes)
{

    File fileMedia = new File(mediaPath);

    File fileMediaSig = new File(mediaPath + OPENPGP_FILE_TAG);
    File fileMediaProof = new File(mediaPath + PROOF_FILE_TAG);
    File fileMediaProofSig = new File(mediaPath + PROOF_FILE_TAG + OPENPGP_FILE_TAG);

    try {

        //sign the media file
        if (!fileMediaSig.exists())
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMedia), new FileOutputStream(fileMediaSig), PgpUtils.DEFAULT_PASSWORD);

        //add data to proof csv and sign again
        boolean writeHeaders = !fileMediaProof.exists();
        writeTextToFile(context, fileMediaProof, buildProof(context, mediaPath, writeHeaders, showDeviceIds, showLocation, showMobileNetwork, safetyCheckResult, isBasicIntegrity, isCtsMatch, notarizeTimestamp, notes));

        if (fileMediaProof.exists()) {
            //sign the proof file again
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMediaProof), new FileOutputStream(fileMediaProofSig), PgpUtils.DEFAULT_PASSWORD);
        }

    } catch (Exception e) {
        Log.e("MediaWatcher", "Error signing media or proof", e);
    }

}
 
Example #6
Source File: ShareProofActivity.java    From proofmode with GNU General Public License v3.0 4 votes vote down vote up
private void generateProofOutput (File fileMedia, Date lastModified, File fileMediaSig, File fileMediaProof, File fileMediaProofSig, String hash, boolean shareMedia, PrintWriter fBatchProofOut, ArrayList<Uri> shareUris, StringBuffer sb)
{
    DateFormat sdf = SimpleDateFormat.getDateTimeInstance();

    String fingerprint = PgpUtils.getInstance(this).getPublicKeyFingerprint();

    sb.append(fileMedia.getName()).append(' ');
    sb.append(getString(R.string.last_modified)).append(' ').append(sdf.format(lastModified));
    sb.append(' ');
    sb.append(getString(R.string.has_hash)).append(' ').append(hash);
    sb.append("\n\n");
    sb.append(getString(R.string.proof_signed) + fingerprint);
    sb.append("\n");
    sb.append(getString(R.string.view_public_key) + fingerprint);
    sb.append("\n\n");

    /**
     * //disable for now
    try {
        final TimeBeatNotarizationProvider tbNotarize = new TimeBeatNotarizationProvider(this);
        String tbProof = tbNotarize.getProof(hash);
        sb.append(getString(R.string.independent_notary) + ' ' + tbProof);
    }
    catch (Exception ioe)
    {
        Timber.e("Error checking for Timebeat proof",ioe);
    }**/

    shareUris.add(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",fileMediaProof));

    if (shareMedia) {
        shareUris.add(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",fileMedia));
        shareUris.add(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",fileMediaSig));
        shareUris.add(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider",fileMediaProofSig));
    }

    if (fBatchProofOut != null)
    {
        try {
            BufferedReader br = new BufferedReader(new FileReader(fileMediaProof));
            br.readLine();//skip header
            String csvLine = br.readLine();
            // Log.i("ShareProof","batching csv line: " + csvLine);
            fBatchProofOut.println(csvLine);
            br.close();
        }
        catch (IOException ioe)
        {}
    }
}