-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using certificate from Key Vault for unit testing (#243)
using certificate from Key Vault for unit testing
- Loading branch information
Showing
12 changed files
with
189 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,5 @@ | ||
{ | ||
"tool": "Credential Scanner", | ||
"suppressions": [ | ||
{ | ||
"file": "test-certificate.pfx", | ||
"_justification": "test self signed certificate to test signing from the library. this certificate is not associated with any tenant" | ||
}, | ||
{ | ||
"placeholder": "client_secret", | ||
"_justification" : "credential used for testing. not associated with any tenant" | ||
}, | ||
{ | ||
"placeholder": "ClientPassword", | ||
"_justification" : "credential used for testing. not associated with any tenant" | ||
}, | ||
{ | ||
"placeholder": "B2C_CONFIDENTIAL_CLIENT_APP_SECRET", | ||
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API" | ||
}, | ||
{ | ||
"placeholder": "MSIDLABB2C-MSAapp-AppSecret", | ||
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/integrationtest/java/com.microsoft.aad.msal4j/CertificateHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import labapi.KeyVaultSecretsProvider; | ||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
import java.io.IOException; | ||
import java.security.*; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
public class CertificateHelper { | ||
static KeyStore createKeyStore() throws KeyStoreException, NoSuchProviderException { | ||
String os = SystemUtils.OS_NAME; | ||
if(os.contains("Mac")){ | ||
return KeyStore.getInstance("KeychainStore"); | ||
} | ||
else{ | ||
return KeyStore.getInstance("Windows-MY", "SunMSCAPI"); | ||
} | ||
} | ||
|
||
static IClientCertificate getClientCertificate() throws | ||
KeyStoreException, IOException, NoSuchAlgorithmException, | ||
CertificateException, UnrecoverableKeyException, NoSuchProviderException { | ||
|
||
KeyStore keystore = createKeyStore(); | ||
|
||
keystore.load(null, null); | ||
|
||
PrivateKey key = (PrivateKey) keystore.getKey(KeyVaultSecretsProvider.CERTIFICATE_ALIAS, null); | ||
X509Certificate publicCertificate = (X509Certificate) keystore.getCertificate( | ||
KeyVaultSecretsProvider.CERTIFICATE_ALIAS); | ||
|
||
return ClientCredentialFactory.createFromCertificate(key, publicCertificate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.