Certreq

Certreq can be used to request certificates from a certification authority (CA), to retrieve a response to a previous request from a CA, to create a new request from an .inf file, to accept and install a response to a request, to construct a cross-certification or qualified subordination request from an existing CA certificate or request, and to sign a cross-certification or qualified subordination request.

Warning

Earlier versions of certreq may not provide all of the options that are described in this document. You can see all the options that a specific version of certreq provides by running the commands shown in the Syntax notations section.

You must specify a certificate request file when using the –submit option. If this parameter is omitted, a common File Open window is displayed where you can select the appropriate certificate request file.

You can use these examples as a starting point to build your certificate submit request:

If you don’t specify the CAComputerName or CAName in -config CAComputerName\CANamea dialog box appears and displays a list of all CAs that are available.

If you use -config - instead of -config CAComputerName\CAName, the operation is processed using the default CA.

You can use certreq -retrieve RequestID to retrieve the certificate after the CA has actually issued it. The RequestIDPKC can be a decimal or hex with 0x prefix and it can be a certificate serial number with no 0x prefix. You can also use it to retrieve any certificate that has ever been issued by the CA, including revoked or expired certificates, without regard to whether the certificate's request was ever in the pending state.

If you submit a request to the CA, the policy module of the CA might leave the request in a pending state and return the RequestID to the Certreq caller for display. Eventually, the CA's administrator will issue the certificate or deny the request.

Since the INF file allows for a rich set of parameters and options to be specified, it is difficult to define a default template that administrators should use for all purposes. Therefore, this section describes all the options to enable you to create an INF file tailored to your specific needs. The following key words are used to describe the INF file structure.

A section is an area in the INF file that covers a logical group of keys. A section always appears in brackets in the INF file.

[NewRequest]
; At least one value must be set in this section
Subject = "CN=W2K8-BO-DC.contoso2.com"

The following are some of the possible sections that may be added to the INF file:

[NewRequest]

This section is mandatory for an INF file that acts as a template for a new certificate request. This section requires at least one key with a value.

Key

Definition

Value

Example

Subject

Several applications rely on the subject information in a certificate. Thus, it is recommended that a value for this key be specified. If the subject is not set here, it is recommended that a subject name be included as part of the subject alternative name certificate extension.

If this attribute is set to TRUE, the private key can be exported with the certificate. To ensure a high level of security, private keys should not be exportable; however, in some cases, it might be required to make the private key exportable if several computers or users must share the same private key.

Not all public key sizes and algorithms will work with all hash algorithms. Tamehe specified CSP must also support the specified hash algorithm. To see the list of supported hash algorithms, you can run the command certutil -oid 1 | findstr pwszCNGAlgid | findstr /v CryptOIDInfo

It is not recommended to set this parameter for new requests where new key material is generated. The key container is automatically generated and maintained by the system. For requests where the existing key material should be used, this value can be set to the key-container name of the existing key. Use the certutil –key command to display the list of available key containers for the machine context. Use the certutil –key –user command for the current user’s context.

Random string value

Tip

You should use double quotes around any INF key value that has blanks or special characters to avoid potential INF parsing issues.

KeyContainer = {C347BD28-7F69-4090-AA16-BC58CF4D749C}

KeyLength

Defines the length of the public and private key. The key length has an impact on the security level of the certificate. Greater key length usually provides a higher security level; however, some applications may have limitations regarding the key length.

Any valid key length that is supported by the cryptographic service provider.

KeyLength = 2048

KeySpec

Determines if the key can be used for signatures, for Exchange (encryption), or for both.

AT_NONE, AT_SIGNATURE, AT_KEYEXCHANGE

KeySpec = AT_KEYEXCHANGE

KeyUsage

Defines what the certificate key should be used for.

CERT_DIGITAL_SIGNATURE_KEY_USAGE -- 80 (128)

Tip

The values shown are hexadecimal (decimal) values for each bit definition. Older syntax can also be used: a single hexadecimal value with multiple bits set, instead of the symbolic representation. For example, KeyUsage = 0xa0.

This key is important when you need to create certificates that are owned by the machine and not a user. The key material that is generated is maintained in the security context of the security principal (user or computer account) that has created the request. When an administrator creates a certificate request on behalf of a computer, the key material must be created in the machine’s security context and not the administrator’s security context. Otherwise, the machine could not access its private key since it would be in the administrator’s security context.

true, false

MachineKeySet = true

Tip

The default is false.

NotBefore

Specifies a date or date and time before which the request cannot be issued. NotBefore can be used with ValidityPeriod and ValidityPeriodUnits.

date or date and time

NotBefore = "7/24/2012 10:31 AM"

Tip

NotBefore and NotAfter are for RequestType=cert only.Date parsing attempts to be locale-sensitive.Using month names will disambiguate and should work in every locale.

NotAfter

Specifies a date or date and time after which the request cannot be issued. NotAfter cannot be used with ValidityPeriod or ValidityPeriodUnits.

date or date and time

NotAfter = "9/23/2014 10:31 AM"

Tip

NotBefore and NotAfter are for RequestType=cert only.Date parsing attempts to be locale-sensitive.Using month names will disambiguate and should work in every locale.

PrivateKeyArchive

The PrivateKeyArchive setting works only if the corresponding RequestType is set to "CMC" because only the Certificate Management Messages over CMS (CMC) request format allows for securely transferring the requester’s private key to the CA for key archival.

true, false

PrivateKeyArchive = True

EncryptionAlgorithm

The encryption algorithm to use.

Possible options vary, depending on the operating system version and the set of installed cryptographic providers.To see the list of available algorithms, run the commandcertutil -oid 2 | findstr pwszCNGAlgidThe specified CSP used must also support the specified symmetric encryption algorithm and length.

EncryptionAlgorithm = 3des

EncryptionLength

Length of encryption algorithm to use.

Any length allowed by the specified EncryptionAlgorithm.

EncryptionLength = 128

ProviderName

The provider name is the display name of the CSP..

If you do not know the provider name of the CSP you are using, run certutil –csplist from a command line. The command will display the names of all CSPs that are available on the local system

ProviderName = "Microsoft RSA SChannel Cryptographic Provider"

ProviderType

The provider type is used to select specific providers based on specific algorithm capability such as "RSA Full".

If you do not know the provider type of the CSP you are using, run certutil –csplist from a command-line prompt. The command will display the provider type of all CSPs that are available on the local system.

ProviderType = 1

RenewalCert

If you need to renew a certificate that exists on the system where the certificate request is generated, you must specify its certificate hash as the value for this key.

The certificate hash of any certificate that is available at the computer where the certificate request is created. If you do not know the certificate hash, use the Certificates MMC Snap-In and look at the certificate that should be renewed. Open the certificate properties and see the "Thumbprint" attribute of the certificate. Certificate renewal requires either a PKCS#7 or a CMC request format.

RenewalCert = 4EDF274BD2919C6E9EC6A522F0F3B153E9B1582D

RequesterName

Note

This makes the request to enroll on behalf of another user request.The request must also be signed with an Enrollment Agent certificate, or the CA will reject the request. Use the -cert option to specify the enrollment agent certificate.

The requester name can be specified for certificate requests if the RequestType is set to PKCS#7 or CMC. If the RequestType is set to PKCS#10, this key will be ignored. The Requestername can only be set as part of the request. You cannot manipulate the Requestername in a pending request.

Domain\User

Requestername = "Contoso\BSmith"

RequestType

Determines the standard that is used to generate and send the certificate request.

PKCS10 -- 1

PKCS7 -- 2

CMC -- 3

Cert -- 4

Tip

This option indicates a self-signed or self-issued certificate. It does not generate a request, but rather a new certificate and then installs the certificate.Self-signed is the default.Specify a signing cert by using the –cert option to create a self-issued certificate that is not self-signed.

RequestType = CMC

SecurityDescriptor

Tip

This is relevant only for machine context non-smart card keys.

Contain the security information associated with securable objects. For most securable objects, you can specify an object's security descriptor in the function call that creates the object.

By default, this option allows the CSP access to the interactive user desktop and request information such as a smart card PIN from the user. If this key is set to TRUE, the CSP must not interact with the desktop and will be blocked from displaying any user interface to the user.

true, false

Silent = true

SMIME

If this parameter is set to TRUE, an extension with the object identifier value 1.2.840.113549.1.9.15 is added to the request. The number of object identifiers depends on the on the operating system version installed and CSP capability, which refer to symmetric encryption algorithms that may be used by Secure Multipurpose Internet Mail Extensions (S/MIME) applications such as Outlook.

true, false

SMIME = true

UseExistingKeySet

This parameter is used to specify that an existing key pair should be used in building a certificate request. If this key is set to TRUE, you must also specify a value for the RenewalCert key or the KeyContainer name. You must not set the Exportable key because you cannot change the properties of an existing key. In this case, no key material is generated when the certificate request is built.

true, false

UseExistingKeySet = true

KeyProtection

Specifies a value that indicates how a private key is protected before use.

XCN_NCRYPT_UI_NO_PROTCTION_FLAG -- 0

XCN_NCRYPT_UI_PROTECT_KEY_FLAG -- 1

XCN_NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG -- 2

KeyProtection = NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG

SuppressDefaults

Specifies a Boolean value that indicates whether the default extensions and attributes are included in the request. The defaults are represented by their object identifiers (OIDs).

true, false

SuppressDefaults = true

FriendlyName

A friendly name for the new certificate.

Text

FriendlyName = "Server1"

ValidityPeriodUnits

Note

This is used only when the request type=cert.

Specifies a number of units that is to be used with ValidityPeriod.

Numeric

ValidityPeriodUnits = 3

ValidityPeriod

Note

This is used only when the request type=cert.

VValidityPeriod must be an US English plural time period.

Years, Months, Weeks, Days, Hours, Minutes, Seconds

ValidityPeriod = Years

[Extensions]

This section is optional.

Extension OID

Definition

Value

Example

2.5.29.17

2.5.29.17 = "{text}"

_continue_

_continue_ = "UPN=User@Domain.com&"

_continue_

_continue_ = "EMail=User@Domain.com&"

_continue_

_continue_ = "DNS=host.domain.com&"

_continue_

_continue_ = "DirectoryName=CN=Name,DC=Domain,DC=com&"

_continue_

_continue_ = "URL=http://host.domain.com/default.html&"

_continue_

_continue_ = "IPAddress=10.0.0.1&"

_continue_

_continue_ = "RegisteredId=1.2.3.4.5&"

_continue_

_continue_ = "1.2.3.4.6.1={utf8}String&"

_continue_

_continue_ = "1.2.3.4.6.2={octet}AAECAwQFBgc=&"

_continue_

_continue_ = "1.2.3.4.6.2={octet}{hex}00 01 02 03 04 05 06 07&"

_continue_

_continue_ = "1.2.3.4.6.3={asn}BAgAAQIDBAUGBw==&"

_continue_

_continue_ = "1.2.3.4.6.3={hex}04 08 00 01 02 03 04 05 06 07"

2.5.29.37

2.5.29.37="{text}"

_continue_

_continue_ = "1.3.6.1.5.5.7.

_continue_

_continue_ = "1.3.6.1.5.5.7.3.1"

2.5.29.19

"{text}ca=0pathlength=3"

Critical

Critical=2.5.29.19

KeySpec

AT_NONE -- 0

AT_SIGNATURE -- 2

AT_KEYEXCHANGE -- 1

RequestType

PKCS10 -- 1

PKCS7 -- 2

CMC -- 3

Cert -- 4

KeyUsage

CERT_DIGITAL_SIGNATURE_KEY_USAGE -- 80 (128)

CERT_NON_REPUDIATION_KEY_USAGE -- 40 (64)

CERT_KEY_ENCIPHERMENT_KEY_USAGE -- 20 (32)

CERT_DATA_ENCIPHERMENT_KEY_USAGE -- 10 (16)

CERT_KEY_AGREEMENT_KEY_USAGE -- 8

CERT_KEY_CERT_SIGN_KEY_USAGE -- 4

CERT_OFFLINE_CRL_SIGN_KEY_USAGE -- 2

CERT_CRL_SIGN_KEY_USAGE -- 2

CERT_ENCIPHER_ONLY_KEY_USAGE -- 1

CERT_DECIPHER_ONLY_KEY_USAGE -- 8000 (32768)

KeyUsageProperty

NCRYPT_ALLOW_DECRYPT_FLAG -- 1

NCRYPT_ALLOW_SIGNING_FLAG -- 2

NCRYPT_ALLOW_KEY_AGREEMENT_FLAG -- 4

NCRYPT_ALLOW_ALL_USAGES -- ffffff (16777215)

KeyProtection

NCRYPT_UI_NO_PROTECTION_FLAG -- 0

NCRYPT_UI_PROTECT_KEY_FLAG -- 1

NCRYPT_UI_FORCE_HIGH_PROTECTION_FLAG -- 2

SubjectNameFlags

template

CT_FLAG_SUBJECT_REQUIRE_COMMON_NAME -- 40000000 (1073741824)

CT_FLAG_SUBJECT_REQUIRE_DIRECTORY_PATH -- 80000000 (2147483648)

CT_FLAG_SUBJECT_REQUIRE_DNS_AS_CN -- 10000000 (268435456)

CT_FLAG_SUBJECT_REQUIRE_EMAIL -- 20000000 (536870912)

CT_FLAG_OLD_CERT_SUPPLIES_SUBJECT_AND_ALT_NAME -- 8

CT_FLAG_SUBJECT_ALT_REQUIRE_DIRECTORY_GUID -- 1000000 (16777216)

CT_FLAG_SUBJECT_ALT_REQUIRE_DNS -- 8000000 (134217728)

CT_FLAG_SUBJECT_ALT_REQUIRE_DOMAIN_DNS -- 400000 (4194304)

CT_FLAG_SUBJECT_ALT_REQUIRE_EMAIL -- 4000000 (67108864)

CT_FLAG_SUBJECT_ALT_REQUIRE_SPN -- 800000 (8388608)

CT_FLAG_SUBJECT_ALT_REQUIRE_UPN -- 2000000 (33554432)

X500NameFlags

CERT_NAME_STR_NONE -- 0

CERT_OID_NAME_STR -- 2

CERT_X500_NAME_STR -- 3

CERT_NAME_STR_SEMICOLON_FLAG -- 40000000 (1073741824)

CERT_NAME_STR_NO_PLUS_FLAG -- 20000000 (536870912)

CERT_NAME_STR_NO_QUOTING_FLAG -- 10000000 (268435456)

CERT_NAME_STR_CRLF_FLAG -- 8000000 (134217728)

CERT_NAME_STR_COMMA_FLAG -- 4000000 (67108864)

CERT_NAME_STR_REVERSE_FLAG -- 2000000 (33554432)

CERT_NAME_STR_FORWARD_FLAG -- 1000000 (16777216)

CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG -- 10000 (65536)

CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG -- 20000 (131072)

CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG -- 40000 (262144)

CERT_NAME_STR_FORCE_UTF8_DIR_STR_FLAG -- 80000 (524288)

CERT_NAME_STR_DISABLE_UTF8_DIR_STR_FLAG -- 100000 (1048576)

CERT_NAME_STR_ENABLE_PUNYCODE_FLAG -- 200000 (2097152)

Note

SubjectNameFlags allows the INF file to specify which Subject and SubjectAltName extension fields should be auto-populated by certreq based on the current user or current machine properties: DNS name, UPN, and so on. Using the literal “template” means the template name flags are used instead. This allows a single INF file to be used in multiple contexts to generate requests with context-specific subject information.

X500NameFlags specifies the flags to be passed directly to CertStrToName API when the Subject INF keys value is converted to an ASN.1 encoded Distinguished Name.

To request a certificate based using certreq -new use the steps from the example below:

Warning

The content for this topic is based on the default settings for Windows Server 2008 AD CS; for example, setting the key length to 2048, selecting Microsoft Software Key Storage Provider as the CSP, and using Secure Hash Algorithm 1 (SHA1). Evaluate these selections against the requirements of your company’s security policy.

To create a Policy File (.inf) copy and save the example below in Notepad and save as RequestConfig.inf:

The following example demonstrates implementing the [Strings] section syntax for OIDs and other difficult to interpret data. The new {text} syntax example for EKU extension, which uses a comma separated list of OIDs:

The –accept parameter links the previously generated private key with the issued certificate and removes the pending certificate request from the system where the certificate is requested (if there is a matching request).

The the -accept verb, the -user and –machine options indicate whether the cert being installed should be installed in user or machine context. If there’s an outstanding request in either context that matches the public key being installed, then these options are not needed. If there is no outstanding request, then one of these must be specified.

If you type the certreq -policy without any additional parameter it will open a dialog window so you can select the requested fie (req, cmc, txt, der, cer or crt). Once you select the requested file and click Open button, another dialog window will open in order to select the INF file.

If you type the certreq -sign without any additional parameter it will open a dialog window so you can select the requested file (req, cmc, txt, der, cer or crt).

Signing the qualified subordination request may require Enterprise Administrator credentials. This is a best practice for issuing signing certificates for qualified subordination.

The certificate used to sign the qualified subordination request is created using the qualified subordination template. Enterprise Admins will have to sign the request or grant user permissions for the individuals that will sign the certificate.

When you sign the CMC request, you may need to have multiple personnel sign this request, depending on the assurance level that is associated with the qualified subordination.

If the parent CA of the qualified subordinate CA you are installing is offline, you must obtain the CA certificate for the qualified subordinate CA from the offline parent. If the parent CA is online, specify the CA certificate for the qualified subordinate CA during the Certificate Services Installation Wizard.

The sequence of commands below will show how to create a new certificate request, sign it and submit it:

Insert the URI or unique ID for a computer running the Certificate Enrollment Policy Web Service.

To specify that you would like to use a request file by browsing, just use a minus (-) sign for <policyserver>.

-config <ConfigString>

Processes the operation by using the CA specified in the configuration string, which is CAHostName\CAName. For an https connection, specify the enrollment server URI. For the local machine store CA, use a minus (-) sign.

You can replace the <ClientCertID> with a certificate thumbprint, CN, EKU, template, email, UPN, and the new name=value syntax.

-UserName <UserName>

Used with Certificate Enrollment Web Services. You can substitute <UserName> with the SAM name or domain\user. This option is for use with the -p option.

-p <Password>

Used with Certificate Enrollment Web Services. Substitute <Password> with the actual user's password. This option is for use with the -UserName option.

-user

Configures the -user context for a new certificate request or specifies the context for an a certificate acceptance. This is the default context, if none is specified in the INF or template.

-machine

Configures a new certificate request or specifies the context for an a certificate acceptance for the machine context. For new requests it must be consistent with the MachineKeyset INF key and the template context. If this option is not specified and the template does not set a context, then the default is the user context.

-crl

Includes certificate revocation lists (CRLs) in the output to the base64-encoded PKCS #7 file specified by CertChainFileOut or to the base64-encoded file specified by RequestFileOut.