Skip to content

Commit

Permalink
removal of ACE, doc updates, src format updates, and new generic-main…
Browse files Browse the repository at this point in the history
… function WIP.
  • Loading branch information
EskoDijk committed Jun 26, 2024
1 parent 8ce105c commit 7fe2960
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
package-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Bootstrap
run: script/bootstrap.sh
- name: Package
Expand Down
17 changes: 5 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Compiled class file
# Compiled class files
*.class

# Log file
# Log files
*.log
logs

Expand All @@ -11,7 +11,7 @@ logs
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
# Package Files
*.jar
*.war
*.nar
Expand All @@ -28,22 +28,15 @@ hs_err_pid*
# maven
target

# idea
# IDE files
.idea
.project
*.iml

# vscode
.vscode

.settings

# utils
# auto-generated config files
Californium.properties
thread-registrar.iml

# Mac OS X
.DS_Store

# Thread Registrar Interface
tri
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
# Authors who wish to be recognized in this file should add themselves (or
# their employer, as appropriate).
Google Inc.
IoTconsultancy.nl
24 changes: 10 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Help us keep OpenThread open and inclusive. Please read and follow our [Code of

## Bugs

If you find a bug in the source code, you can help us by [submitting a GitHub Issue](https://github.com/openthread/ot-registrar/issues/new). Even better, you can [submit a Pull Request](#submitting-a-pull-request) with a fix.
If you find a bug in the source code, you can help us by [submitting a GitHub Issue](https://github.com/EskoDijk/ot-registrar/issues/new). Even better, you can [submit a Pull Request](#submitting-a-pull-request) with a fix.

## New features

You can request a new feature by [submitting a GitHub Issue](https://github.com/openthread/ot-registrar/issues/new).
You can request a new feature by [submitting a GitHub Issue](https://github.com/EskoDijk/ot-registrar/issues/new).

If you would like to implement a new feature, please consider the scope of the new feature:

* *Large feature*[Submit a GitHub Issue](https://github.com/openthread/ot-registrar/issues/new) with your proposal so that the community can review and provide feedback first. Early feedback helps to ensure your proposal is accepted by the community, better coordinate our efforts, and minimize duplicated work.
* *Large feature*[Submit a GitHub Issue](https://github.com/EskoDijk/ot-registrar/issues/new) with your proposal so that the community can review and provide feedback first. Early feedback helps to ensure your proposal is accepted by the community, better coordinate our efforts, and minimize duplicated work.

* *Small feature* — Can be implemented and directly [submitted as a Pull Request](#submitting-a-pull-request) without a proposal.

Expand All @@ -32,17 +32,17 @@ The OpenThread Project follows the "Fork-and-Pull" model for accepting contribut

Setup your GitHub fork and continuous integration services:

1. Fork the [OT Registrar repository](https://github.com/openthread/ot-registrar) by clicking **Fork** on the web UI.
2. Enable [Travis CI](https://travis-ci.org/) by logging into the respective service with your GitHub account and enabling your newly created fork. We use Travis CI for Linux-based continuous integration checks. All contributions must pass these checks to be accepted.
1. Fork the [OT Registrar repository](https://github.com/EskoDijk/ot-registrar) by clicking **Fork** on the web UI.
2. Enable GitHub CI by logging into your GitHub account and enabling it on your newly created fork. We use CI for Linux-based continuous integration checks. All contributions must pass these checks to be accepted.

Setup your local development environment:

```bash
# Clone your fork
git clone [email protected]:<username>/ot-registrar.git
git clone https://<username>@github.com/EskoDijk/ot-registrar.git

# Configure upstream alias
git remote add upstream git@github.com:openthread/ot-registrar.git
git remote add upstream https://<username>@github.com/EskoDijk/ot-registrar.git
```

### Submitting a pull request
Expand Down Expand Up @@ -99,11 +99,7 @@ This will open up a text editor where you can specify which commits to squash.

#### Coding conventions and style

OT Registrar uses and enforces the [Google Java Style](https://google.github.io/styleguide/javaguide.html) on all code. OT Registrar will automatically reformat the code when building the project with [maven](https://maven.apache.org). Use command `mvn com.coveo:fmt-maven-plugin:format` and `mvn com.coveo:fmt-maven-plugin:check` to explicitly reformat code and check for code-style compliance, respectively.

As part of the cleanup process, also run `mvn com.coveo:fmt-maven-plugin:check` to ensure that your code passes the baseline code style checks.

Make sure to include any code format changes in your commits.
OT Registrar does not use the [Google Java Style](https://google.github.io/styleguide/javaguide.html) at this moment. The reason is that it introduces a very narrow line width, which makes code hard to read on normal-size desktop monitors that can handle long line lengths.

#### Push and test

Expand All @@ -115,8 +111,8 @@ git checkout <branch-name>
git push origin <branch-name>
```

This will trigger the Travis Continuous Integration (CI) checks. You can view the results in the respective services. Note that the integration checks will report failures on occasion. If a failure occurs, you may try rerunning the test using the Travis web UI.
This will trigger Github Continuous Integration (CI) checks. You can view the results in the respective services.

#### Submit the pull request

Once you've validated the Travis CI results, go to the page for your fork on GitHub, select your development branch, and click the **Pull Request** button. If you need to make any adjustments to your pull request, push the updates to GitHub. Your pull request will automatically track the changes on your development branch and update.
Once you've validated the CI results, go to the page for your fork on GitHub, select your development branch, and click the **Pull Request** button. If you need to make any adjustments to your pull request, push the updates to GitHub. Your pull request will automatically track the changes on your development branch and update.
2 changes: 1 addition & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ All setup commands assume you are starting in the project's root directory.

## Run services

The OT Registrar JAR file includes the [Registrar](https://tools.ietf.org/id/draft-ietf-anima-bootstrapping-keyinfra-16.html#rfc.section.1.2), [MASA](https://tools.ietf.org/id/draft-ietf-anima-bootstrapping-keyinfra-16.html#rfc.section.1.2) server, and a simulated [Pledge](https://tools.ietf.org/id/draft-ietf-anima-bootstrapping-keyinfra-16.html#rfc.section.1.2).
The OT Registrar JAR file includes the Registrar, TBD [MASA](https://tools.ietf.org/id/draft-ietf-anima-bootstrapping-keyinfra-16.html#rfc.section.1.2) server, and a simulated [Pledge](https://tools.ietf.org/id/draft-ietf-anima-bootstrapping-keyinfra-16.html#rfc.section.1.2).

### Credentials

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OpenThread Registrar

Per [Thread](https://www.threadgroup.org/) 1.2 specification and [Bootstrapping Remote Secure Key Infrastructures (BRSKI)](https://tools.ietf.org/html/draft-ietf-anima-bootstrapping-keyinfra-16), a Domain Registrar securely registry new devices into a Thread Domain with zero-touch.
The [Constrained Bootstrapping Remote Secure Key Infrastructures (cBRSKI)](https://datatracker.ietf.org/doc/html/draft-ietf-anima-constrained-voucher) IETF draft defines a Domain Registrar for securely onboarding new IoT devices into a network domain with zero-touch.

OpenThread's implementation of a Domain Registrar is called OpenThread Registrar (OT Registrar).
OpenThread's implementation of a cBRSKI Domain Registrar, used for onboarding Thread devices, is called OpenThread Registrar (OT Registrar).

> Note: OT Registrar is still under development. We do not recommend using it in production yet.
Expand All @@ -18,10 +18,10 @@ Contributors are required to abide by our [Code of Conduct](CODE_OF_CONDUCT.md).

## Versioning

OT Registrar follows the [Semantic Versioning guidelines](http://semver.org/) for release cycle transparency and to maintain backwards compatibility. OT Registrar's versioning is independent of the Thread protocol specification version but will clearly indicate which version of the specification it currently supports.
OT Registrar follows the [Semantic Versioning guidelines](http://semver.org/) for release cycle transparency and to maintain backwards compatibility. OT Registrar's versioning is independent of the Thread protocol specification version.

## License

OT Registrar is released under the [BSD 3-Clause license](LICENSE). See the [`LICENSE`](LICENSE) file for more information.

Please only use the OpenThread and OT Registrar name and marks when accurately referencing this software distribution. Do not use the marks in a way that suggests you are endorsed by or otherwise affiliated with Nest, Google, or The Thread Group.
Please only use the OpenThread and OT Registrar name and marks when accurately referencing this software distribution. Do not use the marks in a way that suggests you are endorsed by or otherwise affiliated with Nest, Google, or Thread Group.
13 changes: 0 additions & 13 deletions script/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

set -e

ACE_REPO=https://bitbucket.org/marco-tiloca-sics/ace-java

## Test if we has the given command.
## Args: $1, the command.
has_command() {
Expand Down Expand Up @@ -61,15 +59,4 @@ install_toolchain() {
mvn -verion
}

install_ace() {
if [ ! -d ace ]; then
git clone $ACE_REPO ace
fi
cd ace
mvn -DskipTests install
cd -
rm -rf ace
}

install_toolchain
install_ace
38 changes: 38 additions & 0 deletions script/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Copyright (c) 2024, The OpenThread Registrar Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

readonly JAR_FILE=./target/ot-registrar-0.2-jar-with-dependencies.jar

# test if Registrar JAR exists
if [ ! -f "${JAR_FILE}" ]; then
echo "Please build using 'mvn -DskipTests package' before running."
exit 1
fi

java -jar $JAR_FILE $@
164 changes: 164 additions & 0 deletions src/main/java/com/google/openthread/main/OtRegistrarMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2024, The OpenThread Registrar Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

package com.google.openthread.main;

import com.google.openthread.Credentials;
import com.google.openthread.LoggerInitializer;
import com.google.openthread.domainca.DomainCA;
import com.google.openthread.registrar.Registrar;
import com.google.openthread.registrar.RegistrarBuilder;
import com.google.openthread.tools.CredentialGenerator;
import java.security.KeyStoreException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class OtRegistrarMain {

private static Logger logger = LoggerFactory.getLogger(OtRegistrarMain.class);

public static void main(String args[]) {

final String HELP_FORMAT = "[-registrar | -masa | -pledge] [-h] [-v] [-d <domain-name>] [-f <keystore-file>] [-p <udp-port>]";

HelpFormatter helper = new HelpFormatter();
Options options = new Options();

Option registrarOpt =
Option.builder("registrar")
.desc("start as cBRSKI Registrar")
.build();

Option masaOpt =
Option.builder("masa")
.desc("start as cBRSKI/BRSKI MASA")
.build();

Option pledgeOpt =
Option.builder("pledge")
.desc("start as cBRSKI Pledge")
.build();

Option domainNameOpt =
Option.builder("d")
.longOpt("domainname")
.hasArg()
.argName("domain-name")
.desc("the domain name")
.build();

Option fileOpt =
Option.builder("f")
.longOpt("file")
.hasArg()
.argName("keystore-file")
.desc("the keystore file in PKCS#12 format")
.build();

Option optPort =
Option.builder("p")
.longOpt("port")
.hasArg()
.argName("udp-port")
.desc("the port to listen on")
.build();

Option optVerbose =
Option.builder("v")
.longOpt("verbose")
.desc("verbose mode with many logs")
.build();

Option optForceMasaUri =
Option.builder("m")
.longOpt("masa")
.hasArg()
.argName("force-masa-uri")
.desc("force the given MASA URI instead of the default one")
.build();

Option helpOpt =
Option.builder("h").longOpt("help").hasArg(false).desc("print this message").build();

options
.addOption(registrarOpt)
.addOption(masaOpt)
.addOption(pledgeOpt)
.addOption(domainNameOpt)
.addOption(fileOpt)
.addOption(optPort)
.addOption(optVerbose)
.addOption(optForceMasaUri)
.addOption(helpOpt);

try {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);

LoggerInitializer.Init(cmd.hasOption('v'));

if (cmd.hasOption('h')) {
helper.printHelp(HELP_FORMAT, options);
return;
}

String keyStoreFile = cmd.getOptionValue('f');
if (keyStoreFile == null) {
keyStoreFile = "credentials/default.p12";
}

String port = cmd.getOptionValue('p');
if (port == null) {
port = "5683";
}

String domainName = cmd.getOptionValue('d');
if (domainName == null) {
domainName = "DefaultDomain";
}

if (cmd.hasOption('m')) {
// FIXME registrar.setForcedMasaUri(cmd.getOptionValue('m'));
}

logger.info("using keystore: {}", keyStoreFile);

} catch (Exception e) {
logger.error(e.getMessage(), e);
helper.printHelp(HELP_FORMAT, options);
return;
}

}
}
Loading

0 comments on commit 7fe2960

Please sign in to comment.