0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rocky Linux 9でSSL/TLS証明書をOSのトラストストアに追加する

Posted at

What's?

以下の記事でRocky Linux 9にApacheとmod_sslをインストールしました。

インストール時に自己署名証明書が生成されるのですが、これをOSのトラストストアに追加する方法を知っておきたいなということで調べてみました。

RHEL系のトラストストア

このテーマで見た方がよいドキュメントはRed Hat Enterprise Linuxのものですね。

ほぼ答えが書いてあります。

統合されたシステム全体のトラストストアは以下のディレクトリにあり、優先順位は/etc/pki/ca-trustの方が高いです。

  • /etc/pki/ca-trust
  • /usr/share/pki/ca-trust-source

ここに追加するには、証明書をどちらかのディレクトリにコピーしてupdate-ca-trustコマンドを使う、もしくはtrust anchorコマンドを使うようです。

新しい証明書をトラストストアに追加するには、証明書を含むファイルを対応するディレクトリーにコピーし、update-ca-trust コマンドを使用して変更を適用します。または、trust anchor サブコマンドを使用することもできます。

その手順が書かれているのがこちらです。

PEMまたはDER形式の証明書を以下のディレクトリーのどちらかにコピーして、update-ca-trust extractコマンドを実行するようです。
※今回は見ませんが、ブラックリストも追加できます

  • /usr/share/pki/ca-trust-source/anchors
  • /etc/pki/ca-trust/source/anchors

extractの意味もわからないので、manページを見てみましょう。

$ man update-ca-trust
UPDATE-CA-TRUST(8)                                                                                                                                          UPDATE-CA-TRUST(8)

NAME
       update-ca-trust - manage consolidated and dynamic configuration of CA certificates and associated trust

SYNOPSIS
       update-ca-trust [extract] [-o DIR|--output=DIR]

DESCRIPTION
       update-ca-trust(8) is used to manage a consolidated and dynamic configuration feature of Certificate Authority (CA) certificates and associated trust.

       The feature is available for new applications that read the consolidated configuration files found in the /etc/pki/ca-trust/extracted directory or that load the
       PKCS#11 module p11-kit-trust.so

       Parts of the new feature are also provided in a way to make it useful for legacy applications.

       Many legacy applications expect CA certificates and trust configuration in a fixed location, contained in files with particular path and name, or by referring to a
       classic PKCS#11 trust module provided by the NSS cryptographic library.

       The dynamic configuration feature provides functionally compatible replacements for classic configuration files and for the classic NSS trust module named libnssckbi.

       In order to enable legacy applications, that read the classic files or access the classic module, to make use of the new consolidated and dynamic configuration
       feature, the classic filenames have been changed to symbolic links. The symbolic links refer to dynamically created and consolidated output stored below the
       /etc/pki/ca-trust/extracted directory hierarchy.

       The output is produced using the update-ca-trust command (without parameters), or using the update-ca-trust extract command. In order to produce the output, a flexible
       set of source configuration is read, as described in section SOURCE CONFIGURATION.

       In addition, the classic PKCS#11 module is replaced with a new PKCS#11 module (p11-kit-trust.so) that dynamically reads the same source configuration.

SOURCE CONFIGURATION
       The dynamic configuration feature uses several source directories that will be scanned for any number of source files. It is important to select the correct
       subdirectory for adding files, as the subdirectory defines how contained certificates will be trusted or distrusted, and which file formats are read.

       Files in subdirectories below the directory hierarchy /usr/share/pki/ca-trust-source/ contain CA certificates and trust settings in the PEM file format. The trust
       settings found here will be interpreted with a low priority.

       Files in subdirectories below the directory hierarchy /etc/pki/ca-trust/source/ contain CA certificates and trust settings in the PEM file format. The trust settings
       found here will be interpreted with a high priority.

       You may use the following rules of thumb to decide, whether your configuration files should be added to the /etc or rather to the /usr directory hierarchy:

       •   If you are manually adding a configuration file to a system, you probably want it to override any other default configuration, and you most likely should add it to
           the respective subdirectory in the /etc hierarchy.

       •   If you are creating a package that provides additional root CA certificates, that is intended for distribution to several computer systems, but you still want to
           allow the administrator to override your list, then your package should add your files to the respective subdirectory in the /usr hierarchy.

       •   If you are creating a package that is supposed to override the default system trust settings, that is intended for distribution to several computer systems, then
           your package should install the files to the respective subdirectory in the /etc hierarchy.

       QUICK HELP 1: To add a certificate in the simple PEM or DER file formats to the list of CAs trusted on the system:

       •   add it as a new file to directory /etc/pki/ca-trust/source/anchors/

       •   run update-ca-trust extract

       QUICK HELP 2: If your certificate is in the extended BEGIN TRUSTED file format (which may contain distrust/blocklist trust flags, or trust flags for usages other than
       TLS) then:

       •   add it as a new file to directory /etc/pki/ca-trust/source/

       •   run update-ca-trust extract

       In order to offer simplicity and flexibility, the way certificate files are treated depends on the subdirectory they are installed to.

       •   simple trust anchors subdirectory: /usr/share/pki/ca-trust-source/anchors/ or /etc/pki/ca-trust/source/anchors/

       •   simple blocklist (distrust) subdirectory: /usr/share/pki/ca-trust-source/blocklist/ or /etc/pki/ca-trust/source/blocklist/

       •   extended format directory: /usr/share/pki/ca-trust-source/ or /etc/pki/ca-trust/source/

       In the main directories /usr/share/pki/ca-trust-source/ or /etc/pki/ca-trust/source/ you may install one or multiple files in the following file formats:

       •   certificate files that include trust flags, in the BEGIN/END TRUSTED CERTIFICATE file format (any file name), which have been created using the openssl x509 tool
           and the -addreject -addtrust options. Bundle files with multiple certificates are supported.

       •   files in the p11-kit file format using the .p11-kit file name extension, which can (e.g.) be used to distrust certificates based on serial number and issuer name,
           without having the full certificate available. (This is currently an undocumented format, to be extended later. For examples of the supported formats, see the
           files shipped with the ca-certificates package.)

       •   certificate files without trust flags in either the DER file format or in the PEM (BEGIN/END CERTIFICATE) file format (any file name). Such files will be added
           with neutral trust, neither trusted nor distrusted. They will simply be known to the system, which might be helpful to assist cryptographic software in
           constructing chains of certificates. (If you want a CA certificate in these file formats to be trusted, you should remove it from this directory and move it to the
           ./anchors subdirectory instead.)

       In the anchors subdirectories /usr/share/pki/ca-trust-source/anchors/ or /etc/pki/ca-trust/source/anchors/ you may install one or multiple certificates in either the
       DER file format or in the PEM (BEGIN/END CERTIFICATE) file format. Each certificate will be treated as trusted for all purposes.

       In the blocklist subdirectories /usr/share/pki/ca-trust-source/blocklist/ or /etc/pki/ca-trust/source/blocklist/ you may install one or multiple certificates in either
       the DER file format or in the PEM (BEGIN/END CERTIFICATE) file format. Each certificate will be treated as distrusted for all purposes.

       Please refer to the x509(1) manual page for the documentation of the BEGIN/END CERTIFICATE and BEGIN/END TRUSTED CERTIFICATE file formats.

       Applications that rely on a static file for a list of trusted CAs may load one of the files found in the /etc/pki/ca-trust/extracted directory. After modifying any
       file in the /usr/share/pki/ca-trust-source/ or /etc/pki/ca-trust/source/ directories or in any of their subdirectories, or after adding a file, it is necessary to run
       the update-ca-trust extract command, in order to update the consolidated files in /etc/pki/ca-trust/extracted/ .

       Applications that load the classic PKCS#11 module using filename libnssckbi.so (which has been converted into a symbolic link pointing to the new module) and any
       application capable of loading PKCS#11 modules and loading p11-kit-trust.so, will benefit from the dynamically merged set of certificates and trust information stored
       in the /usr/share/pki/ca-trust-source/ and /etc/pki/ca-trust/source/ directories.

EXTRACTED CONFIGURATION
       The directory /etc/pki/ca-trust/extracted/ contains generated CA certificate bundle files which are created and updated, based on the SOURCE CONFIGURATION by running
       the update-ca-trust extract command.

       If your application isn’t able to load the PKCS#11 module p11-kit-trust.so, then you can use these files in your application to load a list of global root CA
       certificates.

       Please never manually edit the files stored in this directory, because your changes will be lost and the files automatically overwritten, each time the update-ca-trust
       extract command gets executed.

       In order to install new trusted or distrusted certificates, please rather install them in the respective subdirectory below the /usr/share/pki/ca-trust-source/ or
       /etc/pki/ca-trust/source/ directories, as described in the SOURCE CONFIGURATION section.

       The directory /etc/pki/ca-trust/extracted/java/ contains a CA certificate bundle in the java keystore file format. Distrust information cannot be represented in this
       file format, and distrusted certificates are missing from these files. File cacerts contains CA certificates trusted for TLS server authentication.

       The directory /etc/pki/ca-trust/extracted/openssl/ contains CA certificate bundle files in the extended BEGIN/END TRUSTED CERTIFICATE file format, as described in the
       x509(1) manual page. File ca-bundle.trust.crt contains the full set of all trusted or distrusted certificates, including the associated trust flags.

       The directory /etc/pki/ca-trust/extracted/pem/ contains CA certificate bundle files in the simple BEGIN/END CERTIFICATE file format, as described in the x509(1) manual
       page. Distrust information cannot be represented in this file format, and distrusted certificates are missing from these files. File tls-ca-bundle.pem contains CA
       certificates trusted for TLS server authentication. File email-ca-bundle.pem contains CA certificates trusted for E-Mail protection. File objsign-ca-bundle.pem
       contains CA certificates trusted for code signing.

       The directory /etc/pki/ca-trust/extracted/edk2/ contains a CA certificate bundle ("cacerts.bin") in the "sequence of EFI_SIGNATURE_LISTs" format, defined in the
       UEFI-2.7 specification, sections "31.4.1 Signature Database" and "EFI_CERT_X509_GUID". Distrust information cannot be represented in this file format, and distrusted
       certificates are missing from these files. File "cacerts.bin" contains CA certificates trusted for TLS server authentication.

COMMANDS
   (absent/empty command)
       Same as the extract command described below. (However, the command may print fewer warnings, as this command is being run during rpm package installation, where
       non-fatal status output is undesired.)

   extract
       Instruct update-ca-trust to scan the SOURCE CONFIGURATION and produce updated versions of the consolidated configuration files stored below the
       /etc/pki/ca-trust/extracted directory hierarchy.

       EXTRACT OPTIONS
           -o DIR, --output=DIR
               Write the extracted trust store into the given directory instead of updating /etc/pki/ca-trust/extracted.

FILES
       /etc/pki/tls/certs/ca-bundle.crt
           Classic filename, file contains a list of CA certificates trusted for TLS server authentication usage, in the simple BEGIN/END CERTIFICATE file format, without
           distrust information. This file is a symbolic link that refers to the consolidated output created by the update-ca-trust command.

       /etc/pki/tls/certs/ca-bundle.trust.crt
           Classic filename, file contains a list of CA certificates in the extended BEGIN/END TRUSTED CERTIFICATE file format, which includes trust (and/or distrust) flags
           specific to certificate usage. This file is a symbolic link that refers to the consolidated output created by the update-ca-trust command.

       /etc/pki/java/cacerts
           Classic filename, file contains a list of CA certificates trusted for TLS server authentication usage, in the Java keystore file format, without distrust
           information. This file is a symbolic link that refers to the consolidated output created by the update-ca-trust command.

       /usr/share/pki/ca-trust-source
           Contains multiple, low priority source configuration files as explained in section SOURCE CONFIGURATION. Please pay attention to the specific meanings of the
           respective subdirectories.

       /etc/pki/ca-trust/source
           Contains multiple, high priority source configuration files as explained in section SOURCE CONFIGURATION. Please pay attention to the specific meanings of the
           respective subdirectories.

       /etc/pki/ca-trust/extracted
           Contains consolidated and automatically generated configuration files for consumption by applications, which are created using the update-ca-trust extract command.
           Don’t edit files in this directory, because they will be overwritten. See section EXTRACTED CONFIGURATION for additional details.

AUTHOR
       Written by Kai Engert and Stef Walter.

update-ca-trust                                                                   10/10/2025                                                                UPDATE-CA-TRUST(8)

update-ca-trustコマンドは認証局および証明書の構成を管理するコマンドです。

extractコマンドは指定してもしなくてもよいみたいですね。

The output is produced using the update-ca-trust command (without parameters), or using the update-ca-trust extract command. In order to produce the output, a flexible

このコマンドで、/etc/pki/ca-trust/extractedディレクトリ配下に統合された証明書を出力します。

The symbolic links refer to dynamically created and consolidated output stored below the
/etc/pki/ca-trust/extracted directory hierarchy.

/usr/share/pki/ca-trust-source/anchors/etc/pki/ca-trust/source/anchorsディレクトリの使い分けについても書かれています。

You may use the following rules of thumb to decide, whether your configuration files should be added to the /etc or rather to the /usr directory hierarchy:

手動でファイルを追加する、もしくはデフォルトのファイルを上書きしたい場合は/etcの方を使います。

If you are manually adding a configuration file to a system, you probably want it to override any other default configuration, and you most likely should add it to
the respective subdirectory in the /etc hierarchy.

If you are creating a package that is supposed to override the default system trust settings, that is intended for distribution to several computer systems, then
your package should install the files to the respective subdirectory in the /etc hierarchy.

複数のコンピュータに上書き可能な証明書を配布するパッケージ等を作成する場合は/usrを使います。

If you are creating a package that provides additional root CA certificates, that is intended for distribution to several computer systems, but you still want to
allow the administrator to override your list, then your package should add your files to the respective subdirectory in the /usr hierarchy.

アプリケーションなどが実際に使うのは、/etc/pki/ca-trust/extractedディレクトリ配下のファイルになるようです。

Applications that rely on a static file for a list of trusted CAs may load one of the files found in the /etc/pki/ca-trust/extracted directory.

そして/usr/share/pki/ca-trust-sourceまたは/etc/pki/ca-trust/sourceディレクトリ内を更新した後に、その変更を/etc/pki/ca-trust/extractedディレクトリに反映するのがupdate-ca-trust extractコマンドです。

file in the /usr/share/pki/ca-trust-source/ or /etc/pki/ca-trust/source/ directories or in any of their subdirectories, or after adding a file, it is necessary to run
the update-ca-trust extract command, in order to update the consolidated files in /etc/pki/ca-trust/extracted/ .

コマンドについてはextract以外は知らなくてもよさそうです。

あとはtrust anchorコマンドですね。

manページを見てみましょう。トラストストアを操作するツールのようです。

$ man trust
TRUST(1)                                                                         User Commands                                                                        TRUST(1)

NAME
       trust - Tool for operating on the trust policy store

SYNOPSIS
       trust list

       trust extract --filter=<what> --format=<type> /path/to/destination

       trust anchor /path/to/certificate.crt

       trust dump

       trust check-format /path/to/file.p11-kit...

DESCRIPTION
       trust is a command line tool to examine and modify the shared trust policy store.

       See the various sub commands below. The following global options can be used:

       -v, --verbose
           Run in verbose mode with debug output.

       -q, --quiet
           Run in quiet mode without warning or failure messages.

LIST
       List trust policy store items.

           $ trust list

       List information about the various items in the trust policy store. Each item is listed with it's PKCS#11 URI and some descriptive information.

       You can specify the following options to control what to list.

       --filter=<what>
           Specifies what certificates to extract. You can specify the following values:

           ca-anchors
               Certificate anchors

           trust-policy
               Anchors and blocklist (default)

           blocklist
               Distrusted certificates

           certificates
               All certificates

           pkcs11:object=xx
               A PKCS#11 URI to filter with

           If an output format is chosen that cannot support type what has been specified by the filter, a message will be printed.

           None of the available formats support storage of blocklist entries that do not contain a full certificate. Thus any certificates distrusted by their issuer and
           serial number alone, are not included in the extracted blocklist.

       --purpose=<usage>
           Limit to certificates usable for the given purpose You can specify one of the following values:

           server-auth
               For authenticating servers

           client-auth
               For authenticating clients

           email
               For email protection

           code-signing
               For authenticated signed code

           1.2.3.4.5...
               An arbitrary purpose OID

ANCHOR
       Store or remove trust anchors.

           $ trust anchor /path/to/certificate.crt
           $ trust anchor --remove /path/to/certificate.crt
           $ trust anchor --remove "pkcs11:id=%AA%BB%CC%DD%EE;type=cert"

       Store or remove trust anchors in the trust policy store. These are usually root certificate authorities.

       Specify either the --store or --remove operations. If no operation is specified then --store is assumed.

       When storing, one or more certificate files are expected on the command line. These are stored as anchors, unless they are already present.

       When removing an anchor, either specify certificate files or PKCS#11 URI's on the command line. Matching anchors will be removed.

       It may be that this command needs to be run as root in order to modify the system trust policy store, if no user specific store is available.

       You can specify the following options.

       --remove
           Remove one or more anchors from the trust policy store. Specify certificate files or PKCS#11 URI's on the command line.

       --store
           Store one or more anchors to the trust policy store. Specify certificate files on the command line.

EXTRACT
       Extract trust policy from the shared trust policy store.

           $ trust extract --format=x509-directory --filter=ca-anchors /path/to/directory

       You can specify the following options to control what to extract. The --filter and --format arguments should be specified. By default this command will not overwrite
       the destination file or directory.

       --comment
           Add identifying comments to PEM bundle output files before each certificate.

       --filter=<what>
           Specifies what certificates to extract. You can specify the following values:

           ca-anchors
               Certificate anchors (default)

           trust-policy
               Anchors and blocklist

           blocklist
               Distrusted certificates

           certificates
               All certificates

           pkcs11:object=xx
               A PKCS#11 URI

           If an output format is chosen that cannot support type what has been specified by the filter, a message will be printed.

           None of the available formats support storage of blocklist entries that do not contain a full certificate. Thus any certificates distrusted by their issuer and
           serial number alone, are not included in the extracted blocklist.

       --format=<type>
           The format of the destination file or directory. You can specify one of the following values:

           x509-file
               DER X.509 certificate file

           x509-directory
               directory of X.509 certificates

           pem-bundle
               File containing one or more certificate PEM blocks

           pem-directory
               Directory of PEM files each containing one certificate

           pem-directory-hash
               Directory of PEM files each containing one certificate, with hash symlinks

           openssl-bundle
               OpenSSL specific PEM bundle of certificates

           openssl-directory
               Directory of OpenSSL specific PEM files

           java-cacerts
               Java keystore 'cacerts' certificate bundle

       --overwrite
           Overwrite output file or directory.

       --purpose=<usage>
           Limit to certificates usable for the given purpose You can specify one of the following values:

           server-auth
               For authenticating servers

           client-auth
               For authenticating clients

           email
               For email protection

           code-signing
               For authenticated signed code

           1.2.3.4.5...
               An arbitrary purpose OID

EXTRACT COMPAT
       Extract compatibility trust certificate bundles.

           $ trust extract-compat

       OpenSSL, Java and some versions of GnuTLS cannot currently read trust information directly from the trust policy store. This command extracts trust information such as
       certificate anchors for use by these libraries.

       What this command does, and where it extracts the files is distribution or site specific. Packagers or administrators are expected customize this command.

DUMP
       Dump PKCS#11 items in the various tokens.

           $ trust dump

       Dump information about the various PKCS#11 items in the tokens. Each item is dumped with it's PKCS#11 URI and information in the .p11-kit persistence format.

       You can specify the following options to control what to dump.

       --filter=<what>
           Specifies what certificates to extract. You can specify the following values:

           all
               All objects. This is the default

           pkcs11:object=xx
               A PKCS#11 URI to filter with

CHECK FORMAT
       Check the format of .p11-kit files.

           $ trust check-format /path/to/file.p11-kit...

       Administrators sometimes need to write a custom .p11-kit file to amend the trust information. This is an error prone process as the file format is mainly for machine
       processing. Administrators can use this command to check whether a file has a correct .p11-kit format.

       This command takes an arbitrary number of files as an input. Each file is then analysed and any mismatch with the .p11-kit format is reported on the standard error
       output. After the file is processed a check result is printed on the standard output.

BUGS
       Please send bug reports to either the distribution bug tracker or the upstream bug tracker at https://github.com/p11-glue/p11-kit/issues/.

SEE ALSO
       p11-kit(8)

       An explanatory document about storing trust policy: https://p11-glue.github.io/p11-glue/doc/storing-trust-policy/

       Further details available in the p11-kit online documentation at https://p11-glue.github.io/p11-glue/p11-kit/manual/.

p11-kit                                                                                                                                                               TRUST(1)

今のトラストストアの証明書を一覧表示するにはtrust list、詳細に見るならtrust dump、証明書を追加するならtrust anchor、証明書を削除するならtrust anchor --removeといった使い分けのようです。

少し使ってみましょうか。

環境

今回の環境はこちらです。

$ cat /etc/redhat-release
Rocky Linux release 9.7 (Blue Onyx)


$ uname -srvmpio
Linux 5.14.0-611.24.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 23 11:42:43 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

現在のトラストストアを確認する

まずは現在のトラストストアを確認してみましょう。

  • /etc/pki/ca-trust
  • /usr/share/pki/ca-trust-source

/etc/pki/ca-trustディレクトリから。

$ tree /etc/pki/ca-trust
/etc/pki/ca-trust
├── README
├── ca-legacy.conf
├── extracted
│   ├── README
│   ├── edk2
│   │   ├── README
│   │   └── cacerts.bin
│   ├── java
│   │   ├── README
│   │   └── cacerts
│   ├── openssl
│   │   ├── README
│   │   └── ca-bundle.trust.crt
│   └── pem
│       ├── README
│       ├── directory-hash
│       │   ├── 002c0b4f.0 -> GlobalSign_Root_R46.pem
│       │   ├── 01419da9.0 -> Microsoft_ECC_Root_Certificate_Authority_2017.pem
│       │   ├── 0179095f.0 -> BJCA_Global_Root_CA1.pem
│       │   ├── 02265526.0 -> Entrust_Root_Certification_Authority_-_G2.pem
│       │   ├── 04f60c28.0 -> USERTrust_ECC_Certification_Authority.pem

〜省略〜

│       │   ├── 9d04f354.0 -> DigiCert_Assured_ID_Root_G2.pem
│       │   ├── 9d6523ce.0 -> ePKI_Root_Certification_Authority.pem
│       │   ├── 9e654b62.0 -> SwissSign_RSA_TLS_Root_CA_2022_-_1.pem
│       │   ├── 9ef4a08a.0 -> D-TRUST_BR_Root_CA_1_2020.pem
│       │   ├── 9f727ac7.0 -> HARICA_TLS_RSA_Root_CA_2021.pem
│       │   ├── ACCVRAIZ1.pem
│       │   ├── AC_RAIZ_FNMT-RCM.pem
│       │   ├── AC_RAIZ_FNMT-RCM_SERVIDORES_SEGUROS.pem
│       │   ├── ANF_Secure_Server_Root_CA.pem
│       │   ├── Actalis_Authentication_Root_CA.pem

〜省略〜

│       │   ├── TunTrust_Root_CA.pem
│       │   ├── UCA_Extended_Validation_Root.pem
│       │   ├── UCA_Global_G2_Root.pem
│       │   ├── USERTrust_ECC_Certification_Authority.pem
│       │   ├── USERTrust_RSA_Certification_Authority.pem
│       │   ├── a09a51ae.0 -> D-TRUST_EV_Root_CA_2_2023.pem
│       │   ├── a2c66da8.0 -> DigiCert_Trusted_Root_G4.pem
│       │   ├── a3418fda.0 -> GTS_Root_R4.pem
│       │   ├── a716d4ed.0 -> D-TRUST_EV_Root_CA_1_2020.pem
│       │   ├── a81e292b.0 -> SZAFIR_ROOT_CA2.pem

〜省略〜

│       │   ├── fe8a2cd8.0 -> SZAFIR_ROOT_CA2.pem
│       │   ├── feffd413.0 -> GlobalSign_Root_E46.pem
│       │   ├── ff34af3f.0 -> TUBITAK_Kamu_SM_SSL_Kok_Sertifikasi_-_Surum_1.pem
│       │   ├── ffa7f1eb.0 -> BJCA_Global_Root_CA1.pem
│       │   ├── ffdd40f9.0 -> D-TRUST_BR_Root_CA_2_2023.pem
│       │   ├── vTrus_ECC_Root_CA.pem
│       │   └── vTrus_Root_CA.pem
│       ├── email-ca-bundle.pem
│       ├── objsign-ca-bundle.pem
│       └── tls-ca-bundle.pem
└── source
    ├── README
    ├── anchors
    ├── blocklist
    └── ca-bundle.legacy.crt -> /usr/share/pki/ca-trust-legacy/ca-bundle.legacy.default.crt

9 directories, 455 files

/etc/pki/ca-trust/source/anchorsディレクトリは空ですね。

最終的に見ることになるのは/etc/pki/ca-trust/extractedディレクトリ配下だと思いますが。

$ tree -L 2 /etc/pki/ca-trust/extracted
/etc/pki/ca-trust/extracted
├── README
├── edk2
│   ├── README
│   └── cacerts.bin
├── java
│   ├── README
│   └── cacerts
├── openssl
│   ├── README
│   └── ca-bundle.trust.crt
└── pem
    ├── README
    ├── directory-hash
    ├── email-ca-bundle.pem
    ├── objsign-ca-bundle.pem
    └── tls-ca-bundle.pem

5 directories, 11 files

/usr/share/pki/ca-trust-sourceディレクトリにはものが少なく、結合された証明書だけがあります。

$ tree /usr/share/pki/ca-trust-source
/usr/share/pki/ca-trust-source
├── README
├── anchors
├── blocklist
└── ca-bundle.trust.p11-kit

2 directories, 2 files

trustコマンドで確認してみる

まずはtrustコマンドを使ってみましょう。

trust list

$ trust list | head -n 30
pkcs11:id=%42%3D%2B%24%A6%C1%45%CE;type=cert
    type: certificate
    label: A-Trust-Qual-02
    trust: anchor
    category: authority

pkcs11:id=%46%06%DF%37%F2%C2%37%10;type=cert
    type: certificate
    label: A-Trust-Qual-03
    trust: anchor
    category: authority

pkcs11:id=%40%F9%B9%67%BE%03%D2%08;type=cert
    type: certificate
    label: A-Trust-Root-05
    trust: anchor
    category: authority

pkcs11:id=%44%6A%95%67%55%79%11%4F;type=cert
    type: certificate
    label: A-Trust-nQual-03
    trust: anchor
    category: authority

pkcs11:id=%33%43%18%B3%C4%4B%1D%CB%1F%F9%F0%4E%FC%DF%4A%E4%15%60%C8%83;type=cert
    type: certificate
    label: AC1 RAIZ MTIN
    trust: anchor
    category: authority

〜省略〜

trust dump

$ trust dump | head -n 100
# pkcs11:
[p11-kit-object-v1]
class: nss-builtin-root-list
private: false
label: "Trust Anchor Roots"
modifiable: false


# pkcs11:
[p11-kit-object-v1]
class: nss-builtin-root-list
private: false
label: "Trust Anchor Roots"
modifiable: false


# pkcs11:id=%57%38%74%BE%5C%36%85%F4%C8%A9%A5%93%87%D5%90%36%2B%A5%93%19
[p11-kit-object-v1]
class: x-certificate-extension
private: false
label: "A-Trust-Qual-02"
value: "0%16%06%03U%1D%25%01%01%FF%04%0C0%0A%06%08%2B%06%01%05%05%07%03%03"
object-id: 2.5.29.37
id: "W8t%BE%5C6%85%F4%C8%A9%A5%93%87%D5%906%2B%A5%93%19"
modifiable: false
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlpGr146wWbgBvbQerZn9
ofzqDJZrjy5JSNjp5CSC4di6zOveB1xIxhmCAUdCCeF8uZ+uj/buXmuoqFaIOFaz
5v7JnU80OFE8nL7zrJwcyD1cmoSu95QsFLJkN2COFLA7Ks2JtSKv9+R/7iwrM/mO
PK1MolcP+4LFjh8B31OMwRWk3e6akhLSKOliFyVgMe/PMZTzffPkPCGrkPxtz2On
xhIAcUnXHMig7WOafeOPKN1g+djmFqsm0dAvvecNCd9u1OzlOFP0ZAu6WsyAtThZ
7IBZZYQxal9VkUwk5SSag4R6voDx7l8gB6p3F2wL4lWqlngIAp6X8CuuWPWAUD/+
OwIDAQAB
-----END PUBLIC KEY-----


# pkcs11:id=%42%3D%2B%24%A6%C1%45%CE;type=cert
[p11-kit-object-v1]
private: false
label: "A-Trust-Qual-02"
issuer: "0%81%8B1%0B0%09%06%03U%04%06%13%02AT1H0F%06%03U%04%0A%0C%3FA-Trust Ges. f. Sicherheitssysteme im elektr. Datenverkehr GmbH1%180%16%06%03U%04%0B%0C%0FA-Trust-Qual-021%180%16%06%03U%04%03%0C%0FA-Trust-Qual-02"
serial-number: "%02%03%14M%E4"
trusted: true
certificate-category: authority
java-midp-security-domain: 0
url: ""
hash-of-subject-public-key: "W8t%BE%5C6%85%F4%C8%A9%A5%93%87%D5%906%2B%A5%93%19"
hash-of-issuer-public-key: ""
check-value: "%CDxz"
subject: "0%81%8B1%0B0%09%06%03U%04%06%13%02AT1H0F%06%03U%04%0A%0C%3FA-Trust Ges. f. Sicherheitssysteme im elektr. Datenverkehr GmbH1%180%16%06%03U%04%0B%0C%0FA-Trust-Qual-021%180%16%06%03U%04%03%0C%0FA-Trust-Qual-02"
id: "B%3D%2B%24%A6%C1E%CE"
start-date: "20140701"
end-date: "20240701"
modifiable: false
nss-mozilla-ca-policy: true
nss-server-distrust-after: "%00"
nss-email-distrust-after: "%00"
x-distrusted: false
-----BEGIN CERTIFICATE-----
MIIDyzCCArOgAwIBAgIDFE3kMA0GCSqGSIb3DQEBBQUAMIGLMQswCQYDVQQGEwJB
VDFIMEYGA1UECgw/QS1UcnVzdCBHZXMuIGYuIFNpY2hlcmhlaXRzc3lzdGVtZSBp
bSBlbGVrdHIuIERhdGVudmVya2VociBHbWJIMRgwFgYDVQQLDA9BLVRydXN0LVF1
YWwtMDIxGDAWBgNVBAMMD0EtVHJ1c3QtUXVhbC0wMjAeFw0xNDA3MDExMTIzMzNa
Fw0yNDA3MDEwOTIzMzNaMIGLMQswCQYDVQQGEwJBVDFIMEYGA1UECgw/QS1UcnVz
dCBHZXMuIGYuIFNpY2hlcmhlaXRzc3lzdGVtZSBpbSBlbGVrdHIuIERhdGVudmVy
a2VociBHbWJIMRgwFgYDVQQLDA9BLVRydXN0LVF1YWwtMDIxGDAWBgNVBAMMD0Et
VHJ1c3QtUXVhbC0wMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJaR
q9eOsFm4Ab20Hq2Z/aH86gyWa48uSUjY6eQkguHYuszr3gdcSMYZggFHQgnhfLmf
ro/27l5rqKhWiDhWs+b+yZ1PNDhRPJy+86ycHMg9XJqErveULBSyZDdgjhSwOyrN
ibUir/fkf+4sKzP5jjytTKJXD/uCxY4fAd9TjMEVpN3umpIS0ijpYhclYDHvzzGU
833z5Dwhq5D8bc9jp8YSAHFJ1xzIoO1jmn3jjyjdYPnY5harJtHQL73nDQnfbtTs
5ThT9GQLulrMgLU4WeyAWWWEMWpfVZFMJOUkmoOEer6A8e5fIAeqdxdsC+JVqpZ4
CAKel/Arrlj1gFA//jsCAwEAAaM2MDQwDwYDVR0TAQH/BAUwAwEB/zARBgNVHQ4E
CgQIQj0rJKbBRc4wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQBh
MfOINQm4XpzF6DmkOmb/ArSXHf5LObqFmIMooNr2TkyzrUTK/NE+mdrm15Rfdts7
kZVq/ICfQSFeaPvWaAVq4plH/26OjvMTVv7DfgfPBUxDWqlCuDnDnPAVQ+yo/o5i
BA5uUlMbp5znbDtlxwF/5gWqcn/hKxSUCP1uiOPIlKfeVvsRmBcJAdoixTM/Ic10
pavJMGOI20onArvQZAUEbXQLA8cs8naxfF6Bo36U9nk6wn7q8VPXhViekByd17F6
9A+ah0Iqw4SPf9BqNRIe1YxxjDhCmjWt3aoyE3ZFBuGjW+r2ipb/vGU1+2oyy2Fd
2dMmiMQ7gGhWX9X6gWLd
-----END CERTIFICATE-----


# pkcs11:id=%AC%2E%43%86%A9%E3%6E%88%7E%D9%0E%22%7E%FC%8E%CB%75%48%3D%2D
[p11-kit-object-v1]
class: x-certificate-extension
private: false
label: "A-Trust-Qual-03"
value: "0%16%06%03U%1D%25%01%01%FF%04%0C0%0A%06%08%2B%06%01%05%05%07%03%03"
object-id: 2.5.29.37
id: "%AC.C%86%A9%E3n%88%7E%D9%0E%22%7E%FC%8E%CBuH%3D-"
modifiable: false
-----BEGIN PUBLIC KEY-----

〜省略〜

trust anchorで証明書を追加します。対象はこちらの記事で使ったApacheの自己署名証明書にしましょう。

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

現在はトラストストアに入っていないので、curlでアクセスする時には--cacertで証明書を指定しないとアクセスできません。

$ curl --cacert /etc/pki/tls/certs/localhost.crt -I https://$(hostname)
HTTP/1.1 403 Forbidden
Date: Sat, 31 Jan 2026 11:38:12 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.1
Last-Modified: Sat, 17 May 2025 02:45:05 GMT
ETag: "1dc4-6354be2d9ae40"
Accept-Ranges: bytes
Content-Length: 7620
Content-Type: text/html; charset=UTF-8

$ curl -I https://$(hostname)
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

trust anchorで証明書を指定して追加。

$ sudo trust anchor /etc/pki/tls/certs/localhost.crt

すると、/etc/pki/ca-trust/sourceディレクトリにファイルが増えます。
※今回使った証明書のCommon Nameはrocky9.localdomainなのですが、これがファイル名になっているようです

$ ll /etc/pki/ca-trust/source
合計 12
-rw-r--r--. 1 root root  932 11月 21 09:25 README
drwxr-xr-x. 2 root root    6 11月 21 09:27 anchors
drwxr-xr-x. 2 root root    6 11月 21 09:27 blocklist
lrwxrwxrwx. 1 root root   59  1月 31 15:31 ca-bundle.legacy.crt -> /usr/share/pki/ca-trust-legacy/ca-bundle.legacy.default.crt
-r--r--r--. 1 root root 3538  1月 31 20:39 rocky9.localdomain.1.p11-kit
-r--r--r--. 1 root root 3060  1月 31 20:39 rocky9.localdomain.p11-kit

こちらの各種ファイルにも取り込まれているようです。

$ tree -L 2 /etc/pki/ca-trust/extracted
/etc/pki/ca-trust/extracted
├── README
├── edk2
│   ├── README
│   └── cacerts.bin
├── java
│   ├── README
│   └── cacerts
├── openssl
│   ├── README
│   └── ca-bundle.trust.crt
└── pem
    ├── README
    ├── directory-hash
    ├── email-ca-bundle.pem
    ├── objsign-ca-bundle.pem
    └── tls-ca-bundle.pem

5 directories, 11 files

trust listで見ると、どうやら先頭に追加されたようです。

$ trust list
pkcs11:id=%68%86%41%87%0C%CA%D1%56%EE%D4%23%FF%A8%B1%4D%F8%F8%77%B1%23;type=cert
    type: certificate
    label: rocky9.localdomain
    trust: anchor
    category: other-entry

pkcs11:id=%CA%9C%76%C4%B4%CA%D0%D8%65%D7%C9%8A%2F%5D%03%AD%F3%98%14%54;type=cert
    type: certificate
    label: rocky9.localdomain
    trust: anchor
    category: authority

これで証明書を指定しなくてもcurlでアクセスできるようになります。

$ curl -I https://$(hostname)
HTTP/1.1 403 Forbidden
Date: Sat, 31 Jan 2026 11:40:44 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.1
Last-Modified: Sat, 17 May 2025 02:45:05 GMT
ETag: "1dc4-6354be2d9ae40"
Accept-Ranges: bytes
Content-Length: 7620
Content-Type: text/html; charset=UTF-8

削除。trust anchor --removeでファイルパスを指定するか、id(pkcs11:id=〜)を指定するようです。

$ sudo trust anchor --remove /etc/pki/tls/certs/localhost.crt

curlでアクセスできなくなりました。

$ curl -I https://$(hostname)
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

update-ca-trustを使う

最後はupdate-ca-trustです。

こちらの場合、以下のどちらかに証明書を追加するのでした。

  • /usr/share/pki/ca-trust-source/anchors
  • /etc/pki/ca-trust/source/anchors

というわけで、証明書をコピー。

$ sudo cp /etc/pki/tls/certs/localhost.crt /etc/pki/ca-trust/source/anchors

トラストストアを更新。

$ sudo update-ca-trust extract

curlでアクセスできるようになりました。

$ curl -I https://$(hostname)
HTTP/1.1 403 Forbidden
Date: Sat, 31 Jan 2026 11:47:10 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.1
Last-Modified: Sat, 17 May 2025 02:45:05 GMT
ETag: "1dc4-6354be2d9ae40"
Accept-Ranges: bytes
Content-Length: 7620
Content-Type: text/html; charset=UTF-8

こちらの場合、/etc/pki/ca-trust/sourceにはファイルは増えないようです。

$ ll /etc/pki/ca-trust/source
合計 4
-rw-r--r--. 1 root root 932 11月 21 09:25 README
drwxr-xr-x. 2 root root  27  1月 31 20:46 anchors
drwxr-xr-x. 2 root root   6 11月 21 09:27 blocklist
lrwxrwxrwx. 1 root root  59  1月 31 15:31 ca-bundle.legacy.crt -> /usr/share/pki/ca-trust-legacy/ca-bundle.legacy.default.crt

/etc/pki/ca-trust/extractedディレクトリ配下は更新されていました。

trust listには表示されます。

$ trust list
pkcs11:id=%68%86%41%87%0C%CA%D1%56%EE%D4%23%FF%A8%B1%4D%F8%F8%77%B1%23;type=cert
    type: certificate
    label: rocky9.localdomain
    trust: anchor
    category: other-entry

pkcs11:id=%CA%9C%76%C4%B4%CA%D0%D8%65%D7%C9%8A%2F%5D%03%AD%F3%98%14%54;type=cert
    type: certificate
    label: rocky9.localdomain
    trust: anchor
    category: authority

削除する場合は、/etc/pki/ca-trust/sourceディレクトリからファイルを削除して

$ sudo rm /etc/pki/ca-trust/source/anchors/localhost.crt

再度update-ca-trust extract

$ sudo update-ca-trust extract

これでcurlでアクセスできなくなりました。

$ curl -I https://$(hostname)
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

確認が大変でしたが、およそ動作がわかったのではないかと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?