use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class VirtualListViewRequestControlTestCase method testConstructor9ValueSequenceInvalid.
/**
* Tests the ninth constructor with a generic control with a value sequence
* whose third element contains an invalid type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testConstructor9ValueSequenceInvalid() throws Exception {
ASN1Element[] elements = { new ASN1Integer(0), new ASN1Integer(0), new ASN1OctetString("foo") };
Control c = new Control(VirtualListViewRequestControl.VIRTUAL_LIST_VIEW_REQUEST_OID, true, new ASN1OctetString(new ASN1Sequence(elements).encode()));
c = new VirtualListViewRequestControl(c);
}
use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class AssuredReplicationServerResultTestCase method testDecodeValueSequenceInvalidResultCode.
/**
* Tests the behavior when trying to decode an ASN.1 element that is a
* sequence containing an unrecognized result code.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidResultCode() throws Exception {
final ASN1Sequence resultSequence = new ASN1Sequence(new ASN1Enumerated((byte) 0x80, 1234), new ASN1Integer((byte) 0x81, 5678));
AssuredReplicationServerResult.decode(resultSequence);
}
use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class AssuredReplicationServerResultTestCase method testDecodeValueSequenceMissingResultCode.
/**
* Tests the behavior when trying to decode an ASN.1 element that is a
* sequence that does not have a result code.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceMissingResultCode() throws Exception {
final ASN1Sequence resultSequence = new ASN1Sequence(new ASN1Integer((byte) 0x81, 1234));
AssuredReplicationServerResult.decode(resultSequence);
}
use of com.mindbright.asn1.ASN1Integer in project gdmatrix by gdmatrix.
the class CMSUtils method createTimeStampRequest.
public static TimeStampReq createTimeStampRequest(byte[] message, String nonce, boolean requireCert, Extensions extensions, String digestAlgorithm, String timestampPolicy) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] hashedMsg = md.digest(message);
ASN1ObjectIdentifier identifier = new ASN1ObjectIdentifier(digestAlgorithm);
org.bouncycastle.asn1.tsp.MessageImprint imprint = new org.bouncycastle.asn1.tsp.MessageImprint(new AlgorithmIdentifier(identifier), hashedMsg);
TimeStampReq request = new TimeStampReq(imprint, timestampPolicy != null ? new ASN1ObjectIdentifier(timestampPolicy) : null, nonce != null ? new ASN1Integer(nonce.getBytes()) : null, ASN1Boolean.getInstance(requireCert), extensions);
return request;
}
use of com.mindbright.asn1.ASN1Integer in project identity-credential by google.
the class Util method signatureDerToCose.
/*
* From RFC 8152 section 8.1 ECDSA:
*
* The signature algorithm results in a pair of integers (R, S). These
* integers will be the same length as the length of the key used for
* the signature process. The signature is encoded by converting the
* integers into byte strings of the same length as the key size. The
* length is rounded up to the nearest byte and is left padded with zero
* bits to get to the correct length. The two integers are then
* concatenated together to form a byte string that is the resulting
* signature.
*/
private static byte[] signatureDerToCose(byte[] signature, int keySize) {
ASN1Primitive asn1;
try {
asn1 = new ASN1InputStream(new ByteArrayInputStream(signature)).readObject();
} catch (IOException e) {
throw new IllegalArgumentException("Error decoding DER signature", e);
}
if (!(asn1 instanceof ASN1Sequence)) {
throw new IllegalArgumentException("Not a ASN1 sequence");
}
ASN1Encodable[] asn1Encodables = ((ASN1Sequence) asn1).toArray();
if (asn1Encodables.length != 2) {
throw new IllegalArgumentException("Expected two items in sequence");
}
if (!(asn1Encodables[0].toASN1Primitive() instanceof ASN1Integer)) {
throw new IllegalArgumentException("First item is not an integer");
}
BigInteger r = ((ASN1Integer) asn1Encodables[0].toASN1Primitive()).getValue();
if (!(asn1Encodables[1].toASN1Primitive() instanceof ASN1Integer)) {
throw new IllegalArgumentException("Second item is not an integer");
}
BigInteger s = ((ASN1Integer) asn1Encodables[1].toASN1Primitive()).getValue();
byte[] rBytes = stripLeadingZeroes(r.toByteArray());
byte[] sBytes = stripLeadingZeroes(s.toByteArray());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
for (int n = 0; n < keySize - rBytes.length; n++) {
baos.write(0x00);
}
baos.write(rBytes);
for (int n = 0; n < keySize - sBytes.length; n++) {
baos.write(0x00);
}
baos.write(sBytes);
} catch (IOException e) {
e.printStackTrace();
return null;
}
return baos.toByteArray();
}
Aggregations