Search in sources :

Example 41 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class X509V2AttributeCertificate method verify.

public final void verify(PublicKey key, String provider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    Signature signature = null;
    if (!cert.getSignatureAlgorithm().equals(cert.getAcinfo().getSignature())) {
        throw new CertificateException("Signature algorithm in certificate info not same as outer certificate");
    }
    signature = Signature.getInstance(cert.getSignatureAlgorithm().getObjectId().getId(), provider);
    signature.initVerify(key);
    try {
        signature.update(cert.getAcinfo().getEncoded());
    } catch (IOException e) {
        throw new SignatureException("Exception encoding certificate info object");
    }
    if (!signature.verify(this.getSignature())) {
        throw new InvalidKeyException("Public key presented not for certificate signature");
    }
}
Also used : Signature(java.security.Signature) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 42 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class X509CertificateObject method verify.

public final void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    Signature signature;
    String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
    try {
        signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
    } catch (Exception e) {
        signature = Signature.getInstance(sigName);
    }
    checkSignature(key, signature);
}
Also used : Signature(java.security.Signature) DERBitString(org.bouncycastle.asn1.DERBitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1String(org.bouncycastle.asn1.ASN1String) CertificateExpiredException(java.security.cert.CertificateExpiredException) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CertificateEncodingException(java.security.cert.CertificateEncodingException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 43 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class SignatureSpiTest method testEngineSign_BII.

public void testEngineSign_BII() {
    MySignature signature = new MySignature("dummy");
    try {
        signature.initSign(new PrivateKey() {

            public String getFormat() {
                return null;
            }

            public byte[] getEncoded() {
                return null;
            }

            public String getAlgorithm() {
                return null;
            }
        });
    } catch (InvalidKeyException e) {
        fail("unexpected exception: " + e);
    }
    byte[] buf = new byte[10];
    try {
        signature.sign(buf, 2, 1);
        assertTrue("SPI method not called", signature.wasMethodCalled("engineSign_[BII"));
    } catch (SignatureException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : PrivateKey(java.security.PrivateKey) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 44 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class SignatureSpiTest method testEngineVerify_BII.

public void testEngineVerify_BII() {
    MySignature signature = new MySignature("dummy");
    try {
        signature.initVerify(new PublicKey() {

            public String getFormat() {
                return null;
            }

            public byte[] getEncoded() {
                return null;
            }

            public String getAlgorithm() {
                return null;
            }
        });
    } catch (InvalidKeyException e) {
        fail("unexpected exception");
    }
    byte[] buf = new byte[10];
    try {
        signature.verify(buf, 2, 5);
        signature.wasMethodCalled("engineVerify_[BII");
    } catch (SignatureException e) {
        fail("unexpected exception");
    }
}
Also used : PublicKey(java.security.PublicKey) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 45 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class SignatureTest method testUpdatebyte.

/*
     * Class under test for void update(byte)
     */
public void testUpdatebyte() throws Exception {
    MySignature1 s = new MySignature1("ABC");
    try {
        s.update((byte) 1);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initVerify(new MyPublicKey());
    s.update((byte) 1);
    s.initSign(new MyPrivateKey());
    s.update((byte) 1);
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("update() failed", s.runEngineUpdate1);
    try {
        Signature sig = getTestSignature();
        sig.update((byte) 42);
        fail("expected SignatureException");
    } catch (SignatureException e) {
    // ok
    }
}
Also used : Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) SignatureException(java.security.SignatureException)

Aggregations

SignatureException (java.security.SignatureException)329 InvalidKeyException (java.security.InvalidKeyException)171 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)132 Signature (java.security.Signature)132 IOException (java.io.IOException)75 PublicKey (java.security.PublicKey)53 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)39 X509Certificate (java.security.cert.X509Certificate)33 BigInteger (java.math.BigInteger)32 CertificateException (java.security.cert.CertificateException)31 NoSuchProviderException (java.security.NoSuchProviderException)29 PrivateKey (java.security.PrivateKey)25 ByteArrayInputStream (java.io.ByteArrayInputStream)17 KeyFactory (java.security.KeyFactory)15 ArrayList (java.util.ArrayList)15 MySignature1 (org.apache.harmony.security.tests.support.MySignature1)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)12 GeneralSecurityException (java.security.GeneralSecurityException)12 MessageDigest (java.security.MessageDigest)12