【发布时间】:2017-08-11 23:05:54
【问题描述】:
在使用证书进行身份验证时,我是新手。如果我的问题没有意义,请纠正我。
我在本地创建了 2048 位 X.509 证书。我有 server.crt 、 server.key 、 server.key.org 和 mycert.pfx (mycert.pfx 包含公钥和私钥,我在我的代码中使用该文件)。
现在我有一个包含以下代码的 Java 应用程序:
String tenant="f6377xxx-aeb2-4a8a-be8a-7xxxxa60be3";
String authority = "https://login.windows.net/"+tenant+"/oauth2/authorize";
ExecutorService service=null;
service= Executors.newFixedThreadPool(1);
try
{
AuthenticationContext authenticationContext =
new AuthenticationContext(authority,false,service);
String certFile="/projects/mycert.pfx";
InputStream pkcs12Cert= new SharedFileInputStream(certFile);
AsymmetricKeyCredential credential = AsymmetricKeyCredential.create(
"xxxx-e53c-45b7-432-7b91d93674b6", pkcs12Cert, "password");
Future<AuthenticationResult> future = authenticationContext.acquireToken(
"https://outlook.office365.com", credential, null);
System.out.println("Token Received"+future.get().getAccessToken());
String token=future.get().getAccessToken();
此代码正在尝试对 Office 365 API 进行身份验证。为此,我在 Azure 上创建了一个包含租户 ID 和其他信息的应用程序。现在上面的代码抛出如下异常。
com.microsoft.aad.adal4j.AuthenticationException: {"error_description":"AADSTS70002:验证凭据时出错。AADSTS50012:客户端断言包含无效签名。[原因 - 找不到密钥。,客户端使用的密钥指纹: 'H6383KO9763C6E4KIE8363032D6', 配置的键: []]\r\n跟踪 ID: 76YT3GG-7b8b-JDU73-afeb-JDUEY7372\r\n相关 ID: 7H3Y743-a5b7-KD98-88ba-HDUYE7663\r\n时间戳: 2016 31 23:56:50Z","错误":"invalid_client"}
原因是我没有在服务器端(即 Azure AD 应用程序)上传证书。我关注this tutorial 并找到了一个解决方案,显示我必须下载 Manifest 文件,使用证书对其进行编辑,然后将其上传到 Azure 服务器。
问题是我不知道从哪里获取证书中以下键的值。你能帮我在哪里找到customKeyIdentifier、keyId和value吗?
"keyCredentials": [
{
"customKeyIdentifier": "$base64Thumbprint_from_above",
"keyId": "$keyid_from_above",
"type": "AsymmetricX509Cert",
"usage": "Verify",
"value": "$base64Value_from_above"
}
],
【问题讨论】:
-
您在什么平台上开发(我假设它不是 Windows,因为您链接的说明向您展示了如何使用 PowerShell 获取这些值)。
-
定义“本地创建”。
-
@PhilippeSignoret 我正在构建一个将调用 O365 API 的 Java 批处理作业。我正在 Mac 上开发,但批处理将在其中一台 Unix 服务器上运行。 EJP,我使用 Openssl 在本地开发机器上创建了证书,它是自签名的。这仅用于开发目的。
-
因此,当您使用 OpenSSL 工具时,您指定了文件名。所以这就是证书所在的地方。不清楚你在问什么。
-
谢谢你们。我已经在下面发布了解决方案。
标签: java ssl-certificate office365 azure-active-directory