Synchronize with tizen 2.4
[platform/core/security/drm-service-core-tizen.git] / test / drm_testutil.h
1 /*
2  * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <openssl/dh.h>
18 #include <tzplatform_config.h>
19
20
21 #define RIURL "http://appdrm.test.com/"
22
23 #define RO_ISSUER_SIGNER_KEY_FILE tzplatform_mkpath(TZ_SYS_DATA, "drm_test/Key/ro_test_signer.key")
24
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"
28
29 #define MAX_CERT_SIZE      (1024*128)
30
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)
37
38 #define DRMTEST_IDENTICAL     ( 0)
39 #define DRMTEST_NOTIDENTICAL  (-1)
40
41 #define DRMTEST_TEST_ROOT_CERT (1)
42 #define DRMTEST_REAL_ROOT_CERT (2)
43
44 #define EVP_SUCCESS 1   // DO NOTCHANGE THIS VALUE
45
46 int generate_purchase_response(char** purchase_response_buff, char** req_id);
47
48 int generate_right_object_request(const char* license_response_buff,
49                               char** ro_request_buff);
50
51 int get_dh_key_from_ro_request(const char* ro_request_buff,
52                               char** dh_key_p, char** dh_key_g, char** dh_key_a);
53
54 int generate_right_object_response(const char* dh_key_p, const char* dh_key_g, const char* dh_key_a,
55                               const char* req_id, const char* cid, const char* ro_template_path,
56                               const char* duid, char** ro_response_buff);
57 int is_identical_files(const char* file1, const char* file2, int* identical);
58
59 int switch_root_cert(int target_cert_type);
60
61
62 void _base64_encode(const unsigned char* input, int len, char** output);
63 void _base64_decode(const char* input, unsigned char** output, int* out_len);
64 char* _replace_all(char *s, const char *olds, const char *news);
65 int _read_text_file(const char* path, char** output);
66
67 int _create_dh_key(const char* dh_key_p_hex, const char* dh_key_g_hex, DH** ppkey);
68 int _free_dh_key(DH* pkey);
69 int _get_dh_hex_pubkey(const DH* pkey, char** dh_pubkey);
70 int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey,
71                                 unsigned char** dh_shared_secret_key, int *dh_sec_key_len);
72
73 int _create_right_object_without_signature(const char* ro_template_path, const char* cid, const char* duid,
74                                char** ro_buff);
75 int _create_ro_signature(const char* ro_buff, const char* signer_prikey_path, char** signature);
76 int _add_signature_to_ro(const char* ro_buff, const char* signature, char** ro_with_signature);
77 int _encrypt_ro_with_dh_sec_key(const char* ro_with_signature, 
78                                 const unsigned char* dh_secret_key, const int dh_sec_key_len, 
79                                 char **encrypted_ro);
80
81 int _create_response_data_in_ro_response(const char* reqid, const char* encrypted_ro, const char* dh_pubkey,
82                                 char **response_data); 
83
84 int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp);
85
86