Skip to content

2022

Calculate the Fingerprint for a Certificate

We can run the following command to calculate the fingerprint for a certificate public key.

Bash
openssl x509 -fingerprint -sha256 -in /path/to/certifiacte/pem

It will show the fingerprint like,

Bash
root@Debian-11:~# openssl x509 -fingerprint -sha256 -in /etc/ssl/domain/pub.pem
SHA256 Fingerprint=7C:28:F2:79:D5:65:67:B0:A8:BC:AF:8A:DC:ED:63:9D:7F:D9:63:06:6E:B4:FD:05:4F:F1:1E:F9:7D:7F:1D:BD
...

Generate a self-signed Certificate for a Domain

We can use openssl to generate a self-signed certificate for a domain for testing puspose, and use it for Nginx or any other tools.

The following command are used to generate.

Bash
sudo mkdir /etc/ssl/domain

sudo openssl req -x509 -nodes -days 3650 -newkey rsa:4096 -keyout /etc/ssl/domain/private.pem -out /etc/ssl/domain/public.pem
It will ask several questions, you should be carefull with the common name, usually, input the domain name.

Dynamic Set Jenkins Plugin Start Parameters

Context

Recently, one of our Jenkins job which running inside docker got exception regarding to the durable task plugin.

Bash
20:07:29  process apparently never started in /path/workspace/durable-181c4c30
20:07:29  (running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
20:07:29  Cannot contact Nodexxx: java.io.FileNotFoundException: /path/workspace/durable-181c4c30/output.txt (No such file or directory)

Add Global API Prefix For Rest API in Spring Boot

For a service application, a global API prefix is required.

For example, we want that all the api have a prefix such as api, and we can achieve this by adding the following configuration in application.properties.

Properties
server.servlet.context-path=/api
Now, all rest API will have the prefix api.

Customize 404 Error Response for Rest API in Spring boot

By default, the Spring boot will return a whitelabel error page, but as a rest API server, it's better to return a JSON response to user like a normal API response.

For example, the GitHub rest API will return a JSON and when the resouce is not found.

Bash
curl https://api.github.com/hub
{
    "message": "Not Found",
    "documentation_url": "https://docs.github.com/rest"
}

Customize Typora Theme to Use Full View

By default, the Typora editor doesn't use all the avaliable space of the view.

But we can customize the Typora theme to let editor use 100% the view.

  • Open the theme folder

  • Create base.user.css with content

    CSS
    #write {
        max-width: none;
    }
    
    Now, close and reopen the Typora, you'll see it use all views.