Infrastruktur Kunci Publik Berdasarkan Kriptografi Rusia: GnuTLS sebagai Alternatif untuk OpenSSL

gambarInfrastruktur Kunci Publik ( PKI / PKI ) mencakup banyak objek dan mekanisme yang berbeda untuk bekerja dengannya, serta protokol untuk interaksi objek satu sama lain (misalnya, TLS, OCSP). Objek PKI mencakup permintaan untuk sertifikat (PKCS # 10) dan sertifikat x509 itu sendiri, pasangan kunci (kunci pribadi dan publik), dokumen yang ditandatangani dan dienkripsi (PKCS # 7, CMS), wadah aman untuk menyimpan kunci pribadi (PKCS # 8) dan sertifikat pribadi dengan kunci (PKCS # 12), dll. Mekanismenya tidak hanya mencakup fungsi kriptografi yang memungkinkan Anda mengenkripsi dan menandatangani dokumen menggunakan berbagai algoritme, tetapi juga fungsi yang membentuk objek PKI akhir. sesuai dengan standar (sertifikat, permintaan, dokumen yang ditandatangani / dienkripsi, paket protokol, dll., dll.). Ya, dan bagaimana untuk tidak mengingat objek sentral IEC / PKI - CA .



Saat ini sulit membayangkan kehidupan bisnis negara tanpa PKI , tanpa sertifikat x509 (tanpa sertifikat yang memenuhi syarat), tanpa layanan layanan publik dan Layanan Pajak Federal, di mana dokumen-dokumen itu diterima dalam bentuk elektronik dengan tanda tangan elektronik. Dan semakin banyak dokumen yang dikembalikan kepada warga negara juga dalam bentuk elektronik dengan tanda tangan elektronik. Proses hukum tidak dapat lagi diajukan tanpa tanda tangan elektronik.



Alat paling canggih untuk membuat alat perangkat lunak yang bekerja dengan objek PKI adalah OpenSSL.



OpenSSL adalah sekumpulan pustaka dan utilitas kriptografi open source lengkap yang mendukung hampir semua algoritma hashing, enkripsi, dan tanda tangan digital tingkat rendah, dan menerapkan sebagian besar standar kriptografi populer. Namun, standar kriptografi ini tidak termasuk kriptografi Rusia. Untuk pekerjaan lengkap dengan kriptografi Rusia di OpenSSL, perlu juga untuk menghubungkan mesin gost .



Kami sudah menulis bahwa pustaka gcrypt bisa menjadi alternatif untuk openssl .... Dan sekarang dukungan untuk kriptografi Rusia dan mekanisme kriptografi telah diimplementasikan dalam proyek GnuTLS . GnuTLS mendukung algoritme kriptografi lama dan yang baru - GOST R 34.10-2012 (tanda tangan elektronik), GOST R 34.11-2012 (hashing), GOST R 34.12-2015 dan GOST R 34.13-2015 (algoritme enkripsi Belalang dan Magma).



Secara analogi dengan utility openssl pada project OpenSSL, project GnuTLS memiliki utility certtool yang dari segi fungsinya tidak kalah dengan utility openssl.



Ini tentang utilitas ini dan kemampuannya yang akan dibahas.



Informasi umum tentang utilitas certtool



Sebagaimana dicatat, utilitas certtool memiliki banyak kesamaan dengan utilitas openssl.



Parameter pertama dari utilitas certtool, sebagai suatu peraturan, adalah sebuah tanda yang menentukan fungsi mana yang harus dijalankan. Misalnya, tanda "--certificate-info" menunjukkan bahwa sertifikat perlu diurai, dan tanda "--generate-privkey" memerintahkan untuk membuat kunci pribadi. Data masukan, yang merupakan objek PKI (kunci, sertifikat, daftar pencabutan sertifikat, dll.) Yang diperlukan untuk eksekusi perintah, dimasukkan sebagai struktur ASN1 dalam format PEM (base64) atau DER. Standarnya adalah format PEM.



Jika data akan diterima dalam format DER, maka opsi "--inder" harus ditentukan.



Hasil dari menjalankan fungsi terkait adalah struktur ASN1 (sertifikat yang sama, misalnya). Secara default, struktur ASN1 keluaran dalam format PEM. Jika Anda perlu mendapatkannya dalam format DER, tambahkan opsi "--outder". Bersama dengan struktur ASN1 default (opsi "--teks"), isinya juga ditampilkan dalam bentuk teks. Jika tidak perlu menampilkan tampilan teks, maka opsi "--tidak ada teks" ditentukan.



Semua ini dapat ditunjukkan dengan contoh mengonversi file sertifikat dari format PEM ke DER dan sebaliknya:



#      PEM  DER
#   --outder,   --no-text   .
$certtool --certificate-info --infile certPEM.pem --outder --outfile certDER.der
#      DER  PEM
$certtool --certificate-info --inder --infile certDER.der --no-text  --outfile certPEM_new.pem
$

      
      





Untuk bantuan tentang utilitas certtool, jalankan perintah:



$ certtool --help



Bantuan utilitas Certtool
certtool - GnuTLS certificate tool
Usage:  certtool [ -<flag> [<val>] | --<name>[{=| }<val>] ]...

   -d, --debug=num            Enable debugging
				- it must be in the range:
				  0 to 9999
   -V, --verbose              More verbose output
				- may appear multiple times
       --infile=file          Input file
				- file must pre-exist
       --outfile=str          Output file

Certificate related options:

   -i, --certificate-info     Print information on the given certificate
       --pubkey-info          Print information on a public key
   -s, --generate-self-signed  Generate a self-signed certificate
   -c, --generate-certificate  Generate a signed certificate
       --generate-proxy       Generates a proxy certificate
   -u, --update-certificate   Update a signed certificate
       --fingerprint          Print the fingerprint of the given certificate
       --key-id               Print the key ID of the given certificate
       --v1                   Generate an X.509 version 1 certificate (with no extensions)
       --sign-params=str      Sign a certificate with a specific signature algorithm

Certificate request related options:

       --crq-info             Print information on the given certificate request
   -q, --generate-request     Generate a PKCS #10 certificate request
				- prohibits the option 'infile'
       --no-crq-extensions    Do not use extensions in certificate requests

PKCS#12 file related options:

       --p12-info             Print information on a PKCS #12 structure
       --p12-name=str         The PKCS #12 friendly name to use
       --to-p12               Generate a PKCS #12 structure

Private key related options:

   -k, --key-info             Print information on a private key
       --p8-info              Print information on a PKCS #8 structure
       --to-rsa               Convert an RSA-PSS key to raw RSA format
   -p, --generate-privkey     Generate a private key
       --key-type=str         Specify the key type to use on key generation
       --bits=num             Specify the number of bits for key generation
       --curve=str            Specify the curve used for EC key generation
       --sec-param=str        Specify the security level [low, legacy, medium, high, ultra]
       --to-p8                Convert a given key to a PKCS #8 structure
   -8, --pkcs8                Use PKCS #8 format for private keys
       --provable             Generate a private key or parameters from a seed using a provable method
       --verify-provable-privkey  Verify a private key generated from a seed using a provable method
       --seed=str             When generating a private key use the given hex-encoded seed

CRL related options:

   -l, --crl-info             Print information on the given CRL structure
       --generate-crl         Generate a CRL
       --verify-crl           Verify a Certificate Revocation List using a trusted list
				- requires the option 'load-ca-certificate'

Certificate verification related options:

   -e, --verify-chain         Verify a PEM encoded certificate chain
       --verify               Verify a PEM encoded certificate (chain) against a trusted set
       --verify-hostname=str  Specify a hostname to be used for certificate chain verification
       --verify-email=str     Specify a email to be used for certificate chain verification
				- prohibits the option 'verify-hostname'
       --verify-purpose=str   Specify a purpose OID to be used for certificate chain verification
       --verify-allow-broken  Allow broken algorithms, such as MD5 for verification
       --verify-profile=str   Specify a security level profile to be used for verification

PKCS#7 structure options:

       --p7-generate          Generate a PKCS #7 structure
       --p7-sign              Signs using a PKCS #7 structure
       --p7-detached-sign     Signs using a detached PKCS #7 structure
       --p7-include-cert      The signer's certificate will be included in the cert list.
				- disabled as '--no-p7-include-cert'
				- enabled by default
       --p7-time              Will include a timestamp in the PKCS #7 structure
				- disabled as '--no-p7-time'
       --p7-show-data         Will show the embedded data in the PKCS #7 structure
				- disabled as '--no-p7-show-data'
       --p7-info              Print information on a PKCS #7 structure
       --p7-verify            Verify the provided PKCS #7 structure
       --smime-to-p7          Convert S/MIME to PKCS #7 structure

Other options:

       --get-dh-params        List the included PKCS #3 encoded Diffie-Hellman parameters
       --dh-info              Print information PKCS #3 encoded Diffie-Hellman parameters
       --load-privkey=str     Loads a private key file
       --load-pubkey=str      Loads a public key file
       --load-request=str     Loads a certificate request file
       --load-certificate=str Loads a certificate file
       --load-ca-privkey=str  Loads the certificate authority's private key file
       --load-ca-certificate=str Loads the certificate authority's certificate file
       --load-crl=str         Loads the provided CRL
       --load-data=str        Loads auxiliary data
       --password=str         Password to use
       --null-password        Enforce a NULL password
       --empty-password       Enforce an empty password
       --hex-numbers          Print big number in an easier format to parse
       --cprint               In certain operations it prints the information in C-friendly format
       --hash=str             Hash algorithm to use for signing
       --salt-size=num        Specify the RSA-PSS key default salt size
       --inder                Use DER format for input certificates, private keys, and DH parameters
				- disabled as '--no-inder'
       --inraw                an alias for the 'inder' option
       --outder               Use DER format for output certificates, private keys, and DH parameters
				- disabled as '--no-outder'
       --outraw               an alias for the 'outder' option
       --template=str         Template file to use for non-interactive operation
       --stdout-info          Print information to stdout instead of stderr
       --ask-pass             Enable interaction for entering password when in batch mode.
       --pkcs-cipher=str      Cipher to use for PKCS #8 and #12 operations
       --provider=str         Specify the PKCS #11 provider library
       --text                 Output textual information before PEM-encoded certificates, private
keys, etc
				- disabled as '--no-text'
				- enabled by default

Version, usage and configuration options:

   -v, --version[=arg]        output version information and exit
   -h, --help                 display extended usage information and exit
   -!, --more-help            extended usage information passed thru pager

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.

Tool to parse and generate X.509 certificates, requests and private keys.
It can be used interactively or non interactively by specifying the
template command line option.

The tool accepts files or supported URIs via the --infile option.  In case
PIN is required for URI access you can provide it using the environment
variables GNUTLS_PIN and GNUTLS_SO_PIN.

Please send bug reports to:  <bugs@gnutls.org>

      
      







Sekarang mari beralih ke fungsi utama dari utilitas certtool.



Menghasilkan dan melihat pasangan



Untuk membuat kunci pribadi menggunakan algoritma GOST R 34.10 2012, perintah berikut digunakan:



$certtool --generate-privkey --key-type [gost12-256 | gost12-512] --curve < > [--no-text] [--outder] [--outfile <   >]
$
      
      





Parameter kripto (--curve) saat membuat pasangan kunci diatur oleh OID. Saat ini, TK-26 telah menetapkan oid-s berikut untuk parameter kripto dari algoritme tanda tangan GOST R 34.10-2012 dengan kunci 256:



1.2.643.7.1.2.1.1.1 (id-tc26-gost-3410-12-256-paramSetA) [TC26-256-A];

1.2.643.7.1.2.1.1.2 (id-tc26-gost-3410-12-256-paramSetB) [TC26-256-B];

1.2.643.7.1.2.1.1.3 (id-tc26-gost-3410-12-256-paramSetC) [TC26-256-C];

1.2.643.7.1.2.1.1.4 (id-tc26-gost-3410-12-256-paramSetD) [TC26-256-D].


Pada saat yang sama, yang disebut parameter OID dari CryptoPro terus beroperasi:



1.2.643.2.2.35.1 (id-GostR3410-2001-CryptoPro-A-ParamSet) [CryptoPro-A];

1.2.643.2.2.35.2 (d-GostR3410-2001-CryptoPro-B-ParamSet) [CryptoPro-B];

1.2.643.2.2.35.3 (id-GostR3410-2001-CryptoPro-C-ParamSet) [CryptoPro-C];

1.2.643.2.2.36.0 (id-GostR3410-2001-CryptoPro-XchA-ParamSet) [CryptoPro-XchA];

1.2.643.2.2.36.1 (id-GostR3410-2001-CryptoPro-XchB-ParamSet) [CryptoPro-XchB].


Ingatlah bahwa parameter CryptoPro dengan OID 1.2.643.2.2.35.1, 1.2.643.2.2.35.2, 1.2.643.2.2.35.3 sesuai dengan parameter TC-26 dengan OID 1.2.643.7.1.2.1.1.1 , 1.2.643.7.1.2.1.1.2, 1.2.643.7.1.2.1.1.3 masing-masing.



Dengan parameter kripto untuk algoritme tanda tangan GOST R 34.10-2012 dengan kunci 512, lebih mudah:



1.2.643.7.1.2.1.2.1 (id-tc26-gost-3410-2012-512-paramSetA) [TC26-512-A];

1.2.643.7.1.2.1.2.2 (id-tc26-gost-3410-2012-512-paramSetB) [TC26-512-B];

1.2.643.7.1.2.1.2.3 (id-tc26-gost-3410-2012-512-paramSetC) [TC26-512-C];


GnuTLS memiliki notasi sendiri untuk parameter kripto dan ditunjukkan dalam tanda kurung siku, misalnya [TC26-256-B]. Sayangnya, saat membuat kunci, parameter kripto hanya dapat disetel dengan penunjukan simbolisnya. OID bertitik dibuang.

Namun ini bukanlah kekurangan terbesar. Saat ini hanya dua parameter kripto yang didukung di GnuTLS. Untuk kunci GOST 34.10-2012-256 (opsi --key-type gost12-256) ini adalah parameter dengan oid 1.2.643.7.1.2.1.1.2 (opsi --curve TC26-256), dan untuk kunci dengan panjang dari 512 bit ini adalah parameter dengan oid 1.2.643.7.1.2.1.2.1 (opsi --curve TC26-512-A).



Jadi, buat kunci pribadi (--generate-privkey flag) dan lihat informasi tentang kunci (--key-info flag):



#    --key-type gost12-256 --curve TC26-256-B
$certtool --generate-privkey --key-type gost12-256 --curve TC26-256-B --no-text --outder --outfile key256.der
Generating a 256 bit GOST R 34.10-2012-256 private key (TC26-256-B)...
#  
$certtool --key-info --inder --infile key256.der
Public Key Info:
   Public Key Algorithm: GOST R 34.10-2012-256
   Key Security Level: High (256 bits)

curve:   TC26-256-B
digest:  STREEBOG-256
paramset:   TC26-Z
private key:
   4b:df:cb:9e:cc:49:c5:a2:70:36:c9:d8:df:55:97:f5
   8b:be:ae:06:7b:34:76:39:b6:aa:57:af:3f:2d:98:36
x:
   0d:71:29:56:d2:39:59:6f:14:d3:4b:75:44:85:91:a9
   5d:fa:83:4a:93:9a:2c:20:b0:6b:5c:74:8c:76:5f:a5
y:
   2d:ac:da:23:f3:2f:45:d9:47:c4:a3:c1:d7:65:bd:46
   1d:ba:12:cd:15:e1:b0:8f:5a:99:f2:35:ea:fc:33:fc
   
Public Key PIN:
   pin-sha256:nrftlmdCrSf11N+ivohfuGXSQixa4Scnhl7GTsUTE2E=
Public Key ID:
   sha256:9eb7ed966742ad27f5d4dfa2be885fb865d2422c5ae12727865ec64ec5131361
   sha1:25927018f3775ed86996c625a99b7db86b2d0a7e
-----BEGIN PRIVATE KEY-----
MEACAQAwFwYIKoUDBwEBAQEwCwYJKoUDBwECAQECBCIEIDaYLT+vV6q2OXY0ewau
vov1l1Xf2Mk2cKLFScyey99L
-----END PRIVATE KEY-----
$
      
      





Dalam informasi tentang kunci, kami memiliki informasi lengkap tentang kunci privat (tertutup), termasuk struktur asn1, dan kunci publik, termasuk nilainya (x dan y).

Sekarang mari kita lihat struktur kunci privat asn1. Untuk melakukan ini, kami akan menggunakan utilitas cryptoarmpkcs :







Anda tidak akan menemukan nilai kunci publik dalam struktur ini. Nilai kunci publik dihitung melalui kunci privat. Tetapi kunci privat tidak dapat dihitung dari kunci publik, tentu saja !!! Namun, sayang sekali bahwa struktur asn1 dari kunci publik tidak tersedia saat melihat kunci privat (tanda --key-info). Dimungkinkan untuk memasukkan opsi --pubkey-info (ada opsi seperti itu untuk sertifikat), yang akan menampilkan struktur asn1 dari kunci publik.



Tentunya private key harus disimpan dengan aman, setidaknya dienkripsi dengan password. Kontainer PKCS8 digunakan untuk menyimpan kunci privat dengan aman, yang memberikan kemampuan untuk mengenkripsi kunci privat menggunakan enkripsi berdasarkan kata sandi pengguna. Karena di sini kita berbicara tentang penggunaan kriptografi Rusia dan rekomendasi TK-26, perintah untuk membuat kunci pribadi dalam wadah PKCS8 yang aman akan terlihat seperti:



$certtool --generate-privkey --pkcs8 --pkcs-cipher gost28147-tc26z [--password <>] --key-type [gost12-256 | gost12-512] --curve < > [--no-text] [--outder] [--outfile <   >]
$
      
      





Jika opsi "--password" tidak ditentukan, maka kata sandi untuk mengenkripsi kunci pribadi akan diminta di baris perintah:



bash-5.1$ ./generate_key_parse_password.sh 
#    --key-type gost12-256 --curve TC26-256-B
$certtool --generate-privkey --pkcs8 --pkcs-cipher gost28147-tc26z --password 01234567  --key-type gost12-256 --curve TC26-256-B --no-text --outder --outfile key256_pkcs8.der
Generating a 256 bit GOST R 34.10-2012-256 private key (TC26-256-B)...
#   
$certtool --key-info --inder --infile key256.der
Encrypted structure detected...
Enter password: < >
PKCS #8 information:
   Cipher: GOST28147-TC26Z-CFB
   Schema: PBES2-GOST28147-89-TC26Z (1.2.643.7.1.2.5.1.1)
   Salt: 32b2798c23a5d0ab8c3144daf273745bdb
   Salt size: 17
   Iteration count: 5333

Public Key Info:
   Public Key Algorithm: GOST R 34.10-2012-256
   Key Security Level: High (256 bits)

curve:   TC26-256-B
digest:  STREEBOG-256
paramset:   TC26-Z
private key:
   05:20:c3:7a:93:a2:e1:b4:64:50:a4:fb:db:cc:74:43
   1a:14:d9:00:c4:82:dc:f5:94:8a:8a:65:a4:76:47:76   
x:
   1b:3e:0b:e0:3b:fc:1d:ee:62:10:63:66:72:fc:66:a6
   d5:b8:94:b1:fe:a4:ec:d6:d8:f1:18:63:95:a9:30:15   
y:
   fb:c0:24:10:41:12:98:7f:aa:15:cd:3b:7e:e7:64:bd
   c4:97:3d:18:04:82:f0:80:61:8e:ff:48:eb:d6:97:d5  
Public Key PIN:
   pin-sha256:eD6s4BQl4R0WY6H8KJZKDA6zuzd6A7JcNCh4FpUH1Rg=
Public Key ID:
   sha256:783eace01425e11d1663a1fc28964a0c0eb3bb377a03b25c342878169507d518
   sha1:62afc2d7c8bf77f1ac0820324170cd2262a63091

-----BEGIN PRIVATE KEY-----
MEACAQAwFwYIKoUDBwEBAQEwCwYJKoUDBwECAQECBCIEIHZHdqRlioqU9dyCxADZ
FBpDdMzb+6RQZLThopN6wyAF
-----END PRIVATE KEY-----
#    openssl  
/usr/local/lirssl_csp_64/bin/lirssl pkcs8 -inform DER -in key256_pkcs8.der  -outform PEM
-----BEGIN PRIVATE KEY-----
MEACAQAwFwYIKoUDBwEBAQEwCwYJKoUDBwECAQECBCIEIHZHdqRlioqU9dyCxADZ
FBpDdMzb+6RQZLThopN6wyAF
-----END PRIVATE KEY-----
bash-5.1$  
      
      





Buat permintaan sertifikat



Dengan kunci privat di tempat, Anda dapat mulai membuat permintaan sertifikat Anda.



Bendera --generate-request digunakan untuk membuat permintaan:



certtool --generate-request --load-privkey <   > --template <   > [--no-text]

      
      





Mari pertimbangkan untuk membuat permintaan sertifikat untuk seorang individu. Sertifikat tersebut rencananya akan digunakan untuk menghasilkan dan memverifikasi tanda tangan elektronik. Dalam kasus ini, file dengan template permintaan hanya dapat berisi nama yang dibedakan (DN) dari pemilik sertifikat, yang menyertakan jenis atribut / oids berikut dan nilainya:



# - oid=2.5.4.6
#country = RU
# 
dn_oid = "2.5.4.6 RU"
# - 2.5.4.8
state = "50  "
# 
#dn_oid = "2.5.4.6 RU"
#,  - 2.5.4.7
locality = ". "
# - 2.5.4.9
#street = "  ,    "
# 
#dn_oid = "2.5.4.9   ,    "
# - 2.5.4.10
#organization = "  "
# surname 2.5.4.4
#sn = ""
dn_oid = "2.5.4.4 "
#,  givenname - 2.5.4.42
#ginenName = " "
dn_oid = "2.5.4.42  "
#  commonName - 2.5.4.3
cn = " "

      
      





Seperti yang Anda lihat dari template, atribut untuk DN (nama yang dibedakan) dapat ditentukan menggunakan nama simbolis dari atribut yang diterima di GnuTLS (misalnya, country = RU), atau menggunakan oid atribut:



dn_oid = "<oid > < >"
      
      



...

Dalam hal ini, Anda dapat menentukan negaranya seperti ini:



dn_oid = "2.5.4.6 RU"
      
      





Jika kita ingin nama yang dibedakan dalam permintaan tersebut mempertimbangkan "Persyaratan untuk bentuk sertifikat yang memenuhi syarat dari kunci verifikasi tanda tangan elektronik" , maka kita harus menambahkan TIN dan SNILS ke dalamnya , jika kita berbicara tentang individu :



#   - /INN
dn_oid = "1.2.643.3.131.1.1  123456789012"
#     - /SNILS
dn_oid = "1.2.643.100.3 12345678901"
      
      





Jadi katakanlah kunci pribadi disimpan di file privkey.pem dan templatnya ada di file templateP10.txt. Kemudian permintaan tersebut dapat dibuat dan dilihat dengan perintah berikut:



$certtool --generate-request --load-privkey privkey.pem --template templateP10.txt
Generating a PKCS #10 certificate request...
PKCS #10 Certificate Request Information:
   Version: 1
   Subject: EMAIL=gnutls@aa.ru,SNILS=12345678909,INN=123456789098,givenName=  ,surName=,street=  \,    ,C=RU,ST= ,L=. ,CN= 
   Subject Public Key Algorithm: GOST R 34.10-2012-256
   Algorithm Security Level: High (256 bits)
      Curve:   TC26-256-B
      Digest:  STREEBOG-256
      ParamSet: TC26-Z
      X:
         23:63:5c:72:6f:ac:bb:76:59:a6:65:d0:45:9b:29:ad
         3c:87:59:15:52:21:e2:91:5c:ca:da:16:3e:b9:f7:fa
      Y:
         4d:84:a0:79:a4:02:d4:20:b4:01:e6:4c:9b:da:5e:6a
         4a:cd:b4:7e:c0:01:7e:8d:29:0c:f4:a6:d7:b3:07:a0
   Signature Algorithm: GOSTR341012-256
   Attributes:
      Extensions:
         Subject Signing Tool(not critical):
            GnuTLS
         Basic Constraints (critical):
            Certificate Authority (CA): FALSE
         Key Usage (critical):
            Digital signature.
Other Information:
   Public Key ID:
      sha1:c0e53bf1cc35f14dce4b7e05ee091c90f497dadf
      sha256:eb3dc1375ea60f165b51a9349b32a1a4eab1614e5d49fd02bdf66785095984ea
   Public Key PIN:
      pin-sha256:6z3BN16mDxZbUak0mzKhpOqxYU5dSf0CvfZnhQlZhOo=

Self signature: verified

-----BEGIN NEW CERTIFICATE REQUEST-----
MIICajCCAhcCAQAwggFrMSQwIgYDVQQDDBvQqNGD0YDQsCDQkdCw0LvQsNCz0LDQ
vdC+0LIxHTAbBgNVBAcMFNCzLiDQmtC+0LfQtdC70YzRgdC6MSwwKgYDVQQIDCPQ
nNC+0YHQutC+0LLRgdC60LDRjyDQvtCx0LvQsNGB0YLRjDELMAkGA1UEBhMCUlUx
SDBGBgNVBAkMP9CS0L7RgiDQvNC+0Y8g0LTQtdGA0LXQstC90Y8sINCy0L7RgiDQ
vNC+0Lkg0LTQvtC8INGA0L7QtNC90L7QuTEbMBkGA1UEBAwS0JHQsNC70LDQs9Cw
0L3QvtCyMTEwLwYDVQQqDCjRgdGL0L0g0LvQtdC50YLQtdC90LDQvdGC0LAg0KjQ
vNC40LTRgtCwMRowGAYIKoUDA4EDAQESDDEyMzQ1Njc4OTA5ODEWMBQGBSqFA2QD
EgsxMjM0NTY3ODkwOTEbMBkGCSqGSIb3DQEJARYMZ251dGxzQGFhLnJ1MF4wFwYI
KoUDBwEBAQEwCwYJKoUDBwECAQECA0MABED697k+FtrKXJHiIVIVWYc8rSmbRdBl
pll2u6xvclxjI6AHs9em9AwpjX4BwH60zUpqXtqbTOYBtCDUAqR5oIRNoEMwQQYJ
KoZIhvcNAQkOMTQwMjARBgUqhQNkbwQIDAZHbnVUTFMwDAYDVR0TAQH/BAIwADAP
BgNVHQ8BAf8EBQMDB4AAMAoGCCqFAwcBAQMCA0EARPHu9P2dPb2GrhQTeOBkmbA0
Fw5I0HDF1S5YI7g0jJmdz70rv80XpozmkNKpARN9yYQx9t82fUXUGqwJK9A4RA==
-----END NEW CERTIFICATE REQUEST-----

$ 
      
      





Mari simpan permintaan sertifikat di file request.pem, dan pergi bersamanya ke CA untuk mendapatkan sertifikat.

Demi keadilan, perlu dicatat bahwa utilitas certtool memiliki kemampuan hebat untuk menghasilkan tidak hanya permintaan sertifikat, tetapi juga sertifikat itu sendiri. Kemampuan ini sama sekali tidak kalah dengan kemampuan openssl atau nss.



Memperoleh, Melihat dan Memverifikasi Sertifikat



Untuk menerbitkan sertifikat, kami masih akan menggunakan utilitas CAFL63 :







Misalkan sertifikat yang diterbitkan disimpan dalam file certfromreq.pem. Bersama dengan sertifikat, pengguna, sebagai suatu peraturan, menerima sertifikat dari otoritas sertifikasi itu sendiri, mis. sertifikat, kunci privat yang menandatangani sertifikat yang diterima. Kehadiran sertifikat CA memungkinkan Anda untuk memeriksa sertifikat pengguna:

$certtool --verify --verify-profile normal   [--inder] --load-ca-certificate <   > --infile <   >
      
      





Misalnya, jika ada sertifikat pengguna yang disimpan di file certfromreq.pem, dan sertifikat CA di file rootca_12_256_TC26.pem, maka untuk memeriksanya, jalankan saja perintah berikut:



bash-5.1$ certtool --verify --verify-profile normal  --load-ca-certificate rootca_12_256_TC26.pem  --infile certfromreq.pem 
Loaded CAs (1 available)
        Subject: EMAIL=gnutls@aa.ru,SNILS=12345678909,INN=123456789098,givenName=  ,surName=,street=  \,    ,C=RU,ST= ,L=. ,CN= 
        Issuer: EMAIL=cafl63@mail.ru,OGRN=1234567890123,INN=001234567890,CN=  CAFL63,OU= ,O=  CAFL63,street=. \, . 4,L=. ,ST= ,C=RU
        Checked against: EMAIL=cafl63@mail.ru,OGRN=1234567890123,INN=001234567890,CN=  CAFL63,OU= ,O=  CAFL63,street=. \, . 4,L=. ,ST= ,C=RU
        Signature algorithm: GOSTR341012-256
        Output: Verified. The certificate is trusted. 

Chain verification output: Verified. The certificate is trusted. 

bash-5.1$
      
      





Untuk melihat sertifikat yang diterima, Anda perlu menggunakan tanda --certificate-info:



bash-5.1$ certtool --certificate-info --infile CertFromReqGnuTLS_2.pem 
      
      





Informasi Sertifikat X.509:

   Version: 3
   Serial Number (hex): 1022
   Issuer: EMAIL=cafl63@mail.ru,OGRN=1234567890123,INN=001234567890,CN=  CAFL63,OU= ,O=  CAFL63,street=. \, . 4,L=. ,ST= ,C=RU
   Validity:
      Not Before: Tue Apr 27 11:50:00 UTC 2021
      Not After: Thu Apr 28 11:50:00 UTC 2022
   Subject: EMAIL=gnutls@aa.ru,SNILS=12345678909,INN=123456789098,givenName=  ,surName=,street=  \,    ,C=RU,ST= ,L=. ,CN= 
   Subject Public Key Algorithm: GOST R 34.10-2012-256
   Algorithm Security Level: High (256 bits)
      Curve:   TC26-256-B
      Digest:  STREEBOG-256
      ParamSet: TC26-Z
      X:
         23:63:5c:72:6f:ac:bb:76:59:a6:65:d0:45:9b:29:ad
         3c:87:59:15:52:21:e2:91:5c:ca:da:16:3e:b9:f7:fa
      Y:
         4d:84:a0:79:a4:02:d4:20:b4:01:e6:4c:9b:da:5e:6a
         4a:cd:b4:7e:c0:01:7e:8d:29:0c:f4:a6:d7:b3:07:a0
   Extensions:
      Basic Constraints (critical):
         Certificate Authority (CA): FALSE
      Issuer Signing Tool(not critical):
         SignTool:  -CSP
         CATool:   CAFL63
         SignToolCert: № -124/3917   29  2020 .
         CAToolCert:   №
      Subject Signing Tool(not critical):
         GnuTLS
      Certificate Policies (not critical):
         1.2.643.100.113.1 (Russian security class KC1)
         1.2.643.100.113.2 (Russian security class KC2)
      Key Usage (not critical):
         Digital signature.
      Key Purpose (not critical):
         1.2.643.6.3.1.2.2
         TLS WWW Client.
         Email protection.
         1.3.6.1.4.1.311.20.2.2
         1.2.643.5.1.28.2
         1.2.643.5.1.28.3
         TLS WWW Client.
         Email protection.
      Subject Key Identifier (not critical):
         ddc80c1857a797dd540b70825e251c2180f585d5
      Authority Key Identifier (not critical):
         directoryName: EMAIL=cafl63@mail.ru,OGRN=1234567890123,INN=001234567890,CN=  CAFL63,OU= ,O=  CAFL63,street=. \, . 4,L=. ,ST= ,C=RU
         serial: 00c79588557040f04e
         70c016b99db59d8466316ea4a51ee0d1026b5cfe
      Subject Alternative Name (not critical):
         RFC822Name: gnutls@aa.ru
      Issuer Alternative Name (not critical):
      Authority Information Access (not critical):
         Access Method: 1.3.6.1.5.5.7.48.2 (id-ad-caIssuers)
         Access Location URI: http://museum.lissi-crypto.ru/docs/ucfz_63/CAFL63.crt
   Signature Algorithm: GOSTR341012-256
   Signature:
      0b:51:a3:d9:77:9f:9e:7d:91:e0:d8:4d:d9:82:a9:71
      91:be:82:ee:5a:6c:c6:79:af:34:1d:30:69:d1:ae:4f
      a5:79:18:6d:46:08:8c:44:65:6f:2c:24:74:8c:09:7f
      30:52:dc:65:9c:f9:b6:46:81:14:a9:83:2a:c0:80:d3
Other Information:
   Fingerprint:
      sha1:d53b007e3d1c3880cb7f92b7e29263cf9c5605c3
      sha256:14bbeeeaeb4219147048dae551eceb2e62de5d00571c6c0ee862161ca2260755
   Public Key ID:
      sha1:c0e53bf1cc35f14dce4b7e05ee091c90f497dadf
      sha256:eb3dc1375ea60f165b51a9349b32a1a4eab1614e5d49fd02bdf66785095984ea
   Public Key PIN:
      pin-sha256:6z3BN16mDxZbUak0mzKhpOqxYU5dSf0CvfZnhQlZhOo=

-----BEGIN CERTIFICATE-----
MIIHXTCCBwigAwIBAgICECIwDAYIKoUDBwEBAwIFADCCAVsxCzAJBgNVBAYTAlJV
MSwwKgYDVQQIDCPQnNC+0YHQutC+0LLRgdC60LDRjyDQvtCx0LvQsNGB0YLRjDEf
MB0GA1UEBwwW0LMuINCu0LHQuNC70LXQudC90YvQuTEoMCYGA1UECQwf0YPQuy4g
0JvQtdC90LjQvdGB0LrQsNGPLCDQtC4gNDElMCMGA1UECgwc0KLQtdGB0YLQvtCy
0YvQuSDQo9CmIENBRkw2MzEwMC4GA1UECwwn0KPQtNC+0YHRgtC+0LLQtdGA0Y/R
jtGI0LjQuSDQptC10L3RgtGAMSUwIwYDVQQDDBzQotC10YHRgtC+0LLRi9C5INCj
0KYgQ0FGTDYzMRowGAYIKoUDA4EDAQESDDAwMTIzNDU2Nzg5MDEYMBYGBSqFA2QB
Eg0xMjM0NTY3ODkwMTIzMR0wGwYJKoZIhvcNAQkBFg5jYWZsNjNAbWFpbC5ydTAe
Fw0yMTA0MjcxMTUwMDBaFw0yMjA0MjgxMTUwMDBaMIIBazEkMCIGA1UEAwwb0KjR
g9GA0LAg0JHQs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AMGCCsGAQUFBwMCBggrBgEFBQcD
BDAdBgNVHQ4EFgQU3cgMGFenl91UC3CCXiUcIYD1hdUwggGVBgNVHSMEggGMMIIB
iIAUcMAWuZ21nYRmMW6kpR7g0QJrXP6hggFjpIIBXzCCAVsxCzAJBgNVBAYTAlJV
MSwwKgYDVQQIDCPQnNC+0YHQutC+0LLRgdC60LDRjyDQvtCx0LvQsNGB0YLRjDEf
MB0GA1UEBwwW0LMuINCu0LHQuNC70LXQudC90YvQuTEoMCYGA1UECQwf0YPQuy4g
0JvQtdC90LjQvdGB0LrQsNGPLCDQtC4gNDElMCMGA1UECgwc0KLQtdGB0YLQvtCy
0YvQuSDQo9CmIENBRkw2MzEwMC4GA1UECwwn0KPQtNC+0YHRgtC+0LLQtdGA0Y/R
jtGI0LjQuSDQptC10L3RgtGAMSUwIwYDVQQDDBzQotC10YHRgtC+0LLRi9C5INCj
0KYgQ0FGTDYzMRowGAYIKoUDA4EDAQESDDAwMTIzNDU2Nzg5MDEYMBYGBSqFA2QB
Eg0xMjM0NTY3ODkwMTIzMR0wGwYJKoZIhvcNAQkBFg5jYWZsNjNAbWFpbC5ydYIJ
AMeViFVwQPBOMBcGA1UdEQQQMA6BDGdudXRsc0BhYS5ydTAJBgNVHRIEAjAAMFEG
CCsGAQUFBwEBBEUwQzBBBggrBgEFBQcwAoY1aHR0cDovL211c2V1bS5saXNzaS1j
cnlwdG8ucnUvZG9jcy91Y2Z6XzYzL0NBRkw2My5jcnQwDAYIKoUDBwEBAwIFAANB
AAtRo9l3n559keDYTdmCqXGRvoLuWmzGea80HTBp0a5PpXkYbUYIjERlbywkdIwJ
fzBS3GWc+bZGgRSpgyrAgNM=
-----END CERTIFICATE-----

      
      



bash-5.1$
      
      





Dan jika alih-alih flag --certificate-info kita menentukan flag --pubkey - info, maka kita tidak hanya akan menerima informasi tentang kunci publik, tetapi juga struktur asn1-nya:

bash-5.1$ certtool --pubkey-info  --infile CertFromReqGnuTLS_2.pem |expand -3
Public Key Information:
   Public Key Algorithm: GOST R 34.10-2012-256
   Algorithm Security Level: High (256 bits)
      Curve:   TC26-256-B
      Digest:  STREEBOG-256
      ParamSet: TC26-Z
      X:
         23:63:5c:72:6f:ac:bb:76:59:a6:65:d0:45:9b:29:ad
         3c:87:59:15:52:21:e2:91:5c:ca:da:16:3e:b9:f7:fa
      Y:
         4d:84:a0:79:a4:02:d4:20:b4:01:e6:4c:9b:da:5e:6a
         4a:cd:b4:7e:c0:01:7e:8d:29:0c:f4:a6:d7:b3:07:a0
Public Key Usage:
   Digital signature.
   Key encipherment.
   Key agreement.
Public Key ID:
   sha1:c0e53bf1cc35f14dce4b7e05ee091c90f497dadf
   sha256:eb3dc1375ea60f165b51a9349b32a1a4eab1614e5d49fd02bdf66785095984ea
Public Key PIN:
   pin-sha256:6z3BN16mDxZbUak0mzKhpOqxYU5dSf0CvfZnhQlZhOo=
#ASN1-    PEM-
-----BEGIN PUBLIC KEY-----
MF4wFwYIKoUDBwEBAQEwCwYJKoUDBwECAQECA0MABED697k+FtrKXJHiIVIVWYc8
rSmbRdBlpll2u6xvclxjI6AHs9em9AwpjX4BwH60zUpqXtqbTOYBtCDUAqR5oIRN
-----END PUBLIC KEY-----
bash-5.1$
      
      





Sekarang setelah Anda memiliki sertifikat dan kunci pribadinya, serta sertifikat CA, Anda dapat menggabungkan semuanya dalam satu wadah PKCS # 12 yang aman.



Bekerja dengan wadah PKCS # 12 yang aman



Bekerja dengan kriptografi Rusia, saat membuat wadah PKCS # 12 yang aman, tentu saja, dipandu oleh Rekomendasi TK-26 , yang menjelaskan pembentukan wadah kunci transportasi untuk kunci yang dibuat sesuai dengan GOST R 34.10.



Berdasarkan ini, perintah untuk membuat container PKCS # 12 akan terlihat seperti ini:



certtool --to-p12  --pkcs-cipher=gost28147-tc26z --hash streebog-512 [--inder] [--ask-pass | --password <  >]  [--p12-name "<friendly name>"]  --load-certificate <  > --load-privkey <    >  --load-ca-certificate <   > [--outder] [--outfile <   >]

      
      





Perhatikan bahwa jika opsi --password dan / atau --p12-name tidak ditentukan, opsi tersebut akan diminta pada baris perintah.



Mari buat wadah PKCS # 12:



$ certtool --to-p12  --pkcs-cipher=gost28147-tc26z --hash streebog-512  --load-certificate certUser.pem  --load-privkey privkeyUser.pem  --load-ca-certificate certCA.pem --p12-name "TectP12GnuTLS" --password "01234567"        
Generating a PKCS #12 structure...
Loading private key list...
Loaded 1 private keys.
      
      



Container PKCS # 12 dalam format PEM
-----BEGIN PKCS12-----

MIIPfgIBAzCCDxcGCSqGSIb3DQEHAaCCDwgEgg8EMIIPADCCCGsGCSqGSIb3DQEH

BqCCCFwwgghYAgEAMIIIUQYJKoZIhvcNAQcBMFwGCSqGSIb3DQEFDTBPMCwGCSqG

SIb3DQEFDDAfBA3JZi1Ugltt8zUsV+TvAgIUzDAKBggqhQMHAQEEAjAfBgYqhQMC

AhUwFQQIgs6KxHT8B3oGCSqFAwcBAgUBAYCCB+SoAUfogfTmJvDWXQfUzOklsci5

SO6niZFbnPnW6Iey0VY3tUCu+vMF301jjjDvZj/4Y3S4qwHXLoLROxU3kQ8o97pY

GVlryw3Eih9wNtVfHa2nCcMYRR5bAjuZ9zYZZpSamaAqml9VyAQJJoBiPEkJu7q+

P1MHwx6SbmW6Pui9Ebi3dtMBr7bYgly4H1upve4cRHJ00WZ403G8eLtLugl3MLK3

f3MI7DWnd+9AV5MvI7Acd85AVYRy2GHlfgWAtUbGS65nzc+DzGIMQuupiQ4ONV4e

9Pl6HEo8Q2UGrgD924ijBE7eQcePXn2L4AVI0c7n1OODZ9rDEpps5KlCdF0gN36Y

AkGtHptjie48zHED8VfQ1JzwGpROWfi+2Tit7Xz03hXihnDIjui4jT3wNUh43JgS

G/UmoWOMDnGbYA9e3g802XJfBx8uo3szoRMq9B6jJwgJ1KDsPF2Q93OKUEl1LTTQ

zQF5EGcQjPkiCr92kNGJXHQGDjWmUDAUiGID6eI38tFvudPf7UGiOVnazKRYNXfO

ggKGA8ojQzTGZCNHTkUzZgH4yvHX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pJfPz+NcffGkBvDjm1iKAmI4

MVAwIwYJKoZIhvcNAQkVMRYEFMDlO/HMNfFNzkt+Be4JHJD0l9rfMCkGCSqGSIb3

DQEJFDEcHhoAVABlAHMAdABQADEAMgBHAG4AdQBUAEwAUzBeME4wCgYIKoUDBwEB

AgMEQBUe/McVL6+rN3mX4cF3gXCmvHqSr8moF/JOzOUkCC6y2alb3+sbbHgeWVTd

Purx3hqM5JQfaVrBJRHPJYBb32sECPJ73kLKv7aNAgIoAA==

-----END PKCS12-----
bash-5.1$
      
      





Perlu dicatat bahwa saat ini wadah aman PKCS # 12 sangat populer.

Kontainer PKCS # 12 yang dibuat oleh utilitas certtool telah berhasil diurai oleh utilitas openssl dengan dukungan GOST. Setelah itu, kami memutuskan untuk menggunakan utilitas cryptoarmpkcs , yang memungkinkan Anda mengekstrak sertifikat dan kunci pribadinya dari penampung PKCS # 12 dan menginstalnya pada token PKCS # 11, serta, menggunakan penampung itu sendiri, menandatangani dokumen.



Dan kemudian saya harus menghadapi kejutan yang tidak menyenangkan: Yang







mengejutkan, saat membuat container PKCS # 12, GnuTLS tidak memperhitungkan persyaratan TK-26 terbaru, yaitu:



Integritas TCC dipastikan menggunakan algoritme HMAC_GOSTR3411_2012_512 sesuai dengan R 50.1.113— 2016.


Utilitas certtool menggunakan algoritma HMAC_GOSTR3411_2012_256, yang di-hardcode ke dalam kode perpustakaan. Tetapi ini adalah bug yang mudah diperbaiki. Untuk melakukan ini, cukup dengan mengubah baris dalam fungsi _gnutls_pkcs_generate_key (file ~ / gnutls-xxx / lib / x509 / pkcs7-crypt.c)



kdf_param->mac = GNUTLS_MAC_STREEBOG_256;
      
      



per baris

kdf_param->mac = GNUTLS_MAC_STREEBOG_512;
      
      





Setelah melakukan perubahan ini, semuanya jatuh ke tempatnya dan container PKCS # 12 dari GnuTLS diadopsi oleh utilitas cryptoarmpkcs:







Contoh container PKCS # 12 di atas (----- BEGIN PKCS12 ----- ... - ---- AKHIR PKCS12- ----) dibentuk dengan mempertimbangkan persyaratan TC-26.



Jadi, memiliki wadah PKCS # 12 dan utilitas cryptoarmpkcs, Anda dapat menghasilkan berbagai jenis tanda tangan untuk dokumen (lihat tangkapan layar). Tetapi sekarang kami tertarik pada pembentukan tanda tangan elektronik menggunakan utilitas certtool.



Tanda tangan elektronik PKCS # 7



Perintah untuk menghasilkan tanda tangan elektronik terlihat seperti ini:



$certtool --p7-sign [--p7-time] [--inder] --load-privkey <   > --load-certificate <  > --infile <  > [--outder] [--outfile <  >]
      
      





Hanya opsi --p7-time yang memerlukan klarifikasi, yang keberadaannya menginstruksikan untuk menyertakan dalam tanda tangan itu sendiri (struktur PKCS # 7) waktu pembuatan tanda tangan elektronik.



Ngomong-ngomong, untuk menguji pembentukan tanda tangan elektronik, sertifikat dan kunci pribadinya dapat diambil dari wadah PKCS # 12 yang diberikan di bagian sebelumnya:



$certtool --p12-info --no-text --infile <,     PKCS#12>
      
      





Jika sertifikat kunci pribadi pengguna disimpan di file privkey.pem, dan sertifikat pengguna di file usercert.pem, maka menandatangani dokumen dari file doc.txt dengan tanda tangan yang disimpan di file signdoc.sig akan terlihat seperti ini :



$certtool --p7-sign --loadcertificate usercert.pem --load-privkey privkey.pem --infile doc.txt --outfile signdoc.sig
Enter password
$
      
      





Jika tanda tangan dilampirkan (dan secara default itu yang dibuat), maka Anda dapat mengekstrak dokumen yang ditandatangani dengan perintah berikut:



$certtool --p7-info --p7-show-data [--inder] --infile <  >

      
      





Untuk melihat informasi tentang tanda tangan elektronik, gunakan tanda --p7-info:



$certtool --p7-info [--inder] 
      
      





Untuk memverifikasi tanda tangan elektronik itu sendiri, diperlukan sertifikat penanda tangan:



$certtool --p7-verify [--inder] --load-certificate <   > --infile <   >

      
      





Ya, opsi --p7-detached-sign digunakan untuk membuat tanda tangan terpisah



Kata Penutup



Saya tidak bermaksud memberikan penjelasan lengkap tentang utilitas certtool, apalagi menulis dokumentasi GnuTLS. Penulis melakukannya dengan baik tanpa saya.



Tujuannya adalah untuk menunjukkan bahwa ada alat seperti GnuTLS dan dapat digunakan bersama dengan OpenSSL atau GCrypt untuk bekerja dengan PKI berdasarkan kriptografi Rusia. Seberapa besar kemungkinannya bagi pembaca untuk menilai.



All Articles