From 5aa36b089f09346787e44f9850924faae1fda363 Mon Sep 17 00:00:00 2001 From: hsm Date: Sun, 29 May 2016 03:12:09 +0100 Subject: ssh authentication support --- .../keychain/pgp/PgpSignEncryptData.java | 12 ++++ .../keychain/pgp/PgpSignEncryptOperation.java | 79 ++++++++++++++++++++-- .../keychain/provider/CachedPublicKeyRing.java | 17 +++++ .../keychain/provider/KeychainProvider.java | 2 + .../keychain/remote/OpenPgpService.java | 23 +++++-- .../securitytoken/SecurityTokenHelper.java | 31 ++++++--- .../ui/SecurityTokenOperationActivity.java | 12 +++- 7 files changed, 152 insertions(+), 24 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptData.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptData.java index c4e569d24..5d904331e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptData.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptData.java @@ -30,6 +30,7 @@ public class PgpSignEncryptData implements Parcelable { protected String mVersionHeader = null; protected boolean mEnableAsciiArmorOutput = false; + protected boolean mSshAuth = false; protected int mCompressionAlgorithm = CompressionAlgorithmTags.UNCOMPRESSED; protected long[] mEncryptionMasterKeyIds = null; protected Passphrase mSymmetricPassphrase = null; @@ -53,6 +54,7 @@ public class PgpSignEncryptData implements Parcelable { mVersionHeader = source.readString(); mEnableAsciiArmorOutput = source.readInt() == 1; + mSshAuth = source.readInt() == 1; mCompressionAlgorithm = source.readInt(); mEncryptionMasterKeyIds = source.createLongArray(); mSymmetricPassphrase = source.readParcelable(loader); @@ -78,6 +80,7 @@ public class PgpSignEncryptData implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeString(mVersionHeader); dest.writeInt(mEnableAsciiArmorOutput ? 1 : 0); + dest.writeInt(mSshAuth ? 1 : 0); dest.writeInt(mCompressionAlgorithm); dest.writeLongArray(mEncryptionMasterKeyIds); dest.writeParcelable(mSymmetricPassphrase, 0); @@ -183,6 +186,10 @@ public class PgpSignEncryptData implements Parcelable { return mEnableAsciiArmorOutput; } + public boolean isSshAuth() { + return mSshAuth; + } + public String getVersionHeader() { return mVersionHeader; } @@ -197,6 +204,11 @@ public class PgpSignEncryptData implements Parcelable { return this; } + public PgpSignEncryptData setSshAuth(boolean sshAuth) { + mSshAuth = sshAuth; + return this; + } + public PgpSignEncryptData setCleartextSignature(boolean cleartextSignature) { this.mCleartextSignature = cleartextSignature; return this; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java index 7a1d99927..a855dcac8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java @@ -24,6 +24,7 @@ import android.net.Uri; import android.os.Parcelable; import android.support.annotation.NonNull; +import org.bouncycastle.bcpg.HashAlgorithmTags; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.BCPGOutputStream; import org.bouncycastle.bcpg.CompressionAlgorithmTags; @@ -58,6 +59,10 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.ProgressScaler; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import java.nio.ByteBuffer; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; @@ -165,6 +170,7 @@ public class PgpSignEncryptOperation extends BaseOperation 0) { // no output stream is written, no changed to original data! + if (raw_digest != null) + raw_digest.update(buffer, 0, length); + signatureGenerator.update(buffer, 0, length); alreadyWritten += length; @@ -582,11 +621,37 @@ public class PgpSignEncryptOperation extends BaseOperation