Download :
- openssh-9.9p2.tar.gz from https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.9p2.tar.gz
- openssl-3.4.1.tar.gz from https://www.openssl.org/source/openssl-3.4.1.tar.gz
 - zlib 1.3.1 from https://zlib.net/zlib-1.3.1.tar.gz
Note: Very important to compile in /tmp/$USER and not in a home directory or it may cause NFS lookups when executing ssh

Note: if patch needs to be updated, this can be done with command "diff -Naur oldfile newfile"

setenv CC gcc
export CC=gcc

====================
Linux/Cygwin:
====================
Linux only: Compile on (from citrix) seliiuts02919.seli.gic.ericsson.se or seliiuts03047 or seliiuts02893 to seliiuts02913 or ottlsvr18 (libc 2.11.3.1) (or seliiuts02929 or sekilx484.wrbs.rnd.ki.sw.ericsson.se or sekilx1260.wrbs.rnd.ki.sw.ericsson.se)

Cygwin only: Make sure that the following dependencies are installed:
	gcc-core
	patch
	make
	libncurses-devel

setenv CC gcc
export CC=gcc
module add perl/5.14.2
module add gcc/10.2.0
module add make/4.3

cd /tmp/$USER
unzip ~/moshell/commonjars/src/openssh/patches.zip -d ~/moshell/commonjars/src/openssh/
rm -rf zlib-1.3.1 && tar xf zlib-1.3.1.tar.gz
cd /tmp/$USER/zlib-1.3.1
#on cygwin32 (not needed for 64), run: cp ~/moshell/commonjars/src/openssh/patches/1.3.1-cygwin-no-widechar.patch .  && patch -p1 -i 1.3.1-cygwin-no-widechar.patch
env CFLAGS="-g -O2 -fPIC" LDSHARED="gcc " ./configure && make 

cd /tmp/$USER
rm -rf openssh-9.9p2 && tar xf openssh-9.9p2.tar.gz
rm -rf openssl-3.4.1 && tar xf openssl-3.4.1.tar.gz

cd /tmp/$USER/openssl-3.4.1
cp ~/moshell/commonjars/src/openssh/patches/0001-Moshell-SSL-mods-3.4.0.patch .
cp ~/moshell/commonjars/src/openssh/patches/0001-Restore-SHA1-security-strength-3.4.0.patch .
cp ~/moshell/commonjars/src/openssh/patches/0001-Allow-client-unsafe-renegotiation-3.4.0.patch .
patch -p1 -i 0001-Moshell-SSL-mods-3.4.0.patch
patch -p1 -i 0001-Restore-SHA1-security-strength-3.4.0.patch
patch -p1 -i 0001-Allow-client-unsafe-renegotiation-3.4.0.patch
Linux:  ./config -fPIC no-shared no-threads -DOPENSSL_TLS_SECURITY_LEVEL=1 && make depend && make
Cygwin: ./config no-shared no-threads enable-capieng -DOPENSSL_TLS_SECURITY_LEVEL=1 && make depend && make

cd /tmp/$USER/openssh-9.9p2
cp ~/moshell/commonjars/src/openssh/patches/0001-Moshell-SSH-mods-9.9p1.patch .
patch -p1 -i 0001-Moshell-SSH-mods-9.9p1.patch
Linux: env CFLAGS="-std=gnu99 -g -O2 -fPIC" LDSHARED="gcc " ./configure --enable-dsa-keys --with-ssl-dir=../openssl-3.4.1 --with-zlib=../zlib-1.3.1 && make
Cygwin: patch configure configure_openssh_cygwin.patch
Cygwin: env LDLIBS="-lcrypt32" ./configure --enable-dsa-keys --with-ssl-dir=../openssl-3.4.1 --with-zlib=../zlib-1.3.1 && make

Keep the following files and store them in the following locations, with the correct extension (.linux, .lin64)
os=exe lin64 (choose appropriate one)
lib=cygwin lin64 (choose appropriate one)
echo $os $lib
strip /tmp/$USER/openssh-9.9p2/ssh            && cp /tmp/$USER/openssh-9.9p2/ssh           ~/moshell/commonjars/ssh.$os
strip /tmp/$USER/openssh-9.9p2/sftp           && cp /tmp/$USER/openssh-9.9p2/sftp          ~/moshell/commonjars/sftp.$os
strip /tmp/$USER/openssh-9.9p2/sshd           && cp /tmp/$USER/openssh-9.9p2/sshd          ~/moshell/commonjars/sshd.$os
strip /tmp/$USER/openssh-9.9p2/sftp-server    && cp /tmp/$USER/openssh-9.9p2/sftp-server   ~/moshell/commonjars/sftp-server.$os
strip /tmp/$USER/openssh-9.9p2/scp            && cp /tmp/$USER/openssh-9.9p2/scp           ~/moshell/commonjars/scp.$os
strip /tmp/$USER/openssh-9.9p2/sshd-session   && cp /tmp/$USER/openssh-9.9p2/sshd-session  ~/moshell/commonjars/sshd-session.$os
strip /tmp/$USER/openssl-3.4.1/apps/openssl  && cp /tmp/$USER/openssl-3.4.1/apps/openssl   ~/moshell/commonjars/openssl.$os
strip /tmp/$USER/openssl-3.4.1/providers/legacy.so && cp /tmp/$USER/openssl-3.4.1/providers/legacy.so ~/moshell/commonjars/lib/$lib/legacy.so

update mos2emInfo["ssh_version"] in moshell/prog.awk


########################################
How to make the patch files for OpenSSL:
########################################
*** In cygwin:
cd /tmp/$USER 
rm -rf openssl-3.4.1
tar xf openssl-3.4.1.tar.gz
cd openssl-3.4.1
copy the patch files to openssl-3.4.1 and run them with patch -p1 -i <file>.patch
*** In WSL:
cd $HOME
rm -rf dummy
mkdir dummy
cd dummy
#module add git
git init
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1.tar.gz .
tar -xf openssl-3.4.1.tar.gz
cd openssl-3.4.1
cp -R $HOME/dummy/.git .
git add -A :/
git commit -m 'Base'
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/apps/include/s_apps.h        apps/include/s_apps.h     
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/apps/lib/s_socket.c          apps/lib/s_socket.c       
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/apps/s_client.c              apps/s_client.c           
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/crypto/bio/bio_sock2.c       crypto/bio/bio_sock2.c    
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/include/openssl/bio.h.in     include/openssl/bio.h.in  
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/ssl/ssl_ciph.c               ssl/ssl_ciph.c            
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/util/libcrypto.num           util/libcrypto.num        
git status
git add -A :/
git commit -m 'Moshell SSL mods 3.4.1'
git format-patch HEAD^
mv 0001-Moshell-SSL-mods-3.4.1.patch ~/
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/ssl/t1_lib.c ssl/t1_lib.c
git status
git add -A :/
git commit -m 'Restore SHA1 security strength 3.4.1'
git format-patch HEAD^
mv 0001-Restore-SHA1-security-strength-3.4.1.patch ~/
cp /mnt/c/cygwin64/tmp/$USER/openssl-3.4.1/ssl/ssl_lib.c ssl/ssl_lib.c
git status
git add -A :/
git commit -m 'Allow client unsafe renegotiation 3.4.1'
git format-patch HEAD^
mv 0001-Allow-client-unsafe-renegotiation-3.4.1.patch ~/
mv ~/0001-*.patch /mnt/c/Users/$USER/Desktop

########################################
How to make the patch files for OpenSSL:
########################################
*** In cygwin:
cd /tmp/$USER 
rm -rf openssh-9.9p2
tar xf openssh-9.9p2.tar.gz
cd openssh-9.9p2
copy the patch file to openssl-9.9p2 and run with patch -p1 -i <file>.patch
*** In WSL:
cd $HOME
rm -rf dummy
mkdir dummy
cd dummy
#module add git
git init
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2.tar.gz .
tar -xf openssh-9.9p2.tar.gz
cd openssh-9.9p2
cp -R $HOME/dummy/.git .
git add -A :/
git commit -m 'Base'
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/auth-passwd.c    ./auth-passwd.c
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/compat.c         ./compat.c     
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/myproposal.h     ./myproposal.h 
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/scp.c            ./scp.c        
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/sftp-client.c    ./sftp-client.c
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/sftp.c           ./sftp.c       
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/ssh.c            ./ssh.c        
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/sshconnect.c     ./sshconnect.c 
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/sshconnect.h     ./sshconnect.h 
cp /mnt/c/cygwin64/tmp/$USER/openssh-9.9p2/sshconnect2.c    ./sshconnect2.c
git status
git add -A :/
git commit -m 'Moshell SSH mods 9.9p2'
git format-patch HEAD^
mv 0001-Moshell-SSH-mods-9.9p2.patch ~/
#############################

