Java Code Examples for sun.security.x509.AlgorithmId#getName()

The following examples show how to use sun.security.x509.AlgorithmId#getName() . 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: MacData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a PKCS#12 MAC data.
 */
MacData(DerInputStream derin)
    throws IOException, ParsingException
{
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
        this.iterations = macData[2].getInteger();
    } else {
        this.iterations = 1;
    }
}
 
Example 2
Source File: MacData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
MacData(String algName, byte[] digest, byte[] salt, int iterations)
    throws NoSuchAlgorithmException
{
    if (algName == null)
       throw new NullPointerException("the algName parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algName);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 3
Source File: MacData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 4
Source File: MacData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 5
Source File: MacData.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 6
Source File: AlgorithmChecker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "Algorithm constraints check failed on signature algorithm: " +
            sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 7
Source File: MacData.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
MacData(String algName, byte[] digest, byte[] salt, int iterations)
    throws NoSuchAlgorithmException
{
    if (algName == null)
       throw new NullPointerException("the algName parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algName);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 8
Source File: AlgorithmChecker.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param algorithmId signature algorithm Algorithm ID
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
static void check(PublicKey key, AlgorithmId algorithmId, String variant)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    certPathDefaultConstraints.permits(new ConstraintsParameters(
            sigAlgName, sigAlgParams, key, variant));
}
 
Example 9
Source File: MacData.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a PKCS#12 MAC data.
 */
MacData(DerInputStream derin)
    throws IOException, ParsingException
{
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
        this.iterations = macData[2].getInteger();
    } else {
        this.iterations = 1;
    }
}
 
Example 10
Source File: MacData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a PKCS#12 MAC data.
 */
MacData(DerInputStream derin)
    throws IOException, ParsingException
{
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
        this.iterations = macData[2].getInteger();
    } else {
        this.iterations = 1;
    }
}
 
Example 11
Source File: MacData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a PKCS#12 MAC data.
 */
MacData(DerInputStream derin)
    throws IOException, ParsingException
{
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
        this.iterations = macData[2].getInteger();
    } else {
        this.iterations = 1;
    }
}
 
Example 12
Source File: MacData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
MacData(String algName, byte[] digest, byte[] salt, int iterations)
    throws NoSuchAlgorithmException
{
    if (algName == null)
       throw new NullPointerException("the algName parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algName);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 13
Source File: MacData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 14
Source File: AlgorithmChecker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param algorithmId signature algorithm Algorithm ID
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
static void check(PublicKey key, AlgorithmId algorithmId, String variant)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    certPathDefaultConstraints.permits(new ConstraintsParameters(
            sigAlgName, sigAlgParams, key, variant));
}
 
Example 15
Source File: MacData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 16
Source File: MacData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a PKCS#12 MAC data.
 */
MacData(DerInputStream derin)
    throws IOException, ParsingException
{
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
        this.iterations = macData[2].getInteger();
    } else {
        this.iterations = 1;
    }
}
 
Example 17
Source File: MacData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
MacData(AlgorithmParameters algParams, byte[] digest,
    byte[] salt, int iterations) throws NoSuchAlgorithmException
{
    if (algParams == null)
       throw new NullPointerException("the algParams parameter " +
                                           "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algParams);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
        throw new NullPointerException("the digest " +
                                       "parameter must be non-null");
    } else if (digest.length == 0) {
        throw new IllegalArgumentException("the digest " +
                                            "parameter must not be empty");
    } else {
        this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;

}
 
Example 18
Source File: AlgorithmChecker.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "algorithm check failed: " + sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 19
Source File: AlgorithmChecker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the signature algorithm with the specified public key.
 *
 * @param key the public key to verify the CRL signature
 * @param crl the target CRL
 */
static void check(PublicKey key, AlgorithmId algorithmId)
                    throws CertPathValidatorException {
    String sigAlgName = algorithmId.getName();
    AlgorithmParameters sigAlgParams = algorithmId.getParameters();

    if (!certPathDefaultConstraints.permits(
            SIGNATURE_PRIMITIVE_SET, sigAlgName, key, sigAlgParams)) {
        throw new CertPathValidatorException(
            "algorithm check failed: " + sigAlgName + " is disabled",
            null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }
}
 
Example 20
Source File: PKCS10.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses an encoded, signed PKCS #10 certificate request, verifying
 * the request's signature as it does so.  This constructor would
 * typically be used by a Certificate Authority, from which a new
 * certificate would then be constructed.
 *
 * @param data the DER-encoded PKCS #10 request.
 * @exception IOException for low level errors reading the data
 * @exception SignatureException when the signature is invalid
 * @exception NoSuchAlgorithmException when the signature
 *  algorithm is not supported in this environment
 */
public PKCS10(byte[] data)
throws IOException, SignatureException, NoSuchAlgorithmException {
    DerInputStream  in;
    DerValue[]      seq;
    AlgorithmId     id;
    byte[]          sigData;
    Signature       sig;

    encoded = data;

    //
    // Outer sequence:  request, signature algorithm, signature.
    // Parse, and prepare to verify later.
    //
    in = new DerInputStream(data);
    seq = in.getSequence(3);

    if (seq.length != 3)
        throw new IllegalArgumentException("not a PKCS #10 request");

    data = seq[0].toByteArray();            // reusing this variable
    id = AlgorithmId.parse(seq[1]);
    sigData = seq[2].getBitString();

    //
    // Inner sequence:  version, name, key, attributes
    //
    BigInteger      serial;
    DerValue        val;

    serial = seq[0].data.getBigInteger();
    if (!serial.equals(BigInteger.ZERO))
        throw new IllegalArgumentException("not PKCS #10 v1");

    subject = new X500Name(seq[0].data);
    subjectPublicKeyInfo = X509Key.parse(seq[0].data.getDerValue());

    // Cope with a somewhat common illegal PKCS #10 format
    if (seq[0].data.available() != 0)
        attributeSet = new PKCS10Attributes(seq[0].data);
    else
        attributeSet = new PKCS10Attributes();

    if (seq[0].data.available() != 0)
        throw new IllegalArgumentException("illegal PKCS #10 data");

    //
    // OK, we parsed it all ... validate the signature using the
    // key and signature algorithm we found.
    //
    try {
        sigAlg = id.getName();
        sig = Signature.getInstance(sigAlg);
        sig.initVerify(subjectPublicKeyInfo);
        sig.update(data);
        if (!sig.verify(sigData))
            throw new SignatureException("Invalid PKCS #10 signature");
    } catch (InvalidKeyException e) {
        throw new SignatureException("invalid key");
    }
}