-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
352 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,99 @@ | ||
--- | ||
name: Publish Python SDK | ||
run-name: Publish Python SDK ${{ inputs.release_type }} | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: "Release Options" | ||
required: true | ||
default: "Release" | ||
type: choice | ||
options: | ||
- Release | ||
- Dry Run | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
stub: | ||
name: Stub | ||
setup: | ||
name: Setup | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Stub | ||
run: echo "Stub" | ||
- name: Checkout repo | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Branch check | ||
if: ${{ github.event.inputs.release_type != 'Dry Run' }} | ||
run: | | ||
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then | ||
echo "===================================" | ||
echo "[!] Can only release from the 'rc' or 'hotfix-rc' branches" | ||
echo "===================================" | ||
exit 1 | ||
fi | ||
publish: | ||
name: Publish | ||
runs-on: ubuntu-22.04 | ||
needs: setup | ||
steps: | ||
- name: Install Python | ||
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: Install twine | ||
run: pip install twine | ||
|
||
- name: Download artifacts | ||
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d # v3.0.0 | ||
with: | ||
workflow: build-python-wheels.yml | ||
path: ${{ github.workspace }}/target/wheels/dist | ||
workflow_conclusion: success | ||
branch: ${{ github.event.inputs.release_type == 'Dry Run' && 'main' || github.ref_name }} | ||
name: bitwarden_sdk(.*) | ||
name_is_regexp: true | ||
|
||
- name: Move files | ||
working-directory: ${{ github.workspace }}/target/wheels/dist | ||
run: | | ||
find . -maxdepth 2 -type f -print0 | xargs -0 mv -t . | ||
rm -rf */ | ||
- name: Login to Azure | ||
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 | ||
with: | ||
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} | ||
|
||
- name: Retrieve pypi api token | ||
id: retrieve-secret | ||
uses: bitwarden/gh-actions/get-keyvault-secrets@main | ||
with: | ||
keyvault: "bitwarden-ci" | ||
secrets: "pypi-api-token, | ||
pypi-test-api-token" | ||
|
||
- name: Check | ||
working-directory: ${{ github.workspace }}/target/wheels | ||
run: twine check dist/* | ||
|
||
- name: Publish | ||
if: ${{ github.event.inputs.release_type != 'Dry Run' }} | ||
working-directory: ${{ github.workspace }}/target/wheels | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ steps.retrieve-secret.outputs.pypi-api-token }} | ||
run: twine upload --repository pypi dist/* | ||
|
||
- name: Dry Run - Publish | ||
if: ${{ github.event.inputs.release_type == 'Dry Run' }} | ||
working-directory: ${{ github.workspace }}/target/wheels | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ steps.retrieve-secret.outputs.pypi-test-api-token }} | ||
run: twine upload --repository testpypi dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
name: Workflow linter | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- .github/workflows/** | ||
|
||
jobs: | ||
call-workflow: | ||
name: Lint | ||
uses: bitwarden/gh-actions/.github/workflows/workflow-linter.yml@main |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,9 @@ pub(crate) fn auth_request_decrypt_user_key( | |
user_key: AsymmetricEncString, | ||
) -> Result<SymmetricCryptoKey, Error> { | ||
let key = AsymmetricCryptoKey::from_der(&STANDARD.decode(private_key)?)?; | ||
let key: String = user_key.decrypt_with_key(&key)?; | ||
let mut key: Vec<u8> = user_key.decrypt_with_key(&key)?; | ||
|
||
Ok(key.parse()?) | ||
Ok(SymmetricCryptoKey::try_from(key.as_mut_slice())?) | ||
} | ||
|
||
/// Approve an auth request. | ||
|
@@ -83,20 +83,25 @@ pub(crate) fn approve_auth_request( | |
|
||
#[test] | ||
fn test_auth_request() { | ||
use zeroize::Zeroizing; | ||
|
||
let request = new_auth_request("[email protected]").unwrap(); | ||
|
||
let secret = | ||
"w2LO+nwV4oxwswVYCxlOfRUseXfvU03VzvKQHrqeklPgiMZrspUe6sOBToCnDn9Ay0tuCBn8ykVVRb7PWhub2Q=="; | ||
let secret: &[u8] = &[ | ||
111, 32, 97, 169, 4, 241, 174, 74, 239, 206, 113, 86, 174, 68, 216, 238, 52, 85, 156, 27, | ||
134, 149, 54, 55, 91, 147, 45, 130, 131, 237, 51, 31, 191, 106, 155, 14, 160, 82, 47, 40, | ||
96, 31, 114, 127, 212, 187, 167, 110, 205, 116, 198, 243, 218, 72, 137, 53, 248, 43, 255, | ||
67, 35, 61, 245, 93, | ||
]; | ||
|
||
let private_key = | ||
AsymmetricCryptoKey::from_der(&STANDARD.decode(&request.private_key).unwrap()).unwrap(); | ||
|
||
let encrypted = | ||
AsymmetricEncString::encrypt_rsa2048_oaep_sha1(secret.as_bytes(), &private_key).unwrap(); | ||
let encrypted = AsymmetricEncString::encrypt_rsa2048_oaep_sha1(secret, &private_key).unwrap(); | ||
|
||
let decrypted = auth_request_decrypt_user_key(request.private_key, encrypted).unwrap(); | ||
|
||
assert_eq!(decrypted.to_base64(), secret); | ||
assert_eq!(decrypted.to_vec(), Zeroizing::new(secret.to_owned())); | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -106,7 +111,10 @@ mod tests { | |
use bitwarden_crypto::Kdf; | ||
|
||
use super::*; | ||
use crate::client::{LoginMethod, UserLoginMethod}; | ||
use crate::{ | ||
client::{LoginMethod, UserLoginMethod}, | ||
mobile::crypto::{InitUserCryptoMethod, InitUserCryptoRequest}, | ||
}; | ||
|
||
#[test] | ||
fn test_approve() { | ||
|
@@ -134,4 +142,66 @@ mod tests { | |
|
||
approve_auth_request(&mut client, public_key.to_owned()).unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_device_login() { | ||
let kdf = Kdf::PBKDF2 { | ||
iterations: NonZeroU32::new(600_000).unwrap(), | ||
}; | ||
let email = "[email protected]"; | ||
|
||
let user_key = "2.Q/2PhzcC7GdeiMHhWguYAQ==|GpqzVdr0go0ug5cZh1n+uixeBC3oC90CIe0hd/HWA/pTRDZ8ane4fmsEIcuc8eMKUt55Y2q/fbNzsYu41YTZzzsJUSeqVjT8/iTQtgnNdpo=|dwI+uyvZ1h/iZ03VQ+/wrGEFYVewBUUl/syYgjsNMbE=".parse().unwrap(); | ||
let private_key = "2.yN7l00BOlUE0Sb0M//Q53w==|EwKG/BduQRQ33Izqc/ogoBROIoI5dmgrxSo82sgzgAMI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71bkcMxtB+WM+pn1XNbVTyl9NR040nhP7KEf6e9ruXAtmrBC2ah5cFEpLIot77VFZ9ilLuitSz+7T8n1yAh1IEG6xxXxninAZIzi2qGbH69O5RSpOJuJTv17zTLJQIIc781JwQ2TTwTGnx5wZLbffhCasowJKd2EVcyMJyhz6ru0PvXWJ4hUdkARJs3Xu8dus9a86N8Xk6aAPzBDqzYb1vyFIfBxP0oO8xFHgd30Cgmz8UrSE3qeWRrF8ftrI6xQnFjHBGWD/JWSvd6YMcQED0aVuQkuNW9ST/DzQThPzRfPUoiL10yAmV7Ytu4fR3x2sF0Yfi87YhHFuCMpV/DsqxmUizyiJuD938eRcH8hzR/VO53Qo3UIsqOLcyXtTv6THjSlTopQ+JOLOnHm1w8dzYbLN44OG44rRsbihMUQp+wUZ6bsI8rrOnm9WErzkbQFbrfAINdoCiNa6cimYIjvvnMTaFWNymqY1vZxGztQiMiHiHYwTfwHTXrb9j0uPM=|09J28iXv9oWzYtzK2LBT6Yht4IT4MijEkk0fwFdrVQ4="; | ||
|
||
// Initialize an existing client which is unlocked | ||
let mut existing_device = Client::new(None); | ||
existing_device.set_login_method(LoginMethod::User(UserLoginMethod::Username { | ||
client_id: "123".to_owned(), | ||
email: email.to_owned(), | ||
kdf: kdf.clone(), | ||
})); | ||
|
||
existing_device | ||
.initialize_user_crypto("asdfasdfasdf", user_key, private_key.parse().unwrap()) | ||
.unwrap(); | ||
|
||
// Initialize a new device which will request to be logged in | ||
let mut new_device = Client::new(None); | ||
|
||
// Initialize an auth request, and approve it on the existing device | ||
let auth_req = new_auth_request(email).unwrap(); | ||
let approved_req = approve_auth_request(&mut existing_device, auth_req.public_key).unwrap(); | ||
|
||
// Unlock the vault using the approved request | ||
new_device | ||
.crypto() | ||
.initialize_user_crypto(InitUserCryptoRequest { | ||
kdf_params: kdf, | ||
email: email.to_owned(), | ||
private_key: private_key.to_owned(), | ||
method: InitUserCryptoMethod::AuthRequest { | ||
request_private_key: auth_req.private_key, | ||
protected_user_key: approved_req, | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
// We can validate that the vault is unlocked correctly by confirming the user key is the | ||
// same | ||
assert_eq!( | ||
existing_device | ||
.get_encryption_settings() | ||
.unwrap() | ||
.get_key(&None) | ||
.unwrap() | ||
.to_base64(), | ||
new_device | ||
.get_encryption_settings() | ||
.unwrap() | ||
.get_key(&None) | ||
.unwrap() | ||
.to_base64() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.