Skip to content

Commit

Permalink
Merge branch 'master' into fragmented_ntske_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thekuwayama committed Aug 1, 2019
2 parents 3e79c50 + 0291e80 commit e2cabc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sudo: false

language: ruby

rvm:
- 2.6.3
- ruby-head

matrix:
allow_failures:
- rvm: ruby-head

before_install:
- gem install bundler
- bundle install

script: bundle exec rake
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# simple_nts_client

[![Build Status](https://travis-ci.org/thekuwayama/simple_nts_client.svg?branch=master)](https://travis-ci.org/thekuwayama/simple_nts_client)
[![Maintainability](https://api.codeclimate.com/v1/badges/7b34a4868f1e297af084/maintainability)](https://codeclimate.com/github/thekuwayama/simple_nts_client/maintainability)

`simple_nts_client` is CLI that is simple NTS(Network Time Security) Client implementation.

https://tools.ietf.org/html/draft-ietf-ntp-using-nts-for-ntp-19
Expand All @@ -21,10 +24,11 @@ $ bundle exec exe/simple_nts_client
## Usage

```bash
$ bundle exec exe/simple_nts_client -help
$ bundle exec exe/simple_nts_client --help
Usage: simple_nts_client [options]
-s, --server VALUE NTS-KE server name (default time.cloudflare.com)
-p, --port VALUE NTS-KE port number (default 1234)
-v, --verbose verbose mode (default false)
```

You can run it the following:
Expand Down
28 changes: 25 additions & 3 deletions lib/nts/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

module Nts
class CLI
# rubocop: disable Metrics/MethodLength
def parse_options(argv = ARGV)
op = OptionParser.new

# default value
opts = {
server: 'time.cloudflare.com',
port: 1234
port: 1234,
verbose: false
}

op.on(
Expand All @@ -29,6 +31,14 @@ def parse_options(argv = ARGV)
opts[:port] = v
end

op.on(
'-v',
'--verbose',
"verbose mode (default #{opts[:verbose]})"
) do |v|
opts[:verbose] = v
end

begin
op.parse(argv)
rescue OptionParser::InvalidOption => e
Expand All @@ -39,18 +49,30 @@ def parse_options(argv = ARGV)

opts
end
# rubocop: enable Metrics/MethodLength

def run
opts = parse_options

# NTS-KE
ntske_client = Ntske::Client.new(opts[:server], opts[:port])
hostname, ntp_port, cookies, c2s_key, s2c_key = ntske_client.key_establish
hostname ||= opts[:server]
ntp_port ||= 123

# verbose mode
if opts[:verbose]
puts "# NTPv4 Server => #{hostname}"
puts "# NTPv4 Port => #{ntp_port}"
puts "# Cookie for NTPv4(hex) => #{cookies.first.unpack1('H*')}"
puts "# client-to-server(hex) => #{c2s_key.unpack1('H*')}"
puts "# server-to-client(hex) => #{s2c_key.unpack1('H*')}"
end

# NTS protected NTP
ntp_client = Nts::Sntp::Client.new(
hostname || opts[:server],
ntp_port || 123,
hostname,
ntp_port,
cookies.first,
c2s_key,
s2c_key
Expand Down

0 comments on commit e2cabc1

Please sign in to comment.