malwaredb 0.3.4

Service for storing malicious, benign, or unknown files and related metadata and relationships.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
name: Release
on:
  push:
    tags:
      - "v*"
    branches:
      - main

permissions:
  attestations: write
  contents: read
  id-token: write

jobs:
  py_linux:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: ubuntu-22.04
            target: x86_64
            manylinux: 2_28
          - runner: ubuntu-22.04
            target: x86
            manylinux: 2_28
          - runner: ubuntu-22.04-arm
            target: aarch64
            manylinux: 2_28
          - runner: ubuntu-22.04-arm
            target: armv7
            manylinux: 2_28
          - runner: ubuntu-22.04
            target: ppc64le
            manylinux: 2_28
          - runner: ubuntu-22.04
            target: riscv64
            manylinux: 2_31
          - runner: ubuntu-22.04
            target: loongarch64
            manylinux: 2_36
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: block
          allowed-endpoints: >
            api.github.com:443
            archive.ubuntu.com:443
            astral.sh:443
            cdn01.quay.io:443
            files.pythonhosted.org:443
            index.crates.io:443
            ghcr.io:443
            github.com:443
            objects.githubusercontent.com:443
            pkg-containers.githubusercontent.com:443
            pypi.org:443
            quay.io:443
            releases.astral.sh:443
            release-assets.githubusercontent.com:443
            security.ubuntu.com:80
            security.ubuntu.com:443
            sh.rustup.rs:443
            static.crates.io:443
            static.rust-lang.org:443
            vault.almalinux.org:443
            vault.centos.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 #v1
      - name: Build Linux ${{ matrix.platform.target }} wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          manylinux: ${{ matrix.platform.manylinux }}
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
      - name: Upload Linux ${{ matrix.platform.target }} wheels
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wheels-linux-${{ matrix.platform.target }}
          path: dist
          retention-days: 5

  py_musllinux:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
        platform:
          - runner: ubuntu-22.04
            target: x86_64
          - runner: ubuntu-22.04
            target: x86
          - runner: ubuntu-22.04-arm
            target: aarch64
          - runner: ubuntu-22.04-arm
            target: armv7
          - runner: ubuntu-22.04
            target: ppc64le
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: block
          allowed-endpoints: >
            api.github.com:443
            archive.ubuntu.com:443
            astral.sh:443
            cdn01.quay.io:443
            files.pythonhosted.org:443
            index.crates.io:443
            ghcr.io:443
            github.com:443
            objects.githubusercontent.com:443
            pkg-containers.githubusercontent.com:443
            pypi.org:443
            quay.io:443
            releases.astral.sh:443
            release-assets.githubusercontent.com:443
            security.ubuntu.com:80
            security.ubuntu.com:443
            sh.rustup.rs:443
            static.crates.io:443
            static.rust-lang.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 #v1
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '>=3.7'
      - name: Build musl Linux ${{ matrix.platform.target }} wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          manylinux: musllinux_1_2
      - name: Upload musl Linux ${{ matrix.platform.target }} wheels
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wheels-musllinux-${{ matrix.platform.target }}
          path: dist
          retention-days: 5

  py_windows:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
        platform:
          - runner: windows-latest
            target: x64
          - runner: windows-latest
            target: x86
          - runner: windows-11-arm
            target: arm64
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            crates.io:443
            github.com:443
            index.crates.io:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '>=3.7'
          architecture: ${{ matrix.platform.target }}
      - name: Install rustup (Windows 11 ARM64) # rust is currently missing from the windows-11-arm runner
        if: matrix.platform.runner == 'windows-11-arm'
        shell: pwsh
        run: |
          Invoke-WebRequest -Uri "https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe" -OutFile rustup-init.exe
          .\rustup-init.exe --default-toolchain none -y
          "$env:USERPROFILE\.cargo\bin" | Out-File -Append -Encoding ascii $env:GITHUB_PATH
          "CARGO_HOME=$env:USERPROFILE\.cargo" | Out-File -Append -Encoding ascii $env:GITHUB_ENV
      - name: Install Rust (Windows 11 ARM64)
        if: matrix.platform.runner == 'windows-11-arm'
        shell: pwsh
        run: |
          rustup install stable
          rustup target add aarch64-pc-windows-msvc
      - name: Build Windows ${{ matrix.platform.target }} wheels
        if: matrix.platform.runner != 'windows-11-arm'
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
      - name: Build Windows ${{ matrix.platform.target }} wheels
        if: matrix.platform.runner == 'windows-11-arm'
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: aarch64-pc-windows-msvc
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
      - name: Upload Windows ${{ matrix.platform.target }} wheels
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wheels-windows-${{ matrix.platform.target }}
          path: dist
          retention-days: 5

  py_macos:
    runs-on: macos-14
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          disable-sudo: true
          allowed-endpoints: >
            cds.apple.com:443
            configuration.apple.com:443
            crates.io:443
            experiments.apple.com:443
            gateway.icloud.com:443
            github.com:443
            gsa.apple.com:443
            help.apple.com:443
            index.crates.io:443
            mesu.apple.com:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '>=3.7'
      - name: Build arm64 macOS wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: aarch64
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
      - name: Install x86_64 Toolchain
        run: rustup target add x86_64-apple-darwin
      - name: Build x86_64 macOS wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: x86_64
          args: --release --strip --out dist --manifest-path client-py/Cargo.toml
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
      - name: Upload macOS wheels
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wheels-macos
          path: dist
          retention-days: 5

  py_sdist:
    runs-on: ubuntu-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          disable-sudo: true
          allowed-endpoints: > # This action seems to connect to node.net but this doen't happen for others with Maturin.
            api.github.com:443
            astral.sh:443
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            cdn01.quay.io:443
            crates.io:443
            esm.ubuntu.com:443
            files.pythonhosted.org:443
            ghcr.io:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            ppa.launchpadcontent.net:443
            prod.app-api.stepsecurity.io:443
            pypi.org:443
            quay.io:443
            release-assets.githubusercontent.com:443
            releases.astral.sh:443
            security.ubuntu.com:80
            security.ubuntu.com:443
            sh.rustup.rs:443
            static.crates.io:443
            static.rust-lang.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - name: Build sdist
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          command: sdist
          args: --out dist --manifest-path client-py/Cargo.toml
      - name: Upload sdist
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wheels-sdist
          path: dist
          retention-days: 5

  linux_x86:
    #if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    runs-on: ubuntu-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: block
          allowed-endpoints: >
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            crates.io:443
            esm.ubuntu.com:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            ppa.launchpadcontent.net:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443

      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 #v1
      - name: Setup Rust toolchain
        run: |
          rustup target install x86_64-unknown-linux-musl
          sudo apt-get update
          sudo apt-get install -y musl musl-dev musl-tools dpkg-dev
      - name: Install cargo-deb
        run: cargo install cargo-deb
      - name: Install cargo audit, auditable, cyclonedx
        uses: taiki-e/install-action@b651345a718c8f44efa2460560b3dbf29cbd7ee1 # v2.75.26
        with:
          tool: cargo-audit,cargo-auditable,cargo-cyclonedx
      - id: version
        run: echo "version=$(cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "malwaredb") | .version' --raw-output)" >>$GITHUB_OUTPUT
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libmagic-dev
      - name: Install GUI dependencies
        run: sudo apt-get install -y libxcb-shape0-dev libxcb-xfixes0-dev libx11-dev libxkbcommon-dev libfontconfig-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev
      - name: Build and package client
        run: |
          cd client
          cargo auditable deb --target x86_64-unknown-linux-musl
          cd ..
          mv target/x86_64-unknown-linux-musl/release/mdb_client target/x86_64-unknown-linux-musl/release/mdb_client_linux_musl_x86_64
      - name: Build and package server
        run: |
          cargo deb --locked --cargo-build 'auditable build'
          mv target/release/mdb_server target/release/mdb_server_linux_gnu_x86_64
      - name: Upload mdb_server
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_server_linux_gnu_x86_64
          path: target/release/mdb_server_linux_gnu_x86_64
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_server deb
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: "malwaredb_${{ steps.version.outputs.version }}-1_amd64.deb"
          path: "target/debian/malwaredb_${{ steps.version.outputs.version }}-1_amd64.deb"
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_client
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_client_linux_musl_x86_64
          path: target/x86_64-unknown-linux-musl/release/mdb_client_linux_musl_x86_64
          retention-days: 5
      - name: Upload mdb_client deb
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: "malwaredb-client_${{ steps.version.outputs.version }}-1_amd64.deb"
          path: "target/x86_64-unknown-linux-musl/debian/malwaredb-client_${{ steps.version.outputs.version }}-1_amd64.deb"
          if-no-files-found: error
          retention-days: 5
      - name: Run cycloneDX and get JSON output
        run: cargo cyclonedx --all --all-features --format=json --override-filename sbom
      - name: Run cycloneDX and get XML output
        run: cargo cyclonedx --all --all-features --format=xml --override-filename sbom
      - name: Upload the JSON BOM file
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: sbom.json
          path: sbom.json
          if-no-files-found: error
          retention-days: 5
      - name: Upload the XML BOM file
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: sbom.xml
          path: sbom.xml
          if-no-files-found: error
          retention-days: 5

  linux_arm:
    #if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    runs-on: ubuntu-24.04-arm
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: block
          allowed-endpoints: >
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            crates.io:443
            esm.ubuntu.com:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            ppa.launchpadcontent.net:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443

      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 #v1
      - name: Setup Rust toolchain
        run: |
          rustup target install aarch64-unknown-linux-musl
          sudo apt-get update
          sudo apt-get install -y musl musl-dev musl-tools dpkg-dev
          cargo install cargo-deb
      - name: Install cargo audit & auditable
        uses: taiki-e/install-action@b651345a718c8f44efa2460560b3dbf29cbd7ee1 # v2.75.26
        with:
          tool: cargo-audit,cargo-auditable
      - id: version
        run: echo "version=$(cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "malwaredb") | .version' --raw-output)" >>$GITHUB_OUTPUT
      - name: Install dependencies
        run: sudo apt-get install -y libmagic-dev
      - name: Install GUI dependencies
        run: sudo apt-get install -y libxcb-shape0-dev libxcb-xfixes0-dev libx11-dev libxkbcommon-dev libfontconfig-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev
      - name: Build and package client
        run: |
          cd client
          cargo auditable deb --target aarch64-unknown-linux-musl
          cd ..
          mv target/aarch64-unknown-linux-musl/release/mdb_client target/aarch64-unknown-linux-musl/release/mdb_client_linux_musl_arm64
      - name: Build and package server
        run: |
          cargo deb --locked --cargo-build 'auditable build'
          mv target/release/mdb_server target/release/mdb_server_linux_gnu_arm64
      - name: Upload mdb_server
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_server_linux_gnu_arm64
          path: target/release/mdb_server_linux_gnu_arm64
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_server deb
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: "malwaredb_${{ steps.version.outputs.version }}-1_arm64.deb"
          path: "target/debian/malwaredb_${{ steps.version.outputs.version }}-1_arm64.deb"
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_client
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_client_linux_musl_arm64
          path: target/aarch64-unknown-linux-musl/release/mdb_client_linux_musl_arm64
          retention-days: 5
      - name: Upload mdb_client deb
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: "malwaredb-client_${{ steps.version.outputs.version }}-1_arm64.deb"
          path: "target/aarch64-unknown-linux-musl/debian/malwaredb-client_${{ steps.version.outputs.version }}-1_arm64.deb"
          if-no-files-found: error
          retention-days: 5

  macos:
    #if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    runs-on: macos-14
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            apple.com:443
            crates.io:443
            github.com:443
            index.crates.io:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443
      - name: Update Rust
        run: rustup update
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - name: Install libmagic
        run: brew install libmagic
      - name: Install cargo audit & auditable
        uses: taiki-e/install-action@b651345a718c8f44efa2460560b3dbf29cbd7ee1 # v2.75.26
        with:
          tool: cargo-audit,cargo-auditable
      - name: Build client
        run: cargo auditable build --workspace --bin mdb_client --release
      - name: Build server
        run: cargo auditable build --features=admin,admin-gui,sqlite,vt,yara --bin mdb_server --release
        env:
          LIBRARY_PATH: "/opt/homebrew/lib:/opt/homebrew/opt/libmagic/lib"
      - name: Rename and prepare for signing
        run: |
          mv ./target/release/mdb_server ./target/release/mdb_server_darwin_arm64
          mv ./target/release/mdb_client ./target/release/mdb_client_darwin_arm64
          mkdir -p private_keys/
          echo -n "${{ secrets.CERTIFICATE_P12 }}" | base64 --decode -o private_keys/cert.p12
      - name: Sign server
        uses: indygreg/apple-code-sign-action@44d0985b7f4363198e80b6fea63ac3e9dd3e9957 # v1.1
        with:
          input_path: ./target/release/mdb_server_darwin_arm64
          p12_file: private_keys/cert.p12
          p12_password: ${{ secrets.CERTIFICATE_PASSWORD }}
          sign_args: |
            --for-notarization
          rcodesign_version: '0.29.0'
      - name: Sign client
        uses: indygreg/apple-code-sign-action@44d0985b7f4363198e80b6fea63ac3e9dd3e9957 # v1.1
        with:
          input_path: ./target/release/mdb_client_darwin_arm64
          p12_file: private_keys/cert.p12
          p12_password: ${{ secrets.CERTIFICATE_PASSWORD }}
          sign_args: |
            --for-notarization
          rcodesign_version: '0.29.0'
      - name: Upload mdb_server
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_server_darwin_arm64
          path: target/release/mdb_server_darwin_arm64
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_client
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_client_darwin_arm64
          path: target/release/mdb_client_darwin_arm64
          if-no-files-found: error
          retention-days: 5
      - name: Cleanup
        run: |
          echo 000000000000 > private_keys/cert.p12
          rm -rf private_keys/

  windows:
    #if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    runs-on: windows-latest
    env:
      VCPKG_BUILD_TYPE: release
      VCPKG_LIBRARY_LINKAGE: static
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            crates.io:443
            github.com:443
            index.crates.io:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: dtolnay/rust-toolchain@d0e72ca3bfdc51937a4f81431ccbed269ef9f2a2 # stable
      - uses: ChristopheLav/windows-sdk-install@aceebd61475568479ce68465d0849f5de9a0bfe9 # v1.0.5
        with:
          version-sdk: 22621
          features: 'OptionId.DesktopCPPx64,OptionId.DesktopCPParm64'
      - run: |
          rustup update
          rustup target install aarch64-pc-windows-msvc
      # We have to update vcpkg because the version installed on the GitHub Actions runners is too old, and
      # we need to deal with https://github.com/microsoft/vcpkg/issues/43565, which was fixed in
      # https://github.com/microsoft/vcpkg/pull/43635, https://github.com/microsoft/vcpkg/commit/a0f974c
      # However, this is very slow (git pull), and should be removed when GitHub advances the vcpkg data in the runner
      - name: Install vcpkg
        run: |
          cd C:\vcpkg
          git pull origin master
          vcpkg upgrade --no-dry-run
          vcpkg install libmagic:x64-windows-static
          vcpkg install libmagic:arm64-windows-static
          vcpkg integrate install
          vcpkg list --triplet x64-windows-static
          vcpkg list --triplet arm64-windows-static
          cargo install cargo-vcpkg
      - name: Install cargo audit & auditable
        uses: taiki-e/install-action@b651345a718c8f44efa2460560b3dbf29cbd7ee1 # v2.75.26
        with:
          tool: cargo-audit,cargo-auditable
      - name: Build client x86_64
        run: cargo auditable build --workspace --bin mdb_client --release
      - name: Build client arm64
        run: cargo auditable build --workspace --bin mdb_client --release --target=aarch64-pc-windows-msvc
      - name: Build server x86_64
        run: cargo auditable build --features=admin,admin-gui,sqlite,vt,yara --release
      - name: Build server arm64
        run: cargo auditable build --features=admin,admin-gui,sqlite,vt,yara --release --target=aarch64-pc-windows-msvc
      - run: |
          copy target/release/mdb_server.exe target/release/mdb_server_amd64.exe
          copy target/release/mdb_client.exe target/release/mdb_client_amd64.exe
          copy target/aarch64-pc-windows-msvc/release/mdb_server.exe target/aarch64-pc-windows-msvc/release/mdb_server_arm64.exe
          copy target/aarch64-pc-windows-msvc/release/mdb_client.exe target/aarch64-pc-windows-msvc/release/mdb_client_arm64.exe
      - name: Upload mdb_server.exe
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_server_amd64.exe
          path: target/release/mdb_server_amd64.exe
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_server_arm64.exe
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_server_arm64.exe
          path: target/aarch64-pc-windows-msvc/release/mdb_server_arm64.exe
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_client.exe
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_client_amd64.exe
          path: target/release/mdb_client_amd64.exe
          if-no-files-found: error
          retention-days: 5
      - name: Upload mdb_client_arm64.exe
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: mdb_client_arm64.exe
          path: target/aarch64-pc-windows-msvc/release/mdb_client_arm64.exe
          if-no-files-found: error
          retention-days: 5

  release:
    if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    name: GitHub Release
    needs: [ windows, macos, linux_x86, linux_arm ]
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      attestations: write
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            api.github.com:443
            api.snapcraft.io:443
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            esm.ubuntu.com:443
            github.com:443
            motd.ubuntu.com:443
            objects.githubusercontent.com:443
            release-assets.githubusercontent.com:443
            uploads.github.com:443
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - id: version
        run: echo "version=$(cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "malwaredb") | .version' --raw-output)" >>$GITHUB_OUTPUT
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_server_darwin_arm64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_client_darwin_arm64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_server_amd64.exe
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_server_arm64.exe
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_client_amd64.exe
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_client_arm64.exe
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_server_linux_gnu_x86_64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_server_linux_gnu_arm64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: "malwaredb_${{ steps.version.outputs.version }}-1_amd64.deb"
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: "malwaredb_${{ steps.version.outputs.version }}-1_arm64.deb"
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_client_linux_musl_x86_64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: mdb_client_linux_musl_arm64
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: "malwaredb-client_${{ steps.version.outputs.version }}-1_amd64.deb"
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: "malwaredb-client_${{ steps.version.outputs.version }}-1_arm64.deb"
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: sbom.xml
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: sbom.json
      - name: Download minisign
        run: |
          sudo apt-get install wget
          wget https://github.com/jedisct1/minisign/releases/download/0.11/minisign-0.11-linux.tar.gz
          tar xzf minisign-0.11-linux.tar.gz
          mv minisign-linux/x86_64/minisign .
      - name: Sign artifacts
        run: |
          mkdir ~/.minisign/
          echo "${{ secrets.MINISIGN_KEY }}" > ~/.minisign/minisign.key
          echo | ./minisign -t "MalwareDB ${{ steps.version.outputs.version }}" -Sm mdb_* malwaredb* sbom.*
          echo | ./minisign -R
      - uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
        with:
          draft: true
          generate_release_notes: true
          files: |
            mdb_server_darwin_arm64
            mdb_server_darwin_arm64.minisig
            mdb_client_darwin_arm64
            mdb_client_darwin_arm64.minisig
            mdb_server_amd64.exe
            mdb_server_amd64.exe.minisig
            mdb_server_arm64.exe
            mdb_server_arm64.exe.minisig
            mdb_client_amd64.exe
            mdb_client_amd64.exe.minisig
            mdb_client_arm64.exe
            mdb_client_arm64.exe.minisig
            mdb_server_linux_gnu_x86_64
            mdb_server_linux_gnu_x86_64.minisig
            mdb_client_linux_musl_x86_64
            mdb_client_linux_musl_x86_64.minisig
            mdb_server_linux_gnu_arm64
            mdb_server_linux_gnu_arm64.minisig
            mdb_client_linux_musl_arm64
            mdb_client_linux_musl_arm64.minisig
            malwaredb_${{ steps.version.outputs.version }}-1_amd64.deb
            malwaredb_${{ steps.version.outputs.version }}-1_amd64.deb.minisig
            malwaredb-client_${{ steps.version.outputs.version }}-1_amd64.deb
            malwaredb-client_${{ steps.version.outputs.version }}-1_amd64.deb.minisig
            malwaredb_${{ steps.version.outputs.version }}-1_arm64.deb
            malwaredb_${{ steps.version.outputs.version }}-1_arm64.deb.minisig
            malwaredb-client_${{ steps.version.outputs.version }}-1_arm64.deb
            malwaredb-client_${{ steps.version.outputs.version }}-1_arm64.deb.minisig
            sbom.xml
            sbom.xml.minisig
            sbom.json
            sbom.json.minisig
            minisign.pub
      - run: echo 00000 > ~/.minisign/minisign.key

      - uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
        with:
          subject-path: |
            mdb_server_darwin_arm64
            mdb_client_darwin_arm64
            mdb_server_amd64.exe
            mdb_server_arm64.exe
            mdb_client_amd64.exe
            mdb_client_arm64.exe
            mdb_server_linux_gnu_x86_64
            mdb_client_linux_musl_x86_64
            mdb_server_linux_gnu_arm64
            mdb_client_linux_musl_arm64
            sbom.xml
            sbom.json

  py_release:
    name: PyPi Release
    runs-on: ubuntu-latest
    needs: [ py_linux, py_musllinux, py_windows, py_macos, py_sdist ]
    environment:
      name: pypi
      url: https://pypi.org/p/malwaredb
    permissions:
      # Use to sign the release artifacts
      id-token: write
      # Used to upload release artifacts
      contents: write
      # Used to generate artifact attestation
      attestations: write
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            cdn.fwupd.org:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            pypi.org:443
            release-assets.githubusercontent.com:443

      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          pattern: "wheels-*"
      - name: Generate artifact attestation
        uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
        with:
          subject-path: 'wheels-*/*'
      - run: |
          mkdir dist
          mv wheels-*/* dist/
          ls -lah dist/
      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
        if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}

  docker:
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    permissions:
      contents: read
      packages: write
      # This is used to complete the identity challenge
      # with sigstore/fulcio when running outside of PRs.
      id-token: write

    env:
      REGISTRY: ghcr.io
      IMAGE_NAME: malwaredb/malwaredb

    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: audit
          allowed-endpoints: >
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            crates.io:443
            esm.ubuntu.com:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            ppa.launchpadcontent.net:443
            quay.io:443
            release-assets.githubusercontent.com:443
            static.crates.io:443
            static.rust-lang.org:443

      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      # Install the cosign tool except on PR
      # https://github.com/sigstore/cosign-installer
      - name: Install cosign
        uses: sigstore/cosign-installer@cad07c2e89fa2edd6e2d7bab4c1aa38e53f76003 #v4.1.1

      # Workaround: https://github.com/docker/build-push-action/issues/461
      - name: Setup Docker buildx
        uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0

      # Login against a Docker registry except on PR
      # https://github.com/docker/login-action
      - name: Log into registry ${{ env.REGISTRY }}
        uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 #v4.1.0
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # Extract metadata (tags, labels) for Docker
      # https://github.com/docker/metadata-action
      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf #v6.0.0
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      # Build and push Docker image with Buildx (don't push on PR)
      # https://github.com/docker/build-push-action
      - name: Build and push Docker image
        id: build-and-push
        uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f #v7.1.0
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

      # Sign the resulting Docker image digest except on PRs.
      # https://github.com/sigstore/cosign
      - name: Sign the published Docker image
        env:
          # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
          TAGS: ${{ steps.meta.outputs.tags }}
          DIGEST: ${{ steps.build-and-push.outputs.digest }}
        # This step uses the identity token to provision an ephemeral certificate
        # against the sigstore community Fulcio instance.
        run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

  crates_io_publish:
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
    name: Publish to crates.io
    needs: [release]
    permissions:
      contents: read
      id-token: write

    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
        with:
          egress-policy: block
          allowed-endpoints: >
            azure.archive.ubuntu.com:80
            cdn.fwupd.org:443
            crates.io:443
            esm.ubuntu.com:443
            github.com:443
            index.crates.io:443
            motd.ubuntu.com:443
            ppa.launchpadcontent.net:443
            static.crates.io:443
            static.rust-lang.org:443

      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y libmagic-dev build-essential

      - uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe # v1.0.4
        id: auth
      - run: cargo publish --workspace
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}