Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. // Generate nested ACL
  2. M_ACL nestedAcl;
  3. memset(&nestedAcl, 0, sizeof(M_ACL));
  4. nestedAcl.n_groups = 1;
  5.  
  6. M_PermissionGroup nestedAclPermGroup;
  7. memset(&nestedAclPermGroup, 0, sizeof(M_PermissionGroup));
  8. nestedAclPermGroup.n_actions = 1;
  9. nestedAclPermGroup.flags = 0x0;
  10. nestedAclPermGroup.n_limits = 0;
  11. nestedAclPermGroup.certifier = NULL;
  12.  
  13. M_Action nestedAclAction0;
  14. memset(&nestedAclAction0, 0, sizeof(M_Action));
  15. nestedAclAction0.type = Act_OpPermissions;
  16. nestedAclAction0.details.oppermissions.perms =
  17. Act_OpPermissions_Details_perms_Encrypt;
  18.  
  19. nestedAclPermGroup.actions = &nestedAclAction0;
  20. nestedAcl.groups = &nestedAclPermGroup;
  21.  
  22. M_ByteBlock nestedAclBytes;
  23.  
  24. ret = NFastApp_MarshalACL(app, *connection, worldInfo, &nestedAcl, &nestedAclBytes);
  25. if (ret != Status_OK)
  26. {
  27. printf("Failed to create nested ACL: ret = %d n", ret);
  28. }
  29.  
  30. // Import template key
  31. M_Command importTemplateKeyCmd;
  32. M_Reply importTemplateKeyReply;
  33. importTemplateKeyCmd.cmd = Cmd_Import;
  34. importTemplateKeyCmd.args.import.data.type = KeyType_DKTemplate;
  35. importTemplateKeyCmd.args.import.data.data.dktemplate.nested_acl = nestedAclBytes;
  36.  
  37. char appdataTemplateKey[] = "02020202";
  38. memset(&appdataTemplateKey, 0, sizeof(M_AppData));
  39. memcpy(importTemplateKeyCmd.args.import.appdata.bytes, appdataTemplateKey, strlen(appdataTemplateKey) < 64 ? strlen(appdataTemplateKey) : 63);
  40.  
  41. // Generate the import command ACL
  42. NFKM_MakeACLParams templateKeyAclParams;
  43. memset(&templateKeyAclParams, 0, sizeof(templateKeyAclParams));
  44. templateKeyAclParams.f = 0x0;
  45. templateKeyAclParams.op_base = Act_DeriveKey;
  46. templateKeyAclParams.timelimit = 0;
  47.  
  48. M_ACL* templateKeyAcl;
  49. templateKeyAcl = malloc(sizeof(M_ACL));
  50. templateKeyAcl->n_groups = 1;
  51. /*
  52. M_PermissionGroup* templateKeyAclPermissionGroup;
  53. templateKeyAclPermissionGroup = malloc(sizeof(M_PermissionGroup));
  54. templateKeyAclPermissionGroup->flags = 0x0;
  55. templateKeyAclPermissionGroup->n_limits = 0;
  56. templateKeyAclPermissionGroup->n_actions = 1;
  57. templateKeyAclPermissionGroup->certifier = NULL;
  58.  
  59. M_Action* templateKeyAction;
  60. templateKeyAction = malloc(sizeof(M_Action));
  61. templateKeyAction->type = Act_DeriveKey;
  62. templateKeyAction->details.derivekey.flags = 0x0;
  63. templateKeyAction->details.derivekey.role = DeriveRole_TemplateKey;
  64. templateKeyAction->details.derivekey.mech = Mech_Any;
  65. templateKeyAction->details.derivekey.n_otherkeys = 0;
  66.  
  67. templateKeyAclPermissionGroup->actions = templateKeyAction;
  68.  
  69. templateKeyAcl->groups = templateKeyAclPermissionGroup;
  70. */
  71. // NF_MarshalFast_ACL(*connection, templateKeyAcl);
  72.  
  73. NFKM_MkACLHandle mkAclHandle;
  74. mkAclHandle = malloc(sizeof(mkAclHandle));
  75. NFKM_mkacl_create(app, *connection, &mkAclHandle, 0);
  76. NFKM_mkacl_pgroup(mkAclHandle, 0x0, NULL);
  77. NFKM_mkacl_derivekey(mkAclHandle, 0x0, DeriveRole_TemplateKey, DeriveMech_Any);
  78. NFKM_mkacl_setacl(mkAclHandle, templateKeyAcl);
  79. importTemplateKeyCmd.args.import.acl = *templateKeyAcl;
  80.  
  81. ret = (M_Status)NFastApp_Transact(*connection, 0, &importTemplateKeyCmd, &importTemplateKeyReply, 0);
  82. if (ret != Status_OK)
  83. {
  84. printf("Failed to import template key: %d (%d)n", ret, importTemplateKeyReply.status);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement