Skip to content

Commit

Permalink
try to fix secret-service in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Dec 17, 2024
1 parent c9aa3e6 commit 8e1f1bf
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 120 deletions.
48 changes: 34 additions & 14 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,48 @@ jobs:
include:
# Secret Service + D-Bus + std (blocking)

- os: ubuntu-latest
- os: ubuntu-24.04
features: secret-service-dbus-std,secret-service-openssl-std
example: secret-service-openssl-std
- os: ubuntu-latest
example: secret-service-dbus-openssl-std
- os: ubuntu-24.04
features: secret-service-dbus-std,secret-service-rust-crypto-std
example: secret-service-rust-crypto-std
example: secret-service-dbus-rust-crypto-std

# Secret Service + D-Bus + tokio

- os: ubuntu-latest
- os: ubuntu-24.04
features: secret-service-dbus-tokio,secret-service-openssl-std
example: secret-service-openssl-std
- os: ubuntu-latest
example: secret-service-dbus-openssl-tokio
- os: ubuntu-24.04
features: secret-service-dbus-tokio,secret-service-rust-crypto-std
example: secret-service-rust-crypto-std
example: secret-service-dbus-rust-crypto-tokio

# Secret Service + Z-Bus + std (blocking)

- os: ubuntu-24.04
features: secret-service-zbus-std,secret-service-openssl-std
example: secret-service-zbus-openssl-std
- os: ubuntu-24.04
features: secret-service-zbus-std,secret-service-rust-crypto-std
example: secret-service-zbus-rust-crypto-std

# Secret Service + Z-Bus + async-std

- os: ubuntu-latest
- os: ubuntu-24.04
features: secret-service-zbus-async-std,secret-service-openssl-std
example: secret-service-openssl-std
- os: ubuntu-latest
example: secret-service-zbus-openssl-async-std
- os: ubuntu-24.04
features: secret-service-zbus-async-std,secret-service-rust-crypto-std
example: secret-service-rust-crypto-std
example: secret-service-zbus-rust-crypto-async-std

# Secret Service + Z-Bus + tokio

- os: ubuntu-24.04
features: secret-service-zbus-tokio,secret-service-openssl-std
example: secret-service-zbus-openssl-tokio
- os: ubuntu-24.04
features: secret-service-zbus-tokio,secret-service-rust-crypto-std
example: secret-service-zbus-rust-crypto-tokio

# MacOS/iOS Keychain

Expand All @@ -60,8 +78,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
with:
packages: libdbus-1-dev
packages: libdbus-1-dev libssl-dev gnome-keyring
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: gnome-keyring-daemon --components=secrets --daemonize --unlock <<< 'password'
if: matrix.os == 'ubuntu-24.04'
- run: cargo run --features ${{ matrix.features }} --example ${{ matrix.example }}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ full = [
# Linux Secret service, based on D-Bus
#
secret-service-dbus-std = ["dep:dbus", "dep:dbus-codegen"]
secret-service-dbus-tokio = ["dep:dbus-codegen", "dep:dbus-tokio", "dep:tokio"]
secret-service-dbus-tokio = ["dep:dbus", "dep:dbus-codegen", "dep:dbus-tokio", "dep:tokio"]

# Linux Secret service, based on Z-Bus
#
Expand All @@ -49,7 +49,7 @@ secret-service-zbus-tokio = ["dep:serde", "dep:tokio", "dep:zbus", "serde?/deriv
# Linux Secret service crypto
#
secret-service-openssl-std = ["dep:num", "dep:openssl", "dep:once_cell", "dep:rand"]
secret-service-rust-crypto-std = ["dep:aes", "dep:block-padding", "dep:cbc", "dep:hkdf", "dep:sha2"]
secret-service-rust-crypto-std = ["dep:aes", "dep:block-padding", "dep:cbc", "dep:hkdf", "dep:num", "dep:once_cell", "dep:rand", "dep:sha2"]

# MacOS/iOS Keychain
#
Expand Down
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ fn main() {
generate_dbus_apis();
}

#[cfg(feature = "secret-service-dbus-std")]
#[cfg(any(
feature = "secret-service-dbus-std",
feature = "secret-service-dbus-tokio"
))]
fn generate_dbus_apis() {
let _ = std::fs::remove_file("./src/secret_service/dbus/blocking/api.rs");
let _ = std::fs::remove_file("./src/secret_service/dbus/nonblock/api.rs");
Expand Down
28 changes: 18 additions & 10 deletions examples/apple-native-std.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
#![cfg(target_vendor = "apple")]
#![cfg(feature = "apple-native-std")]

use std::env;

use keyring::{
apple::{
flow::{ReadEntryFlow, WriteEntryFlow},
std::IoConnector,
std::IoConnector as Keychain,
Flow,
},
Io,
};
use secrecy::ExposeSecret;

fn main() {
const SERVICE: &str = "service";
const ACCOUNT: &str = "account";
const SECRET: &str = "test";
const SECRET: &str = "apple-native-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

let account = env::var("ACCOUNT").unwrap_or(String::from("test-account"));
println!("using account name: {service:?}");

let keychain = Keychain::new();

println!("write secret {SECRET:?} to entry {ACCOUNT}@{SERVICE}");
let mut flow = WriteEntryFlow::new(SERVICE, ACCOUNT, SECRET.as_bytes().to_vec());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(&service, &account, SECRET.as_bytes().to_vec());
while let Some(io) = flow.next() {
match io {
Io::Write => {
IoConnector::write(&mut flow).unwrap();
keychain.write(&mut flow).unwrap();
}
_ => {
unreachable!();
}
}
}

let mut flow = ReadEntryFlow::new(SERVICE, ACCOUNT);
let mut flow = ReadEntryFlow::new(&service, &account);
while let Some(io) = flow.next() {
match io {
Io::Read => {
IoConnector::read(&mut flow).unwrap();
keychain.read(&mut flow).unwrap();
}
_ => unreachable!(),
}
Expand All @@ -42,5 +50,5 @@ fn main() {
let secret = flow.take_secret().unwrap();
let secret = secret.expose_secret();
let secret = String::from_utf8_lossy(&secret);
println!("read secret from entry {ACCOUNT}@{SERVICE}: {secret:?}");
println!("read secret {secret:?} from entry {service}:{account}");
}
6 changes: 4 additions & 2 deletions examples/secret-service-dbus-openssl-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use keyring::{
use secrecy::ExposeSecret;

fn main() {
const SECRET: &str = "secret-service-dbus-openssl-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -31,8 +33,8 @@ fn main() {
let mut dbus = DbusIoConnector::new(&service, &account, encryption.clone()).unwrap();
let mut crypto = CryptoIoConnector::new(dbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-dbus-openssl-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[tokio::main]
async fn main() {
const SECRET: &str = "secret-service-dbus-openssl-tokio";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(dbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-dbus-rust-crypto-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use keyring::{
use secrecy::ExposeSecret;

fn main() {
const SECRET: &str = "secret-service-dbus-rust-crypto-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -31,8 +33,8 @@ fn main() {
let mut dbus = DbusIoConnector::new(&service, &account, encryption.clone()).unwrap();
let mut crypto = CryptoIoConnector::new(dbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-dbus-rust-crypto-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[tokio::main]
async fn main() {
const SECRET: &str = "secret-service-dbus-rust-crypto-tokio";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(dbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-zbus-openssl-async-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[async_std::main]
async fn main() {
const SECRET: &str = "secret-service-zbus-openssl-async-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-zbus-openssl-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[async_std::main]
async fn main() {
const SECRET: &str = "secret-service-zbus-openssl-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -32,8 +34,8 @@ async fn main() {
let mut zbus = ZbusIoConnector::new(&service, &account, encryption.clone()).unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
8 changes: 5 additions & 3 deletions examples/secret-service-zbus-openssl-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[tokio::main]
async fn main() {
const SECRET: &str = "secret-service-zbus-openssl-tokio";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down Expand Up @@ -68,5 +70,5 @@ async fn main() {
let secret = String::from_utf8_lossy(&secret);
println!("read secret {secret:?} from entry {service}:{account}");

zbus.disconnect().await;
zbus.disconnect().await.unwrap();
}
6 changes: 4 additions & 2 deletions examples/secret-service-zbus-rust-crypto-async-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[async_std::main]
async fn main() {
const SECRET: &str = "zbus-rust-crypto-async-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-zbus-rust-crypto-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[async_std::main]
async fn main() {
const SECRET: &str = "secret-service-zbus-rust-crypto-std";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -32,8 +34,8 @@ async fn main() {
let mut zbus = ZbusIoConnector::new(&service, &account, encryption.clone()).unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
6 changes: 4 additions & 2 deletions examples/secret-service-zbus-rust-crypto-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use secrecy::ExposeSecret;

#[tokio::main]
async fn main() {
const SECRET: &str = "secret-service-zbus-rust-crypto-tokio";

let service = env::var("SERVICE").unwrap_or(String::from("test-service"));
println!("using service name: {service:?}");

Expand All @@ -34,8 +36,8 @@ async fn main() {
.unwrap();
let mut crypto = CryptoIoConnector::new(zbus.session()).unwrap();

println!("write secret {:?} to entry {service}:{account}", "test");
let mut flow = WriteEntryFlow::new(b"test".to_vec(), encryption.clone());
println!("write secret {SECRET:?} to entry {service}:{account}");
let mut flow = WriteEntryFlow::new(SECRET.as_bytes().to_vec(), encryption.clone());
while let Some(io) = flow.next() {
match io {
secret_service::Io::Crypto(crypto::Io::Encrypt) => {
Expand Down
Loading

0 comments on commit 8e1f1bf

Please sign in to comment.