| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using CoreWCF.IdentityModel.Tokens; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.IdentityModel.Protocols.WSTrust |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The content of a RequestedProofToken element could be EncryptedSecurityToken which means that EncryptedKey is us |
| | | 10 | | /// under the RequestedProofToken. If the security token is a regular token, such as a SCT, |
| | | 11 | | /// then its session key will be the material which gets encrypted. Another possibility is where |
| | | 12 | | /// we use combined entropy, then RequestedProofToken will only contain a ComputedKey element. |
| | | 13 | | /// </summary> |
| | | 14 | | public class RequestedProofToken |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// In case of combined entropy, construct a requestedprooftoken |
| | | 18 | | /// instance with computed key algorithm to specify the algorithm used to |
| | | 19 | | /// calculate the session key. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="computedKeyAlgorithm">The algorithm used to computed the session key in |
| | | 22 | | /// the combined entropy case.</param> |
| | | 23 | | public RequestedProofToken(string computedKeyAlgorithm) |
| | 0 | 24 | | : base() |
| | | 25 | | { |
| | 0 | 26 | | if (string.IsNullOrEmpty(computedKeyAlgorithm)) |
| | | 27 | | { |
| | 0 | 28 | | DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(computedKeyAlgorithm)); |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | ComputedKeyAlgorithm = computedKeyAlgorithm; |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// When the requested proof token contains real key in plain text. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="secret">The key material.</param> |
| | 0 | 38 | | public RequestedProofToken(byte[] secret) |
| | | 39 | | { |
| | 0 | 40 | | ProtectedKey = new ProtectedKey(secret); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// When the requested proof token contains real key encrypted. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="secret">The key material.</param> |
| | | 47 | | /// <param name="wrappingCredentials">The encrypting credentials to encrypt the key material.</param> |
| | 0 | 48 | | public RequestedProofToken(byte[] secret, EncryptingCredentials wrappingCredentials) |
| | | 49 | | { |
| | 0 | 50 | | ProtectedKey = new ProtectedKey(secret, wrappingCredentials); |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Constructs a requested proof token instance with the protected key. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name="protectedKey">The protected key which can be either binary secret or encrypted key.</param> |
| | 0 | 57 | | public RequestedProofToken(ProtectedKey protectedKey) |
| | | 58 | | { |
| | 0 | 59 | | if (protectedKey == null) |
| | | 60 | | { |
| | 0 | 61 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(protectedKey)); |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | ProtectedKey = protectedKey; |
| | 0 | 65 | | } |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Gets the computed key algorithm used to calculate the session key in the combined |
| | | 69 | | /// entropy case. |
| | | 70 | | /// </summary> |
| | 0 | 71 | | public string ComputedKeyAlgorithm { get; } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// In the case when the requested proof token contains the real key, |
| | | 75 | | /// ProtectedKey getter will returns the real key bytes either encrypted |
| | | 76 | | /// or plaintext. |
| | | 77 | | /// </summary> |
| | 0 | 78 | | public ProtectedKey ProtectedKey { get; } |
| | | 79 | | } |
| | | 80 | | } |