Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on X509_check_private_key #234

Open
jdanthinne opened this issue Jan 21, 2025 · 0 comments
Open

Crash on X509_check_private_key #234

jdanthinne opened this issue Jan 21, 2025 · 0 comments

Comments

@jdanthinne
Copy link

I'm using OpenSSL 1.1.2301, and I recently got a crash report for X509_check_private_key, but by checking the source, I don't understand where that could come from. Before calling X509_check_private_key, I only call some other conversions methods, but none of them are throwing, so difficult to know if pointers are correctly created. Any clue/advice?

func pkcs12(fromPem pemCertificate: String, withPrivateKey pemPrivateKey: String) throws -> NSData {
    // Set OpenSSL parameters
    OpenSSL_add_all_algorithms()

    // Read certificate and private key
    let x509CertificateBuffer = BIO_new_mem_buf(pemCertificate, Int32(pemCertificate.count))
    let x509Certificate = PEM_read_bio_X509(x509CertificateBuffer, nil, nil, nil)

    let privateKeyBuffer = BIO_new_mem_buf(pemPrivateKey, Int32(pemPrivateKey.count))
    let privateKey = PEM_read_bio_PrivateKey(privateKeyBuffer, nil, nil, nil)

    defer {
        BIO_free(x509CertificateBuffer)
        BIO_free(privateKeyBuffer)
        X509_free(x509Certificate)
    }

    // Check if private key matches certificate
    guard X509_check_private_key(x509Certificate, privateKey) == 1 else {
        throw X509Error.privateKeyDoesNotMatchCertificate
    }

    
Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant