Search in sources :

Example 61 with Signature

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

the class CertificationRequest method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    v.add(certificationRequestInfo);
    v.add(signatureAlgorithm);
    v.add(signature);
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 62 with Signature

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

the class CVCertificate method toASN1Primitive.

/**
 * @see com.github.zhenwei.core.asn1.ASN1Object#toASN1Primitive()
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(2);
    v.add(certificateBody);
    try {
        v.add(new DERApplicationSpecific(false, EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP, new DEROctetString(signature)));
    } catch (IOException e) {
        throw new IllegalStateException("unable to convert signature!");
    }
    return new DERApplicationSpecific(EACTags.CARDHOLDER_CERTIFICATE, v);
}
Also used : DERApplicationSpecific(com.github.zhenwei.core.asn1.DERApplicationSpecific) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) IOException(java.io.IOException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Example 63 with Signature

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

the class CVCertificate method setPrivateData.

/**
 * Sets the values of the certificate (body and signature).
 *
 * @param appSpe is a ASN1ApplicationSpecific object containing body and signature.
 * @throws IOException if tags or value are incorrect.
 */
private void setPrivateData(ASN1ApplicationSpecific appSpe) throws IOException {
    valid = 0;
    if (appSpe.getApplicationTag() == EACTags.CARDHOLDER_CERTIFICATE) {
        ASN1InputStream content = new ASN1InputStream(appSpe.getContents());
        ASN1Primitive tmpObj;
        while ((tmpObj = content.readObject()) != null) {
            ASN1ApplicationSpecific aSpe;
            if (tmpObj instanceof ASN1ApplicationSpecific) {
                aSpe = (ASN1ApplicationSpecific) tmpObj;
                switch(aSpe.getApplicationTag()) {
                    case EACTags.CERTIFICATE_CONTENT_TEMPLATE:
                        certificateBody = CertificateBody.getInstance(aSpe);
                        valid |= bodyValid;
                        break;
                    case EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP:
                        signature = aSpe.getContents();
                        valid |= signValid;
                        break;
                    default:
                        throw new IOException("Invalid tag, not an Iso7816CertificateStructure :" + aSpe.getApplicationTag());
                }
            } else {
                throw new IOException("Invalid Object, not an Iso7816CertificateStructure");
            }
        }
        content.close();
    } else {
        throw new IOException("not a CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
    }
    if (valid != (signValid | bodyValid)) {
        throw new IOException("invalid CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
    }
}
Also used : ASN1InputStream(com.github.zhenwei.core.asn1.ASN1InputStream) ASN1ApplicationSpecific(com.github.zhenwei.core.asn1.ASN1ApplicationSpecific) IOException(java.io.IOException) ASN1Primitive(com.github.zhenwei.core.asn1.ASN1Primitive)

Example 64 with Signature

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

the class SignatureSpiLe method engineVerify.

protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
    byte[] bytes = null;
    try {
        bytes = ((ASN1OctetString) ASN1OctetString.fromByteArray(sigBytes)).getOctets();
    } catch (IOException e) {
        throw new SignatureException("error decoding signature bytes.");
    }
    reverseBytes(bytes);
    try {
        return super.engineVerify((new DEROctetString(bytes)).getEncoded());
    } catch (SignatureException e) {
        throw e;
    } catch (Exception e) {
        throw new SignatureException(e.toString());
    }
}
Also used : IOException(java.io.IOException) SignatureException(java.security.SignatureException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) SignatureException(java.security.SignatureException) IOException(java.io.IOException)

Example 65 with Signature

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

the class PKCS10CertificationRequest method verify.

/**
 * verify the request using the passed in public key and the provider..
 */
public boolean verify(PublicKey pubKey, String provider) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException {
    Signature sig;
    try {
        if (provider == null) {
            sig = Signature.getInstance(getSignatureName(sigAlgId));
        } else {
            sig = Signature.getInstance(getSignatureName(sigAlgId), provider);
        }
    } catch (NoSuchAlgorithmException e) {
        // 
        if (oids.get(sigAlgId.getAlgorithm()) != null) {
            String signatureAlgorithm = (String) oids.get(sigAlgId.getAlgorithm());
            if (provider == null) {
                sig = Signature.getInstance(signatureAlgorithm);
            } else {
                sig = Signature.getInstance(signatureAlgorithm, provider);
            }
        } else {
            throw e;
        }
    }
    setSignatureParameters(sig, sigAlgId.getParameters());
    sig.initVerify(pubKey);
    try {
        sig.update(reqInfo.getEncoded(ASN1Encoding.DER));
    } catch (Exception e) {
        throw new SignatureException("exception encoding TBS cert request - " + e);
    }
    return sig.verify(sigBits.getOctets());
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DERBitString(com.github.zhenwei.core.asn1.DERBitString) SignatureException(java.security.SignatureException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) GeneralSecurityException(java.security.GeneralSecurityException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

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