2021年6月

“欲速则不达,见小利则大事不成。”

1、查看curl与时间相关的选项

curl -h |grep time

有用的输出

--connect-timeout <seconds> Maximum time allowed for connection
--expect100-timeout <seconds> How long to wait for 100-continue
--keepalive-time <seconds> Interval time for keepalive probes
-m, --max-time <seconds> Maximum time allowed for the transfer
-y, --speed-time <seconds> Trigger 'speed-limit' abort after this time

2、控制连接超时--connect-timeout 5

curl -v --connect-timeout 1 https://const.net.cn

当出现连接超时时,会提示如下信息

curl: (28) Connection timed out after 1001 milliseconds

3、总超时时间--max-time
 我们希望curl程序在运行一段时间后,不管有没有执行完成都能正常退出。就用这个max-time

curl -v -m 60 https://const.net.cn

4、--speed-time 的用法
speed-time是用来根据速率来控制连接是否断开的。
用法:

curl -o const.log "https://const.net.cn" --speed-time 5 --speed-limit 1

是说将url内容保存到const.log中, 如果传输速度小于1字节/秒的状态持续5秒,该连接就会断开,并退出程序。

1、使用默认的 归档管理器 打开
使用提取到此处功能,如果可以就不用其他办法了。
有时候会不哪么好使,会提示错误。
2、安装rar

sudo apt install rar
sudo apt install unrar

3、解压使用 rar x file.rar
示例:

rar x "孙露《2021最新专辑·再远的远方》.rar"

输出:

RAR 5.50 Copyright (c) 1993-2017 Alexander Roshal 11 Aug 2017
Trial version Type 'rar -?' for help

Extracting from 孙露《2021最新专辑·再远的远方》.rar

Creating 孙露《2021最新专辑·再远的远方》[WAV分轨]
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/01.孙露 - 再远的远方.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/02.孙露 - 迷人月光.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/03.孙露 - 心软.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/04.孙露 - 不忘.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/05.孙露 - 你敢不敢.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/06.孙露 - 好好爱自己.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/07.孙露 - 破晓.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/08.孙露 - 呓语.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/09.孙露 - 眼泪会说谎.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/10.孙露 - 爱的太假.wav
OK Extracting 孙露《2021最新专辑·再远的远方》[WAV分轨]/Cover.jpg
OK

1、curl -w参数

curl -h |grep "write-out"

-w, --write-out <format> Use output FORMAT after completion

2、显示所有时间示例

curl -o /dev/null -s -w "time_namelookup:%{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n"  "https://const.net.cn/"

输出:

time_namelookup:0.058759
time_connect: 0.069912
time_starttransfer: 0.147355
time_total: 0.167685

3、参数说明

time_namelookup: DNS 服务器域名解析的时间(以上时间单位都是s)
time_connect: client 发出请求,到 c/s 建立TCP 的时间;里面包括 DNS 解析的时间
time_starttransfer: client 发出请求;到 server 响应发出第一个字节开始的时间;包括前面的2个时间
time_total: 从请求发起到链接关闭的总耗时

4、官方英文说明

time_appconnect: The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0)
time_connect: The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
time_namelookup: The time, in seconds, it took from the start until the name resolving was completed.
time_pretransfer: The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
time_redirect: The time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3)
time_starttransfer: The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
time_total: The total time, in seconds, that the full operation lasted.

5、格式可以使用字符串,格式化文件以及标准输入

The format can be specified as a literal "string", or you can have curl read the format from a file with "@filename" and to tell curl to read the format from stdin you write "@-".

6、使用格式文件示例

cat curl-format.txt

   time_namelookup:%{time_namelookup}\n
      time_connect:%{time_connect}\n
   time_appconnect:%{time_appconnect}\n
     time_redirect:%{time_redirect}\n    
  time_pretransfer:%{time_pretransfer}\n  
time_starttransfer:%{time_starttransfer}\n
------------------------------\n
        time_total:  %{time_total}\n

使用示例:

curl -o /dev/null -s -w "@curl-format.txt"  "https://const.net.cn/"

输出结果:

   time_namelookup:0.165160
      time_connect:0.240436
   time_appconnect:0.326137
     time_redirect:0.000000
  time_pretransfer:0.326211
time_starttransfer:0.412927
------------------------------
        time_total:  0.486244

1、需要使用到的go-sqlite 的 github地址

https://github.com/mattn/go-sqlite3

2、安装go-sqlite

go get github.com/mattn/go-sqlite3

提示:
Important: because this is a CGO enabled package you are required to set the environment variable CGO_ENABLED=1 and have a gcc compile present within your path.

3、示例代码

package main

import (
    "database/sql"
    "fmt"
    "log"
    "os"

    _ "github.com/mattn/go-sqlite3"
)

func main() {
    os.Remove("./foo.db")

    db, err := sql.Open("sqlite3", "./foo.db")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    sqlStmt := `
    create table foo (id integer not null primary key, name text);
    delete from foo;
    `
    _, err = db.Exec(sqlStmt)
    if err != nil {
        log.Printf("%q: %s\n", err, sqlStmt)
        return
    }

    tx, err := db.Begin()
    if err != nil {
        log.Fatal(err)
    }
    stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
    if err != nil {
        log.Fatal(err)
    }
    defer stmt.Close()
    for i := 0; i < 10; i++ {
        _, err = stmt.Exec(i, fmt.Sprintf("https://const.net.cn %03d", i))
        if err != nil {
            log.Fatal(err)
        }
    }
    tx.Commit()

    rows, err := db.Query("select id, name from foo")
    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()
    for rows.Next() {
        var id int
        var name string
        err = rows.Scan(&id, &name)
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println(id, name)
    }
    err = rows.Err()
    if err != nil {
        log.Fatal(err)
    }

    stmt, err = db.Prepare("select name from foo where id = ?")
    if err != nil {
        log.Fatal(err)
    }
    defer stmt.Close()
    var name string
    err = stmt.QueryRow("3").Scan(&name)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(name)

    _, err = db.Exec("delete from foo")
    if err != nil {
        log.Fatal(err)
    }

    _, err = db.Exec("insert into foo(id, name) values(1, 'const'), (2, 'net'), (3, 'cn')")
    if err != nil {
        log.Fatal(err)
    }

    rows, err = db.Query("select id, name from foo")
    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()
    for rows.Next() {
        var id int
        var name string
        err = rows.Scan(&id, &name)
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println(id, name)
    }
    err = rows.Err()
    if err != nil {
        log.Fatal(err)
    }
}

4、编译运行

CGO_ENABLED=1 GOOS=linux go run .

运行结果:

0 https://const.net.cn 000
1 https://const.net.cn 001
2 https://const.net.cn 002
3 https://const.net.cn 003
4 https://const.net.cn 004
5 https://const.net.cn 005
6 https://const.net.cn 006
7 https://const.net.cn 007
8 https://const.net.cn 008
9 https://const.net.cn 009
https://const.net.cn 003
1 const
2 net
3 cn

5、go sqlite3 arm64/aarch64

env CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++  CGO_ENABLED=1 GOOS=linux GOARCH=arm64 GOARM=7  go build -v 

  • 可信根证书列表管理机构(Trusted Root Certificate List Authority,TRCLA):负责签发可信根证书列表。
  • 可信根证书列表(Trusted Root Certificate List,TRCL):由可信的PKI系统的根证书、可信的PKI系统的可信域CA证书列表下载地址和保护可信根证书列表的安全机制构成。保护可信根证书列表的安全机制为数字签名技术。

本文提供一个 CAICT  中国信息通信研究院 trcla.oer 证书。

trcla.oer Hex 内容

80 03 00 81 02 58 81 0f 76 32 78 2e 63 61 69 63 74 2e 61 63 2e 63 6e 00 00 00 00 00 1f 52 63 65 86 00 1e 83 01 01 80 00 9c 01 02 80 02 0e 2b 80 03 80 00 01 80 02 0e 2c 80 07 00 01 00 01 01 00 00 01 02 e0 81 01 02 01 ff c0 60 80 01 03 00 02 0e 2b 00 02 0e 2c 00 02 0e 2d 01 ff c0 80 84 21 82 e5 81 03 b0 8a b0 75 6f a9 f4 99 f9 eb d9 3d 55 6e 8a 80 b4 8d ff 1d e8 7a f9 8a 71 4e 80 c0 fa 84 40 b9 0d 5a cd 70 c4 0f 1e 93 5d 83 b7 c6 4b 61 9a e1 cf dc ab ef cb 92 57 92 82 05 8f 68 f2 29 c9 c6 b0 5f 6e 03 64 57 93 9f 74 0d ec ae 4a c7 6a 6f 41 2a a0 67 5c 79 73 b2 b9 74 f4 49 6b 0d 39

trcla.oer XML 格式内容

<?xml version="1.0"?>
<Certificate>
    <version>3</version>
    <type>
        <explicit/>
    </type>
    <issuer>
        <self>
            <sm3/>
        </self>
    </issuer>
    <toBeSigned>
        <id>
            <name>v2x.caict.ac.cn</name>
        </id>
        <cracaId>00 00 00</cracaId>
        <crlSeries>0</crlSeries>
        <validityPeriod>
            <start>525493093</start>
            <duration>
                <years>30</years>
            </duration>
        </validityPeriod>
        <region>
            <identifiedRegion>
                <countryOnly>156</countryOnly>
            </identifiedRegion>
        </region>
        <appPermissions>
            <AidSsp>
                <aid>3627</aid>
                <ssp>
                    <opaque>80 00 01</opaque>
                </ssp>
            </AidSsp>
            <AidSsp>
                <aid>3628</aid>
                <ssp>
                    <opaque>00 01 00 01 01 00 00</opaque>
                </ssp>
            </AidSsp>
        </appPermissions>
        <certIssuePermissions>
            <AidGroupPermissions>
                <subjectPermissions>
                    <all/>
                </subjectPermissions>
                <minChainLength>2</minChainLength>
                <chainLengthRange>-1</chainLengthRange>
                <eeType>
                    11000000
                </eeType>
            </AidGroupPermissions>
            <AidGroupPermissions>
                <subjectPermissions>
                    <explicit>
                        <AidSspRange>
                            <aid>3627</aid>
                        </AidSspRange>
                        <AidSspRange>
                            <aid>3628</aid>
                        </AidSspRange>
                        <AidSspRange>
                            <aid>3629</aid>
                        </AidSspRange>
                    </explicit>
                </subjectPermissions>
                <minChainLength>1</minChainLength>
                <chainLengthRange>-1</chainLengthRange>
                <eeType>
                    11000000
                </eeType>
            </AidGroupPermissions>
        </certIssuePermissions>
        <verifyKeyIndicator>
            <verificationKey>
                <ecsigSm2>
                    <compressed-y-0>
                        E5 81 03 B0 8A B0 75 6F A9 F4 99 F9 EB D9 3D 55 
                        6E 8A 80 B4 8D FF 1D E8 7A F9 8A 71 4E 80 C0 FA
                    </compressed-y-0>
                </ecsigSm2>
            </verificationKey>
        </verifyKeyIndicator>
    </toBeSigned>
    <signature>
        <sm2Signature>
            <rSig>
                B9 0D 5A CD 70 C4 0F 1E 93 5D 83 B7 C6 4B 61 9A 
                E1 CF DC AB EF CB 92 57 92 82 05 8F 68 F2 29 C9
            </rSig>
            <sSig>
                C6 B0 5F 6E 03 64 57 93 9F 74 0D EC AE 4A C7 6A 
                6F 41 2A A0 67 5C 79 73 B2 B9 74 F4 49 6B 0D 39
            </sSig>
        </sm2Signature>
    </signature>
</Certificate>

trcla.oer 公钥

04 e5 81 03 b0 8a b0 75 6f a9 f4 99 f9 eb d9 3d 55 6e 8a 80 b4 8d ff 1d e8 7a f9 8a 71 4e 80 c0 fa 6d 06 45 66 83 74 ba eb 82 ba 79 1c 90 24 ee 1d c8 9a 46 10 eb 18 28 cc e6 09 33 40 f3 33 42 1e

trcla.oer SM3 hashid32

f8 7a 5e 87 67 2a 67 c7 e3 33 64 40 af f5 64 32 0c 99 47 25 e7 fa be be 0b 2c 85 a0 f3 b2 62 2c

trcla.oer Start Time

2020-08-26 10:18:13

trcla.oer End Time

2050-08-26 08:54:13

trcla.oer SM2 Signature

b9 0d 5a cd 70 c4 0f 1e 93 5d 83 b7 c6 4b 61 9a e1 cf dc ab ef cb 92 57 92 82 05 8f 68 f2 29 c9 c6 b0 5f 6e 03 64 57 93 9f 74 0d ec ae 4a c7 6a 6f 41 2a a0 67 5c 79 73 b2 b9 74 f4 49 6b 0d 39

trcla.oer 验签
trcla.oer是自签名根证书,要验证签名,当签发的证书为自签名证书时,IDA为16进制整数

31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38

trcla.oer tbsData

58 81 0f 76 32 78 2e 63 61 69 63 74 2e 61 63 2e 63 6e 00 00 00 00 00 1f 52 63 65 86 00 1e 83 01 01 80 00 9c 01 02 80 02 0e 2b 80 03 80 00 01 80 02 0e 2c 80 07 00 01 00 01 01 00 00 01 02 e0 81 01 02 01 ff c0 60 80 01 03 00 02 0e 2b 00 02 0e 2c 00 02 0e 2d 01 ff c0 80 84 21 82 e5 81 03 b0 8a b0 75 6f a9 f4 99 f9 eb d9 3d 55 6e 8a 80 b4 8d ff 1d e8 7a f9 8a 71 4e 80 c0 fa