Skip to content

Commit

Permalink
Run the Prettier code formatter
Browse files Browse the repository at this point in the history
> prettier --write $(git ls-files)
  • Loading branch information
jablko committed Jul 17, 2019
1 parent 380f62b commit a85463e
Show file tree
Hide file tree
Showing 12 changed files with 1,388 additions and 800 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dist: trusty
language: node_js

node_js:
- "8"
- '8'
env:
- TASK=test
- TASK=lint
Expand Down
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
# DNSSEC Oracle

[![Build Status](https://travis-ci.org/ensdomains/dnssec-oracle.svg?branch=master)](https://travis-ci.org/ensdomains/dnssec-oracle) [![License](https://img.shields.io/badge/License-BSD--2--Clause-blue.svg)](LICENSE)
[![Build Status](https://travis-ci.org/ensdomains/dnssec-oracle.svg?branch=master)](https://travis-ci.org/ensdomains/dnssec-oracle)
[![License](https://img.shields.io/badge/License-BSD--2--Clause-blue.svg)](LICENSE)

This is an implementation of a DNSSEC oracle for Ethereum. With it, you can securely prove the contents of any DNSSEC-signed DNS record on the Ethereum blockchain, as long as it was signed using supported public key schemes and digests. Presently, the oracle only supports RSA and SHA-256; fortunately, over 3/4 of TLDs use this combination of algorithms.
This is an implementation of a DNSSEC oracle for Ethereum. With it, you
can securely prove the contents of any DNSSEC-signed DNS record on the
Ethereum blockchain, as long as it was signed using supported public key
schemes and digests. Presently, the oracle only supports RSA and
SHA-256; fortunately, over 3/4 of TLDs use this combination of
algorithms.

Once a record is proven to the oracle, any contract or external caller can fetch it with the `rrsets` constant function, allowing other contracts to read data from DNS.
Once a record is proven to the oracle, any contract or external caller
can fetch it with the `rrsets` constant function, allowing other
contracts to read data from DNS.

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
These instructions will get you a copy of the project up and running on
your local machine for development and testing purposes.

### Installing

The DNSSEC Oracle uses npm to manage dependencies, therefore the installation process is kept simple:
The DNSSEC Oracle uses npm to manage dependencies, therefore the
installation process is kept simple:

```
npm install
```

### Running tests

The DNSSEC Oracle uses truffle for its ethereum development environment. All tests can be run using truffle:
The DNSSEC Oracle uses truffle for its ethereum development environment.
All tests can be run using truffle:

```
truffle test
Expand Down Expand Up @@ -52,24 +63,33 @@ import "dnssec-oracle/build/contracts/DNSSEC"
var data = require("dnssec-oracle/build/contracts/DNSSEC.json")
```

The JSON file is same as the one generated using `truffle compile`. You can pass the loaded data to `truffle-contract` or use it via web3 by passing `data.abi`.
The JSON file is same as the one generated using `truffle compile`. You
can pass the loaded data to `truffle-contract` or use it via web3 by
passing `data.abi`.

### Usage

A [command line utility](https://github.com/arachnid/dnsprove) is available that automates the task of generating the necessary proofs from DNS data and submitting them to the oracle.
A [command line utility](https://github.com/arachnid/dnsprove) is
available that automates the task of generating the necessary proofs
from DNS data and submitting them to the oracle.

The oracle is still in alpha, and does not yet have any official deployments on the main network or test networks.
The oracle is still in alpha, and does not yet have any official
deployments on the main network or test networks.

## Built With
* [Truffle](https://github.com/trufflesuite/truffle) - Ethereum development environment

- [Truffle](https://github.com/trufflesuite/truffle) - Ethereum
development environment

## Authors

* **Nick Johnson** - [Arachnid](https://github.com/Arachnid)
- **Nick Johnson** - [Arachnid](https://github.com/Arachnid)

See also the list of [contributors](https://github.com/ensdomains/dnssec-oracle/contributors) who participated in this project.
See also the list of
[contributors](https://github.com/ensdomains/dnssec-oracle/contributors)
who participated in this project.

## License

This project is licensed under the BSD 2-clause "Simplified" License - see the [LICENSE](LICENSE) file for details
This project is licensed under the BSD 2-clause "Simplified" License -
see the [LICENSE](LICENSE) file for details
81 changes: 46 additions & 35 deletions lib/anchors.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
const packet = require('dns-packet');

exports.realEntries = [
{
name: ".",
type: 'DS',
class: 'IN',
ttl: 3600,
data:{
keyTag: 19036,
algorithm: 8,
digestType: 2,
digest: new Buffer("49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5", "hex")
}
},
{
name: ".",
type: 'DS',
klass: 'IN',
ttl: 3600,
data:{
keyTag: 20326,
algorithm: 8,
digestType: 2,
digest: new Buffer("E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D", "hex")
}
},
];

{
name: '.',
type: 'DS',
class: 'IN',
ttl: 3600,
data: {
keyTag: 19036,
algorithm: 8,
digestType: 2,
digest: new Buffer(
'49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5',
'hex'
)
}
},
{
name: '.',
type: 'DS',
klass: 'IN',
ttl: 3600,
data: {
keyTag: 20326,
algorithm: 8,
digestType: 2,
digest: new Buffer(
'E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D',
'hex'
)
}
}
];

exports.dummyEntry = {
name: ".",
name: '.',
type: 'DS',
class: 'IN',
ttl: 3600,
data:{
data: {
keyTag: 5647, // Empty body, flags == 0x0101, algorithm = 253, body = 0x1111
algorithm: 253,
digestType: 253,
digest: new Buffer("", "hex")
digest: new Buffer('', 'hex')
}
}
};

exports.encode = (anchors) =>{
return '0x' + anchors.map((anchor)=>{
return packet.answer.encode(anchor).toString('hex')
}).join('')
}
exports.encode = anchors => {
return (
'0x' +
anchors
.map(anchor => {
return packet.answer.encode(anchor).toString('hex');
})
.join('')
);
};
2 changes: 1 addition & 1 deletion migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Migrations = artifacts.require("./Migrations.sol");
var Migrations = artifacts.require('./Migrations.sol');

module.exports = function(deployer) {
deployer.deploy(Migrations);
Expand Down
113 changes: 56 additions & 57 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
const RSASHA1Algorithm = artifacts.require("./algorithms/RSASHA1Algorithm");
const RSASHA256Algorithm = artifacts.require("./algorithms/RSASHA256Algorithm");
const SHA1Digest = artifacts.require("./digests/SHA1Digest");
const SHA256Digest = artifacts.require("./digests/SHA256Digest");
const SHA1NSEC3Digest = artifacts.require("./nsec3digests/SHA1NSEC3Digest");
const DNSSEC = artifacts.require("./DNSSECImpl");
const DummyAlgorithm = artifacts.require("./algorithms/DummyAlgorithm");
const DummyDigest = artifacts.require("./digests/DummyDigest");
const P256SHA256Algorithm = artifacts.require("P256SHA256Algorithm.sol");
const EllipticCurve = artifacts.require("EllipticCurve.sol");

const dnsAnchors = require("../lib/anchors.js");
const RSASHA1Algorithm = artifacts.require('./algorithms/RSASHA1Algorithm');
const RSASHA256Algorithm = artifacts.require('./algorithms/RSASHA256Algorithm');
const SHA1Digest = artifacts.require('./digests/SHA1Digest');
const SHA256Digest = artifacts.require('./digests/SHA256Digest');
const SHA1NSEC3Digest = artifacts.require('./nsec3digests/SHA1NSEC3Digest');
const DNSSEC = artifacts.require('./DNSSECImpl');
const DummyAlgorithm = artifacts.require('./algorithms/DummyAlgorithm');
const DummyDigest = artifacts.require('./digests/DummyDigest');
const P256SHA256Algorithm = artifacts.require('P256SHA256Algorithm.sol');
const EllipticCurve = artifacts.require('EllipticCurve.sol');

const dnsAnchors = require('../lib/anchors.js');

module.exports = function(deployer, network) {
return deployer.then(async () => {
let dev = (network == "test" || network == "local");
// From http://data.iana.org/root-anchors/root-anchors.xml
let anchors = dnsAnchors.realEntries;
return deployer.then(async () => {
let dev = network == 'test' || network == 'local';
// From http://data.iana.org/root-anchors/root-anchors.xml
let anchors = dnsAnchors.realEntries;

if (dev) {
anchors.push(dnsAnchors.dummyEntry);
}
await deployer.deploy(DNSSEC, dnsAnchors.encode(anchors));
if (dev) {
anchors.push(dnsAnchors.dummyEntry);
}
await deployer.deploy(DNSSEC, dnsAnchors.encode(anchors));

await deployer.deploy(RSASHA256Algorithm);
await deployer.deploy(RSASHA1Algorithm);
await deployer.deploy(SHA256Digest);
await deployer.deploy(SHA1Digest);
await deployer.deploy(SHA1NSEC3Digest);
await deployer.deploy(RSASHA256Algorithm);
await deployer.deploy(RSASHA1Algorithm);
await deployer.deploy(SHA256Digest);
await deployer.deploy(SHA1Digest);
await deployer.deploy(SHA1NSEC3Digest);

await deployer.deploy(EllipticCurve);
await deployer.deploy(EllipticCurve);

let curve = await EllipticCurve.deployed()
await deployer.deploy(P256SHA256Algorithm, curve.address)
let curve = await EllipticCurve.deployed();
await deployer.deploy(P256SHA256Algorithm, curve.address);

if (dev) {
await deployer.deploy(DummyAlgorithm);
await deployer.deploy(DummyDigest);
}

if (dev) {
await deployer.deploy(DummyAlgorithm)
await deployer.deploy(DummyDigest)
}
let tasks = [];

let tasks = [];
const dnssec = await DNSSEC.deployed();

const dnssec = await DNSSEC.deployed();
const rsasha1 = await RSASHA1Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(5, rsasha1.address));
tasks.push(dnssec.setAlgorithm(7, rsasha1.address));

const rsasha1 = await RSASHA1Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(5, rsasha1.address));
tasks.push(dnssec.setAlgorithm(7, rsasha1.address));
const rsasha256 = await RSASHA256Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(8, rsasha256.address));

const rsasha256 = await RSASHA256Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(8, rsasha256.address));
const sha1 = await SHA1Digest.deployed();
tasks.push(dnssec.setDigest(1, sha1.address));

const sha1 = await SHA1Digest.deployed();
tasks.push(dnssec.setDigest(1, sha1.address));
const sha256 = await SHA256Digest.deployed();
tasks.push(dnssec.setDigest(2, sha256.address));

const sha256 = await SHA256Digest.deployed();
tasks.push(dnssec.setDigest(2, sha256.address));
const nsec3sha1 = await SHA1NSEC3Digest.deployed();
tasks.push(dnssec.setNSEC3Digest(1, nsec3sha1.address));

const nsec3sha1 = await SHA1NSEC3Digest.deployed();
tasks.push(dnssec.setNSEC3Digest(1, nsec3sha1.address));
const p256 = await P256SHA256Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(13, p256.address));

const p256 = await P256SHA256Algorithm.deployed();
tasks.push(dnssec.setAlgorithm(13, p256.address));
if (dev) {
const dummyalgorithm = await DummyAlgorithm.deployed();
tasks.push(dnssec.setAlgorithm(253, dummyalgorithm.address));
tasks.push(dnssec.setAlgorithm(254, dummyalgorithm.address));

if (dev) {
const dummyalgorithm = await DummyAlgorithm.deployed();
tasks.push(dnssec.setAlgorithm(253, dummyalgorithm.address));
tasks.push(dnssec.setAlgorithm(254, dummyalgorithm.address));
const dummydigest = await DummyDigest.deployed();
tasks.push(dnssec.setDigest(253, dummydigest.address));
}

const dummydigest = await DummyDigest.deployed();
tasks.push(dnssec.setDigest(253, dummydigest.address));
}

await Promise.all(tasks)
});
await Promise.all(tasks);
});
};
33 changes: 19 additions & 14 deletions test/TestAlgorithms.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
const algorithms = require("./data/algorithms");
const algorithms = require('./data/algorithms');

algorithms.forEach(function ([algo, vector]) {
contract(algo, function (accounts) {
algorithms.forEach(function([algo, vector]) {
contract(algo, function(accounts) {
const algorithm = artifacts.require('./algorithms/' + algo + '.sol');

const algorithm = artifacts.require("./algorithms/" + algo + ".sol");
it('should return true for valid signatures', async function() {
var instance = await algorithm.deployed();

it('should return true for valid signatures', async function() {
var instance = await algorithm.deployed();

assert.equal(await instance.verify(vector[0], vector[1], vector[2]), true);
});
assert.equal(
await instance.verify(vector[0], vector[1], vector[2]),
true
);
});

it('should return false for invalid signatures', async function() {
var instance = await algorithm.deployed();
it('should return false for invalid signatures', async function() {
var instance = await algorithm.deployed();

vector[1] = vector[1] + "00";
assert.equal(await instance.verify(vector[0], vector[1], vector[2]), false);
});
vector[1] = vector[1] + '00';
assert.equal(
await instance.verify(vector[0], vector[1], vector[2]),
false
);
});
});
});
Loading

0 comments on commit a85463e

Please sign in to comment.