1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.IdentityModel.Selectors;
|
---|
24 | using System.IdentityModel.Tokens;
|
---|
25 | using System.Security.Cryptography.X509Certificates;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Services.OKB {
|
---|
28 |
|
---|
29 | /// <summary>
|
---|
30 | /// A certificate validator that uses a list of certificates to validate.
|
---|
31 | /// </summary>
|
---|
32 | public class CustomCertificateValidator : X509CertificateValidator {
|
---|
33 |
|
---|
34 | private IList<X509Certificate2> validCertificates;
|
---|
35 |
|
---|
36 | /// <summary>
|
---|
37 | /// Initializes a new instance of the <see cref="CustomCertificateValidator"/> class.
|
---|
38 | /// </summary>
|
---|
39 | /// <param name="validCertificates">The valid certificates.</param>
|
---|
40 | public CustomCertificateValidator(IEnumerable<X509Certificate2> validCertificates) {
|
---|
41 | this.validCertificates = new List<X509Certificate2>(validCertificates);
|
---|
42 | }
|
---|
43 |
|
---|
44 | /// <summary>
|
---|
45 | /// Validates the X.509 certificate using an internal list of valid certifiates.
|
---|
46 | /// </summary>
|
---|
47 | /// <param name="certificate">The <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate2"/> that represents the X.509 certificate to validate.</param>
|
---|
48 | public override void Validate(X509Certificate2 certificate) {
|
---|
49 | if (!validCertificates.Contains(certificate))
|
---|
50 | throw new SecurityTokenValidationException("certificate has not been registered");
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|