summaryrefslogtreecommitdiff
path: root/security/keymint/support/keymint_utils.cpp
diff options
context:
space:
mode:
authorOrion Hodson <oth@google.com>2020-12-11 10:45:43 +0000
committerOrion Hodson <oth@google.com>2020-12-11 10:45:43 +0000
commit1ffcdebadd7229af65c575dc1271084b17fe42d7 (patch)
tree70e75b174e2b7851ed235089f13a55a72f11d441 /security/keymint/support/keymint_utils.cpp
parentf73e952ea46e4ff394efa1c77bab4cfecba301ed (diff)
Revert "Move keymint to android.hardware.security."
Revert "Keystore 2.0 SPI: Move keymint spec to security namespace." Revert "Keystore 2.0: Move keymint spec to security namespace." Revert "Keystore 2.0: Move keymint spec to security namespace." Revert "Move keymint to android.hardware.security." Revert "Configure CF to start KeyMint service by default." Revert "Move keymint to android.hardware.security." Revert "Move keymint to android.hardware.security." Revert submission 1522123-move_keymint Reason for revert: Build breakage Bug: 175345910 Bug: 171429297 Reverted Changes: Ief0e9884a:Keystore 2.0: Move keymint spec to security namesp... Idb54e8846:Keystore 2.0: Move keymint spec to security namesp... I9f70db0e4:Remove references to keymint1 I2b4ce3349:Keystore 2.0 SPI: Move keymint spec to security na... I2498073aa:Move keymint to android.hardware.security. I098711e7d:Move keymint to android.hardware.security. I3ec8d70fe:Configure CF to start KeyMint service by default. Icbb373c50:Move keymint to android.hardware.security. I86bccf40e:Move keymint to android.hardware.security. Change-Id: I160cae568ed6b15698bd0af0b19c6c949528762d
Diffstat (limited to 'security/keymint/support/keymint_utils.cpp')
-rw-r--r--security/keymint/support/keymint_utils.cpp114
1 files changed, 0 insertions, 114 deletions
diff --git a/security/keymint/support/keymint_utils.cpp b/security/keymint/support/keymint_utils.cpp
deleted file mode 100644
index cd4cca222a..0000000000
--- a/security/keymint/support/keymint_utils.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <regex.h>
-
-#include <android-base/properties.h>
-#include <hardware/hw_auth_token.h>
-#include <keymint_support/keymint_utils.h>
-
-#include <arpa/inet.h>
-
-namespace android::hardware::security::keymint {
-
-namespace {
-
-constexpr char kPlatformVersionProp[] = "ro.build.version.release";
-constexpr char kPlatformVersionRegex[] = "^([0-9]{1,2})(\\.([0-9]{1,2}))?(\\.([0-9]{1,2}))?";
-constexpr size_t kMajorVersionMatch = 1;
-constexpr size_t kMinorVersionMatch = 3;
-constexpr size_t kSubminorVersionMatch = 5;
-constexpr size_t kPlatformVersionMatchCount = kSubminorVersionMatch + 1;
-
-constexpr char kPlatformPatchlevelProp[] = "ro.build.version.security_patch";
-constexpr char kPlatformPatchlevelRegex[] = "^([0-9]{4})-([0-9]{2})-[0-9]{2}$";
-constexpr size_t kYearMatch = 1;
-constexpr size_t kMonthMatch = 2;
-constexpr size_t kPlatformPatchlevelMatchCount = kMonthMatch + 1;
-
-uint32_t match_to_uint32(const char* expression, const regmatch_t& match) {
- if (match.rm_so == -1) return 0;
-
- size_t len = match.rm_eo - match.rm_so;
- std::string s(expression + match.rm_so, len);
- return std::stoul(s);
-}
-
-std::string wait_and_get_property(const char* prop) {
- std::string prop_value;
- while (!::android::base::WaitForPropertyCreation(prop))
- ;
- prop_value = ::android::base::GetProperty(prop, "" /* default */);
- return prop_value;
-}
-
-} // anonymous namespace
-
-uint32_t getOsVersion(const char* version_str) {
- regex_t regex;
- if (regcomp(&regex, kPlatformVersionRegex, REG_EXTENDED)) {
- return 0;
- }
-
- regmatch_t matches[kPlatformVersionMatchCount];
- int not_match =
- regexec(&regex, version_str, kPlatformVersionMatchCount, matches, 0 /* flags */);
- regfree(&regex);
- if (not_match) {
- return 0;
- }
-
- uint32_t major = match_to_uint32(version_str, matches[kMajorVersionMatch]);
- uint32_t minor = match_to_uint32(version_str, matches[kMinorVersionMatch]);
- uint32_t subminor = match_to_uint32(version_str, matches[kSubminorVersionMatch]);
-
- return (major * 100 + minor) * 100 + subminor;
-}
-
-uint32_t getOsVersion() {
- std::string version = wait_and_get_property(kPlatformVersionProp);
- return getOsVersion(version.c_str());
-}
-
-uint32_t getOsPatchlevel(const char* patchlevel_str) {
- regex_t regex;
- if (regcomp(&regex, kPlatformPatchlevelRegex, REG_EXTENDED) != 0) {
- return 0;
- }
-
- regmatch_t matches[kPlatformPatchlevelMatchCount];
- int not_match =
- regexec(&regex, patchlevel_str, kPlatformPatchlevelMatchCount, matches, 0 /* flags */);
- regfree(&regex);
- if (not_match) {
- return 0;
- }
-
- uint32_t year = match_to_uint32(patchlevel_str, matches[kYearMatch]);
- uint32_t month = match_to_uint32(patchlevel_str, matches[kMonthMatch]);
-
- if (month < 1 || month > 12) {
- return 0;
- }
- return year * 100 + month;
-}
-
-uint32_t getOsPatchlevel() {
- std::string patchlevel = wait_and_get_property(kPlatformPatchlevelProp);
- return getOsPatchlevel(patchlevel.c_str());
-}
-
-} // namespace android::hardware::security::keymint