Skip to content

Commit

Permalink
fix loading of bitwarden authenticator export
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed May 4, 2024
1 parent 03ae673 commit 4fb4cfd
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ private ConversionResult ConvertVault(Vault vault)
item.Type == LoginType && item.Login != null && !string.IsNullOrEmpty(item.Login.Totp));

var authenticators = new List<Authenticator>();
var categories = vault.Folders.Select(f => f.Convert()).ToList();
var categories = new List<Category>();
var bindings = new List<AuthenticatorCategory>();
var failures = new List<ConversionFailure>();

if (vault.Folders != null)
{
categories.AddRange(vault.Folders.Select(f => f.Convert()));
}

foreach (var item in convertableItems)
{
Expand All @@ -207,7 +212,7 @@ private ConversionResult ConvertVault(Vault vault)

authenticators.Add(auth);

if (item.FolderId != null)
if (vault.Folders != null && item.FolderId != null)
{
var folderName = vault.Folders.First(f => f.Id == item.FolderId).Name;
var category = categories.First(c => c.Name == folderName);
Expand Down
3 changes: 3 additions & 0 deletions AuthenticatorPro.Test/AuthenticatorPro.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
<None Update="data\bitwarden.encrypted.accountrestricted.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\bitwardenauthenticator.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
83 changes: 83 additions & 0 deletions AuthenticatorPro.Test/data/bitwardenauthenticator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"encrypted": false,
"items": [
{
"id": "21442bd8-2e15-4983-9d31-960a46d9e157",
"name": "Standard",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/Standard%3ATotp?secret=54VEGZFJHM3BGDONFERMPUOKNGDJETGM&algorithm=SHA1&digits=6&period=30&issuer=Standard"
},
"favorite": false
},
{
"id": "78b8c94b-f83f-4437-a0a0-d659d337d727",
"name": "NoIssuer",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/NoIssuer%3ANoIssuer?secret=KY2QJPMNQLSGSZE2C5F7AYBLBVEEDHFX&algorithm=SHA1&digits=6&period=30&issuer=NoIssuer"
},
"favorite": false
},
{
"id": "ffd38503-3778-4c03-976e-2f7de2665be9",
"name": "Sha",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/Sha%3A256?secret=RJNZJM7PAGJUBG32XHQWHFZVLYOMGIUQ&algorithm=SHA256&digits=6&period=30&issuer=Sha"
},
"favorite": false
},
{
"id": "5f457f06-d009-4dda-aa13-3efc465be907",
"name": "Sha",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/Sha%3A512?secret=UW33SR5O4EKTDXNCBBS5FSPUKAYXIWOH&algorithm=SHA512&digits=6&period=30&issuer=Sha"
},
"favorite": false
},
{
"id": "376fe2a6-4441-4af1-83ea-24e7cd94e691",
"name": "Many",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/Many%3ADigits?secret=WEV2GHDH4EAU7D5SZGCIQOFBNQ35EHBS&algorithm=SHA1&digits=9&period=30&issuer=Many"
},
"favorite": false
},
{
"id": "57b1a2ec-16e1-4cbf-9a18-ea871a8db739",
"name": "Long",
"folderId": null,
"organizationId": null,
"collectionIds": null,
"notes": null,
"type": 1,
"login": {
"totp": "otpauth://totp/Long%3APeriod?secret=JGRMXBLPPYQIFMRBFQDHNP3MPPYQYNUN&algorithm=SHA1&digits=6&period=60&issuer=Long"
},
"favorite": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,18 @@ await Assert.ThrowsAsync<ArgumentException>(() =>
_bitwardenBackupConverter.ConvertAsync(_bitwardenBackupFixture.EncryptedArgon2IdData,
"wrong password"));
}

[Fact]
public async Task ConvertAsync_authenticator()
{
var result = await _bitwardenBackupConverter.ConvertAsync(_bitwardenBackupFixture.AuthenticatorData);

Assert.Empty(result.Failures);

Assert.Equal(6, result.Backup.Authenticators.Count());
Assert.Empty(result.Backup.Categories);
Assert.Empty(result.Backup.AuthenticatorCategories);
Assert.Null(result.Backup.CustomIcons);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public BitwardenBackupFixture()
EncryptedArgon2IdData = File.ReadAllBytes(Path.Join("data", "bitwarden.encrypted.argon2id.json"));
EncryptedAccountRestrictedData =
File.ReadAllBytes(Path.Join("data", "bitwarden.encrypted.accountrestricted.json"));
AuthenticatorData = File.ReadAllBytes(Path.Join("data", "bitwardenauthenticator.json"));
}

public byte[] Data { get; }
public byte[] EncryptedPbkdf2Data { get; }
public byte[] EncryptedArgon2IdData { get; }
public byte[] EncryptedAccountRestrictedData { get; }
public byte[] AuthenticatorData { get; }
}
}

0 comments on commit 4fb4cfd

Please sign in to comment.