diff --git a/README.md b/README.md index 747c3ac..29b24ba 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ fcgi_thread_pool_size = 1 *\# значение по умолчанию: 1* - В секции **\[sign\]** задать настройки модуля подписания: location = /sign *\# значение по умолчанию: /sign, должно совпадать со значением в nginx.conf* signer_subject = signer@example.ru *\# email, ИНН, СНИЛС или любая другая строка из свойства контейнера «Субъект»* -pin = \*\*\*\* *\# пароль от контейнера* +sign_cert_password = \*\*\*\* *\# пароль от контейнера* - В секции **\[verify\]** задать настройки проверки подписи маркера доступа: location = /verify *\# значение по умолчанию: /verify, должно совпадать со значением в nginx.conf* diff --git a/conf/ervu-sign-module.conf.example b/conf/ervu-sign-module.conf.example index f50d665..50da565 100644 --- a/conf/ervu-sign-module.conf.example +++ b/conf/ervu-sign-module.conf.example @@ -10,7 +10,7 @@ fcgi_listen_host = 127.0.0.1 [sign] #location = /sign signer_subject = signer@example.ru -pin = **** +sign_cert_password = **** [verify] #location = /verify diff --git a/src/modules/service_sign.c b/src/modules/service_sign.c index 429c142..d0cc461 100644 --- a/src/modules/service_sign.c +++ b/src/modules/service_sign.c @@ -7,7 +7,7 @@ #define SIGN_CONF_SECTION "sign" #define SIGN_CONF_KEY_LOCATION "location" #define SIGN_CONF_KEY_SIGNER "signer_subject" -#define SIGN_CONF_KEY_PIN "pin" +#define SIGN_CONF_KEY_PASSWORD "sign_cert_password" #define FCGI_OK_RESPONSE_FORMAT \ "Content-type: text/plain" CRLF\ @@ -66,8 +66,8 @@ sign_conf_load(sign_conf_t *conf, const conf_file_context_t conf_file) }, { SIGN_CONF_SECTION, - SIGN_CONF_KEY_PIN, - &(conf->pin), + SIGN_CONF_KEY_PASSWORD, + &(conf->sign_cert_password), CONF_FILE_VALUE_STRT, CONF_FILE_VALUE_PSWD, NULL @@ -94,10 +94,10 @@ sign_conf_clear(sign_conf_t *conf) if (conf == NULL) return; - if (conf->pin.data != 0) { - explicit_bzero(conf->pin.data, conf->pin.len); + if (conf->sign_cert_password.data != 0) { + explicit_bzero(conf->sign_cert_password.data, conf->sign_cert_password.len); } - str_t_clear(&conf->pin); + str_t_clear(&conf->sign_cert_password); str_t_clear(&conf->location); free(conf->signer); @@ -118,7 +118,7 @@ sign_service_create(const sign_conf_t *conf) hsign->conf = conf; - cryptopro_context_set(&hsign->cryptopro_ctx, conf->signer, &conf->pin); + cryptopro_context_set(&hsign->cryptopro_ctx, conf->signer, &conf->sign_cert_password); LOG_TRACE("sign_service_create exit"); return (HSign)hsign; diff --git a/src/modules/service_sign.h b/src/modules/service_sign.h index 8289199..5bc4546 100644 --- a/src/modules/service_sign.h +++ b/src/modules/service_sign.h @@ -12,7 +12,7 @@ typedef struct sign_conf_s { str_t location; char *signer; /* субъект контейнера */ - str_t pin; /* pin-код от контейнера */ + str_t sign_cert_password; /* пароль от контейнера */ } sign_conf_t; diff --git a/src/utils/cryptopro.c b/src/utils/cryptopro.c index 1a8b853..fc35ca2 100644 --- a/src/utils/cryptopro.c +++ b/src/utils/cryptopro.c @@ -16,7 +16,7 @@ static HCERTSTORE cert_open_store(); static PCCERT_CONTEXT get_signer_cert(const cryptopro_context_t *ctx, HCERTSTORE hStoreHandle); -static int set_pin(PCCERT_CONTEXT pSignerCert, const str_t *pin); +static int set_password(PCCERT_CONTEXT cert_ctx, const str_t *password); bool cryptopro_init(const char* cp_file) @@ -45,7 +45,7 @@ cryptopro_sign(const cryptopro_context_t *ctx, const str_t *data, /*out*/ str_t assert(ctx != NULL); assert(ctx->signer != NULL); - assert(ctx->pin != NULL); + assert(ctx->password != NULL); assert(data != NULL && !str_t_is_null(*data)); assert(sign != NULL); @@ -211,45 +211,43 @@ cert_open_store() static PCCERT_CONTEXT get_signer_cert(const cryptopro_context_t *ctx, HCERTSTORE hStoreHandle) { - PCCERT_CONTEXT pSignerCert; - - pSignerCert = cp_function_list.CertFindCertificateInStore(hStoreHandle, + PCCERT_CONTEXT cert_ctx = cp_function_list.CertFindCertificateInStore(hStoreHandle, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR, ctx->signer, NULL); - if (pSignerCert == NULL) { + if (cert_ctx == NULL) { LOG_ERROR("Could not find certificate in store"); goto error; } - if (set_pin(pSignerCert, ctx->pin)) { + if (set_password(cert_ctx, ctx->password)) { goto error; } LOG_DEBUG("The signer's certificate was found"); - return pSignerCert; + return cert_ctx; error: - if (pSignerCert) { - cp_function_list.CertFreeCertificateContext(pSignerCert); + if (cert_ctx) { + cp_function_list.CertFreeCertificateContext(cert_ctx); } LOG_ERROR("get_signer_cert exit with error"); return NULL; } static int -set_pin(PCCERT_CONTEXT pSignerCert, const str_t *pin) +set_password(PCCERT_CONTEXT cert_ctx, const str_t *password) { DWORD dwSize; if (!cp_function_list.CertGetCertificateContextProperty( - pSignerCert, + cert_ctx, CERT_KEY_PROV_INFO_PROP_ID, NULL, &dwSize)) { LOG_ERROR("Error getting key property"); - LOG_ERROR("set_pin exit with error. Last error code: 0x%08x", cp_function_list.GetLastError()); + LOG_ERROR("set_password exit with error. Last error code: 0x%08x", cp_function_list.GetLastError()); return -1; } @@ -257,7 +255,7 @@ set_pin(PCCERT_CONTEXT pSignerCert, const str_t *pin) CRYPT_KEY_PROV_INFO* pKeyInfo = (CRYPT_KEY_PROV_INFO*) pKeyInfoBuffer; if (!cp_function_list.CertGetCertificateContextProperty( - pSignerCert, + cert_ctx, CERT_KEY_PROV_INFO_PROP_ID, pKeyInfo, &dwSize)){ @@ -272,14 +270,14 @@ set_pin(PCCERT_CONTEXT pSignerCert, const str_t *pin) memset(&keyProvParam, 0, sizeof(CRYPT_KEY_PROV_PARAM)); keyProvParam.dwFlags = 0; keyProvParam.dwParam = keyType; - keyProvParam.cbData = (DWORD)(pin->len + 1); - keyProvParam.pbData = (BYTE*) pin->data; + keyProvParam.cbData = (DWORD)(password->len + 1); + keyProvParam.pbData = (BYTE*) password->data; pKeyInfo->cProvParam = 1; pKeyInfo->rgProvParam = &keyProvParam; if (!cp_function_list.CertSetCertificateContextProperty( - pSignerCert, + cert_ctx, CERT_KEY_PROV_INFO_PROP_ID, 0, pKeyInfo)) { @@ -290,7 +288,7 @@ set_pin(PCCERT_CONTEXT pSignerCert, const str_t *pin) return 0; error: - LOG_ERROR("set_pin exit with error. Last error code: 0x%08x", cp_function_list.GetLastError()); + LOG_ERROR("set_password exit with error. Last error code: 0x%08x", cp_function_list.GetLastError()); return -1; } diff --git a/src/utils/cryptopro.h b/src/utils/cryptopro.h index b76dbf1..1f30c85 100644 --- a/src/utils/cryptopro.h +++ b/src/utils/cryptopro.h @@ -9,17 +9,17 @@ typedef struct cryptopro_context_s { const char *signer; - const str_t *pin; + const str_t *password; } cryptopro_context_t; static inline void -cryptopro_context_set(cryptopro_context_t *ctx, const char *signer, const str_t *pin) +cryptopro_context_set(cryptopro_context_t *ctx, const char *signer, const str_t *password) { assert(ctx != NULL); ctx->signer = signer; - ctx->pin = pin; + ctx->password = password; } bool cryptopro_init(const char* cp_file); diff --git a/Инструкция по установке.md b/Инструкция по установке.md index 2c21942..160acf0 100644 --- a/Инструкция по установке.md +++ b/Инструкция по установке.md @@ -49,7 +49,7 @@ chown -R ervu:ervu /var/opt/cprocsp/keys/ervu/key_cont.000/ - Поле "Субъект": любая подстрока из этого поля является signer_subject (нужно будет указать в конфигурационном файле модуля подписания) - Поле "Ссылка на ключ": убедиться, что значение равно "Есть" (иначе необходимо проверить выполнение предыдущих шагов) -4. (опционально) Сделать тестовую подпись с помощью установленного контейнера и полученных значений \ и \: +4. (опционально) Сделать тестовую подпись с помощью установленного контейнера и полученных значений \ и \: ``` bash touch test.txt /opt/cprocsp/bin/amd64/cryptcp -signf -dn ./test.txt