mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Merge branch '763-remove-signature-api' into 'master'
Remove old signature class from API I decided not to remove the SignatureImpl class, as it's not a trivial wrapper around the Bouncy Castle class, but I moved the interface into briar-core and made it package-private. Closes #763 See merge request !424
This commit is contained in:
@@ -9,7 +9,6 @@ import org.briarproject.api.crypto.PrivateKey;
|
|||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.crypto.PublicKey;
|
import org.briarproject.api.crypto.PublicKey;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.crypto.Signature;
|
|
||||||
import org.briarproject.api.system.SeedProvider;
|
import org.briarproject.api.system.SeedProvider;
|
||||||
import org.briarproject.api.transport.IncomingKeys;
|
import org.briarproject.api.transport.IncomingKeys;
|
||||||
import org.briarproject.api.transport.OutgoingKeys;
|
import org.briarproject.api.transport.OutgoingKeys;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.api.crypto.PrivateKey;
|
||||||
|
import org.briarproject.api.crypto.PublicKey;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
public interface Signature {
|
interface Signature {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see {@link java.security.Signature#initSign(java.security.PrivateKey)}
|
* @see {@link java.security.Signature#initSign(java.security.PrivateKey)}
|
||||||
@@ -10,7 +13,7 @@ public interface Signature {
|
|||||||
void initSign(PrivateKey k) throws GeneralSecurityException;
|
void initSign(PrivateKey k) throws GeneralSecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see {@link java.security.Signature#initVafiry(java.security.PublicKey)}
|
* @see {@link java.security.Signature#initVerify(java.security.PublicKey)}
|
||||||
*/
|
*/
|
||||||
void initVerify(PublicKey k) throws GeneralSecurityException;
|
void initVerify(PublicKey k) throws GeneralSecurityException;
|
||||||
|
|
||||||
@@ -2,7 +2,6 @@ package org.briarproject.crypto;
|
|||||||
|
|
||||||
import org.briarproject.api.crypto.PrivateKey;
|
import org.briarproject.api.crypto.PrivateKey;
|
||||||
import org.briarproject.api.crypto.PublicKey;
|
import org.briarproject.api.crypto.PublicKey;
|
||||||
import org.briarproject.api.crypto.Signature;
|
|
||||||
import org.spongycastle.crypto.Digest;
|
import org.spongycastle.crypto.Digest;
|
||||||
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
|
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
|
||||||
import org.spongycastle.crypto.params.ECPublicKeyParameters;
|
import org.spongycastle.crypto.params.ECPublicKeyParameters;
|
||||||
@@ -33,30 +32,36 @@ class SignatureImpl implements Signature {
|
|||||||
signer = new DSADigestSigner(new ECDSASigner(calculator), digest);
|
signer = new DSADigestSigner(new ECDSASigner(calculator), digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void initSign(PrivateKey k) throws GeneralSecurityException {
|
public void initSign(PrivateKey k) throws GeneralSecurityException {
|
||||||
if (!(k instanceof Sec1PrivateKey)) throw new GeneralSecurityException();
|
if (!(k instanceof Sec1PrivateKey)) throw new GeneralSecurityException();
|
||||||
ECPrivateKeyParameters priv = ((Sec1PrivateKey) k).getKey();
|
ECPrivateKeyParameters priv = ((Sec1PrivateKey) k).getKey();
|
||||||
signer.init(true, new ParametersWithRandom(priv, secureRandom));
|
signer.init(true, new ParametersWithRandom(priv, secureRandom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void initVerify(PublicKey k) throws GeneralSecurityException {
|
public void initVerify(PublicKey k) throws GeneralSecurityException {
|
||||||
if (!(k instanceof Sec1PublicKey)) throw new GeneralSecurityException();
|
if (!(k instanceof Sec1PublicKey)) throw new GeneralSecurityException();
|
||||||
ECPublicKeyParameters pub = ((Sec1PublicKey) k).getKey();
|
ECPublicKeyParameters pub = ((Sec1PublicKey) k).getKey();
|
||||||
signer.init(false, pub);
|
signer.init(false, pub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(byte b) {
|
public void update(byte b) {
|
||||||
signer.update(b);
|
signer.update(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(byte[] b) {
|
public void update(byte[] b) {
|
||||||
update(b, 0, b.length);
|
update(b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(byte[] b, int off, int len) {
|
public void update(byte[] b, int off, int len) {
|
||||||
signer.update(b, off, len);
|
signer.update(b, off, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] sign() {
|
public byte[] sign() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] signature = signer.generateSignature();
|
byte[] signature = signer.generateSignature();
|
||||||
@@ -66,6 +71,7 @@ class SignatureImpl implements Signature {
|
|||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean verify(byte[] signature) {
|
public boolean verify(byte[] signature) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
boolean valid = signer.verifySignature(signature);
|
boolean valid = signer.verifySignature(signature);
|
||||||
|
|||||||
@@ -1,31 +1,20 @@
|
|||||||
package org.briarproject.invitation;
|
package org.briarproject.invitation;
|
||||||
|
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.api.FormatException;
|
||||||
import org.briarproject.api.TransportId;
|
|
||||||
import org.briarproject.api.contact.ContactExchangeTask;
|
import org.briarproject.api.contact.ContactExchangeTask;
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.KeyPair;
|
import org.briarproject.api.crypto.KeyPair;
|
||||||
import org.briarproject.api.crypto.KeyParser;
|
import org.briarproject.api.crypto.KeyParser;
|
||||||
import org.briarproject.api.crypto.MessageDigest;
|
import org.briarproject.api.crypto.MessageDigest;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.crypto.Signature;
|
|
||||||
import org.briarproject.api.data.BdfReader;
|
import org.briarproject.api.data.BdfReader;
|
||||||
import org.briarproject.api.data.BdfReaderFactory;
|
import org.briarproject.api.data.BdfReaderFactory;
|
||||||
import org.briarproject.api.data.BdfWriter;
|
import org.briarproject.api.data.BdfWriter;
|
||||||
import org.briarproject.api.data.BdfWriterFactory;
|
import org.briarproject.api.data.BdfWriterFactory;
|
||||||
import org.briarproject.api.db.DbException;
|
|
||||||
import org.briarproject.api.identity.Author;
|
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.system.Clock;
|
|
||||||
import org.briarproject.api.transport.StreamReaderFactory;
|
|
||||||
import org.briarproject.api.transport.StreamWriterFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
@@ -34,9 +23,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
|
||||||
import static org.briarproject.api.invitation.InvitationConstants.CONNECTION_TIMEOUT;
|
import static org.briarproject.api.invitation.InvitationConstants.CONNECTION_TIMEOUT;
|
||||||
|
|
||||||
// FIXME: This class has way too many dependencies
|
// FIXME: This class has way too many dependencies
|
||||||
|
|||||||
Reference in New Issue
Block a user