Skip to content

Blog

WebDav Based On Caddy

This article introducing a method on servering webdav service with CaddyServer.

The easiest way to install caddy is using package manager.

  • On Debian/Ubuntu

    sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
    | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
    | sudo tee /etc/apt/sources.list.d/caddy-stable.list
    sudo apt update
    sudo apt install caddy
  • On RHEL/CentOS/RockyLinux

    dnf install 'dnf-command(copr)'
    dnf copr enable @caddy/caddy
    dnf install caddy
  • Add Packages Online

    sudo caddy add-package XXX

    XXX is the package name, which always start with github.com/xxxxxx.

    It’s easy to find packages name from Download Page.

    Examples:

    install webdav module:

    sudo caddy add-package github.com/mholt/caddy-webdav

  • Add Packages Manually

    Select and Download CaddyServer with modules from Download Page.

    Replace executable caddy file with downloaded:

    sudo mv caddy /usr/bin
    sudo chmod +x /usr/bin/caddy
    sudo restorecon /usr/bin/caddy
    sudo chown root:root /usr/bin/caddy

Due to the configuration in default systemd file, the parameter ProtectSystem=full, caddy lose the permission on writing /usr, /boot and /etc.(Reference-2 for details).

  • Add ReadWrite permission to caddy web folder /usr/share/caddy Adding paramter to service file /usr/lib/systemd/system/caddy.service under [service] lable:

  • Reload systemd

    sudo systemctl daemon-reload

4. Make caddy has authority to access files

Section titled “4. Make caddy has authority to access files”
  • Change the owner of /path/to/data with caddy

    sudo chwon caddy /path/to/data -R

  • Add caddy to the group of the files’ owner

    sudo usermod -a -G $GROUP

  • webdav Module Configure introduction is available: caddy-webdav

    {
    basicauth {
    username password_generate_by_openssl
    }
    root * /path/to/data/
    route {
    rewrite /webdav /webdav/
    webdav /webdav/* {
    prefix /webdav
    }
    }
    file_server browse
    }
  • global config set webdav before file_server:

    {
    order webdav before file_server
    }

[1]. https://caddyserver.com/docs/install

[2]. https://www.redhat.com/sysadmin/mastering-systemd

[3]. https://github.com/abiosoft/caddy-webdav

[4]. Reverse-Proxy-with-Caddy-on-RHEL

Webhook Based On Caddy

This article introducing a method on building webhook service with CaddyServer.

The easiest way to install caddy is using package manager.

  • On Debian/Ubuntu

    sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
    | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
    | sudo tee /etc/apt/sources.list.d/caddy-stable.list
    sudo apt update
    sudo apt install caddy
  • On RHEL/CentOS/RockyLinux

    dnf install 'dnf-command(copr)'
    dnf copr enable @caddy/caddy
    dnf install caddy
  • Add Packages Online

    sudo caddy add-package XXX

    XXX is the package name, which always start with github.com/xxxxxx.

    It’s easy to find packages name from Download Page.

    Examples:

    install webhook module:

    sudo caddy add-package github.com/WingLim/caddy-webhook

    install exec module:

    sudo caddy add-package github.com/mholt/caddy-events-exec

  • Add Packages Manually

    Select and Download CaddyServer with modules from Download Page.

    Replace executable caddy file with downloaded:

    sudo mv caddy /usr/bin
    sudo chmod +x /usr/bin/caddy
    sudo restorecon /usr/bin/caddy
    sudo chown root:root /usr/bin/caddy

Due to the configuration in default systemd file, the parameter ProtectSystem=full, caddy lose the permission on writing /usr, /boot and /etc.(Reference-2 for details).

  • Add ReadWrite permission to caddy web folder /usr/share/caddy Adding paramter to service file /usr/lib/systemd/system/caddy.service under [service] lable:

    ReadWritePaths=/usr/share/caddy

  • Reload systemd

    sudo systemctl daemon-reload

  • Webhook Module Configure introduction is available: caddy-webhook

    route /webhook {
    webhook {
    repo https://github.com/WingLim/winglim.github.io.git
    path /usr/share/caddy
    branch master
    depth 1
    type github/gitlab/gitee/gogs/bitbucket
    command
    username
    password
    key
    token
    submodule
    }
    }
  • Exec Module Configure introduction is available: caddy-exec

    route /webhook {
    exec {
    command git
    args pull
    directory /usr/share/caddy
    log file /var/log/caddy/git.log
    }
    }

[1]. https://caddyserver.com/docs/install

[2]. https://www.redhat.com/sysadmin/mastering-systemd

[3]. https://github.com/abiosoft/caddy-exec

[4]. https://github.com/WingLim/caddy-webhook

[5]. Reverse-Proxy-with-Caddy-on-RHEL

GnuPG Home Configuration on Winodws

The default GnuPG home is ~/.gnupg on Linux, and ~\AppData\Roaming\gnupg on Windows.

To change the gnupg home on Windows, set a System Variables in Environment Variables:

Variable = GNUPGHOME
VALUE = ~\gnupg

You should do the commands one by one.

[1].https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration.html

[2].https://www.gnupg.org/gph/en/manual/r1616.html

[3]. OpenPGP-初探

Yubikey-PIV-as-SSH-Key

Use Yubikey as SSH Key.

1. Install OpenSC and YubiKey Manager (CLI only)

Section titled “1. Install OpenSC and YubiKey Manager (CLI only)”
sudo apt update
sudo apt install opensc yubikey-manager

2. If this is a new Yubikey, change the default PIV management key, PIN and PUK.

Section titled “2. If this is a new Yubikey, change the default PIV management key, PIN and PUK.”

The ykman tool can generate a new management key for you. For the PIN and PUK you’ll need to provide your own values (6-8 digits).

ykman piv change-management-key --touch --generate
ykman piv change-pin -P 123456
ykman piv change-puk -p 12345678

Make sure you save the generated password somewhere secure such as a password manager. The management key is needed any time you generate a keypair, import a certificate or change the number of PIN or PUK retries

The PUK should also be kept somewhere safe. This is used if the PIN is entered incorrectly too many times.

  1. Ensure CCID mode is enabled on the Yubikey
ykman mode

If CCID is not in the list, enable it by adding CCID to the list, e.g.

ykman mode OTP+FIDO+CCID

(This assumes you had OTP+FIDO previously, and still want them enabled.)

  1. Generate a PIV key and output the public key
ykman piv generate-key 9a pubkey.pem

Alternatively, you can require that you have to touch the Yubikey every time the slot is accessed:

ykman piv generate-key --touch-policy always 9a pubkey.pem

This is an RSA 2048-bit key by default. Depending which Yubikey you have, you can change it using -a / --algorithm.

(9a is the PIV authentication slot.)

  1. Generate a self-signed X.509 certificate
ykman piv generate-certificate -s "SSH key" 9a pubkey.pem
  1. Setting the system path

Go to Control Panel → System and Security → System → Advanced system setting

Click “Environment Variables…“

Under System Variables, highlight “Path“ and click “Edit…“

Click “New“ and add the absolute path to Yubico PIV Tool\bin

  1. Set ssh config file

Open PowerShell and run the following:

New-Item -Path $env:USERPROFILE\.ssh\ -Name "config" -ItemType "file" -Value `
'PKCS11Provider "C:\Program Files\Yubico\Yubico PIV Tool\bin\libykcs11.dll"'
  1. Export your SSH public key from the Yubikey
ssh-keygen -D /usr/local/lib/opensc-pkcs11.so

And that’s all the hard stuff done.

Now just add the public key to your authorized_keys file on a remote host and try to use it:

ssh -I /usr/local/lib/opensc-pkcs11.so -i /usr/local/lib/opensc-pkcs11.so \
-o IdentitiesOnly=yes server.example.com

You should be prompted for your Yubikey’s PIV PIN.

You can add the PKCS11 library to ssh-agent.

ssh-add -s /usr/local/lib/opensc-pkcs11.so

Once more you will be prompted for your PIN, and from there SSH authentication will happen as usual.

To configure ssh to use the Yubikey’s SSH key, use the PKCS11Provider config option instead of IdentityFile, e.g.:

Host foo
PKCS11Provider /usr/local/lib/opensc-pkcs11.so
IdentitiesOnly yes
  • When SSHing, you may get prompted with the key’s subject name, like Enter PIN for 'SSH key':. But if you add the key to the agent, you’ll get a prompt like Enter passphrase for PKCS#11:. These are the same PIN (your PIV PIN).

  • If you remove the key from ssh-agent using ssh-add -d or ssh-add -D, you’ll have to either remove and re-add the PKCS library to the agent or restart the agent.

    • To re-add the library run
      ssh-add -e /usr/local/lib/opensc-pkcs11.so
      ssh-add -s /usr/local/lib/opensc-pkcs11.so

[1].https://github.com/jamesog/yubikey-ssh

[2].SSH-Configuration

FFmpeg Development Environment

Build a FFmpeg developing environment on Ubuntu-22.04-LTS with Qt and SDL.

Update all repositories.

sudo apt update && apt upgrade

Resolved in Ubuntu 22.04.2 LTS

On Video decoding/encoding with FFmpeg

  • x264

    • libavcodec58
      • libavcodec-extra58
    • libavformat58
      • libavformat-extra58
    • libavutil56
    • libc6
    • libffms2-5
    • libgpac11
    • libswscale5
    • libx264-163
  • x265

    • libc6
    • libstdc++6
    • libx265-199
    • libx265-199
  • libx264-dev

    • libx264-163
  • libx265-dev

    • libx265-199
  • libass-dev

    • libass9
    • libfontconfig1-dev
      • libfontconfig-dev
    • libfreetype-dev
    • libfribidi-dev
    • libharfbuzz-dev
  • libfdk-aac-dev

    • libfdk-aac2
    • pkg-config
      • pkg-config:i386
      • pkgconf
  • libfreetype-dev

    • libfreetype6
    • libbrotli-dev
    • libc6-dev
    • libc-dev
      • libc6-dev
    • zlib1g-dev
    • libz-dev
      • zlib1g-dev
  • libmp3lame-dev

    • libmp3lame0
  • libopus-dev

    • libopus0
  • libvorbis-dev

    • libogg-dev
    • libvorbis0a
    • libvorbisenc2
    • libvorbisfile3
  • libvpx-dev

    • libvpx7

On Audio decoding/encoding with SDL2:

  • libsdl2-dev
    • libasound2-dev
    • libdbus-1-dev
    • libdecor-0-dev
    • libdrm-dev
    • libegl1-mesa-dev
    • libgbm-dev
    • libgl-dev
    • libgles-dev
    • libglu1-mesa-dev
    • libibus-1.0-dev
    • libpulse-dev
    • libsdl2-2.0-0
    • libsndio-dev
    • libudev-dev
    • libwayland-dev
    • libx11-dev
    • libxcursor-dev
    • libxext-dev
    • libxfixes-dev
    • libxi-dev
    • libxinerama-dev
    • libxkbcommon-dev
    • libxrandr-dev
    • libxss-dev
    • libxt-dev
    • libxv-dev
    • libxxf86vm-dev
    • libc6
    • libopengl0
    • libx11-6

On configuring FFmpeg:

  • yasm
    • libc6

Install all dependencies with following command:

sudo apt install yasm gcc g++ cmake make \
x264 x265 libx264-dev libx265-dev \
libass-dev libfdk-aac-dev libvorbis-dev \
libfreetype-dev libmp3lame-dev libopus-dev \
libvpx-dev libsdl2-dev

Install Qt with Qt Online Installer.

It’s better to install Qt with USTC’s mirror.

Install with commands: .\qt-unified-windows-x86-online.exe --mirror https://mirrors.ustc.edu.cn/qtproject

DO NOT install Qt with sudo command nor with user ROOT.

If you prefer Qt Online Installer, libxcb-xinerama.so.0 is needed. To install this dependency, run following command sudo apt install libxcb-xinerama0.

It’s possible to install Qt from source. Follow the instruction, and the script is available here.

Download FFmpeg from Offical Web Site, install with compile commands below:

wget http://ffmpeg.org/releases/ffmpeg-4.2.9.tar.xz
tar -xvf ffmpeg-4.2.9.tar.xz
cd ffmpeg-4.2.9
sudo ./configure --enable-gpl --enable-libass --enable-libfdk-aac \
--enable-libfreetype --enable-libmp3lame --enable-libopus \
--enable-libvorbis --enable-libvpx --enable-libx264 \
--enable-libx265 --enable-pic --enable-shared --enable-nonfree \
--prefix=/usr/local/ffmpeg-4.2.9
make -j8
sudo make install

SDL2 has installed with system, headers installed when dependencies installed.

One-key environment installing script is provided:

Qt Framework will be installed via local compile, and downloaded opensource from USTC Mirror.

Qt will be installed in path: /usr/local/qt-5.15.2

  • Add FFmpeg to INCLUDEPATH in .pro file.

    • Add dynamic link -lavfilter -lavformat -lavdevice -lavcodec -lpostproc -lswscale -lavutil -lswresample to LIBS in .pro file for FFmpeg;
  • Add -lSDL2main -lSDL2 for SDL.

[1].https://qt.io

[2].http://mirrors.ustc.edu.cn/help/qtproject.html

[3].http://ffmpeg.org

[4].https://libsdl.org/

[5].https://blog.csdn.net/a1367666195/article/details/126055594

[6].https://askubuntu.com/questions/1298645/shared-library-not-found-for-pyqt5-libxcb-xinerama-so-0-not-found

[7]. Install-Qt-From-Source

[8]. VSCode-C-CPP-Environment