Usage
All three calls are synchronous, so keep Connect() and Status() off the UI thread: Connect()
generates a key, talks to your Broker and installs a profile, and Status() may ask your Broker too.
When something goes wrong, each call throws a WiDasException.
Implement IBroker
IBroker is how the SDK reaches your Broker. It has two methods:
public interface IBroker
{
IssuanceResponse Sign(SigningRequestSubmission submission);
CertificateStatusResponse? Status(string serial);
}
Sign gets a SigningRequestSubmission carrying ClientId, PartnerUserId, Csr,
RequestedValidity and DeviceId. Send them to your Broker, which makes the
certificate request and returns the Wi-DAS
response. Turn that response into an IssuanceResponse.
RequestedValidity is null when your app calls Connect() without one. Forward it as it is: with no value,
Wi-DAS issues the certificate for your maximum. Fill in your own only if you want a shorter lifetime.
When something fails, throw one of these two exceptions. Most other exceptions you let escape are
reported as internal.
- Your Broker answered with a refusal: throw
BrokerRefusedExceptionwith the problemtitlefrom the response, exactly as it arrived. The SDK maps it to an error code, and matching is exact, so a trimmed or re-cased title lands on the genericissuanceRejected. - No answer arrived at all (a timeout, DNS failure, refused connection, or TLS failure): throw
BrokerUnreachableException, passing the original exception. The SDK reports it asnetwork.
Here's an implementation over HttpClient, talking to a Broker endpoint you define (here
POST /wi-das/certificates) that relays to Wi-DAS and passes its response back. The HttpClient you
pass in needs its BaseAddress set to your Broker.
The example is written for net10.0-windows. On net48 you'll need the System.Net.Http.Json
package, and you'll have to rewrite its newer C# syntax for C# 7.3.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
using WiDas.Sdk.Windows;
public sealed class MyBroker(HttpClient http, Func<string> userAccessToken) : IBroker
{
public IssuanceResponse Sign(SigningRequestSubmission submission)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "wi-das/certificates")
{
Content = JsonContent.Create(new
{
clientId = submission.ClientId,
partnerUserId = submission.PartnerUserId,
csr = submission.Csr,
requestedValidity = submission.RequestedValidity, // null means your maximum
deviceId = submission.DeviceId,
}),
};
// Your own sign-in. The Broker should work out who the user is from this,
// not trust partnerUserId as sent.
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccessToken());
HttpResponseMessage response;
try
{
response = http.SendAsync(request).GetAwaiter().GetResult();
}
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException)
{
throw new BrokerUnreachableException(ex);
}
using (response)
{
if (!response.IsSuccessStatusCode)
{
throw new BrokerRefusedException(ProblemTitle(response));
}
Issued? issued;
try
{
issued = response.Content.ReadFromJsonAsync<Issued>().GetAwaiter().GetResult();
}
catch (JsonException)
{
throw new BrokerRefusedException(null); // an answer we couldn't read
}
if (issued is null)
{
throw new BrokerRefusedException(null);
}
return new IssuanceResponse(
serial: issued.Serial,
clientCertificatePem: issued.CertificatePem,
serverCaPem: issued.ServerCaPem,
passpoint: new PasspointSettings(
issued.Passpoint.FriendlyName,
issued.Passpoint.Realm,
issued.Passpoint.HomeFqdn,
issued.Passpoint.Mcc,
issued.Passpoint.Mnc,
issued.Passpoint.Rcoi),
notAfter: issued.NotAfter,
deviceId: issued.DeviceId,
issuingCaPem: issued.ChainPem); // lets Windows pick the certificate without asking
}
}
// Optional. If you don't relay status, throw: Status() then works from the certificate on the
// machine. Return null only for a serial Wi-DAS doesn't recognise (a 404).
public CertificateStatusResponse? Status(string serial) =>
throw new NotSupportedException("This Broker doesn't relay certificate status.");
private static string? ProblemTitle(HttpResponseMessage response)
{
try
{
using var problem = JsonDocument.Parse(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
return problem.RootElement.TryGetProperty("title", out var title) && title.ValueKind == JsonValueKind.String
? title.GetString()
: response.ReasonPhrase;
}
catch (JsonException)
{
return response.ReasonPhrase;
}
}
// The Wi-DAS certificate response, as your Broker passes it back.
private sealed record Issued(
string Serial, string? DeviceId, string CertificatePem, string? ChainPem, string ServerCaPem,
DateTimeOffset NotAfter, IssuedPasspoint Passpoint);
private sealed record IssuedPasspoint(
string FriendlyName, string Realm, string HomeFqdn, string? Mcc, string? Mnc, string? Rcoi);
}
Talk to your Broker over HTTPS, for integrity more than secrecy. The SDK builds the Passpoint profile from the response, including the server CA it trusts and the network it joins, and installs the issuing CA from it, so nothing between your Broker and the app may be able to change it. HTTPS also keeps your user's token private.
Pass the PEM values through exactly as Wi-DAS sent them. The profile pins certificate hashes, so a copy your Broker re-encodes can be refused, or pin something no machine holds.
Returning the issuing CA
Pass the Wi-DAS response's chainPem to IssuanceResponse as issuingCaPem, as the example does. It
holds the CA that signed the client certificate. With it, the SDK adds a certificate filter to the
Passpoint profile and installs the CA in the user's intermediate store, so Windows picks this
certificate by itself. Without it, a machine that has more than one client certificate makes the user
choose one when it joins the network, which an unattended machine can't do.
It's optional, and leaving it out never stops Connect(). If the value doesn't contain the CA that
signed the certificate, or can't be read, the SDK writes the profile without a filter and installs no
CA. It reports why as a warning through System.Diagnostics.Trace, so add a trace listener if you want
to see it in your logs. If you ship as MSIX, read
MSIX: let the issuing CA reach the real certificate store
first.
Relaying status (optional)
To give Status() a live answer, have your Broker relay
GET /certificates/{serial}/status
and build a CertificateStatusResponse from it. The wire status is lowercase (active, revoked,
expired, unknown), so map it to the CertificateStatus enum. Return null for a 404, which
means the serial isn't one Wi-DAS issued. If you skip this, Status() works from the certificate on
the machine, which is enough for most UIs.
Create the flow
Create one OnboardingFlow and keep it for the life of your app. It holds no secret.
var http = new HttpClient { BaseAddress = new Uri("https://broker.example.com/") };
var flow = new OnboardingFlow(clientId: "client-acme", broker: new MyBroker(http, GetUserToken));
| Parameter | Notes |
|---|---|
clientId | Your Wi-DAS-issued client identifier. |
broker | Your IBroker implementation. |
additionalServerTrustRoots | Optional, on the three-argument constructor. Extra root certificates, as PEM, that the profile accepts the Wi-DAS RADIUS servers under. |
The profile normally trusts the RADIUS servers under the root that the response's serverCaPem chains
to. Where the servers' certificate is cross-signed, Windows can end its chain at a different root and
then refuse the server. If we tell you that applies to your network, pass the roots we give you:
var flow = new OnboardingFlow("client-acme", new MyBroker(http, GetUserToken), new[] { extraRootPem });
Each root is added to the profile after the one from serverCaPem, in your order. They widen which CA
may sign the server's certificate, not which server is accepted, and the SDK never installs them. Each
has to be a self-signed CA certificate that this machine already trusts for server authentication,
passed exactly as published: the profile pins a hash of the bytes you pass, so a re-encoded copy
matches nothing. A root that fails these checks makes Connect() throw PasspointInstallFailed
before any certificate or profile is installed. A null list, or a null entry in it, throws
ArgumentNullException from the constructor. The list is copied when you create the flow, so changing
it afterwards has no effect.
Connect
Connect() onboards the user. Call it when Status() reports None, Expired or Revoked. It
handles first enrolment, renewal and recovery in one call. Before it installs anything, it clears this
user's previous profile and certificate from the machine. If part of that clear fails, Connect()
carries on and reports it on Connection.Reconciliation, so check Reconciliation.Complete and log
anything left behind.
try
{
Connection connection = await Task.Run(() => flow.Connect("user-42", "P365D"));
ShowConnected(connection.NotAfter);
}
catch (WiDasException ex)
{
Handle(ex); // see Error handling
}
user is your identifier for the user, the same one your Broker vouches for. It may only contain
ASCII letters, digits, -, . and _, so an email address won't do. Anything else fails as
internal before the SDK touches the machine.
requestedValidity is an ISO 8601 duration, cut down to your maximum by Wi-DAS. If you leave it out,
Wi-DAS issues the certificate for your maximum. Connection carries the certificate's Serial, its
NotAfter expiry and the KeyBacking that holds the key. There's no separate renew call: connect again before NotAfter.
Calling Connect() again is safe, but each call issues a new certificate through your Broker, so
don't call it on every launch. Certificates last about a year: at launch, call Status() first and
connect only when there's no usable certificate.
Status() reads the certificate on the machine, so if the user deletes the Wi-Fi profile by hand it
still reports Valid. Keep a Connect or Reinstall action in your UI even while connected, so the
user can put the profile back; otherwise it comes back at the next renewal.
Status
Status() tells your UI where this machine stands. If you've implemented IBroker.Status, it asks
Wi-DAS; otherwise, or if that call fails, it reads the certificate on the machine.
ConnectionStatus status = await Task.Run(() => flow.Status());
switch (status.State)
{
case ConnectionState.None:
PromptToConnect();
break;
case ConnectionState.Valid:
ShowConnected(status.Expiry); // DateTimeOffset?
break;
case ConnectionState.Expired:
case ConnectionState.Revoked:
await Task.Run(() => flow.Connect("user-42", "P365D"));
break;
case ConnectionState.Unknown:
// Not produced on Windows today; it's there so code shared with Android compiles.
break;
}
The network has the final say on whether the machine gets on. Use Status() for the UI.
If you revoke a user on purpose, have your Broker refuse them too; otherwise the code above issues them a new certificate the next time it runs.
Disconnect
Remove the profile and certificate when the user signs out or asks to leave.
try
{
Reconciliation result = flow.Disconnect();
}
catch (WiDasException.PasspointInstallFailed ex)
{
// Something couldn't be removed. ex.Reconciliation says which step and why.
Log(ex.Reconciliation?.Profile.Fault, ex.Reconciliation?.Certificate.Fault);
}
Disconnect() tries every step even when one fails, then throws PasspointInstallFailed if anything
was left behind. Each step reports Removed, NothingToRemove or Failed.
It also removes the issuing CA, if the SDK added it and no certificate left in the user's personal
store still needs it. That step isn't reported on Reconciliation: an intermediate CA left behind
gives no trust and can't be used to join the network, so it never makes Disconnect() fail.
When there's nothing to remove, Disconnect() returns NothingToRemove for both steps and doesn't
throw. That covers a machine where the SDK has never run, a second sign-out, and a sign-out after a
Connect() that failed before installing anything.
The SDK finds your profile by its realm. Connect() records that realm just before it installs the
profile, so Disconnect() can still find and remove the profile if the certificate has already gone, and it
deletes the record along with the profile (see
What the SDK leaves on the machine). If the
certificate and the record have both gone, for example because the profile was installed by an earlier
SDK version that kept no record, Disconnect() can't tell which profile was yours and reports
NothingToRemove. Keep the catch anyway: anything that is there and won't come off still throws.
The device key stays, so a later Connect() replaces the old certificate on this machine. Disconnecting
removes this installation; it doesn't revoke the user's access. Revocation happens at the network,
where the RADIUS servers check the CRL, and Wi-DAS does it on request.
Next: Error handling.