#signature #web #mehal #brog

messagesign

Library for signing requests to mehal services

10 stable releases (4 major)

new 7.0.2 Mar 17, 2025
6.0.0 Mar 17, 2025
5.0.0 Mar 3, 2025
4.0.2 Feb 22, 2025
1.0.0 Dec 7, 2024

#246 in Authentication

Download history 318/week @ 2024-12-04 59/week @ 2024-12-11 3/week @ 2025-01-01 145/week @ 2025-01-29 421/week @ 2025-02-19 226/week @ 2025-02-26 293/week @ 2025-03-05 343/week @ 2025-03-12

1,283 downloads per month

MIT license

21KB
297 lines

messagesign

A rust library to sign requests to mehal services based on the AWS S3V4 approach.

The implementation is based on the s3v4 library.

This crate provides a signature function that can be used to sign a request to an mehal services.

Both functions return an Error generated by the error_chain crate which can be converted to a String or accessed through the description method or display_chain and backtrace methods in case a full backtrace is needed.

Build codecov OpenSSF Best Practices

Examples

Signing a request

   let url = url::Url::parse("https://mehal.tech/endpoint").unwrap();
   let signature: messagesign::Signature = messagesign::signature(
       &url, // The endpoint of the mehel services
       "GET",   // The http Method  
       "ivegotthekey",  // the access key provided with your secret
       "ivegotthesecret", // The secret provided for your project
       "global", // A supported region See mehal.tech docs
       &"brog",
       "machineid", // The data in /etc/machine-id
       "hostname", // The data in /etc/machine-id
       "UNSIGNED-PAYLOAD", //payload hash, or "UNSIGNED-PAYLOAD"
       "", // An empty string or a random u32
   ).map_err(|err| format!("Signature error: {}", err.display_chain()))?;

Using the signature data to make a request

Hyper

       let req = Request::builder()
       .method(Method::GET)
       .header("x-mhl-content-sha256", "UNSIGNED-PAYLOAD")
       .header("x-mhl-date", &signature.date_time)
       .header("x-mhl-mid", &machineid)
       .header("authorization", &signature.auth_header)

Ureq

   let agent = AgentBuilder::new().build();
   let response = agent
       .put(&uri)
       .set("x-mhl-content-sha256", "UNSIGNED-PAYLOAD")
       .set("x-mhl-date", &signature.date_time)
       .set("x-mhl-mid", &machineid)
       .set("authorization", &signature.auth_header)

Dependencies

~6–13MB
~163K SLoC