Skip to content

Commit 58c26ab

Browse files
committed
feat(python): expose acl-free server
1 parent baf9e05 commit 58c26ab

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

ead/lakers-ead-authz/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod test_vectors;
99

1010
pub use authenticator::{ZeroTouchAuthenticator, ZeroTouchAuthenticatorWaitVoucherResp};
1111
pub use device::{ZeroTouchDevice, ZeroTouchDeviceDone, ZeroTouchDeviceWaitEAD2};
12-
pub use server::ZeroTouchServer;
12+
pub use server::{ZeroTouchServer, ZeroTouchServerUserAcl};
1313

1414
#[derive(PartialEq, Debug)]
1515
#[repr(C)]

lakers-python/src/ead_authz/server.rs

+37
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,40 @@ impl PyAuthzEnrollmentServer {
3535
}
3636
}
3737
}
38+
39+
#[pyclass(name = "AuthzServerUserAcl")]
40+
pub struct PyAuthzServerUserAcl {
41+
server: ZeroTouchServerUserAcl,
42+
}
43+
44+
#[pymethods]
45+
impl PyAuthzServerUserAcl {
46+
#[new]
47+
pub fn new(w: Vec<u8>, cred_v: Vec<u8>) -> Self {
48+
let mut w_arr = BytesP256ElemLen::default();
49+
w_arr.copy_from_slice(&w.as_slice());
50+
51+
Self {
52+
server: ZeroTouchServerUserAcl::new(w_arr, cred_v.as_slice()),
53+
}
54+
}
55+
56+
fn decode_voucher_request<'a>(&self, py: Python<'a>, vreq: Vec<u8>) -> PyResult<&'a PyBytes> {
57+
let vreq = EdhocMessageBuffer::new_from_slice(vreq.as_slice()).unwrap();
58+
match self
59+
.server
60+
.decode_voucher_request(&mut default_crypto(), &vreq)
61+
{
62+
Ok(id_u) => Ok(PyBytes::new(py, id_u.as_slice())),
63+
Err(error) => Err(error.into()),
64+
}
65+
}
66+
67+
fn prepare_voucher<'a>(&self, py: Python<'a>, vreq: Vec<u8>) -> PyResult<&'a PyBytes> {
68+
let vreq = EdhocMessageBuffer::new_from_slice(vreq.as_slice()).unwrap();
69+
match self.server.prepare_voucher(&mut default_crypto(), &vreq) {
70+
Ok(voucher_response) => Ok(PyBytes::new(py, voucher_response.as_slice())),
71+
Err(error) => Err(error.into()),
72+
}
73+
}
74+
}

lakers-python/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ fn lakers_python(_py: Python, m: &PyModule) -> PyResult<()> {
6666
m.add_class::<ead_authz::PyAuthzDevice>()?;
6767
m.add_class::<ead_authz::PyAuthzAutenticator>()?;
6868
m.add_class::<ead_authz::PyAuthzEnrollmentServer>()?;
69+
m.add_class::<ead_authz::PyAuthzServerUserAcl>()?;
6970
Ok(())
7071
}

lakers-python/test/test_ead_authz.py

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def test_authenticator_and_server():
3535
assert ead_2.is_critical() == True
3636
assert ead_2.value() == EAD_2_VALUE
3737

38+
def test_authenticator_and_server():
39+
VOUCHER_REQUEST_TV = bytes.fromhex("8158520382060258208af6f430ebe18d34184017a9a11bf511c8dff8f834730b96c1b7c8dbca2fc3b6370158287818636f61703a2f2f656e726f6c6c6d656e742e7365727665724dda9784962883c96ed01ff122c3")
40+
enrollment_server = lakers.AuthzServerUserAcl(W, CRED_V)
41+
42+
id_u = enrollment_server.decode_voucher_request(VOUCHER_REQUEST_TV)
43+
assert id_u == ID_U
44+
voucher_response = enrollment_server.prepare_voucher(VOUCHER_REQUEST_TV)
45+
assert type(voucher_response) == bytes
46+
3847
def test_handshake_with_authz():
3948
initiator = lakers.EdhocInitiator()
4049
responder = lakers.EdhocResponder(V, CRED_V)

0 commit comments

Comments
 (0)