public static int main(string[] args) { if(args.length < 2) { print(@"USAGE: $(args[0]) [COMMAND]\nCommands:\n\tnew [output]: create new PPCL and private key\n\tnew-member [member name]: generates a new keypair for a member\n\tadd-member [collection] [member name] [member key]: add a member to the member register\n\tadd-domain [collection] [DNS name]: add an authorative domain\n\tpublish [collection] [publication] [member]: publish the specified PPUB to the collection\n"); return -1; } if(args[1] == "new") { uint8[] signing_key; var collection = new Ppub.Collection(out signing_key); var col_str = collection.to_string(signing_key); FileUtils.set_contents(args[2], col_str, col_str.length); var key_str = Base64.encode(signing_key); FileUtils.set_contents(args[2] + ".private.key", key_str, key_str.length); return 0; } if(args[1] == "new-member") { uint8[] sk; uint8[] pk; Ppub.CollectionMember.new_keypair(out sk, out pk); var sk_str = Base64.encode(sk); FileUtils.set_contents(args[2] + ".private.key", sk_str, sk_str.length); var pk_str = Base64.encode(pk); FileUtils.set_contents(args[2] + ".public.key", pk_str, pk_str.length); return 0; } var collection_name = args[2]; string key_str; FileUtils.get_contents(args[2] + ".private.key", out key_str, null); var signing_key = Base64.decode(key_str); var collection_stream = new DataInputStream(File.new_for_path(collection_name).read()); var collection = new Ppub.Collection.from_stream(collection_stream); if(args[1] == "add-member") { collection.increment_serial(); collection.members.add(new Ppub.CollectionMember(args[3], Base64.decode(args[4]))); } else if(args[1] == "add-domain") { collection.increment_serial(); collection.domains.add(args[3]); } else if(args[1] == "publish") { var checksum = Ppub.CollectionPublication.generate_ppub_checksum(File.new_for_path(args[3])); string mem_key_str; FileUtils.get_contents(args[4] + ".private.key", out mem_key_str, null); var mem_signing_key = Base64.decode(mem_key_str); var publication = new Ppub.CollectionPublication(args[3], new DateTime.now_local(), args[4], checksum, mem_signing_key); collection.publications.add(publication); } else { print(@"Unrecognised command $(args[1])\n"); return -2; } collection.touch(); var col_str = collection.to_string(signing_key); FileUtils.set_contents(args[2], col_str, col_str.length); return 0; }