mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
fix!: Remove sha1 dependency (#379)
Removed cryptographically insecure sha1. This existed only for OPA compatibility. Also exclude bindings from main workspace Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
c6a5f1d852
commit
4a2df93ae2
2
.github/workflows/pr-extensions.yml
vendored
2
.github/workflows/pr-extensions.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: tests/release
|
name: tests/release-extensions
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|||||||
3
.github/workflows/test-go.yml
vendored
3
.github/workflows/test-go.yml
vendored
@@ -18,7 +18,6 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
architecture: x64
|
architecture: x64
|
||||||
|
|
||||||
- name: Build ffi
|
- name: Build ffi
|
||||||
@@ -29,5 +28,5 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go build
|
go build
|
||||||
LD_LIBRARY_PATH=../../target/release ./regorus_test
|
LD_LIBRARY_PATH=../ffi/target/release ./regorus_test
|
||||||
working-directory: ./bindings/go
|
working-directory: ./bindings/go
|
||||||
|
|||||||
2
.github/workflows/test-java.yml
vendored
2
.github/workflows/test-java.yml
vendored
@@ -33,5 +33,5 @@ jobs:
|
|||||||
- name: Test jar
|
- name: Test jar
|
||||||
run: |
|
run: |
|
||||||
javac -cp target/regorus-java-0.2.2.jar Test.java
|
javac -cp target/regorus-java-0.2.2.jar Test.java
|
||||||
java -Djava.library.path=../../target/release -cp target/regorus-java-0.2.2.jar:. Test
|
java -Djava.library.path=target/release -cp target/regorus-java-0.2.2.jar:. Test
|
||||||
working-directory: ./bindings/java
|
working-directory: ./bindings/java
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -25,4 +25,6 @@ worktrees/
|
|||||||
|
|
||||||
# Generated C, C++ headers
|
# Generated C, C++ headers
|
||||||
bindings/ffi/regorus.h
|
bindings/ffi/regorus.h
|
||||||
bindings/ffi/regorus.ffi.hpp
|
bindings/ffi/regorus.ffi.hpp
|
||||||
|
|
||||||
|
bindings/*/target
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"bindings/ffi",
|
|
||||||
"bindings/python",
|
|
||||||
"bindings/wasm",
|
|
||||||
"bindings/java",
|
|
||||||
"bindings/ruby/ext/regorusrb",
|
|
||||||
"tests/ensure_no_std",
|
"tests/ensure_no_std",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -31,7 +26,7 @@ ast = []
|
|||||||
base64 = ["dep:data-encoding"]
|
base64 = ["dep:data-encoding"]
|
||||||
base64url = ["dep:data-encoding"]
|
base64url = ["dep:data-encoding"]
|
||||||
coverage = []
|
coverage = []
|
||||||
crypto = ["dep:constant_time_eq", "dep:hmac", "dep:hex", "dep:md-5", "dep:sha1", "dep:sha2"]
|
crypto = ["dep:constant_time_eq", "dep:hmac", "dep:hex", "dep:md-5", "dep:sha2"]
|
||||||
deprecated = []
|
deprecated = []
|
||||||
hex = ["dep:data-encoding"]
|
hex = ["dep:data-encoding"]
|
||||||
http = []
|
http = []
|
||||||
@@ -109,7 +104,6 @@ constant_time_eq = {version = "0.4.0", optional = true, default-features = false
|
|||||||
hmac = {version = "0.12.1", optional = true, default-features = false}
|
hmac = {version = "0.12.1", optional = true, default-features = false}
|
||||||
sha2 = {version= "0.10.8", optional = true, default-features = false }
|
sha2 = {version= "0.10.8", optional = true, default-features = false }
|
||||||
hex = {version = "0.4.3", optional = true, default-features = false, features = ["alloc"] }
|
hex = {version = "0.4.3", optional = true, default-features = false, features = ["alloc"] }
|
||||||
sha1 = {version = "0.10.6", optional = true, default-features = false }
|
|
||||||
md-5 = {version = "0.10.6", optional = true, default-features = false }
|
md-5 = {version = "0.10.6", optional = true, default-features = false }
|
||||||
|
|
||||||
data-encoding = { version = "2.8.0", optional = true, default-features=false, features = ["alloc"] }
|
data-encoding = { version = "2.8.0", optional = true, default-features=false, features = ["alloc"] }
|
||||||
|
|||||||
@@ -319,6 +319,8 @@ The following test suites don't pass fully due to missing builtins:
|
|||||||
- `regoparsemodule`
|
- `regoparsemodule`
|
||||||
- `rendertemplate`
|
- `rendertemplate`
|
||||||
|
|
||||||
|
Cryptographically insecure `sha1` related builtins are intentionally not supported to discourage their use.
|
||||||
|
|
||||||
They are captured in the following [github issues](https://github.com/microsoft/regorus/issues?q=is%3Aopen+is%3Aissue+label%3Alib).
|
They are captured in the following [github issues](https://github.com/microsoft/regorus/issues?q=is%3Aopen+is%3Aissue+label%3Alib).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ include(FetchContent)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
Corrosion
|
Corrosion
|
||||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||||
GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here
|
# Use a tag that has a fix for https://github.com/corrosion-rs/corrosion/issues/590
|
||||||
|
GIT_TAG 6be991bb34c348dfb8344be22f3606288ea5c7fd
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Corrosion)
|
FetchContent_MakeAvailable(Corrosion)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ include(FetchContent)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
Corrosion
|
Corrosion
|
||||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||||
GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here
|
# Use a tag that has a fix for https://github.com/corrosion-rs/corrosion/issues/590
|
||||||
|
GIT_TAG 6be991bb34c348dfb8344be22f3606288ea5c7fd
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Corrosion)
|
FetchContent_MakeAvailable(Corrosion)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ include(FetchContent)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
Corrosion
|
Corrosion
|
||||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||||
GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here
|
# Use a tag that has a fix for https://github.com/corrosion-rs/corrosion/issues/590
|
||||||
|
GIT_TAG 6be991bb34c348dfb8344be22f3606288ea5c7fd
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Corrosion)
|
FetchContent_MakeAvailable(Corrosion)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<Exec Command="cargo build -r --manifest-path ../../ffi/Cargo.toml" />
|
<Exec Command="cargo build -r --manifest-path ../../ffi/Cargo.toml" />
|
||||||
<Copy SourceFiles="../../ffi/RegorusFFI.g.cs" DestinationFolder="." />
|
<Copy SourceFiles="../../ffi/RegorusFFI.g.cs" DestinationFolder="." />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<RegorusDylib Include="..\..\..\target\release\*regorus_ffi*" />
|
<RegorusDylib Include="..\..\ffi\target\release\*regorus_ffi*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Copy SourceFiles="@(RegorusDylib)" DestinationFolder="." />
|
<Copy SourceFiles="@(RegorusDylib)" DestinationFolder="." />
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<Exec Command="cargo build -r --manifest-path ../../ffi/Cargo.toml" />
|
<Exec Command="cargo build -r --manifest-path ../../ffi/Cargo.toml" />
|
||||||
<Copy SourceFiles="../../ffi/RegorusFFI.g.cs" DestinationFolder="." />
|
<Copy SourceFiles="../../ffi/RegorusFFI.g.cs" DestinationFolder="." />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<RegorusDylib Include="..\..\..\target\release\*regorus_ffi*" />
|
<RegorusDylib Include="..\..\ffi\target\release\*regorus_ffi*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Copy SourceFiles="@(RegorusDylib)" DestinationFolder="." />
|
<Copy SourceFiles="@(RegorusDylib)" DestinationFolder="." />
|
||||||
</Target>
|
</Target>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "regorus-ffi"
|
name = "regorus-ffi"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package regorus
|
package regorus
|
||||||
|
|
||||||
// #cgo LDFLAGS: -L ../../../../target/release -lregorus_ffi
|
// #cgo LDFLAGS: -L ../../../ffi/target/release -lregorus_ffi
|
||||||
// #include "../../../ffi/regorus.h"
|
// #include "../../../ffi/regorus.h"
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
@@ -28,7 +28,7 @@ func (e *Engine) Clone() *Engine {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) SetRegoV0(enable bool) (error) {
|
func (e *Engine) SetRegoV0(enable bool) error {
|
||||||
result := C.regorus_engine_set_rego_v0(e.e, C.bool(enable))
|
result := C.regorus_engine_set_rego_v0(e.e, C.bool(enable))
|
||||||
defer C.regorus_result_drop(result)
|
defer C.regorus_result_drop(result)
|
||||||
|
|
||||||
@@ -84,7 +84,6 @@ func (e *Engine) GetPolicies() (string, error) {
|
|||||||
return C.GoString(result.output), nil
|
return C.GoString(result.output), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (e *Engine) AddDataJson(data string) error {
|
func (e *Engine) AddDataJson(data string) error {
|
||||||
data_c := C.CString(data)
|
data_c := C.CString(data)
|
||||||
defer C.free(unsafe.Pointer(data_c))
|
defer C.free(unsafe.Pointer(data_c))
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "regorus-java"
|
name = "regorus-java"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Afterwards, you can build native library for that target using:
|
|||||||
$ cargo build --release --target aarch64-apple-darwin
|
$ cargo build --release --target aarch64-apple-darwin
|
||||||
```
|
```
|
||||||
|
|
||||||
You will then have a native library at `../../target/aarch64-apple-darwin/release/libregorus_java.dylib` depending on your target.
|
You will then have a native library at `target/aarch64-apple-darwin/release/libregorus_java.dylib` depending on your target.
|
||||||
|
|
||||||
You then need to build Java bindings using:
|
You then need to build Java bindings using:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "regoruspy"
|
name = "regoruspy"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "regorusjs"
|
name = "regorusjs"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|||||||
@@ -11,18 +11,15 @@ use anyhow::{bail, Result};
|
|||||||
use constant_time_eq::constant_time_eq;
|
use constant_time_eq::constant_time_eq;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use sha1::Sha1;
|
|
||||||
use sha2::{Sha256, Sha512};
|
use sha2::{Sha256, Sha512};
|
||||||
|
|
||||||
pub fn register(m: &mut builtins::BuiltinsMap<&'static str, builtins::BuiltinFcn>) {
|
pub fn register(m: &mut builtins::BuiltinsMap<&'static str, builtins::BuiltinFcn>) {
|
||||||
m.insert("crypto.hmac.equal", (hmac_equal_fixed_time, 2));
|
m.insert("crypto.hmac.equal", (hmac_equal_fixed_time, 2));
|
||||||
m.insert("crypto.hmac.md5", (hmac_md5, 2));
|
m.insert("crypto.hmac.md5", (hmac_md5, 2));
|
||||||
m.insert("crypto.hmac.sha1", (hmac_sha1, 2));
|
|
||||||
m.insert("crypto.hmac.sha256", (hmac_sha256, 2));
|
m.insert("crypto.hmac.sha256", (hmac_sha256, 2));
|
||||||
m.insert("crypto.hmac.sha512", (hmac_sha512, 2));
|
m.insert("crypto.hmac.sha512", (hmac_sha512, 2));
|
||||||
|
|
||||||
m.insert("crypto.md5", (crypto_md5, 1));
|
m.insert("crypto.md5", (crypto_md5, 1));
|
||||||
m.insert("crypto.sha1", (crypto_sha1, 1));
|
|
||||||
m.insert("crypto.sha256", (crypto_sha256, 1));
|
m.insert("crypto.sha256", (crypto_sha256, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,22 +57,6 @@ fn hmac_md5(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) ->
|
|||||||
Ok(Value::String(hex::encode(result.into_bytes()).into()))
|
Ok(Value::String(hex::encode(result.into_bytes()).into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hmac_sha1(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
|
||||||
let name = "crypto.hmac.sha1";
|
|
||||||
ensure_args_count(span, name, params, args, 2)?;
|
|
||||||
|
|
||||||
let x = ensure_string(name, ¶ms[0], &args[0])?;
|
|
||||||
let key = ensure_string(name, ¶ms[1], &args[1])?;
|
|
||||||
|
|
||||||
let mut hmac = Hmac::<Sha1>::new_from_slice(key.as_bytes())
|
|
||||||
.or_else(|_| bail!(span.error("failed to create hmac instance")))?;
|
|
||||||
|
|
||||||
hmac.update(x.as_bytes());
|
|
||||||
let result = hmac.finalize();
|
|
||||||
|
|
||||||
Ok(Value::String(hex::encode(result.into_bytes()).into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hmac_sha256(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
fn hmac_sha256(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||||
let name = "crypto.hmac.sha256";
|
let name = "crypto.hmac.sha256";
|
||||||
ensure_args_count(span, name, params, args, 2)?;
|
ensure_args_count(span, name, params, args, 2)?;
|
||||||
@@ -122,20 +103,6 @@ fn crypto_md5(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool)
|
|||||||
Ok(Value::String(hex::encode(result).into()))
|
Ok(Value::String(hex::encode(result).into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crypto_sha1(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
|
||||||
let name = "crypto.sha1";
|
|
||||||
ensure_args_count(span, name, params, args, 1)?;
|
|
||||||
|
|
||||||
let x = ensure_string(name, ¶ms[0], &args[0])?;
|
|
||||||
|
|
||||||
let mut h = Sha1::new();
|
|
||||||
|
|
||||||
h.update(x.as_bytes());
|
|
||||||
let result = h.finalize();
|
|
||||||
|
|
||||||
Ok(Value::String(hex::encode(result).into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn crypto_sha256(
|
fn crypto_sha256(
|
||||||
span: &Span,
|
span: &Span,
|
||||||
params: &[Ref<Expr>],
|
params: &[Ref<Expr>],
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ v0/comprehensions
|
|||||||
v0/containskeyword
|
v0/containskeyword
|
||||||
v0/cryptohmacequal
|
v0/cryptohmacequal
|
||||||
v0/cryptohmacmd5
|
v0/cryptohmacmd5
|
||||||
v0/cryptohmacsha1
|
|
||||||
v0/cryptohmacsha256
|
v0/cryptohmacsha256
|
||||||
v0/cryptohmacsha512
|
v0/cryptohmacsha512
|
||||||
v0/cryptomd5
|
v0/cryptomd5
|
||||||
v0/cryptosha1
|
|
||||||
v0/cryptosha256
|
v0/cryptosha256
|
||||||
v0/dataderef
|
v0/dataderef
|
||||||
v0/defaultkeyword
|
v0/defaultkeyword
|
||||||
@@ -137,11 +135,9 @@ v1/comprehensions
|
|||||||
v1/containskeyword
|
v1/containskeyword
|
||||||
v1/cryptohmacequal
|
v1/cryptohmacequal
|
||||||
v1/cryptohmacmd5
|
v1/cryptohmacmd5
|
||||||
v1/cryptohmacsha1
|
|
||||||
v1/cryptohmacsha256
|
v1/cryptohmacsha256
|
||||||
v1/cryptohmacsha512
|
v1/cryptohmacsha512
|
||||||
v1/cryptomd5
|
v1/cryptomd5
|
||||||
v1/cryptosha1
|
|
||||||
v1/cryptosha256
|
v1/cryptosha256
|
||||||
v1/dataderef
|
v1/dataderef
|
||||||
v1/defaultkeyword
|
v1/defaultkeyword
|
||||||
|
|||||||
Reference in New Issue
Block a user