M-plane file transfer 实现 FTPES 的
实现要求
首先,可以确认,使用 FTPES 的 file transfer 功能在 ORAN M-Plane v8.0 中是一定需要的。

上图中还规定了 TLS 1.2 是必须支持的。
协议中还给出了几个 RFC 的链接:
- RFC 4210: "Internet X.509 Public Key Infrastructure Certificate Management Protocol".
- RFC 4217: "Securing FTP with TLS”, IETF, October 2005
- Transport Layer Security (TLS) Parameters. https://www.iana.org/assignments/tls-parameters/tlsparameters.xhtml, Internet Assigned Numbers Authority, (IANA), January 27, 2021
- RFC 5246, "The Transport Layer Security (TLS) Protocol Version 1.2", IETF, August 2008
- RFC 5289, "TLS Elliptic Curve Cipher Suites with SHA-256/384 and AES Galois Counter Mode (GCM)”, IETF, August 2008.
- RFC 5288, "AES Galois Counter Mode (GCM) Cipher Suites for TLS", August 2008.
- RFC 6125, "Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) Certificates in the Context of Transport Layer Security (TLS)", IETF, March 2011
- RFC 7589, "Using the NETCONF Protocol over Transport Layer Security (TLS) with Mutual X.509 Authentication", IETF, June 2015
下图介绍了一些实现 TLS 1.2 认证中的一些要求。

文档看下来,能明确的是 file transfer 必须要支持 FTPES,而 FTPES 是否必须要支持 mutual authentication 并没有明确说。 但既然 FTPES 要用到 TLS,且文档明确要求 TLS 1.2 需要支持,而 TLS 1.2 目前看来又是 mutual authentication 的,所以 FTPES 应该也是要支持 mutual authentication 的。
TLS 的基本知识
在 client/server 之间的连接中,数字证书的主要用途是 server 向 client 证明自己的身份。
server 的证书中,包含数字签名,它是认证 server 身份的关键信息。
server 的证书中,包含自己的 public key,它用于 client 与 server 之间传输信息时的加密。
现在使用的证书一般都遵循 X.509 标准,一个 X.509 证书一般包含以下信息:
- Information about the subject a.k.a. Subject Name- "subject" refers to the site represented by the cert.
- Information about the certificate issuer/certificate authority (CA)- The CA is the body that issued and signed the certificate.
- Serial number- this is the serial number assigned by the issuer to this certificate. Each issuer must make sure each certificate it issues has a unique serial number.
- Version - the X.509 version used by a given certificate. These days, you'll usually find version 3.
- Validity period- certs aren't meant to last forever. The validity period defines the period over which the cert can still be deemed trustworthy.
- Signature - This is the digital signature of the entire digital certificate, generated using the certificate issuer's private key
- Signature algorithm - The cryptographic signature algorithm used to generate the digital signature (e.g. SHA-1 with RSA Encryption)
-
Public key information - Information about the subject's public key. This includes:
- the algorithm (e.g. Elliptic Curve Public Key),
- the key size (e.g. 256 bits),
- the key usage (e.g. can encrypt, verify, derive), and
- the public key itself
Certification Authority 作为一个可信第三方,负责为其他 entity 签发证书。
Server 通过向 CA 发送 CSR(certificate signing request) 来申请证书的签发。 CSR 中包含 server 自身的一些信息,CA 通过这些信息来判断它值得信任,然后 CA 为其签发证书。
当我们用浏览器通过 HTTPS 访问网站前,我们的浏览器内部首先就有一组 certificate,它又叫 CA certificates,它包含可能用于签发 server certificate 的 CA 的 public key。 CA 用自己的 private key 为 server 签发证书,而浏览器用本地的 CA certificate 中的 public key 来验证证书是否由这些 CA 签发。
支持 FTP 的开源库
目前找到的支持 FTPES 的比较出名的开源库为 libcurl。
根据 链接,安装 curl,以及 libcurl4-openssl-dev。
openssl 学习
openssl 参考书籍
openssl version
查看 openssl 版本
openssl version -a
详细的 openssl 信息,包括 OPENSSLDIR,it is where OpenSSL looks for its default configuration and root certificates。
去 OPENSSLDIR 指定的路径,可以看到 private 路径,此路径用于保存 private keys。
还可以看到 cert 路径,此路径保存 CA certficates。
此路径也是 trusted store,即保存受信任的 root certificate。这里的 certificate 只包含 public key,用于 verify 证书。
此外还有一个 key store,它包含 private key/public key,用于生成证书。
简单地说,trusted store 用于保存别人的证书,key store 用于保存你自己的证书。
openssl help
查看 openssl 支持的命令
此输出有3个部分,第1部分是 Standard commands,你可以用 man 命令来查看他们的详细信息。
比如 ciphers,可以输入 man openssl-ciphers
第2部分是 digest command,第3部分是 cipher command。这些先不管。
为自己的 server 生成 certificate 主要需要 3 步:
- generate a private key
- create a Certificate Signing Request (CSR) and send it to a CA
- install the CA-provided certificate in your server
第一步
其中,步骤1首先需要你选择加密算法,密钥长度,是否给密钥添加 passphrase。
这里主要用 genpkey 命令。
使用例子:
$ openssl genpkey -out fd.key \
-algorithm RSA \
-pkeyopt rsa_keygen_bits:2048 \
-aes-128-cbc
..........................................+++++
...................................................................+++++
Enter PEM pass phrase: ************
Verifying - Enter PEM pass phrase: ************
这里使用 aes-128 来保护 key,你也可以换成 aes-256,把上面的选项换为 aes-256-cbc
即可。
生成的 fd.key,如果你直接看其内容,是基本无意义的,可用以下命令查看该文件的structure。
openssl pkey -in fd.key -text -noout
也可用以下命令单独看 public key:
$ openssl pkey -in fd.key -pubout -out fd-public.key
Enter pass phrase for fd.key: ****************
第二步
接下来,发送 CSR 到 CA,让它为你签发一个证书。
发送 CSR 是一个交互的过程,这个过程中你应该仔细阅读一下 openssl 给你的提示。
这里需要注意的是,如果有些项目你想填为空,你应该输入小数点 .
,而不是直接按回车。直接按回车的话,值不会为空,而是默认值。
$ openssl req -new -key fd.key -out fd.csr
Enter pass phrase for fd.key: ****************
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:London
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Feisty Duck Ltd
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:www.feistyduck.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
challange password 可以放着不管。它用于 CA 辨认 entity 的身份。它并不会增强 CSR 的安全性。其详细信息可见 RFC 2985 Section 5.4.1。
生成 CSR 之后,可以通过以下命令检查它的内容:
$ openssl req -text -in fd.csr -noout
通过编写 .cnf
文件,在其中添加我们需要的配置,也可以让生成 CSR 的过程不需要任何交互。
如果你的 TLS server 只是给自己用的,那么你也许并不需要依靠 CA 来给出一个 public trusted certificate,你可以自签发。比如以下命令可通过 csr 文件生成证书:
$ openssl x509 -req -days 365 -in fd.csr -signkey fd.key -out fd.crt
Signature ok
subject=C = GB, L = London, O = Feisty Duck Ltd, CN = www.feistyduck.com
Getting Private key
Enter pass phrase for fd.key: ****************
可以通过以下命令将 crt 格式的证书转换成 pem 格式:
openssl x509 -in mycert.crt -out mycert.pem -outform PEM
以下命令可通过 key 直接生成证书:
$ openssl req -new -x509 -days 365 -key fd.key -out fd.crt
如果你不想交互式地输入 subject 信息,也可以直接在命令行中指定:
$ openssl req -new -x509 -days 365 -key fd.key -out fd.crt \
-subj "/C=GB/L=London/O=Feisty Duck Ltd/CN=www.feistyduck.com"
可以通过以下命令来检查证书内容。 其中 -text
用于打印证书内容,-noout
用于不打印编码后的内容。
$ openssl x509 -text -in fd.crt -noout
openssl 默认配置
当 openssl 启动时,它会执行以下步骤:
- 检查
OPENSSL_CONF
环境变量,它指示配置文件所在路径。 如果编译 binary 文件时加上了setuid
或setguid
选项,则这步会被跳过。 - 若上一步失败,则会检查在 compile time 指定的 default system-wide configuration directory,寻找名为
openssl.cnf
的文件。
我们可以通过以下命令查看默认配置文件路径:
$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"
找到配置文件后,可以改其中的内容。以下是一个例子:
[default_conf]
ssl_conf = ssl_section
[ssl_section]
system_default = system_default_section
[system_default_section]
MinProtocol = TLSv1.2
CipherString = DEFAULT:@SECLEVEL=2
Ciphersuites = TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256
Options = ServerPreference,PrioritizeChaCha
更多有关配置的信息,推荐查看 openssl 官方文档。
此 链接 为 Mozilla CA certificate store,我们可以将其下载下来,作为 cacert.pem 保存。我们可以通过它为我们校验一个证书,如下面的命令:
$ openssl verify -verbose -CAfile cacert.pem server.crt
server.crt: OK
如果返回的结果不是 OK,则说明此证书不是由以上的 CA 签名的。
FTPS server -- vsftpd
ubuntu doc about FTP server
vsftpd 配置文档
参考链接之配置 vsftpd 验证 client certificate
在 ubuntu 中,可以用 vsftpd 作为 FTP server。
sudo apt install vsftpd
vsftpd 的配置文件在 /etc/vsftpd.conf
其 log 文件默认在 /var/log/vsftpd.log
,但可以在配置文件中修改。
在修改 vsftpd 的配置后,可用以下命令重启 vsftpd 使其生效
service vsftpd restart
vsftpd 匿名 user 的 home 路径在 /srv/ftp
使用以下命令生成自签名证书,并修改配置文件中的参数,使用此证书
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
添加 self-signed certificate 到 trusted store
参考链接
在 Debian 系统中,可以执行以下步骤:
- Install the ca-certificates package
apt-get install ca-certificates
- You then copy the public half of your untrusted CA certificate (the one you use to sign your CSR) into the CA certificate directory (as root):
cp cacert.crt /usr/share/ca-certificates
NOTE: Certificate needs to have .crt extension for it to be picked up.
And get it to rebuild the directory with your certificate included, run as root:
dpkg-reconfigure ca-certificates
and select the ask option, scroll to your certificate, mark it for inclusion and select ok.
curl 访问 ftp server
参考链接之 curl 常用命令
参考链接之 curl 中的 FTPS 相关选项
上传文件时需要的 ftp server 配置
使用以下命令访问 ftp server
curl -v --cacert vsftpd.pem --user username:passwd --ssl-reqd ftp://hostname
curl -v --cacert vsftpd.pem -T uploadfile.txt --ssl-reqd ftp://hostname/upload/myfile
curl -v -k -E client-crt.pem --ftp-ssl-reqd ftp://server:21/testfile
与 TLS 相关的 curl_easy_setopt 函数的 option:
CURLOPT_SSL_VERIFYPEER
CURLOPT_CAINFO
-
CURLOPT_SSLKEY
andCURLOPT_SSLCERT
用于配置 client certificate
上传文件
当 client 以 anonymous 访问的时候,在 server 端使用的用户并不是 anonymous,而是 ftp。
想要让 client 以 anonymous 成功上传文件,必须合理配置 server 端的权限。
vsftpd server 默认的 ftp 根目录在 /srv/ftp
,我们需要确保此目录的所有者和群组为 root。配置此路径的权限为 555。
在 ftp 根目录下创建一个 download 路径,用于下载文件。所有者和群组为 ftp,权限为555。
在 ftp 根目录下创建一个 upload 路径,用于上传文件。所有者和群组为 ftp,权限为755。
vsftpd server 的版本为 3.0.5,其配置文件内容如下:
listen=NO
listen_ipv6=YES
anonymous_enable=YES
local_enable=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_root=/srv/ftp
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=YES
require_ssl_reuse=NO
allow_writeable_chroot=YES