Skip to content

Commit 12c3590

Browse files
committed
Make it bunx runnable
1 parent ceaf047 commit 12c3590

7 files changed

Lines changed: 46 additions & 22 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.envrc
2+
CA-PEM
3+
14
# Dependencies
25
node_modules/
36
npm-debug.log*
@@ -101,4 +104,4 @@ temp/
101104
.Spotlight-V100
102105
.Trashes
103106
ehthumbs.db
104-
Thumbs.db
107+
Thumbs.db

CA-PEM/.gitkeep

Whitespace-only changes.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ Modern TypeScript utility to check the signature of Apple P12 Certificates using
2222
# Install Bun (if not already installed)
2323
curl -fsSL https://bun.sh/install | bash
2424

25-
# Install dependencies
25+
# Install dependencies (only if you want to develop, otherwise see the bunx command below)
2626
bun install
2727
```
2828

2929
## Usage
3030

31+
## Give me quick copy-paste command I’m impatient
32+
33+
```bash
34+
bunx github:Olympta/CertCheck certcheck cert.p12 --password 123456
35+
```
36+
37+
No need to clone the repo.
38+
3139
### Using Package Scripts (Recommended)
3240
```bash
3341
# Main certificate checker
@@ -143,4 +151,4 @@ $ bun certcheck cert.p12 --password 123456 --json
143151
```
144152

145153
## License
146-
MIT
154+
MIT

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "3.0.0",
44
"description": "Modern Bun utility to check the signature of Apple P12 Certificates",
55
"type": "module",
6-
"main": "src/index.ts",
6+
"bin": {
7+
"certcheck": "./src/index.ts"
8+
},
79
"scripts": {
810
"certcheck": "bun run src/index.ts",
911
"ca-downloader": "bun run src/caDownloader.ts",

src/caDownloader.ts

100644100755
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env bun
12
import { CerUtils } from './cerUtils.js';
23

34
interface DownloadResult {
@@ -6,7 +7,7 @@ interface DownloadResult {
67
error?: string;
78
}
89

9-
class CaDownloader {
10+
export class CaDownloader {
1011
private readonly caDirectory = 'CA-PEM';
1112
private readonly certificates = [
1213
'AppleWWDRCA',
@@ -20,7 +21,7 @@ class CaDownloader {
2021
private getCertificateUrl(filename: string): string {
2122
// The first CA certificate (AppleWWDRCA) is stored in a different place for some reason...
2223
if (filename.endsWith('A')) {
23-
return 'https://developer.apple.com/certificationauthority/AppleWWDRCA.cer';
24+
return `https://developer.apple.com/certificationauthority/${filename}.cer`;
2425
}
2526
return `https://www.apple.com/certificateauthority/${filename}.cer`;
2627
}
@@ -30,7 +31,7 @@ class CaDownloader {
3031
const url = this.getCertificateUrl(filename);
3132
const tempFileName = `cctmp-${filename}.cer`;
3233

33-
console.log(`[*] Downloading ${filename}.cer...`);
34+
console.error(`[*] Downloading ${filename}.cer...`);
3435
const response = await fetch(url);
3536

3637
if (!response.ok) {
@@ -54,7 +55,7 @@ class CaDownloader {
5455
try {
5556
const tempCerPath = `cctmp-${filename}.cer`;
5657

57-
console.log(`[*] '${filename}.cer' has been downloaded, converting to PEM format...`);
58+
console.error(`[*] '${filename}.cer' has been downloaded, converting to PEM format...`);
5859

5960
await new CerUtils(tempCerPath).convertToPem();
6061

@@ -75,7 +76,7 @@ class CaDownloader {
7576
await Bun.file(tempCerPath).unlink();
7677
await Bun.file(tempPemPath).unlink();
7778

78-
console.log(`[*] Successfully converted and moved ${filename}.pem to CA-PEM directory`);
79+
console.error(`[*] Successfully converted and moved ${filename}.pem to CA-PEM directory`);
7980
} catch (error) {
8081
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
8182
console.error(`[!] Failed to convert ${filename}.cer: ${errorMessage}`);
@@ -85,12 +86,12 @@ class CaDownloader {
8586
private async ensureCaDirectory(): Promise<void> {
8687
if (!(await Bun.file(this.caDirectory).exists())) {
8788
await Bun.write(`${this.caDirectory}/.gitkeep`, '');
88-
console.log(`[*] Created ${this.caDirectory} directory`);
89+
console.error(`[*] Created ${this.caDirectory} directory`);
8990
}
9091
}
9192

9293
public async downloadAllCertificates(): Promise<void> {
93-
console.log('[*] Downloading resources...\n[*] Once complete, you can run the main script again.\n');
94+
console.error('[*] Downloading resources...\n[*] Once complete, you can run the main script again.\n');
9495

9596
await this.ensureCaDirectory();
9697

@@ -105,15 +106,23 @@ class CaDownloader {
105106
});
106107

107108
await Promise.all(downloadPromises);
108-
console.log('\n[*] Download process completed!');
109+
console.error('\n[*] Download process completed!');
109110
}
110111
}
111112

112-
// Main execution
113-
const downloader = new CaDownloader();
114-
await downloader.downloadAllCertificates().catch(error => {
115-
console.error('[!] Unexpected error during download:', error);
116-
process.exit(1);
117-
});
113+
// Export a standalone function for importing
114+
export async function downloadCaCertificates(): Promise<void> {
115+
const downloader = new CaDownloader();
116+
await downloader.downloadAllCertificates();
117+
}
118+
119+
// Main execution (only run if this file is executed directly)
120+
if (import.meta.main) {
121+
const downloader = new CaDownloader();
122+
await downloader.downloadAllCertificates().catch(error => {
123+
console.error('[!] Unexpected error during download:', error);
124+
process.exit(1);
125+
});
126+
}
118127

119128
export {};

src/cerUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class CerUtils {
5959
const outputPath = this.getOutputPath();
6060

6161
await Bun.write(outputPath, pemContent);
62-
console.log(`Converted ${this.filePath} to ${outputPath}`);
62+
console.error(`Converted ${this.filePath} to ${outputPath}`);
6363
} catch (error) {
6464
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
6565
console.error(`[!] Conversion failed: ${errorMessage}`);

src/index.ts

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#!/usr/bin/env bun
12
import * as ocsp from 'ocsp';
23
import { P12Utils } from './p12Utils.js';
4+
import { downloadCaCertificates } from './caDownloader.js';
35

46
interface ParsedArgs {
57
p12File?: string | undefined;
@@ -137,9 +139,9 @@ class CertCheck {
137139
try {
138140
await fs.access('CA-PEM');
139141
} catch {
140-
throw new Error(
141-
"Please run 'bun run src/caDownloader.ts' to retrieve the necessary certificate authorities from Apple's servers.\n[*] The downloaded certificates will be automatically converted to the correct format."
142-
);
142+
console.error('[*] CA-PEM directory not found. Downloading Apple CA certificates...');
143+
await downloadCaCertificates();
144+
console.error('[*] CA certificates downloaded successfully!');
143145
}
144146
}
145147

0 commit comments

Comments
 (0)