Fix svace defects
[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 #ifndef __DRM_TESTUTIL_H_
17 #define __DRM_TESTUTIL_H_
18
19 #include <vector>
20 #include <openssl/dh.h>
21 #include <tzplatform_config.h>
22
23 #define RIURL "http://appdrm.test.com/"
24
25 #define RO_ISSUER_SIGNER_KEY_FILE TEST_DATA_DIR "/Key/ro_test_signer.key"
26
27 #define STR_PLACE_HOLDER_CID        "PLACE_HOLDER_FOR_CID"
28 #define STR_PLACE_HOLDER_DUID       "PLACE_HOLDER_FOR_DUID"
29 #define STR_PLACE_HOLDER_SIGNATURE  "PLACE_HOLDER_FOR_SIGNATURE"
30
31 #define MAX_CERT_SIZE      (1024 * 128)
32
33 #define DRMTEST_SUCCESS       (0)
34 #define DRMTEST_ERR_CRYPTO    (-1)
35 #define DRMTEST_ERR_IO        (-2)
36 #define DRMTEST_ERR_MEMORY    (-3)
37 #define DRMTEST_ERR_TIZDRM    (-4)
38 #define DRMTEST_ERR_PARAM     (-5)
39
40 #define DRMTEST_IDENTICAL     (0)
41 #define DRMTEST_NOTIDENTICAL  (-1)
42
43 #define DRMTEST_TEST_ROOT_CERT (1)
44 #define DRMTEST_REAL_ROOT_CERT (2)
45
46 #define EVP_SUCCESS 1   // DO NOTCHANGE THIS VALUE
47
48 int generate_purchase_response(char **purchase_response_buff, char **req_id);
49
50 int generate_right_object_request(const char *license_response_buff);
51
52 int get_dh_key_from_ro_request(const char *ro_request_buff, char **dh_key_p,
53                                                            char **dh_key_g, char **dh_key_a);
54
55 int generate_right_object_response(const char *dh_key_p, const char *dh_key_g,
56                                                                    const char *dh_key_a, const char *req_id, const char *cid,
57                                                                    const char *ro_template_path, const char *duid,
58                                                                    char **ro_response_buff);
59 int is_identical_files(const char *file1, const char *file2, int *identical);
60
61 int switch_root_cert(int target_cert_type);
62
63
64 void _base64_encode(const unsigned char *input, int len, char **output);
65 void _base64_decode(const char *input, unsigned char **output, int *out_len);
66 char *_replace_all(char *s, const char *olds, const char *news);
67 int _read_text_file(const char *path, char **output);
68
69 int _create_dh_key(const char *dh_key_p_hex, const char *dh_key_g_hex,
70                                    DH **ppkey);
71 int _free_dh_key(DH *pkey);
72 int _get_dh_hex_pubkey(const DH *pkey, char **dh_pubkey);
73 int _get_dh_shared_secret_key(const char *dh_hex_pubkey, DH *pkey,
74                                                           unsigned char **dh_shared_secret_key, int *dh_sec_key_len);
75
76 int _create_right_object_without_signature(const char *ro_template_path,
77                 const char *cid, const char *duid, char **ro_buff);
78 int _create_ro_signature(const char *ro_buff, const char *signer_prikey_path,
79                                                  char **signature);
80 int _add_signature_to_ro(const char *ro_buff, const char *signature,
81                                                  char **ro_with_signature);
82 int _encrypt_ro_with_dh_sec_key(const char *ro_with_signature,
83                                                                 const unsigned char *dh_secret_key, const int dh_sec_key_len,
84                                                                 char **encrypted_ro);
85
86 int _create_response_data_in_ro_response(const char *reqid,
87                 const char *encrypted_ro, const char *dh_pubkey, char **response_data);
88
89 int _create_time_stamp(const unsigned char *dh_secret_key, char **time_stamp);
90
91
92 using Binary = std::vector<unsigned char>;
93 Binary _read_ro_file(const char *filename);
94
95 #endif //__DRM_TESTUTIL_H_