-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got rid of the DTOs, properly created the Authorization and MasterKey…
… objects, wrote tests and refactored other tests
- Loading branch information
Showing
25 changed files
with
416 additions
and
279 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using PassFruit.Security.Cryptography; | ||
|
||
namespace PassFruit.Security | ||
{ | ||
public class Authorization | ||
{ | ||
|
||
private const string AuthorizedMessage = "AUTHORIZED"; | ||
|
||
/// <summary> | ||
/// A new message is generated by encrypting a hard coded value with the provided Master Key and random | ||
/// generated Initialization Vector. | ||
/// The message is then passed to the hashing function and the key used is the provided Master Key. | ||
/// </summary> | ||
public Authorization(MasterKey masterKey, Aes aes, HmacSha256 hmacSha256) | ||
: this(masterKey, aes.GenerateInitializationVector(), aes, hmacSha256) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// A message is generated by encrypting a hard coded value with the provided Master Key and | ||
/// Initialization Vector. | ||
/// The message is then passed to the hashing function and the key used is the provided Master Key. | ||
/// </summary> | ||
public Authorization(MasterKey masterKey, byte[] initializationVector, Aes aes, HmacSha256 hmacSha256) | ||
{ | ||
InitializationVector = initializationVector; | ||
var ciphertext = aes.Encrypt(AuthorizedMessage, masterKey.SecretKey, initializationVector); | ||
Hmac = hmacSha256.Compute(ciphertext, masterKey.SecretKey); | ||
} | ||
|
||
public byte[] InitializationVector { get; private set; } | ||
|
||
public byte[] Hmac { get; private set; } | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,22 @@ | ||
namespace PassFruit.Security | ||
{ | ||
public class EncryptedData | ||
{ | ||
public EncryptedData(byte[] salt, byte[] initializationVector, int iterations, byte[] ciphertext) | ||
{ | ||
Ciphertext = ciphertext; | ||
Iterations = iterations; | ||
InitializationVector = initializationVector; | ||
Salt = salt; | ||
} | ||
|
||
public byte[] Salt { get; private set; } | ||
|
||
public byte[] InitializationVector { get; private set; } | ||
|
||
public int Iterations { get; private set; } | ||
|
||
public byte[] Ciphertext { get; private set; } | ||
|
||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using PassFruit.Security.Cryptography; | ||
|
||
namespace PassFruit.Security | ||
{ | ||
public class MasterKey | ||
{ | ||
|
||
public MasterKey(string secretPassword, int iterations, Pbkdf2 pbkdf2) | ||
: this(secretPassword, pbkdf2.GenerateSalt(), iterations, pbkdf2) | ||
{ | ||
|
||
} | ||
|
||
public MasterKey(string secretPassword, byte[] salt, int iterations, Pbkdf2 pbkdf2) | ||
{ | ||
Salt = salt; | ||
SecretKey = pbkdf2.Compute(secretPassword, Salt, iterations); | ||
Iterations = iterations; | ||
} | ||
|
||
/// <summary> | ||
/// The value of the SecretKey should never be stored locally or transmitted on the wire | ||
/// </summary> | ||
public byte[] SecretKey { get; private set; } | ||
|
||
public byte[] Salt { get; private set; } | ||
|
||
public int Iterations { get; private set; } | ||
|
||
} | ||
} |
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.