Skip to content

Commit b97baab

Browse files
committed
Fixes certificate based authentication
1 parent 4edbcdd commit b97baab

File tree

14 files changed

+2362
-2175
lines changed

14 files changed

+2362
-2175
lines changed

Documentation/APIReference.md

Lines changed: 2215 additions & 2164 deletions
Large diffs are not rendered by default.

Documentation/Testing.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ features like proxy settings.
4747
4848
### `Common` Azure App Registration
4949

50-
Configure an Azure App for which a Client Secret has been generated as the
51-
`Storage` App Registration. And if also running the interactive authentication
52-
tests make sure that for this App:
50+
Configure an Azure App for which a Client Secret has been generated and a
51+
Client Certificate has been registered. Ensure this App's service principal
52+
is granted access to the storage account used for testing, see also
53+
[Storage Account](#storage-account) below. And if also running the
54+
interactive authentication tests make sure that for this App:
5355

5456
* A Redirect Uri has been configured in the form of `http://localhost:PORT`
5557
where *PORT* is configurable.
@@ -92,7 +94,7 @@ which:
9294

9395
* A Client Secret has been generated.
9496

95-
### `Storage` Storage Account
97+
### Storage Account
9698

9799
The storage account should contain three containers:
98100

@@ -134,6 +136,7 @@ Once generated note down the "Connection string" and "SAS token".
134136
| `STORAGE_ACCOUNT_NAME` | Name of the storage account |
135137
| `AZURE_CLIENT_ID` | Client ID of the Azure App |
136138
| `AZURE_CLIENT_SECRET` | Client Secret which has been generated for the App |
139+
| `AZURE_CLIENT_CERTIFICATE` | Base64 encoded PEM-format certificate as registered for the App |
137140
| `AZURE_TENANT_ID` | Azure Tenant ID |
138141

139142
## `/KeyVault` Azure Key Vault unit tests
@@ -174,4 +177,4 @@ A Key Vault account needs to exist:
174177
| `KEYVAULT_TENANT_ID` | Azure Tenant ID |
175178
| `KEYVAULT_VAULT_NAME` | Name of the Key Vault |
176179

177-
[//]: # (Copyright 2021-2022 The MathWorks, Inc.)
180+
[//]: # (Copyright 2021-2023 The MathWorks, Inc.)

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Release Notes
44

5+
## Release 0.3.1 April 11th 2023
6+
7+
* Fixes issue with client certificate authentication
8+
59
## Release 0.3.0 March 27th 2023
610

711
* Added EndPoint setting support

Software/MATLAB/app/functions/configureCredentials.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@
178178
write(logObj,'error',['pem certificate file not found: ', strrep(char(settings.PemCertificate),'\','\\')]);
179179
else
180180
usePemfile = true;
181+
builder = azure.identity.ClientCertificateCredentialBuilder();
181182
end
183+
else
184+
write(logObj,'error','PemCertificate may not be set to an empty string');
182185
end
186+
else
187+
builder = azure.identity.ClientSecretCredentialBuilder();
183188
end
184-
builder = azure.identity.ClientSecretCredentialBuilder();
185189
builder = builder.clientId(settings.ClientId);
186190
builder = builder.tenantId(settings.TenantId);
187191
% If a pem file is configured and exists use it else default to the client secret
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classdef ClientCertificateCredential < azure.core.credential.TokenCredential
2+
% CLIENTCERTIFICATECREDENTIAL AAD credential acquires a token with a client certificate
3+
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
properties
7+
end
8+
9+
methods
10+
function obj = ClientCertificateCredential(clientCertificateCredentialj)
11+
% Created using a ClientCertificateCredential java object from the
12+
% ClientCertificateCredentialBuilder class only
13+
if isa(clientCertificateCredentialj, 'com.azure.identity.ClientCertificateCredential')
14+
obj.Handle = clientCertificateCredentialj;
15+
else
16+
logObj = Logger.getLogger();
17+
write(logObj,'error','Expected argument of type com.azure.identity.ClientCertificateCredential');
18+
end
19+
end
20+
end
21+
22+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
classdef ClientCertificateCredentialBuilder < azure.identity.CredentialBuilderBase
2+
% CLIENTCERTIFICATECREDENTIALBUILDER Builder for ClientCertificateCredential
3+
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
properties
7+
end
8+
9+
methods
10+
11+
function obj = ClientCertificateCredentialBuilder(varargin)
12+
13+
initialize('loggerPrefix', 'Azure:Common');
14+
if nargin == 0
15+
obj.Handle = com.azure.identity.ClientCertificateCredentialBuilder();
16+
elseif nargin == 1 && isa(varargin{1}, 'com.azure.identity.ClientCertificateCredentialBuilder')
17+
obj.Handle = varargin{1};
18+
else
19+
logObj = Logger.getLogger();
20+
write(logObj,'error','Invalid argument(s)');
21+
end
22+
23+
end %function
24+
25+
end %methods
26+
end %class
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function clientCertificateCredentialBuilder = authorityHost(obj, authorityHost)
2+
% AUTHORITYHOST Specifies the Azure Active Directory endpoint to acquire tokens
3+
% An updated ClientCertificateCredentialBuilder is returned.
4+
5+
% Copyright 2023 The MathWorks, Inc.
6+
7+
if ~(ischar(authorityHost) || isStringScalar(authorityHost))
8+
logObj = Logger.getLogger();
9+
write(logObj,'error','Expected argument of type character vector or scalar string');
10+
end
11+
12+
clientCertificateCredentialBuilderj = obj.Handle.authorityHost(authorityHost);
13+
clientCertificateCredentialBuilder = azure.identity.ClientCertificateCredentialBuilder(clientCertificateCredentialBuilderj);
14+
15+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function clientCertificateCredential = build(obj)
2+
% BUILD Creates new ClientCertificateCredential with the configured options set
3+
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
clientCertificateCredentialj = obj.Handle.build();
7+
clientCertificateCredential = azure.identity.ClientCertificateCredential(clientCertificateCredentialj);
8+
9+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function clientCertificateCredentialBuilder = clientId(obj, clientId)
2+
% CLIENTID Sets client id
3+
% An updated ClientCertificateCredentialBuilder is returned.
4+
5+
% Copyright 2020 The MathWorks, Inc.
6+
7+
if ~(ischar(clientId) || isStringScalar(clientId))
8+
logObj = Logger.getLogger();
9+
write(logObj,'error','Expected argument of type character vector or scalar string');
10+
end
11+
12+
clientCertificateCredentialBuilderj = obj.Handle.clientId(clientId);
13+
clientCertificateCredentialBuilder = azure.identity.ClientCertificateCredentialBuilder(clientCertificateCredentialBuilderj);
14+
15+
end

Software/MATLAB/app/system/+azure/+identity/@ClientSecretCredentialBuilder/pemCertificate.m renamed to Software/MATLAB/app/system/+azure/+identity/@ClientCertificateCredentialBuilder/pemCertificate.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function clientSecretCredentialBuilder = pemCertificate(obj, certificatePath)
1+
function clientCertificateCredentialBuilder = pemCertificate(obj, certificatePath)
22
% PEMCERTIFICATE Sets the path of the PEM certificate for authenticating to AAD
3-
% An updated ClientSecretCredentialBuilder is returned.
3+
% An updated ClientCertificateCredentialBuilder is returned.
44

55
% Copyright 2020 The MathWorks, Inc.
66

@@ -14,7 +14,7 @@
1414
write(logObj,'error',['File not found: ', strrep(char(certificatePath),'\','\\')]);
1515
end
1616

17-
clientSecretCredentialBuilderj = obj.Handle.pemCertificate(certificatePath);
18-
clientSecretCredentialBuilder = azure.identity.ClientSecretCredentialBuilder(clientSecretCredentialBuilderj);
17+
clientCertificateCredentialBuilderj = obj.Handle.pemCertificate(certificatePath);
18+
clientCertificateCredentialBuilder = azure.identity.ClientCertificateCredentialBuilder(clientCertificateCredentialBuilderj);
1919

2020
end

0 commit comments

Comments
 (0)