Skip to content

Commit

Permalink
Create dummy key
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanoabdi committed May 14, 2020
1 parent 3c15a16 commit 2fa1bb5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ LOCAL_CFLAGS += \

LOCAL_SRC_FILES += \
KeyBuffer.cpp \
Keymaster4.cpp
Keymaster4.cpp \
main.cpp

LOCAL_SHARED_LIBRARIES += \
[email protected] \
libkeymaster4support
libbinder \
libhidlbase \
libkeymaster4support \
libutils

include $(BUILD_EXECUTABLE)
46 changes: 46 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2020 Erfan Abdi <[email protected]>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Keymaster4.h"

/* Maximum allowed keymaster blob size. */
#define KEYMASTER_BLOB_SIZE 2048

#define RSA_KEY_SIZE 2048
#define RSA_KEY_SIZE_BYTES (RSA_KEY_SIZE / 8)
#define RSA_EXPONENT 0x10001
#define KEYMASTER_CRYPTFS_RATE_LIMIT 1 // Maximum one try per second

int main(int argc, char *argv[]) {
unsigned char keymaster_blob[KEYMASTER_BLOB_SIZE];
unsigned int keymaster_blob_size = 0;
memset(keymaster_blob, 0, KEYMASTER_BLOB_SIZE);

printf("Generating dummy keypair\n");
int rc = keymaster_create_key_for_cryptfs_scrypt(RSA_KEY_SIZE, RSA_EXPONENT, KEYMASTER_CRYPTFS_RATE_LIMIT, keymaster_blob, KEYMASTER_BLOB_SIZE, &keymaster_blob_size);
if (rc) {
if (keymaster_blob_size > KEYMASTER_BLOB_SIZE) {
printf("Keymaster key blob to large\n");
keymaster_blob_size = 0;
}
printf("Failed to generate keypair\n");
return -1;
}
return 0;
}

0 comments on commit 2fa1bb5

Please sign in to comment.