2017-10-14 18:29:23 -05:00
|
|
|
# Nearenough
|
|
|
|
|
|
|
|
[](https://www.apache.org/licenses/LICENSE-2.0.txt)
|
|
|
|
[](https://travis-ci.org/int08h/nearenough)
|
|
|
|
|
2017-02-10 10:00:06 -06:00
|
|
|
**Nearenough** is a Java client of the [Roughtime](https://roughtime.googlesource.com/roughtime)
|
|
|
|
secure time synchronization protocol.
|
2017-01-25 12:36:31 -06:00
|
|
|
|
2017-02-07 17:28:14 -06:00
|
|
|
Nearenough aims to be 100% interoperable with the wider Roughtime ecosystem.
|
|
|
|
|
|
|
|
## About the Roughtime Protocol
|
2017-01-26 15:53:00 -06:00
|
|
|
[Roughtime](https://roughtime.googlesource.com/roughtime) is a protocol that aims to achieve rough
|
2017-01-25 12:36:31 -06:00
|
|
|
time synchronisation in a secure way that doesn't depend on any particular time server, and in such
|
|
|
|
a way that, if a time server does misbehave, clients end up with cryptographic proof of it. It was
|
|
|
|
created by Adam Langley and Robert Obryk.
|
2017-01-20 12:12:45 -06:00
|
|
|
|
2018-02-17 18:53:01 -06:00
|
|
|
## Resources
|
2017-01-20 17:48:42 -06:00
|
|
|
* [Nearenough Github repo](https://github.com/int08h/nearenough)
|
|
|
|
* [Roughtime project](https://roughtime.googlesource.com/roughtime)
|
2017-04-28 22:02:58 -05:00
|
|
|
* My blog posts [describing Roughtime features](https://int08h.com/post/to-catch-a-lying-timeserver/) and
|
|
|
|
exploring the [Nearenough API and details of Roughtime messages](https://int08h.com/post/roughtime-message-anatomy/).
|
2018-02-17 18:53:01 -06:00
|
|
|
|
|
|
|
### Public int08h.com Roughtime Server
|
|
|
|
|
|
|
|
A publicly accessible Roughtime server is available at `roughtime.int08h.com` port `2002`. The
|
|
|
|
server's long-term public key is `016e6e0284d24c37c6e4d7d8d5b4e1d3c1949ceaa545bf875616c9dce0c9bec1`
|
|
|
|
and can verified by querying the server's DNS `TXT` record:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ dig -t txt roughtime.int08h.com
|
|
|
|
...
|
|
|
|
;; ANSWER SECTION:
|
|
|
|
roughtime.int08h.com. 1799 IN TXT "016e6e0284d24c37c6e4d7d8d5b4e1d3c1949ceaa545bf875616c9dce0c9bec1"
|
|
|
|
```
|
2017-01-20 17:48:42 -06:00
|
|
|
|
|
|
|
## Building
|
2018-01-27 21:21:17 -06:00
|
|
|
Gradle is used to build Nearenough. Run the tests:
|
2018-01-27 21:20:49 -06:00
|
|
|
|
|
|
|
```bash
|
2018-01-27 21:21:17 -06:00
|
|
|
$ ./gradlew test
|
2018-01-27 21:20:49 -06:00
|
|
|
```
|
|
|
|
|
2018-01-27 21:21:17 -06:00
|
|
|
And the examples:
|
2018-01-27 21:20:49 -06:00
|
|
|
|
|
|
|
```bash
|
2018-01-27 21:21:17 -06:00
|
|
|
$ ./gradlew nioExample
|
|
|
|
# or
|
2018-01-27 21:20:49 -06:00
|
|
|
$ ./gradlew nettyExample
|
|
|
|
```
|
2017-01-20 17:48:42 -06:00
|
|
|
|
2017-02-10 10:00:06 -06:00
|
|
|
## Quickstart
|
2017-02-06 16:21:49 -06:00
|
|
|
|
|
|
|
### Client Examples
|
2017-02-07 17:28:14 -06:00
|
|
|
See [`examples/NioClient.java`](../master/examples/NioClient.java) and
|
|
|
|
[`examples/NettyClient.java`](../master/examples/NettyClient.java) for examples of how to send a
|
|
|
|
request to a Roughtime server and process the response.
|
2017-02-06 16:21:49 -06:00
|
|
|
|
|
|
|
### DIY Client
|
|
|
|
If implementing your own client, the general idea is:
|
2017-02-01 17:55:35 -06:00
|
|
|
|
|
|
|
```java
|
|
|
|
// The RoughTime server's long term public key, must be obtained a priori
|
|
|
|
byte[] serverLongTermPublicKey = { ... };
|
|
|
|
|
|
|
|
// Create client passing the server's long-term key
|
|
|
|
RoughtimeClient client = new RoughtimeClient(serverLongTermPublicKey);
|
|
|
|
|
|
|
|
// Construct a request, then encode it for transmission
|
|
|
|
RtMessage request = client.createRequest();
|
|
|
|
ByteBuf encodedRequest = RtWire.toWire(request);
|
|
|
|
|
|
|
|
// send encodedRequest using NIO, Netty, or some other mechanism...
|
|
|
|
RtMessage response = // ...and receive the response via NIO, Netty, etc ...
|
|
|
|
|
|
|
|
// Process the response
|
|
|
|
client.processResponse(response);
|
|
|
|
|
|
|
|
// Check the result
|
|
|
|
if (client.isResponseValid()) {
|
|
|
|
Instant midpoint = Instant.ofEpochMilli(client.midpoint() / 1000L);
|
|
|
|
System.out.println("midpoint: " + midpoint);
|
|
|
|
} else {
|
|
|
|
System.out.println("Invalid response: " + client.invalidResponseCause().getMessage());
|
|
|
|
}
|
|
|
|
```
|
|
|
|
See the javadocs in [`RoughtimeClient.java`](../master/src/nearenough/client/RoughtimeClient.java)
|
|
|
|
for more information.
|
|
|
|
|
2017-01-20 17:48:42 -06:00
|
|
|
## Implementation Status
|
2017-02-10 10:00:06 -06:00
|
|
|
Nearenough is stable.
|
2017-02-01 17:55:35 -06:00
|
|
|
|
2017-02-10 10:00:06 -06:00
|
|
|
* Protocol - Client protocol is feature complete.
|
2017-02-07 17:28:14 -06:00
|
|
|
* Client - Feature complete except for ecosystem-style request chaining.
|
2017-01-20 13:43:12 -06:00
|
|
|
|
2017-01-20 17:48:42 -06:00
|
|
|
## Contributors
|
2017-02-07 11:37:36 -06:00
|
|
|
* Stuart Stock, original author and current maintainer (stuart {at} int08h.com)
|
2017-01-20 12:12:45 -06:00
|
|
|
|
2017-02-10 10:00:06 -06:00
|
|
|
If you would like to contribute to Nearenough, please see the guidelines in
|
2017-02-07 21:23:15 -06:00
|
|
|
[CONTRIBUTING.md](../master/CONTRIBUTING.md).
|
|
|
|
|
2017-01-20 17:48:42 -06:00
|
|
|
## Copyright and License
|
2018-01-27 21:20:49 -06:00
|
|
|
Nearenough is Copyright (c) 2017-2018 int08h LLC. All rights reserved.
|
2017-01-20 12:12:45 -06:00
|
|
|
|
2017-01-31 11:08:52 -06:00
|
|
|
int08h LLC licenses Nearenough (the "Software") to you under the Apache License, version 2.0
|
|
|
|
(the "License"); you may not use this Software except in compliance with the License. You may obtain
|
|
|
|
a copy of the License from the [LICENSE](../master/LICENSE) file included with the Software or at:
|
2017-01-20 12:12:45 -06:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
the License.
|