krzyzanowskim / OpenSSL

OpenSSL package for SwiftPM, CocoaPod, and Carthage, multiplatform
https://swift.best
Other
920 stars 340 forks source link

Question about a Swift import issue #108

Closed lendvair closed 1 year ago

lendvair commented 3 years ago

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

gb-solutions commented 3 years ago

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

mcecunda commented 3 years ago

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.

Oni-zerone commented 3 years ago

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

krzyzanowskim commented 3 years ago

@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.

harmancode commented 2 years ago

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.

mmysliwiec commented 1 year ago

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?

krzyzanowskim commented 1 year ago

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

Rool commented 1 year ago

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);

krzyzanowskim commented 1 year ago

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

Rool commented 1 year ago

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

krzyzanowskim commented 1 year ago

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