sun.security.krb5.internal.util.KerberosString Java Examples

The following examples show how to use sun.security.krb5.internal.util.KerberosString. 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: ETypeInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #2
Source File: ETypeInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #3
Source File: PrincipalName.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #4
Source File: ETypeInfo.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #5
Source File: ETypeInfo.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #6
Source File: ETypeInfo.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #7
Source File: ETypeInfo.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #8
Source File: PrincipalName.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #9
Source File: PrincipalName.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #10
Source File: PrincipalName.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #11
Source File: ETypeInfo.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #12
Source File: PrincipalName.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #13
Source File: PrincipalName.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #14
Source File: ETypeInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #15
Source File: PrincipalName.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a <code>PrincipalName</code> object. Note that only the type and
 * names are encoded. To encode the realm, call getRealm().asn1Encode().
 * @return the byte array of the encoded PrncipalName object.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 *
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    BigInteger bint = BigInteger.valueOf(this.nameType);
    temp.putInteger(bint);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    DerValue der[] = new DerValue[nameStrings.length];
    for (int i = 0; i < nameStrings.length; i++) {
        der[i] = new KerberosString(nameStrings[i]).toDerValue();
    }
    temp.putSequence(der);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #16
Source File: Realm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #17
Source File: ETypeInfo2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (saltStr != null) {
        temp = new DerOutputStream();
        temp.putDerValue(new KerberosString(saltStr).toDerValue());
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE1), temp);
    }
    if (s2kparams != null) {
        temp = new DerOutputStream();
        temp.putOctetString(s2kparams);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE2), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #18
Source File: ETypeInfo2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ETypeInfo2 object.
 * @param encoding a DER-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an
 *            ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;

    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    // etype
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        this.etype = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    // salt
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
            der = encoding.getData().getDerValue();
            this.saltStr = new KerberosString(
                    der.getData().getDerValue()).toString();
        }
    }

    // s2kparams
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
            der = encoding.getData().getDerValue();
            this.s2kparams = der.getData().getOctetString();
        }
    }

    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #19
Source File: ETypeInfo2.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (saltStr != null) {
        temp = new DerOutputStream();
        temp.putDerValue(new KerberosString(saltStr).toDerValue());
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE1), temp);
    }
    if (s2kparams != null) {
        temp = new DerOutputStream();
        temp.putOctetString(s2kparams);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE2), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #20
Source File: ETypeInfo2.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (saltStr != null) {
        temp = new DerOutputStream();
        temp.putDerValue(new KerberosString(saltStr).toDerValue());
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE1), temp);
    }
    if (s2kparams != null) {
        temp = new DerOutputStream();
        temp.putOctetString(s2kparams);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE2), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #21
Source File: ETypeInfo2.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (saltStr != null) {
        temp = new DerOutputStream();
        temp.putDerValue(new KerberosString(saltStr).toDerValue());
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE1), temp);
    }
    if (s2kparams != null) {
        temp = new DerOutputStream();
        temp.putOctetString(s2kparams);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE2), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #22
Source File: ETypeInfo2.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ETypeInfo2 object.
 * @param encoding a DER-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an
 *            ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;

    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    // etype
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        this.etype = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    // salt
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
            der = encoding.getData().getDerValue();
            this.saltStr = new KerberosString(
                    der.getData().getDerValue()).toString();
        }
    }

    // s2kparams
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
            der = encoding.getData().getDerValue();
            this.s2kparams = der.getData().getOctetString();
        }
    }

    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #23
Source File: Realm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #24
Source File: ETypeInfo2.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ETypeInfo2 object.
 * @param encoding a DER-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an
 *            ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;

    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    // etype
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        this.etype = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    // salt
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
            der = encoding.getData().getDerValue();
            this.saltStr = new KerberosString(
                    der.getData().getDerValue()).toString();
        }
    }

    // s2kparams
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
            der = encoding.getData().getDerValue();
            this.s2kparams = der.getData().getOctetString();
        }
    }

    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #25
Source File: Realm.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #26
Source File: Realm.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #27
Source File: ETypeInfo2.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ETypeInfo2 object.
 * @param encoding a DER-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an
 *            ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;

    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    // etype
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        this.etype = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    // salt
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
            der = encoding.getData().getDerValue();
            this.saltStr = new KerberosString(
                    der.getData().getDerValue()).toString();
        }
    }

    // s2kparams
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
            der = encoding.getData().getDerValue();
            this.s2kparams = der.getData().getOctetString();
        }
    }

    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #28
Source File: ETypeInfo2.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (saltStr != null) {
        temp = new DerOutputStream();
        temp.putDerValue(new KerberosString(saltStr).toDerValue());
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE1), temp);
    }
    if (s2kparams != null) {
        temp = new DerOutputStream();
        temp.putOctetString(s2kparams);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE2), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #29
Source File: Realm.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #30
Source File: ETypeInfo2.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ETypeInfo2 object.
 * @param encoding a DER-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an
 *            ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 */
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;

    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    // etype
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        this.etype = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    // salt
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
            der = encoding.getData().getDerValue();
            this.saltStr = new KerberosString(
                    der.getData().getDerValue()).toString();
        }
    }

    // s2kparams
    if (encoding.getData().available() > 0) {
        if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
            der = encoding.getData().getDerValue();
            this.s2kparams = der.getData().getOctetString();
        }
    }

    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}