simple-c2pa

This is a fork of https://gitlab.com/guardianproject/proofmode/simple-c2pa
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/simple-c2pa.git
Log | Files | Refs | README | LICENSE

commit fa0337b67e2c23bc09a6386bd4e722380d383d12
parent a222d5bcbc5938e108e32864b4db6bc9471691a0
Author: Darren Clarke <darren@redaranj.com>
Date:   Wed,  6 Dec 2023 12:05:44 +0000

Merge branch 'develop' into 'main'

Bug and CI fixes

See merge request guardianproject/proofmode/simple-c2pa!2
Diffstat:
MCargo.toml | 2+-
MMakefile.toml | 4----
Mandroid/.gitlab-ci.yml | 31++++++++++++++-----------------
Mapple/.gitlab-ci.yml | 37++++++++++++++++++++-----------------
Msrc/certificates.rs | 22+++++++++++++++++++++-
Mtests/examples.rs | 16++++++++++++----
6 files changed, 68 insertions(+), 44 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple-c2pa" -version = "0.8.0" +version = "0.0.6" edition = "2021" [dependencies] diff --git a/Makefile.toml b/Makefile.toml @@ -91,8 +91,6 @@ cp "${TARGET_DIR}/x86_64-linux-android/${BUILD_MODE}/${LIB_NAME}" "${JNILIBS_DIR cp "${TARGET_DIR}/i686-linux-android/${BUILD_MODE}/${LIB_NAME}" "${JNILIBS_DIR}/x86/${LIB_NAME}" cp "${TARGET_DIR}/armv7-linux-androideabi/${BUILD_MODE}/${LIB_NAME}" "${JNILIBS_DIR}/armeabi-v7a/${LIB_NAME}" cp "${TARGET_DIR}/aarch64-linux-android/${BUILD_MODE}/${LIB_NAME}" "${JNILIBS_DIR}/arm64-v8a/${LIB_NAME}" -(cd "${OUT_DIR}" && zip -r "jniLibs.zip" "jniLibs") -(cd "${OUT_DIR}" && zip -r "kotlin.zip" "kotlin") ''' [tasks.android-build] @@ -102,5 +100,3 @@ dependencies = [ "android-build-bindings", "android-assemble-aar-files", ] - -[tasks.create-release] diff --git a/android/.gitlab-ci.yml b/android/.gitlab-ci.yml @@ -4,6 +4,10 @@ stages: - release build_android: + only: + - main + - develop + - tags tags: - proofmode-debian stage: build @@ -14,28 +18,21 @@ build_android: - ./out/android/ upload_android: + only: + - tags stage: upload image: curlimages/curl:latest script: - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./out/android/kotlin.zip "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/android-v0.${CI_PIPELINE_IID}/kotlin.zip"' - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./out/android/jniLibs.zip "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/android-v0.${CI_PIPELINE_IID}/jniLibs.zip"' -release_android: +publish_android: + image: mobiledevops/android-sdk-image:33.0.2 + only: + - develop + - tags stage: release - image: registry.gitlab.com/gitlab-org/release-cli:latest - rules: - - if: $CI_COMMIT_TAG - when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH script: - - echo "running release_android for $TAG" - release: - tag_name: "android-v0.$CI_PIPELINE_IID" - description: "android-v0.$CI_PIPELINE_IID" - ref: "$CI_COMMIT_SHA" - assets: - links: - - name: "kotlin.zip" - url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/android-v0.${CI_PIPELINE_IID}/kotlin.zip" - - name: "jniLibs.zip" - url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/android-v0.${CI_PIPELINE_IID}/jniLibs.zip" + - cp -r out/android/* android/project/simple_c2pa/src/main/ + - ls -al android/project/simple_c2pa/src/main/ + - cd android/project && ./gradlew clean assembleRelease diff --git a/apple/.gitlab-ci.yml b/apple/.gitlab-ci.yml @@ -20,22 +20,25 @@ upload_apple: - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./out/apple/SimpleC2PA.swift "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/apple-v0.${CI_PIPELINE_IID}/SimpleC2PA.swift"' - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./out/apple/SimpleC2PA.xcframework.zip "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/apple-v0.${CI_PIPELINE_IID}/SimpleC2PA.xcframework.zip"' -release_apple: +publish_apple: stage: release - image: registry.gitlab.com/gitlab-org/release-cli:latest - rules: - - if: $CI_COMMIT_TAG - when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + image: debian:bullseye + before_script: + - apt-get update && apt-get install -y git perl + - git config --global user.email "${GITLAB_USER_EMAIL}" + - git config --global user.name "${GITLAB_USER_NAME}" script: - - echo "running release_apple for $TAG" - release: - tag_name: "apple-v0.$CI_PIPELINE_IID" - description: "apple-v0.$CI_PIPELINE_IID" - ref: "$CI_COMMIT_SHA" - assets: - links: - - name: "SimpleC2PA.swift" - url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/apple-v0.${CI_PIPELINE_IID}/SimpleC2PA.swift" - - name: "SimpleC2PA.xcframework.zip" - url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/apple-v0.${CI_PIPELINE_IID}/SimpleC2PA.xcframework.zip" + - cp out/apple/SimpleC2PA.swift apple/src/SimpleC2PA/ + - FRAMEWORK_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/simple_c2pa/apple-v0.${CI_PIPELINE_IID}/SimpleC2PA.xcframework.zip" + - echo "Calculating checksum..." + - CHECKSUM=$(shasum -a 256 ./out/apple/SimpleC2PA.xcframework.zip | awk '{print $1}') + - echo "Updating Package.swift..." + - echo $FRAMEWORK_URL + - echo $CHECKSUM + - 'sed -i "s|url: \\".*\\"|url: \\"${FRAMEWORK_URL}\\"|g" Package.swift' + - 'sed -i "s|checksum: \\".*\\"|checksum: \\"${CHECKSUM}\\"|g" Package.swift' + - cat Package.swift + - git add Package.swift + - git add apple/src/SimpleC2PA/SimpleC2PA.swift + - git commit -m "Update Swift files" + - git push origin HEAD:$CI_COMMIT_REF_NAME diff --git a/src/certificates.rs b/src/certificates.rs @@ -84,6 +84,26 @@ impl CertificateType { } } + fn to_organization(&self) -> String { + match self { + CertificateType::OnlineRoot { organization, .. } => { + organization.clone().unwrap_or(DEFAULT_ORGANIZATION.to_owned()) + } + CertificateType::OnlineIntermediate { organization, .. } => { + organization.clone().unwrap_or(DEFAULT_ORGANIZATION.to_owned()) + } + CertificateType::OfflineRoot { organization, .. } => { + organization.clone().unwrap_or(DEFAULT_ORGANIZATION.to_owned()) + } + CertificateType::OfflineIntermediate { organization, .. } => { + organization.clone().unwrap_or(DEFAULT_ORGANIZATION.to_owned()) + } + CertificateType::ContentCredentials { organization, .. } => { + organization.clone().unwrap_or(DEFAULT_ORGANIZATION.to_owned()) + } + } + } + fn to_common_name(&self) -> String { match self { CertificateType::OnlineRoot { organization, .. } => { @@ -177,7 +197,7 @@ fn generate_serial_number() -> Result<Asn1Integer, SimpleC2PAError> { fn create_name(options: Arc<CertificateOptions>) -> Result<X509Name, SimpleC2PAError> { let mut name_builder = X509NameBuilder::new()?; name_builder.append_entry_by_text("CN", &options.certificate_type.to_common_name())?; - name_builder.append_entry_by_text("O", DEFAULT_ORGANIZATION)?; + name_builder.append_entry_by_text("O", &options.certificate_type.to_organization())?; if let Some(email_address) = options.email_address.clone() { name_builder.append_entry_by_text("emailAddress", &email_address)?; diff --git a/tests/examples.rs b/tests/examples.rs @@ -20,7 +20,6 @@ pub mod tests { let file = FileData::new(None, Some(file_data), Some(file_name.clone())); let cc = ContentCredentials::new(content_credentials_certificate, file, None); cc.add_created_assertion().unwrap(); - let output_path = format!("outputs/c2pa-basic-{}", file_name); let file_data = cc.embed_manifest(Some(output_path.clone())).unwrap(); fs::write(output_path, file_data.get_bytes().unwrap()).expect("Can't write file"); @@ -33,15 +32,24 @@ pub mod tests { let file_data = fs::read(image_path).expect("Can't read image"); let fingerprint = "BA08 71E8 0200 B95D 8297  7ED0 4D1E C37F 88A7 FDCE".to_string(); - let root_certificate = create_root_certificate(None, None).unwrap(); + let organization = "Sample Organization".to_string(); + let root_certificate = create_root_certificate(Some(organization.clone()), None).unwrap(); + let root_bytes = root_certificate.get_certificate_bytes().unwrap(); + let root_path = "outputs/c2pa-root-certificate.crt"; + fs::write(root_path, root_bytes).expect("Can't write file"); + let content_credentials_certificate = - create_content_credentials_certificate(Some(root_certificate.clone()), None, None) + create_content_credentials_certificate(Some(root_certificate.clone()), Some(organization.clone()), None) .unwrap(); + let content_bytes = content_credentials_certificate + .get_certificate_bytes() + .unwrap(); + let content_path = "outputs/c2pa-credentials-certificate.crt"; + fs::write(content_path, content_bytes).expect("Can't write file"); let file = FileData::new(None, Some(file_data), Some(file_name.clone())); let app_info = ApplicationInfo::new("SampleApp".to_string(), "1.0.0".to_string(), None); let cc = ContentCredentials::new(content_credentials_certificate, file, Some(app_info)); - println!("{:?}", cc); cc.add_created_assertion().unwrap(); let exif_data = ExifData {