mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
Replace BC ASN.1 dependency with asn-one library
This commit is contained in:
@@ -48,6 +48,7 @@ dependencies {
|
|||||||
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
||||||
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
||||||
implementation "com.jcraft:jzlib:1.1.3"
|
implementation "com.jcraft:jzlib:1.1.3"
|
||||||
|
implementation "com.hierynomus:asn-one:0.4.0"
|
||||||
|
|
||||||
implementation "net.i2p.crypto:eddsa:0.3.0"
|
implementation "net.i2p.crypto:eddsa:0.3.0"
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package net.schmizz.sshj.signature;
|
package net.schmizz.sshj.signature;
|
||||||
|
|
||||||
|
import com.hierynomus.asn1.encodingrules.der.DEREncoder;
|
||||||
|
import com.hierynomus.asn1.types.ASN1Object;
|
||||||
|
import com.hierynomus.asn1.types.constructed.ASN1Sequence;
|
||||||
|
import com.hierynomus.asn1.types.primitive.ASN1Integer;
|
||||||
import net.schmizz.sshj.common.KeyType;
|
import net.schmizz.sshj.common.KeyType;
|
||||||
import net.schmizz.sshj.common.SSHRuntimeException;
|
import net.schmizz.sshj.common.SSHRuntimeException;
|
||||||
import org.bouncycastle.asn1.*;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DSA {@link Signature}
|
* DSA {@link Signature}
|
||||||
@@ -97,18 +102,19 @@ public class SignatureDSA
|
|||||||
* Encodes the signature as a DER sequence (ASN.1 format).
|
* Encodes the signature as a DER sequence (ASN.1 format).
|
||||||
*/
|
*/
|
||||||
private byte[] asnEncode(byte[] sigBlob) throws IOException {
|
private byte[] asnEncode(byte[] sigBlob) throws IOException {
|
||||||
byte[] r = new BigInteger(1, Arrays.copyOfRange(sigBlob, 0, 20)).toByteArray();
|
BigInteger r = new BigInteger(1, Arrays.copyOfRange(sigBlob, 0, 20));
|
||||||
byte[] s = new BigInteger(1, Arrays.copyOfRange(sigBlob, 20, 40)).toByteArray();
|
BigInteger s = new BigInteger(1, Arrays.copyOfRange(sigBlob, 20, 40));
|
||||||
|
|
||||||
ASN1EncodableVector vector = new ASN1EncodableVector();
|
List<ASN1Object> vector = new ArrayList<ASN1Object>();
|
||||||
vector.add(new ASN1Integer(r));
|
vector.add(new com.hierynomus.asn1.types.primitive.ASN1Integer(r));
|
||||||
vector.add(new ASN1Integer(s));
|
vector.add(new ASN1Integer(s));
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ASN1OutputStream asnOS = new ASN1OutputStream(baos);
|
com.hierynomus.asn1.ASN1OutputStream asn1OutputStream = new com.hierynomus.asn1.ASN1OutputStream(new DEREncoder(), baos);
|
||||||
|
|
||||||
|
asn1OutputStream.writeObject(new ASN1Sequence(vector));
|
||||||
|
asn1OutputStream.flush();
|
||||||
|
|
||||||
asnOS.writeObject(new DERSequence(vector));
|
|
||||||
asnOS.flush();
|
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,18 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package net.schmizz.sshj.signature;
|
package net.schmizz.sshj.signature;
|
||||||
|
|
||||||
|
import com.hierynomus.asn1.encodingrules.der.DEREncoder;
|
||||||
|
import com.hierynomus.asn1.types.ASN1Object;
|
||||||
|
import com.hierynomus.asn1.types.constructed.ASN1Sequence;
|
||||||
|
import com.hierynomus.asn1.types.primitive.ASN1Integer;
|
||||||
import net.schmizz.sshj.common.Buffer;
|
import net.schmizz.sshj.common.Buffer;
|
||||||
import net.schmizz.sshj.common.KeyType;
|
import net.schmizz.sshj.common.KeyType;
|
||||||
import net.schmizz.sshj.common.SSHRuntimeException;
|
import net.schmizz.sshj.common.SSHRuntimeException;
|
||||||
import org.bouncycastle.asn1.ASN1EncodableVector;
|
|
||||||
import org.bouncycastle.asn1.ASN1Integer;
|
|
||||||
import org.bouncycastle.asn1.ASN1OutputStream;
|
|
||||||
import org.bouncycastle.asn1.DERSequence;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** ECDSA {@link Signature} */
|
/** ECDSA {@link Signature} */
|
||||||
public class SignatureECDSA extends AbstractSignature {
|
public class SignatureECDSA extends AbstractSignature {
|
||||||
@@ -122,18 +124,18 @@ public class SignatureECDSA extends AbstractSignature {
|
|||||||
*/
|
*/
|
||||||
private byte[] asnEncode(byte[] sigBlob) throws IOException {
|
private byte[] asnEncode(byte[] sigBlob) throws IOException {
|
||||||
Buffer.PlainBuffer sigbuf = new Buffer.PlainBuffer(sigBlob);
|
Buffer.PlainBuffer sigbuf = new Buffer.PlainBuffer(sigBlob);
|
||||||
byte[] r = sigbuf.readBytes();
|
BigInteger r = sigbuf.readMPInt();
|
||||||
byte[] s = sigbuf.readBytes();
|
BigInteger s = sigbuf.readMPInt();
|
||||||
|
|
||||||
ASN1EncodableVector vector = new ASN1EncodableVector();
|
List<ASN1Object> vector = new ArrayList<ASN1Object>();
|
||||||
vector.add(new ASN1Integer(r));
|
vector.add(new ASN1Integer(r));
|
||||||
vector.add(new ASN1Integer(s));
|
vector.add(new ASN1Integer(s));
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ASN1OutputStream asnOS = new ASN1OutputStream(baos);
|
com.hierynomus.asn1.ASN1OutputStream asn1OutputStream = new com.hierynomus.asn1.ASN1OutputStream(new DEREncoder(), baos);
|
||||||
|
|
||||||
asnOS.writeObject(new DERSequence(vector));
|
asn1OutputStream.writeObject(new ASN1Sequence(vector));
|
||||||
asnOS.flush();
|
asn1OutputStream.flush();
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user