Java Code Examples for sun.security.util.DerInputStream#available()

The following examples show how to use sun.security.util.DerInputStream#available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncryptedPrivateKeyInfo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("fallthrough")
private static void checkPKCS8Encoding(byte[] encodedKey)
    throws IOException {
    DerInputStream in = new DerInputStream(encodedKey);
    DerValue[] values = in.getSequence(3);

    switch (values.length) {
    case 4:
        checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
        /* fall through */
    case 3:
        checkTag(values[0], DerValue.tag_Integer, "version");
        DerInputStream algid = values[1].toDerInputStream();
        algid.getOID();
        if (algid.available() != 0) {
            algid.getDerValue();
        }
        checkTag(values[2], DerValue.tag_OctetString, "privateKey");
        break;
    default:
        throw new IOException("invalid key encoding");
    }
}
 
Example 2
Source File: EncryptedPrivateKeyInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("fallthrough")
private static void checkPKCS8Encoding(byte[] encodedKey)
    throws IOException {
    DerInputStream in = new DerInputStream(encodedKey);
    DerValue[] values = in.getSequence(3);

    switch (values.length) {
    case 4:
        checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
        /* fall through */
    case 3:
        checkTag(values[0], DerValue.tag_Integer, "version");
        DerInputStream algid = values[1].toDerInputStream();
        algid.getOID();
        if (algid.available() != 0) {
            algid.getDerValue();
        }
        checkTag(values[2], DerValue.tag_OctetString, "privateKey");
        break;
    default:
        throw new IOException("invalid key encoding");
    }
}
 
Example 3
Source File: EncryptedPrivateKeyInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("fallthrough")
private static void checkPKCS8Encoding(byte[] encodedKey)
    throws IOException {
    DerInputStream in = new DerInputStream(encodedKey);
    DerValue[] values = in.getSequence(3);

    switch (values.length) {
    case 4:
        checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
        /* fall through */
    case 3:
        checkTag(values[0], DerValue.tag_Integer, "version");
        DerInputStream algid = values[1].toDerInputStream();
        algid.getOID();
        if (algid.available() != 0) {
            algid.getDerValue();
        }
        checkTag(values[2], DerValue.tag_OctetString, "privateKey");
        break;
    default:
        throw new IOException("invalid key encoding");
    }
}
 
Example 4
Source File: EncryptedPrivateKeyInfo.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("fallthrough")
private static void checkPKCS8Encoding(byte[] encodedKey)
    throws IOException {
    DerInputStream in = new DerInputStream(encodedKey);
    DerValue[] values = in.getSequence(3);

    switch (values.length) {
    case 4:
        checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
        /* fall through */
    case 3:
        checkTag(values[0], DerValue.tag_Integer, "version");
        DerInputStream algid = values[1].toDerInputStream();
        algid.getOID();
        if (algid.available() != 0) {
            algid.getDerValue();
        }
        checkTag(values[2], DerValue.tag_OctetString, "privateKey");
        break;
    default:
        throw new IOException("invalid key encoding");
    }
}
 
Example 5
Source File: PKCS12KeyStore.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals(pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 6
Source File: PKCS12KeyStore.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals(pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 7
Source File: PKCS12KeyStore.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals((Object)pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 8
Source File: PKCS12KeyStore.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals((Object)pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 9
Source File: PKCS12KeyStore.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals((Object)pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 10
Source File: PKCS12KeyStore.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals((Object)pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
Example 11
Source File: IssuingDistributionPointExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}
 
Example 12
Source File: SignerInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
Example 13
Source File: IssuingDistributionPointExtension.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}
 
Example 14
Source File: SignerInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
Example 15
Source File: SignerInfo.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
Example 16
Source File: SignerInfo.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
Example 17
Source File: IssuingDistributionPointExtension.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}
 
Example 18
Source File: SignerInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
Example 19
Source File: IssuingDistributionPointExtension.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}
 
Example 20
Source File: IssuingDistributionPointExtension.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}