Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bgon committed Dec 20, 2024
0 parents commit 9201be7
Show file tree
Hide file tree
Showing 32 changed files with 5,507 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/*
resources
node_modules
package-lock.json
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 140,
"tabWidth": 2
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Hacker Factor, Dr. Neal Krawetz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions LICENSE-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Original C code Copyright (c) 2024 Hacker Factor, Dr. Neal Krawetz
Ported to TypeScript by Bertrand Gondouin (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# SEAL-js
- [SEAL-js](#seal-js)
- [About](#about)
- [Roadmap and current status](#roadmap-and-current-status)
- [Overall functionalities](#overall-functionalities)
- [Image file formats Read Support](#image-file-formats-read-support)
- [Audio file formats Read Support](#audio-file-formats-read-support)
- [Video file formats Read Support](#video-file-formats-read-support)
- [Document formats Read Support](#document-formats-read-support)
- [Container formats Read Support](#container-formats-read-support)
- [Usage examples](#usage-examples)
- [Reading and validating a media](#reading-and-validating-a-media)
- [Creating a SEAL](#creating-a-seal)
- [Contributing](#contributing)
- [License](#license)

## About
`SEAL-js` is a TypeScript implementation of [Secure Evidence Attribution Label (SEAL)](https://github.com/hackerfactor/SEAL) according to [Version 1.1.4, 5-October-2024](https://github.com/hackerfactor/SEAL/blob/master/SPECIFICATION.md).

It should run out of the box in modern browsers as well as Node.js

## Roadmap and current status

This library is under active development and not fully functional yet. Proceed with caution!

### Overall functionalities

- ✅ Read SEAL metadata
- ✅ DNS record lookup
- ✅ Parse DNS record
- ✅ Parse signature format
- ✅ Compute the digest
- ✅ Compute the Double Digest
- ✅ Hash the digest
- 🚧 Validate the digest **(sha256 RSA only)**
- ❌ Write SEAL metadata

### Image file formats Read Support

- ✅ JPEG
- ✅ PNG
- ✅ GIF
- ✅ WEBP
- ✅ HEIC
- 🚧 AVIF
- ✅ PNM/PPM/PGM
- ✅ SVG
- ✅ TIFF
- ✅ DICOM
- ❌ BMP (no metadata support)
- ❌ FAX (No. Seriously, just no.)

### Audio file formats Read Support
- ✅ AAC
- 🚧 AVIF
- ✅ M4A
- ✅ MKA
- ✅ MP3
- ✅ MP3+ID3
- ✅ MPEG
- ✅ WAV

### Video file formats Read Support
- ✅ MP4
- 🚧 3GP
- 🚧 AVI
- 🚧 AVIF
- 🚧 HEIF
- 🚧 HEVC
- 🚧 DIVX
- 🚧 MKV
- 🚧 MOV/Quicktime
- ✅ MPEG
- 🚧 WEBM

### Document formats Read Support
- ✅ PDF
- ✅ XML
- ✅ HTML
- ✅ Plain Text
- 🚧 OpenDocument (docx, pptx, etc.)

### Container formats Read Support
- ✅ EXIF (Nested EXIF records are unsupported due to the ambiguous scope.)
- ✅ XMP (Nested XMP records are unsupported due to the ambiguous scope.)
- 🚧 RIFF
- 🚧 ISO-BMFF
- ✅ Matroska
- 🚧 ZIP (The OpenDocument formats use ZIP.)

## Usage examples

### Reading and validating a media

Example usage in a Node.js environment:

```typescript
import path from 'path'
import { readFileSync } from 'node:fs';
import { SEAL, mediaAsset } from './dist/seal.js';

if (process.argv.length < 3) {
console.error('Missing filename');
process.exit(1);
}

// Read the asset file
const buf = readFileSync(process.argv[2]).buffer;

let asset = new mediaAsset(buf, path.basename(process.argv[2]));

if (asset.seal_segments.length > 0) {
SEAL.parse(asset);
console.log(await SEAL.validateSig(asset))
};
```

### Creating a SEAL

TODO

## Contributing

Contributions are welcome!

- [Create an issue](https://github.com/bgon/SEAL-js/issues)
- [Fork this repository](https://github.com/bgon/SEAL-js/fork)
- [Open a pull request](https://github.com/bgon/SEAL-js/pulls)

## License

Distributed under MIT License. See `LICENSE` and `LICENSE-typescript`for more information.

78 changes: 78 additions & 0 deletions dist/chunk-5QIYPGHP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
detectMimeType
} from "./chunk-APGEQWFO.js";

// src/mediaasset.ts
var textDecoder = new TextDecoder();
var mediaAsset = class {
constructor(data, filename) {
this.data = data;
this.filename = filename;
this.filename = filename;
this.readChunks();
console.log(`[${filename}](${this.mimeType})`);
}
mimeType = "image/jpeg";
seal_segments = [];
getDataLength() {
return this.data.byteLength;
}
/**
* Reads chunks of data and processes SEAL segments.
*/
readChunks() {
console.time("readChunks");
const dataArray = new Uint8Array(this.data);
this.data = dataArray;
this.mimeType = detectMimeType(dataArray.slice(0, 140));
let skip = false;
if (this.getDataLength() - 65536 > 65536) {
skip = true;
}
for (let i = 0; i < dataArray.length; i++) {
if (i > 65536 && skip === true) {
i = this.getDataLength() - 65536;
skip = false;
}
if (dataArray[i] == 60 && dataArray[i + 1] == 115 && dataArray[i + 2] == 101 && dataArray[i + 3] == 97 && dataArray[i + 4] == 108 || // Detect the start of a SEAL segment "<?seal " (hex: 3C 3F 73 65 61 6C 20)
dataArray[i] == 60 && dataArray[i + 1] == 63 && dataArray[i + 2] == 115 && dataArray[i + 3] == 101 && dataArray[i + 4] == 97 && dataArray[i + 5] == 108 || // Detect the start of a SEAL segment "&lt;seal " (hex: 26 6C 74 3B 73 65 61 6C 20)
dataArray[i] == 38 && dataArray[i + 1] == 108 && dataArray[i + 2] == 116 && dataArray[i + 3] == 59 && dataArray[i + 4] == 115 && dataArray[i + 5] == 101) {
const sealStart = i;
let continueReading = true;
while (continueReading) {
if (dataArray[i] == 47 && dataArray[i + 1] == 62 || dataArray[i] == 63 && dataArray[i + 1] == 62 || dataArray[i] == 47 && dataArray[i + 1] == 38 && dataArray[i + 2] == 103 && dataArray[i + 3] == 116) {
continueReading = false;
}
i++;
}
const sealString = textDecoder.decode(dataArray.slice(sealStart, i + 1));
this.seal_segments.push({ string: sealString, signature_end: i - 2 });
}
}
console.timeEnd("readChunks");
}
dumpInfo() {
console.log(this);
}
/**
* Assembles a data buffer based on a list of ranges.
*
* @param ranges - An array of tuples, each representing the start and end positions of a range.
* @returns A new Uint8Array that contains the assembled data from the specified ranges.
*/
assembleBuffer(ranges) {
const totalLength = ranges.reduce((sum, [start, end]) => sum + (end - start), 0);
const assembledBuffer = new Uint8Array(totalLength);
let currentPosition = 0;
ranges.forEach(([start, end]) => {
const dataSlice = this.data.slice(start, end);
assembledBuffer.set(new Uint8Array(dataSlice), currentPosition);
currentPosition += dataSlice.byteLength;
});
return assembledBuffer;
}
};

export {
mediaAsset
};
103 changes: 103 additions & 0 deletions dist/chunk-APGEQWFO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// src/mimetypes.ts
var textDecoder = new TextDecoder();
var mimeTypes = {
dcdc: "application/cpl+xml",
"1f8b08": "application/gzip",
"25504446": "application/pdf",
"7b5c72746631": "application/rtf",
"526172211A0700": "application/vnd.rar",
"526172211a070100": "application/vnd.rar",
"425a68": "application/x-bzip2",
"7573746172003030": "application/x-tar",
"7573746172202000": "application/x-tar",
"504b0304": "application/zip",
"504b0506": "application/zip",
"504b0708": "application/zip",
"2321414d52": "audio/AMR",
"2e736e64": "audio/basic",
"646e732e": "audio/basic",
"4d546864": "audio/midi",
"667479704d344120": "audio/mp4",
fffb: "audio/mp3",
fff3: "audio/mp3",
fff2: "audio/mp3",
ffe3: "audio/mp3",
"494433": "audio/mp3",
fff1: "audio/aac",
fff9: "audio/aac",
"57415645": "audio/wav",
"464f524d00": "audio/x-aiff",
"664c6143": "audio/x-flac",
"424d": "image/bmp",
"4449434D": "image/dcm",
"47494638": "image/gif",
"0000000C6A502020": "image/jp2",
ffd8ff: "image/jpeg",
"89504e470d0a1a0a": "image/png",
"49492a00": "image/tiff",
"4d4d002a": "image/tiff",
"3c737667": "image/svg",
"38425053": "image/vnd.adobe.photoshop",
"57454250": "image/webp",
"010009000003": "image/wmf",
d7cdc69a: "image/wmf",
"5035": "image/x-portable-graymap",
"5036": "image/x-portable-pixmap",
"01da01010003": "image/x-rgb",
"67696d7020786366": "image/x-xcf",
"0000001466747970336770": "video/3gpp2",
"0000002066747970336770": "video/3gpp2",
"6674797069736f6d": "video/mp4",
"667479704d534e56": "video/mp4",
"000000186674797033677035": "video/mp4",
"0000001c667479704d534e56012900464d534e566d703432": "video/mp4",
"6674797033677035": "video/mp4",
"00000018667479706d703432": "video/mp4",
"667479706d703432": "video/mp4",
ffd8: "video/mpeg",
"000001ba": "video/mpeg",
"4F676753": "video/ogg",
"1466747970717420": "video/quicktime",
"6674797071742020": "video/quicktime",
"6d6f6f76": "video/quicktime",
"20667479704d3456": "video/x-flv",
"464c5601": "video/x-flv",
"1a45dfa3": "video/x-matroska"
};
function detectMimeType(fileBytes) {
const bytesHex = Array.from(fileBytes.slice(0, 16)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
for (const [signature, mimeType] of Object.entries(mimeTypes)) {
if (bytesHex.includes(signature)) {
return mimeType;
}
}
const textCharactersRegex = /^[\x09\x0A\x0D\x20-\x7E\x80-\xFF]*$/m;
let string = textDecoder.decode(fileBytes.slice(1, 32));
if (string.includes("mp4")) {
return "video/mp4";
}
if (string.includes("heic")) {
return "image/heif";
}
if (string.includes("jumb")) {
return "application/c2pa";
}
if (string.includes("DICM")) {
return "image/dcm";
}
if (textCharactersRegex.test(string)) {
if (string.includes("DOCTYPE") && string.includes("html")) {
return "text/html";
}
if (string.includes("DOCTYPE") && string.includes("svg")) {
return "image/svg";
} else {
return "text/plain";
}
}
return "unknown";
}

export {
detectMimeType
};
Loading

0 comments on commit 9201be7

Please sign in to comment.