OpenSSL で”error while loading serial number”が出た

OpenSSLで証明書作るときに、Serial NumberのLoad Errorが出る。

[root@srv SuiteBCA]# openssl ca -in vsrx1.csr -out certs/vsrx1.pem -keyfile ec_key.pem -cert cacert.pem -md SHA384 -extfile subalt.txtUsing configuration from /etc/pki/tls/openssl.cnfunable to load number from ./serialerror while loading serial number139852154750864:error:0D066091:asn1 encoding routines:a2i_ASN1_INTEGER:odd number of chars:f_int.c:163:[root@srv SuiteBCA]#

ファイルはあるし読めるのに...

[root@srv SuiteBCA]# cat serial
101
[root@srv SuiteBCA]# ls -l
total 28
-rw-r--r-- 1 root root  916 Nov 27 19:50 cacert.pem
drwxr-xr-x 2 root root 4096 Nov 27 20:45 certs
-rw-r--r-- 1 root root  359 Nov 27 19:48 ec_key.pem
-rw-r--r-- 1 root root    0 Nov 27 19:51 index.txt
drwxr-xr-x 2 root root 4096 Nov 27 19:41 newcerts
-rw-r--r-- 1 root root    4 Nov 27 19:51 serial
-rw-r--r-- 1 root root   40 Nov 27 20:45 subalt.txt
-rw-r--r-- 1 root root  651 Nov 27 20:41 vsrx1.csr

 

数を増やしたりしても駄目。

正解は「改行コード」を入れたら、Generateできた。

[root@srv SuiteBCA]# openssl ca -in vsrx1.csr -out certs/vsrx1.pem -keyfile ec_key.pem -cert cacert.pem -md SHA384 -extfile subalt.txt
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 4096 (0x1000)
Validity
Not Before: Nov 28 02:12:41 2019 GMT
Not After : Nov 27 02:12:41 2020 GMT
Subject:
countryName = JP
stateOrProvinceName = Tokyo
organizationName = UnyaUnya
commonName = vpn
X509v3 extensions:
X509v3 Subject Alternative Name:
email:unyaunya@example.com
Certificate is to be certified until Nov 27 02:12:41 2020 GMT (365 days)
Sign the certificate? [y/n]:y

 

---2020/3/30 追記---

より正確に書くと ANSI である必要があるので、

viで書かずに、echoでファイルを作成する。

echo 1001 > serial