use of com.mindbright.asn1.ASN1Integer in project sshj by hierynomus.
the class DSAPrivateKeyInfoKeyPairConverter method getDsaParameters.
private DSAParameters getDsaParameters(final AlgorithmIdentifier algorithmIdentifier) {
final ASN1Sequence sequence = ASN1Sequence.getInstance(algorithmIdentifier.getParameters());
final ASN1Integer p = ASN1Integer.getInstance(sequence.getObjectAt(P_INDEX));
final ASN1Integer q = ASN1Integer.getInstance(sequence.getObjectAt(Q_INDEX));
final ASN1Integer g = ASN1Integer.getInstance(sequence.getObjectAt(G_INDEX));
return new DSAParameters(p.getValue(), q.getValue(), g.getValue());
}
use of com.mindbright.asn1.ASN1Integer in project sshj by hierynomus.
the class DSAPrivateKeyInfoKeyPairConverter method getKeyPair.
/**
* Get PEM Key Pair calculating DSA Public Key from DSA Private Key Information
*
* @param privateKeyInfo DSA Private Key Information
* @return PEM Key Pair
* @throws IOException Thrown on Public Key parsing failures
*/
@Override
public PEMKeyPair getKeyPair(final PrivateKeyInfo privateKeyInfo) throws IOException {
Objects.requireNonNull(privateKeyInfo, "Private Key Info required");
final AlgorithmIdentifier algorithmIdentifier = privateKeyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
if (X9ObjectIdentifiers.id_dsa.equals(algorithm)) {
logger.debug("DSA Algorithm Found [{}]", algorithm);
} else {
throw new IllegalArgumentException(String.format("DSA Algorithm OID required [%s]", algorithm));
}
final ASN1Integer encodedPublicKey = getEncodedPublicKey(privateKeyInfo);
final SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, encodedPublicKey);
return new PEMKeyPair(subjectPublicKeyInfo, privateKeyInfo);
}
use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class GetPasswordQualityRequirementsExtendedResult method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value for this extended result, if appropriate.
*
* @param resultCode The result code for the response. This
* must not be {@code null}.
* @param passwordRequirements The password quality requirements for this
* result. This must be {@code null} or
* empty if this result is for an operation
* that was not processed successfully. It
* may be {@code null} or empty if the
* server will not enforce any password
* quality requirements for the target
* operation.
* @param currentPasswordRequired Indicates whether the user will be
* required to provide his/her current
* password when performing a self change.
* This must be {@code null} if this result
* is for an operation that was not processed
* successfully or if the target operation is
* not a self change.
* @param mustChangePassword Indicates whether the user will be
* required to change their password after
* the associated add or administrative
* reset before that user will be allowed to
* issue any other requests. This must be
* {@code null} if this result is for an
* operation that was not processed
* successfully or if the target operation is
* not an add or an administrative reset.
* @param secondsUntilExpiration Indicates the maximum length of time, in
* seconds, that the password set in the
* target operation will be valid. If
* {@code mustChangePassword} is {@code true}
* then this will indicate the length of time
* that the user has to change his/her
* password after the add/reset. If
* {@code mustChangePassword} is {@code null}
* or {@code false} then this will indicate
* the length of time until the password
* expires. This must be {@code null} if
* this result is for an operation that was
* not processed successfully, or if the new
* password will be valid indefinitely.
*
* @return The ASN.1 element with the encoded result value, or {@code null}
* if the result should not have a value.
*/
@Nullable()
private static ASN1OctetString encodeValue(@NotNull final ResultCode resultCode, @Nullable final Collection<PasswordQualityRequirement> passwordRequirements, @Nullable final Boolean currentPasswordRequired, @Nullable final Boolean mustChangePassword, @Nullable final Integer secondsUntilExpiration) {
if (resultCode != ResultCode.SUCCESS) {
Validator.ensureTrue((passwordRequirements == null) || passwordRequirements.isEmpty());
Validator.ensureTrue(currentPasswordRequired == null);
Validator.ensureTrue(mustChangePassword == null);
Validator.ensureTrue(secondsUntilExpiration == null);
return null;
}
final ArrayList<ASN1Element> valueSequence = new ArrayList<>(4);
if (passwordRequirements == null) {
valueSequence.add(new ASN1Sequence());
} else {
final ArrayList<ASN1Element> requirementElements = new ArrayList<>(passwordRequirements.size());
for (final PasswordQualityRequirement r : passwordRequirements) {
requirementElements.add(r.encode());
}
valueSequence.add(new ASN1Sequence(requirementElements));
}
if (currentPasswordRequired != null) {
valueSequence.add(new ASN1Boolean(TYPE_CURRENT_PW_REQUIRED, currentPasswordRequired));
}
if (mustChangePassword != null) {
valueSequence.add(new ASN1Boolean(TYPE_MUST_CHANGE_PW, mustChangePassword));
}
if (secondsUntilExpiration != null) {
valueSequence.add(new ASN1Integer(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
}
return new ASN1OctetString(new ASN1Sequence(valueSequence).encode());
}
use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class GetChangelogBatchExtendedRequestTestCase method testDecodeValueSequenceInvalidChangeType.
/**
* Provides test coverage for an attempt to decode an extended request with a
* value sequence with an invalid change type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidChangeType() throws Exception {
final ASN1Set changeTypeSet = new ASN1Set((byte) 0xA4, new ASN1Enumerated(0), new ASN1Enumerated(5));
final ASN1Sequence valueSequence = new ASN1Sequence(new EndOfChangelogStartingPoint().encode(), new ASN1Integer(0), changeTypeSet);
new GetChangelogBatchExtendedRequest(new ExtendedRequest(GetChangelogBatchExtendedRequest.GET_CHANGELOG_BATCH_REQUEST_OID, new ASN1OctetString(valueSequence.encode())));
}
use of com.mindbright.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class GetChangelogBatchExtendedRequestTestCase method testDecodeValueSequenceInvalidElementType.
/**
* Provides test coverage for an attempt to decode an extended request with a
* value sequence with an element with an invalid type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidElementType() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new EndOfChangelogStartingPoint().encode(), new ASN1Integer(0), new ASN1Integer((byte) 0x80, -1), new ASN1OctetString((byte) 0x00, "foo"));
new GetChangelogBatchExtendedRequest(new ExtendedRequest(GetChangelogBatchExtendedRequest.GET_CHANGELOG_BATCH_REQUEST_OID, new ASN1OctetString(valueSequence.encode())));
}
Aggregations