Skip to content

Commit

Permalink
Merge branch 'master' into SM-773-bws-no-args-to-stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
tangowithfoxtrot authored Oct 19, 2023
2 parents 790b1be + f51b5b9 commit 660fb5b
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-rust-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/get-keyvault-secrets@c970b0fb89bd966749280e832928db62040812bf
with:
keyvault: "bitwarden-ci"
secrets: "cratesio-api-token"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Download all Release artifacts
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-cli.yml
path: packages
Expand All @@ -67,15 +67,15 @@ jobs:

- name: Dry Run - Download all artifacts
if: ${{ github.event.inputs.release_type == 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-cli.yml
path: packages
workflow_conclusion: success
branch: master

- name: Get checksum files
uses: bitwarden/gh-actions/get-checksum@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/get-checksum@c970b0fb89bd966749280e832928db62040812bf
with:
packages_dir: "packages"
file_path: "packages/bws-sha256-checksums-${{ steps.version.outputs.version }}.txt"
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/get-keyvault-secrets@c970b0fb89bd966749280e832928db62040812bf
with:
keyvault: "bitwarden-ci"
secrets: "cratesio-api-token"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release-napi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Check Release Version
id: version
uses: bitwarden/gh-actions/release-version-check@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/release-version-check@c970b0fb89bd966749280e832928db62040812bf
with:
release-type: ${{ github.event.inputs.release_type }}
project-type: ts
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:

- name: Download schemas
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-napi.yml
artifacts: schemas.ts
Expand All @@ -111,7 +111,7 @@ jobs:

- name: Dry Run - Download schemas
if: ${{ github.event.inputs.release_type == 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-napi.yml
artifacts: schemas.ts
Expand All @@ -132,14 +132,14 @@ jobs:

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/get-keyvault-secrets@c970b0fb89bd966749280e832928db62040812bf
with:
keyvault: "bitwarden-ci"
secrets: "npm-api-key"

- name: Download artifacts
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-napi.yml
path: ${{ github.workspace }}/crates/bitwarden-napi/artifacts
Expand All @@ -148,7 +148,7 @@ jobs:

- name: Dry Run - Download artifacts
if: ${{ github.event.inputs.release_type == 'Dry Run' }}
uses: bitwarden/gh-actions/download-artifacts@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/download-artifacts@c970b0fb89bd966749280e832928db62040812bf
with:
workflow: build-napi.yml
path: ${{ github.workspace }}/crates/bitwarden-napi/artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@f1125802b1ccae8c601d7c4f61ce39ea254b10c8
uses: bitwarden/gh-actions/get-keyvault-secrets@c970b0fb89bd966749280e832928db62040812bf
with:
keyvault: "bitwarden-ci"
secrets: "github-gpg-private-key, github-gpg-private-key-passphrase"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ bench = false

[dependencies]
async-lock = "2.7.0"
chrono = { version = ">=0.4.26, <0.5", features = [
"serde",
"std",
], default-features = false }
env_logger = "0.10.0"
uniffi = "=0.24.1"
schemars = { version = ">=0.8, <0.9", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion crates/bitwarden-uniffi/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use bitwarden::{
client::kdf::Kdf,
mobile::crypto::InitCryptoRequest,
tool::{ExportFormat, PassphraseGeneratorRequest, PasswordGeneratorRequest},
vault::{Cipher, CipherView, Collection, Folder, FolderView, Send, SendListView, SendView},
vault::{
Cipher, CipherView, Collection, Folder, FolderView, Send, SendListView, SendView,
TotpResponse,
},
};
use schemars::JsonSchema;

Expand Down Expand Up @@ -35,4 +38,7 @@ pub enum DocRef {

// Kdf
Kdf(Kdf),

/// TOTP
TotpResponse(TotpResponse),
}
1 change: 1 addition & 0 deletions crates/bitwarden-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bitwarden::{client::client_settings::ClientSettings, mobile::crypto::InitCry
pub mod auth;
mod error;
pub mod tool;
mod uniffi_support;
pub mod vault;

#[cfg(feature = "docs")]
Expand Down
16 changes: 16 additions & 0 deletions crates/bitwarden-uniffi/src/uniffi_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::UniffiCustomTypeConverter;

type DateTime = chrono::DateTime<chrono::Utc>;
uniffi::custom_type!(DateTime, std::time::SystemTime);

impl UniffiCustomTypeConverter for chrono::DateTime<chrono::Utc> {
type Builtin = std::time::SystemTime;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok(Self::from(val))
}

fn from_custom(obj: Self) -> Self::Builtin {
obj.into()
}
}
19 changes: 19 additions & 0 deletions crates/bitwarden-uniffi/src/vault/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::sync::Arc;

use bitwarden::vault::TotpResponse;
use chrono::{DateTime, Utc};

use crate::Client;

pub mod ciphers;
Expand Down Expand Up @@ -37,4 +40,20 @@ impl ClientVault {
pub fn sends(self: Arc<Self>) -> Arc<sends::ClientSends> {
Arc::new(sends::ClientSends(self.0.clone()))
}

/// Generate a TOTP code from a provided key.
///
/// The key can be either:
/// - A base32 encoded string
/// - OTP Auth URI
/// - Steam URI
pub async fn generate_totp(&self, key: String, time: Option<DateTime<Utc>>) -> TotpResponse {
self.0
.0
.read()
.await
.vault()
.generate_totp(key, time)
.await
}
}
3 changes: 2 additions & 1 deletion crates/bitwarden/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.1] - 2023-10-13

### Changed

- `auth::request::AccessTokenLoginRequest` moved to `auth::login::AccessTokenLoginRequest` (#178)

- Support for fetching multiple secrets by ids (#150)

## [0.3.0] - 2023-07-26
Expand Down
18 changes: 18 additions & 0 deletions crates/bitwarden/src/mobile/vault/client_totp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use chrono::{DateTime, Utc};

use crate::vault::{generate_totp, TotpResponse};

use super::client_vault::ClientVault;

impl<'a> ClientVault<'a> {
/// Generate a TOTP code from a provided key.
///
/// Key can be either:
/// - A base32 encoded string
/// - OTP Auth URI
/// - Steam URI
///
pub async fn generate_totp(&'a self, key: String, time: Option<DateTime<Utc>>) -> TotpResponse {
generate_totp(key, time).await
}
}
1 change: 1 addition & 0 deletions crates/bitwarden/src/mobile/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mod client_collection;
mod client_folders;
mod client_password_history;
mod client_sends;
mod client_totp;
mod client_vault;
2 changes: 2 additions & 0 deletions crates/bitwarden/src/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ mod collection;
mod folder;
mod password_history;
mod send;
mod totp;

pub use cipher::{Cipher, CipherListView, CipherView};
pub use collection::{Collection, CollectionView};
pub use folder::{Folder, FolderView};
pub use password_history::{PasswordHistory, PasswordHistoryView};
pub use send::{Send, SendListView, SendView};
pub use totp::{generate_totp, TotpResponse};
30 changes: 30 additions & 0 deletions crates/bitwarden/src/vault/totp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct TotpResponse {
/// Generated TOTP code
pub code: String,
/// Time period
pub period: u32,
}

/// Generate a OATH or RFC 6238 TOTP code from a provided key.
///
/// <https://datatracker.ietf.org/doc/html/rfc6238>
///
/// Key can be either:
/// - A base32 encoded string
/// - OTP Auth URI
/// - Steam URI
///
/// Supports providing an optional time, and defaults to current system time if none is provided.
pub async fn generate_totp(_key: String, _time: Option<DateTime<Utc>>) -> TotpResponse {
TotpResponse {
code: "000 000".to_string(),
period: 30,
}
}
2 changes: 2 additions & 0 deletions crates/bws/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.1] - 2023-10-13

### Added

- Support for shell autocompletion with the `bws completions` command (#103)
Expand Down
52 changes: 45 additions & 7 deletions languages/kotlin/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,24 @@ Sends operations

**Output**: Arc<sends::ClientSends>

### `generate_totp`

Generate a TOTP code from a provided key.

The key can be either:

- A base32 encoded string
- OTP Auth URI
- Steam URI

**Arguments**:

- self:
- key: String
- time: Option<DateTime>

**Output**: [TotpResponse](#totpresponse)

# References

References are generated from the JSON schemas and should mostly match the kotlin and swift
Expand Down Expand Up @@ -541,17 +559,17 @@ implementations.
</tr>
<tr>
<th>attachments</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
<th>fields</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
<th>passwordHistory</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
Expand Down Expand Up @@ -606,7 +624,7 @@ implementations.
</tr>
<tr>
<th>notes</th>
<th>string</th>
<th>string,null</th>
<th></th>
</tr>
<tr>
Expand Down Expand Up @@ -666,17 +684,17 @@ implementations.
</tr>
<tr>
<th>attachments</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
<th>fields</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
<th>passwordHistory</th>
<th>array</th>
<th>array,null</th>
<th></th>
</tr>
<tr>
Expand Down Expand Up @@ -1253,3 +1271,23 @@ implementations.
<th></th>
</tr>
</table>

## `TotpResponse`

<table>
<tr>
<th>Key</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<th>code</th>
<th>string</th>
<th>Generated TOTP code</th>
</tr>
<tr>
<th>period</th>
<th>integer</th>
<th>Time period</th>
</tr>
</table>

0 comments on commit 660fb5b

Please sign in to comment.