Rename PGPAuthenticationSignatureGenerator to

AuthenticationSignatureGenerator & reformat
This commit is contained in:
Christian Hagau
2017-11-12 00:00:00 +00:00
parent 48b8f97b78
commit 2e3649100c
3 changed files with 29 additions and 60 deletions

View File

@@ -28,7 +28,7 @@ import java.util.Map;
import org.bouncycastle.bcpg.S2K; import org.bouncycastle.bcpg.S2K;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.openpgp.PGPAuthenticationSignatureGenerator; import org.bouncycastle.openpgp.AuthenticationSignatureGenerator;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKey;
@@ -253,8 +253,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
} }
} }
public PGPAuthenticationSignatureGenerator getAuthenticationSignatureGenerator(int hashAlgorithm, public AuthenticationSignatureGenerator getAuthenticationSignatureGenerator(int hashAlgorithm,
Map<ByteBuffer, byte[]> signedHashes) Map<ByteBuffer, byte[]> signedHashes)
throws PgpGeneralException { throws PgpGeneralException {
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) { if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
throw new PrivateKeyNotUnlockedException(); throw new PrivateKeyNotUnlockedException();
@@ -263,7 +263,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
PGPContentSignerBuilder contentSignerBuilder = getContentSignerBuilder(hashAlgorithm, signedHashes); PGPContentSignerBuilder contentSignerBuilder = getContentSignerBuilder(hashAlgorithm, signedHashes);
try { try {
PGPAuthenticationSignatureGenerator signatureGenerator = new PGPAuthenticationSignatureGenerator(contentSignerBuilder); AuthenticationSignatureGenerator signatureGenerator = new AuthenticationSignatureGenerator(contentSignerBuilder);
signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, mPrivateKey); signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, mPrivateKey);
return signatureGenerator; return signatureGenerator;

View File

@@ -19,7 +19,7 @@ package org.sufficientlysecure.keychain.ssh;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.bouncycastle.openpgp.PGPAuthenticationSignatureGenerator; import org.bouncycastle.openpgp.AuthenticationSignatureGenerator;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder;
import org.sufficientlysecure.keychain.operations.BaseOperation; import org.sufficientlysecure.keychain.operations.BaseOperation;
@@ -206,7 +206,7 @@ public class AuthenticationOperation extends BaseOperation<AuthenticationParcel>
} }
PGPAuthenticationSignatureGenerator signatureGenerator; AuthenticationSignatureGenerator signatureGenerator;
try { try {
signatureGenerator = authKey.getAuthenticationSignatureGenerator( signatureGenerator = authKey.getAuthenticationSignatureGenerator(
hashAlgorithm, cryptoInput.getCryptoData()); hashAlgorithm, cryptoInput.getCryptoData());

View File

@@ -12,23 +12,20 @@ import java.io.OutputStream;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
* Generator for PGP Signatures. * Generator for authentication signatures.
*/ */
public class PGPAuthenticationSignatureGenerator public class AuthenticationSignatureGenerator {
{
private OutputStream sigOut; private OutputStream sigOut;
private PGPContentSignerBuilder contentSignerBuilder; private PGPContentSignerBuilder contentSignerBuilder;
private PGPContentSigner contentSigner; private PGPContentSigner contentSigner;
private int sigType; private int sigType;
/** /**
* Create a signature generator built on the passed in contentSignerBuilder. * Create a signature generator built on the passed in contentSignerBuilder.
* *
* @param contentSignerBuilder builder to produce PGPContentSigner objects for generating signatures. * @param contentSignerBuilder builder to produce PGPContentSigner objects for generating signatures.
*/ */
public PGPAuthenticationSignatureGenerator( public AuthenticationSignatureGenerator(PGPContentSignerBuilder contentSignerBuilder) {
PGPContentSignerBuilder contentSignerBuilder)
{
this.contentSignerBuilder = contentSignerBuilder; this.contentSignerBuilder = contentSignerBuilder;
} }
@@ -39,57 +36,36 @@ public class PGPAuthenticationSignatureGenerator
* @param key * @param key
* @throws PGPException * @throws PGPException
*/ */
public void init( public void init(int signatureType, PGPPrivateKey key) throws PGPException {
int signatureType,
PGPPrivateKey key)
throws PGPException
{
contentSigner = contentSignerBuilder.build(signatureType, key); contentSigner = contentSignerBuilder.build(signatureType, key);
sigOut = contentSigner.getOutputStream(); sigOut = contentSigner.getOutputStream();
sigType = contentSigner.getType(); sigType = contentSigner.getType();
} }
public void update( public void update(byte b) {
byte b)
{
byteUpdate(b); byteUpdate(b);
} }
public void update( public void update(byte[] b) {
byte[] b)
{
update(b, 0, b.length); update(b, 0, b.length);
} }
public void update( public void update(byte[] b, int off, int len) {
byte[] b,
int off,
int len)
{
blockUpdate(b, off, len); blockUpdate(b, off, len);
} }
private void byteUpdate(byte b) private void byteUpdate(byte b) {
{ try {
try
{
sigOut.write(b); sigOut.write(b);
} } catch (IOException e) {
catch (IOException e)
{
throw new PGPRuntimeOperationException(e.getMessage(), e); throw new PGPRuntimeOperationException(e.getMessage(), e);
} }
} }
private void blockUpdate(byte[] block, int off, int len) private void blockUpdate(byte[] block, int off, int len) {
{ try {
try
{
sigOut.write(block, off, len); sigOut.write(block, off, len);
} } catch (IOException e) {
catch (IOException e)
{
throw new PGPRuntimeOperationException(e.getMessage(), e); throw new PGPRuntimeOperationException(e.getMessage(), e);
} }
} }
@@ -100,28 +76,21 @@ public class PGPAuthenticationSignatureGenerator
* @return PGPSignature * @return PGPSignature
* @throws PGPException * @throws PGPException
*/ */
public PGPSignature generate() public PGPSignature generate() throws PGPException {
throws PGPException MPInteger[] sigValues;
{
MPInteger[] sigValues;
if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN
|| contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) // an RSA signature || contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) {
{
sigValues = new MPInteger[1]; sigValues = new MPInteger[1];
sigValues[0] = new MPInteger(new BigInteger(1, contentSigner.getSignature())); sigValues[0] = new MPInteger(new BigInteger(1, contentSigner.getSignature()));
} } else if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA) {
else if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA)
{
byte[] sig = contentSigner.getSignature(); byte[] sig = contentSigner.getSignature();
sigValues = new MPInteger[2]; sigValues = new MPInteger[2];
sigValues[0] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 0, 32)); sigValues[0] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 0, 32));
sigValues[1] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 32, 32)); sigValues[1] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 32, 32));
} } else {
else
{
sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature()); sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature());
} }