@@ -68,6 +68,7 @@ import (
68
68
"github.com/sigstore/cosign/v2/pkg/cosign/kubernetes"
69
69
"github.com/sigstore/cosign/v2/pkg/oci/mutate"
70
70
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
71
+ "github.com/sigstore/sigstore-go/pkg/root"
71
72
"github.com/sigstore/sigstore/pkg/signature/payload"
72
73
tsaclient "github.com/sigstore/timestamp-authority/pkg/client"
73
74
"github.com/sigstore/timestamp-authority/pkg/server"
@@ -859,6 +860,114 @@ func TestAttestationRFC3161Timestamp(t *testing.T) {
859
860
must (verifyAttestation .Exec (ctx , []string {imgName }), t )
860
861
}
861
862
863
+ func TestAttestationBlobRFC3161Timestamp (t * testing.T ) {
864
+ // TSA server needed to create timestamp
865
+ viper .Set ("timestamp-signer" , "memory" )
866
+ viper .Set ("timestamp-signer-hash" , "sha256" )
867
+ apiServer := server .NewRestAPIServer ("localhost" , 0 , []string {"http" }, false , 10 * time .Second , 10 * time .Second )
868
+ server := httptest .NewServer (apiServer .GetHandler ())
869
+ t .Cleanup (server .Close )
870
+
871
+ blob := "someblob"
872
+ predicate := `{ "buildType": "x", "builder": { "id": "2" }, "recipe": {} }`
873
+ predicateType := "slsaprovenance"
874
+
875
+ td := t .TempDir ()
876
+ t .Cleanup (func () {
877
+ os .RemoveAll (td )
878
+ })
879
+
880
+ bp := filepath .Join (td , blob )
881
+ if err := os .WriteFile (bp , []byte (blob ), 0600 ); err != nil {
882
+ t .Fatal (err )
883
+ }
884
+
885
+ predicatePath := filepath .Join (td , "predicate" )
886
+ if err := os .WriteFile (predicatePath , []byte (predicate ), 0600 ); err != nil {
887
+ t .Fatal (err )
888
+ }
889
+
890
+ bundlePath := filepath .Join (td , "bundle.sigstore.json" )
891
+ _ , privKeyPath , pubKeyPath := keypair (t , td )
892
+
893
+ ctx := context .Background ()
894
+ ko := options.KeyOpts {
895
+ KeyRef : privKeyPath ,
896
+ BundlePath : bundlePath ,
897
+ NewBundleFormat : true ,
898
+ TSAServerURL : server .URL + "/api/v1/timestamp" ,
899
+ PassFunc : passFunc ,
900
+ }
901
+
902
+ attestBlobCmd := attest.AttestBlobCommand {
903
+ KeyOpts : ko ,
904
+ PredicatePath : predicatePath ,
905
+ PredicateType : predicateType ,
906
+ Timeout : 30 * time .Second ,
907
+ TlogUpload : false ,
908
+ RekorEntryType : "dsse" ,
909
+ }
910
+ must (attestBlobCmd .Exec (ctx , bp ), t )
911
+
912
+ client , err := tsaclient .GetTimestampClient (server .URL )
913
+ if err != nil {
914
+ t .Error (err )
915
+ }
916
+
917
+ chain , err := client .Timestamp .GetTimestampCertChain (nil )
918
+ if err != nil {
919
+ t .Fatalf ("unexpected error getting timestamp chain: %v" , err )
920
+ }
921
+
922
+ var certs []* x509.Certificate
923
+ for block , contents := pem .Decode ([]byte (chain .Payload )); ; block , contents = pem .Decode (contents ) {
924
+ cert , err := x509 .ParseCertificate (block .Bytes )
925
+ if err != nil {
926
+ t .Error (err )
927
+ }
928
+ certs = append (certs , cert )
929
+
930
+ if len (contents ) == 0 {
931
+ break
932
+ }
933
+ }
934
+
935
+ tsaCA := root.CertificateAuthority {
936
+ Root : certs [len (certs )- 1 ],
937
+ Intermediates : certs [:len (certs )- 1 ],
938
+ }
939
+
940
+ trustedRoot , err := root .NewTrustedRoot (root .TrustedRootMediaType01 , nil , nil , []root.CertificateAuthority {tsaCA }, nil )
941
+ if err != nil {
942
+ t .Error (err )
943
+ }
944
+
945
+ trustedRootPath := filepath .Join (td , "trustedroot.json" )
946
+ trustedRootBytes , err := trustedRoot .MarshalJSON ()
947
+ if err != nil {
948
+ t .Error (err )
949
+ }
950
+ if err := os .WriteFile (trustedRootPath , trustedRootBytes , 0600 ); err != nil {
951
+ t .Fatal (err )
952
+ }
953
+
954
+ ko = options.KeyOpts {
955
+ KeyRef : pubKeyPath ,
956
+ BundlePath : bundlePath ,
957
+ NewBundleFormat : true ,
958
+ }
959
+
960
+ verifyBlobAttestation := cliverify.VerifyBlobAttestationCommand {
961
+ KeyOpts : ko ,
962
+ PredicateType : predicateType ,
963
+ IgnoreTlog : true ,
964
+ CheckClaims : true ,
965
+ TrustedRootPath : trustedRootPath ,
966
+ }
967
+
968
+ must (verifyBlobAttestation .Exec (ctx , bp ), t )
969
+ }
970
+
862
971
func TestVerifyWithCARoots (t * testing.T ) {
863
972
ctx := context .Background ()
864
973
// TSA server needed to create timestamp
0 commit comments