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

OpenSSL - byo v0.3.0 #3

Merged
merged 5 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Build Automation.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Begin CopyFilesBuildStep CopyOpenSSL
AppliesTo = 0
Architecture = 0
Target = 0
Destination = 2
Subdirectory =
FolderItem = Li4vb3BlbnNzbC8xLjEvbGliY3J5cHRvLjEuMS5keWxpYg==
Expand All @@ -17,6 +18,11 @@
FolderItem = Li4vb3BlbnNzbC8wLjkuOHpoL2xpYnNzbC4wLjkuOC5keWxpYg==
FolderItem = Li4vb3BlbnNzbC8zLjAvbGliY3J5cHRvLjMuZHlsaWI=
FolderItem = Li4vb3BlbnNzbC8zLjAvbGlic3NsLjMuZHlsaWI=
FolderItem = Li4vb3BlbnNzbC8zLjEvbGliY3J5cHRvLjMuMS5keWxpYg==
FolderItem = Li4vb3BlbnNzbC8zLjEvbGlic3NsLjMuMS5keWxpYg==
End
Begin SignProjectStep Sign
DeveloperID=
End
End
Begin BuildStepList Windows
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This example project shows how you can build the [OpenSSL](https://www.openssl.o

Included in this repository:
- [How to: Build OpenSSL on macOS](./openssl)
- Provides [Shell Script](./openssl/3.0/build.sh) you can use as a template to build the [OpenSSL](https://www.openssl.org) Library yourself
- A [Shell Script](./openssl/3.0/build.sh) you can use as a template to build the [OpenSSL](https://www.openssl.org) Library yourself
- Example Xojo Project - showing how to bundle your own built ```.dylib```'s in your application

### ScreenShots
Expand All @@ -21,7 +21,7 @@ Using OpenSSL 3.0.x in a Xojo built application
[Xojo](https://www.xojo.com/) is a rapid application development for Desktop, Web, Mobile & Raspberry Pi.

The Desktop application Xojo example project ```openssl-byo.xojo_project``` is using:
- Xojo 2021r3.1
- Xojo 2023r1.1
- API 2

### How to use in your own Xojo project?
Expand Down
8 changes: 5 additions & 3 deletions openssl-byo.xojo_project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Type=Desktop
RBProjectVersion=2021.031
RBProjectVersion=2023.011
MinIDEVersion=20150400
OrigIDEVersion=20210301
Folder=openssl-byo;openssl-byo;&h00000000119AB7FF;&h0000000000000000;false
Expand All @@ -13,13 +13,13 @@ MultiImage=AppIcon_64;resources/AppIcon_64.xojo_image;&h0000000048D837FF;&h00000
DefaultWindow=Window1
AppMenuBar=MainMenuBar
MajorVersion=0
MinorVersion=2
MinorVersion=3
SubVersion=0
NonRelease=0
Release=0
InfoVersion=OpenSSL - byo
LongVersion=jo-tools.ch
ShortVersion=0.2.0
ShortVersion=0.3.0
WinCompanyName=jo-tools.ch
WinInternalName=macos-openssl-byo
WinProductName=OpenSSL - byo
Expand All @@ -44,9 +44,11 @@ UseBuildsFolder=True
HiDPI=True
DarkMode=True
CopyRedistNextToWindowsEXE=False
IncludePDB=False
IsWebProject=False
LinuxBuildArchitecture=1
MacBuildArchitecture=4
OptimizationLevel=6
WindowsVersions={35138b9a-5d96-4fbd-8e2d-a2440225f93a}|{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}|{1f676c76-80e1-4239-95bb-83d0f6d0da78}|{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}
WindowsRunAs=0
MacOSMinimumVersion=
109 changes: 98 additions & 11 deletions openssl-byo/Window1.xojo_window
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ Begin Window Window1
TabIndex = 8
TabPanelIndex = 0
TabStop = True
Tooltip = ""
Tooltip = "OpenSSL Version"
Top = 110
Transparent = False
Underline = False
Expand Down Expand Up @@ -556,6 +556,12 @@ End
#tag Event
Sub Open()
Self.Examples()

#If TargetMacOS Then
Dim rect As Xojo.Rect = Self.Bounds
rect.Top = DesktopDisplay.DisplayAt(0).AvailableTop
Self.Bounds = rect
#EndIf
End Sub
#tag EndEvent

Expand Down Expand Up @@ -590,6 +596,9 @@ End
Case 2 '3.0
Me.Examples_3_0_SHA1()

Case 3 '3.1
Me.Examples_3_1_SHA1()

End Select
End Sub
#tag EndMethod
Expand Down Expand Up @@ -807,6 +816,77 @@ End
End Sub
#tag EndMethod

#tag Method, Flags = &h21
Private Sub Examples_3_1_SHA1()
Dim sError As String

#If TargetMacOS Then
Try
Const constLibCrypto = "@executable_path/../Frameworks/libcrypto.3.1.dylib"

Declare Function OpenSSL_version Lib constLibCrypto (i As Integer) As CString
Dim sData As String = ConvertEncoding(OpenSSL_version(0), Encodings.UTF8)
labSHA1Test.Tooltip = "SHA1 of '" + sData + "'"

//SHA1 Hash
Declare Function SHA1_Init Lib constLibCrypto (c As Ptr) As Integer
Declare Function SHA1_Update Lib constLibCrypto (c As Ptr, data As CString, mlen As Integer) As Integer
Declare Function SHA1_Final Lib constLibCrypto (md As Ptr, c As Ptr) As Integer

Dim mbSHAContext As New MemoryBlock(256)

Dim iRes As Integer = SHA1_Init(mbSHAContext)
If (iRes <> 1) Then
Dim err As New RuntimeException
err.Message = "SHA1_Init failed"
Raise err
End If

iRes = SHA1_Update(mbSHAContext, sData, sData.Bytes)
If (iRes <> 1) Then
Dim err As New RuntimeException
err.Message = "SHA1_Update failed"
Raise err
End If

Dim mbSHA1Result As New MemoryBlock(20) 'SHA1 Length
iRes = SHA1_Final(mbSHA1Result, mbSHAContext)
If (iRes <> 1) Then
Dim err As New RuntimeException
err.Message = "SHA1_Final failed"
Raise err
End If

Dim sResultBinary As String = mbSHA1Result
Dim sResult As String = Self.BinaryToHexString(sResultBinary)
labSHA1Test.Text = sResult
labSHA1Test.TextColor = &c00BB00

//Double check with Xojo's Crypto
Dim encryptedValue As String = Crypto.Hash(sData, Crypto.HashAlgorithms.SHA1)
Dim sResult2 As String = Self.BinaryToHexString(encryptedValue)
If (sResult <> sResult2) Then
sError = "SHA1 of OpenSSL and Xojo are different"
End If


Catch e As FunctionNotFoundException
sError = e.Message
Catch e As RuntimeException
sError = e.Message
End Try

#Else
sError = "This example is only for TargetMacOS"
#EndIf

If (sError <> "") Then
labSHA1Test.Text = sError
labSHA1Test.TextColor = &cFF0000
End If
End Sub
#tag EndMethod

#tag Method, Flags = &h21
Private Sub Examples_Version()
Dim sError As String
Expand All @@ -833,6 +913,12 @@ End
Declare Function OpenSSL_version Lib constLibCrypto (i As Integer) As CString
labOpenSSLVersion.Text = OpenSSL_version(0)

Case 3 '3.1
Const constLibCrypto = "@executable_path/../Frameworks/libcrypto.3.1.dylib"

Declare Function OpenSSL_version Lib constLibCrypto (i As Integer) As CString
labOpenSSLVersion.Text = OpenSSL_version(0)

End Select

labOpenSSLVersion.TextColor = &c00BB00
Expand Down Expand Up @@ -865,12 +951,11 @@ End
---------------------
This example is building OpenSSL as a Universal Binary for Intel-64Bit and ARM-64Bit.
It requires a macOS Version and Xcode version that is capable of building these two targets.
I am currently using: macOS 11.2, Xcode 12.4

1. Delete all files in the folder 'openssl', except for "build.sh"
2. Edit the Build Script "build.sh" with a TextEditor of your choice
3. change the variable to the OpenSSL version you're going to build
DOWNLOAD_OPENSSL_VERSION="1.1.1k"
DOWNLOAD_OPENSSL_VERSION="3.0.11"
4. Launch Terminal
5. Change to the openssl folder:
cd /path/to/where/you/have/saved/openssl-byo/openssl
Expand All @@ -890,19 +975,19 @@ End

Result:
In your "openssl" folder you should now have 2 files:
1. libssl.1.1.dylib
2. libcrypto.1.1.dylib
1. libssl.3.dylib
2. libcrypto.3.dylib

Note: The version number in the filename is being set automatically according to the version you've built.


How to: Use your own Openssl .dylib's in a Xojo project
How to: Use your own OpenSSL .dylib's in a Xojo project
-------------------------------------------------------
1. Open the example project "openssl-byo.xojo_binary_project"
Or create a new project, use your own, ...
2. In the Navigator, go to: Build Settings -> macOS
3. Use a "Post Build Step: Copy Files"
4. Drag in the two built .dylibs: libssl.1.1.dylib and libcrypto.1.1.dylib
4. Drag in the two built .dylibs: libssl.3.dylib and libcrypto.3.dylib
5. Set the Post Build Script behavior in the Inspector:
1. Applies to: both
2. Subdirectory: (empty)
Expand All @@ -913,7 +998,7 @@ End

As an example: Get the OpenSSL Version like this:

Const constLibCrypto = "@executable_path/../Frameworks/libcrypto.1.1.dylib"
Const constLibCrypto = "@executable_path/../Frameworks/libcrypto.3.dylib"
Declare Function OpenSSL_version Lib constLibCrypto (i As Integer) As CString
Me.Text = OpenSSL_version(0)

Expand Down Expand Up @@ -1077,11 +1162,13 @@ End
#tag Events lstBringYourOwn
#tag Event
Sub Open()
me.RemoveAllRows
Me.RemoveAllRows
me.AddRow "0.9.8"
me.AddRow "1.1"
me.AddRow "3.0"
me.SelectedRowIndex = me.LastRowIndex
Me.AddRow "3.0"
Me.AddRow "3.1"
Me.SelectedRowIndex = Me.LastRowIndex - 1

End Sub
#tag EndEvent
#tag Event
Expand Down
2 changes: 1 addition & 1 deletion openssl/1.1/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DOWNLOAD_OPENSSL_VERSION="1.1.1l"
DOWNLOAD_OPENSSL_VERSION="1.1.1w"

#Download
echo ----------------------------------------------
Expand Down
Binary file modified openssl/1.1/libcrypto.1.1.dylib
Binary file not shown.
Binary file modified openssl/1.1/libssl.1.1.dylib
Binary file not shown.
2 changes: 1 addition & 1 deletion openssl/3.0/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DOWNLOAD_OPENSSL_VERSION="3.0.1"
DOWNLOAD_OPENSSL_VERSION="3.0.11"

#Download
echo ----------------------------------------------
Expand Down
Binary file modified openssl/3.0/libcrypto.3.dylib
100644 → 100755
Binary file not shown.
Binary file modified openssl/3.0/libssl.3.dylib
100644 → 100755
Binary file not shown.
78 changes: 78 additions & 0 deletions openssl/3.1/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

DOWNLOAD_OPENSSL_VERSION="3.1.3"

#Download
echo ----------------------------------------------
echo - Download: OpenSSL $DOWNLOAD_OPENSSL_VERSION
echo ----------------------------------------------

curl -O https://www.openssl.org/source/openssl-$DOWNLOAD_OPENSSL_VERSION.tar.gz

echo ----------------------------------------------
echo - Extracting...
echo ----------------------------------------------

#Extract for Intel-64Bit build
tar -xvzf openssl-$DOWNLOAD_OPENSSL_VERSION.tar.gz
mv openssl-$DOWNLOAD_OPENSSL_VERSION openssl_x86_64

#Extract for ARM-64Bit build
tar -xvzf openssl-$DOWNLOAD_OPENSSL_VERSION.tar.gz
mv openssl-$DOWNLOAD_OPENSSL_VERSION openssl_arm64


#cleanup
rm openssl-$DOWNLOAD_OPENSSL_VERSION.tar.gz

echo ----------------------------------------------
echo - Building x86_64
echo ----------------------------------------------

#Build x86_64
cd openssl_x86_64
#modify SHLIB_VERSION so that .dylibs will have "3.1" in filename
sed -i -- 's/SHLIB_VERSION=3$/SHLIB_VERSION=3.1/g' ./VERSION.dat
#configure
./Configure darwin64-x86_64-cc -shared -mmacosx-version-min=10.10
#edit paths
sed -i -- 's/INSTALLTOP=\/.*/INSTALLTOP=./g' ./Makefile
sed -i -- 's/OPENSSLDIR=\/.*/OPENSSLDIR=./g' ./Makefile
sed -i -- 's/LIBDIR=lib.*/LIBDIR=./g' ./Makefile
make
FILENAME_VERSION_NUMBER=`grep -o "\"shlib_version\".*" ./configdata.pm | awk -F'"' '{print $4}'`
cd ../

echo ----------------------------------------------
echo - Building arm64
echo ----------------------------------------------

#Build arm64
cd openssl_arm64
#modify SHLIB_VERSION so that .dylibs will have "3.1" in filename
sed -i -- 's/SHLIB_VERSION=3$/SHLIB_VERSION=3.1/g' ./VERSION.dat
#configure
./Configure darwin64-arm64-cc -shared -mmacosx-version-min=10.10
#edit paths
sed -i -- 's/INSTALLTOP=\/.*/INSTALLTOP=./g' ./Makefile
sed -i -- 's/OPENSSLDIR=\/.*/OPENSSLDIR=./g' ./Makefile
sed -i -- 's/LIBDIR=lib.*/LIBDIR=./g' ./Makefile
make
FILENAME_VERSION_NUMBER=`grep -o "\"shlib_version\".*" ./configdata.pm | awk -F'"' '{print $4}'`
cd ../


echo ----------------------------------------------
echo - Combine arm64 and x86_64
echo ----------------------------------------------


#combine
lipo -create openssl_arm64/libcrypto.$FILENAME_VERSION_NUMBER.dylib openssl_x86_64/libcrypto.$FILENAME_VERSION_NUMBER.dylib -output libcrypto.$FILENAME_VERSION_NUMBER.dylib
lipo -create openssl_arm64/libssl.$FILENAME_VERSION_NUMBER.dylib openssl_x86_64/libssl.$FILENAME_VERSION_NUMBER.dylib -output libssl.$FILENAME_VERSION_NUMBER.dylib

#end
echo ----------------------------------------------
echo - Built: OpenSSL $DOWNLOAD_OPENSSL_VERSION
echo ----------------------------------------------

Binary file added openssl/3.1/libcrypto.3.1.dylib
Binary file not shown.
Binary file added openssl/3.1/libssl.3.1.dylib
Binary file not shown.
32 changes: 19 additions & 13 deletions openssl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ This example is building OpenSSL as a Universal Binary for Intel-64Bit and ARM-6
It requires a macOS Version and Xcode version that is capable of building these two targets.

The included built ```.dylib```'s have been built using:
- macOS 12.2.1
- Xcode 13.2.1
- macOS 13.6
- Xcode 15.0

## Let's build OpenSSL
There are subfolders for different OpenSSL versions.
Version [0.9.8](./0.9.8zh) needs some manual modifications in order to compile it for ARM-64Bit. However - it's an outdated version. So best look in the folders [1.1](./1.1) and [3.0](./3.0)

1. Delete all files in the folder, except for ```build.sh```
2. Edit the Build Script ```build.sh``` with a TextEditor of your choice
3. Change the variable to the OpenSSL version you're going to build:
- To build OpenSSL 3.0.x:
```DOWNLOAD_OPENSSL_VERSION="3.0.1"```
- To build OpenSSL 1.1.1x:
```DOWNLOAD_OPENSSL_VERSION="1.1.1l"```
4. Launch Terminal
5. Change to the openssl build folder:
- Version [0.9.8](./0.9.8zh) needs some manual modifications in order to compile it for ARM-64Bit.
However - it's an outdated OpenSSL version.
- For Version [3.1](./3.1) the script modifies `VERSION.dat` so that .dylibs will have `3.1` in the filename.
- So best look in the folders [3.0 (LTS)](./3.0), [3.1](./3.1) and [1.1](./1.1).

How to build OpenSSL using the provided Shell Scripts:
1. Launch Terminal
2. Change to the OpenSSL build folder:
```cd /path/to/where/you/have/saved/openssl-byo/openssl/3.0```
3. Delete all files in the folder, except for ```build.sh```
4. Edit the Build Script ```build.sh``` with a TextEditor of your choice
5. Change the variable to the OpenSSL version you're going to build:
- To build OpenSSL 3.0.x (LTS):
```DOWNLOAD_OPENSSL_VERSION="3.0.11"```
- To build OpenSSL 3.1.x:
```DOWNLOAD_OPENSSL_VERSION="3.1.3"```
- To build OpenSSL 1.1.1x:
```DOWNLOAD_OPENSSL_VERSION="1.1.1w"```
6. just in case: the build script needs to be executable:
```chmod 755 ./build.sh```
7. Run the Script build.sh:
Expand Down
Binary file modified screenshots/example_openssl-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.