andrewcbancroft / SwiftyLocalReceiptValidator

An implementation of local receipt validation logic for iOS in Swift
MIT License
286 stars 32 forks source link

Use of unresolved identifier c2i_ASN1_INTEGER #8

Closed simonmitchell closed 6 years ago

simonmitchell commented 6 years ago

I'm trying to use code similar to this, however with the version of OpenSSL (v1.1.1) that I have compiled myself (Using a similar script to the CocoaPod you use) I get Use of unresolved identifier c2i_ASN1_INTEGER. It seems like that file is in the Crypto framework rather than the OpenSSL framework, but even if I get that into an importable state it doesn't work 😞

I'm very new to cryptography and trying to use OpenSSL, do you have any ideas?

andrewcbancroft commented 6 years ago

Hey Simon - I apologize, but I don't know off the top of my head. I'll need to get some code in front of me at some point in the near future to try and help troubleshoot.

simonmitchell commented 6 years ago

Hi there! Thanks for the quick response 😊 I ended up doing what you did with pkcs7_union_accessors.h and copy-pasting the code from the c file in the Crypto library into my project and all works nicely! Will mark this as closed 😄

andrewcbancroft commented 6 years ago

Oh awesome! I'm glad that union accessor workaround worked. I couldn't tell if that could be the source of the problem or not, haha. Thanks for following up and closing out the issue with your solution. Hope you have a great day, Simon!

chamitha commented 6 years ago

I am having this issue as well. Is there a solution without the need to copy across C code? If not can you please elaborate a bit further on the workaround? Thanks!

simonmitchell commented 6 years ago

Hi @chamitha, I tried to go the route of also importing the headers from where this code has moved to, but couldn’t get that to work! I haven’t been on this project for a while, but will try and get a code example to you soon!

zzdravkin commented 5 years ago

Problem is your Header Search Paths and Library Search Paths

If you add folder OpenSSL to your project, and all files for OpenSSL will be there. Add OpenSSL folder to the top of your Project (not in subfolders)

Click on the project Select the application’s target Select the Build Settings tab Select the All and Combined filters. Add the following values:

$(PROJECT_DIR)/OpenSSL/include - Header Search Paths $(PROJECT_DIR)/OpenSSL/lib - Library Search Paths

aalenliang commented 4 years ago

https://github.com/openssl/openssl/issues/7538

The c2i functions are considered internal only and were removed from the public API in OpenSSL 1.1.0. You should use the d2i equivalents instead.

Maybe we should use d2i_ASN1_INTEGER instead of c2i_ASN1_INTEGER? But apparently, they are not the same, it's really difficult for me to convert the c2i function call into the d2i version.

thejeff77 commented 3 years ago

This was my solution based off of openssl#7538

    func DecodeASN1Integer(startOfInt intPointer: inout UnsafePointer<UInt8>?, length: Int) -> Int? {
        let integer = d2i_ASN1_UINTEGER(nil, &intPointer, length)
        let result = ASN1_INTEGER_get(integer)
        ASN1_INTEGER_free(integer)
        return result
    }
Rumy-hasan commented 3 years ago

here is an explanation for understanding how it works.