Search in sources :

Example 6 with DnssecValidationFailedException

use of org.minidns.dnssec.DnssecValidationFailedException in project minidns by MiniDNS.

the class ECDSASignatureVerifier method getPublicKey.

@Override
protected PublicKey getPublicKey(byte[] key) {
    DataInput dis = new DataInputStream(new ByteArrayInputStream(key));
    try {
        byte[] xBytes = new byte[length];
        dis.readFully(xBytes);
        BigInteger x = new BigInteger(1, xBytes);
        byte[] yBytes = new byte[length];
        dis.readFully(yBytes);
        BigInteger y = new BigInteger(1, yBytes);
        return getKeyFactory().generatePublic(new ECPublicKeySpec(new ECPoint(x, y), spec));
    } catch (IOException | InvalidKeySpecException e) {
        throw new DNSSECValidationFailedException("Invalid public key!", e);
    }
}
Also used : DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DNSSECValidationFailedException(org.minidns.dnssec.DNSSECValidationFailedException) BigInteger(java.math.BigInteger) IOException(java.io.IOException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DataInputStream(java.io.DataInputStream) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec)

Example 7 with DnssecValidationFailedException

use of org.minidns.dnssec.DnssecValidationFailedException in project minidns by MiniDNS.

the class ECGOSTSignatureVerifier method getPublicKey.

@Override
protected PublicKey getPublicKey(byte[] key) {
    DataInput dis = new DataInputStream(new ByteArrayInputStream(key));
    try {
        byte[] xBytes = new byte[LENGTH];
        dis.readFully(xBytes);
        reverse(xBytes);
        BigInteger x = new BigInteger(1, xBytes);
        byte[] yBytes = new byte[LENGTH];
        dis.readFully(yBytes);
        reverse(yBytes);
        BigInteger y = new BigInteger(1, yBytes);
        return getKeyFactory().generatePublic(new ECPublicKeySpec(new ECPoint(x, y), SPEC));
    } catch (IOException | InvalidKeySpecException e) {
        throw new DNSSECValidationFailedException("Invalid public key!", e);
    }
}
Also used : DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DNSSECValidationFailedException(org.minidns.dnssec.DNSSECValidationFailedException) BigInteger(java.math.BigInteger) IOException(java.io.IOException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DataInputStream(java.io.DataInputStream) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec)

Example 8 with DnssecValidationFailedException

use of org.minidns.dnssec.DnssecValidationFailedException in project Smack by igniterealtime.

the class DnsOverXmppMiniDnsResolverTest method dnsOverXmppMiniDnsResolverTest.

@Test
public void dnsOverXmppMiniDnsResolverTest() throws IOException {
    TestDnsDataSource dnsSource = new TestDnsDataSource();
    TestDnsDataSource dnssecSource = new TestDnsDataSource();
    DnsClient dnsClient = new DnsClient(NoopDnsCache.INSTANCE);
    dnsClient.setDataSource(dnsSource);
    DnssecClient dnssecClient = new DnssecClient(NoopDnsCache.INSTANCE);
    dnssecClient.setDataSource(dnssecSource);
    DnsOverXmppMiniDnsResolver doxResolver = new DnsOverXmppMiniDnsResolver(dnsClient, dnssecClient);
    Question question = new Question("example.org", TYPE.A);
    {
        DnsMessage nondnssecQuery = question.asQueryMessage();
        doxResolver.resolve(nondnssecQuery);
        assertTrue(dnsSource.getAndResetWasQueried());
        assertFalse(dnssecSource.getAndResetWasQueried());
    }
    {
        DnsMessage.Builder dnssecQueryBuilder = question.asMessageBuilder();
        dnssecQueryBuilder.getEdnsBuilder().setDnssecOk();
        DnsMessage dnssecQuery = dnssecQueryBuilder.build();
        DnssecValidationFailedException dnssecValidationFailedException = null;
        try {
            doxResolver.resolve(dnssecQuery);
        } catch (DnssecValidationFailedException e) {
            dnssecValidationFailedException = e;
        }
        // This exception is expected since we don't have a realy DNS source.
        assertNotNull(dnssecValidationFailedException);
        assertFalse(dnsSource.getAndResetWasQueried());
        assertTrue(dnssecSource.getAndResetWasQueried());
    }
}
Also used : DnssecClient(org.minidns.dnssec.DnssecClient) DnssecValidationFailedException(org.minidns.dnssec.DnssecValidationFailedException) DnsClient(org.minidns.DnsClient) Question(org.minidns.dnsmessage.Question) DnsMessage(org.minidns.dnsmessage.DnsMessage) Test(org.junit.jupiter.api.Test)

Aggregations

DNSSECValidationFailedException (org.minidns.dnssec.DNSSECValidationFailedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInput (java.io.DataInput)6 DataInputStream (java.io.DataInputStream)6 IOException (java.io.IOException)6 BigInteger (java.math.BigInteger)4 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)4 ECPoint (java.security.spec.ECPoint)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)2 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 Signature (java.security.Signature)1 SignatureException (java.security.SignatureException)1 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 Test (org.junit.jupiter.api.Test)1 DnsClient (org.minidns.DnsClient)1