Search in sources :

Example 1 with DSADigestSigner

use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.

the class BcITSContentSigner method getSignature.

public byte[] getSignature() {
    byte[] clientCertDigest = new byte[digest.getDigestSize()];
    digest.doFinal(clientCertDigest, 0);
    final DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(), digest);
    signer.init(true, privKey);
    signer.update(clientCertDigest, 0, clientCertDigest.length);
    signer.update(parentDigest, 0, parentDigest.length);
    return signer.generateSignature();
}
Also used : DSADigestSigner(com.github.zhenwei.core.crypto.signers.DSADigestSigner) ECDSASigner(com.github.zhenwei.core.crypto.signers.ECDSASigner)

Example 2 with DSADigestSigner

use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.

the class BcITSContentVerifierProvider method get.

public ContentVerifier get(final int verifierAlgorithmIdentifier) throws OperatorCreationException {
    if (sigChoice != verifierAlgorithmIdentifier) {
        throw new OperatorCreationException("wrong verifier for algorithm: " + verifierAlgorithmIdentifier);
    }
    final Digest digest = BcDefaultDigestProvider.INSTANCE.get(digestAlgo);
    final byte[] parentDigest = new byte[digest.getDigestSize()];
    digest.update(parentData, 0, parentData.length);
    digest.doFinal(parentDigest, 0);
    final byte[] parentTBSDigest = issuer.getIssuer().isSelf() ? new byte[digest.getDigestSize()] : null;
    if (parentTBSDigest != null) {
        byte[] enc = OEREncoder.toByteArray(issuer.toASN1Structure().getCertificateBase().getToBeSignedCertificate(), IEEE1609dot2.tbsCertificate);
        digest.update(enc, 0, enc.length);
        digest.doFinal(parentTBSDigest, 0);
    }
    final OutputStream os = new OutputStream() {

        public void write(int b) throws IOException {
            digest.update((byte) b);
        }

        public void write(byte[] b) throws IOException {
            digest.update(b, 0, b.length);
        }

        public void write(byte[] b, int off, int len) throws IOException {
            digest.update(b, off, len);
        }
    };
    return new ContentVerifier() {

        final DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(), BcDefaultDigestProvider.INSTANCE.get(digestAlgo));

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return null;
        }

        public OutputStream getOutputStream() {
            return os;
        }

        public boolean verify(byte[] expected) {
            byte[] clientCertDigest = new byte[digest.getDigestSize()];
            digest.doFinal(clientCertDigest, 0);
            // System.out.println("Verify: "+ Hex.toHexString(clientCertDigest));
            signer.init(false, pubParams);
            signer.update(clientCertDigest, 0, clientCertDigest.length);
            // 
            if (parentTBSDigest != null && Arrays.areEqual(clientCertDigest, parentTBSDigest)) {
                byte[] empty = new byte[digest.getDigestSize()];
                digest.doFinal(empty, 0);
                // System.out.println("Empty: "+Hex.toHexString(empty));
                signer.update(empty, 0, empty.length);
            } else {
                signer.update(parentDigest, 0, parentDigest.length);
            }
            return signer.verifySignature(expected);
        }
    };
}
Also used : DSADigestSigner(com.github.zhenwei.core.crypto.signers.DSADigestSigner) Digest(com.github.zhenwei.core.crypto.Digest) ECDSASigner(com.github.zhenwei.core.crypto.signers.ECDSASigner) OutputStream(java.io.OutputStream) ContentVerifier(com.github.zhenwei.pkix.operator.ContentVerifier) OperatorCreationException(com.github.zhenwei.pkix.operator.OperatorCreationException)

Example 3 with DSADigestSigner

use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.

the class BcECContentVerifierProviderBuilder method createSigner.

protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException {
    AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
    Digest dig = digestProvider.get(digAlg);
    return new DSADigestSigner(new ECDSASigner(), dig);
}
Also used : DSADigestSigner(com.github.zhenwei.core.crypto.signers.DSADigestSigner) Digest(com.github.zhenwei.core.crypto.Digest) ECDSASigner(com.github.zhenwei.core.crypto.signers.ECDSASigner) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 4 with DSADigestSigner

use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.

the class BcDSAContentVerifierProviderBuilder method createSigner.

protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException {
    AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
    Digest dig = digestProvider.get(digAlg);
    return new DSADigestSigner(new DSASigner(), dig);
}
Also used : DSASigner(com.github.zhenwei.core.crypto.signers.DSASigner) DSADigestSigner(com.github.zhenwei.core.crypto.signers.DSADigestSigner) Digest(com.github.zhenwei.core.crypto.Digest) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Aggregations

DSADigestSigner (com.github.zhenwei.core.crypto.signers.DSADigestSigner)4 Digest (com.github.zhenwei.core.crypto.Digest)3 ECDSASigner (com.github.zhenwei.core.crypto.signers.ECDSASigner)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 DSASigner (com.github.zhenwei.core.crypto.signers.DSASigner)1 ContentVerifier (com.github.zhenwei.pkix.operator.ContentVerifier)1 OperatorCreationException (com.github.zhenwei.pkix.operator.OperatorCreationException)1 OutputStream (java.io.OutputStream)1