将证书颁发者设置为自签名证书,并使用Azure Key Vault证书SDK生成中间证书

时间:2020-01-23 14:33:44

标签: azure azure-keyvault azure-java-sdk

我正在使用Java SDK创建和处理证书。我已经成功生成了根证书。我是通过使用自定义CertificatePolicy调用SDK来完成此操作的:

public KeyVaultCertificateWithPolicy createNewCACertificate(final String issuer, final String certificateName) {
    if (!certificateNameExists(certificateName)) {
        final SyncPoller<CertificateOperation, KeyVaultCertificateWithPolicy> certificatePoller = client
                .beginCreateCertificate(certificateName, getCACertificatePolicy(issuer, certificateName));
        certificatePoller.waitUntil(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED);
        return certificatePoller.getFinalResult();
    }
    throw new RuntimeException("Certificate already exists, use the update method");
}

private boolean certificateNameExists(final String certificateName) {
    return getCertificateByName(certificateName).isPresent();
}

private CertificatePolicy getCACertificatePolicy(final String issuer, final String name) {
    return new CertificatePolicy(issuer, format("CN=%s", name))
            .setContentType(CertificateContentType.PEM)
            .setKeyUsage(CertificateKeyUsage.KEY_CERT_SIGN, CertificateKeyUsage.CRL_SIGN);
}

在公共方法中这样调用:

client.createNewCACertificate("Self", "root")

此初始步骤运行良好,并在密钥库中创建了一个证书:

Cert in key vault

但是,当我尝试将新创建的证书添加为颁发者时:

client.createIssuer(new CertificateIssuer(certificateName, "Self"))

呼叫失败,并出现以下错误:

com.azure.core.exception.HttpResponseException:状态代码400,“ {”错误“:{”代码“:” BadParameter“,”消息“:”此提供程序不允许进行帐户配置“”}}“ < / p>

我正在使用的主体具有以下权限:

{
    "permissions": {
        "certificates": [
            "Backup",
            "Delete",
            "Get",
            "List",
            "Create",
            "SetIssuers"
        ]
    }
}

尝试通过Key vaults -> my-keyvault - Certificates -> Certificate Authorities上的门户手动添加任何证书,也只能让我添加Microsoft所谓的“合作CA提供商”。我不需要全球认可的证书,我想充当自己的CA和RA。

我该如何实现?我希望能够基于此自签名根生成其他中间和/或叶证书。

0 个答案:

没有答案