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

View File

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

View File

@@ -12,23 +12,20 @@ import java.io.OutputStream;
import java.math.BigInteger;
/**
* Generator for PGP Signatures.
* Generator for authentication signatures.
*/
public class PGPAuthenticationSignatureGenerator
{
public class AuthenticationSignatureGenerator {
private OutputStream sigOut;
private PGPContentSignerBuilder contentSignerBuilder;
private PGPContentSigner contentSigner;
private int sigType;
private int sigType;
/**
* 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(
PGPContentSignerBuilder contentSignerBuilder)
{
public AuthenticationSignatureGenerator(PGPContentSignerBuilder contentSignerBuilder) {
this.contentSignerBuilder = contentSignerBuilder;
}
@@ -39,89 +36,61 @@ public class PGPAuthenticationSignatureGenerator
* @param key
* @throws PGPException
*/
public void init(
int signatureType,
PGPPrivateKey key)
throws PGPException
{
public void init(int signatureType, PGPPrivateKey key) throws PGPException {
contentSigner = contentSignerBuilder.build(signatureType, key);
sigOut = contentSigner.getOutputStream();
sigType = contentSigner.getType();
}
public void update(
byte b)
{
public void update(byte b) {
byteUpdate(b);
}
public void update(
byte[] b)
{
public void update(byte[] b) {
update(b, 0, b.length);
}
public void update(
byte[] b,
int off,
int len)
{
public void update(byte[] b, int off, int len) {
blockUpdate(b, off, len);
}
private void byteUpdate(byte b)
{
try
{
private void byteUpdate(byte b) {
try {
sigOut.write(b);
}
catch (IOException e)
{
} catch (IOException e) {
throw new PGPRuntimeOperationException(e.getMessage(), e);
}
}
private void blockUpdate(byte[] block, int off, int len)
{
try
{
private void blockUpdate(byte[] block, int off, int len) {
try {
sigOut.write(block, off, len);
}
catch (IOException e)
{
} catch (IOException e) {
throw new PGPRuntimeOperationException(e.getMessage(), e);
}
}
/**
* Return a signature object containing the current signature state.
*
*
* @return PGPSignature
* @throws PGPException
*/
public PGPSignature generate()
throws PGPException
{
MPInteger[] sigValues;
public PGPSignature generate() throws PGPException {
MPInteger[] sigValues;
if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN
|| contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) // an RSA signature
{
|| contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) {
sigValues = new MPInteger[1];
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();
sigValues = new MPInteger[2];
sigValues[0] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 0, 32));
sigValues[1] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 32, 32));
}
else
{
} else {
sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature());
}