Stop killing cryptohomed at the end of tests.

Now the TPM_DICTIONARY_ATTACK_COUNTER data can be obtained without
stopping services.

This makes client tests happy when used as an utility within server tests,
in a way described in:
 docs/best-practices.md#Calling-client_side-tests-from-a-server_side-test
In particular, cheets_CTSHelper test, meant to leave logged-in Chrome
state for the server-side test, can now correctly keep cryptohomed alive.

BUG=b:36574842
TEST=test_that cheets_GTS.4.1_r1.GtsGmscoreHostTestCases

Change-Id: I24679f7b6d69d94aa8185d054fa74024a58588cf
Reviewed-on: https://chromium-review.googlesource.com/461783
Commit-Ready: Kazuhiro Inaba <kinaba@chromium.org>
Tested-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
diff --git a/client/bin/site_sysinfo.py b/client/bin/site_sysinfo.py
index 8baaf02..9bb7ac8 100755
--- a/client/bin/site_sysinfo.py
+++ b/client/bin/site_sysinfo.py
@@ -8,7 +8,7 @@
 from autotest_lib.client.common_lib import log
 from autotest_lib.client.common_lib import error, utils, global_config
 from autotest_lib.client.bin import base_sysinfo, utils
-from autotest_lib.client.cros import constants, tpm_dam
+from autotest_lib.client.cros import constants
 
 get_value = global_config.global_config.get_config_value
 collect_corefiles = get_value('CLIENT', 'collect_corefiles',
@@ -376,9 +376,15 @@
         keyval["CHROME_VERSION"], keyval["MILESTONE"] = (
                 self._get_chrome_version())
 
+        # TODO(kinaba): crbug.com/707448 Import at the head of this file.
+        # Currently a server-side script server/server_job.py is indirectly
+        # importing this file, so we cannot globaly import cryptohome that
+        # has dependency to a client-only library.
+        from autotest_lib.client.cros import cryptohome
         # Get the dictionary attack counter.
         keyval["TPM_DICTIONARY_ATTACK_COUNTER"] = (
-                tpm_dam.get_dictionary_attack_counter())
+                cryptohome.get_tpm_more_status().get(
+                    'dictionary_attack_counter', 'Failed to query cryptohome'))
 
         # Return the updated keyvals.
         return keyval
diff --git a/client/cros/tpm_dam.py b/client/cros/tpm_dam.py
deleted file mode 100644
index 15887ae..0000000
--- a/client/cros/tpm_dam.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# Copyright 2014 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""
-Provides a utility function for working with TPM DAM logic.
-
-Dictionary Attack Mitigation (DAM) logic causes TPMs to enter a locked down
-state to defend against dictionary attacks. Authentication failures cause a
-counter to increment and when the counter exceeds some threshold, the defense
-mechanism is triggered.
-"""
-
-import os, re
-
-from autotest_lib.client.common_lib import utils
-from autotest_lib.client.cros import service_stopper
-
-def get_dictionary_attack_counter():
-    """Returns the current dictionary attack counter."""
-    tpm_command_info = {
-        '0x49465800': {  # Infineon
-            'command': ('00 c1 '         # Tag = TPM_TAG_RQU_COMMAND
-                        '00 00 00 16 '   # Size = 22
-                        '00 00 00 65 '   # Ordinal = TPM_ORD_GetCapability
-                        '00 00 00 10 '   # Capability Area = TPM_CAP_MFR
-                        '00 00 00 04 '   # Size = 4
-                        '00 00 08 02'),  # Vendor-specific
-            'response_offset': 23},      # Vendor-specific
-        '0x57454300': {  # Nuvoton
-            'command': ('00 c1 '         # Tag = TPM_TAG_RQU_COMMAND
-                        '00 00 00 14 '   # Size = 20
-                        '00 00 00 65 '   # Ordinal = TPM_ORD_GetCapability
-                        '00 00 00 19 '   # Capability Area = TPM_CAP_DA_LOGIC
-                        '00 00 00 02 '   # Size = 2
-                        '00 04'),        # Entity Type = TPM_ET_SRK
-            'response_offset': 18},      # TPM_DA_INFO.currentCount LSB
-        '0x53544d20': {  # STMicro
-            'command': ('00 c1 '         # Tag = TPM_TAG_RQU_COMMAND
-                        '00 00 00 14 '   # Size = 20
-                        '00 00 00 65 '   # Ordinal = TPM_ORD_GetCapability
-                        '00 00 00 19 '   # Capability Area = TPM_CAP_DA_LOGIC
-                        '00 00 00 02 '   # Size = 2
-                        '00 04'),        # Entity Type = TPM_ET_SRK
-            'response_offset': 18}}      # TPM_DA_INFO.currentCount LSB
-    caps_file='/sys/class/misc/tpm0/device/caps'
-    if not os.path.exists(caps_file):
-        caps_file='/sys/class/tpm/tpm0/device/caps'
-    try:
-        with open(caps_file, 'r') as fp:
-            caps = fp.read()
-    except IOError:
-        return 'Could not read TPM device caps.'
-    match = re.search(r'Manufacturer: (0x[0-9A-Fa-f]*)', caps)
-    if not match:
-        return 'Could not find TPM manufacturer.'
-    manufacturer = match.group(1)
-    if manufacturer not in tpm_command_info:
-        return 'TPM manufacturer not supported.'
-    with service_stopper.ServiceStopper(['cryptohomed',
-                                         'chapsd',
-                                         'tcsd']):
-        # The output of 'tpmc raw' is a series of bytes in the form
-        # '0x00 0x01 0x02 ...'.
-        tpm_response = utils.system_output(
-                'tpmc raw %s' % tpm_command_info[manufacturer]['command'],
-                ignore_status=True).split()
-    offset = tpm_command_info[manufacturer]['response_offset']
-    if (len(tpm_response) <= offset):
-        return 'Unexpected TPM response (length = %d).' % len(tpm_response)
-    return int(tpm_response[offset], base=16)
-
-