Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
//
// AsymmetricSecurityKey.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
namespace System.IdentityModel.Tokens
{
public abstract class AsymmetricSecurityKey : SecurityKey
{
protected AsymmetricSecurityKey ()
{
}
public abstract AsymmetricAlgorithm GetAsymmetricAlgorithm (
string algorithm, bool privateKey);
public abstract HashAlgorithm GetHashAlgorithmForSignature (
string algorithm);
public abstract AsymmetricSignatureDeformatter GetSignatureDeformatter (string algorithm);
public abstract AsymmetricSignatureFormatter GetSignatureFormatter (string algorithm);
public abstract bool HasPrivateKey ();
}
}

View File

@@ -0,0 +1,86 @@
//
// BinaryKeyIdentifierClause.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
namespace System.IdentityModel.Tokens
{
public abstract class BinaryKeyIdentifierClause : SecurityKeyIdentifierClause
{
protected BinaryKeyIdentifierClause (string clauseType, byte [] identificationData, bool cloneBuffer)
: this (clauseType, identificationData, cloneBuffer, null, 0)
{
}
protected BinaryKeyIdentifierClause (string clauseType, byte [] identificationData, bool cloneBuffer, byte [] derivationNonce, int derivationLength)
: base (clauseType, derivationNonce, derivationLength)
{
this.data = cloneBuffer ?
(byte []) identificationData.Clone () :
identificationData;
}
byte [] data;
public byte [] GetBuffer ()
{
return (byte []) GetRawBuffer ().Clone ();
}
public override bool Matches (SecurityKeyIdentifierClause clause)
{
BinaryKeyIdentifierClause other =
clause as BinaryKeyIdentifierClause;
if (other == null)
return false;
return Matches (other.GetRawBuffer ());
}
public bool Matches (byte [] data)
{
return Matches (data, 0);
}
public bool Matches (byte [] data, int offset)
{
if (data.Length + offset != this.data.Length)
return false;
for (int i = 0; i < this.data.Length; i++)
if (data [i + offset] != this.data [i])
return false;
return true;
}
protected byte [] GetRawBuffer ()
{
return data;
}
}
}

View File

@@ -0,0 +1,334 @@
2010-07-26 Atsushi Enomoto <atsushi@ximian.com>
* SamlSubject.cs : add missing .ctor().
2007-11-27 Atsushi Enomoto <atsushi@ximian.com>
* SecurityKeyIdentifier.cs : fill 'out' parameter properly (gmcs
does not report this as error; see bug #334258).
2007-02-21 Atsushi Enomoto <atsushi@ximian.com>
* InMemorySymmetricSecurityKey.cs : added some argument check.
2007-02-15 Atsushi Enomoto <atsushi@ximian.com>
* SecurityKeyIdentifier.cs : implemented all.
* EncryptedKeyIdentifierClause.cs : forgot to commit; importtant
"return false" was missing.
2007-02-05 Atsushi Enomoto <atsushi@ximian.com>
* InMemorySymmetricSecurityKey.cs, SecurityKey.cs,
X509AsymmetricSecurityKey.cs :
implemented [IsSupported|IsSymmetric|IsAsymmetric]Algorithm.
2007-02-05 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs :
implemented GetHashAlgorithmForSignature().
2007-01-31 Atsushi Enomoto <atsushi@ximian.com>
* InMemorySymmetricSecurityKey.cs : implemented some algorithm related
members.
* X509ThumbprintKeyIdentifierClause.cs : thumbprint comparison was
broken. Now it compares byte sequences.
* SecurityTokenResolver.cs : (removed MonoTODO.)
2007-01-11 Atsushi Enomoto <atsushi@ximian.com>
* X509IssuerSerialKeyIdentifierClause.cs : fixed previous change,
and check null argument.
2007-01-11 Atsushi Enomoto <atsushi@ximian.com>
* X509IssuerSerialKeyIdentifierClause.cs,
X509ThumbprintKeyIdentifierClause.cs : clause type is null.
2006-12-06 Atsushi Enomoto <atsushi@ximian.com>
* X509IssuerSerialKeyIdentifierClause.cs : IssuerSerialNumber is a
decimal string.
2006-10-29 Atsushi Enomoto <atsushi@ximian.com>
* SamlSubject.cs
SamlAuthorizationDecisionStatement.cs
SamlAssertion.cs
SamlConditions.cs
SamlAudienceRestrictionCondition.cs
SamlDoNotCacheCondition.cs
SamlEvidence.cs
SamlSubjectStatement.cs
SamlAdvice.cs
SamlAttribute.cs
SamlAuthenticationStatement.cs
SamlConstants.cs
SamlAction.cs
SamlAuthorityBinding.cs : implemented all WriteXml() and some of
ReadXml(). A couple of more API fixes.
2006-10-12 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs : implemented IsSupportedAlgorithm().
* EncryptedKeyIdentifierClause.cs : implemented.
* AsymmetricSecurityKey.cs : removed MonoTODO.
2006-10-03 Atsushi Enomoto <atsushi@ximian.com>
* SamlSerializer.cs : fixed API; ReadXml()->ReadToken().
* SamlAuthenticationClaimResource.cs : fixed breakage when it becomes
part of the build.
* SamlDoNotCacheCondition.cs, SamlNameIdentifierClaimResource.cs :
new files.
* Dummy.cs : removed. Now we can live without this.
* X509SecurityToken.cs : fix API (virtualize Dispose()).
2006-10-03 Atsushi Enomoto <atsushi@ximian.com>
* SamlAuthorizationDecisionStatement.cs,
SamlConditions.cs,
SamlAudienceRestrictionCondition.cs,
SamlEvidence.cs,
SamlAuthenticationClaimResource.cs,
SamlSerializer.cs,
SamlAuthorityBinding.cs,
SamlCondition.cs,
SamlAuthorizationDecisionClaimResource.cs : new files.
* Dummy.cs : removed all above.
* SamlSubject.cs : added missing members.
* X509SecurityToken.cs : seems like it does not use urn:uuid.
2006-09-27 Atsushi Enomoto <atsushi@ximian.com>
* LocalIdKeyIdentifierClause.cs : implemented Matches().
2006-09-22 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs : use EncryptedXml.DecryptKey() in
DecryptKey() to just reuse correct implementation.
Implemented EncryptKey().
2006-09-22 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs : fixed GetAsymmetricAlgorithm().
(URI, useOAEP)
2006-09-14 Atsushi Enomoto <atsushi@ximian.com>
* Dummy.cs : added more types.
* SecurityAlgorithms.cs : fixed consts.
2006-09-14 Atsushi Enomoto <atsushi@ximian.com>
* UserNameSecurityToken.cs, RsaSecurityToken.cs : implemented.
2006-09-12 Atsushi Enomoto <atsushi@ximian.com>
* SecurityKeyIdentifierClause.cs : avoid NRE on null nonce.
2006-09-12 Atsushi Enomoto <atsushi@ximian.com>
* SigningCredentials.cs : new file.
* Dummy.cs : removed above.
* X509ThumbprintKeyIdentifierClause.cs,
X509SubjectKeyIdentifierClause.cs :
API fix and removed unused field.
* RsaSecurityKey.cs, RsaKeyIdentifierClause.cs :
Implemented some members.
* SecurityKeyIdentifierClause.cs, LocalIdKeyIdentifierClause.cs,
BinaryKeyIdentifierClause.cs : Added missing nonce info.
* SamlAttribute.cs : fixed warned code: raise an error.
2006-09-12 Atsushi Enomoto <atsushi@ximian.com>
* X509RawDataKeyIdentifierClause.cs,
X509IssuerSerialKeyIdentifierClause.cs,
BinaryKeyIdentifierClause.cs: implemented several members.
* SecurityToken.cs : implemented MatchesKeyIdentifierClause() and
ResolveKeyIdentifierClause().
* X509SecurityToken.cs : implemented MatchesKeyIdentifierClause().
* SecurityKeyIdentifierClause.cs : implemented CanCreateKey and
CreateKey().
2006-09-12 Atsushi Enomoto <atsushi@ximian.com>
* SecurityAlgorithms.cs : added missing constants.
* X509AsymmetricSecurityKey.cs : implemented GetAsymmetricAlgorithm().
* LocalIdKeyIdentifierClause.cs : added missing bits.
2006-09-07 Atsushi Enomoto <atsushi@ximian.com>
* SamlConstants.cs : implemented.
* SamlAttributeStatement.cs :
Correct constructor chain. implemented WriteXml().
* SamlAttribute.cs : implemented WriteXml(). API updates.
* SamlSubjectStatement.cs : null arg check.
* SamlAssertion.cs : write prefix.
Pass through NullImplementedException in WriteXml().
* SamlSubject.cs : implemented several members.
2006-09-07 Atsushi Enomoto <atsushi@ximian.com>
* SamlSubject.cs, SamlConstants.cs : added missing classes.
* Dummy.cs : removed above.
* SamlAssertion.cs : implemented WriteXml() and more .ctor()
argument check.
* SamlAttribute.cs : added missing .ctor().
* SamlAttributeStatement.cs : derive from SamlSubjectStatement.
* SecurityAlgorithms.cs : updated WS-SC P_SHA1 URI.
* TlsHMAC.cs : new support file, copied from Mono.Security.
(WS-SecureConversation uses P_SHA from RFC 2246.)
* InMemorySymmetricSecurityKey.cs : partly implemented
GetSymmetricAlgorithm() and GenerateDerivedKey().
* X509AsymmetricSecurityKey.cs : partly implement EncryptKey.
2006-09-04 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs : partial GetAsymmetricAlgorithm()
implementation. Implement DecryptKey().
* X509ThumbprintKeyIdentifierClause.cs : certificate could be null
through the entire class.
* SamlStatement.cs, SamlSubjectStatement.cs,
SamlAuthenticationStatement.cs : added missing members.
* SamlAssertion.cs : added missing members. implemented .ctor().
2006-09-01 Atsushi Enomoto <atsushi@ximian.com>
* X509AsymmetricSecurityKey.cs : partly implemented.
2006-08-28 Atsushi Enomoto <atsushi@ximian.com>
* X509ThumbprintKeyIdentifierClause.cs : implemented .ctor(),
CreateKey() and Matches().
2006-08-14 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenTypes.cs : implemented.
2006-08-04 Atsushi Enomoto <atsushi@ximian.com>
* InMemorySymmetricSecurityKey.cs : added another .ctor().
* X509SecurityToken.cs : implemented [Can]CreateKeyIdentifierClause().
* SecurityKeyIdentifier.cs : .ctor() accepts varargs.
2006-08-04 Atsushi Enomoto <atsushi@ximian.com>
* InMemorySymmetricSecurityKey.cs : oops, it was not added.
* GenericXmlSecurityToken.cs : added missing members.
* UserNameSecurityToken.cs : ValidFrom should be fixed value.
2006-08-04 Atsushi Enomoto <atsushi@ximian.com>
* X509IssuerSerialKeyIdentifierClause.cs : some annotations.
* InMemorySymmetricSecurityKey.cs :
new file required by BinarySecurityToken.
2006-08-01 Atsushi Enomoto <atsushi@ximian.com>
* UserNameSecurityToken.cs : implemented.
2006-07-31 Atsushi Enomoto <atsushi@ximian.com>
* X509SecurityToken.cs : implemented some members.
2006-07-18 Atsushi Enomoto <atsushi@ximian.com>
* GenericXmlSecurityToken.cs : added.
2006-07-04 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenTypes.cs : added missing type.
2006-07-04 Atsushi Enomoto <atsushi@ximian.com>
* SamlAssertion.cs, SamlSubjectStatement.cs, SamlAdvice.cs,
SamlAttribute.cs, SamlAuthenticationStatement.cs, SamlStatement.cs
SamlAction.cs, Dummy.cs, SamlAttributeStatement.cs:
some June CTP updates.
* SymmetricKey.cs : removed old code.
2006-03-23 Atsushi Enomoto <atsushi@ximian.com>
* SecurityKeyType.cs SecurityKeyUsage.cs : new enums.
* Dummy.cs : removed above.
2006-03-22 Atsushi Enomoto <atsushi@ximian.com>
* SecurityKeyIdentifierClause.cs SecurityTokenException.cs
BinaryKeyIdentifierClause.cs LocalIdKeyIdentifierClause.cs
X509IssuerSerialKeyIdentifierClause.cs
X509RawDataKeyIdentifierClause.cs
SecurityKeyIdentifier.cs X509ThumbprintKeyIdentifierClause.cs
SamlAssertionKeyIdentifierClause.cs RsaKeyIdentifierClause.cs
X509SubjectKeyIdentifierClause.cs
SecurityTokenValidationException.cs
EncryptedKeyIdentifierClause.cs :
new stubs for SecurityKeyIdentifierClause and Exception classes
in Feb. CTP.
* Dummy.cs : removed above.
2006-03-22 Atsushi Enomoto <atsushi@ximian.com>
* SecurityToken.cs : updated to Feb.CTP API.
* RsaSecurityToken.cs KerberosRequestorSecurityToken.cs
WindowsSecurityToken.cs SamlSecurityToken.cs
KerberosReceiverSecurityToken.cs X509SecurityToken.cs
UserNameSecurityToken.cs X509WindowsSecurityToken.cs :
new stubs for SecurityToken classes in Feb.CTP.
* Dummy.cs : removed all above.
2006-03-22 Atsushi Enomoto <atsushi@ximian.com>
* SymmetricSecurityKey.cs AsymmetricSecurityKey.cs SecurityKey.cs
SymmetricKey.cs RsaSecurityKey.cs X509AsymmetricSecurityKey.cs :
stubs for SecurityKey classes in Feb.CTP.
* Dummy.cs : removed all above.
2006-02-23 Atsushi Enomoto <atsushi@ximian.com>
* Dummy.cs SamlAccessDecision.cs SamlAction.cs SamlAdvice.cs
SamlAssertion.cs SamlAttribute.cs SamlAttributeStatement.cs
SamlAuthenticationStatement.cs SamlStatement.cs
SamlSubjectStatement.cs SecurityAlgorithms.cs SecurityToken.cs
SecurityTokenProvider.cs SecurityTokenResolver.cs :
Moving namespaces to System.IdentityModel.*.
2006-02-23 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenResolver.cs : some members are removed (by nature of
System.ServiceModel.dll independency).
2006-02-23 Atsushi Enomoto <atsushi@ximian.com>
* SamlAccessDecision.cs SamlAction.cs SamlAdvice.cs
SamlAssertion.cs SamlAttribute.cs SamlAttributeStatement.cs
SamlAuthenticationStatement.cs SamlStatement.cs
SamlSubjectStatement.cs SecurityToken.cs :
Feb. CTP API changes - chapter 1.
2006-01-19 Atsushi Enomoto <atsushi@ximian.com>
* SamlStatement.cs : update to be in sync with sys.sec.auth changes.
2005-10-31 Atsushi Enomoto <atsushi@ximian.com>
* SecurityToken.cs : new file.
* Dummy.cs : removed above.
2005-09-29 Atsushi Enomoto <atsushi@ximian.com>
* SamlAttribute.cs, SamlAuthenticationStatement.cs, SamlStatement.cs
SamlSubjectStatement.cs, SamlAttributeStatement.cs :
Warning fix; signatures and unused methods. More readonly check.
2005-09-28 Atsushi Enomoto <atsushi@ximian.com>
* SamlAccessDecision.cs, SamlAttribute.cs,
SamlAuthenticationStatement.cs, SamlStatement.cs,
SamlSubjectStatement.cs, SamlAssertion.cs,
SamlAttributeStatement.cs, SamlAdvice.cs, SamlAction.cs : new files.
* Dummy.cs : removed those classes above.

View File

@@ -0,0 +1,116 @@
//
// EncryptedKeyIdentifierClause.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
namespace System.IdentityModel.Tokens
{
public sealed class EncryptedKeyIdentifierClause : BinaryKeyIdentifierClause
{
public EncryptedKeyIdentifierClause (
byte [] encryptedKey, string encryptionMethod)
: this (encryptedKey, encryptionMethod, null)
{
}
public EncryptedKeyIdentifierClause (
byte [] encryptedKey, string encryptionMethod,
SecurityKeyIdentifier identifier)
: this (encryptedKey, encryptionMethod, identifier, null)
{
}
public EncryptedKeyIdentifierClause (
byte [] encryptedKey, string encryptionMethod,
SecurityKeyIdentifier identifier, string carriedKeyName)
: this (encryptedKey, encryptionMethod, identifier, carriedKeyName, null, 0)
{
}
public EncryptedKeyIdentifierClause (
byte [] encryptedKey, string encryptionMethod,
SecurityKeyIdentifier identifier, string carriedKeyName,
byte [] derivationNonce, int derivationLength)
: base (encryptionMethod, encryptedKey, true, derivationNonce, derivationLength)
{
this.carried_key_name = carriedKeyName;
this.identifier = identifier;
this.enc_method = encryptionMethod;
}
string carried_key_name, enc_method;
SecurityKeyIdentifier identifier;
public string CarriedKeyName {
get { return carried_key_name; }
}
public string EncryptionMethod {
get { return enc_method; }
}
public SecurityKeyIdentifier EncryptingKeyIdentifier {
get { return identifier; }
}
public byte [] GetEncryptedKey ()
{
return GetBuffer ();
}
public bool Matches (byte [] encryptedKey, string encryptionMethod, string carriedKeyName)
{
if (encryptedKey == null)
throw new ArgumentNullException ("encryptedKey");
byte [] buf = GetRawBuffer ();
if (encryptionMethod != this.enc_method ||
carriedKeyName != this.carried_key_name ||
encryptedKey.Length != buf.Length)
return false;
for (int i = 0; i < buf.Length; i++)
if (encryptedKey [i] != buf [i])
return false;
return true;
}
public override bool Matches (SecurityKeyIdentifierClause clause)
{
EncryptedKeyIdentifierClause e =
clause as EncryptedKeyIdentifierClause;
return e != null && Matches (e.GetRawBuffer (), e.EncryptionMethod, e.CarriedKeyName);
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
}
}

View File

@@ -0,0 +1,119 @@
//
// GenericXmlSecurityToken.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Principal;
namespace System.IdentityModel.Tokens
{
public class GenericXmlSecurityToken : SecurityToken
{
XmlElement xml;
SecurityToken proof_token;
DateTime from, to;
SecurityKeyIdentifierClause int_tokenref, ext_tokenref;
ReadOnlyCollection<IAuthorizationPolicy> auth_policies;
public GenericXmlSecurityToken (
XmlElement tokenXml,
SecurityToken proofToken,
DateTime effectiveTime,
DateTime expirationTime,
SecurityKeyIdentifierClause internalTokenReference,
SecurityKeyIdentifierClause externalTokenReference,
ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies)
{
xml = tokenXml;
proof_token = proofToken;
from = effectiveTime;
to = expirationTime;
int_tokenref = internalTokenReference;
ext_tokenref = externalTokenReference;
auth_policies = authorizationPolicies;
}
[MonoTODO] // verify
public override string Id {
get { return proof_token.Id; }
}
public XmlElement TokenXml {
get { return xml; }
}
public SecurityToken ProofToken {
get { return proof_token; }
}
public override DateTime ValidFrom {
get { return from; }
}
public override DateTime ValidTo {
get { return to; }
}
public SecurityKeyIdentifierClause InternalTokenReference {
get { return int_tokenref; }
}
public SecurityKeyIdentifierClause ExternalTokenReference {
get { return ext_tokenref; }
}
public ReadOnlyCollection<IAuthorizationPolicy> AuthorizationPolicies {
get { return auth_policies; }
}
[MonoTODO]
public override ReadOnlyCollection<SecurityKey> SecurityKeys {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override bool CanCreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override T CreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool MatchesKeyIdentifierClause (
SecurityKeyIdentifierClause skiClause)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,235 @@
//
// InMemorySymmetricSecurityKey.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006-2007 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using M = Mono.Security.Cryptography;
using AES = System.Security.Cryptography.RijndaelManaged;
namespace System.IdentityModel.Tokens
{
public class InMemorySymmetricSecurityKey : SymmetricSecurityKey
{
byte [] key;
public InMemorySymmetricSecurityKey (byte [] key)
: this (key, true)
{
}
public InMemorySymmetricSecurityKey (byte [] key, bool clone)
{
if (key == null)
throw new ArgumentNullException ("key");
this.key = clone ? (byte []) key.Clone() : key;
}
// SymmetricSecurityKey implementation
public override byte [] GenerateDerivedKey (
string algorithm, byte [] label, byte [] nonce,
int derivedKeyLength, int offset)
{
if (derivedKeyLength < 0)
throw new ArgumentOutOfRangeException ("derivedKeyLength");
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset");
if (label == null)
throw new ArgumentNullException ("label");
if (nonce == null)
throw new ArgumentNullException ("nonce");
if (algorithm != SecurityAlgorithms.Psha1KeyDerivation)
throw new InvalidOperationException (String.Format ("Key derivation algorithm '{0}' is not supported", algorithm));
byte [] seed = new byte [label.Length + nonce.Length];
Array.Copy (label, seed, label.Length);
Array.Copy (nonce, 0, seed, label.Length, nonce.Length);
byte [] p_sha = Expand ("SHA1", key, seed, derivedKeyLength / 8);
return p_sha;
}
// from Mono.Security.Protocol.Tls.CipherSuite.Expand() with
// a bit of modification ...
byte [] Expand (string hashName, byte[] secret, byte[] seed, int length)
{
int hashLength = hashName == "MD5" ? 16 : 20;
int iterations = (int)(length / hashLength);
if ((length % hashLength) > 0)
{
iterations++;
}
M.HMAC hmac = new M.HMAC(hashName, secret);
MemoryStream resMacs = new MemoryStream ();
byte[][] hmacs = new byte[iterations + 1][];
hmacs[0] = seed;
for (int i = 1; i <= iterations; i++)
{
MemoryStream hcseed = new MemoryStream ();
hmac.TransformFinalBlock(hmacs[i-1], 0, hmacs[i-1].Length);
hmacs[i] = hmac.Hash;
hcseed.Write(hmacs[i], 0, hmacs [i].Length);
hcseed.Write(seed, 0, seed.Length);
hmac.TransformFinalBlock(hcseed.ToArray(), 0, (int)hcseed.Length);
resMacs.Write(hmac.Hash, 0, hmac.Hash.Length);
}
byte[] res = new byte[length];
Buffer.BlockCopy(resMacs.ToArray(), 0, res, 0, res.Length);
return res;
}
public override byte [] GetSymmetricKey ()
{
return (byte []) key.Clone ();
}
public override KeyedHashAlgorithm GetKeyedHashAlgorithm (
string algorithm)
{
if (algorithm == SecurityAlgorithms.HmacSha1Signature)
return new HMACSHA1 (key);
//if (algorithm == SecurityAlgorithms.HmacSha256Signature)
// return new HMACSHA256 (key);
throw new NotSupportedException ();
}
public override SymmetricAlgorithm GetSymmetricAlgorithm (string algorithm)
{
SymmetricAlgorithm s = null;
switch (algorithm) {
case SecurityAlgorithms.Aes128Encryption:
case SecurityAlgorithms.Aes192Encryption:
case SecurityAlgorithms.Aes256Encryption:
case SecurityAlgorithms.Aes128KeyWrap:
case SecurityAlgorithms.Aes192KeyWrap:
case SecurityAlgorithms.Aes256KeyWrap:
s = new AES ();
break;
case SecurityAlgorithms.TripleDesEncryption:
case SecurityAlgorithms.TripleDesKeyWrap:
if (key.Length == 24)
throw new CryptographicException ("The key size is 24 bytes, which known as vulnerable and thus not allowed.");
s = TripleDES.Create ();
break;
default:
throw new NotSupportedException (String.Format ("This symmetric security key does not support specified algorithm '{0}'", algorithm));
}
s.Mode = CipherMode.CBC;
s.GenerateIV ();
s.Key = key;
return s;
}
public override ICryptoTransform GetDecryptionTransform (string algorithm, byte [] iv)
{
if (iv == null)
throw new ArgumentNullException ("iv");
SymmetricAlgorithm alg = GetSymmetricAlgorithm (algorithm);
alg.IV = iv;
return alg.CreateDecryptor ();
}
public override ICryptoTransform GetEncryptionTransform (string algorithm, byte [] iv)
{
if (iv == null)
throw new ArgumentNullException ("iv");
SymmetricAlgorithm alg = GetSymmetricAlgorithm (algorithm);
alg.IV = iv;
return alg.CreateEncryptor ();
}
[MonoTODO]
public override int GetIVSize (string algorithm)
{
throw new NotImplementedException ();
}
// SecurityKey implementation
public override int KeySize {
get { return key.Length << 3; }
}
public override byte [] DecryptKey (string algorithm, byte [] keyData)
{
if (algorithm == null)
throw new ArgumentNullException ("algorithm");
if (keyData == null)
throw new ArgumentNullException ("keyData");
return EncryptedXml.DecryptKey (keyData, GetSymmetricAlgorithm (algorithm));
}
public override byte [] EncryptKey (string algorithm, byte [] keyData)
{
if (algorithm == null)
throw new ArgumentNullException ("algorithm");
if (keyData == null)
throw new ArgumentNullException ("keyData");
return EncryptedXml.EncryptKey (keyData, GetSymmetricAlgorithm (algorithm));
}
public override bool IsAsymmetricAlgorithm (string algorithm)
{
return GetAlgorithmSupportType (algorithm) == AlgorithmSupportType.Asymmetric;
}
public override bool IsSupportedAlgorithm (string algorithm)
{
switch (algorithm) {
case SecurityAlgorithms.HmacSha1Signature:
case SecurityAlgorithms.Psha1KeyDerivation:
case SecurityAlgorithms.Aes128Encryption:
case SecurityAlgorithms.Aes128KeyWrap:
case SecurityAlgorithms.Aes192Encryption:
case SecurityAlgorithms.Aes192KeyWrap:
case SecurityAlgorithms.Aes256Encryption:
case SecurityAlgorithms.Aes256KeyWrap:
case SecurityAlgorithms.TripleDesEncryption:
case SecurityAlgorithms.TripleDesKeyWrap:
return true;
default:
return false;
}
}
public override bool IsSymmetricAlgorithm (string algorithm)
{
return GetAlgorithmSupportType (algorithm) == AlgorithmSupportType.Symmetric;
}
}
}

View File

@@ -0,0 +1,86 @@
//
// KerberosReceiverSecurityToken.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Principal;
namespace System.IdentityModel.Tokens
{
public class KerberosReceiverSecurityToken : WindowsSecurityToken
{
[MonoTODO]
public KerberosReceiverSecurityToken (byte [] request)
{
throw new NotImplementedException ();
}
[MonoTODO]
public KerberosReceiverSecurityToken (byte [] request, string id)
{
throw new NotImplementedException ();
}
[MonoTODO]
public SymmetricSecurityKey SecurityKey {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override ReadOnlyCollection<SecurityKey> SecurityKeys {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override bool CanCreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override T CreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool MatchesKeyIdentifierClause (
SecurityKeyIdentifierClause skiClause)
{
throw new NotImplementedException ();
}
[MonoTODO]
public byte [] GetRequest ()
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,112 @@
//
// KerberosRequestorSecurityToken.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Principal;
namespace System.IdentityModel.Tokens
{
public class KerberosRequestorSecurityToken : SecurityToken
{
[MonoTODO]
public KerberosRequestorSecurityToken (string servicePrincipalName)
{
throw new NotImplementedException ();
}
[MonoTODO]
public KerberosRequestorSecurityToken (
string servicePrincipalName,
TokenImpersonationLevel tokenImpersonationLevel,
NetworkCredential networkCredential,
string id)
{
throw new NotImplementedException ();
}
NetworkCredential cred;
TokenImpersonationLevel imp_level;
string svc_principal_name, id;
public string ServicePrincipalName {
get { return svc_principal_name; }
}
[MonoTODO]
public SymmetricSecurityKey SecurityKey {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override DateTime ValidFrom {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override DateTime ValidTo {
get { throw new NotImplementedException (); }
}
public override string Id {
get { return id; }
}
[MonoTODO]
public override ReadOnlyCollection<SecurityKey> SecurityKeys {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override bool CanCreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override T CreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool MatchesKeyIdentifierClause (
SecurityKeyIdentifierClause skiClause)
{
throw new NotImplementedException ();
}
[MonoTODO]
public byte [] GetRequest ()
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,85 @@
//
// LocalIdKeyIdentifierClause.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
namespace System.IdentityModel.Tokens
{
public class LocalIdKeyIdentifierClause : SecurityKeyIdentifierClause
{
public LocalIdKeyIdentifierClause (string localId)
: this (localId, null)
{
}
public LocalIdKeyIdentifierClause (string localId, Type ownerType)
: this (localId, null, 0, ownerType)
{
}
public LocalIdKeyIdentifierClause (string localId, byte [] derivationNonce, int derivationLength, Type ownerType)
: base (localId, derivationNonce, derivationLength)
{
local_id = localId;
owner_type =ownerType;
}
string local_id;
Type owner_type;
public string LocalId {
get { return local_id; }
}
public Type OwnerType {
get { return owner_type; }
}
public override bool Matches (SecurityKeyIdentifierClause clause)
{
if (clause == null)
throw new ArgumentNullException ("clause");
LocalIdKeyIdentifierClause c =
clause as LocalIdKeyIdentifierClause;
return c != null && Matches (c.LocalId, c.OwnerType);
}
public bool Matches (string localId, Type ownerType)
{
return local_id == localId && (owner_type == null || owner_type == ownerType);
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
}
}

View File

@@ -0,0 +1,102 @@
//
// RsaKeyIdentifierClause.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
namespace System.IdentityModel.Tokens
{
public class RsaKeyIdentifierClause : SecurityKeyIdentifierClause
{
public RsaKeyIdentifierClause (RSA rsa)
: base (null)
{
this.rsa = rsa;
}
RSA rsa;
public RSA Rsa {
get { return rsa; }
}
public override bool CanCreateKey {
get { return true; }
}
public override SecurityKey CreateKey ()
{
return new RsaSecurityKey (rsa);
}
public byte [] GetExponent ()
{
return rsa.ExportParameters (false).Exponent;
}
[MonoTODO]
public void WriteExponentAsBase64 (XmlWriter writer)
{
throw new NotImplementedException ();
}
public byte [] GetModulus ()
{
return rsa.ExportParameters (false).Modulus;
}
[MonoTODO]
public void WriteModulusAsBase64 (XmlWriter writer)
{
throw new NotImplementedException ();
}
public override bool Matches (SecurityKeyIdentifierClause clause)
{
if (clause == null)
throw new ArgumentNullException ("clause");
RsaKeyIdentifierClause rkic =
clause as RsaKeyIdentifierClause;
return rkic != null && Matches (rkic.Rsa);
}
public bool Matches (RSA rsa)
{
// hmm, there should be more decent way to compare ...
return rsa.ToXmlString (false) == this.rsa.ToXmlString (false);
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
}
}

View File

@@ -0,0 +1,122 @@
//
// AsymmetricSecurityKey.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
namespace System.IdentityModel.Tokens
{
public sealed class RsaSecurityKey : AsymmetricSecurityKey
{
public RsaSecurityKey (RSA rsa)
{
this.rsa = rsa;
}
RSA rsa;
// AsymmetricSecurityKey implementation
[MonoTODO]
public override AsymmetricAlgorithm GetAsymmetricAlgorithm (
string algorithm, bool privateKey)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override HashAlgorithm GetHashAlgorithmForSignature (
string algorithm)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override AsymmetricSignatureDeformatter GetSignatureDeformatter (string algorithm)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override AsymmetricSignatureFormatter GetSignatureFormatter (string algorithm)
{
throw new NotImplementedException ();
}
public override bool HasPrivateKey ()
{
RSACryptoServiceProvider rcsp = rsa as RSACryptoServiceProvider;
if (rcsp != null)
return !rcsp.PublicOnly;
try {
rcsp.ExportParameters (true);
return true;
} catch (CryptographicException) {
return false;
}
}
// SecurityKey implementation
public override int KeySize {
get { return rsa.KeySize; }
}
[MonoTODO]
public override byte [] DecryptKey (string algorithm, byte [] keyData)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override byte [] EncryptKey (string algorithm, byte [] keyData)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool IsAsymmetricAlgorithm (string algorithm)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool IsSupportedAlgorithm (string algorithm)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool IsSymmetricAlgorithm (string algorithm)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,95 @@
//
// RsaSecurityToken.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
namespace System.IdentityModel.Tokens
{
public class RsaSecurityToken : SecurityToken
{
public RsaSecurityToken (RSA rsa)
: this (rsa, new UniqueId ().ToString ())
{
}
public RsaSecurityToken (RSA rsa, string id)
{
if (rsa == null)
throw new ArgumentNullException ("rsa");
this.rsa = rsa;
this.id = id;
}
RSA rsa;
string id;
DateTime valid_from = DateTime.Now.ToUniversalTime ();
public override DateTime ValidFrom {
get { return valid_from; }
}
public override DateTime ValidTo {
get { return DateTime.MaxValue.AddDays (-1); }
}
public override string Id {
get { return id; }
}
public RSA Rsa {
get { return rsa; }
}
[MonoTODO]
public override ReadOnlyCollection<SecurityKey> SecurityKeys {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override bool CanCreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override T CreateKeyIdentifierClause<T> ()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override bool MatchesKeyIdentifierClause (
SecurityKeyIdentifierClause skiClause)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,42 @@
//
// SamlAccessDecision.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
namespace System.IdentityModel.Tokens
{
[DataContract]
public enum SamlAccessDecision
{
[EnumMember]
Permit,
[EnumMember]
Deny,
[EnumMember]
Indeterminate,
}
}

View File

@@ -0,0 +1,124 @@
//
// SamlAction.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAction
{
string action, ns;
bool is_readonly;
public SamlAction ()
{
}
public SamlAction (string action)
{
Action = action;
}
public SamlAction (string action, string ns)
{
Action = action;
Namespace = ns;
}
public string Action {
get { return action; }
set {
CheckReadOnly ();
if (value == null || value.Length == 0)
throw new ArgumentException ("SAML Action must be non-zero length string.");
action = value;
}
}
public bool IsReadOnly {
get { return is_readonly; }
}
public string Namespace {
get { return ns; }
set {
CheckReadOnly ();
ns = value;
}
}
void CheckReadOnly ()
{
if (is_readonly)
throw new InvalidOperationException ("This SAML action is read-only.");
}
public void MakeReadOnly ()
{
is_readonly = true;
}
public virtual void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
if (reader == null)
throw new ArgumentNullException ("writer");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
Namespace = reader.GetAttribute ("Namespace");
Action = reader.ReadElementContentAsString ("Action", SamlConstants.Namespace);
if (Action == null)
throw new SecurityTokenException ("non-zero length string must exist for SAML Action.");
}
public virtual void WriteXml (XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
if (Action == null)
throw new SecurityTokenException ("non-zero length string must be set for SAML Action before being written.");
writer.WriteStartElement ("saml", "Action", SamlConstants.Namespace);
if (Namespace != null)
writer.WriteAttributeString ("Namespace", Namespace);
writer.WriteString (Action);
writer.WriteEndElement ();
}
}
}

View File

@@ -0,0 +1,137 @@
//
// SamlAdvice.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAdvice
{
List<string> idrefs = new List<string> ();
List<SamlAssertion> assertions = new List<SamlAssertion> ();
bool is_readonly;
public SamlAdvice ()
{
}
public SamlAdvice (IEnumerable<SamlAssertion> assertions)
: this (new string [0], assertions)
{
}
public SamlAdvice (IEnumerable<string> references)
: this (references, new SamlAssertion [0])
{
}
public SamlAdvice (IEnumerable<string> references, IEnumerable<SamlAssertion> assertions)
{
if (references == null)
throw new ArgumentException ("references are null.");
if (assertions == null)
throw new ArgumentException ("assertions are null.");
foreach (string r in references) {
if (r == null)
throw new ArgumentException ("references contain null item.");
idrefs.Add (r);
}
foreach (SamlAssertion a in assertions) {
if (a == null)
throw new ArgumentException ("assertions contain null item.");
this.assertions.Add (a);
}
}
public bool IsReadOnly {
get { return is_readonly; }
}
public IList<SamlAssertion> Assertions {
get { return assertions; }
}
public IList<string> AssertionIdReferences {
get { return idrefs; }
}
public void MakeReadOnly ()
{
is_readonly = true;
}
public virtual void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
if (reader == null)
throw new ArgumentNullException ("reader");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
reader.ReadStartElement ("Advice", SamlConstants.Namespace);
for (reader.MoveToContent ();
reader.NodeType == XmlNodeType.Element;
reader.MoveToContent ()) {
if (reader.NamespaceURI != SamlConstants.Namespace)
throw new SecurityTokenException (String.Format ("Invalid SAML Advice element: element '{0}' in namespace '{1}' is unexpected.", reader.LocalName, reader.NamespaceURI));
switch (reader.LocalName) {
case "Assertion":
SamlAssertion a = new SamlAssertion ();
a.ReadXml (reader, samlSerializer, keyInfoTokenSerializer, outOfBandTokenResolver);
assertions.Add (a);
break;
case "AssertionIDReference":
idrefs.Add (reader.ReadElementContentAsString ());
break;
default:
throw new SecurityTokenException (String.Format ("Invalid SAML Advice element: SAML element '{0}' is unexpected.", reader.LocalName));
}
}
reader.ReadEndElement ();
}
public virtual void WriteXml (XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
writer.WriteStartElement ("saml", "Advice", SamlConstants.Namespace);
foreach (string idref in AssertionIdReferences)
writer.WriteElementString ("saml", "AssertionIDReference", SamlConstants.Namespace, idref);
foreach (SamlAssertion assertion in Assertions)
assertion.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
writer.WriteEndElement ();
}
}
}

View File

@@ -0,0 +1,236 @@
//
// SamlAssertion.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAssertion
{
bool is_readonly;
SamlAdvice advice;
SamlConditions conditions;
string assertion_id, issuer;
DateTime issue_instant;
int major, minor;
SigningCredentials signing_credentials;
List<SamlStatement> statements = new List<SamlStatement> ();
public SamlAssertion ()
{
assertion_id = "SamlSecurityToken-" + Guid.NewGuid ();
major = 1;
minor = 1;
issue_instant = DateTime.Now.ToUniversalTime ();
}
public SamlAssertion (string assertionId, string issuer,
DateTime issueInstant, SamlConditions conditions,
SamlAdvice advice, IEnumerable<SamlStatement> statements)
{
if (IsInvalidAssertionId (assertionId))
throw new ArgumentException (String.Format ("The assertionId '{0}' must be a valid XML NCName.", assertionId));
if (issuer == null || issuer.Length == 0)
throw new ArgumentException ("issuer");
if (statements == null)
throw new ArgumentNullException ("statements");
major = 1;
minor = 1;
assertion_id = assertionId;
this.issuer = issuer;
issue_instant = issueInstant;
this.conditions = conditions;
this.advice = advice;
foreach (SamlStatement s in statements) {
if (s == null)
throw new ArgumentException ("statements contain null item.");
this.statements.Add (s);
}
if (this.statements.Count == 0)
throw new ArgumentException ("At least one assertion statement is required.");
}
bool IsInvalidAssertionId (string assertionId)
{
if (assertionId == null || assertionId.Length == 0)
return true;
try {
XmlConvert.VerifyNCName (assertionId);
} catch (XmlException) {
return true;
}
return false;
}
public SamlAdvice Advice {
get { return advice; }
set {
CheckReadOnly ();
advice = value;
}
}
public string AssertionId {
get { return assertion_id; }
set {
CheckReadOnly ();
assertion_id = value;
}
}
public SamlConditions Conditions {
get { return conditions; }
set {
CheckReadOnly ();
conditions = value;
}
}
public DateTime IssueInstant {
get { return issue_instant; }
set {
CheckReadOnly ();
issue_instant = value;
}
}
public string Issuer {
get { return issuer; }
set {
CheckReadOnly ();
issuer = value;
}
}
public int MajorVersion {
get { return major; }
}
public int MinorVersion {
get { return minor; }
}
public SigningCredentials SigningCredentials {
get { return signing_credentials; }
set {
CheckReadOnly ();
signing_credentials = value;
}
}
[MonoTODO]
public SecurityToken SigningToken {
get {
if (signing_credentials == null)
return null;
throw new NotImplementedException ();
}
}
public IList<SamlStatement> Statements {
get { return statements; }
}
public bool IsReadOnly {
get { return is_readonly; }
}
private void CheckReadOnly ()
{
if (is_readonly)
throw new InvalidOperationException ("This SAML assertion is read-only.");
}
public void MakeReadOnly ()
{
is_readonly = true;
}
[MonoTODO]
public virtual void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
throw new NotImplementedException ();
}
public virtual void WriteXml (XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
if (Issuer == null || Issuer.Length == 0)
throw new SecurityTokenException ("Issuer must not be null or empty.");
if (Statements.Count == 0)
throw new SecurityTokenException ("At least one assertion statement is required.");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
CultureInfo invariant = CultureInfo.InvariantCulture;
writer.WriteStartElement ("saml", "Assertion", SamlConstants.Namespace);
writer.WriteAttributeString ("MajorVersion", MajorVersion.ToString (invariant));
writer.WriteAttributeString ("MinorVersion", MinorVersion.ToString (invariant));
writer.WriteAttributeString ("AssertionID", AssertionId);
writer.WriteAttributeString ("Issuer", Issuer);
writer.WriteAttributeString ("IssueInstant", IssueInstant.ToString (SamlConstants.DateFormat, invariant));
try {
if (Conditions != null)
Conditions.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
if (Advice != null)
Advice.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
foreach (SamlStatement statement in Statements)
statement.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
} catch (NotImplementedException) {
throw;
} catch (Exception ex) { // bad catch, eh?
throw new InvalidOperationException ("There is an error on writing assertion statements.", ex);
}
writer.WriteEndElement ();
}
[MonoTODO]
protected void ReadSignature (XmlDictionaryReader reader,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver,
SamlSerializer samlSerializer)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,68 @@
//
// SamlAssertionKeyIdentifierClause.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Policy;
using System.Security.Cryptography;
namespace System.IdentityModel.Tokens
{
public class SamlAssertionKeyIdentifierClause : SecurityKeyIdentifierClause
{
[MonoTODO]
public SamlAssertionKeyIdentifierClause (string assertionId)
: base (assertionId)
{
id = assertionId;
}
string id;
public string AssertionId {
get { return id; }
}
[MonoTODO]
public override bool Matches (SecurityKeyIdentifierClause clause)
{
throw new NotImplementedException ();
}
public bool Matches (string assertionId)
{
return id == assertionId;
}
[MonoTODO]
public override string ToString ()
{
return id;
}
}
}

View File

@@ -0,0 +1,141 @@
//
// SamlAttribute.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml;
using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAttribute
{
bool is_readonly;
string name, ns;
List<string> attribute_values;
public SamlAttribute ()
{
attribute_values = new List<string> ();
}
public SamlAttribute (Claim claim)
{
if (claim == null)
throw new ArgumentNullException ("claim");
if (claim.ClaimType == null)
throw new ArgumentException ("Claim type is null.");
int idx = claim.ClaimType.LastIndexOf ('/');
if (idx <= 0 || idx == claim.ClaimType.Length - 1)
throw new ArgumentException ("Claim type does not contain '/' or it is at improper position.");
name = claim.ClaimType.Substring (idx + 1);
ns = claim.ClaimType.Substring (0, idx);
if (claim.Resource != null && !(claim.Resource is string))
throw new ArgumentException ("Claim resource is not a string.");
attribute_values = new List<string> ();
attribute_values.Add ((string) claim.Resource);
if (claim.Right != Rights.PossessProperty)
throw new ArgumentException ("Claim right is not PossessProperty");
}
public SamlAttribute (string attributeNamespace,
string attributeName,
IEnumerable<string> attributeValues)
{
ns = attributeNamespace;
name = attributeName;
attribute_values = new List<string> (attributeValues);
}
public IList<string> AttributeValues {
get { return attribute_values; }
}
public string Name {
get { return name; }
set {
CheckReadOnly ();
name = value;
}
}
public string Namespace {
get { return ns; }
set {
CheckReadOnly ();
ns = value;
}
}
public bool IsReadOnly {
get { return is_readonly; }
}
private void CheckReadOnly ()
{
if (is_readonly)
throw new InvalidOperationException ("This SAML assertion is read-only.");
}
public void MakeReadOnly ()
{
is_readonly = true;
}
[MonoTODO]
public virtual void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
throw new NotImplementedException ();
}
public virtual void WriteXml (XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer)
{
writer.WriteStartElement ("saml", "Attribute", SamlConstants.Namespace);
writer.WriteAttributeString ("AttributeName", Name);
writer.WriteAttributeString ("AttributeNamespace", Namespace);
foreach (string s in AttributeValues)
writer.WriteElementString ("saml", "AttributeValue", SamlConstants.Namespace, s);
writer.WriteEndElement ();
}
[MonoTODO]
public virtual ReadOnlyCollection<Claim> ExtractClaims ()
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,94 @@
//
// SamlAttributeStatement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAttributeStatement : SamlSubjectStatement
{
bool is_readonly;
List<SamlAttribute> attributes;
public SamlAttributeStatement ()
{
attributes = new List<SamlAttribute> ();
}
public SamlAttributeStatement (SamlSubject samlSubject,
IEnumerable<SamlAttribute> attributes)
: base (samlSubject)
{
this.attributes = new List<SamlAttribute> (attributes);
}
public IList<SamlAttribute> Attributes {
get { return attributes; }
}
public override bool IsReadOnly {
get { return is_readonly; }
}
public override void MakeReadOnly ()
{
is_readonly = true;
}
[MonoTODO]
public override void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
throw new NotImplementedException ();
}
public override void WriteXml (XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoTokenSerializer)
{
if (SamlSubject == null)
throw new SecurityTokenException ("Subject is null in the AttributeStatement");
writer.WriteStartElement ("saml", "AttributeStatement", SamlConstants.Namespace);
SamlSubject.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
foreach (SamlAttribute a in Attributes)
a.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
writer.WriteEndElement ();
}
[MonoTODO]
protected override void AddClaimsToList (IList<Claim> claims)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,94 @@
//
// SamlAudienceRestrictionCondition.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Xml;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
namespace System.IdentityModel.Tokens
{
public class SamlAudienceRestrictionCondition : SamlCondition
{
List<Uri> audiences = new List<Uri> ();
bool is_readonly;
public SamlAudienceRestrictionCondition ()
{
}
public SamlAudienceRestrictionCondition (IEnumerable<Uri> audiences)
{
if (audiences == null)
throw new ArgumentNullException ("audiences");
foreach (Uri uri in audiences)
this.audiences.Add (uri);
}
public IList<Uri> Audiences {
get { return audiences; }
}
public override bool IsReadOnly {
get { return is_readonly; }
}
public override void MakeReadOnly ()
{
is_readonly = true;
}
[MonoTODO]
public override void ReadXml (XmlDictionaryReader reader,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoSerializer,
SecurityTokenResolver outOfBandTokenResolver)
{
throw new NotImplementedException ();
}
public override void WriteXml (
XmlDictionaryWriter writer,
SamlSerializer samlSerializer,
SecurityTokenSerializer keyInfoSerializer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
if (samlSerializer == null)
throw new ArgumentNullException ("samlSerializer");
if (Audiences.Count == 0)
throw new SecurityTokenException ("SAML AudienceRestrictionCondition must contain at least one Audience.");
writer.WriteStartElement ("saml", "AudienceRestrictionCondition", SamlConstants.Namespace);
foreach (Uri a in Audiences)
writer.WriteElementString ("saml", "Audience", SamlConstants.Namespace, a.AbsoluteUri);
writer.WriteEndElement ();
}
}
}

Some files were not shown because too many files have changed in this diff Show More