Voici un C# MAC code sample qui pourrait être modifié pour alerter ou enregistrer lorsque l'authentification échoue. Ceci est un échantillon incomplet qui ne devrait pas être utilisé AS-IS car beaucoup d'autres détails doivent être pris en considération avant la mise en œuvre Authenticate-then-Encrypt (AtE)
ou Encrypt-then-Authenticate (EtA)
Il serait bon de savoir ce compteur de performance, le fichier journal ou DLL exception
se rapporte à cette Erreur. J'étudierai BouncyCastle pour voir où se trouve l'exception correspondante.
// Compares the key in the source file with a new key created for the data portion of the file. If the keys
// compare the data has not been tampered with.
public static bool VerifyFile(byte[] key, String sourceFile)
{
bool err = false;
// Initialize the keyed hash object.
using (HMACSHA1 hmac = new HMACSHA1(key))
{
// Create an array to hold the keyed hash value read from the file.
byte[] storedHash = new byte[hmac.HashSize/8];
// Create a FileStream for the source file.
using (FileStream inStream = new FileStream(sourceFile, FileMode.Open))
{
// Read in the storedHash.
inStream.Read(storedHash, 0, storedHash.Length);
// Compute the hash of the remaining contents of the file.
// The stream is properly positioned at the beginning of the content,
// immediately after the stored hash value.
byte[] computedHash = hmac.ComputeHash(inStream);
// compare the computed hash with the stored value
for (int i = 0; i < storedHash.Length; i++)
{
if (computedHash[i] != storedHash[i])
{
err = true;
}
}
}
}
if (err)
{
Console.WriteLine("Hash values differ! Signed file has been tampered with!");
//
//
// <-------- This is where the MAC alerting would go
//
//
return false;
}
else
{
Console.WriteLine("Hash values agree -- no tampering occurred.");
return true;
}
} //end VerifyFile
Peut-être que cela devrait aussi être étiqueté "attaque active"? Je n'ai pas le représentant, donc s'il vous plaît modifier si vous êtes d'accord. – LamonteCristo
Ce n'est pas vraiment clair pour moi ce que vous essayez de faire ... avoir un serveur qui fournit une fonction de connexion, et que vous voulez enregistrer les tentatives d'authentification échouées? (Ce n'est pas vraiment lié à la cryptographie.) –
@ PaŭloEbermann, je ne suis pas intéressé par une question de type Serverfault, mais plutôt pour suivre les violations de code d'authentification de message (MAC) ou tout ce qui indique que l'intégrité a été brisée. – LamonteCristo