Skip to content

Commit

Permalink
KSM-550 Stop generating UIDs that start with "-" (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
idimov-keeper authored Sep 4, 2024
1 parent f7ec4fb commit 5ee4eba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions sdk/dotNet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

# Change Log

## 16.6.7

* KSM-550 - Stop generating UIDs that start with "-"

## 16.6.6

* KSM-360 - GHA to build and release strong named assemblies
Expand Down
13 changes: 13 additions & 0 deletions sdk/dotNet/SecretsManager/CryptoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ public static byte[] GetRandomBytes(int length)
return bytes;
}

public static byte[] GetUidBytes()
{
byte dash = 0b1111_1000;
var bytes = new byte[] { };
for (int i = 0; i < 8; i++) {
bytes = GetRandomBytes(16);
if ((dash & bytes[0]) != dash) break;
}
if ((dash & bytes[0]) == dash)
bytes[0] = (byte)(bytes[0] & (byte)0b0111_1111);
return bytes;
}

public static byte[] GenerateKeyPair()
{
var keyGenerator = new ECKeyPairGenerator();
Expand Down
6 changes: 3 additions & 3 deletions sdk/dotNet/SecretsManager/SecretsManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<LangVersion>9</LangVersion>
<Company>Keeper Security Inc.</Company>
<Product>SecretsManager .Net SDK</Product>
<AssemblyVersion>16.6.6</AssemblyVersion>
<FileVersion>16.6.6</FileVersion>
<PackageVersion>16.6.6</PackageVersion>
<AssemblyVersion>16.6.7</AssemblyVersion>
<FileVersion>16.6.7</FileVersion>
<PackageVersion>16.6.7</PackageVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<PackageId>Keeper.SecretsManager</PackageId>
<Authors>Sergey Aldoukhov</Authors>
Expand Down
4 changes: 2 additions & 2 deletions sdk/dotNet/SecretsManager/SecretsManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ private static CreatePayload PrepareCreatePayload(IKeyValueStorage storage, Crea

var recordBytes = JsonUtils.SerializeJson(recordData);
var recordKey = CryptoUtils.GetRandomBytes(32);
var recordUid = CryptoUtils.GetRandomBytes(16);
var recordUid = CryptoUtils.GetUidBytes();
var encryptedRecord = CryptoUtils.Encrypt(recordBytes, recordKey);
var encryptedRecordKey = CryptoUtils.PublicEncrypt(recordKey, ownerPublicKey);
var encryptedFolderKey = CryptoUtils.Encrypt(recordKey, folderKey);
Expand All @@ -1283,7 +1283,7 @@ private static CreateFolderPayload PrepareCreateFolderPayload(IKeyValueStorage s

var folderDataBytes = JsonUtils.SerializeJson(new KeeperFolderName { name = folderName });
var folderKey = CryptoUtils.GetRandomBytes(32);
var folderUid = CryptoUtils.GetRandomBytes(16);
var folderUid = CryptoUtils.GetUidBytes();
var encryptedFolderData = CryptoUtils.Encrypt(folderDataBytes, folderKey, true);
var encryptedFolderKey = CryptoUtils.Encrypt(folderKey, sharedFolderKey, true);

Expand Down

0 comments on commit 5ee4eba

Please sign in to comment.