Search in sources :

Example 6 with BitArray

use of sun.security.util.BitArray in project Bytecoder by mirkosertic.

the class IPAddressName method parseIPv6.

private void parseIPv6(String name) throws IOException {
    int slashNdx = name.indexOf('/');
    if (slashNdx == -1) {
        address = InetAddress.getByName(name).getAddress();
    } else {
        address = new byte[32];
        byte[] base = InetAddress.getByName(name.substring(0, slashNdx)).getAddress();
        System.arraycopy(base, 0, address, 0, 16);
        // append a mask corresponding to the num of prefix bits specified
        int prefixLen = Integer.parseInt(name.substring(slashNdx + 1));
        if (prefixLen < 0 || prefixLen > 128) {
            throw new IOException("IPv6Address prefix length (" + prefixLen + ") in out of valid range [0,128]");
        }
        // create new bit array initialized to zeros
        BitArray bitArray = new BitArray(MASKSIZE * 8);
        // set all most significant bits up to prefix length
        for (int i = 0; i < prefixLen; i++) bitArray.set(i, true);
        byte[] maskArray = bitArray.toByteArray();
        // copy mask bytes into mask portion of address
        for (int i = 0; i < MASKSIZE; i++) address[MASKSIZE + i] = maskArray[i];
    }
}
Also used : IOException(java.io.IOException) BitArray(sun.security.util.BitArray)

Example 7 with BitArray

use of sun.security.util.BitArray in project Bytecoder by mirkosertic.

the class DistributionPoint method encode.

/**
 * Write the DistributionPoint value to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on error.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tagged = new DerOutputStream();
    // NOTE: only one of pointNames and pointRDN can be set
    if ((fullName != null) || (relativeName != null)) {
        DerOutputStream distributionPoint = new DerOutputStream();
        if (fullName != null) {
            DerOutputStream derOut = new DerOutputStream();
            fullName.encode(derOut);
            distributionPoint.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FULL_NAME), derOut);
        } else if (relativeName != null) {
            DerOutputStream derOut = new DerOutputStream();
            relativeName.encode(derOut);
            distributionPoint.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REL_NAME), derOut);
        }
        tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_DIST_PT), distributionPoint);
    }
    if (reasonFlags != null) {
        DerOutputStream reasons = new DerOutputStream();
        BitArray rf = new BitArray(reasonFlags);
        reasons.putTruncatedUnalignedBitString(rf);
        tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, false, TAG_REASONS), reasons);
    }
    if (crlIssuer != null) {
        DerOutputStream issuer = new DerOutputStream();
        crlIssuer.encode(issuer);
        tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_ISSUER), issuer);
    }
    out.write(DerValue.tag_Sequence, tagged);
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) BitArray(sun.security.util.BitArray)

Example 8 with BitArray

use of sun.security.util.BitArray in project j2objc by google.

the class IPAddressName method getName.

/**
 * Return a standard String representation of IPAddress.
 * See IPAddressName(String) for the formats used for IPv4
 * and IPv6 addresses.
 *
 * @throws IOException if the IPAddress cannot be converted to a String
 */
public String getName() throws IOException {
    if (name != null)
        return name;
    if (isIPv4) {
        // IPv4 address or subdomain
        byte[] host = new byte[4];
        System.arraycopy(address, 0, host, 0, 4);
        name = InetAddress.getByAddress(host).getHostAddress();
        if (address.length == 8) {
            byte[] mask = new byte[4];
            System.arraycopy(address, 4, mask, 0, 4);
            name = name + "/" + InetAddress.getByAddress(mask).getHostAddress();
        }
    } else {
        // IPv6 address or subdomain
        byte[] host = new byte[16];
        System.arraycopy(address, 0, host, 0, 16);
        name = InetAddress.getByAddress(host).getHostAddress();
        if (address.length == 32) {
            // IPv6 subdomain: display prefix length
            // copy subdomain into new array and convert to BitArray
            byte[] maskBytes = new byte[16];
            for (int i = 16; i < 32; i++) maskBytes[i - 16] = address[i];
            BitArray ba = new BitArray(16 * 8, maskBytes);
            // Find first zero bit
            int i = 0;
            for (; i < 16 * 8; i++) {
                if (!ba.get(i))
                    break;
            }
            name = name + "/" + i;
            // Verify remaining bits 0
            for (; i < 16 * 8; i++) {
                if (ba.get(i)) {
                    throw new IOException("Invalid IPv6 subdomain - set " + "bit " + i + " not contiguous");
                }
            }
        }
    }
    return name;
}
Also used : BitArray(sun.security.util.BitArray) IOException(java.io.IOException)

Example 9 with BitArray

use of sun.security.util.BitArray in project j2objc by google.

the class DistributionPoint method encode.

/**
 * Write the DistributionPoint value to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on error.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tagged = new DerOutputStream();
    // NOTE: only one of pointNames and pointRDN can be set
    if ((fullName != null) || (relativeName != null)) {
        DerOutputStream distributionPoint = new DerOutputStream();
        if (fullName != null) {
            DerOutputStream derOut = new DerOutputStream();
            fullName.encode(derOut);
            distributionPoint.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FULL_NAME), derOut);
        } else if (relativeName != null) {
            DerOutputStream derOut = new DerOutputStream();
            relativeName.encode(derOut);
            distributionPoint.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REL_NAME), derOut);
        }
        tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_DIST_PT), distributionPoint);
    }
    if (reasonFlags != null) {
        DerOutputStream reasons = new DerOutputStream();
        BitArray rf = new BitArray(reasonFlags);
        reasons.putTruncatedUnalignedBitString(rf);
        tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, false, TAG_REASONS), reasons);
    }
    if (crlIssuer != null) {
        DerOutputStream issuer = new DerOutputStream();
        crlIssuer.encode(issuer);
        tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_ISSUER), issuer);
    }
    out.write(DerValue.tag_Sequence, tagged);
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) BitArray(sun.security.util.BitArray)

Example 10 with BitArray

use of sun.security.util.BitArray in project OpenAM by OpenRock.

the class DerInputBuffer method getUnalignedBitString.

/**
     * Returns the bit string which takes up the rest of this buffer. The bit
     * string need not be byte-aligned.
     */
BitArray getUnalignedBitString() {
    if (pos >= count)
        return null;
    /*
         * Just copy the data into an aligned, padded octet buffer, and consume
         * the rest of the buffer.
         */
    int len = available();
    byte[] bits = new byte[len - 1];
    // number of valid bits
    int length = bits.length * 8 - buf[pos];
    System.arraycopy(buf, pos + 1, bits, 0, len - 1);
    BitArray bitArray = new BitArray(length, bits);
    pos = count;
    return bitArray;
}
Also used : BitArray(sun.security.util.BitArray)

Aggregations

BitArray (sun.security.util.BitArray)15 IOException (java.io.IOException)7 DerOutputStream (sun.security.util.DerOutputStream)6 DerValue (sun.security.util.DerValue)2 ObjectIdentifier (sun.security.util.ObjectIdentifier)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 Method (java.lang.reflect.Method)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 MessageDigest (java.security.MessageDigest)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 Signature (java.security.Signature)1 X509Certificate (java.security.cert.X509Certificate)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 BASE64Encoder (sun.misc.BASE64Encoder)1