---
title: Ensure the System Wide Crypto Policy Disables SHA-1 Hash and Signature Support
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Ensure the System Wide Crypto Policy
  Disables SHA-1 Hash and Signature Support
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Ensure the System Wide Crypto Policy Disables SHA-1 Hash and Signature Support
 
## Description{% #description %}

The system wide crypto policy has to remove SHA-1 from the hash and signature algorithms. The rule reads the resolved policy that `update-crypto-policies` writes to `/etc/crypto-policies/state/CURRENT.pol` when it applies a policy. That file has to exist, and in it:

- the `hash` and `sign` lines list no SHA-1 algorithm,
- the `sha1_in_certs` line is set to `0`.

To disable SHA-1, add the `NO-SHA1` subpolicy to the system wide crypto policy, together with the subpolicies already in use, for example:

```
$ sudo update-crypto-policies --set DEFAULT:NO-SHA1
```

If the system provides no `NO-SHA1` subpolicy in `/usr/share/crypto-policies/policies/modules`, first create `/etc/crypto-policies/policies/modules/NO-SHA1.pmod` with the following lines:

```
hash = -SHA1
sign = -*-SHA1
sha1_in_certs = 0
```

## Rationale{% #rationale %}

The SHA-1 hash function is vulnerable to collision attacks, in which an attacker produces two different inputs with the same hash. A collision lets an attacker forge a signature or a certificate made with SHA-1. The rule leaves the mac lines as they are: HMAC-SHA1 relies on properties of SHA-1 that collision attacks leave intact.

## Remediation{% #remediation %}

### Shell script{% #shell-script %}

The following script can be run on the host to remediate the issue.

```bash
#!/bin/bash

# Remediation is applicable only in certain platforms
if rpm --quiet -q crypto-policies; then

current_pol=/etc/crypto-policies/state/CURRENT.pol
sha1_in_certs='^[[:space:]]*sha1_in_certs[[:space:]]*='

if [ ! -f "$current_pol" ] ||
    grep -Eiq '^[[:space:]]*(hash|sign)[[:space:]]*=[^#]*SHA-?1\b' "$current_pol" ||
    ! grep -Eiq "$sha1_in_certs" "$current_pol" ||
    grep -Ei "$sha1_in_certs" "$current_pol" | grep -Evq '=[[:space:]]*0[[:space:]]*(#.*)?$'; then
    module=/etc/crypto-policies/policies/modules/NO-SHA1.pmod
    if [ -f "$module" ] || [ ! -f /usr/share/crypto-policies/policies/modules/NO-SHA1.pmod ]; then
        # End the module with a newline, so that the lines appended below
        # start lines of their own.
        [ -z "$(tail -c 1 "$module" 2>/dev/null)" ] || echo >>"$module"
        for line in 'hash = -SHA1' 'sign = -*-SHA1' 'sha1_in_certs = 0'; do
            grep -qsxF -- "$line" "$module" || echo "$line" >>"$module"
        done
        chmod 0644 "$module"
    fi
    # Apply NO-SHA1 last, after any subpolicy that enables what it disables.
    crypto_policy=$(update-crypto-policies --show | sed -e 's/$/:/' -e 's/:NO-SHA1:/:/g' -e 's/:$//')
    update-crypto-policies --set "$crypto_policy:NO-SHA1"
fi

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi
```
