OpenSSL icon indicating copy to clipboard operation
OpenSSL copied to clipboard

Question about a Swift import issue

Open lendvair opened this issue 5 years ago • 5 comments

Hi Marcin,

I tried to build your CocoaPods Example application on master branch. Downloaded, pod install, build, happiness.

If I insert at line 17 in AppDelegate.swift:

let cert : UnsafeMutablePointer<X509>

Xcode failed to build the application with the following error at line 17: Cannot find type 'X509' in scope. I've tried everything to solve this issue, but ran out of ideas.

Xcode 12.3 (12C33)

Could you check it please?

Best regards, Richard

lendvair avatar Jan 04 '21 21:01 lendvair

Any idea @krzyzanowskim? Still couldn't solve this issue. Are you able to reproduce it?

gb-solutions avatar Jan 06 '21 20:01 gb-solutions

Hi, this issue is related to update of underlying OpenSSL library (from 1.0.* to 1.1.*) made here in this repo in July.

OpenSSL 1.1.* switched to predefined C structs and Swift is not handling them very nicely. You can read something about it here.

mcecunda avatar Jan 14 '21 21:01 mcecunda

Hi, I'm also having issues with Xcode 12.3 (12C33), I've tried to import OpenSSL in every way possible, also tried to run the Cocoapods Integration-Example, but I'm always getting the same error: No such module 'OpenSSL' Someone can help me? I need to upgrate OpenSSL to the latest version to get M1 support... Thanks

Oni-zerone avatar Jan 18 '21 11:01 Oni-zerone

@Oni-zerone arm is supported since 1.1.x. It looks like some configuration issue you have. You can always get OpenSSL.xcframework and link it manually.

krzyzanowskim avatar Jan 18 '21 18:01 krzyzanowskim

I got the same issue with @Oni-zerone. I have Xcode 13.1 and OpenSSL 1.1.13 added via Swift Package Manager, and "No such module OpenSSL" error appeared when I try to use import OpenSSL line.

This error disappears when I clean the build folder, build the project, and wait until the build process is complete.

harmancode avatar Jan 18 '22 03:01 harmancode

For me, the import seems working fine (I'm using SPM) but I have the same error as @lendvair: Cannot find type 'X509' in scope for a simple line: let cert : UnsafeMutablePointer<X509> How to solve this? Is it some configuration issue or we can't use X509 this way anymore? If not, what is a proper implementation for dealing with X509 certificates now? @lendvair were you able to fix this?

mmysliwiec avatar Apr 14 '23 08:04 mmysliwiec

X509 struct is no longer part of the public API in OpenSSL 1.1.x. All you can do is use OpaquePointer with functions

krzyzanowskim avatar Apr 14 '23 10:04 krzyzanowskim

I'm using the library in Objective-C and can use the X509 stuff with an import

#import <openssl/x509.h> #import <openssl/x509v3.h> #import <openssl/x509_vfy.h>

And do stuff like X509 *x509 = PEM_read_bio_X509(blob, NULL, 0, NULL);

Rool avatar Apr 14 '23 18:04 Rool

afair struct itself is in private header, the X509 is just a declaration, and Swift don't understand that

krzyzanowskim avatar Apr 14 '23 19:04 krzyzanowskim

There is a new Apple package for working with X509 certificates. Haven't tried that myself.

Rool avatar Apr 15 '23 08:04 Rool

Whatever you do, you just need to use X509 functions that are available and pass OpaquePointer

let x509 = d2i_X509(...) // OpaquePointer
X509_free(x509)

also since Swift can't import macros, some functions may not be available and you have to untangle C macro manually

krzyzanowskim avatar Apr 16 '23 14:04 krzyzanowskim