Search in sources :

Example 1 with ASN1Integer

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());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Example 2 with ASN1Integer

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);
}
Also used : PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 3 with ASN1Integer

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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) ASN1Integer(com.unboundid.asn1.ASN1Integer) Nullable(com.unboundid.util.Nullable)

Example 4 with ASN1Integer

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())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 5 with ASN1Integer

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())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Aggregations

ASN1Integer (org.bouncycastle.asn1.ASN1Integer)213 ASN1Integer (com.unboundid.asn1.ASN1Integer)96 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)94 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)91 IOException (java.io.IOException)89 DERSequence (org.bouncycastle.asn1.DERSequence)89 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)86 BigInteger (java.math.BigInteger)86 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)80 ASN1Element (com.unboundid.asn1.ASN1Element)69 Test (org.testng.annotations.Test)63 ArrayList (java.util.ArrayList)50 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)49 DERSequence (com.github.zhenwei.core.asn1.DERSequence)47 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)47 DEROctetString (org.bouncycastle.asn1.DEROctetString)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)35 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)28 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)27 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)27