use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeMalformedIssuerUniqueID.
/**
* Tests the behavior when trying to decode a certificate with a malformed
* issuer unique ID.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedIssuerUniqueID() throws Exception {
final long notBefore = System.currentTimeMillis();
final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024])), new ASN1Element((byte) 0x81)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeMalformedExtension.
/**
* Tests the behavior when trying to decode a certificate with a malformed
* subject unique ID.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedExtension() throws Exception {
final long notBefore = System.currentTimeMillis();
final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024])), new ASN1Element((byte) 0xA3)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeMalformedSignatureBitString.
/**
* Tests the behavior when trying to decode a certificate with a malformed
* signature bit string.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedSignatureBitString() throws Exception {
final long notBefore = System.currentTimeMillis();
final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024]))), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class MatchingEntryCountResponseControl method encodeValue.
/**
* Encodes a control value with the provided information.
*
* @param countType The matching entry count type. It must not
* be {@code null}.
* @param countValue The matching entry count value. It must be
* greater than or equal to zero for a count
* type of either {@code EXAMINED_COUNT} or
* {@code UNEXAMINED_COUNT}. It must be greater
* than zero for a count type of
* {@code UPPER_BOUND}. It must be -1 for a
* count type of {@code UNKNOWN}.
* @param searchIndexed Indicates whether the search criteria is
* considered at least partially indexed and
* could be processed more efficiently than
* examining all entries with a full database
* scan.
* @param shortCircuited Indicates whether the server short-circuited
* during candidate set processing before
* evaluating all elements of the search
* criteria (the filter and scope). This may be
* {@code null} if it is not available (e.g.,
* because extended response data was not
* requested).
* @param fullyIndexed Indicates whether the search is considered
* fully indexed. Note that this may be
* {@code false} even if the filter is actually
* fully indexed if server index processing
* short-circuited before evaluating all
* components of the filter. To avoid this,
* issue the request control with both fast and
* slow short-circuit thresholds set to zero.
* This may be {@code null} if this is not
* available (e.g., because extended response
* data was not requested).
* @param candidatesAreInScope Indicates whether all the identified
* candidate entries are within the scope of
* the search. It may be {@code null} if this
* is not available (e.g., because extended
* response data was not requested).
* @param remainingFilter The portion of the filter that was either
* identified as unindexed or that was not
* evaluated because processing short-circuited
* in the course of building the candidate set.
* It may be {@code null} if there is no
* remaining filter or if this information is
* not available (e.g., because extended
* response data was not requested).
* @param debugInfo An optional list of messages providing debug
* information about the processing performed by
* the server. It may be {@code null} or empty
* if no debug messages should be included.
*
* @return The encoded control value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final MatchingEntryCountType countType, final int countValue, final boolean searchIndexed, @Nullable final Boolean shortCircuited, @Nullable final Boolean fullyIndexed, @Nullable final Boolean candidatesAreInScope, @Nullable final Filter remainingFilter, @Nullable final Collection<String> debugInfo) {
final ArrayList<ASN1Element> elements = new ArrayList<>(3);
switch(countType) {
case EXAMINED_COUNT:
case UNEXAMINED_COUNT:
case UPPER_BOUND:
elements.add(new ASN1Integer(countType.getBERType(), countValue));
break;
case UNKNOWN:
elements.add(new ASN1Null(countType.getBERType()));
break;
}
if (debugInfo != null) {
final ArrayList<ASN1Element> debugElements = new ArrayList<>(debugInfo.size());
for (final String s : debugInfo) {
debugElements.add(new ASN1OctetString(s));
}
elements.add(new ASN1Sequence(TYPE_DEBUG_INFO, debugElements));
}
if (!searchIndexed) {
elements.add(new ASN1Boolean(TYPE_SEARCH_INDEXED, searchIndexed));
}
if (shortCircuited != null) {
elements.add(new ASN1Boolean(TYPE_SHORT_CIRCUITED, shortCircuited));
}
if (fullyIndexed != null) {
elements.add(new ASN1Boolean(TYPE_FULLY_INDEXED, fullyIndexed));
}
if (candidatesAreInScope != null) {
elements.add(new ASN1Boolean(TYPE_CANDIDATES_ARE_IN_SCOPE, candidatesAreInScope));
}
if (remainingFilter != null) {
elements.add(new ASN1OctetString(TYPE_REMAINING_FILTER, remainingFilter.encode().encode()));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class GetPasswordQualityRequirementsExtendedRequest method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value of this extended request.
*
* @param targetType The target type for this request. It must not be
* {@code null}.
* @param targetDN The target DN for this request. It may be {@code null}
* if no target DN is required for the specified target
* type.
*
* @return The ASN.1 octet string containing the encoded request value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final GetPasswordQualityRequirementsTargetType targetType, @Nullable final String targetDN) {
final ASN1Element targetElement;
switch(targetType) {
case ADD_WITH_SPECIFIED_PASSWORD_POLICY:
case SELF_CHANGE_FOR_SPECIFIED_USER:
case ADMINISTRATIVE_RESET_FOR_SPECIFIED_USER:
targetElement = new ASN1OctetString(targetType.getBERType(), targetDN);
break;
case ADD_WITH_DEFAULT_PASSWORD_POLICY:
case SELF_CHANGE_FOR_AUTHORIZATION_IDENTITY:
default:
targetElement = new ASN1Null(targetType.getBERType());
break;
}
final ASN1Sequence valueSequence = new ASN1Sequence(targetElement);
return new ASN1OctetString(valueSequence.encode());
}
Aggregations