@@ -84,7 +84,10 @@ public static void init(String[] args) {
84
84
client = new Client (networkURL , adminName , adminEmail , adminPrivateKey );
85
85
}
86
86
87
- // user commands
87
+ /*
88
+ * USER MANAGEMENT USERS COMMANDS
89
+ */
90
+
88
91
public static void createUser (String [] args ){
89
92
String name = args [1 ];
90
93
String email = args [2 ];
@@ -110,7 +113,9 @@ public static void load(String[] args){
110
113
client .setActiveUser (args [1 ]);
111
114
}
112
115
113
- // DCPABE commands
116
+ /*
117
+ * DCPABE COMMANDS
118
+ */
114
119
115
120
public static void createAttributes (String [] args ){
116
121
String [] attributes = new String [args .length - 1 ];
@@ -139,7 +144,9 @@ public static void decrypt(String[] args){
139
144
140
145
}
141
146
142
- // blockchain commands
147
+ /*
148
+ * BLOCKCHAIN COMMANDS
149
+ */
143
150
144
151
public static void requestAttributes (String [] args ){
145
152
String [] attributes = new String [args .length - 2 ];
@@ -171,7 +178,9 @@ public static void publish(String[] args){
171
178
}
172
179
}
173
180
174
- // integrated blockchain / server commands
181
+ /*
182
+ * NETWORK (BLOCKCHAIN / FILE SERVER) COMMANDS
183
+ */
175
184
public static void send (String [] args ){
176
185
if (args [1 ].equals ("attributes" )) {
177
186
for (int i = 2 ; i < args .length ; i ++) {
@@ -192,15 +201,14 @@ public static void getRecordings(String[] args){
192
201
client .getRecordings (args [1 ], recordings );
193
202
}
194
203
195
- // demonstration command
204
+ /*
205
+ * DEMONSTRATION OF USE CASES
206
+ */
196
207
public static void milestone (String [] args ){
197
- // parsing necessary to navigate through milestone function
198
- String [] numberSplit = args [1 ].split ("\\ ." );
199
- int [] choices = new int [numberSplit .length ];
200
- for (int i = 0 ; i < choices .length ; i ++) {
201
- choices [i ] = Integer .parseInt (numberSplit [i ]);
202
- }
203
- runMilestone (choices );
208
+ String [] choice = args [1 ].split ("\\ ." );
209
+ int scenario = Integer .parseInt (choice [0 ]);
210
+ int subScenario = (choice .length == 2 ? Integer .parseInt (choice [0 ]) : 0 );
211
+ runMilestone (scenario , subScenario );
204
212
}
205
213
206
214
public static void help (String [] args ){
@@ -267,75 +275,96 @@ public static void runCommand(String[] args) {
267
275
client .decrypt (args [1 ]);
268
276
break ;
269
277
default :
270
- System .out .println ("Comando não reconhecido : " + String .join (" " , args ));
278
+ System .out .println ("Command is not valid : " + String .join (" " , args ));
271
279
}
272
280
}
273
281
274
- public static void runMilestone (int [] choice ) {
282
+ public static void runMilestone (int scenario , int subScenario ) {
283
+ if ((scenario > 2 ) ||
284
+ (scenario == 1 && subScenario != 0 ) ||
285
+ (scenario == 2 && (subScenario < 1 || subScenario > 3 ))) {
286
+ String subScenario_ = (subScenario == 0 ? "" : "." + subScenario );
287
+ System .out .println (String .format ("Milestone invalid: %s%s" , scenario , subScenario_ ));
288
+ System .exit (-1 );
289
+ }
290
+
291
+ PersonData admin = new PersonData (
292
+ "admin" ,
293
+ "0xFae373E0BFfaE794fA818D749D6da38D4f7cA986" ,
294
+ "e4d8c81796894ea5bf202e3a3204948dddd62f4d709c278bf8096898957be241"
295
+ );
296
+ PersonData crm = new PersonData (
297
+ "crm" ,
298
+ "0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" ,
299
+ "e15b910f8c61580befebecff2d79abf38998035cbc317400a96c4736a424f6dc"
300
+ );
301
+ PersonData alice = new PersonData (
302
+ "Alice" ,
303
+ "0xb038476875480BCE0D0FCf0991B4BB108A3FCB47" ,
304
+ "4237a475aa6579f2a0fc85d90cbcda1fad3db70391315a6c37b51de3a8cb503a"
305
+ );
306
+ PersonData bob = new PersonData (
307
+ "Bob" ,
308
+ "0xF7908374b1a445cCf65F729887dbB695c918BEfc" ,
309
+ "ab0439882857ffb5859c1a3a6bf40a6848daeaab6605c873c3e425de53c2c4ab"
310
+ );
311
+
275
312
/**
276
313
* Milestone 1 cenário: novo prontuário Cliente 1 java usa o código do ABE (cria
277
314
* usuário, obtém atributo1, envia prontuário1 - i.e., pdf1 encriptado) Cliente
278
315
* 2 java usa o código do ABE (supondo que possui o atributo1, obtém prontuário1
279
316
* codificado e o decodifica)
280
317
*/
281
318
String args ;
282
- if (choice [ 0 ] == 1 ) {
319
+ if (scenario == 1 ) {
283
320
// pre-setup to deliver file to be encrypted to user folder
284
- String path = "data/client/Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47/" ;
321
+ String path = String . format ( "data/client/%s/" , alice . gid ) ;
285
322
new File (path ).mkdirs ();
286
- getFileFromResources (path , "test /lorem_ipsum.md" , "lorem_ipsum.md" );
323
+ getFileFromResources (path , "demo /lorem_ipsum.md" , "lorem_ipsum.md" );
287
324
288
325
// admin inicia o sistema e cria os contratos
289
- args =
"--init http://127.0.0.1:7545 admin [email protected] " ;
290
- args = args + "e4d8c81796894ea5bf202e3a3204948dddd62f4d709c278bf8096898957be241" ;
326
+ args = String .format ("--init http://127.0.0.1:7545 %s %s %s" , admin .name , admin .email , admin .pKey );
291
327
init (args .split (" " ));
292
328
293
329
// certificador cria perfil e atributo, e os publica
294
- args =
"--create-user CRM [email protected] " ;
295
- args = args + "e15b910f8c61580befebecff2d79abf38998035cbc317400a96c4736a424f6dc" ;
296
- runCommand (args .split (" " ));
330
+ runCommand (String .format ("--create-user %s %s %s " , crm .name , crm .email , crm .pKey ).split (" " ));
297
331
runCommand ("--create-certifier" .split (" " ));
298
332
runCommand ("--create-attributes atributo1 atributo2 atributo3" .split (" " ));
299
333
runCommand ("--publish user certifier attributes" .split (" " ));
300
334
301
335
// usuário 1 - Bob, cria perfil e solicita concessão do atributo 1 (chave pessoal ABE)
302
- args =
"--create-user Bob [email protected] " ;
303
- args = args + "ab0439882857ffb5859c1a3a6bf40a6848daeaab6605c873c3e425de53c2c4ab" ;
304
- runCommand (args .split (" " ));
336
+ runCommand (String .format ("--create-user %s %s %s " , bob .name , bob .email , bob .pKey ).split (" " ));
305
337
runCommand ("--publish user" .split (" " ));
306
- runCommand ("--load Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
307
- runCommand ("--request-attribute CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0 atributo1" .split (" " ));
338
+ runCommand (String .format ("--request-attribute %s atributo1" , crm .gid ).split (" " ));
308
339
309
340
// usuário 2 - Alice, cria perfil, recebe chaves públicas e criptografa um documento
310
- args =
"--create-user Alice [email protected] " ;
311
- args = args + "4237a475aa6579f2a0fc85d90cbcda1fad3db70391315a6c37b51de3a8cb503a" ;
312
- runCommand (args .split (" " ));
341
+ runCommand (String .format ("--create-user %s %s %s " , alice .name , alice .email , alice .pKey ).split (" " ));
313
342
runCommand ("--publish user" .split (" " ));
314
- runCommand ("--load Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47" .split (" " ));
315
- runCommand ("--get-attributes CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0 atributo1" .split (" " ));
316
- runCommand ("--encrypt lorem_ipsum.md atributo1 CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" .split (" " ));
343
+ runCommand (String .format ("--get-attributes %s atributo1" , crm .gid ).split (" " ));
344
+ runCommand (String .format ("--encrypt lorem_ipsum.md atributo1 %s" , crm .gid ).split (" " ));
317
345
runCommand ("--send lorem_ipsum.md" .split (" " ));
318
346
319
347
// certificador recebe requisição de atributo e o concede ao Bob
320
- runCommand ("--load CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" .split (" " ));
348
+ runCommand (String . format ( "--load %s" , crm . gid ) .split (" " ));
321
349
runCommand ("--check-requests pending" .split (" " ));
322
- runCommand ("--yield-attributes Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc 0" .split (" " ));
323
- runCommand ("--send attributes Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
350
+ runCommand (String . format ( "--yield-attributes %s 0" , bob . gid ) .split (" " ));
351
+ runCommand (String . format ( "--send attributes %s" , bob . gid ) .split (" " ));
324
352
325
353
// usuário 1 - Bob, de posse do atributo, o descriptografa
326
- runCommand ("--load Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
354
+ runCommand (String . format ( "--load %s" , bob . gid ) .split (" " ));
327
355
runCommand ("--check-requests ok" .split (" " ));
328
356
runCommand ("--check-requests download" .split (" " ));
329
- runCommand ("--get-recordings Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47 lorem_ipsum.md" .split (" " ));
357
+ runCommand (String . format ( "--get-recordings %s lorem_ipsum.md" , alice . gid ) .split (" " ));
330
358
runCommand ("--decrypt lorem_ipsum.md" .split (" " ));
331
359
}
332
360
333
- if (choice [ 0 ] == 2 ) {
361
+ if (scenario == 2 ) {
334
362
// pre-setup to deliver file to be encrypted to user folder
335
- String path = "data/client/Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47/" ;
363
+ String path = String . format ( "data/client/%s/" , alice . gid ) ;
336
364
new File (path ).mkdirs ();
337
- getFileFromResources (path , "test /lorem_ipsum2.md" , "lorem_ipsum2.md" );
365
+ getFileFromResources (path , "demo /lorem_ipsum2.md" , "lorem_ipsum2.md" );
338
366
367
+ runMilestone (1 , 0 );
339
368
/**
340
369
* cenário: novo prontuário
341
370
* Cliente 1 java (usuário já criado) obtém novos atributos: atributo2 e
@@ -344,15 +373,13 @@ public static void runMilestone(int[] choice) {
344
373
* java (só com atributo1) tenta mas não consegue obter o prontuário2 (nem
345
374
* decodificá-lo) pois não tem atributos.
346
375
*/
347
- if (choice [1 ] == 1 ) {
348
- runMilestone (new int []{1 });
349
- runCommand ("--load Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47" .split (" " ));
350
- runCommand ("--get-attributes CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0 atributo2 atributo3" .split (" " ));
351
- String [] specialArgs = {"--encrypt" , "lorem_ipsum2.md" , "and atributo2 atributo3" , "CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" };
352
- runCommand (specialArgs );
376
+ if (subScenario == 1 ) {
377
+ runCommand (String .format ("--load %s" , alice .gid ).split (" " ));
378
+ runCommand (String .format ("--get-attributes %s atributo2 atributo3" , crm .gid ).split (" " ));
379
+ runCommand (String .format ("--encrypt lorem_ipsum2.md \" and atributo2 atributo3\" %s" , crm .gid ).split (" " ));
353
380
runCommand ("--send lorem_ipsum2.md" .split (" " ));
354
- runCommand ("--load Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
355
- runCommand ("--get-recordings Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47 lorem_ipsum2.md" .split (" " ));
381
+ runCommand (String . format ( "--load %s" , bob . gid ) .split (" " ));
382
+ runCommand (String . format ( "--get-recordings %s lorem_ipsum2.md" , alice . gid ) .split (" " ));
356
383
runCommand ("--decrypt lorem_ipsum2.md" .split (" " ));
357
384
}
358
385
/**
@@ -362,39 +389,30 @@ public static void runMilestone(int[] choice) {
362
389
* Cliente 2 java obtém prontuário1 codificado e o decodifica (pois possui
363
390
* atributo1 do milestone1).
364
391
*/
365
- if (choice [1 ] == 2 ) {
366
- runMilestone (new int [] { 1 });
367
- getFileFromResources (path , "test/lorem_ipsum-edit.md" , "lorem_ipsum.md" );
368
- runCommand ("--load Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47" .split (" " ));
369
- runCommand ("--encrypt lorem_ipsum.md atributo1 CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" .split (" " ));
392
+ if (subScenario == 2 ) {
393
+ getFileFromResources (path , "demo/lorem_ipsum-edit.md" , "lorem_ipsum.md" );
394
+ runCommand (String .format ("--load %s" , alice .gid ).split (" " ));
395
+ runCommand (String .format ("--encrypt lorem_ipsum.md atributo1 %s" , crm .gid ).split (" " ));
370
396
runCommand ("--send lorem_ipsum.md" .split (" " ));
371
- runCommand ("--load Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
372
- runCommand ("--get-recordings Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47 lorem_ipsum.md" .split (" " ));
397
+ runCommand (String . format ( "--load %s" , bob . gid ) .split (" " ));
398
+ runCommand (String . format ( "--get-recordings %s lorem_ipsum.md" , alice . gid ) .split (" " ));
373
399
runCommand ("--decrypt lorem_ipsum.md" .split (" " ));
374
400
}
375
401
/*
376
402
* Cliente 1 java procura prontuario1 e atualiza: a) atributo1 por atributo1 AND
377
403
* atributo2 e b) dataEnvio. Cliente 2 java (só com atributo1) tenta mas não
378
404
* consegue obter o prontuário1 (nem decodificá-lo) pois não tem atributo2.
379
405
*/
380
- if (choice [1 ] == 3 ) {
381
- runMilestone (new int [] { 1 });
382
- runCommand ("--load Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47" .split (" " ));
383
- runCommand ("--get-attributes CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0 atributo1" .split (" " ));
384
- String [] encryptArgs = { "--encrypt" , "lorem_ipsum.md" , "and atributo1 atributo2" ,
385
- "CRM-0xFB7EAfB7fBdaA775d0D52fAaEBC525C1cE173EE0" };
386
- runCommand (encryptArgs );
406
+ if (subScenario == 3 ) {
407
+ runCommand (String .format ("--load %s" , alice .gid ).split (" " ));
408
+ runCommand (String .format ("--get-attributes %s atributo1" , crm .gid ).split (" " ));
409
+ runCommand (String .format ("--encrypt lorem_ipsum \" and atributo1 atributo2\" %s" , crm .gid ).split (" " ));
387
410
runCommand ("--send lorem_ipsum.md" .split (" " ));
388
- runCommand ("--load Bob-0xF7908374b1a445cCf65F729887dbB695c918BEfc" .split (" " ));
389
- runCommand ("--get-recordings Alice-0xb038476875480BCE0D0FCf0991B4BB108A3FCB47 lorem_ipsum.md" .split (" " ));
411
+ runCommand (String . format ( "--load %s" , bob . gid ) .split (" " ));
412
+ runCommand (String . format ( "--get-recordings %s lorem_ipsum.md" , alice . gid ) .split (" " ));
390
413
runCommand ("--decrypt lorem_ipsum.md" .split (" " ));
391
414
}
392
415
}
393
-
394
- if (choice [0 ] > 2 ) {
395
- System .out .println ("Milestone not recognized." );
396
- System .exit (-1 );
397
- }
398
416
}
399
417
400
418
private static void getFileFromResources (String path , String inputFileName , String outputFileName ) {
@@ -418,4 +436,15 @@ private static void getFileFromResources(String path, String inputFileName, Stri
418
436
}
419
437
}
420
438
}
439
+ private static class PersonData {
440
+ public String name , email , address , gid , pKey ;
441
+
442
+ public PersonData (String name , String address , String privateKey ) {
443
+ this .name = name ;
444
+ this .email = name .toLowerCase () + "@email.com" ;
445
+ this .address = address ;
446
+ this .gid = name + "-" + this .address ;
447
+ this .pKey = privateKey ;
448
+ }
449
+ }
421
450
}
0 commit comments