---
policy: /ce/ca/google/dns/rsasha1-for-zone-signing-key
logic: /ce/ca/google/dns/rsasha1-for-zone-signing-key/prod.logic.yaml
executionTime: 2025-05-10T12:05:17.448268611Z
rows:
  - id: 111
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: 112
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value').contains('rsasha1')
      actual: extract('caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value').contains('rsasha1')
    runtimeError: {}
  - id: 113
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/dns/rsasha1-for-zone-signing-key/policy.yaml
    md5Hash: 67E0017D56128BDC1E9ADE768507D3D6
    content: "---\nnames: \n  full: \"Google Cloud DNS Managed Zone DNSSEC Zone-Signing\
      \ Algorithm is RSASHA1\"\n  contextual: \"Managed Zone DNSSEC Zone-Signing Algorithm\
      \ is RSASHA1\"\ndescription: \"DNSSEC algorithm numbers in this registry may\
      \ be used in CERT RRs. Zone signing (DNSSEC) and \\ \n transaction security\
      \ mechanisms (SIG(0) and TSIG) make use of particular subsets of these algorithms.\
      \ \\ \n The algorithm used for key signing should be a recommended one and it\
      \ should be strong.\"\ntype: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/03/05\n  - /frameworks/cloudaware/secret-and-certificate-governance/cryptographic-configuration\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudDNS/dns-sec-zone-signing-algorithm-in-use.html\"\
      \n      name: \"Check for DNSSEC Zone-Signing Algorithm in Use\"\n"
  - path: /ce/ca/google/dns/rsasha1-for-zone-signing-key/prod.logic.yaml
    md5Hash: 68BD5F3078516D46768CA2D6A98D8806
    content: "---\n\ninputType: \"CA10__CaGoogleDnsManagedZone__c\"\ntestData:\n \
      \ - file: test-data.json\nimportExtracts:\n  - file: /types/CA10__CaGoogleDnsManagedZone__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The Managed\
      \ Zone uses the RSASHA1 algorithm for the Zone-Signing Key.\"\n    remediationMessage:\
      \ \"Change the DNSSEC Configuration for the Managed Zone.\"\n    check:\n  \
      \    CONTAINS:\n        arg:\n          EXTRACT: \"caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value\"\
      \n        substring: \n          TEXT: \"rsasha1\"\notherwise:\n  status: \"\
      COMPLIANT\"\n  currentStateMessage: \"The Managed Zone doesn't use the RSASHA1\
      \ algorithm for the Zone-Signing Key.\"\n\n"
  - path: /ce/ca/google/dns/rsasha1-for-zone-signing-key/test-data.json
    md5Hash: 12003E80055EE6EB8A232FEACD6BAF5C
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "111",
          "CA10__disappearanceTime__c": "2025-01-14T19:40:37Z",
          "CA10__dnssecConfigurationKeySpecs__c": ""
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value').contains('rsasha1')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "112",
          "CA10__disappearanceTime__c": null,
          "CA10__dnssecConfigurationKeySpecs__c": "[{\"algorithm\":\"rsasha256\",\"keyLength\":2048,\"keyType\":\"keySigning\",\"kind\":\"dns#dnsKeySpec\"},{\"algorithm\":\"rsasha1\",\"keyLength\":1024,\"keyType\":\"zoneSigning\",\"kind\":\"dns#dnsKeySpec\"}]"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "113",
          "CA10__disappearanceTime__c": null,
          "CA10__dnssecConfigurationKeySpecs__c": "[{\"algorithm\":\"rsasha256\",\"keyLength\":2048,\"keyType\":\"keySigning\",\"kind\":\"dns#dnsKeySpec\"},{\"algorithm\":\"rsasha256\",\"keyLength\":1024,\"keyType\":\"zoneSigning\",\"kind\":\"dns#dnsKeySpec\"}]"
        }
      ]
  - path: /types/CA10__CaGoogleDnsManagedZone__c/object.extracts.yaml
    md5Hash: DEC5B55A555645F54FDC22FF0932896B
    content: "---\nextracts:\n  - name: \"CA10__visibility__c\"\n    value: \n   \
      \   FIELD:\n        path: \"CA10__visibility__c\"\n  - name: \"CA10__dnssecConfigurationState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__dnssecConfigurationState__c\"\
      \n  - name: \"CA10__dnssecConfigurationKeySpecs__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__dnssecConfigurationKeySpecs__c\"\n        returnType:\
      \ BYTES\n  - name: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\n    value:\
      \ \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__dnssecConfigurationKeySpecs__c\"\
      \n        undeterminedIf:\n          isInvalid: \"JSON is invalid.\"\n     \
      \     isEmpty: \"JSON is empty.\"\n  - name: \"caJsonFrom__dnssecConfigurationKeySpecs_keySigning_algorithm_value\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\
      \n        expression: \"to_string([?keyType == 'keySigning'].algorithm)\"\n\
      \        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\n  - name:\
      \ \"caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\
      \n        expression: \"to_string([?keyType == 'zoneSigning'].algorithm)\"\n\
      \        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\n\n\n\n\
      \n\n          "
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "111",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "112",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value').contains('rsasha1')",
      "runtimeError" : null
    }
  }, {
    "Id" : "113",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleDnsManagedZone__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__dnssecConfigurationKeySpecs__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "111",
    "CA10__disappearanceTime__c" : new Date("2025-01-14T19:40:37Z"),
    "CA10__dnssecConfigurationKeySpecs__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "112",
    "CA10__dnssecConfigurationKeySpecs__c" : "[{\"algorithm\":\"rsasha256\",\"keyLength\":2048,\"keyType\":\"keySigning\",\"kind\":\"dns#dnsKeySpec\"},{\"algorithm\":\"rsasha1\",\"keyLength\":1024,\"keyType\":\"zoneSigning\",\"kind\":\"dns#dnsKeySpec\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "113",
    "CA10__dnssecConfigurationKeySpecs__c" : "[{\"algorithm\":\"rsasha256\",\"keyLength\":2048,\"keyType\":\"keySigning\",\"kind\":\"dns#dnsKeySpec\"},{\"algorithm\":\"rsasha256\",\"keyLength\":1024,\"keyType\":\"zoneSigning\",\"kind\":\"dns#dnsKeySpec\"}]"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleDnsManagedZone__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__dnssecConfigurationKeySpecs__c STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.js'])
  AS r"""
      var TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function jsonQueryChecked4() {
          var input = extract6.call(extract6);
          var out;
          try {
              out = jmespath.search(input, 'to_string([?keyType == \'zoneSigning\'].algorithm)');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extract('caJsonFrom__dnssecConfigurationKeySpecs__c').jsonQueryText('to_string([?keyType == \\'zoneSigning\\'].algorithm)').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a text.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "extract('caJsonFrom__dnssecConfigurationKeySpecs__c').jsonQueryText('to_string([?keyType == \\'zoneSigning\\'].algorithm)').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          if (TextLib.isEmpty(out)) {
              throw new Error("UNDETERMINED condition:105", {cause: {status: 'UNDETERMINED', conditionIndex: 105, conditionText: "extract('caJsonFrom__dnssecConfigurationKeySpecs__c').jsonQueryText('to_string([?keyType == \\'zoneSigning\\'].algorithm)').isResultEmpty()", currentStateMessage: "The JSON query did not return a value.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return out;
      }
      function jsonChecked7() {
          var input = extract9.call(extract9);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "extract('CA10__dnssecConfigurationKeySpecs__c').asJson().isEmpty()", currentStateMessage: "JSON is empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extract('CA10__dnssecConfigurationKeySpecs__c').asJson().isInvalid()", currentStateMessage: "JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract9() { if (!this.out) { this.out = obj.CA10__dnssecConfigurationKeySpecs__c; } return this.out; };
      function extract6() { if (!this.out) { this.out = jsonChecked7(); } return this.out; };
      function extract3() { if (!this.out) { this.out = jsonQueryChecked4(); } return this.out; };
      references1.push('DNSSEC Configuration Key Specs [obj.CA10__dnssecConfigurationKeySpecs__c]: ' + obj.CA10__dnssecConfigurationKeySpecs__c);
      try {
          if (TextLib.contains(extract3.call(extract3), 'rsasha1')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value').contains('rsasha1')", currentStateMessage: "The Managed Zone uses the RSASHA1 algorithm for the Zone-Signing Key.", currentStateReferences: references1.join('\n'), remediation: "Change the DNSSEC Configuration for the Managed Zone.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Managed Zone doesn't use the RSASHA1 algorithm for the Zone-Signing Key.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__dnssecConfigurationKeySpecs__c AS CA10__dnssecConfigurationKeySpecs__c,
          process_CA10__CaGoogleDnsManagedZone__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__dnssecConfigurationKeySpecs__c AS CA10__dnssecConfigurationKeySpecs__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleDnsManagedZone__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
