Manifest.cs 3.49 KB
Newer Older
Archnoc's avatar
Archnoc committed
1
2
3
using System;
using System.Collections.Generic;
using System.IO;
Archnoc's avatar
Archnoc committed
4
5
using System.Linq;
using System.Text.Json.Serialization;
Archnoc's avatar
Archnoc committed
6
7
8

namespace sunrise_launcher
{
Archnoc's avatar
Archnoc committed
9
10
11
12
13
14
    public class Manifest : ManifestMetadata
    {
        [JsonPropertyName("files")]
        public List<ManifestFile> Files { get; set; }
    }

Archnoc's avatar
Archnoc committed
15
16
17
18
    public class ManifestMetadata
    {
        [JsonPropertyName("title")]
        public string Title { get; set; }
Archnoc's avatar
Archnoc committed
19
20
        [JsonPropertyName("version")]
        public string Version { get; set; }
Archnoc's avatar
Archnoc committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
        [JsonPropertyName("launch_path")]
        public string LaunchPath { get; set; }
        [JsonPropertyName("launch_env")]
        public string LaunchEnv { get; set; }
        [JsonPropertyName("launch_args")]
        public string LaunchArgs { get; set; }

        public bool Verify()
        {
            if (Path.IsPathFullyQualified(LaunchPath))
            {
                Console.WriteLine("launch path is fully qualified");
                return false;
            }

            return true;
        }
    }

    public class ManifestFile
    {
        [JsonPropertyName("path")]
        public string Path { get; set; }
        [JsonPropertyName("size")]
        public long Size { get; set; }
        [JsonPropertyName("sha256")]
        public string Sha256 { get; set; }
        [JsonPropertyName("md5")]
        public string MD5 { get; set; }
        [JsonPropertyName("sources")]
        public List<FileSource> Sources { get; set; }

        public bool Verify()
        {
            if (Path.Contains(".."))
            {
                Console.WriteLine("illegal sequence in manifest file path: '..' in {0}", Path);
                return false;
            }
                
            if (Path.Contains("~"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '~' in {0}", Path);
                return false;
            }

            if (Path.Contains("$"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '$' in {0}", Path);
                return false;
            }

            if (Path.Contains("%"))
            {
                Console.WriteLine("illegal sequence in manifest file path: '%' in {0}", Path);
                return false;
            }

            if (System.IO.Path.IsPathFullyQualified(Path))
            {
                Console.WriteLine("file path is fully qualified: {0}", Path);
                return false;
            }

            if (Path.Contains("main.js"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'main.js' in {0}", Path);
                return false;
            }

            if (Path.Contains("main.qml"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'main.qml' in {0}", Path);
                return false;
            }

            if (Path.Contains("sunrise-launcher"))
            {
                Console.WriteLine("illegal sequence in manifest file path: 'sunrise-launcher' in {0}", Path);
                return false;
            }

            return Sources.All(x => x.Verify());
        }
    }

    public class FileSource
    {
        [JsonPropertyName("url")]
        public string URL { get; set; }

        public bool Verify()
        {
            if (URL.ToLower().Contains("file:"))
            {
                Console.WriteLine("illegal sequence in manifest source url: 'file:' in source {0}", URL);
                return false;
            }

            return true;
        }
    }
}