2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <openssl/dh.h>
19 #include <tzplatform_config.h>
21 #define RIURL "http://appdrm.test.com/"
23 #define RO_ISSUER_SIGNER_KEY_FILE tzplatform_mkpath(TZ_SYS_DATA, "drm_test/Key/ro_test_signer.key")
25 #define STR_PLACE_HOLDER_CID "PLACE_HOLDER_FOR_CID"
26 #define STR_PLACE_HOLDER_DUID "PLACE_HOLDER_FOR_DUID"
27 #define STR_PLACE_HOLDER_SIGNATURE "PLACE_HOLDER_FOR_SIGNATURE"
29 #define MAX_CERT_SIZE (1024*128)
31 #define DRMTEST_SUCCESS ( 0)
32 #define DRMTEST_ERR_CRYPTO (-1)
33 #define DRMTEST_ERR_IO (-2)
34 #define DRMTEST_ERR_MEMORY (-3)
35 #define DRMTEST_ERR_TIZDRM (-4)
36 #define DRMTEST_ERR_PARAM (-5)
38 #define DRMTEST_IDENTICAL ( 0)
39 #define DRMTEST_NOTIDENTICAL (-1)
41 #define DRMTEST_TEST_ROOT_CERT (1)
42 #define DRMTEST_REAL_ROOT_CERT (2)
44 #define EVP_SUCCESS 1 // DO NOTCHANGE THIS VALUE
46 int generate_purchase_response(char** purchase_response_buff, char** req_id);
48 int generate_right_object_request(const char* license_response_buff);
50 int get_dh_key_from_ro_request(const char* ro_request_buff,
51 char** dh_key_p, char** dh_key_g, char** dh_key_a);
53 int generate_right_object_response(const char* dh_key_p, const char* dh_key_g, const char* dh_key_a,
54 const char* req_id, const char* cid, const char* ro_template_path,
55 const char* duid, char** ro_response_buff);
56 int is_identical_files(const char* file1, const char* file2, int* identical);
58 int switch_root_cert(int target_cert_type);
61 void _base64_encode(const unsigned char* input, int len, char** output);
62 void _base64_decode(const char* input, unsigned char** output, int* out_len);
63 char* _replace_all(char *s, const char *olds, const char *news);
64 int _read_text_file(const char* path, char** output);
66 int _create_dh_key(const char* dh_key_p_hex, const char* dh_key_g_hex, DH** ppkey);
67 int _free_dh_key(DH* pkey);
68 int _get_dh_hex_pubkey(const DH* pkey, char** dh_pubkey);
69 int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey,
70 unsigned char** dh_shared_secret_key, int *dh_sec_key_len);
72 int _create_right_object_without_signature(const char* ro_template_path, const char* cid, const char* duid,
74 int _create_ro_signature(const char* ro_buff, const char* signer_prikey_path, char** signature);
75 int _add_signature_to_ro(const char* ro_buff, const char* signature, char** ro_with_signature);
76 int _encrypt_ro_with_dh_sec_key(const char* ro_with_signature,
77 const unsigned char* dh_secret_key, const int dh_sec_key_len,
80 int _create_response_data_in_ro_response(const char* reqid, const char* encrypted_ro, const char* dh_pubkey,
81 char **response_data);
83 int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp);
86 using Binary = std::vector<unsigned char>;
87 Binary _read_ro_file(const char *filename);