diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..3cf7618 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,57 @@ +--- +name: Build and test +on: + pull_request: + paths: + - .github/workflows/build-and-test.yml + - '**/*.rs' + - Cargo.toml + - Cargo.lock + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: --deny warnings + +jobs: + build-and-test: + strategy: + matrix: + rust: [stable, beta, nightly, 1.56.0] + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + default: true + + - name: Build + run: cargo build --all-targets + + - name: Test + # Since the tests modify global state (the system firewall) they cannot run in parallel. + # The integration tests must run as root since they write firewall state (/dev/pf) + run: sudo cargo test -- --test-threads=1 + + # Make sure the library builds with all dependencies downgraded to their + # oldest versions allowed by the semver spec. This ensures we have not + # under-specified any dependency + minimal-versions: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: nightly + profile: minimal + default: true + + - name: Downgrade dependencies to minimal versions + run: cargo +nightly update -Z minimal-versions + + - name: Compile with minimal versions + run: cargo build --all-targets diff --git a/.github/workflows/cargo-audit.yml b/.github/workflows/cargo-audit.yml new file mode 100644 index 0000000..bfe548f --- /dev/null +++ b/.github/workflows/cargo-audit.yml @@ -0,0 +1,35 @@ +--- +name: Audit dependencies +on: + pull_request: + paths: + - .github/workflows/cargo-audit.yml + - Cargo.toml + - Cargo.lock + schedule: + # At 06:20 UTC every day. Will create an issue if a CVE is found. + - cron: '20 6 * * *' + workflow_dispatch: +jobs: + audit: + runs-on: ubuntu-latest + permissions: + issues: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # We don't need to check CVEs against the checked in lockfile, + # but only against the newest compatible dependencies. + # This avoids significant maintenance work that provide no benefits. + # We only need to make sure there is any compatible dependency without a known issue + - run: cargo update + + - uses: actions-rust-lang/audit@160ac8b6edd32f74656cabba9d1de3fc8339f676 # v1.2 + name: Audit Rust Dependencies + with: + denyWarnings: true + # Ignored audit issues. This list should be kept short, and effort should be + # put into removing items from the list. + ignore: diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..73a287e --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,25 @@ +--- +name: Rust formatting +on: + pull_request: + paths: + - .github/workflows/formatting.yml + - '**/*.rs' + workflow_dispatch: +jobs: + check-formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: stable + profile: minimal + components: rustfmt + default: true + + - name: Check formatting + run: | + rustfmt --version + cargo fmt -- --check diff --git a/.github/workflows/git-commit-message-style.yml b/.github/workflows/git-commit-message-style.yml new file mode 100644 index 0000000..4125202 --- /dev/null +++ b/.github/workflows/git-commit-message-style.yml @@ -0,0 +1,32 @@ +--- +name: Git - Check commit message style +on: + push: + workflow_dispatch: + +jobs: + check-commit-message-style: + name: Check commit message style + runs-on: ubuntu-latest + steps: + # Make sure there are no whitespaces other than space, tab and newline in a commit message. + - name: Check for unicode whitespaces + uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee #v2.0.0 + with: + # Pattern matches strings not containing weird unicode whitespace/separator characters + # \P{Z} = All non-whitespace characters (the u-flag is needed to enable \P{Z}) + # [ \t\n] = Allowed whitespace characters + pattern: '^(\P{Z}|[ \t\n])+$' + flags: 'u' + error: 'Detected unicode whitespace character in commit message.' + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # only required if checkAllCommitMessages is true + + # Git commit messages should follow these guidelines: https://cbea.ms/git-commit/ + - name: Check against guidelines + uses: mristin/opinionated-commit-message@f3b9cec249cabffbae7cd564542fd302cc576827 #v3.1.1 + with: + # Commit messages are allowed to be subject only, no body + allow-one-liners: 'true' + # This action defaults to 50 char subjects, but 72 is fine. + max-subject-line-length: '72' diff --git a/.gitignore b/.gitignore index c3bb4ab..bf9e027 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ target/ -Cargo.lock **/*.rs.bk .vscode/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a4e43bd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: rust -cache: cargo -rust: - - nightly - - stable - - beta - - 1.42.0 -os: - - osx - - -before_script: - - export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH - - env - -script: - - cargo build --verbose - - sudo cargo test --verbose -- --test-threads=1 - - sudo chmod -R o+w target/ - - if [ "${TRAVIS_RUST_VERSION}" = "stable" ]; then - rustup component add rustfmt; - rustfmt --version; - cargo fmt -- --check; - else - echo "Not checking formatting on this build"; - fi - -notifications: - email: - on_success: never - on_failure: never diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2c103cc --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,387 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "assert_matches" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e772942dccdf11b368c31e044e4fca9189f80a773d2f0808379de65894cbf57" + +[[package]] +name = "autocfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23213af7601f0f2d929f73d2a772804562cb09063f50bba9c361f86d6a0376f8" + +[[package]] +name = "backtrace" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebbbf59b1c43eefa8c3ede390fcc36820b4999f7914104015be25025e0d62af2" +dependencies = [ + "backtrace-sys", + "cfg-if", + "libc", + "rustc-demangle", + "winapi 0.3.6", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3216d6e2b2c36c648a78afab0fdcb124d5365f7eb9b0895eab395549d76280d2" +dependencies = [ + "libc", +] + +[[package]] +name = "bitflags" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989" + +[[package]] +name = "c2-chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" +dependencies = [ + "lazy_static", + "ppv-lite86", +] + +[[package]] +name = "cfg-if" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "derive_builder" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" +dependencies = [ + "darling", + "derive_builder_core", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "errno" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901ad47d20b4647d9f3daf635c6c10a71920fdab6e425bde4eb3f30ceac0e0e0" +dependencies = [ + "kernel32-sys", + "libc", + "winapi 0.2.4", +] + +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "backtrace", + "version_check", +] + +[[package]] +name = "fnv" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31" + +[[package]] +name = "getrandom" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e738b1f02e4d17217cae7648e774c03a19cd9de18bc294c538cc3e780f8c3bbd" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "winapi 0.3.6", +] + +[[package]] +name = "ident_case" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c9826188e666f2ed92071d2dadef6edc430b11b158b5b2b3f4babbcc891eaaa" + +[[package]] +name = "ioctl-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c429fffa658f288669529fc26565f728489a2e39bc7b24a428aaaf51355182e" + +[[package]] +name = "ipnetwork" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" +dependencies = [ + "serde", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1ca084b49bfd975182288e1a5f1d27ea34ff2d6ae084ae5e66e1652427eada" +dependencies = [ + "winapi 0.2.4", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" + +[[package]] +name = "libc" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" + +[[package]] +name = "pfctl" +version = "0.4.6" +dependencies = [ + "assert_matches", + "derive_builder", + "errno", + "error-chain", + "ioctl-sys", + "ipnetwork", + "libc", + "scopeguard", + "uuid", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe1c37e6347ad1a8351171bee25a92342401f8cd550f76e153724e765ac76bca" + +[[package]] +name = "proc-macro2" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f287c234c9b2d0308d692dee5c449c1a171167a6f8150f7cf2a49d8fd96967" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab938ebe6f1c82426b5fb82eaf10c3e3028c53deaa3fbe38f5904b37cf4d767" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e193067942ef6f485a349a113329140d0ab9e2168ce92274499bb0e9a4190d9d" +dependencies = [ + "autocfg", + "c2-chacha", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" + +[[package]] +name = "scopeguard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" + +[[package]] +name = "serde" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "369633cfe0f0bde1dfc037fb6c5a329d46586a31f981bed14d87487a3439ae37" + +[[package]] +name = "strsim" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7be23478587f30ca7b4b423b6bee7baf5b6986c1e511bf1904a984cb6105621" + +[[package]] +name = "syn" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863ecbce06044c8380458360b4146d7372edadfedd77f120ba8c193da427b708" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "uuid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf1d83e5fa94e6c54ee47351bc92daca1f386aa1529ffbb668d2cee5e8173013" +dependencies = [ + "rand", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5350e40d908c7e8b9e5c9edb541ca47cc617c6229d3575a46da6f550f36c96fd" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 21dd8f0..119fa78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ travis-ci = { repository = "mullvad/pfctl-rs" } [dependencies] errno = "0.2" -error-chain = "0.12" +error-chain = "0.12.4" ioctl-sys = "0.6.0" libc = "0.2.29" derive_builder = "0.9"