2

重複の可能性:
生成された署名付きX.509クライアント証明書が無効です(CAへの証明書チェーンがありません)

私は次の例に従いました:

http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation

ただし、結果の署名付きクライアント証明書は、Windowsで開くと次のエラーが発生します。

「このファイルは、次のように使用するには無効です:セキュリティ証明書」

とにかくインストールしてcertmgrで表示すると、認証パスはOKに見えます-自己署名認証局(問題ありません、問題ありません)が表示されますが、クライアント証明書のステータスは次のとおりです。

「この証明書には無効なデジタル署名があります。」

X509Certificate.Verify()を呼び出すと、次の例外がスローされます。

「証明書の署名用ではなく公開鍵が提示されました」

それでも、Pkcs10CertificationRequestから抽出されたものとまったく同じ公開鍵を使用しており、Verify()を呼び出したときは問題ありません。

何か案は?これに何日も苦労した後、私はこの最後のものを除いてすべての部分が機能するようになりました-そして本当に混乱しているのは、私の自己署名CA証明書が問題ないということです。クライアント証明書で何かが起こっているだけです。コードのブロック全体は次のとおりです。

        TextReader textReader = new StreamReader("certificaterequest.pkcs10");
        PemReader pemReader = new PemReader(textReader);

        Pkcs10CertificationRequest certificationRequest = (Pkcs10CertificationRequest)pemReader.ReadObject();
        CertificationRequestInfo certificationRequestInfo = certificationRequest.GetCertificationRequestInfo();
        SubjectPublicKeyInfo publicKeyInfo = certificationRequestInfo.SubjectPublicKeyInfo;

        RsaPublicKeyStructure publicKeyStructure = RsaPublicKeyStructure.GetInstance(publicKeyInfo.GetPublicKey());

        RsaKeyParameters publicKey = new RsaKeyParameters(false, publicKeyStructure.Modulus, publicKeyStructure.PublicExponent);

        bool certIsOK = certificationRequest.Verify(publicKey);
        // public key is OK here...

        // get the server certificate
        Org.BouncyCastle.X509.X509Certificate serverCertificate = DotNetUtilities.FromX509Certificate(System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile("servermastercertificate.cer"));

        // get the server private key
        byte[] privateKeyBytes = File.ReadAllBytes("serverprivate.key");
        AsymmetricKeyParameter serverPrivateKey = PrivateKeyFactory.CreateKey(privateKeyBytes);

        // generate the client certificate
        X509V3CertificateGenerator generator = new X509V3CertificateGenerator();

        generator.SetSerialNumber(BigInteger.ProbablePrime(120, new Random()));
        generator.SetIssuerDN(serverCertificate.SubjectDN);
        generator.SetNotBefore(DateTime.Now);
        generator.SetNotAfter(DateTime.Now.AddYears(5));
        generator.SetSubjectDN(certificationRequestInfo.Subject);
        generator.SetPublicKey(publicKey);
        generator.SetSignatureAlgorithm("SHA512withRSA");
        generator.AddExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(serverCertificate));
        generator.AddExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(publicKey));

        var newClientCert = generator.Generate(serverPrivateKey);

        newClientCert.Verify(publicKey); // <-- this blows up

        return DotNetUtilities.ToX509Certificate(newClientCert).Export(X509ContentType.Pkcs12, "user password");
4

1 に答える 1

1

私はこれを理解しました。を呼び出すX509Certificate.Verify(publicKey)場合は、 からのクライアントの公開鍵ではなく、CA の公開鍵を渡す必要がありますPkcs10CertificationRequest

于 2011-01-14T01:42:26.260 に答える