Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

US or EU Data Region Selection #3752

Merged
merged 12 commits into from
Jan 1, 2024
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@
# WEBSOCKET_PORT=3012

## Enables push notifications (requires key and id from https://bitwarden.com/host)
## If you choose "European Union" Data Region, uncomment PUSH_RELAY_URI and PUSH_IDENTITY_URI then replace .com by .eu
# PUSH_ENABLED=true
# PUSH_INSTALLATION_ID=CHANGEME
# PUSH_INSTALLATION_KEY=CHANGEME
## Don't change this unless you know what you're doing.
# PUSH_RELAY_URI=https://push.bitwarden.com
# PUSH_IDENTITY_URI=https://identity.bitwarden.com

## Controls whether users are allowed to create Bitwarden Sends.
## This setting applies globally to all users.
Expand Down Expand Up @@ -451,4 +453,4 @@
## HaveIBeenPwned API Key, request it here: https://haveibeenpwned.com/API/Key
# HIBP_API_KEY=

# vim: syntax=ini
# vim: syntax=ini
Copy link

@SuperSandro2000 SuperSandro2000 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newline should probably stay here

6 changes: 5 additions & 1 deletion src/api/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ async fn get_auth_push_token() -> ApiResult<String> {
("client_secret", &client_secret),
];

let res = match get_reqwest_client().post("https://identity.bitwarden.com/connect/token").form(&params).send().await
let res = match get_reqwest_client()
.post(&format!("{}/connect/token", CONFIG.push_identity_uri()))
.form(&params)
.send()
.await
{
Ok(r) => r,
Err(e) => err!(format!("Error getting push token from bitwarden server: {e}")),
Expand Down
24 changes: 23 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ make_config! {
push {
/// Enable push notifications
push_enabled: bool, false, def, false;
/// Push relay base uri
/// Push relay uri
push_relay_uri: String, false, def, "https://push.bitwarden.com".to_string();
/// Push identity uri
push_identity_uri: String, false, def, "https://identity.bitwarden.com".to_string();
/// Installation id |> The installation id from https://bitwarden.com/host
push_installation_id: Pass, false, def, String::new();
/// Installation key |> The installation key from https://bitwarden.com/host
Expand Down Expand Up @@ -751,6 +753,26 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
)
}

if cfg.push_enabled {
let push_relay_uri = cfg.push_relay_uri.to_lowercase();
BlackDex marked this conversation as resolved.
Show resolved Hide resolved
if !push_relay_uri.starts_with("https://") {
err!("`PUSH_RELAY_URI` must start with 'https://'.")
}

if Url::parse(&push_relay_uri).is_err() {
err!("Invalid URL format for `PUSH_RELAY_URI`.");
}

let push_identity_uri = cfg.push_identity_uri.to_lowercase();
BlackDex marked this conversation as resolved.
Show resolved Hide resolved
if !push_identity_uri.starts_with("https://") {
err!("`PUSH_IDENTITY_URI` must start with 'https://'.")
}

if Url::parse(&push_identity_uri).is_err() {
err!("Invalid URL format for `PUSH_IDENTITY_URI`.");
}
}

if cfg._enable_duo
&& (cfg.duo_host.is_some() || cfg.duo_ikey.is_some() || cfg.duo_skey.is_some())
&& !(cfg.duo_host.is_some() && cfg.duo_ikey.is_some() && cfg.duo_skey.is_some())
Expand Down