Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0748068 authored by Andres Morales's avatar Andres Morales Committed by Android Git Automerger
Browse files

am 9dde5667: Merge "Revert "[core][trusty] add keymaster module""

* commit '9dde5667':
  Revert "[core][trusty] add keymaster module"
parents ee47386a 9dde5667
Loading
Loading
Loading
Loading

trusty/keymaster/Android.mk

deleted100644 → 0
+0 −76
Original line number Diff line number Diff line
#
# Copyright (C) 2015 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.
#

# WARNING: Everything listed here will be built on ALL platforms,
# including x86, the emulator, and the SDK.  Modules must be uniquely
# named (liblights.panda), and must build everywhere, or limit themselves
# to only building on ARM if they include assembly. Individual makefiles
# are responsible for having their own logic, for fine-grained control.

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

###
# trusty_keymaster is a binary used only for on-device testing.  It
# runs Trusty Keymaster through a basic set of operations with RSA
# and ECDSA keys.
###
LOCAL_MODULE := trusty_keymaster
LOCAL_C_INCLUDES:= \
	system/keymaster \
	external/openssl/include
LOCAL_SRC_FILES := \
	trusty_keymaster_device.cpp \
	trusty_keymaster_ipc.c \
	trusty_keymaster_main.cpp
LOCAL_SHARED_LIBRARIES := \
	libcrypto \
	libcutils \
	libkeymaster1 \
	libtrusty \
	libkeymaster_messages \
	liblog

include $(BUILD_EXECUTABLE)

###
# keystore.trusty is the HAL used by keystore on Trusty devices.
##

include $(CLEAR_VARS)

LOCAL_MODULE := keystore.trusty
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := module.cpp \
	trusty_keymaster_ipc.c \
	trusty_keymaster_device.cpp
LOCAL_C_INCLUDES := system/keymaster
LOCAL_CLFAGS = -fvisibility=hidden -Wall -Werror
LOCAL_SHARED_LIBRARIES := \
	libcrypto \
	libkeymaster_messages \
	libtrusty \
	liblog \
	libcutils
LOCAL_MODULE_TAGS := optional
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk

# Symlink keymaster.trusty.so -> keymaster.<device>.so so libhardware can find it.
LOCAL_POST_INSTALL_CMD = \
    $(hide) ln -sf $(notdir $(LOCAL_INSTALLED_MODULE)) $(dir $(LOCAL_INSTALLED_MODULE))keystore.$(TARGET_DEVICE).so

include $(BUILD_SHARED_LIBRARY)

trusty/keymaster/Makefile

deleted100644 → 0
+0 −199
Original line number Diff line number Diff line
#####
# Local unit test Makefile
#
# This makefile builds and runs the trusty_keymaster unit tests locally on the development
# machine, not on an Android device.
#
# To build and run these tests, one pre-requisite must be manually installed: BoringSSL.
# This Makefile expects to find BoringSSL in a directory adjacent to $ANDROID_BUILD_TOP.
# To get and build it, first install the Ninja build tool (e.g. apt-get install
# ninja-build), then do:
#
# cd $ANDROID_BUILD_TOP/..
# git clone https://boringssl.googlesource.com/boringssl
# cd boringssl
# mdkir build
# cd build
# cmake -GNinja ..
# ninja
#
# Then return to $ANDROID_BUILD_TOP/system/keymaster and run "make".
#####

BASE=../../../..
SUBS=system/core \
	system/keymaster \
	hardware/libhardware \
	external/gtest
GTEST=$(BASE)/external/gtest
KM=$(BASE)/system/keymaster

INCLUDES=$(foreach dir,$(SUBS),-I $(BASE)/$(dir)/include) \
	-I $(BASE)/libnativehelper/include/nativehelper \
	-I ../tipc/include \
	-I $(BASE)/system/keymaster \
	-I $(GTEST) \
	-I$(BASE)/../boringssl/include

ifdef USE_CLANG
CC=/usr/bin/clang
CXX=/usr/bin/clang
CLANG_TEST_DEFINE=-DKEYMASTER_CLANG_TEST_BUILD
COMPILER_SPECIFIC_ARGS=-std=c++11 $(CLANG_TEST_DEFINE)
else
COMPILER_SPECIFIC_ARGS=-std=c++0x -fprofile-arcs
endif

CPPFLAGS=$(INCLUDES) -g -O0 -MD
CXXFLAGS=-Wall -Werror -Wno-unused -Winit-self -Wpointer-arith	-Wunused-parameter \
	-Wmissing-declarations -ftest-coverage \
	-Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS \
	$(COMPILER_SPECIFIC_ARGS)
LDLIBS=-L$(BASE)/../boringssl/build/crypto -lcrypto -lpthread -lstdc++

CPPSRCS=\
	$(KM)/aead_mode_operation.cpp \
	$(KM)/aes_key.cpp \
	$(KM)/aes_operation.cpp \
	$(KM)/android_keymaster.cpp \
	$(KM)/android_keymaster_messages.cpp \
	$(KM)/android_keymaster_messages_test.cpp \
	$(KM)/android_keymaster_test.cpp \
	$(KM)/android_keymaster_test_utils.cpp \
	$(KM)/android_keymaster_utils.cpp \
	$(KM)/asymmetric_key.cpp \
	$(KM)/auth_encrypted_key_blob.cpp \
	$(KM)/auth_encrypted_key_blob.cpp \
	$(KM)/authorization_set.cpp \
	$(KM)/authorization_set_test.cpp \
	$(KM)/ec_key.cpp \
	$(KM)/ec_keymaster0_key.cpp \
	$(KM)/ecdsa_operation.cpp \
	$(KM)/hmac_key.cpp \
	$(KM)/hmac_operation.cpp \
	$(KM)/integrity_assured_key_blob.cpp \
	$(KM)/key.cpp \
	$(KM)/key_blob_test.cpp \
	$(KM)/keymaster0_engine.cpp \
	$(KM)/logger.cpp \
	$(KM)/ocb_utils.cpp \
	$(KM)/openssl_err.cpp \
	$(KM)/openssl_utils.cpp \
	$(KM)/operation.cpp \
	$(KM)/operation_table.cpp \
	$(KM)/rsa_key.cpp \
	$(KM)/rsa_keymaster0_key.cpp \
	$(KM)/rsa_operation.cpp \
	$(KM)/serializable.cpp \
	$(KM)/soft_keymaster_context.cpp \
	$(KM)/symmetric_key.cpp \
	$(KM)/unencrypted_key_blob.cpp \
	trusty_keymaster_device.cpp \
	trusty_keymaster_device_test.cpp
CCSRCS=$(GTEST)/src/gtest-all.cc
CSRCS=ocb.c

OBJS=$(CPPSRCS:.cpp=.o) $(CCSRCS:.cc=.o) $(CSRCS:.c=.o)
DEPS=$(CPPSRCS:.cpp=.d) $(CCSRCS:.cc=.d) $(CSRCS:.c=.d)
GCDA=$(CPPSRCS:.cpp=.gcda) $(CCSRCS:.cc=.gcda) $(CSRCS:.c=.gcda)
GCNO=$(CPPSRCS:.cpp=.gcno) $(CCSRCS:.cc=.gcno) $(CSRCS:.c=.gcno)

LINK.o=$(LINK.cc)

BINARIES=trusty_keymaster_device_test

ifdef TRUSTY
BINARIES += trusty_keymaster_device_test
endif # TRUSTY

.PHONY: coverage memcheck massif clean run

%.run: %
	./$<
	touch $@

run: $(BINARIES:=.run)

coverage: coverage.info
	genhtml coverage.info --output-directory coverage

coverage.info: run
	lcov --capture --directory=. --output-file coverage.info

%.coverage : %
	$(MAKE) clean && $(MAKE) $<
	./$<
	lcov --capture --directory=. --output-file coverage.info
	genhtml coverage.info --output-directory coverage

#UNINIT_OPTS=--track-origins=yes
UNINIT_OPTS=--undef-value-errors=no

MEMCHECK_OPTS=--leak-check=full \
	--show-reachable=yes \
	--vgdb=full \
	$(UNINIT_OPTS) \
	--error-exitcode=1

MASSIF_OPTS=--tool=massif \
	--stacks=yes

%.memcheck : %
	valgrind $(MEMCHECK_OPTS) ./$< && \
	touch $@

%.massif : %
	valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$<

memcheck: $(BINARIES:=.memcheck)

massif: $(BINARIES:=.massif)

trusty_keymaster_device_test: trusty_keymaster_device_test.o \
	trusty_keymaster_device.o \
	$(KM)/aead_mode_operation.o \
	$(KM)/aes_key.o \
	$(KM)/aes_operation.o \
	$(KM)/android_keymaster.o \
	$(KM)/android_keymaster_messages.o \
	$(KM)/android_keymaster_test_utils.o \
	$(KM)/android_keymaster_utils.o \
	$(KM)/asymmetric_key.o \
	$(KM)/auth_encrypted_key_blob.o \
	$(KM)/auth_encrypted_key_blob.o \
	$(KM)/authorization_set.o \
	$(KM)/ec_key.o \
	$(KM)/ec_keymaster0_key.cpp \
	$(KM)/ecdsa_operation.o \
	$(KM)/hmac_key.o \
	$(KM)/hmac_operation.o \
	$(KM)/integrity_assured_key_blob.o \
	$(KM)/key.o \
	$(KM)/keymaster0_engine.o \
	$(KM)/logger.o \
	$(KM)/ocb.o \
	$(KM)/ocb_utils.o \
	$(KM)/openssl_err.o \
	$(KM)/openssl_utils.o \
	$(KM)/operation.o \
	$(KM)/operation_table.o \
	$(KM)/rsa_key.o \
	$(KM)/rsa_keymaster0_key.o \
	$(KM)/rsa_operation.o \
	$(KM)/serializable.o \
	$(KM)/soft_keymaster_context.o \
	$(KM)/symmetric_key.o \
	$(GTEST)/src/gtest-all.o

$(GTEST)/src/gtest-all.o: CXXFLAGS:=$(subst -Wmissing-declarations,,$(CXXFLAGS))
ocb.o: CFLAGS=$(CLANG_TEST_DEFINE)

clean:
	rm -f $(OBJS) $(DEPS) $(GCDA) $(GCNO) $(BINARIES) \
		$(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \
		coverage.info
	rm -rf coverage

-include $(CPPSRCS:.cpp=.d)
-include $(CCSRCS:.cc=.d)

trusty/keymaster/keymaster_ipc.h

deleted100644 → 0
+0 −57
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

#pragma once

#define KEYMASTER_PORT "com.android.trusty.keymaster"
#define KEYMASTER_MAX_BUFFER_LENGTH 4096

// Commands
enum keymaster_command {
	KEYMASTER_RESP_BIT              = 1,
	KEYMASTER_REQ_SHIFT             = 1,

    KM_GENERATE_KEY                 = (0 << KEYMASTER_REQ_SHIFT),
    KM_BEGIN_OPERATION              = (1 << KEYMASTER_REQ_SHIFT),
    KM_UPDATE_OPERATION             = (2 << KEYMASTER_REQ_SHIFT),
    KM_FINISH_OPERATION             = (3 << KEYMASTER_REQ_SHIFT),
    KM_ABORT_OPERATION              = (4 << KEYMASTER_REQ_SHIFT),
    KM_IMPORT_KEY                   = (5 << KEYMASTER_REQ_SHIFT),
    KM_EXPORT_KEY                   = (6 << KEYMASTER_REQ_SHIFT),
    KM_GET_VERSION                  = (7 << KEYMASTER_REQ_SHIFT),
    KM_ADD_RNG_ENTROPY              = (8 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_ALGORITHMS     = (9 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_BLOCK_MODES    = (10 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_PADDING_MODES  = (11 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_DIGESTS        = (12 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_IMPORT_FORMATS = (13 << KEYMASTER_REQ_SHIFT),
    KM_GET_SUPPORTED_EXPORT_FORMATS = (14 << KEYMASTER_REQ_SHIFT),
    KM_GET_KEY_CHARACTERISTICS      = (15 << KEYMASTER_REQ_SHIFT),
};

#ifdef __ANDROID__

/**
 * keymaster_message - Serial header for communicating with KM server
 * @cmd: the command, one of keymaster_command.
 * @payload: start of the serialized command specific payload
 */
struct keymaster_message {
	uint32_t cmd;
	uint8_t payload[0];
};

#endif

trusty/keymaster/module.cpp

deleted100644 → 0
+0 −60
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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 <errno.h>
#include <string.h>

#include <hardware/hardware.h>
#include <hardware/keymaster0.h>

#include "trusty_keymaster_device.h"

using keymaster::TrustyKeymasterDevice;

/*
 * Generic device handling
 */
static int trusty_keymaster_open(const hw_module_t* module, const char* name,
                                 hw_device_t** device) {
    if (strcmp(name, KEYSTORE_KEYMASTER) != 0)
        return -EINVAL;

    TrustyKeymasterDevice* dev = new TrustyKeymasterDevice(module);
    if (dev == NULL)
        return -ENOMEM;
    *device = dev->hw_device();
    // Do not delete dev; it will get cleaned up when the caller calls device->close(), and must
    // exist until then.
    return 0;
}

static struct hw_module_methods_t keystore_module_methods = {
    .open = trusty_keymaster_open,
};

struct keystore_module HAL_MODULE_INFO_SYM __attribute__((visibility("default"))) = {
    .common =
        {
         .tag = HARDWARE_MODULE_TAG,
         .module_api_version = KEYMASTER_MODULE_API_VERSION_0_3,
         .hal_api_version = HARDWARE_HAL_API_VERSION,
         .id = KEYSTORE_HARDWARE_MODULE_ID,
         .name = "Trusty Keymaster HAL",
         .author = "The Android Open Source Project",
         .methods = &keystore_module_methods,
         .dso = 0,
         .reserved = {},
        },
};
+0 −536

File deleted.

Preview size limit exceeded, changes collapsed.

Loading