Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noise Explorer command-line tool #1

Merged
merged 5 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[Noise Explorer Repository](https://source.symbolic.software/noiseexplorer/noiseexplorer)


<!-- GETTING STARTED -->
## Getting Started

The Noise Explorer command-line tool can parse Noise Handshake Patterns according to the original specification. It can generate cryptographic models for formal verification, including security queries, top-level processes and malicious principals, for testing against an active or passive attacker. Noise Explorer can also generate fully functional discrete implementations for any Noise Handshake Pattern, written in the Go and Rust programming languages, as well as WebAssembly binaries.
Noise Explorer can also render results from the ProVerif output into an elegant and easy to read HTML format: the pattern results that can be explored on Noise Explorer were generated using the Noise Explorer command-line tool.

### Prerequisites
Install Nix with flake support as given in [https://nixos.wiki/wiki/Flakes](https://nixos.wiki/wiki/Flakes)
In debian based systems the method is as follows after installing Nix
```sh
nix-env -iA nixpkgs.nixUnstable
```
Edit either ~/.config/nix/nix.conf or /etc/nix/nix.conf and add:
```sh
experimental-features = nix-command flakes
```


### Installation

1. The flake can be installed like other Nix flakes.

2. The command line tool operates on noise pattern files from the repository and creates output in files.

3. Therefore the required noise patttern files can be copied from result/src/ folder and use it from working directory.

4. The process can be as follows
```sh
nix develop
node noiseExplorer.js
```
5. The output will be as follows
```sh
Noise Explorer version 0.3 (specification revision 34)
Noise Explorer has three individual modes: generation, rendering and web interface.

Generation:
--generate=(json|pv|go|rs|wasm): Specify output format.
--pattern=[file]: Specify input pattern file (required).
--attacker=(active|passive): Specify ProVerif attacker type (default: active).

Rendering:
--render: Render results from ProVerif output files into HTML.
--pattern=[file]: Specify input pattern file (required).
--activeModel=[file]: Specify ProVerif active attacker model (required).

42 changes: 4 additions & 38 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 54 additions & 97 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,120 +1,77 @@
{
description = "(insert short project description here)";
description = "Commandline tool for testing Noise Protocol for parse Noise Handshake Patterns";

# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-20.09";
inputs = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you also need the source of the noise explorer as well ?
Perhaps you have it locally, but I don't think it's available to everybody.
Perhaps that explains why you needed to cd src further down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fetched via fetchgit in default.nix which seems fine.
But I agree, handling the source as a flake input will allow the user to change the source version via flakes interface (nix flake lock --update-input will be possible for example). That can be convenient, especially when this flake is used by other flakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fetched in default.nix and try to use the same version in the flake.nix and also in default.nix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind putting the src in the inputs ?
It's a little clearer that way, it also provides a convenient update mechanism.

nixpkgs.url = "nixpkgs/nixos-unstable";
};

# Upstream source tree(s).
inputs.hello-src = { url = git+https://git.savannah.gnu.org/git/hello.git; flake = false; };
inputs.gnulib-src = { url = git+https://git.savannah.gnu.org/git/gnulib.git; flake = false; };

outputs = { self, nixpkgs, hello-src, gnulib-src }:
outputs = { self, nixpkgs }:
let

# Generate a user-friendly version numer.
version = builtins.substring 0 8 hello-src.lastModifiedDate;

# System types to support.
supportedSystems = [ "x86_64-linux" ];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);

# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });

in

{
defaultPackage = forAllSystems (system: (import nixpkgs {
inherit system;
overlays = [ self.overlay ];
}).noiseExplorer);

# A Nixpkgs overlay.
overlay = final: prev: {

hello = with final; stdenv.mkDerivation rec {
name = "hello-${version}";

src = hello-src;

buildInputs = [ autoconf automake gettext gnulib perl gperf texinfo help2man ];

preConfigure = ''
mkdir -p .git # force BUILD_FROM_GIT
./bootstrap --gnulib-srcdir=${gnulib-src} --no-git --skip-po
'';

meta = {
homepage = "https://www.gnu.org/software/hello/";
description = "A program to show a familiar, friendly greeting";
};
};

};

# Provide some binary packages for selected system types.
packages = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
{
inherit (nixpkgsFor.${system}) hello;
inherit (pkgs) noiseExplorer;
});

# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = forAllSystems (system: self.packages.${system}.hello);

# A NixOS module, if applicable (e.g. if the package provides a system service).
nixosModules.hello =
{ pkgs, ... }:
{
nixpkgs.overlays = [ self.overlay ];

environment.systemPackages = [ pkgs.hello ];

#systemd.services = { ... };
};
overlay = final: prev: {
noiseExplorer = final.callPackage ./noiseExplorer { };
};

# Tests run by 'nix flake check' and by Hydra.
checks = forAllSystems (system: {
inherit (self.packages.${system}) hello;
devShell = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};

# Additional tests, if applicable.
test =
with nixpkgsFor.${system};
stdenv.mkDerivation {
name = "hello-test-${version}";
nodeDependencies = (pkgs.callPackage ./noiseExplorer/dep.nix { }).shell.nodeDependencies;
in
pkgs.mkShell {

buildInputs = [ hello ];

unpackPhase = "true";
buildInputs = with pkgs; [
cargo
nodejs
go
rustc
wasm
wasm-pack
];

buildPhase = ''
echo 'running some integration tests'
[[ $(hello) = 'Hello, world!' ]]
'';

installPhase = "mkdir -p $out";
};
});

# A VM test of the NixOS module.
vmTest =
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
checks = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};

makeTest {
nodes = {
client = { ... }: {
imports = [ self.nixosModules.hello ];
};
};

testScript =
''
start_all()
client.wait_for_unit("multi-user.target")
client.succeed("hello")
'';
};
});

in
{
format = pkgs.runCommand "check-format"
{
buildInputs = with pkgs; [ cargo nodejs go rustc wasm wasm-pack ];
}
''
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.}
touch $out
#nixpkgs-fmt check sucessfull
'';
});
};
}
38 changes: 38 additions & 0 deletions noiseExplorer/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ stdenv, lib, fetchgit, fetchurl, nodejs, pkgs }:
let
nodeDependencies = (pkgs.callPackage ./dep.nix { }).shell.nodeDependencies;
in

stdenv.mkDerivation rec {
pname = "NoiseExplorer";

version = "1.0.3";

src = fetchgit {
url = "https://source.symbolic.software/noiseexplorer/noiseexplorer.git";
rev = "5b03267416fd5deb8b08f9d254b4c64b00baa676";
sha256 = "sha256-hXTKrRDpdmHvGgIyPnyjYopNgvewvxbzEgBxOfFa62w=";
};

buildInputs = with pkgs; [ cargo nodejs go rustc wasm wasm-pack ];
raghuramlavan marked this conversation as resolved.
Show resolved Hide resolved

buildPhase = ''
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
export PATH="${nodeDependencies}/bin:$PATH"
cd src
pegjs -o parser/noiseParser.js parser/noiseParser.pegjs
echo -n "[NoiseExplorer] Generating NoiseParser..."
echo "Parser Generated"
cd util
bash genModels.sh
bash genHtml.sh
'';


installPhase = ''
mkdir -p $out/bin
cd ../../
cp -vr . $out
cp ${pkgs.writeScript "noiseexplorer" ''${nodejs}/bin/node ${src}/src/noiseExplorer.js $0 $1 $2''} $out/bin/noiseexplorer
raghuramlavan marked this conversation as resolved.
Show resolved Hide resolved
'';
raghuramlavan marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions noiseExplorer/dep.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file has been generated by node2nix 1.9.0. Do not edit!

{ pkgs ? import <nixpkgs> {
inherit system;
}
, system ? builtins.currentSystem
, nodejs ? pkgs."nodejs-12_x"
}:

let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages.nix {
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
}
Loading