diff --git a/Cargo.lock b/Cargo.lock index 1c25b756..7bba713d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2734,6 +2734,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "base64 0.22.1", "bytes", "c2pa 0.58.0 (git+https://github.com/streamplace/c2pa-rs.git?rev=544825abfaf9e588813e18dba70c8d5afd039d46)", "hex", diff --git a/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.go b/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.go index bb584adc..11f057bd 100644 --- a/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.go +++ b/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.go @@ -414,7 +414,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iroh_streamplace_checksum_func_sign() }) - if checksum != 50601 { + if checksum != 41179 { // If this happens try cleaning and rebuilding your project panic("iroh_streamplace: uniffi_iroh_streamplace_checksum_func_sign: UniFFI API checksum mismatch") } @@ -423,7 +423,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iroh_streamplace_checksum_func_sign_with_ingredients() }) - if checksum != 52190 { + if checksum != 15411 { // If this happens try cleaning and rebuilding your project panic("iroh_streamplace: uniffi_iroh_streamplace_checksum_func_sign_with_ingredients: UniFFI API checksum mismatch") } @@ -5654,10 +5654,10 @@ func Resign(segsToSign ManySegmentsToSign, signedConcatData Stream) error { return _uniffiErr.AsError() } -func Sign(manifest string, data Stream, certs []byte, gosigner GoSigner) ([]byte, error) { +func Sign(manifest string, data Stream, certsStr string, gosigner GoSigner) ([]byte, error) { _uniffiRV, _uniffiErr := rustCallWithError[SpError](FfiConverterSpError{}, func(_uniffiStatus *C.RustCallStatus) RustBufferI { return GoRustBuffer{ - inner: C.uniffi_iroh_streamplace_fn_func_sign(FfiConverterStringINSTANCE.Lower(manifest), FfiConverterStreamINSTANCE.Lower(data), FfiConverterBytesINSTANCE.Lower(certs), FfiConverterGoSignerINSTANCE.Lower(gosigner), _uniffiStatus), + inner: C.uniffi_iroh_streamplace_fn_func_sign(FfiConverterStringINSTANCE.Lower(manifest), FfiConverterStreamINSTANCE.Lower(data), FfiConverterStringINSTANCE.Lower(certsStr), FfiConverterGoSignerINSTANCE.Lower(gosigner), _uniffiStatus), } }) if _uniffiErr != nil { @@ -5668,9 +5668,9 @@ func Sign(manifest string, data Stream, certs []byte, gosigner GoSigner) ([]byte } } -func SignWithIngredients(manifest string, data Stream, certs []byte, ingredients ManyStreams, gosigner GoSigner, output Stream) error { +func SignWithIngredients(manifest string, data Stream, certsStr string, ingredients ManyStreams, gosigner GoSigner, output Stream) error { _, _uniffiErr := rustCallWithError[SpError](FfiConverterSpError{}, func(_uniffiStatus *C.RustCallStatus) bool { - C.uniffi_iroh_streamplace_fn_func_sign_with_ingredients(FfiConverterStringINSTANCE.Lower(manifest), FfiConverterStreamINSTANCE.Lower(data), FfiConverterBytesINSTANCE.Lower(certs), FfiConverterManyStreamsINSTANCE.Lower(ingredients), FfiConverterGoSignerINSTANCE.Lower(gosigner), FfiConverterStreamINSTANCE.Lower(output), _uniffiStatus) + C.uniffi_iroh_streamplace_fn_func_sign_with_ingredients(FfiConverterStringINSTANCE.Lower(manifest), FfiConverterStreamINSTANCE.Lower(data), FfiConverterStringINSTANCE.Lower(certsStr), FfiConverterManyStreamsINSTANCE.Lower(ingredients), FfiConverterGoSignerINSTANCE.Lower(gosigner), FfiConverterStreamINSTANCE.Lower(output), _uniffiStatus) return false }) return _uniffiErr.AsError() diff --git a/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.h b/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.h index 8e7eaf97..e74ee140 100644 --- a/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.h +++ b/pkg/iroh/generated/iroh_streamplace/iroh_streamplace.h @@ -1054,12 +1054,12 @@ void uniffi_iroh_streamplace_fn_func_resign(void* segs_to_sign, void* signed_con #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_STREAMPLACE_FN_FUNC_SIGN #define UNIFFI_FFIDEF_UNIFFI_IROH_STREAMPLACE_FN_FUNC_SIGN -RustBuffer uniffi_iroh_streamplace_fn_func_sign(RustBuffer manifest, void* data, RustBuffer certs, void* gosigner, RustCallStatus *out_status +RustBuffer uniffi_iroh_streamplace_fn_func_sign(RustBuffer manifest, void* data, RustBuffer certs_str, void* gosigner, RustCallStatus *out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_STREAMPLACE_FN_FUNC_SIGN_WITH_INGREDIENTS #define UNIFFI_FFIDEF_UNIFFI_IROH_STREAMPLACE_FN_FUNC_SIGN_WITH_INGREDIENTS -void uniffi_iroh_streamplace_fn_func_sign_with_ingredients(RustBuffer manifest, void* data, RustBuffer certs, void* ingredients, void* gosigner, void* output, RustCallStatus *out_status +void uniffi_iroh_streamplace_fn_func_sign_with_ingredients(RustBuffer manifest, void* data, RustBuffer certs_str, void* ingredients, void* gosigner, void* output, RustCallStatus *out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_STREAMPLACE_FN_FUNC_SUBSCRIBE_ITEM_DEBUG diff --git a/pkg/media/media_signer.go b/pkg/media/media_signer.go index 25123ff1..32afa1ac 100644 --- a/pkg/media/media_signer.go +++ b/pkg/media/media_signer.go @@ -6,6 +6,7 @@ import ( "crypto/ecdsa" "crypto/rand" "crypto/sha256" + "encoding/base64" "encoding/json" "fmt" "io" @@ -160,7 +161,7 @@ func (ms *MediaSignerLocal) SignMP4(ctx context.Context, input io.ReadSeeker, st rustCallbackSigner := &RustCallbackSigner{ Signer: ms.Signer, } - bs, err = iroh_streamplace.Sign(string(manifestBs), c2patypes.NewReader(aqio.NewReadWriteSeeker(bs)), ms.Cert, rustCallbackSigner) + bs, err = iroh_streamplace.Sign(string(manifestBs), c2patypes.NewReader(aqio.NewReadWriteSeeker(bs)), base64.StdEncoding.EncodeToString(ms.Cert), rustCallbackSigner) if err != nil { return nil, err } @@ -232,7 +233,7 @@ func (ms *MediaSignerLocal) SignConcatMP4(ctx context.Context, input io.ReadSeek for _, ingredient := range ingredients { many.AddStream(ingredient) } - err = iroh_streamplace.SignWithIngredients(string(manifestBs), c2patypes.NewReader(input), ms.Cert, many, rustCallbackSigner, c2patypes.NewWriter(output)) + err = iroh_streamplace.SignWithIngredients(string(manifestBs), c2patypes.NewReader(input), base64.StdEncoding.EncodeToString(ms.Cert), many, rustCallbackSigner, c2patypes.NewWriter(output)) if err != nil { return err } diff --git a/rust/iroh-streamplace/Cargo.toml b/rust/iroh-streamplace/Cargo.toml index ae375a0e..b2a6372b 100644 --- a/rust/iroh-streamplace/Cargo.toml +++ b/rust/iroh-streamplace/Cargo.toml @@ -36,6 +36,7 @@ hex = "0.4.3" iroh-gossip = "0.93.1" ref-cast = "1.0.25" rand = "0.9" +base64 = "0.22.1" [dev-dependencies] testresult = "0.4.1" diff --git a/rust/iroh-streamplace/src/c2pa.rs b/rust/iroh-streamplace/src/c2pa.rs index f5bc8d00..a35472b4 100644 --- a/rust/iroh-streamplace/src/c2pa.rs +++ b/rust/iroh-streamplace/src/c2pa.rs @@ -16,6 +16,7 @@ use crate::streams::StreamAdapter; use serde_json; use crate::error::SPError; +use base64::{Engine as _, engine::general_purpose::STANDARD}; #[uniffi::export] pub fn get_manifest_and_cert(data: &dyn Stream) -> Result { let reader = Reader::from_stream("video/mp4", StreamAdapter::from(data)) @@ -111,10 +112,13 @@ enabled = true pub fn sign( manifest: String, data: &dyn Stream, - certs: Vec, + certs_str: String, gosigner: Arc, ) -> Result, SPError> { Settings::from_toml(TOML_SETTINGS).map_err(|e| SPError::C2paError(e.to_string()))?; + let certs = STANDARD + .decode(certs_str) + .map_err(|e| SPError::C2paError(e.to_string()))?; let callback_signer = CallbackSigner::new( move |_context: *const (), data: &[u8]| { let signature = gosigner @@ -242,11 +246,14 @@ pub fn resign( pub fn sign_with_ingredients( manifest: String, data: &dyn Stream, - certs: Vec, + certs_str: String, ingredients: &dyn ManyStreams, gosigner: Arc, output: &dyn Stream, ) -> Result<(), SPError> { + let certs = STANDARD + .decode(certs_str) + .map_err(|e| SPError::C2paError(e.to_string()))?; Settings::from_toml(TOML_SETTINGS).map_err(|e| SPError::C2paError(e.to_string()))?; let callback_signer = CallbackSigner::new( move |_context: *const (), data: &[u8]| {