Search in sources :

Example 66 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class X509V2CRLGenerator method generate.

/**
 * generate an X509 CRL, based on the current issuer and subject, using the passed in provider for
 * the signing.
 */
public X509CRL generate(PrivateKey key, String provider, SecureRandom random) throws CRLException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertList tbsCrl = generateCertList();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCrl);
    } catch (IOException e) {
        throw new ExtCRLException("cannot generate CRL encoding", e);
    }
    return generateJcaObject(tbsCrl, signature);
}
Also used : TBSCertList(com.github.zhenwei.core.asn1.x509.TBSCertList) IOException(java.io.IOException)

Example 67 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class X509V3CertificateGenerator method generate.

/**
 * generate an X509 certificate, based on the current issuer and subject, using the passed in
 * provider for the signing and the supplied source of randomness, if required.
 */
public X509Certificate generate(PrivateKey key, String provider, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertificate tbsCert = generateTbsCert();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCert);
    } catch (IOException e) {
        throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
    }
    try {
        return generateJcaObject(tbsCert, signature);
    } catch (Exception e) {
        throw new ExtCertificateEncodingException("exception producing certificate object", e);
    }
}
Also used : IOException(java.io.IOException) TBSCertificate(com.github.zhenwei.core.asn1.x509.TBSCertificate) CertificateParsingException(java.security.cert.CertificateParsingException) GeneralSecurityException(java.security.GeneralSecurityException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 68 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class X509V1CertificateGenerator method generateJcaObject.

private X509Certificate generateJcaObject(TBSCertificate tbsCert, byte[] signature) throws CertificateEncodingException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbsCert);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));
    try {
        return (X509Certificate) certificateFactory.engineGenerateCertificate(new ByteArrayInputStream(new DERSequence(v).getEncoded(ASN1Encoding.DER)));
    } catch (Exception e) {
        throw new ExtCertificateEncodingException("exception producing certificate object", e);
    }
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) DERBitString(com.github.zhenwei.core.asn1.DERBitString) X509Certificate(java.security.cert.X509Certificate) GeneralSecurityException(java.security.GeneralSecurityException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 69 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class GMSSPrivateKey method encode.

// TODO: change method signature to something more integrated into BouncyCastle
/**
 * @param index             tree indices
 * @param currentSeeds      seed for the generation of private OTS keys for the current subtrees
 *                          (TREE)
 * @param nextNextSeeds     seed for the generation of private OTS keys for the subtrees after
 *                          next (TREE++)
 * @param currentAuthPaths  array of current authentication paths (AUTHPATH)
 * @param nextAuthPaths     array of next authentication paths (AUTHPATH+)
 * @param keep              keep array for the authPath algorithm
 * @param currentTreehash   treehash for authPath algorithm of current tree
 * @param nextTreehash      treehash for authPath algorithm of next tree (TREE+)
 * @param currentStack      shared stack for authPath algorithm of current tree
 * @param nextStack         shared stack for authPath algorithm of next tree (TREE+)
 * @param currentRetain     retain stack for authPath algorithm of current tree
 * @param nextRetain        retain stack for authPath algorithm of next tree (TREE+)
 * @param nextNextLeaf      array of upcoming leafs of the tree after next (LEAF++) of each layer
 * @param upperLeaf         needed for precomputation of upper nodes
 * @param upperTreehashLeaf needed for precomputation of upper treehash nodes
 * @param minTreehash       index of next treehash instance to receive an update
 * @param nextRoot          the roots of the next trees (ROOT+)
 * @param nextNextRoot      the roots of the tree after next (ROOT++)
 * @param currentRootSig    array of signatures of the roots of the current subtrees (SIG)
 * @param nextRootSig       array of signatures of the roots of the next subtree (SIG+)
 * @param gmssParameterset  the GMSS Parameterset
 * @param algorithms        An array of algorithm identifiers, containing the hash function
 *                          details
 */
private ASN1Primitive encode(int[] index, byte[][] currentSeeds, byte[][] nextNextSeeds, byte[][][] currentAuthPaths, byte[][][] nextAuthPaths, byte[][][] keep, Treehash[][] currentTreehash, Treehash[][] nextTreehash, Vector[] currentStack, Vector[] nextStack, Vector[][] currentRetain, Vector[][] nextRetain, GMSSLeaf[] nextNextLeaf, GMSSLeaf[] upperLeaf, GMSSLeaf[] upperTreehashLeaf, int[] minTreehash, byte[][] nextRoot, GMSSRootCalc[] nextNextRoot, byte[][] currentRootSig, GMSSRootSig[] nextRootSig, GMSSParameters gmssParameterset, AlgorithmIdentifier[] algorithms) {
    ASN1EncodableVector result = new ASN1EncodableVector();
    // --- Encode <index>.
    ASN1EncodableVector indexPart = new ASN1EncodableVector();
    for (int i = 0; i < index.length; i++) {
        indexPart.add(new ASN1Integer(index[i]));
    }
    result.add(new DERSequence(indexPart));
    // --- Encode <curSeeds>.
    ASN1EncodableVector curSeedsPart = new ASN1EncodableVector();
    for (int i = 0; i < currentSeeds.length; i++) {
        curSeedsPart.add(new DEROctetString(currentSeeds[i]));
    }
    result.add(new DERSequence(curSeedsPart));
    // --- Encode <nextNextSeeds>.
    ASN1EncodableVector nextNextSeedsPart = new ASN1EncodableVector();
    for (int i = 0; i < nextNextSeeds.length; i++) {
        nextNextSeedsPart.add(new DEROctetString(nextNextSeeds[i]));
    }
    result.add(new DERSequence(nextNextSeedsPart));
    // --- Encode <curAuth>.
    ASN1EncodableVector curAuthPart0 = new ASN1EncodableVector();
    ASN1EncodableVector curAuthPart1 = new ASN1EncodableVector();
    for (int i = 0; i < currentAuthPaths.length; i++) {
        for (int j = 0; j < currentAuthPaths[i].length; j++) {
            curAuthPart0.add(new DEROctetString(currentAuthPaths[i][j]));
        }
        curAuthPart1.add(new DERSequence(curAuthPart0));
        curAuthPart0 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(curAuthPart1));
    // --- Encode <nextAuth>.
    ASN1EncodableVector nextAuthPart0 = new ASN1EncodableVector();
    ASN1EncodableVector nextAuthPart1 = new ASN1EncodableVector();
    for (int i = 0; i < nextAuthPaths.length; i++) {
        for (int j = 0; j < nextAuthPaths[i].length; j++) {
            nextAuthPart0.add(new DEROctetString(nextAuthPaths[i][j]));
        }
        nextAuthPart1.add(new DERSequence(nextAuthPart0));
        nextAuthPart0 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(nextAuthPart1));
    // --- Encode <curTreehash>.
    ASN1EncodableVector seqOfTreehash0 = new ASN1EncodableVector();
    ASN1EncodableVector seqOfTreehash1 = new ASN1EncodableVector();
    ASN1EncodableVector seqOfStat = new ASN1EncodableVector();
    ASN1EncodableVector seqOfByte = new ASN1EncodableVector();
    ASN1EncodableVector seqOfInt = new ASN1EncodableVector();
    for (int i = 0; i < currentTreehash.length; i++) {
        for (int j = 0; j < currentTreehash[i].length; j++) {
            seqOfStat.add(new DERSequence(algorithms[0]));
            int tailLength = currentTreehash[i][j].getStatInt()[1];
            seqOfByte.add(new DEROctetString(currentTreehash[i][j].getStatByte()[0]));
            seqOfByte.add(new DEROctetString(currentTreehash[i][j].getStatByte()[1]));
            seqOfByte.add(new DEROctetString(currentTreehash[i][j].getStatByte()[2]));
            for (int k = 0; k < tailLength; k++) {
                seqOfByte.add(new DEROctetString(currentTreehash[i][j].getStatByte()[3 + k]));
            }
            seqOfStat.add(new DERSequence(seqOfByte));
            seqOfByte = new ASN1EncodableVector();
            seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[0]));
            seqOfInt.add(new ASN1Integer(tailLength));
            seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[2]));
            seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[3]));
            seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[4]));
            seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[5]));
            for (int k = 0; k < tailLength; k++) {
                seqOfInt.add(new ASN1Integer(currentTreehash[i][j].getStatInt()[6 + k]));
            }
            seqOfStat.add(new DERSequence(seqOfInt));
            seqOfInt = new ASN1EncodableVector();
            seqOfTreehash1.add(new DERSequence(seqOfStat));
            seqOfStat = new ASN1EncodableVector();
        }
        seqOfTreehash0.add(new DERSequence(seqOfTreehash1));
        seqOfTreehash1 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfTreehash0));
    // --- Encode <nextTreehash>.
    seqOfTreehash0 = new ASN1EncodableVector();
    seqOfTreehash1 = new ASN1EncodableVector();
    seqOfStat = new ASN1EncodableVector();
    seqOfByte = new ASN1EncodableVector();
    seqOfInt = new ASN1EncodableVector();
    for (int i = 0; i < nextTreehash.length; i++) {
        for (int j = 0; j < nextTreehash[i].length; j++) {
            seqOfStat.add(new DERSequence(algorithms[0]));
            int tailLength = nextTreehash[i][j].getStatInt()[1];
            seqOfByte.add(new DEROctetString(nextTreehash[i][j].getStatByte()[0]));
            seqOfByte.add(new DEROctetString(nextTreehash[i][j].getStatByte()[1]));
            seqOfByte.add(new DEROctetString(nextTreehash[i][j].getStatByte()[2]));
            for (int k = 0; k < tailLength; k++) {
                seqOfByte.add(new DEROctetString(nextTreehash[i][j].getStatByte()[3 + k]));
            }
            seqOfStat.add(new DERSequence(seqOfByte));
            seqOfByte = new ASN1EncodableVector();
            seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[0]));
            seqOfInt.add(new ASN1Integer(tailLength));
            seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[2]));
            seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[3]));
            seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[4]));
            seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[5]));
            for (int k = 0; k < tailLength; k++) {
                seqOfInt.add(new ASN1Integer(nextTreehash[i][j].getStatInt()[6 + k]));
            }
            seqOfStat.add(new DERSequence(seqOfInt));
            seqOfInt = new ASN1EncodableVector();
            seqOfTreehash1.add(new DERSequence(seqOfStat));
            seqOfStat = new ASN1EncodableVector();
        }
        seqOfTreehash0.add(new DERSequence(new DERSequence(seqOfTreehash1)));
        seqOfTreehash1 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfTreehash0));
    // --- Encode <keep>.
    ASN1EncodableVector keepPart0 = new ASN1EncodableVector();
    ASN1EncodableVector keepPart1 = new ASN1EncodableVector();
    for (int i = 0; i < keep.length; i++) {
        for (int j = 0; j < keep[i].length; j++) {
            keepPart0.add(new DEROctetString(keep[i][j]));
        }
        keepPart1.add(new DERSequence(keepPart0));
        keepPart0 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(keepPart1));
    // --- Encode <curStack>.
    ASN1EncodableVector curStackPart0 = new ASN1EncodableVector();
    ASN1EncodableVector curStackPart1 = new ASN1EncodableVector();
    for (int i = 0; i < currentStack.length; i++) {
        for (int j = 0; j < currentStack[i].size(); j++) {
            curStackPart0.add(new DEROctetString((byte[]) currentStack[i].elementAt(j)));
        }
        curStackPart1.add(new DERSequence(curStackPart0));
        curStackPart0 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(curStackPart1));
    // --- Encode <nextStack>.
    ASN1EncodableVector nextStackPart0 = new ASN1EncodableVector();
    ASN1EncodableVector nextStackPart1 = new ASN1EncodableVector();
    for (int i = 0; i < nextStack.length; i++) {
        for (int j = 0; j < nextStack[i].size(); j++) {
            nextStackPart0.add(new DEROctetString((byte[]) nextStack[i].elementAt(j)));
        }
        nextStackPart1.add(new DERSequence(nextStackPart0));
        nextStackPart0 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(nextStackPart1));
    // --- Encode <curRetain>.
    ASN1EncodableVector currentRetainPart0 = new ASN1EncodableVector();
    ASN1EncodableVector currentRetainPart1 = new ASN1EncodableVector();
    ASN1EncodableVector currentRetainPart2 = new ASN1EncodableVector();
    for (int i = 0; i < currentRetain.length; i++) {
        for (int j = 0; j < currentRetain[i].length; j++) {
            for (int k = 0; k < currentRetain[i][j].size(); k++) {
                currentRetainPart0.add(new DEROctetString((byte[]) currentRetain[i][j].elementAt(k)));
            }
            currentRetainPart1.add(new DERSequence(currentRetainPart0));
            currentRetainPart0 = new ASN1EncodableVector();
        }
        currentRetainPart2.add(new DERSequence(currentRetainPart1));
        currentRetainPart1 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(currentRetainPart2));
    // --- Encode <nextRetain>.
    ASN1EncodableVector nextRetainPart0 = new ASN1EncodableVector();
    ASN1EncodableVector nextRetainPart1 = new ASN1EncodableVector();
    ASN1EncodableVector nextRetainPart2 = new ASN1EncodableVector();
    for (int i = 0; i < nextRetain.length; i++) {
        for (int j = 0; j < nextRetain[i].length; j++) {
            for (int k = 0; k < nextRetain[i][j].size(); k++) {
                nextRetainPart0.add(new DEROctetString((byte[]) nextRetain[i][j].elementAt(k)));
            }
            nextRetainPart1.add(new DERSequence(nextRetainPart0));
            nextRetainPart0 = new ASN1EncodableVector();
        }
        nextRetainPart2.add(new DERSequence(nextRetainPart1));
        nextRetainPart1 = new ASN1EncodableVector();
    }
    result.add(new DERSequence(nextRetainPart2));
    // --- Encode <nextNextLeaf>.
    ASN1EncodableVector seqOfLeaf = new ASN1EncodableVector();
    seqOfStat = new ASN1EncodableVector();
    seqOfByte = new ASN1EncodableVector();
    seqOfInt = new ASN1EncodableVector();
    for (int i = 0; i < nextNextLeaf.length; i++) {
        seqOfStat.add(new DERSequence(algorithms[0]));
        byte[][] tempByte = nextNextLeaf[i].getStatByte();
        seqOfByte.add(new DEROctetString(tempByte[0]));
        seqOfByte.add(new DEROctetString(tempByte[1]));
        seqOfByte.add(new DEROctetString(tempByte[2]));
        seqOfByte.add(new DEROctetString(tempByte[3]));
        seqOfStat.add(new DERSequence(seqOfByte));
        seqOfByte = new ASN1EncodableVector();
        int[] tempInt = nextNextLeaf[i].getStatInt();
        seqOfInt.add(new ASN1Integer(tempInt[0]));
        seqOfInt.add(new ASN1Integer(tempInt[1]));
        seqOfInt.add(new ASN1Integer(tempInt[2]));
        seqOfInt.add(new ASN1Integer(tempInt[3]));
        seqOfStat.add(new DERSequence(seqOfInt));
        seqOfInt = new ASN1EncodableVector();
        seqOfLeaf.add(new DERSequence(seqOfStat));
        seqOfStat = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfLeaf));
    // --- Encode <upperLEAF>.
    ASN1EncodableVector seqOfUpperLeaf = new ASN1EncodableVector();
    seqOfStat = new ASN1EncodableVector();
    seqOfByte = new ASN1EncodableVector();
    seqOfInt = new ASN1EncodableVector();
    for (int i = 0; i < upperLeaf.length; i++) {
        seqOfStat.add(new DERSequence(algorithms[0]));
        byte[][] tempByte = upperLeaf[i].getStatByte();
        seqOfByte.add(new DEROctetString(tempByte[0]));
        seqOfByte.add(new DEROctetString(tempByte[1]));
        seqOfByte.add(new DEROctetString(tempByte[2]));
        seqOfByte.add(new DEROctetString(tempByte[3]));
        seqOfStat.add(new DERSequence(seqOfByte));
        seqOfByte = new ASN1EncodableVector();
        int[] tempInt = upperLeaf[i].getStatInt();
        seqOfInt.add(new ASN1Integer(tempInt[0]));
        seqOfInt.add(new ASN1Integer(tempInt[1]));
        seqOfInt.add(new ASN1Integer(tempInt[2]));
        seqOfInt.add(new ASN1Integer(tempInt[3]));
        seqOfStat.add(new DERSequence(seqOfInt));
        seqOfInt = new ASN1EncodableVector();
        seqOfUpperLeaf.add(new DERSequence(seqOfStat));
        seqOfStat = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfUpperLeaf));
    // encode <upperTreehashLeaf>
    ASN1EncodableVector seqOfUpperTreehashLeaf = new ASN1EncodableVector();
    seqOfStat = new ASN1EncodableVector();
    seqOfByte = new ASN1EncodableVector();
    seqOfInt = new ASN1EncodableVector();
    for (int i = 0; i < upperTreehashLeaf.length; i++) {
        seqOfStat.add(new DERSequence(algorithms[0]));
        byte[][] tempByte = upperTreehashLeaf[i].getStatByte();
        seqOfByte.add(new DEROctetString(tempByte[0]));
        seqOfByte.add(new DEROctetString(tempByte[1]));
        seqOfByte.add(new DEROctetString(tempByte[2]));
        seqOfByte.add(new DEROctetString(tempByte[3]));
        seqOfStat.add(new DERSequence(seqOfByte));
        seqOfByte = new ASN1EncodableVector();
        int[] tempInt = upperTreehashLeaf[i].getStatInt();
        seqOfInt.add(new ASN1Integer(tempInt[0]));
        seqOfInt.add(new ASN1Integer(tempInt[1]));
        seqOfInt.add(new ASN1Integer(tempInt[2]));
        seqOfInt.add(new ASN1Integer(tempInt[3]));
        seqOfStat.add(new DERSequence(seqOfInt));
        seqOfInt = new ASN1EncodableVector();
        seqOfUpperTreehashLeaf.add(new DERSequence(seqOfStat));
        seqOfStat = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfUpperTreehashLeaf));
    // --- Encode <minTreehash>.
    ASN1EncodableVector minTreehashPart = new ASN1EncodableVector();
    for (int i = 0; i < minTreehash.length; i++) {
        minTreehashPart.add(new ASN1Integer(minTreehash[i]));
    }
    result.add(new DERSequence(minTreehashPart));
    // --- Encode <nextRoot>.
    ASN1EncodableVector nextRootPart = new ASN1EncodableVector();
    for (int i = 0; i < nextRoot.length; i++) {
        nextRootPart.add(new DEROctetString(nextRoot[i]));
    }
    result.add(new DERSequence(nextRootPart));
    // --- Encode <nextNextRoot>.
    ASN1EncodableVector seqOfnextNextRoot = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRStats = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRStrings = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRBytes = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRInts = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRTreehash = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnnRRetain = new ASN1EncodableVector();
    for (int i = 0; i < nextNextRoot.length; i++) {
        seqOfnnRStats.add(new DERSequence(algorithms[0]));
        seqOfnnRStrings = new ASN1EncodableVector();
        int heightOfTree = nextNextRoot[i].getStatInt()[0];
        int tailLength = nextNextRoot[i].getStatInt()[7];
        seqOfnnRBytes.add(new DEROctetString(nextNextRoot[i].getStatByte()[0]));
        for (int j = 0; j < heightOfTree; j++) {
            seqOfnnRBytes.add(new DEROctetString(nextNextRoot[i].getStatByte()[1 + j]));
        }
        for (int j = 0; j < tailLength; j++) {
            seqOfnnRBytes.add(new DEROctetString(nextNextRoot[i].getStatByte()[1 + heightOfTree + j]));
        }
        seqOfnnRStats.add(new DERSequence(seqOfnnRBytes));
        seqOfnnRBytes = new ASN1EncodableVector();
        seqOfnnRInts.add(new ASN1Integer(heightOfTree));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[1]));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[2]));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[3]));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[4]));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[5]));
        seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[6]));
        seqOfnnRInts.add(new ASN1Integer(tailLength));
        for (int j = 0; j < heightOfTree; j++) {
            seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[8 + j]));
        }
        for (int j = 0; j < tailLength; j++) {
            seqOfnnRInts.add(new ASN1Integer(nextNextRoot[i].getStatInt()[8 + heightOfTree + j]));
        }
        seqOfnnRStats.add(new DERSequence(seqOfnnRInts));
        seqOfnnRInts = new ASN1EncodableVector();
        // add treehash of nextNextRoot object
        // ----------------------------
        seqOfStat = new ASN1EncodableVector();
        seqOfByte = new ASN1EncodableVector();
        seqOfInt = new ASN1EncodableVector();
        if (nextNextRoot[i].getTreehash() != null) {
            for (int j = 0; j < nextNextRoot[i].getTreehash().length; j++) {
                seqOfStat.add(new DERSequence(algorithms[0]));
                tailLength = nextNextRoot[i].getTreehash()[j].getStatInt()[1];
                seqOfByte.add(new DEROctetString(nextNextRoot[i].getTreehash()[j].getStatByte()[0]));
                seqOfByte.add(new DEROctetString(nextNextRoot[i].getTreehash()[j].getStatByte()[1]));
                seqOfByte.add(new DEROctetString(nextNextRoot[i].getTreehash()[j].getStatByte()[2]));
                for (int k = 0; k < tailLength; k++) {
                    seqOfByte.add(new DEROctetString(nextNextRoot[i].getTreehash()[j].getStatByte()[3 + k]));
                }
                seqOfStat.add(new DERSequence(seqOfByte));
                seqOfByte = new ASN1EncodableVector();
                seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[0]));
                seqOfInt.add(new ASN1Integer(tailLength));
                seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[2]));
                seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[3]));
                seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[4]));
                seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[5]));
                for (int k = 0; k < tailLength; k++) {
                    seqOfInt.add(new ASN1Integer(nextNextRoot[i].getTreehash()[j].getStatInt()[6 + k]));
                }
                seqOfStat.add(new DERSequence(seqOfInt));
                seqOfInt = new ASN1EncodableVector();
                seqOfnnRTreehash.add(new DERSequence(seqOfStat));
                seqOfStat = new ASN1EncodableVector();
            }
        }
        // ----------------------------
        seqOfnnRStats.add(new DERSequence(seqOfnnRTreehash));
        seqOfnnRTreehash = new ASN1EncodableVector();
        // encode retain of nextNextRoot
        // ----------------------------
        // --- Encode <curRetain>.
        currentRetainPart0 = new ASN1EncodableVector();
        if (nextNextRoot[i].getRetain() != null) {
            for (int j = 0; j < nextNextRoot[i].getRetain().length; j++) {
                for (int k = 0; k < nextNextRoot[i].getRetain()[j].size(); k++) {
                    currentRetainPart0.add(new DEROctetString((byte[]) nextNextRoot[i].getRetain()[j].elementAt(k)));
                }
                seqOfnnRRetain.add(new DERSequence(currentRetainPart0));
                currentRetainPart0 = new ASN1EncodableVector();
            }
        }
        // ----------------------------
        seqOfnnRStats.add(new DERSequence(seqOfnnRRetain));
        seqOfnnRRetain = new ASN1EncodableVector();
        seqOfnextNextRoot.add(new DERSequence(seqOfnnRStats));
        seqOfnnRStats = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfnextNextRoot));
    // --- Encode <curRootSig>.
    ASN1EncodableVector curRootSigPart = new ASN1EncodableVector();
    for (int i = 0; i < currentRootSig.length; i++) {
        curRootSigPart.add(new DEROctetString(currentRootSig[i]));
    }
    result.add(new DERSequence(curRootSigPart));
    // --- Encode <nextRootSig>.
    ASN1EncodableVector seqOfnextRootSigs = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnRSStats = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnRSStrings = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnRSBytes = new ASN1EncodableVector();
    ASN1EncodableVector seqOfnRSInts = new ASN1EncodableVector();
    for (int i = 0; i < nextRootSig.length; i++) {
        seqOfnRSStats.add(new DERSequence(algorithms[0]));
        seqOfnRSStrings = new ASN1EncodableVector();
        seqOfnRSBytes.add(new DEROctetString(nextRootSig[i].getStatByte()[0]));
        seqOfnRSBytes.add(new DEROctetString(nextRootSig[i].getStatByte()[1]));
        seqOfnRSBytes.add(new DEROctetString(nextRootSig[i].getStatByte()[2]));
        seqOfnRSBytes.add(new DEROctetString(nextRootSig[i].getStatByte()[3]));
        seqOfnRSBytes.add(new DEROctetString(nextRootSig[i].getStatByte()[4]));
        seqOfnRSStats.add(new DERSequence(seqOfnRSBytes));
        seqOfnRSBytes = new ASN1EncodableVector();
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[0]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[1]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[2]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[3]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[4]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[5]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[6]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[7]));
        seqOfnRSInts.add(new ASN1Integer(nextRootSig[i].getStatInt()[8]));
        seqOfnRSStats.add(new DERSequence(seqOfnRSInts));
        seqOfnRSInts = new ASN1EncodableVector();
        seqOfnextRootSigs.add(new DERSequence(seqOfnRSStats));
        seqOfnRSStats = new ASN1EncodableVector();
    }
    result.add(new DERSequence(seqOfnextRootSigs));
    // --- Encode <parameterset>.
    ASN1EncodableVector parSetPart0 = new ASN1EncodableVector();
    ASN1EncodableVector parSetPart1 = new ASN1EncodableVector();
    ASN1EncodableVector parSetPart2 = new ASN1EncodableVector();
    ASN1EncodableVector parSetPart3 = new ASN1EncodableVector();
    for (int i = 0; i < gmssParameterset.getHeightOfTrees().length; i++) {
        parSetPart1.add(new ASN1Integer(gmssParameterset.getHeightOfTrees()[i]));
        parSetPart2.add(new ASN1Integer(gmssParameterset.getWinternitzParameter()[i]));
        parSetPart3.add(new ASN1Integer(gmssParameterset.getK()[i]));
    }
    parSetPart0.add(new ASN1Integer(gmssParameterset.getNumOfLayers()));
    parSetPart0.add(new DERSequence(parSetPart1));
    parSetPart0.add(new DERSequence(parSetPart2));
    parSetPart0.add(new DERSequence(parSetPart3));
    result.add(new DERSequence(parSetPart0));
    // --- Encode <names>.
    ASN1EncodableVector namesPart = new ASN1EncodableVector();
    for (int i = 0; i < algorithms.length; i++) {
        namesPart.add(algorithms[i]);
    }
    result.add(new DERSequence(namesPart));
    return new DERSequence(result);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Example 70 with Signature

use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.

the class CertUtils method generateAttrStructure.

private static AttributeCertificate generateAttrStructure(AttributeCertificateInfo attrInfo, AlgorithmIdentifier sigAlgId, byte[] signature) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(attrInfo);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));
    return AttributeCertificate.getInstance(new DERSequence(v));
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) DERBitString(com.github.zhenwei.core.asn1.DERBitString)

Aggregations

IOException (java.io.IOException)44 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)34 DERSequence (com.github.zhenwei.core.asn1.DERSequence)29 DERBitString (com.github.zhenwei.core.asn1.DERBitString)21 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)20 OutputStream (java.io.OutputStream)20 SignatureException (java.security.SignatureException)20 GeneralSecurityException (java.security.GeneralSecurityException)15 Signature (java.security.Signature)15 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)14 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)14 InvalidKeyException (java.security.InvalidKeyException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 Iterator (java.util.Iterator)13 OperatorCreationException (com.github.zhenwei.pkix.operator.OperatorCreationException)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 NoSuchProviderException (java.security.NoSuchProviderException)10 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)9 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)9 List (java.util.List)9