From 9306b129fd16210c8638efd036ea0a9e5abe1d69 Mon Sep 17 00:00:00 2001 From: Dongsun Lee Date: Tue, 7 Jul 2015 11:25:07 +0900 Subject: [PATCH] [Tutorial][key-manager]replace deprecated APIs(ckmc_load_from_pkcs12_file,ckmc_remove_key,ckmc_remove_cert,ckmc_remove_data,ckmc_allow_access,ckmc_deny_access) to new APIs Change-Id: I47a442e105c2fa4892b7e9a6393a7fc02693e037 Signed-off-by: Dongsun Lee --- .../html/native/security/key_tutorial_n.htm | 63 +++++++++++++--------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/org.tizen.tutorials/html/native/security/key_tutorial_n.htm b/org.tizen.tutorials/html/native/security/key_tutorial_n.htm index 4a93e91..22e1e2f 100644 --- a/org.tizen.tutorials/html/native/security/key_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/security/key_tutorial_n.htm @@ -187,12 +187,24 @@ int ret = CKMC_ERROR_NONE; const char* alias= "mykey"; -ret = ckmc_remove_key(alias); +ret = ckmc_remove_alias(alias); if (CKMC_ERROR_NONE != ret) {    // Error handling } - + + + + + + + + + + +
Note
Note that a few Key manager APIs have been deprecated since Tizen 2.4. + For example, several ckmc_remove_* () have been replaced by ckmc_remove_alias(). Although the deprecated APIs continue to be available, it is strongly recommended to use new APIs. For more information on the deprecated information, please refer to the Key-manager API References.
+

Saving, Getting, or Removing a Certificate

@@ -302,12 +314,13 @@ int ret = CKMC_ERROR_NONE; const char* alias= "myCert"; -ret = ckmc_remove_cert(alias); +ret = ckmc_remove_alias(alias); if (CKMC_ERROR_NONE != ret) {    // Error handling } - + +

Saving, Getting, or Removing Data

@@ -389,12 +402,13 @@ int ret = CKMC_ERROR_NONE; const char* alias= "myData"; -ret = ckmc_remove_data(alias); +ret = ckmc_remove_alias(alias); if (CKMC_ERROR_NONE != ret) {    // Error handling } - + +

Creating Key Pairs

@@ -900,32 +914,30 @@ ckmc_cert_free(pcert); // Called when the certificate is no longer needed
 int ret = CKMC_ERROR_NONE;
 
-ckmc_key_s *private_key = NULL;
-ckmc_cert_s *cert = NULL;
-ckmc_cert_list_s *ca_cert_list = NULL;
+ckmc_pkcs12_s *ppkcs12 = NULL;
 // defined_media_storage_directory can be obtained with the storage_get_directory() function
 const char *p12file = "<defined_media_storage_directory>/ckmc_p12_test.p12"; 
 const char *password = "password";  // PKCS#12 file can be protected by a password
 
-ret = ckmc_load_from_pkcs12_file(p12file, password, &private_key, &cert, &ca_cert_list);
-if (CKMC_ERROR_NONE != ret)
+ret = ckmc_pkcs12_load(p12file, password, &ppkcs12);
+if (CKMC_ERROR_NONE != ret || ppkcs12 == NULL)
 {
    // Error handling
 }
 
-if (private_key != NULL)
+if (ppkcs12->priv_key != NULL)
 {
    // Check a private key
 }
 
-if (cert != NULL)
+if (ppkcs12->cert != NULL)
 {
    // Check a certificate
 
 }
 
 int cnt = 0;
-ckmc_cert_list_s *tmp_list = ca_cert_list;
+ckmc_cert_list_s *tmp_list = ppkcs12->ca_chain;
 while(tmp_list!= NULL)
 {
    // Check a certificate list
@@ -933,10 +945,9 @@ while(tmp_list!= NULL)
    tmp_list = tmp_list ->next;
 }
 
-ckmc_key_free(private_key); // Called when the key is no longer needed
-ckmc_cert_free(cert); // Called when the certificate is no longer needed
-ckmc_cert_list_all_free(ca_cert_list); // Called when the list is no longer needed
-
+ckmc_pkcs12_free(ppkcs12);; // Called when the pkcs12 data is no longer needed + +

Implementing Access Control

@@ -974,18 +985,19 @@ const char *target1 = "accessor-allow-1"; const char *target2 = "accessor-allow-2"; const char *alias = "targetData"; -ret = ckmc_allow_access(alias, target1, CKMC_AR_READ); // Only allow reading data +ret = ckmc_set_permission(alias, target1, CKMC_PERMISSION_READ); // Only allow reading data if (CKMC_ERROR_NONE != ret) {    // Error handling } -ret = ckmc_allow_access(alias, target2, CKMC_AR_READ_REMOVE); // Allow reading and deleting data +ret = ckmc_set_permission(alias, target2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE); // Allow reading and deleting data if (CKMC_ERROR_NONE != ret) {    // Error handling } - + +
  • Set a rule to deny access:

    @@ -994,19 +1006,20 @@ int ret = CKMC_ERROR_NONE;
     const char *target = "denied-accessor";
     const char *alias = "targetData";
     
    -ret = ckmc_allow_access(alias, target, CKMC_AR_READ); // Allow the target user to a read (alias)
    +ret = ckmc_set_permission(alias, target, CKMC_PERMISSION_READ); // Allow the target user to a read (alias)
     if (CKMC_ERROR_NONE != ret)
     {
        // Error handling
     }
     
    -ret = ckmc_deny_access(alias, target); // Deny the target user access to data (alias)
    +ret = ckmc_set_permission(alias, target, CKMC_PERMISSION_NONE); // Deny the target user access to data (alias)
     if (CKMC_ERROR_NONE != ret)
     
     {
        // Error handling
     }
    -
  • + + @@ -1032,4 +1045,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga - \ No newline at end of file + -- 2.7.4