157 lines
3.1 KiB
C#
157 lines
3.1 KiB
C#
using SPSolutions.Resources;
|
|
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Security.Cryptography;
|
|
using System.Web;
|
|
namespace SPSolutions.Trust
|
|
{
|
|
public class DigestTrustRequest : ITrustRequest
|
|
{
|
|
private string m_validationErrorMessage;
|
|
private string m_digestKeyName;
|
|
private string m_digestValue;
|
|
private string m_digestValueKeyName;
|
|
private HashAlgorithm m_hashAlgorithm;
|
|
private string m_hashKey;
|
|
private bool m_usingUserDefinedHashKey;
|
|
public string DigestValue
|
|
{
|
|
get
|
|
{
|
|
return this.m_digestValue;
|
|
}
|
|
set
|
|
{
|
|
this.m_digestValue = value;
|
|
}
|
|
}
|
|
public string DigestValueKeyName
|
|
{
|
|
get
|
|
{
|
|
if (this.m_digestKeyName == null)
|
|
{
|
|
return ConfigRes.DefaultDigestValueKeyName;
|
|
}
|
|
return this.m_digestValueKeyName;
|
|
}
|
|
set
|
|
{
|
|
this.m_digestValueKeyName = value;
|
|
}
|
|
}
|
|
public string DigestKeyName
|
|
{
|
|
get
|
|
{
|
|
if (this.m_digestKeyName == null)
|
|
{
|
|
return ConfigRes.DefaultDigestKeyName;
|
|
}
|
|
return this.m_digestKeyName;
|
|
}
|
|
set
|
|
{
|
|
this.m_digestKeyName = value;
|
|
}
|
|
}
|
|
public HashAlgorithm HashAlgorithm
|
|
{
|
|
get
|
|
{
|
|
return this.m_hashAlgorithm;
|
|
}
|
|
set
|
|
{
|
|
this.m_hashAlgorithm = value;
|
|
}
|
|
}
|
|
public string HashKey
|
|
{
|
|
get
|
|
{
|
|
return this.m_hashKey;
|
|
}
|
|
set
|
|
{
|
|
this.m_hashKey = value;
|
|
}
|
|
}
|
|
public bool IsValid
|
|
{
|
|
get
|
|
{
|
|
if (this.DigestValue == null || this.DigestValue.Length == 0)
|
|
{
|
|
this.m_validationErrorMessage = StringsRes.DigestTrustRequest_NullOrEmptyDigestValue;
|
|
return false;
|
|
}
|
|
this.m_validationErrorMessage = null;
|
|
return true;
|
|
}
|
|
}
|
|
public bool UsingUserDefinedHashKey
|
|
{
|
|
get
|
|
{
|
|
return this.m_usingUserDefinedHashKey;
|
|
}
|
|
set
|
|
{
|
|
this.m_usingUserDefinedHashKey = value;
|
|
}
|
|
}
|
|
public string ValidationErrorMessage
|
|
{
|
|
get
|
|
{
|
|
return this.m_validationErrorMessage;
|
|
}
|
|
}
|
|
public DigestTrustRequest()
|
|
{
|
|
this.m_usingUserDefinedHashKey = false;
|
|
}
|
|
public DigestTrustRequest(string digestKeyName, string digestValueKeyName) : this()
|
|
{
|
|
this.m_digestKeyName = digestKeyName;
|
|
this.m_digestValueKeyName = digestValueKeyName;
|
|
}
|
|
public string CreateDigest()
|
|
{
|
|
if (this.HashAlgorithm == null)
|
|
{
|
|
throw new TrustException(ErrorsRes.TrustException_NoHashAlgorithm);
|
|
}
|
|
string hashKey = this.HashKey;
|
|
if (hashKey == null || hashKey.Length == 0)
|
|
{
|
|
throw new TrustException(ErrorsRes.TrustException_NoHashKey);
|
|
}
|
|
string input = string.Format("{0}{1}", this.DigestValue, hashKey);
|
|
byte[] input2 = this.HashAlgorithm.ComputeHash(TrustUtil.StringToByteArray(input));
|
|
return TrustUtil.ByteArrayToString(input2);
|
|
}
|
|
public string CreateQueryString(HttpServerUtility httpUtil)
|
|
{
|
|
string text = this.CreateDigest();
|
|
return string.Format("{0}={1}&{2}={3}", new object[]
|
|
{
|
|
this.DigestValueKeyName,
|
|
this.DigestValue,
|
|
this.DigestKeyName,
|
|
text
|
|
});
|
|
}
|
|
public void FillFromQueryString(NameValueCollection queryString)
|
|
{
|
|
this.DigestValue = queryString[this.DigestValueKeyName];
|
|
}
|
|
public bool IsValidDigest(string digest)
|
|
{
|
|
string b = this.CreateDigest();
|
|
return digest == b;
|
|
}
|
|
}
|
|
}
|