diff --git a/libwvdrmengine/factory_upload_tool/Android.bp b/libwvdrmengine/factory_upload_tool/Android.bp
new file mode 100644
index 00000000..03a017f0
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/Android.bp
@@ -0,0 +1,52 @@
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "vendor_widevine_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ // legacy_by_exception_only (by exception only)
+ default_applicable_licenses: ["vendor_widevine_license"],
+}
+
+
+
+cc_binary {
+ name: "android.hardware.security.keymint-service.widevine",
+ relative_install_path: "hw",
+ init_rc: ["android.hardware.security.keymint-service.widevine.rc"],
+ vintf_fragments: [
+ "android.hardware.security.keymint-service.widevine.xml",
+ ],
+ vendor: true,
+ cflags: [
+ "-Wall",
+ "-Wextra",
+ ],
+ shared_libs: [
+ "android.hardware.security.keymint-V2-ndk",
+ "libbase",
+ "libbinder_ndk",
+ "libcppbor_external",
+ "libcrypto",
+ "libkeymaster_portable",
+ "libkeymint",
+ "liblog",
+ "libpuresoftkeymasterdevice",
+ "libutils",
+ "libcppcose_rkp",
+ ],
+ srcs: [
+ "service.cpp",
+ "src/log.cpp",
+ "src/properties_android.cpp",
+ "src/WidevineRemotelyProvisionedComponent.cpp",
+ "src/WidevineProvisioner.cpp",
+ "src/WidevineOemcryptoInterface.cpp",
+ ],
+ include_dirs: [
+ "vendor/widevine/libwvdrmengine/oemcrypto/include",
+ "vendor/widevine/libwvdrmengine/cdm/util/include",
+ "vendor/widevine/libwvdrmengine/factory_upload_tool/include",
+ ],
+}
+
diff --git a/libwvdrmengine/factory_upload_tool/README b/libwvdrmengine/factory_upload_tool/README
new file mode 100644
index 00000000..af5b1353
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/README
@@ -0,0 +1 @@
+This folder contains Widevine's implementation of Android Remote Provisioning HAL, which is used as part of provisioning 4.0 process. It is intented for factory usage only, and should not be present on user devices.
\ No newline at end of file
diff --git a/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.rc b/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.rc
new file mode 100644
index 00000000..43d0d5f5
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.rc
@@ -0,0 +1,4 @@
+service vendor.keymint-widevine /vendor/bin/hw/android.hardware.security.keymint-service.widevine
+ class early_hal
+ user nobody
+ group drmrpc
\ No newline at end of file
diff --git a/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.xml b/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.xml
new file mode 100644
index 00000000..723026ae
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/android.hardware.security.keymint-service.widevine.xml
@@ -0,0 +1,6 @@
+
+
+ android.hardware.security.keymint
+ IRemotelyProvisionedComponent/widevine
+
+
diff --git a/libwvdrmengine/factory_upload_tool/include/WidevineOemcryptoInterface.h b/libwvdrmengine/factory_upload_tool/include/WidevineOemcryptoInterface.h
new file mode 100644
index 00000000..be355532
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/include/WidevineOemcryptoInterface.h
@@ -0,0 +1,52 @@
+// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
+// source code may only be used and distributed under the Widevine License
+// Agreement.
+
+#ifndef WIDEVINE_OEMCRYPTO_INTERFACE_H_
+#define WIDEVINE_OEMCRYPTO_INTERFACE_H_
+
+#include
+#include
+#include
+
+#include "OEMCryptoCENC.h"
+
+namespace widevine {
+
+class OEMCryptoInterface {
+ public:
+ OEMCryptoInterface() = default;
+ OEMCryptoInterface(const OEMCryptoInterface&) = delete;
+ OEMCryptoInterface& operator=(const OEMCryptoInterface&) = delete;
+ virtual ~OEMCryptoInterface();
+
+ // Initializes this interface by providing path to the OEMCrypto library.
+ bool Init(const std::string& oemcrypto_path);
+
+ // Retrieves the boot certificate chain from OEMCrypto implementation.
+ OEMCryptoResult GetBcc(std::vector& bcc);
+
+ // Retrieves the build information of the OEMCrypto library from OEMCrypto
+ // implementation.
+ OEMCryptoResult GetOEMCryptoBuildInfo(std::string& build_info);
+
+ private:
+ typedef OEMCryptoResult (*Initialize_t)();
+ typedef OEMCryptoResult (*Terminate_t)();
+ typedef OEMCryptoResult (*GetBootCertificateChain_t)(
+ uint8_t* bcc, size_t* bcc_size, uint8_t* additional_signature,
+ size_t* additional_signature_size);
+ typedef OEMCryptoResult (*BuildInformation_t)(char* buffer,
+ size_t* buffer_length);
+
+ Initialize_t Initialize = nullptr;
+ Terminate_t Terminate = nullptr;
+ GetBootCertificateChain_t GetBootCertificateChain = nullptr;
+ BuildInformation_t BuildInformation = nullptr;
+
+ void* handle_ = nullptr;
+};
+
+} // namespace widevine
+
+#endif // WIDEVINE_OEMCRYPTO_INTERFACE_H_
\ No newline at end of file
diff --git a/libwvdrmengine/factory_upload_tool/include/WidevineProvisioner.h b/libwvdrmengine/factory_upload_tool/include/WidevineProvisioner.h
new file mode 100644
index 00000000..41014642
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/include/WidevineProvisioner.h
@@ -0,0 +1,50 @@
+// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
+// source code may only be used and distributed under the Widevine License
+// Agreement.
+
+#ifndef WIDEVINE_PROVISIONER_H_
+#define WIDEVINE_PROVISIONER_H_
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include "WidevineOemcryptoInterface.h"
+
+namespace widevine {
+
+class WidevineProvisioner {
+ public:
+ WidevineProvisioner();
+ WidevineProvisioner(const WidevineProvisioner&) = delete;
+ WidevineProvisioner& operator=(const WidevineProvisioner&) = delete;
+ virtual ~WidevineProvisioner() = default;
+
+ bool GenerateCertificateRequest(
+ bool testMode, const std::vector& endpointEncCertChain,
+ std::vector& deviceInfo, std::vector& protectedData);
+
+ private:
+ bool GetDeviceInfo(std::vector& device_info);
+ bool GenerateProtectedData(
+ bool test_mode,
+ const std::vector& endpoint_encryption_cert_chain,
+ std::vector bcc, std::vector& protected_data) const;
+ bool ValidateAndExtractEekPubAndId(
+ bool test_mode,
+ const std::vector& endpoint_encryption_cert_chain,
+ std::vector* eek_pub, std::vector* eek_id) const;
+ cppbor::Array BuildCertReqRecipients(const std::vector& pubkey,
+ const std::vector& kid) const;
+ void InitializeCryptoInterface();
+
+ std::unique_ptr crypto_interface_;
+};
+
+} // namespace widevine
+
+#endif // WIDEVINE_PROVISIONER_H_
diff --git a/libwvdrmengine/factory_upload_tool/include/WidevineRemotelyProvisionedComponent.h b/libwvdrmengine/factory_upload_tool/include/WidevineRemotelyProvisionedComponent.h
new file mode 100644
index 00000000..2a107b58
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/include/WidevineRemotelyProvisionedComponent.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2021, 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
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "WidevineProvisioner.h"
+
+namespace aidl::android::hardware::security::keymint {
+
+class WidevineRemotelyProvisionedComponent
+ : public BnRemotelyProvisionedComponent {
+ using ScopedAStatus = ::ndk::ScopedAStatus;
+
+ public:
+ WidevineRemotelyProvisionedComponent() = default;
+ virtual ~WidevineRemotelyProvisionedComponent() = default;
+
+ ScopedAStatus getHardwareInfo(RpcHardwareInfo* info) override;
+
+ ScopedAStatus generateEcdsaP256KeyPair(
+ bool testMode, MacedPublicKey* macedPublicKey,
+ std::vector* privateKeyHandle) override;
+
+ ScopedAStatus generateCertificateRequest(
+ bool testMode, const std::vector& keysToSign,
+ const std::vector& endpointEncCertChain,
+ const std::vector& challenge, DeviceInfo* deviceInfo,
+ ProtectedData* protectedData,
+ std::vector* keysToSignMac) override;
+
+ private:
+ std::unique_ptr provisioner_;
+};
+
+} // namespace aidl::android::hardware::security::keymint
diff --git a/libwvdrmengine/factory_upload_tool/include/properties.h b/libwvdrmengine/factory_upload_tool/include/properties.h
new file mode 100644
index 00000000..d61394f8
--- /dev/null
+++ b/libwvdrmengine/factory_upload_tool/include/properties.h
@@ -0,0 +1,34 @@
+// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
+// source code may only be used and distributed under the Widevine License
+// Agreement.
+
+#ifndef WVCDM_CORE_PROPERTIES_H_
+#define WVCDM_CORE_PROPERTIES_H_
+
+#include