Skip to content

Commit

Permalink
gpg logic improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Aug 14, 2023
1 parent bc95355 commit 6928a1b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/operations/utility/key.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public int key_main (string[] args) {
if(get_bool("add")){
foreach(string arg in args){
add_gpg_key(arg);
}
}
return 0;
}
void key_init () {
operation op = new operation ();
op.help = new helpmsg ();
op.callback.connect (key_main);
op.names = {_ ("key"), "key"};
op.help.name = _ ("key");
op.help.description = _ ("Gpg key operations.");
add_operation (op);
}
6 changes: 6 additions & 0 deletions src/util/file.vala
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ public void copy_file (string src, string desc) {
File file2 = File.new_for_path (desc);
create_dir (sdirname (desc));
int64 sync_bytes = 0;
if("://" in src){
if(!fetch(src, desc)){
error_add (_ ("Failed to fetch file: %s => %s").printf (src, desc));
}
return;
}
if (isfile (desc)) {
remove_file (desc);
}
Expand Down
25 changes: 24 additions & 1 deletion src/util/gpg.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,30 @@ public bool verify_file (string path) {
if (!isfile (path)) {
return false;
}
return 0 == run ("sh -c \"gpg --verify %s'\" 2>/dev/null".printf (path + ".gpg'"));
string gpgdir = get_storage()+"/gpg/";
foreach(string file in listdir(gpgdir)) {
if(!endswith(file,".gpg")){
continue;
}
string[] args = {"gpg","--homedir", gpgdir, "--trust-model", "always", "--no-default-keyring", "--keyring", gpgdir+"%s".printf(file), "--quiet" ,"--verify", path+".gpg"};
int status = run_args (args);
if(status == 0){
return true;
}

}
return false;
}

public void add_gpg_key(string path){
if(endswith(path,".asc")){
string target = get_storage()+"/gpg/"+sbasename(path);
copy_file(path, target);
run_args({"gpg", "--dearmor", target});
move_file(target+".gpg",get_storage()+"/gpg/"+calculate_md5sum(target+".gpg")+".gpg");
remove_file(target);
}

}

//DOC: `void sign_elf (string path):`
Expand Down
2 changes: 2 additions & 0 deletions src/ymp.vala
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private void directories_init () {
create_dir (get_storage () + "/metadata/");
create_dir (get_storage () + "/files/");
create_dir (get_storage () + "/links/");
create_dir (get_storage () + "/gpg/");
create_dir (get_storage () + "/sources.list.d/");
create_dir (get_storage () + "/quarantine/");
if (!isexists (get_storage () + "/sources.list")) {
Expand All @@ -239,6 +240,7 @@ private void directories_init () {
Posix.chown (path, 0, 0);
}
}
GLib.FileUtils.chmod (get_storage () + "/gpg/", 0700);
}

private bool ymp_activated = false;
Expand Down

0 comments on commit 6928a1b

Please sign in to comment.