Commit 8b9cef8c authored by Marvin S. Addison's avatar Marvin S. Addison
Browse files

Create ED-ID query sample solution for .NET.

git-svn-id: fa4a4108-76f2-0310-9f0d-ba9fffaf4ff6
parent 6b180e0f

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdIdTest", "EdIdTest\EdIdTest.csproj", "{2899C510-962B-47C3-B972-F9FB7871FE27}"
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2899C510-962B-47C3-B972-F9FB7871FE27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2899C510-962B-47C3-B972-F9FB7871FE27}.Release|Any CPU.Build.0 = Release|Any CPU
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
GlobalSection(ExtensibilityGlobals) = postSolution
VisualSVNWorkingCopyRoot = .
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="">
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Reference Include="System" />
<Reference Include="System.Core">
<Reference Include="System.DirectoryServices.Protocols" />
<Reference Include="System.Xml.Linq">
<Reference Include="System.Data.DataSetExtensions">
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
<Target Name="AfterBuild">
\ No newline at end of file
using System;
using System.Security.Cryptography.X509Certificates;
using System.DirectoryServices.Protocols;
namespace EdIdTest
class Program
const string LDAP_HOST = "";
const int LDAP_PORT = 10636;
const string LDAP_BASE = "ou=people,dc=vt,dc=edu";
static void Main(string[] args)
if (args.Length < 2)
Console.WriteLine("USAGE: EdIdTest uusid query");
// The following should be the uusid of your ED-ID service
string certCN = args[0];
string ldapQuery = args[1];
Console.WriteLine(string.Format("Querying {0} as service {1} for {2}", LDAP_HOST, certCN, ldapQuery));
// Create connection and attempt to bind and search
LdapConnection conn = null;
conn = new LdapConnection(
new LdapDirectoryIdentifier(LDAP_HOST, LDAP_PORT),
// VT Enterprise Directory requires LDAPv3
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
// Look up client cert in Local Machine store by subject CN
conn.SessionOptions.QueryClientCertificate =
delegate(LdapConnection c, byte[][] trustedCAs)
X509Store lmStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
// Uncomment the following lines to help diagnose cert problems
//Console.WriteLine("Available certificates in Local Machine store:");
//foreach (X509Certificate cert in lmStore.Certificates)
// Console.WriteLine(" " + cert.Subject);
//Console.WriteLine("Querying Local Machine store for valid cert with subject " + certCN);
X509Certificate2Collection clientCerts = lmStore.Certificates.Find(
X509FindType.FindBySubjectName, certCN, true);
if (clientCerts.Count == 0)
throw new ArgumentException("Cannot find valid certificate with subject " + certCN);
return clientCerts[0];
// The 4th parameter, attributeList, is omitted to indicate all available attributes
SearchResponse response = (SearchResponse)conn.SendRequest(
new SearchRequest(LDAP_BASE, ldapQuery, SearchScope.Subtree));
Console.WriteLine(response.Entries.Count + " entries found:");
foreach (SearchResultEntry entry in response.Entries)
Console.WriteLine(" " + entry.DistinguishedName);
foreach (String name in entry.Attributes.AttributeNames)
Console.Write(" " + name + "=");
int n = 0;
foreach (object value in entry.Attributes[name].GetValues(typeof(string)))
if (n++ > 0)
catch (Exception e)
Console.WriteLine("Application error: \n" + e);
if (conn != null)
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EdIdTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EdIdTest")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dc897f85-4f33-45dc-bac1-4ffa7ee212b0")]
// Version information for an assembly consists of the following four values:
// Major Version
// Minor Version
// Build Number
// Revision
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment