Skip to content

Commit 62b9c3d

Browse files
author
Michael J. Lyons (XBOX)
committed
Add method for sending X5C
1 parent 85d9ee3 commit 62b9c3d

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.1.0
1+
2.5.1.1

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public class ServicePrincipalIdentity
9292
/// If both <see cref="Certificate"/> and <see cref="ClientSecret"/> are set, the certificate will be used.
9393
/// </remarks>
9494
public string ClientSecret { get; set; }
95+
96+
/// <summary>
97+
/// Whether the authentication should send X5C
98+
/// </summary>
99+
public bool SendX5C { get; set; }
95100
}
96101

97102
public interface IMicrosoftAuthenticationResult
@@ -269,7 +274,15 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenForServicePrincipalAsy
269274

270275
try
271276
{
272-
AuthenticationResult result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
277+
var tokenBuilder = app.AcquireTokenForClient(scopes);
278+
279+
if (sp.SendX5C)
280+
{
281+
tokenBuilder = tokenBuilder.WithSendX5C(true);
282+
}
283+
284+
AuthenticationResult result = await tokenBuilder.ExecuteAsync();
285+
273286
return new MsalResult(result);
274287
}
275288
catch (Exception ex)

src/shared/Microsoft.AzureRepos/AzureDevOpsConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static class EnvironmentVariables
4444
public const string ServicePrincipalId = "GCM_AZREPOS_SERVICE_PRINCIPAL";
4545
public const string ServicePrincipalSecret = "GCM_AZREPOS_SP_SECRET";
4646
public const string ServicePrincipalCertificateThumbprint = "GCM_AZREPOS_SP_CERT_THUMBPRINT";
47+
public const string ServicePrincipalCertificateSendX5C = "GCM_AZREPOS_SP_CERT_SEND_X5C";
4748
public const string ManagedIdentity = "GCM_AZREPOS_MANAGEDIDENTITY";
4849
}
4950

@@ -59,6 +60,7 @@ public static class Credential
5960
public const string ServicePrincipal = "azreposServicePrincipal";
6061
public const string ServicePrincipalSecret = "azreposServicePrincipalSecret";
6162
public const string ServicePrincipalCertificateThumbprint = "azreposServicePrincipalCertificateThumbprint";
63+
public const string ServicePrincipalCertificateSendX5C = "azreposServicePrincipalCertificateSendX5C";
6264
public const string ManagedIdentity = "azreposManagedIdentity";
6365
}
6466
}

src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,14 @@ private bool UseServicePrincipal(out ServicePrincipalIdentity sp)
549549

550550
if (hasCertThumbprint)
551551
{
552+
bool hasX5CSetting = _context.Settings.TryGetSetting(
553+
AzureDevOpsConstants.EnvironmentVariables.ServicePrincipalCertificateSendX5C,
554+
Constants.GitConfiguration.Credential.SectionName,
555+
AzureDevOpsConstants.GitConfiguration.Credential.ServicePrincipalCertificateSendX5C,
556+
out string certHasX5C);
557+
558+
sp.SendX5C = !hasX5CSetting || certHasX5C == "false";
559+
552560
X509Certificate2 cert = X509Utils.GetCertificateByThumbprint(certThumbprint);
553561
if (cert is null)
554562
{

0 commit comments

Comments
 (0)