am f9a8ecc4: Merge change 25737 into eclair

Merge commit 'f9a8ecc457144769cffef39af538186215e00d7a' into eclair-plus-aosp

* commit 'f9a8ecc457144769cffef39af538186215e00d7a':
  keystore: switch to multi-user version.
This commit is contained in:
Chia-chi Yeh
2009-09-20 20:46:54 -07:00
committed by Android Git Automerger
4 changed files with 87 additions and 61 deletions

View File

@@ -1,22 +1,32 @@
ifneq ($(TARGET_SIMULATOR),true) #
# Copyright (C) 2009 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.
#
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_SRC_FILES := keystore.c
LOCAL_SRC_FILES:= \ LOCAL_C_INCLUDES := external/openssl/include
netkeystore.c netkeystore_main.c keymgmt.c LOCAL_SHARED_LIBRARIES := libcutils libcrypto
LOCAL_C_INCLUDES := \
$(call include-path-for, system-core)/cutils \
external/openssl/include
LOCAL_SHARED_LIBRARIES := \
libcutils libssl
LOCAL_STATIC_LIBRARIES :=
LOCAL_MODULE:= keystore LOCAL_MODULE:= keystore
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif # !simulator)) include $(CLEAR_VARS)
LOCAL_SRC_FILES := keystore_cli.c
LOCAL_C_INCLUDES := external/openssl/include
LOCAL_SHARED_LIBRARIES := libcutils libcrypto
LOCAL_MODULE:= keystore_cli
LOCAL_MODULE_TAGS := debug
include $(BUILD_EXECUTABLE)

View File

@@ -217,8 +217,10 @@ static int8_t decrypt_blob(char *name, AES_KEY *aes_key)
/* Here are the actions. Each of them is a function without arguments. All /* Here are the actions. Each of them is a function without arguments. All
* information is defined in global variables, which are set properly before * information is defined in global variables, which are set properly before
* performing an action. The number of parameters required by each action is * performing an action. The number of parameters required by each action is
* fixed and defined in a table. Note that the lengths of parameters are checked * fixed and defined in a table. If the return value of an action is positive,
* when they are received, so boundary checks on parameters are omitted. */ * it will be treated as a response code and transmitted to the client. Note
* that the lengths of parameters are checked when they are received, so
* boundary checks on parameters are omitted. */
#define MAX_PARAM 2 #define MAX_PARAM 2
#define MAX_RETRY 4 #define MAX_RETRY 4
@@ -321,12 +323,10 @@ static int8_t reset()
return SYSTEM_ERROR; return SYSTEM_ERROR;
} }
while ((file = readdir(dir)) != NULL) { while ((file = readdir(dir)) != NULL) {
if (strcmp(".", file->d_name) || strcmp("..", file->d_name)) { unlink(file->d_name);
unlink(file->d_name);
}
} }
closedir(dir); closedir(dir);
return UNINITIALIZED; return NO_ERROR;
} }
#define MASTER_KEY_FILE ".masterkey" #define MASTER_KEY_FILE ".masterkey"
@@ -387,7 +387,7 @@ static int8_t lock()
memset(&encryption_key, 0, sizeof(encryption_key)); memset(&encryption_key, 0, sizeof(encryption_key));
memset(&decryption_key, 0, sizeof(decryption_key)); memset(&decryption_key, 0, sizeof(decryption_key));
state = LOCKED; state = LOCKED;
return LOCKED; return NO_ERROR;
} }
static int8_t unlock() static int8_t unlock()

View File

@@ -53,8 +53,8 @@ int main(int argc, char **argv)
return 0; return 0;
} }
sock = socket_local_client("keystore", sock = socket_local_client("keystore", ANDROID_SOCKET_NAMESPACE_RESERVED,
ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); SOCK_STREAM);
if (sock == -1) { if (sock == -1) {
puts("Failed to connect"); puts("Failed to connect");
return 1; return 1;

View File

@@ -1,53 +1,69 @@
/* /*
** * Copyright (C) 2009 The Android Open Source Project
** Copyright 2009, The Android Open Source Project *
** * Licensed under the Apache License, Version 2.0 (the "License");
** Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
** you may not use this file except in compliance with the License. * You may obtain a copy of the License at
** You may obtain a copy of the License at *
** * http://www.apache.org/licenses/LICENSE-2.0
** http://www.apache.org/licenses/LICENSE-2.0 *
** * Unless required by applicable law or agreed to in writing, software
** Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS,
** distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and
** See the License for the specific language governing permissions and * limitations under the License.
** limitations under the License. */
*/
#ifndef __KEYSTORE_GET_H__ #ifndef __KEYSTORE_GET_H__
#define __KEYSTORE_GET_H__ #define __KEYSTORE_GET_H__
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "certtool.h" #include <cutils/sockets.h>
/* This function is provided to native components to get values from keystore. #define KEYSTORE_MESSAGE_SIZE 65535
* Users are required to link against libcutils. If something goes wrong, NULL
* is returned. Otherwise it returns the value in dynamically allocated memory /* This function is provided for native components to get values from keystore.
* and sets the size if the pointer is not NULL. One can release the memory by * Users are required to link against libcutils. The lengths of keys and values
* calling free(). */ * are limited to KEYSTORE_MESSAGE_SIZE. This function returns the length of
static char *keystore_get(const char *key, int *size) * the requested value or -1 if something goes wrong. */
static int keystore_get(const char *key, char *value)
{ {
char buffer[MAX_KEY_VALUE_LENGTH]; int length = strlen(key);
char *value; uint8_t bytes[2] = {length >> 8, length};
int length; uint8_t code = 'g';
int sock;
if (get_cert(key, (unsigned char *)buffer, &length) != 0) { if (length > KEYSTORE_MESSAGE_SIZE) {
return NULL; return -1;
} }
value = malloc(length + 1); sock = socket_local_client("keystore", ANDROID_SOCKET_NAMESPACE_RESERVED,
if (!value) { SOCK_STREAM);
return NULL; if (sock == -1) {
return -1;
} }
memcpy(value, buffer, length); if (send(sock, &code, 1, 0) == 1 && send(sock, bytes, 2, 0) == 2 &&
value[length] = 0; send(sock, key, length, 0) == length && shutdown(sock, SHUT_WR) == 0 &&
if (size) { recv(sock, &code, 1, 0) == 1 && code == /* NO_ERROR */ 1 &&
*size = length; recv(sock, &bytes[0], 1, 0) == 1 && recv(sock, &bytes[1], 1, 0) == 1) {
int offset = 0;
length = bytes[0] << 8 | bytes[1];
while (offset < length) {
int n = recv(sock, &value[offset], length - offset, 0);
if (n <= 0) {
length = -1;
break;
}
offset += n;
}
} }
return value; close(sock);
return length;
} }
#endif #endif